-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
207 lines (186 loc) · 7.37 KB
/
admin.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
199
200
201
202
203
204
205
206
207
<?php
// Include default dependencies
require_once("./php/conf.php");
// HTTP Authentication
if (
!isset($_SERVER["PHP_AUTH_USER"]) ||
!isset($_SERVER["PHP_AUTH_PW"]) ||
!($_SERVER["PHP_AUTH_USER"] == ADMIN_NAME && $_SERVER["PHP_AUTH_PW"] == ADMIN_PASSWORD)
) {
header('WWW-Authenticate: Basic realm="Admin console"');
header('HTTP/1.0 401 Unauthorized');
echo 'Please refresh the page and enter the admin credentials';
exit;
}
// Create app object
$app = new AppManager();
$app->initiateRouter([UserType::temp->value => ["admin"]], ["admin" => "Admin console"]);
// Start output buffering to allow for response rewrite
ob_start();
if ($app->pageManager->isNormalRequest) { // Only for initial page load
$app->cssManager->require("reset", "fonts", "transitions", "dialog", "index", "phone");
$app->jsManager->require("ajax", "util", "index", "api", "transitions", "bind");
?>
<!DOCTYPE html>
<html lang="cs">
<head>
<title><?= $app->pageManager->pageTitle ?></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="mobile-web-app-capable" content="yes">
<link rel="manifest" href="<?= $prefix ?>/assets/manifest.json<?= $v ?>">
<meta name="theme-color" content="<?= COLOR ?>">
<meta name="description" content="<?= DESCRIPTION ?>">
<link rel="icon" href="<?= $prefix ?>/assets/icons/icon.png">
<script>
const base_url = '<?= $prefix ?>';
<?php
if (SERVICE_WORKER_ENABLED) {
?>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register(base_url + '/serviceworker.js?base_url=<?= urlEncode($prefix) ?>&cacheId=<?= substr($v, 3) ?>&enabled=<?= SERVICE_WORKER_ENABLED ? "true" : "false" ?>');
}
<?php
}
?>
</script>
<?php
$app->cssManager->fetch();
$app->jsManager->fetch();
?>
</head>
<body>
<?php
}
?>
<header>
<img src="<?= $prefix ?>/assets/icons/icon.png" class="logo">
Admin console | <?= NAME ?>
</header>
<div class="mainWrapper">
<main>
<?= AdminSetting::render(
"Force reload HejPanel clients",
"Force reload check: " . $forceReload,
"Force reload",
function () use ($forceReload) {
$str = file_get_contents('php/conf.php');
$str = str_replace("\$forceReload = $forceReload;", "\$forceReload = " . ($forceReload + 1) . ";", $str);
file_put_contents('php/conf.php', $str);
},
RELOAD()
) ?>
<hr>
<?= AdminSetting::render(
"Update",
"Run suite of actions:<br>- clearMinifiedPackages<br>- updateManifest<br>- updateRobotsTxt<br>- updateSitemap<br>- incrementVersion",
"Update app",
function () use ($app) {
$app->pushNewVersion();
},
CREATE_MODAL("Success", "App was updated successfully") . ON_CLOSE(RELOAD())
) ?>
<hr>
<?= AdminSetting::render(
"Remove orphan files",
"Remove files that are not assigned to any panel.<br>Orphan files: " . $con->select(["COUNT(*)" => "count"], "files")->addSQL("WHERE id NOT IN (SELECT content FROM panels WHERE type = \"image\");")->fetchValue(),
"Send",
function () use ($con) {
$files = $con->select("file", "files")->addSQL("WHERE id NOT IN (SELECT content FROM panels WHERE type = \"image\");")->fetchColumn();
foreach ($files as $file) {
unlink(PREFIX . "uploads/" . $file);
}
$con->delete("files")->addSQL("WHERE id NOT IN (SELECT content FROM panels WHERE type = \"image\");")->execute();
return $files;
},
CREATE_MODAL("Successfully removed ' + output.length + ' files", "Files removed: ' + output.join(', ') + '") . ON_CLOSE(RELOAD())
) ?>
<hr>
<?= AdminSetting::render(
"App version",
"Current version: " . substr($v, 3),
"Increment version",
function () use ($app) {
$app->incrementVersion();
},
RELOAD()
) ?>
<?= AdminSetting::render(
"Minified packages cache",
"Cached packages:<br>" . join(", ", array_filter(scandir("generated/packages"), fn ($e) => is_file("generated/packages/" . $e))),
"Clear minified packages cache",
function () use ($app) {
$app->clearMinifiedPackages();
},
RELOAD(),
) ?>
<?= AdminSetting::render(
"Manifest",
"Generates a new version of the manifest.json file",
"Generate manifest",
function () use ($app) {
$app->updateManifest();
},
RELOAD()
) ?>
<?= AdminSetting::render(
"Robots",
"Generates a new version of the robots.txt file",
"Generate robots.txt",
function () {
},
CREATE_MODAL("ERROR", "Not implemented")
) ?>
<?= AdminSetting::render(
"Sitemap",
"Generates a new version of the sitemap.xml file",
"Generate sitemap",
function () {
},
CREATE_MODAL("ERROR", "Not implemented")
) ?>
<hr>
<?= AdminSetting::render(
"MySQL database structure",
"WARNING - REMOVES ALL DATA",
"Update tables",
function () use ($app) {
// $app->synchronizeTables();
},
CREATE_MODAL("ERROR", "Not implemented"),
) ?>
<hr>
<?= AdminSetting::render(
"Push notification",
"Sends a test push notification to all available subscriptions",
"Send",
function () use ($prefix) {
NotificationManager::broadcastNotification(
function (User $user) use ($prefix) {
return ["Hello $user->name", "This is only a test notification, please ignore it. Have a nice rest of the day :)", $prefix];
}
);
},
CREATE_MODAL("SUCCESS", "Notifications successfully sent")
) ?>
</main>
</div>
<footer>
<?= NAME ?> version <?= substr($v, 3) ?>
</footer>
<?php
if ($app->pageManager->isNormalRequest) {
// Fetch dynamic modules (Initial load)
$app->cssManager->fetch();
$app->jsManager->fetch();
// Finish document
?>
</body>
</html>
<?php
} else {
// Fetch dynamic modules - using js (Hydration load)
$app->cssManager->fetch(false);
$app->jsManager->fetch(false);
}
$app->bind->handleEventHandlers();