-
Notifications
You must be signed in to change notification settings - Fork 2
/
guiCore.php
198 lines (166 loc) · 9.58 KB
/
guiCore.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
/*
HonestRepair Diablo Engine - GUI Core
https://www.HonestRepair.net
https://github.com/zelon88
Licensed Under GNU GPLv3
https://www.gnu.org/licenses/gpl-3.0.html
Author: Justin Grimes
Date: 3/12/2021
<3 Open-Source
The GUI Core provides resources for the user interfaces & decides which interface to use.
*/
// / ----------------------------------------------------------------------------------
// / Prepare the execution environment.
// / Reset PHP's time limit for execution.
set_time_limit(0);
// / Make sure there is a session started.
if (session_status() == PHP_SESSION_NONE) session_start();
// / Determine the root path where the application is installed and where it is running from.
$RootPath = '';
if (!file_exists('core.php')) {
// / If we can't use a relative path, check the server document root directory instead.
$RootPath = $_SERVER['DOCUMENT_ROOT'];
if (!file_exists($RootPath.DIRECTORY_SEPARATOR.'core.php')) die('<a class="errorMessage">ERROR!!! 16, Could not process the Core Diablo Engine file (core.php)!</a>'.PHP_EOL); }
// / ----------------------------------------------------------------------------------
// / ----------------------------------------------------------------------------------
// / Perform sanity checks to verify the environment is suitable for running.
// / Determine if the core.php file has been called already and stop execution if it has not.
if (!isset($GlobalsAreVerified)) die('<a class="errorMessage">ERROR!!! 17, Out of context execution of this file is forbidden!</a>'.PHP_EOL);
// / Stop the application if $MaintenanceMode is enabled.
if ($MaintenanceMode) die('The requested application is currently unavailable due to maintenance.'.PHP_EOL);
// / ----------------------------------------------------------------------------------
// / ----------------------------------------------------------------------------------
// / The following code sets the functions for the session.
// / A function to determine the current URL.
function getCurrentURL() {
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
$httpPrefix = 'https://'; }
if (!empty($_SERVER['HTTPS']) or $_SERVER['HTTPS'] = 'on') {
$httpPrefix = 'http://'; }
$Current_URL = $httpPrefix.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
return ($CurrentURL); }
// / A function to get a list of files from a folder as an array.
// / Set $pathToFiles to an absolute path to a valid directory where www-data has read access.
// / Set $includeIndexFiles to TRUE to have index.html files appear in the array of results.
// / Set $includeIndexFiles to FALSE to have index.html files removed from the array of results.
// / Set $includeDangerousFiles to TRUE to have dangerous files appear in the array of results.
// / Set $includeDangerousFiles to FALSE to have dangerous files removed from the array of results.
// / The $DangerousFiles array defined in config.php contains the global list of dangerous file extensions.
// / Set $includeDirectories to TRUE to have directories appear in the array of results.
// / Set $includeDirectories to FALSE to have directories removed from the array of results.
function getFiles($pathToFiles, $includeIndexFiles, $includeDangerousFiles, $includeDirectories) {
global $DangerousFiles;
$dirtyFileArr = $OperationSuccessful = FALSE;
$dirtyFileArr = array();
$dirtyFileArr = scandir($Files);
foreach ($dirtyFileArr as $dirtyFile) {
if ($dirtyFile === '.' or $dirtyFile === '..') continue;
$dirtyExt = pathinfo($pathToFiles.DIRECTORY_SEPARATOR.$dirtyFile, PATHINFO_EXTENSION);
if (!$includeDangerousFiles && in_array($dirtyExt, $DangerousFiles)) continue;
if (!$includeIndexFiles && $dirtyFile == 'index.html') continue;
if (!$includeDirectories && is_dir($pathToFiles)) continue;
array_push($Files, $dirtyFile); }
// / Check that the operation returned some files.
if (count($Files) > 0) $OperationSuccessful = TRUE;
$dirtyFileArr = $dirtyFile = $dirtyExt = $pathToFiles = $includeDangerousFiles = $includeIndexFiles = NULL;
unset($dirtyFileArr, $dirtyFile, $dirtyExt, $pathToFiles, $includeDangerousFiles, $includeIndexFiles);
return ($Files); }
// / A function to return the file extension of an input file.
// / Set $pathToFile to an absolute path to a valid directory where www-data has read access.
function getExtension($pathToFile) {
$output = pathinfo($pathToFile, PATHINFO_EXTENSION);
$pathToFile = NULL;
unset($pathToFile);
return $output; }
// / A function to return a human readable file size that scales from Bytes->KB->MB->GB automatically.
// / Set $File to an absolute path to a valid directory where www-data has read access.
function getFilesize($file) {
$Size = filesize($file);
$file = NULL;
unset($file);
if ($Size < 1024) $Size = $Size." Bytes";
elseif (($Size < 1048576) && ($Size > 1023)) $Size = round($Size / 1024, 1)." KB";
elseif (($Size < 1073741824) && ($Size > 1048575)) $Size = round($Size / 1048576, 1)." MB";
else ($Size = round($Size / 1073741824, 1)." GB");
return ($Size); }
// / A function to set the color scheme for the session.
function setColorScheme() {
if ($ColorScheme == '0' or $ColorScheme == '' or !isset($ColorScheme)) {
$ColorScheme = '1'; }
if ($ColorScheme == '1') {
echo ('<link rel="stylesheet" type="text/css" href="'.$CD.'Styles/iframeStyle.css">'); }
if ($ColorScheme == '2') {
echo ('<link rel="stylesheet" type="text/css" href="'.$CD.'Styles/iframeStyleRED.css">'); }
if ($ColorScheme == '3') {
echo ('<link rel="stylesheet" type="text/css" href="'.$CD.'Styles/iframeStyleGREEN.css">'); }
if ($ColorScheme == '4') {
echo ('<link rel="stylesheet" type="text/css" href="'.$CD.'Styles/iframeStyleGREY.css">'); }
if ($ColorScheme == '5') {
echo ('<link rel="stylesheet" type="text/css" href="'.$CD.'Styles/iframeStyleBLACK.css">'); } }
function outputPageElement($htmlFile) {
global $DefaultTheme;
return ($HtmlElement);
}
// / A function to initialize installed widgets.
// / Widgets are small macros for adding standalone functionality to the GUI.
function initializeWidgets() {
global $WidgetsArrayCache;
$wac = $wid = $widget = $widgets = $WidgetsAreLoaded = $key = $keyCheck = $keyWac = $widgetArrayCountRaw = $widgetArrayCountRaw = $widgetArrayCheck = FALSE;
$widgetsArray = $newWidgetsArray = array();
// / Scan the Widgets directory and build an array of installed Widgets.
$widgetsArray = getFiles('Widgets', FALSE, TRUE);
// / Iterate through all installed widgets and
foreach ($widgetsArray as $widget) if (!is_dir($widget) && !($widget === '.' or $widget === '..' or $widget === 'index.html')) array_push($WidgetsArrayCache, $widget);
$WidgetArrayCountRaw = count($WidgetsArrayCache);
$widgetArrayCountRaw = count($WidgetsArrayCache);
// / Validate the Widget cache is accurate.
// / The cahce is not for improving performance, but rather to store the order that the user has arranged their Widgets.
// / Detects when Widgets are added or removed and updates the cache accordingly.
foreach ($widgetsArray as $keyCheck => $widgetArrayCheck) {
// / Detect if a Widget needs to be removed from the Widget cache.
if (!in_array($widgetArrayCheck, $widgetsArray)) {
// / Remove the Widget from the cache array.
$WidgetsArrayCache[$keyCheck] = NULL;
unset ($WidgetsArrayCache[$keyCheck]); } }
// / Consolidate the WidgetsArrayCache but keep the order of array elements intact.
foreach ($WidgetsArrayCache as $keyWac => $wac) {
// / Add the current array index to a new array, but in the same order as the original array.
// / This way new array keys will be generated in-order, but the order of the array will be preserved.
// / This is required to keep the number of array keys down.
// / Otherwise our array keys would become orphaned and the our index would grow arbitrarily.
$newWidgetsArray = array_push($newWidgetsArray, $wac);
// / Erase the current array index from the original WidgetsArrayCache array.
$WidgetsArrayCache[$keyWac] = NULL;
unset ($WidgetsArrayCache[$keyWac]); }
// / Redefine the WidgetsArrayCache with data from the newWidgetsArray.
$WidgetsArrayCache = $newWidgetsArray;
// / Clean up unneeded memory.
$wac = $wid = $widget = $widgets = $WidgetsAreLoaded = $key = $keyCheck = $keyWac = $widgetArrayCountRaw = $widgetArrayCountRaw = $widgetArrayCheck = $widgetsArray = $newWidgetsArray = NULL;
unset($wac, $wid, $widget, $widgets, $WidgetsAreLoaded, $key, $keyCheck, $keyWac, $widgetArrayCountRaw, $widgetArrayCountRaw, $widgetArrayCheck, $widgetsArray, $newWidgetsArray);
return (array($WidgetsArrayCache, $WidgetsAreLoaded)); }
function updateWidgetOrder() {
return ($WidgetOrder);
}
function outputWidgets($StyleToUse) {
return ($WidgetsElement);
}
function initializeApplications() {
$app = $application = $applications = $ApplicationsAreLoaded = $key = FALSE;
$ApplicationsArray = $applicationArray = array();
$applicationsArray = scandir('Widgets');
foreach ($applicationsArray as $application) if (is_dir($application) && !($application === '.' or $application === '..')) array_push($ApplicationsArray, $application);
foreach ($ApplicationsArray as $key => $application) { }
$applicationsArray = $applications = NULL;
unset($applicationsArray, $applications);
return (array($ApplicationArray, $applicationsAreLoaded)); }
function updateApplicationOrder() {
return ($ApplicationOrder);
}
function outputApplications($StyleToUse) {
return ($ApplicationsElement);
}
function outputLogs($StyleToUse, $LogSource) {
return ($LogsElement);
}
// / -----------------------------------------------------------------------------------