PluginProbe
WebTotem Security / 2.1.6
WebTotem Security v2.1.6
3.0.1 3.0.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 2.0 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.1 2.2.2 2.2.3 2.2.4 All 109 releases
wt-security / routes.php

routes.php in WebTotem Security 2.1.6, at routes.php

469 lines 19.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php defined('ABSPATH') or die("Protected By WT!");
2
3 add_action('admin_menu', 'wtsec_add_menu_link');
4 add_action('wp_ajax_change_status', 'wtsec_ajax_changeStatus');
5 add_action('admin_post_change_status', 'wtsec_changeStatus');
6 add_action('wp_ajax_cmd', 'wtsec_cmd_ajax');
7 add_action('admin_post_login_form', 'wtsec_login_form');
8 add_action('admin_post_ajax_cmd', 'wtsec_cmd_ajax');
9
10 function wtsec_add_menu_link()
11 {
12 add_menu_page(
13 WTSEC_PAGE_TITLE,
14 WTSEC_MENU_TITLE,
15 'manage_options',
16 wtsec_getRoute('dashboard'),
17 'wtsec_index_page',
18 '',
19 '1'
20 );
21 $parent = wtsec_getRoute('dashboard');
22 if (WTSEC_LIBRARY_App::authorized()) {
23 $capability = 'manage_options';
24 foreach (wtsec_pages() as $page => $arguments) {
25 add_submenu_page($parent, $arguments['page_title'], $arguments['menu_title'], $capability, wtsec_getRoute($page), $arguments['function']);
26 }
27 add_submenu_page(null, WTSEC_LIBRARY_Localization::lmsg('sign_in'), WTSEC_LIBRARY_Localization::lmsg('sign_in'), 'manage_options', wtsec_getRoute('login'), 'wtsec_login');
28 add_submenu_page($parent, WTSEC_LIBRARY_Localization::lmsg('logout'), WTSEC_LIBRARY_Localization::lmsg('logout'), 'manage_options', wtsec_getRoute('logout'), 'wtsec_logout');
29 } else {
30 $capability = 'manage_options';
31 foreach (wtsec_pages() as $page => $arguments) {
32 add_submenu_page(null, $arguments['page_title'], $arguments['menu_title'], $capability, wtsec_getRoute($page), function () {
33 wp_safe_redirect(wtsec_getUrl('login'));
34 });
35 }
36 add_submenu_page($parent, WTSEC_LIBRARY_Localization::lmsg('sign_in'), WTSEC_LIBRARY_Localization::lmsg('sign_in'), 'manage_options', wtsec_getRoute('login'), 'wtsec_login');
37 add_submenu_page(null, WTSEC_LIBRARY_Localization::lmsg('logout'), WTSEC_LIBRARY_Localization::lmsg('logout'), 'manage_options', wtsec_getRoute('logout'), 'wtsec_logout');
38 }
39 }
40
41 function wtsec_index_page()
42 {
43 $host = WTSEC_LIBRARY_WT::getOwnSite();
44 $services = [];
45 if (!empty($host)) {
46 $services = [
47 "settings" => [
48 "token" => WTSEC_LIBRARY_App::getToken(),
49 "site_id" => $host['id'],
50 ],
51 ];
52 $checks = WTSEC_LIBRARY_WT::getAllChecks($host['id']);
53 foreach ($checks as $service => $site) {
54 if (empty($site) || !is_array($site)) {
55 continue;
56 }
57 switch ($service) {
58 case "availability":
59 $services["wa"] = [
60 // "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']),
61 "pause" => "",
62 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
63 "response_time" => ceil($site['responseTime'] / 1000000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'),
64 "availability" => $site['percent'] . '%',
65 "availability_percent" => $site['percent'],
66 "downtime" => ceil($site['downTime'] / 1000000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'),
67 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.availability')
68 ];
69 break;
70 case "ssl":
71 if ((int)$site['expiryDate'] === 0) {
72 $days_left = 0;
73 } else {
74 $earlier = new DateTime();
75 $later = new DateTime($site['expiryDate']);
76 $days_left = $later->diff($earlier)->format("%a");
77 }
78 $services["ssl"] = [
79 "pause" => "",
80 "information" => wtsec_getInformation($service, $site['status']),
81 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
82 "days_left" => $days_left,
83 "issue_date" => $site['issueDate'],
84 "expiry_date" => $site['expiryDate'],
85 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.ssl')
86 ];
87 break;
88 case "domain":
89 if ((int)$site['expiredDate'] === 0) {
90 $days_left = 0;
91 } else {
92 $earlier = new DateTime();
93 $later = new DateTime($site['expiredDate']);
94 $days_left = $later->diff($earlier)->format("%a");
95 }
96
97 $services["dec"] = [
98 "pause" => "",
99 "registrar" => $site['registrar'],
100 "owner" => $site['owner'],
101 "information" => wtsec_getInformation($service, $site['status']),
102 "email" => $site['email'],
103 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
104 "days_left" => $days_left,
105 "created" => $site['createdDate'],
106 "expiry_date" => $site['expiredDate'],
107 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.domain')
108 ];
109 break;
110 case "reputation":
111 $count = 0;
112 if ($site['status'] != "clean") {
113 foreach ($site['virusList'] as &$list) {
114 if (!empty($list['viruses'])) {
115 $count++;
116 }
117 }
118 }
119 $services["av"] = [
120 "pause" => "",
121 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
122 "time_of_the_last_test" => $site['lastTest']['time'],
123 "blacklists_entries" => $count,
124 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.reputation')
125 ];
126 break;
127 case "maliciousScript":
128 $services["cms"] = [
129 "pause" => "",
130 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
131 "time_of_the_last_test" => $site['lastTest']['time'],
132 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.malicious')
133 ];
134 break;
135 case "deface":
136 $services["dc"] = [
137 "pause" => "",
138 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
139 "time_of_the_last_test" => $site['lastTest']['time'],
140 "number" => $site['count'],
141 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.deface')
142 ];
143 break;
144 case "ports":
145 $services["ps"] = [
146 "pause" => "",
147 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
148 "ip" => $site['ip'],
149 "time_of_the_last_test" => $site['lastTest']['time'],
150 "number" => count($site['tcp']),
151 "tcp" => !empty($site['tcp']) ? implode(",", $site['tcp']) : '',
152 "udp" => "",
153 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.port')
154 ];
155 break;
156 case "firewall":
157 $service = "WAF";
158 $_service = strtolower($service);
159 $domain = $host['hostname'];
160 $uid = $host['id'];
161 $chart = generateChart($site['chart']);
162 // $status = wtsec_checkStatus($uid, $service);
163 $services["waf"] = [
164 "pause" => "",
165 "site_address" => $domain,
166 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
167 "_status" => $site['status'],
168 "installed_status" => in_array($site['status'],["not_installed","error","down","not_supported","not_registered"]) ? false : true,
169 "time_of_the_last_check" => $site['lastTest']['time'],
170 "attacks" => $chart['count_attacks'],
171 "blocking" => $chart['count_blocks'],
172 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.firewall'),
173 "actions" => wtsec_generateButtons($uid, $_service, $service, $site['status'], WTSEC_SITE_URL),
174 "chart" => json_encode($chart['chart'], true)
175 ];
176 break;
177 case "antivirus":
178 $service = "AV";
179 $_service = strtolower($service);
180 $domain = $host['hostname'];
181 $uid = $host['id'];
182 // $status = wtsec_checkStatus($uid, $service);
183 $services["vc"] = [
184 "pause" => "",
185 "site_address" => $domain,
186 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
187 "installed_status" => in_array($site['status'],["not_installed","error","down","not_supported","not_registered"]) ? false : true,
188 "_status" => $site['status'],
189 "signatures" => (int)$site['stats']['infected'],
190 "changes" => (int)$site['stats']['changed'],
191 "list" => $site['stats']["infected"],
192 "actions" => wtsec_generateButtons($uid, $_service, $service, $site['status'], WTSEC_SITE_URL),
193 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus')
194 ];
195 break;
196 }
197 }
198
199
200 //check AM, if not installed , run install
201 $process = "installing";
202 $check_am_file = wtsec_checkInstalledFile("AM");
203 $am_installed = $check_am_file["status"];
204 $am_installed_status = wtsec_app()->get('am_installed');
205 if (!$am_installed && !$am_installed_status) {
206 $am_is_installed = wtsec_cmd("am_install", "AM", "am", $host['id'], [], WTSEC_SITE_URL);
207 if (!$am_is_installed) {
208 $process = "failed";
209 wtsec_app()->set('am_installed', false);
210 } else {
211 wtsec_app()->set('am_installed', true);
212 }
213 } elseif ($services["vc"]["_status"] === "not_installed" || $services["waf"]["_status"] === "not_installed") {
214 $process = "installing";
215 } else {
216 $process = "installed";
217 }
218
219
220
221 $services["am"] = [
222 "status" => WTSEC_LIBRARY_WT::getStatusIcon($am_installed ? "working" : "not_installed"),
223 "actions" => wtsec_generateButtons($host['id'], "am", "AM", ["active" => $check_am_file], WTSEC_SITE_URL),
224 "process_status" => $process,
225 "installed" => $am_installed,
226 ];
227 }
228
229 wtsec_layout("dashboard", $services);
230 }
231
232 function generateChart($charts)
233 {
234 $count_attacks = 0;
235 $count_blocks = 0;
236 $d = date("d");
237 $m = date("m");
238 $c = [];
239 $first_day = $d - 6;
240 if ($first_day < 1) {
241 $lastmonth = (int)date('d', strtotime('last day of previous month'));
242 $lastmonth_day = $lastmonth;
243 $lastmonth_month = (int)date('m', strtotime('last day of previous month'));
244 $lastmonth = $lastmonth - ($first_day * -1);
245 for ($i = $lastmonth; $i <= $lastmonth_day; $i++) {
246 $c[$i] = [
247 'day' => "{$i}/$lastmonth_month",
248 'count' => 0,
249 ];
250 }
251 $first_day = 1;
252 }
253 for ($i = $first_day; $i <= $d; $i++) {
254 $c[$i] = [
255 'day' => "{$i}/$m",
256 'count' => 0,
257 ];
258 }
259 foreach ($charts as $chart) {
260 $d = (int)date("d", strtotime($chart['time']));
261 $c[$d]['count'] = $chart['blocked'];
262 $count_attacks += $chart['attacks'];
263 $count_blocks += $chart['blocked'];
264 }
265
266 //unset keys, because the js parser sorting by key in integer
267 $result = [];
268 foreach ($c as $d) {
269 $result[] = $d;
270 }
271 return ['chart' => $result, 'count_attacks' => $count_attacks, 'count_blocks' => $count_blocks];
272 }
273
274 function wtsec_getInformation($service, $status)
275 {
276 $information = [
277 "ssl" => [
278 WTSEC_LIBRARY_Localization::lmsg("statuses.ok"),
279 WTSEC_LIBRARY_Localization::lmsg("statuses.invalid"),
280 WTSEC_LIBRARY_Localization::lmsg("statuses.expired"),
281 WTSEC_LIBRARY_Localization::lmsg("statuses.expires"),
282 "unknown_status" => WTSEC_LIBRARY_Localization::lmsg("statuses.missing"),
283 ],
284 "domain" => [
285 WTSEC_LIBRARY_Localization::lmsg("statuses.ok"),
286 WTSEC_LIBRARY_Localization::lmsg("statuses.expires"),
287 "unknown_status" => WTSEC_LIBRARY_Localization::lmsg("statuses.error"),
288 ]
289 ];
290 return isset($information[$service][$status]) ? $information[$service][$status] : $information[$service]["unknown_status"];
291 }
292
293 function wtsec_getStatusStartPauseIcon($status, $config_id, $host_id)
294 {
295 $icon = '';
296 switch ($status) {
297 case "1":
298 $icon = '<div class="v-pause ww-icon ww-icon--pause" style="border:none" data-config_id="' . $config_id . '" data-host_id="' . $host_id . '"></div>';
299 break;
300 case "0":
301 $icon = '<div class="v-pause ww-icon ww-icon--play" style="border:none" data-config_id="' . $config_id . '" data-host_id="' . $host_id . '"></div>';
302 break;
303 }
304 return $icon;
305 }
306
307 function wtsec_options_page()
308 {
309 $host = WTSEC_LIBRARY_WT::getOwnSite();
310 $result = WTSEC_LIBRARY_WT::getOptions($host['id']);
311 $options = [];
312 if (isset($result['data']['userHost']['services'])) {
313 foreach ($result['data']['userHost']['services'] as $service) {
314 $configs = $service['configs'][0];
315 $options[$service['name']] = ['config_id' => $configs['id'], 'is_active' => $configs['isActive']];
316 }
317 }
318 $options['host_id'] = $host['id'];
319 wtsec_layout("options", $options);
320 }
321
322 function wtsec_services_page()
323 {
324 wtsec_layout("services");
325 }
326
327 function wtsec_antivirus_page()
328 {
329 $host = WTSEC_LIBRARY_WT::getOwnSite();
330 $services = [];
331 if (!empty($host)) {
332 $site = WTSEC_LIBRARY_WT::getAntivirus($host['id']);
333 if (isset($site['data']['auth']['viewer']['sites']['one']['antivirus']['log'])) {
334 $site = $site['data']['auth']['viewer']['sites']['one']['antivirus'];
335 $service = "AV";
336 $_service = strtolower($service);
337 $domain = $host['hostname'];
338 $uid = $host['id'];
339 $status = wtsec_checkStatus($uid, $service);
340 $services["vc"] = [
341 "pause" => "",
342 "site_address" => $domain,
343 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
344 "signatures" => $site['stats']['infected'],
345 "changes" => $site['stats']['changed'],
346 "list" => $site["log"]['edges'],
347 "actions" => $buttons = wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL),
348 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus')
349 ];
350 }
351 }
352 wtsec_layout("antivirus", $services);
353 }
354
355 function wtsec_login_form()
356 {
357 if (wtsec_request()->method === "POST") {
358 $result = WTSEC_LIBRARY_WT::auth(wtsec_request()->key);
359 if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) {
360 WTSEC_LIBRARY_Session::setNotification("success", WTSEC_LIBRARY_Localization::lmsg('successfully_activated'));
361 $token = $result['data']['guest']['apiKeys']['auth']['token']['value'];
362 WTSEC_LIBRARY_App::login($token);
363 wtsec_app()->set("api_key", wtsec_request()->key);
364 wp_safe_redirect(wtsec_getUrl('dashboard'));
365 exit;
366 } else {
367 WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg("form.incorrect"));
368 }
369 }
370 wp_safe_redirect(wtsec_getUrl('login'));
371 }
372
373 function wtsec_cmd_ajax()
374 {
375 $service = strtoupper(wtsec_request()->service);
376 $_service = strtolower(wtsec_request()->service);
377 $uid = wtsec_request()->uid;
378 $cmd = wtsec_request()->cmd;
379 $status = wtsec_checkStatus($uid, $service);
380 if (stripos($cmd, "install") === false) {
381 wtsec_cmd($cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL);
382 wp_safe_redirect(wp_get_referer());
383 } else {
384 $redirect = wtsec_getUrl("dashboard");
385 $form_url = wp_nonce_url(admin_url('admin-post.php?cmd=' . $cmd . '&action=ajax_cmd&service=' . $service . '&uid=' . $uid), "ajax_cmd");
386 if (wtsec_filesystem_init($form_url, '', false, false)) {
387 wtsec_cmd($cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL);
388 wp_safe_redirect($redirect);
389 }
390 }
391 }
392
393 function wtsec_login()
394 {
395 wtsec_layout("login");
396 }
397
398 function wtsec_logout()
399 {
400 WTSEC_LIBRARY_App::logout();
401 }
402
403
404 function wtsec_layout($template, $arguments = [], $faq = "faq")
405 {
406 $body = WTSEC_PLUGIN_PATH . "includes/" . $template . ".php";
407 $faq = WTSEC_PLUGIN_PATH . "includes/" . $faq . ".php";
408 require_once WTSEC_PLUGIN_PATH . "includes/layout.php";
409 }
410
411
412 function wtsec_ajax_changeStatus()
413 {
414 if (wtsec_request()->method === "POST") {
415 $host_id = wtsec_request()->host_id;
416 $config_id = wtsec_request()->config_id;
417 $result = WTSEC_LIBRARY_WT::changeStatus($config_id, $host_id);
418 echo json_encode($result);
419 }
420 wp_die();
421 }
422
423 function wtsec_changeStatus()
424 {
425 if (wtsec_request()->method === "POST") {
426 $host_id = wtsec_request()->host_id;
427 $config_id = wtsec_request()->config_id;
428 WTSEC_LIBRARY_WT::changeStatus($config_id, $host_id);
429 }
430 wp_safe_redirect(wp_get_referer());
431 }
432
433 function wtsec_page($page)
434 {
435 return wtsec_pages()[$page];
436 }
437
438 function wtsec_getUrl($page)
439 {
440 return admin_url('admin.php?page=' . WTSEC_PAGE_PREFIX . $page);
441 }
442
443 function wtsec_getRoute($page)
444 {
445 return WTSEC_PAGE_PREFIX . $page;
446 }
447
448 function wtsec_pages()
449 {
450 return [
451 // "options" => [
452 // "page_title" => WTSEC_LIBRARY_Localization::lmsg('options'),
453 // "menu_title" => WTSEC_LIBRARY_Localization::lmsg('options'),
454 // "function" => "wtsec_options_page",
455 // ],
456 "services" => [
457 "page_title" => WTSEC_LIBRARY_Localization::lmsg('services'),
458 "menu_title" => WTSEC_LIBRARY_Localization::lmsg('services'),
459 "function" => "wtsec_services_page",
460 ],
461 "vc" => [
462 "page_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'),
463 "menu_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'),
464 "function" => "wtsec_antivirus_page",
465 "vc_action" => "vc-action",
466 "vc_function" => "wtsec_vc_function"
467 ],
468 ];
469 }