PluginProbe
WebTotem Security / 2.2.2
WebTotem Security v2.2.2
3.0.2 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 All 110 releases
← All changes | routes.php +1077 -418 1.12.2.2 View file →
@@ -1,418 +1,1077 @@
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 -
42 -function wtsec_index_page()
43 -{
44 - $host = WTSEC_LIBRARY_WT::getOwnSite();
45 - $services = [];
46 - if (!empty($host)) {
47 - $checks = WTSEC_LIBRARY_WT::getAllChecks($host['id']);
48 - foreach ($checks['data'] as $service => $site) {
49 - if (empty($site) || !is_array($site)) {
50 - continue;
51 - }
52 - $site = $site[0];
53 - switch ($service) {
54 - case "waServiceChecks":
55 - $services["wa"] = [
56 - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']),
57 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "wa"),
58 - "response_time" => $site['responseTime']['avg'] . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'),
59 - "availability" => ceil($site['average']['uptimePercent'] * 100) . '%',
60 - "availability_percent" => ceil($site['average']['uptimePercent'] * 100),
61 - "downtime" => ceil($site['average']['totalDown'] / 1000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('sec'),
62 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.availability')
63 - ];
64 - break;
65 - case "sslServiceChecks":
66 - $services["ssl"] = [
67 - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']),
68 - "information" => wtsec_getInformation($service, $site['status']),
69 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "ssl"),
70 - "days_left" => $site['daysLeft'],
71 - "issue_date" => date("Y-m-d H:i", $site['issued'] / 1000),
72 - "expiry_date" => date("Y-m-d H:i", $site['expires'] / 1000),
73 - "tls" => $site['tls'],
74 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.ssl')
75 - ];
76 - break;
77 - case "decServiceChecks":
78 - $services["dec"] = [
79 - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']),
80 - "registrar" => $site['registrar'],
81 - "owner" => $site['owner'],
82 - "information" => wtsec_getInformation($service, $site['status']),
83 - "email" => $site['email'],
84 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "dec"),
85 - "days_left" => $site['daysLeft'],
86 - "created" => date("Y-m-d", $site['created'] / 1000),
87 - "expiry_date" => date("Y-m-d", $site['expires'] / 1000),
88 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.domain')
89 - ];
90 - break;
91 - case "avServiceChecks":
92 - $services["av"] = [
93 - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']),
94 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "av"),
95 - "time_of_the_last_test" => date("Y-m-d H:i", $site['lastTestTime'] / 1000),
96 - "blacklists_entries" => $site['count'],
97 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.reputation')
98 - ];
99 - break;
100 - case "cmsServiceChecks":
101 - $services["cms"] = [
102 - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']),
103 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "cms"),
104 - "time_of_the_last_test" => date("Y-m-d H:i", $site['lastTestTime'] / 1000),
105 - "detected_keywords" => $site['count'],
106 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.malicious')
107 - ];
108 - break;
109 - case "dcServiceChecks":
110 - $services["dc"] = [
111 - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']),
112 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "dc"),
113 - "time_of_the_last_test" => date("Y-m-d H:i", $site['lastTestTime'] / 1000),
114 - "number" => $site['count'],
115 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.deface')
116 - ];
117 - break;
118 - case "psServiceChecks":
119 - $services["ps"] = [
120 - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']),
121 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "ps"),
122 - "ip" => $site['ip'],
123 - "time_of_the_last_test" => date("Y-m-d H:i", $site['lastTestTime'] / 1000),
124 - "number" => $site['count'],
125 - "tcp" => !empty($site['openTCPs']) ? implode(",", $site['openTCPs']) : '',
126 - "udp" => !empty($site['openUDPs']) ? implode(",", $site['openUDPs']) : '',
127 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.port')
128 - ];
129 - break;
130 - case "wafServiceChecks":
131 - $service = "WAF";
132 - $_service = strtolower($service);
133 - $domain = $host['hostname'];
134 - $uid = $host['id'];
135 - $status = wtsec_checkStatus($uid, $service);
136 - $services["waf"] = [
137 - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $uid),
138 - "site_address" => $domain,
139 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "waf"),
140 - "time_of_the_last_check" => empty($site['lastTestTime']) ? '' : date("Y-m-d H:i", $site['lastTestTime'] / 1000),
141 - "signatures" => $site['count'],
142 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.firewall'),
143 - "actions" => wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL),
144 - "chart" => json_encode((array)generateChart($site['chart']), true)
145 - ];
146 - break;
147 - case "vcServiceChecks":
148 - $service = "VC";
149 - $_service = strtolower($service);
150 - $domain = $host['hostname'];
151 - $uid = $host['id'];
152 - $status = wtsec_checkStatus($uid, $service);
153 - $services["vc"] = [
154 - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $uid),
155 - "site_address" => $domain,
156 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "vc"),
157 - "signatures" => $site['signaturesCount'],
158 - "changes" => $site['fileChangesCount'],
159 - "list" => $site["list"],
160 - "actions" => wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL),
161 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus')
162 - ];
163 - break;
164 - }
165 - }
166 - }
167 - wtsec_layout("dashboard", $services);
168 -}
169 -
170 -function generateChart($charts)
171 -{
172 - $d = date("d");
173 - $m = date("m");
174 - $c = [];
175 - $first_day = $d - 6;
176 - if ($first_day < 1) {
177 - $lastmonth = (int)date('d', strtotime('last day of previous month'));
178 - $lastmonth_day = $lastmonth;
179 - $lastmonth_month = (int)date('m', strtotime('last day of previous month'));
180 - $lastmonth = $lastmonth - ($first_day * -1);
181 - for ($i = $lastmonth; $i <= $lastmonth_day; $i++) {
182 - $c[$i] = [
183 - 'day' => "{$i}/$lastmonth_month",
184 - 'count' => 0,
185 - ];
186 - }
187 - $first_day = 1;
188 - }
189 - for ($i = $first_day; $i <= $d; $i++) {
190 - $c[$i] = [
191 - 'day' => "{$i}/$m",
192 - 'count' => 0,
193 - ];
194 - }
195 - foreach ($charts as $chart) {
196 - $d = (int)date("d", strtotime($chart['date']));
197 - $c[$d]['count'] = $chart['count'];
198 - }
199 -
200 - //unset keys, because the js parser sorting by key in integer
201 - $result = [];
202 - foreach ($c as $d) {
203 - $result[] = $d;
204 - }
205 - return $result;
206 -}
207 -
208 -function wtsec_getInformation($service, $status)
209 -{
210 - $information = [
211 - "sslServiceChecks" => [
212 - WTSEC_LIBRARY_Localization::lmsg("statuses.ok"),
213 - WTSEC_LIBRARY_Localization::lmsg("statuses.invalid"),
214 - WTSEC_LIBRARY_Localization::lmsg("statuses.expired"),
215 - WTSEC_LIBRARY_Localization::lmsg("statuses.expires"),
216 - "unknown_status" => WTSEC_LIBRARY_Localization::lmsg("statuses.missing"),
217 - ],
218 - "decServiceChecks" => [
219 - WTSEC_LIBRARY_Localization::lmsg("statuses.ok"),
220 - WTSEC_LIBRARY_Localization::lmsg("statuses.expires"),
221 - "unknown_status" => WTSEC_LIBRARY_Localization::lmsg("statuses.error"),
222 - ]
223 - ];
224 - return isset($information[$service][$status]) ? $information[$service][$status] : $information[$service]["unknown_status"];
225 -}
226 -function wtsec_getStatusStartPauseIcon($status, $config_id, $host_id)
227 -{
228 - $icon = '';
229 - switch ($status) {
230 - case "1":
231 - $icon = '<div class="v-pause ww-icon ww-icon--pause" style="border:none" data-config_id="' . $config_id . '" data-host_id="' . $host_id . '"></div>';
232 - break;
233 - case "0":
234 - $icon = '<div class="v-pause ww-icon ww-icon--play" style="border:none" data-config_id="' . $config_id . '" data-host_id="' . $host_id . '"></div>';
235 - break;
236 - }
237 - return $icon;
238 -}
239 -
240 -function wtsec_options_page()
241 -{
242 - $host = WTSEC_LIBRARY_WT::getOwnSite();
243 - $result = WTSEC_LIBRARY_WT::getOptions($host['id']);
244 - $options = [];
245 - if (isset($result['data']['userHost']['services'])) {
246 - foreach ($result['data']['userHost']['services'] as $service) {
247 - $configs = $service['configs'][0];
248 - $options[$service['name']] = ['config_id' => $configs['id'], 'is_active' => $configs['isActive']];
249 - }
250 - }
251 - $options['host_id'] = $host['id'];
252 - wtsec_layout("options", $options);
253 -}
254 -
255 -function wtsec_services_page()
256 -{
257 - wtsec_layout("services");
258 -}
259 -
260 -function wtsec_antivirus_page()
261 -{
262 - $host = WTSEC_LIBRARY_WT::getOwnSite();
263 - $site = WTSEC_LIBRARY_WT::getAntivirus($host['id']);
264 - if (isset($site['data']['vcServiceChecks'][0])) {
265 - $site = $site['data']['vcServiceChecks'][0];
266 - $service = "VC";
267 - $_service = strtolower($service);
268 - $signatures = [];
269 - $changes = [];
270 - $errors = [];
271 - $sign_count = 0;
272 - $changes_count = 0;
273 - $domain = $host['hostname'];
274 - if (!empty($site['list'])) {
275 - foreach ($site['list'] as $list) {
276 - if ($list['event'] > -1 && empty($list['matches'])) {
277 - $changes[$host['id']][] = $list;
278 - $changes_count++;
279 - } elseif ($list['event'] > -1 && !empty($list['matches'])) {
280 - $signatures[$host['id']][] = $list;
281 - $sign_count++;
282 - } else {
283 - $errors[$host['id']][] = $list;
284 - }
285 - }
286 - }
287 - $uid = $host['id'];
288 - $status = wtsec_checkStatus($uid, $service);
289 - $services["vc"] = [
290 - "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $uid),
291 - "site_address" => $domain,
292 - "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status'], "vc"),
293 - "signatures" => $sign_count,
294 - "changes" => $changes_count,
295 - "list" => $site["list"],
296 - "actions" => $buttons = wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL),
297 - "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus')
298 - ];
299 - }
300 - wtsec_layout("antivirus", $services);
301 -}
302 -
303 -function wtsec_login_form()
304 -{
305 - if (wtsec_request()->method === "POST") {
306 - $result = WTSEC_LIBRARY_WT::auth(wtsec_request()->key);
307 - if (isset($result['data']['apiServiceMutation']['auth']['value'])) {
308 - WTSEC_LIBRARY_Session::setNotification("success", WTSEC_LIBRARY_Localization::lmsg('successfully_activated'));
309 - $token = $result['data']['apiServiceMutation']['auth']['value'];
310 - WTSEC_LIBRARY_App::login($token);
311 - wtsec_app()->set("api_key", wtsec_request()->key);
312 - wp_safe_redirect(wtsec_getUrl('dashboard'));
313 - exit;
314 - } else {
315 - WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg("form.incorrect"));
316 - }
317 - }
318 - wp_safe_redirect(wtsec_getUrl('login'));
319 -}
320 -
321 -function wtsec_cmd_ajax()
322 -{
323 - $service = strtoupper(wtsec_request()->service);
324 - $_service = strtolower(wtsec_request()->service);
325 - $uid = wtsec_request()->uid;
326 - $cmd = wtsec_request()->cmd;
327 - $status = wtsec_checkStatus($uid, $service);
328 - global $wp_filesystem;
329 - if (mb_stripos($cmd, "install") === false) {
330 - wtsec_cmd($wp_filesystem, $cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL);
331 - wp_safe_redirect(wp_get_referer());
332 - } else {
333 - $redirect = wtsec_getUrl("dashboard");
334 - $form_url = wp_nonce_url(admin_url('admin-post.php?cmd=' . $cmd . '&action=ajax_cmd&service=' . $service . '&uid=' . $uid), "ajax_cmd");
335 - if (wtsec_filesystem_init($form_url, '', false, false)) {
336 - wtsec_cmd($wp_filesystem, $cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL);
337 - wp_safe_redirect($redirect);
338 - }
339 - }
340 -}
341 -
342 -function wtsec_login()
343 -{
344 - wtsec_layout("login");
345 -}
346 -
347 -function wtsec_logout()
348 -{
349 - WTSEC_LIBRARY_App::logout();
350 -}
351 -
352 -
353 -function wtsec_layout($template, $arguments = [], $faq = "faq")
354 -{
355 - $body = WTSEC_PLUGIN_PATH . "includes/" . $template . ".php";
356 - $faq = WTSEC_PLUGIN_PATH . "includes/" . $faq . ".php";
357 - require_once WTSEC_PLUGIN_PATH . "includes/layout.php";
358 -}
359 -
360 -
361 -function wtsec_ajax_changeStatus()
362 -{
363 - if (wtsec_request()->method === "POST") {
364 - $host_id = wtsec_request()->host_id;
365 - $config_id = wtsec_request()->config_id;
366 - $result = WTSEC_LIBRARY_WT::changeStatus($config_id, $host_id);
367 - echo json_encode($result);
368 - }
369 - wp_die();
370 -}
371 -
372 -function wtsec_changeStatus()
373 -{
374 - if (wtsec_request()->method === "POST") {
375 - $host_id = wtsec_request()->host_id;
376 - $config_id = wtsec_request()->config_id;
377 - WTSEC_LIBRARY_WT::changeStatus($config_id, $host_id);
378 - }
379 - wp_safe_redirect(wp_get_referer());
380 -}
381 -
382 -function wtsec_page($page)
383 -{
384 - return wtsec_pages()[$page];
385 -}
386 -
387 -function wtsec_getUrl($page)
388 -{
389 - return admin_url('admin.php?page=' . WTSEC_PAGE_PREFIX . $page);
390 -}
391 -
392 -function wtsec_getRoute($page)
393 -{
394 - return WTSEC_PAGE_PREFIX . $page;
395 -}
396 -
397 -function wtsec_pages()
398 -{
399 - return [
400 - "options" => [
401 - "page_title" => WTSEC_LIBRARY_Localization::lmsg('options'),
402 - "menu_title" => WTSEC_LIBRARY_Localization::lmsg('options'),
403 - "function" => "wtsec_options_page",
404 - ],
405 - "services" => [
406 - "page_title" => WTSEC_LIBRARY_Localization::lmsg('services'),
407 - "menu_title" => WTSEC_LIBRARY_Localization::lmsg('services'),
408 - "function" => "wtsec_services_page",
409 - ],
410 - "vc" => [
411 - "page_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'),
412 - "menu_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'),
413 - "function" => "wtsec_antivirus_page",
414 - "vc_action" => "vc-action",
415 - "vc_function" => "wtsec_vc_function"
416 - ],
417 - ];
418 -}
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('admin_post_login_form', 'wtsec_login_form');
7 +add_action('wp_ajax_cmd', 'wtsec_cmd_ajax');
8 +add_action('admin_post_ajax_cmd', 'wtsec_cmd_ajax');
9 +add_action('wp_ajax_ajax_firewall', 'wtsec_ajax_firewall');
10 +add_action('wp_ajax_ajax_antivirus', 'wtsec_ajax_antivirus');
11 +add_action('wp_ajax_chart_filter', 'wtsec_chart_filter');
12 +add_action('wp_ajax_map_filter', 'wtsec_map_filter');
13 +add_action('wp_ajax_color_scheme_toggle', 'wtsec_color_scheme');
14 +
15 +
16 +function wtsec_add_menu_link()
17 +{
18 + add_menu_page(
19 + WTSEC_PAGE_TITLE,
20 + WTSEC_MENU_TITLE,
21 + 'manage_options',
22 + wtsec_getRoute('dashboard'),
23 + 'wtsec_index_page',
24 + '',
25 + '1'
26 + );
27 + $parent = wtsec_getRoute('dashboard');
28 + if (WTSEC_LIBRARY_App::authorized()) {
29 + $capability = 'manage_options';
30 + foreach (wtsec_pages() as $page => $arguments) {
31 + add_submenu_page($parent, $arguments['page_title'], $arguments['menu_title'], $capability, wtsec_getRoute($page), $arguments['function']);
32 + }
33 + add_submenu_page(null, WTSEC_LIBRARY_Localization::lmsg('sign_in'), WTSEC_LIBRARY_Localization::lmsg('sign_in'), 'manage_options', wtsec_getRoute('login'), 'wtsec_login');
34 + add_submenu_page($parent, WTSEC_LIBRARY_Localization::lmsg('logout'), WTSEC_LIBRARY_Localization::lmsg('logout'), 'manage_options', wtsec_getRoute('logout'), 'wtsec_logout');
35 + } else {
36 + $capability = 'manage_options';
37 + foreach (wtsec_pages() as $page => $arguments) {
38 + add_submenu_page(null, $arguments['page_title'], $arguments['menu_title'], $capability, wtsec_getRoute($page), function () {
39 + wp_safe_redirect(wtsec_getUrl('login'));
40 + });
41 + }
42 + add_submenu_page($parent, WTSEC_LIBRARY_Localization::lmsg('sign_in'), WTSEC_LIBRARY_Localization::lmsg('sign_in'), 'manage_options', wtsec_getRoute('login'), 'wtsec_login');
43 + add_submenu_page(null, WTSEC_LIBRARY_Localization::lmsg('logout'), WTSEC_LIBRARY_Localization::lmsg('logout'), 'manage_options', wtsec_getRoute('logout'), 'wtsec_logout');
44 + }
45 +}
46 +
47 +function dd($vl)
48 +{
49 + echo '<pre>';
50 + print_r($vl);
51 + echo '</pre>';
52 + die();
53 +}
54 +
55 +function myGrading($score)
56 +{
57 + if ($score < 0 || $score > 100) return ['grade' => '','color' => ''];
58 + $scores = [100 => 'A+', 90 => 'A', 80 => 'A-', 70 => 'B+', 60 => 'B', 50 => 'B-', 35 => 'C+', 20 => 'C', 0 => 'C-' ];
59 + foreach ($scores as $key => $value){
60 + if($score >= $key){
61 + $grade = $value;
62 + break;
63 + }
64 + }
65 +
66 + $color = ($score >= 80) ? 'green' : ($score >= 50) ? 'orange' : 'red';
67 +
68 + return ['grade' => $grade,'color' => $color];
69 +}
70 +
71 +
72 +function convertTimeToReadable($date)
73 +{
74 + $lang = get_locale();
75 + //enable russian language
76 + if ($lang === "ru_RU") {
77 + $lang .= ".UTF-8";
78 + setlocale(LC_ALL, $lang);
79 + }
80 + if(strpos($date, ".") !== false){
81 + $date = substr($date, 0, strpos($date, "."));
82 + }
83 + return strftime("%B %e, %Y / %R", strtotime($date." UTC"));
84 +}
85 +
86 +
87 +function convertToCurrentTime($date)
88 +{
89 + $lang = get_locale();
90 + //enable russian language
91 + if ($lang === "ru_RU") {
92 + $lang .= ".UTF-8";
93 + setlocale(LC_ALL, $lang);
94 + }
95 + if(strpos($date, ".") !== false){
96 + $date = substr($date, 0, strpos($date, "."));
97 + }
98 + $date .= " UTC";
99 + $current_time = strtotime($date);
100 + return ['date' => date("Y-m-d", $current_time),'time' => date("H:i:s",$current_time)];
101 +}
102 +
103 +function wtsec_index_page()
104 +{
105 + $host = WTSEC_LIBRARY_WT::getOwnSite();
106 +
107 + $services = [];
108 + if (!empty($host)) {
109 + $services = [
110 + "settings" => [
111 + "token" => WTSEC_LIBRARY_App::getToken(),
112 + "site_id" => $host['id'],
113 + ],
114 + "score" => [
115 + "total_score" => 0,
116 + "tested_on" => "",
117 + "server_ip" => "",
118 + "location" => "",
119 + "description" => wtsec_locale("score.description"),
120 + "information" => "",
121 + "grade" => "",
122 + ],
123 + ];
124 +
125 + $score = json_decode(WTSEC_LIBRARY_WT::getScore(), true);
126 + if (!empty($score)) {
127 + $total_score = round($score['totalScore']);
128 + $my_grading = myGrading($total_score);
129 + $services["score"] = [
130 + "total_score" => $total_score."%",
131 + "tested_on" => convertTimeToReadable($score['date']),
132 + "server_ip" => $score['ip'],
133 + "location" => $score['country'],
134 + "description" => wtsec_locale("score.description"),
135 + "information" => wtsec_locale("score.higher_than_percent", ['percent' => $score['ishigherthan']]),
136 + "grade" => $my_grading['grade'],
137 + "color" => $my_grading['color'],
138 + ];
139 + }
140 +
141 + $checks = WTSEC_LIBRARY_WT::getAllChecks($host['id']);
142 + foreach ($checks as $service => $site) {
143 + if (empty($site) || !is_array($site)) {
144 + continue;
145 + }
146 + switch ($service) {
147 + case "availability":
148 + $services["wa"] = [
149 +// "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']),
150 + "pause" => "",
151 + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
152 + "response_time" => ceil($site['responseTime'] / 1000000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'),
153 + "availability" => $site['percent'] . '%',
154 + "availability_percent" => $site['percent'],
155 + "last_test" => convertTimeToReadable($site['lastTest']['time']),
156 + "downtime" => ceil($site['downTime'] / 1000000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'),
157 + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.availability')
158 + ];
159 + break;
160 + case "ssl":
161 + if ((int)$site['expiryDate'] === 0) {
162 + $days_left = 0;
163 + } else {
164 + $earlier = new DateTime();
165 + $later = new DateTime($site['expiryDate']);
166 + $days_left = $later->diff($earlier)->format("%a");
167 + }
168 + $services["ssl"] = [
169 + "pause" => "",
170 + "information" => wtsec_getInformation($service, $site['status']),
171 + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
172 + "days_left" => $days_left,
173 + "issue_date" => convertTimeToReadable($site['issueDate']),
174 + "expiry_date" => convertTimeToReadable($site['expiryDate']),
175 + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.ssl'),
176 + "solve_it" => in_array($site['status'],['clean','pending']) ? '' : wtsec_locale('solve_it'),
177 + ];
178 + break;
179 + case "domain":
180 + if ((int)$site['expiredDate'] === 0) {
181 + $days_left = 0;
182 + } else {
183 + $earlier = new DateTime();
184 + $later = new DateTime($site['expiredDate']);
185 + $days_left = $later->diff($earlier)->format("%a");
186 + }
187 +
188 + $services["dec"] = [
189 + "pause" => "",
190 + "registrar" => $site['registrar'],
191 + "owner" => $site['owner'],
192 + "information" => wtsec_getInformation($service, $site['status']),
193 + "email" => $site['email'],
194 + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
195 + "days_left" => $days_left,
196 + "created" => convertTimeToReadable($site['createdDate']),
197 + "expiry_date" => convertTimeToReadable($site['expiredDate']),
198 + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.domain')
199 + ];
200 + break;
201 + case "reputation":
202 + $count = 0;
203 + if ($site['status'] != "clean") {
204 + foreach ($site['virusList'] as &$list) {
205 + if (!empty($list['virus']['type'])) {
206 + $count++;
207 + }
208 + }
209 + }
210 + $services["av"] = [
211 + "pause" => "",
212 + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
213 + "time_of_the_last_test" => convertTimeToReadable($site['lastTest']['time']),
214 + "blacklists_entries" => $count,
215 + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.reputation'),
216 + "reputation" => $site['status'] === "infected" ? wtsec_locale('bad_reputation') : wtsec_locale('good_reputation'),
217 + ];
218 + break;
219 + case "maliciousScript":
220 + $services["cms"] = [
221 + "pause" => "",
222 + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
223 + "time_of_the_last_test" => $site['lastTest']['time'],
224 + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.malicious')
225 + ];
226 + break;
227 + case "deface":
228 + $services["dc"] = [
229 + "pause" => "",
230 + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
231 + "time_of_the_last_test" => convertTimeToReadable($site['lastTest']['time']),
232 + "number" => $site['count'],
233 + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.deface')
234 + ];
235 + break;
236 + case "ports":
237 + $services["ps"] = [
238 + "pause" => "",
239 + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
240 + "ip" => $site['ip'],
241 + "last_test" => convertTimeToReadable($site['lastTest']['time']),
242 + "number" => count($site['tcp']),
243 + "tcp" => !empty($site['tcp']) ? implode(",", $site['tcp']) : '',
244 + "udp" => "",
245 + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.port')
246 + ];
247 + break;
248 + case "firewall":
249 + $service = "WAF";
250 + $_service = strtolower($service);
251 + $domain = $host['hostname'];
252 + $uid = $host['id'];
253 +
254 + $chart = generateChart($site['chart'], 30);
255 +// $status = wtsec_checkStatus($uid, $service);
256 +
257 + $data = WTSEC_LIBRARY_WT::getFirewall($host['id']);
258 + $data = $data['data']['auth']['viewer']['sites']['one']['firewall'];
259 +
260 + $countryAttacks = getCountryAttacks($data['map'], $chart['count_attacks']);
261 + $edges = $data['logs']['edges'];
262 +
263 + $services["waf"] = [
264 + "pause" => "",
265 + "site_address" => $domain,
266 + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
267 + "_status" => $site['status'],
268 + "installed_status" => in_array($site['status'], ["not_installed", "error", "down", "not_supported", "not_registered"]) ? false : true,
269 + "time_of_the_last_check" => convertTimeToReadable($site['lastTest']['time']),
270 + "attacks" => $chart['count_attacks'],
271 + "blocking" => $chart['count_blocks'],
272 + "non-blocking" => $chart['count_attacks'] - $chart['count_blocks'],
273 + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.firewall'),
274 + "actions" => wtsec_generateButtons($uid, $_service, $service, $site['status'], WTSEC_SITE_URL),
275 + "chart" => json_encode($chart['chart'], true),
276 + "edges" => $edges,
277 + "countryAttacks" => $countryAttacks,
278 + ];
279 + break;
280 + case "antivirus":
281 + $service = "AV";
282 + $_service = strtolower($service);
283 + $domain = $host['hostname'];
284 + $uid = $host['id'];
285 +// $status = wtsec_checkStatus($uid, $service);
286 + $services["vc"] = [
287 + "pause" => "",
288 + "site_address" => $domain,
289 + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
290 + "installed_status" => in_array($site['status'], ["not_installed", "error", "down", "not_supported", "not_registered"]) ? false : true,
291 + "_status" => $site['status'],
292 + "signatures" => (int)$site['stats']['infected'],
293 + "changes" => (int)$site['stats']['changed'],
294 + "scanned" => (int)$site['stats']['scaned'],
295 + "deleted" => (int)$site['stats']['deleted'],
296 + "list" => $site['stats']["infected"],
297 + "actions" => wtsec_generateButtons($uid, $_service, $service, $site['status'], WTSEC_SITE_URL),
298 + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus')
299 + ];
300 + break;
301 + }
302 + }
303 +
304 + //check AM, if not installed , run install
305 + $process = "installing";
306 + $check_am_file = wtsec_checkInstalledFile("am");
307 + $am_installed = $check_am_file["status"];
308 + $am_installed_status = wtsec_app()->get('am_installed');
309 +
310 + if (!$am_installed || !$am_installed_status) {
311 + $am_is_installed = wtsec_cmd("am_install", "AM", "am", $host['id'], [], WTSEC_SITE_URL);
312 + if (!$am_is_installed) {
313 + $process = "failed";
314 + wtsec_app()->set('am_installed', false);
315 + } else {
316 + wtsec_app()->set('am_installed', true);
317 + }
318 + } elseif ($services["vc"]["_status"] === "not_installed" || $services["waf"]["_status"] === "not_installed") {
319 + $process = "installing";
320 + } else {
321 + $process = "installed";
322 + }
323 +
324 + $services["am"] = [
325 + "status" => WTSEC_LIBRARY_WT::getStatusIcon($am_installed ? "working" : "not_installed"),
326 + "actions" => wtsec_generateButtons($host['id'], "am", "AM", ["active" => $check_am_file], WTSEC_SITE_URL),
327 + "process_status" => $process,
328 + "installed" => $am_installed,
329 + ];
330 + }
331 +
332 + wtsec_layout("dashboard", $services);
333 +}
334 +
335 +function getCountryAttacks($map, $countAttacks){
336 +
337 + if($map){
338 + $attackKey = array_search(max(array_column($map, 'attacks')), array_column($map, 'attacks'));
339 + $map[$attackKey]['percent'] = ($countAttacks) ? round($map[$attackKey]['attacks'] / $countAttacks * 100) : 0;
340 + $map[$attackKey]['country'] = wtsec_getCountryName($map[$attackKey]['country']);
341 + return $map[$attackKey];
342 + }
343 +
344 + return ['percent' => 0, 'country' => false];
345 +
346 +}
347 +function getAttacksMap($map){
348 + $attacks = [];
349 + $countries = [];
350 + foreach ($map as $value){
351 + $attacks[] = $value['attacks'];
352 + $countries[] = wtsec_getCountryName($value['country']);
353 + }
354 + return ['attacks' => $attacks, 'countries' => $countries];
355 +}
356 +
357 +
358 +function generateChart($charts, $days = 7)
359 +{
360 +
361 + if(is_array($days)) {
362 + $beginDate = new DateTime( $days['begin'] );
363 + $endDate = new DateTime( $days['end'] );
364 + $dateDiff = strtotime($days['end'] - strtotime($days['begin']));
365 + $days = floor($dateDiff / (60 * 60 * 24));
366 + }
367 +
368 + if($days <= 1){
369 + $begin = new DateTime( date('Y-m-d 00:00:00') );
370 + $end = new DateTime( date('Y-m-d 23:59:59') );
371 + $step = 'hour';
372 + } elseif($days <= 31){
373 + $begin = new DateTime( date('Y-m-d', strtotime('-'.($days - 1).' day')) );
374 + $end = new DateTime( date('Y-m-d') );
375 + $step = 'day';
376 + } else {
377 + $begin = new DateTime( date('Y-m-01', strtotime('- 11 month')) );
378 + $end = new DateTime( date('Y-m-01', time()) );
379 + $step = 'month';
380 + }
381 +
382 +
383 + $count_attacks = 0;
384 + $count_blocks = 0;
385 + $c = [];
386 +
387 + for($i = $begin; $i <= $end; $i->modify('+1 '.$step)){
388 +
389 + $c[$i->format('U')] = [
390 + 'date' => ($days <= 1) ? $i->format("Y-m-d H:00:00") : $i->format("Y-m-d"),
391 + 'count' => 0,
392 + 'attacks' => 0,
393 + 'blocked' => 0,
394 + ];
395 + }
396 +
397 + foreach ($charts as $chart) {
398 + $d = strtotime($chart['time']);
399 + $c[$d]['count'] = $chart['blocked'];
400 + $c[$d]['attacks'] = $chart['attacks'];
401 + $c[$d]['blocked'] = $chart['blocked'];
402 + $count_attacks += $chart['attacks'];
403 + $count_blocks += $chart['blocked'];
404 + }
405 +
406 +
407 + //unset keys, because the js parser sorting by key in integer
408 + $result = [];
409 + foreach ($c as $d) {
410 + $result[] = $d;
411 + }
412 +
413 + return ['chart' => $result, 'count_attacks' => $count_attacks, 'count_blocks' => $count_blocks];
414 +}
415 +
416 +function wtsec_getInformation($service, $status)
417 +{
418 + $information = [
419 + "ssl" => [
420 + WTSEC_LIBRARY_Localization::lmsg("statuses.ok"),
421 + WTSEC_LIBRARY_Localization::lmsg("statuses.invalid"),
422 + WTSEC_LIBRARY_Localization::lmsg("statuses.expired"),
423 + WTSEC_LIBRARY_Localization::lmsg("statuses.expires"),
424 + "unknown_status" => WTSEC_LIBRARY_Localization::lmsg("statuses.missing"),
425 + ],
426 + "domain" => [
427 + WTSEC_LIBRARY_Localization::lmsg("statuses.ok"),
428 + WTSEC_LIBRARY_Localization::lmsg("statuses.expires"),
429 + "unknown_status" => WTSEC_LIBRARY_Localization::lmsg("statuses.error"),
430 + ]
431 + ];
432 + return isset($information[$service][$status]) ? $information[$service][$status] : $information[$service]["unknown_status"];
433 +}
434 +
435 +function wtsec_getStatusStartPauseIcon($status, $config_id, $host_id)
436 +{
437 + $icon = '';
438 + switch ($status) {
439 + case "1":
440 + $icon = '<div class="v-pause ww-icon ww-icon--pause" style="border:none" data-config_id="' . $config_id . '" data-host_id="' . $host_id . '"></div>';
441 + break;
442 + case "0":
443 + $icon = '<div class="v-pause ww-icon ww-icon--play" style="border:none" data-config_id="' . $config_id . '" data-host_id="' . $host_id . '"></div>';
444 + break;
445 + }
446 + return $icon;
447 +}
448 +
449 +function wtsec_options_page()
450 +{
451 + $host = WTSEC_LIBRARY_WT::getOwnSite();
452 + $result = WTSEC_LIBRARY_WT::getOptions($host['id']);
453 + $options = [];
454 + if (isset($result['data']['userHost']['services'])) {
455 + foreach ($result['data']['userHost']['services'] as $service) {
456 + $configs = $service['configs'][0];
457 + $options[$service['name']] = ['config_id' => $configs['id'], 'is_active' => $configs['isActive']];
458 + }
459 + }
460 + $options['host_id'] = $host['id'];
461 + wtsec_layout("options", $options);
462 +}
463 +
464 +function wtsec_services_page()
465 +{
466 + wtsec_layout("services");
467 +}
468 +
469 +function wtsec_antivirus_page()
470 +{
471 + $host = WTSEC_LIBRARY_WT::getOwnSite();
472 + $services = [];
473 + if (!empty($host)) {
474 + $site = WTSEC_LIBRARY_WT::getAntivirus($host['id']);
475 + if (isset($site['data']['auth']['viewer']['sites']['one']['antivirus']['log'])) {
476 + $site = $site['data']['auth']['viewer']['sites']['one']['antivirus'];
477 +
478 + $_SESSION['antivirus_endCursor'] = $site['log']['pageInfo']['endCursor'];
479 + $_SESSION['antivirus_hasNextPage'] = $site['log']['pageInfo']['hasNextPage'];
480 +
481 + $service = "AV";
482 + $_service = strtolower($service);
483 + $domain = $host['hostname'];
484 + $uid = $host['id'];
485 + $status = wtsec_checkStatus($uid, $service);
486 + $services["vc"] = [
487 + "pause" => "",
488 + "site_address" => $domain,
489 + "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
490 + "signatures" => (int)$site['stats']['infected'],
491 + "changes" => (int)$site['stats']['changed'],
492 + "scanned" => (int)$site['stats']['scaned'],
493 + "deleted" => (int)$site['stats']['deleted'],
494 + "list" => $site["log"]['edges'],
495 + "actions" => $buttons = wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL),
496 + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus')
497 + ];
498 + }
499 + }
500 + wtsec_layout("antivirus", $services);
501 +}
502 +
503 +
504 +function wtsec_firewall_page()
505 +{
506 + $host = WTSEC_LIBRARY_WT::getOwnSite();
507 + $services = [];
508 +
509 + if (!empty($host)) {
510 + $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10,null,30);
511 + $chart = WTSEC_LIBRARY_WT::getFirewallChart($host['id'], 30);
512 + if (isset($site['data']['auth']['viewer']['sites']['one']['firewall']['logs'])) {
513 + $logs = $site['data']['auth']['viewer']['sites']['one']['firewall']['logs'];
514 + $firewall = $site['data']['auth']['viewer']['sites']['one']['firewall'];
515 + $edges = $logs['edges'];
516 +
517 + $chart = $chart['data']['auth']['viewer']['sites']['one']['firewall']['chart'];
518 +
519 + $chart = generateChart($chart, 30);
520 +
521 + $domain = $host['hostname'];
522 +
523 + $_SESSION['firewall_endCursor'] = $logs['pageInfo']['endCursor'];
524 + $_SESSION['firewall_hasNextPage'] = $logs['pageInfo']['hasNextPage'];
525 +
526 + $countryAttacks = getCountryAttacks($firewall['map'], $chart['count_attacks']);
527 + $attacksMap = getAttacksMap($firewall['map']);
528 +
529 + $services["waf"] = [
530 + "pause" => "",
531 + "site_address" => $domain,
532 + "status" => WTSEC_LIBRARY_WT::getStatusIcon($firewall['status']),
533 + "_status" => $firewall['status'],
534 + "installed_status" => in_array($firewall['status'], ["not_installed", "error", "down", "not_supported", "not_registered"]) ? false : true,
535 + "time_of_the_last_check" => convertTimeToReadable($firewall['lastTest']['time']),
536 + "attacks" => $chart['count_attacks'],
537 + "blocking" => $chart['count_blocks'],
538 + "non-blocking" => $chart['count_attacks'] - $chart['count_blocks'],
539 + "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.firewall'),
540 + "chart" => json_encode($chart['chart'], true),
541 + "edges" => $edges,
542 + "countryAttacks" => $countryAttacks,
543 + "attacksMap" => $attacksMap,
544 + ];
545 + }
546 + }
547 + wtsec_layout("firewall", $services);
548 +}
549 +
550 +/**
551 + * ajax load firewall
552 + */
553 +function wtsec_ajax_firewall()
554 +{
555 + $host = WTSEC_LIBRARY_WT::getOwnSite();
556 + $services = [];
557 +
558 + $post = ($_POST) ? wtsec_clean($_POST):[];
559 + $days = ($post['period']) ? wtsec_period_as_time($post['period']) : 7;
560 +
561 + if (!empty($host)) {
562 +
563 + if(!$_SESSION['firewall_endCursor'] || $post['filter'] == 'period_filter') $_SESSION['firewall_endCursor'] = null;
564 +
565 + $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10, $_SESSION['firewall_endCursor'], $days);
566 + if (isset($site['data']['auth']['viewer']['sites']['one']['firewall']['logs'])) {
567 + $logs = $site['data']['auth']['viewer']['sites']['one']['firewall']['logs'];
568 +
569 + $services["waf"]['edges'] = $logs['edges'];
570 +
571 + $_SESSION['firewall_endCursor'] = $logs['pageInfo']['endCursor'];
572 + $_SESSION['firewall_hasNextPage'] = $logs['pageInfo']['hasNextPage'];
573 + }
574 +
575 + }
576 +
577 + wtsec_layout_part("_firewall_lazy", $services);
578 + wp_die();
579 +}
580 +
581 +/**
582 + * ajax load antivirus
583 + */
584 +function wtsec_ajax_antivirus()
585 +{
586 + $host = WTSEC_LIBRARY_WT::getOwnSite();
587 + $services = [];
588 +
589 + $post = ($_POST) ? wtsec_clean($_POST):[];
590 + $days = ($post['period']) ? wtsec_period_as_time($post['period']) : 7;
591 +
592 + if (!empty($host)) {
593 +
594 + if(!$_SESSION['antivirus_endCursor'] || $post['filter'] == 'period_filter') $_SESSION['antivirus_endCursor'] = null;
595 + if($post['event'] || $_SESSION['antivirus_event']){
596 + if($post['event']){
597 + $_SESSION['antivirus_event'] = $post['event'];
598 + }
599 + $site = WTSEC_LIBRARY_WT::getAntivirus($host['id'],10, $_SESSION['antivirus_endCursor'],$days, $_SESSION['antivirus_event']);
600 + } else {
601 + $site = WTSEC_LIBRARY_WT::getAntivirus($host['id'],10, $_SESSION['antivirus_endCursor'],$days);
602 + }
603 +
604 + if (isset($site['data']['auth']['viewer']['sites']['one']['antivirus']['log'])) {
605 + $logs = $site['data']['auth']['viewer']['sites']['one']['antivirus']['log'];
606 +
607 + $services["vc"]['list'] = $logs['edges'];
608 +
609 + $_SESSION['antivirus_endCursor'] = $logs['pageInfo']['endCursor'];
610 + $_SESSION['antivirus_hasNextPage'] = $logs['pageInfo']['hasNextPage'];
611 +
612 + }
613 + }
614 + wtsec_layout_part("_antivirus_lazy", $services);
615 +
616 + wp_die();
617 +}
618 +
619 +/**
620 + * ajax load chart
621 + */
622 +function wtsec_chart_filter()
623 +{
624 + $days = (int)$_POST['days'];
625 + $days = $days ?: 7;
626 +
627 + $host = WTSEC_LIBRARY_WT::getOwnSite();
628 + $chart = WTSEC_LIBRARY_WT::getFirewallChart($host['id'], $days);
629 + $chart = $chart['data']['auth']['viewer']['sites']['one']['firewall']['chart'];
630 + $chart = generateChart($chart, $days);
631 + $res['chart'] = json_encode($chart['chart'], true);
632 + $res['days'] = $days;
633 +
634 + wtsec_layout_part("_chart_ajax", $res);
635 +
636 + wp_die();
637 +}
638 +
639 +/**
640 + * ajax load attack map
641 + */
642 +function wtsec_map_filter()
643 +{
644 + $days = (int)$_POST['days'];
645 + $days = $days ?: 7;
646 +
647 + $host = WTSEC_LIBRARY_WT::getOwnSite();
648 + $site = WTSEC_LIBRARY_WT::getFirewall($host['id'],10,null,$days);
649 + $firewall = $site['data']['auth']['viewer']['sites']['one']['firewall'];
650 +
651 + $attacksMap = getAttacksMap($firewall['map']);
652 + $res["waf"]['attacksMap'] = $attacksMap;
653 + $res['days'] = $days;
654 +
655 + wtsec_layout_part("_map_view", $res);
656 +
657 + wp_die();
658 +}
659 +
660 +function wtsec_color_scheme()
661 +{
662 + $checked = (bool)$_POST['checked'];
663 +
664 + if($checked){
665 + WTSEC_LIBRARY_App::_set('color_scheme', 'dark');
666 + echo 'dark';
667 + } else {
668 + WTSEC_LIBRARY_App::_set('color_scheme', 'light');
669 + echo 'light';
670 + }
671 +
672 + wp_die();
673 +}
674 +
675 +function wtsec_login_form()
676 +{
677 + if (wtsec_request()->method === "POST") {
678 + $result = WTSEC_LIBRARY_WT::auth(wtsec_request()->key);
679 + if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) {
680 + WTSEC_LIBRARY_Session::setNotification("success", WTSEC_LIBRARY_Localization::lmsg('successfully_activated'));
681 + $token = $result['data']['guest']['apiKeys']['auth']['token']['value'];
682 + WTSEC_LIBRARY_App::login($token);
683 + wtsec_app()->set("api_key", wtsec_request()->key);
684 + wp_safe_redirect(wtsec_getUrl('dashboard'));
685 + exit;
686 + } else {
687 + WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg("form.incorrect"));
688 + }
689 + }
690 + wp_safe_redirect(wtsec_getUrl('login'));
691 +}
692 +
693 +function wtsec_cmd_ajax()
694 +{
695 + $service = strtoupper(wtsec_request()->service);
696 + $_service = strtolower(wtsec_request()->service);
697 + $uid = wtsec_request()->uid;
698 + $cmd = wtsec_request()->cmd;
699 + $status = wtsec_checkStatus($uid, $service);
700 +
701 + if (stripos($cmd, "install") === false) {
702 + wtsec_cmd($cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL);
703 + wp_safe_redirect(wp_get_referer());
704 + } else {
705 + $redirect = wtsec_getUrl("dashboard");
706 + $form_url = wp_nonce_url(admin_url('admin-post.php?cmd=' . $cmd . '&action=ajax_cmd&service=' . $service . '&uid=' . $uid), "ajax_cmd");
707 + if (wtsec_filesystem_init($form_url, '', false, false)) {
708 + wtsec_cmd($cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL);
709 + wp_safe_redirect($redirect);
710 + }
711 + }
712 +}
713 +
714 +function wtsec_login()
715 +{
716 + require_once WTSEC_PLUGIN_PATH . "includes/login.php";
717 +}
718 +
719 +function wtsec_logout()
720 +{
721 + WTSEC_LIBRARY_App::logout();
722 +}
723 +
724 +function wtsec_layout_part($template, $arguments = [])
725 +{
726 + wp_register_script( 'ajaxHandle', get_template_directory() . 'PATH TO YOUR JS FILE', array(), false, true );
727 + wp_enqueue_script( 'ajaxHandle' );
728 + wp_localize_script( 'ajaxHandle', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
729 +
730 + require WTSEC_PLUGIN_PATH . "includes/components/" . $template . ".php";
731 +
732 +}
733 +
734 +function wtsec_layout($template, $arguments = [], $faq = "faq")
735 +{
736 + $body = WTSEC_PLUGIN_PATH . "includes/" . $template . ".php";
737 + $faq = WTSEC_PLUGIN_PATH . "includes/" . $faq . ".php";
738 + require_once WTSEC_PLUGIN_PATH . "includes/layout.php";
739 +}
740 +
741 +
742 +function wtsec_ajax_changeStatus()
743 +{
744 + if (wtsec_request()->method === "POST") {
745 + $host_id = wtsec_request()->host_id;
746 + $config_id = wtsec_request()->config_id;
747 + $result = WTSEC_LIBRARY_WT::changeStatus($config_id, $host_id);
748 + echo json_encode($result);
749 + }
750 + wp_die();
751 +}
752 +
753 +function wtsec_changeStatus()
754 +{
755 + if (wtsec_request()->method === "POST") {
756 + $host_id = wtsec_request()->host_id;
757 + $config_id = wtsec_request()->config_id;
758 + WTSEC_LIBRARY_WT::changeStatus($config_id, $host_id);
759 + }
760 + wp_safe_redirect(wp_get_referer());
761 +}
762 +
763 +function wtsec_page($page)
764 +{
765 + return wtsec_pages()[$page];
766 +}
767 +
768 +function wtsec_clean($data)
769 +{
770 + if (is_array($data)) {
771 + foreach ($data as $key => $value) {
772 + unset($data[$key]);
773 + $data[wtsec_clean($key)] = wtsec_clean($value);
774 + }
775 + } else {
776 + $data = htmlspecialchars(strip_tags($data), ENT_COMPAT, 'UTF-8');
777 + }
778 + return $data;
779 +}
780 +
781 +function wtsec_period_as_time($period){
782 + $end = $period[1] ?: $period[0];
783 + $array['begin'] = strtotime(date('d-m-Y 00:00:00',strtotime($period[0])));
784 + $array['end'] = strtotime(date('d-m-Y 23:59:59',strtotime($end)));
785 +
786 + return $array;
787 +}
788 +
789 +function wtsec_getUrl($page)
790 +{
791 + return admin_url('admin.php?page=' . WTSEC_PAGE_PREFIX . $page);
792 +}
793 +
794 +function wtsec_getRoute($page)
795 +{
796 + return WTSEC_PAGE_PREFIX . $page;
797 +}
798 +
799 +function wtsec_pages()
800 +{
801 + return [
802 +// "options" => [
803 +// "page_title" => WTSEC_LIBRARY_Localization::lmsg('options'),
804 +// "menu_title" => WTSEC_LIBRARY_Localization::lmsg('options'),
805 +// "function" => "wtsec_options_page",
806 +// ],
807 + "services" => [
808 + "page_title" => WTSEC_LIBRARY_Localization::lmsg('services'),
809 + "menu_title" => WTSEC_LIBRARY_Localization::lmsg('services'),
810 + "function" => "wtsec_services_page",
811 + ],
812 + "vc" => [
813 + "page_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'),
814 + "menu_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'),
815 + "function" => "wtsec_antivirus_page",
816 + "vc_action" => "vc-action",
817 + "vc_function" => "wtsec_vc_function"
818 + ],
819 + "waf" => [
820 + "page_title" => WTSEC_LIBRARY_Localization::lmsg('firewall'),
821 + "menu_title" => WTSEC_LIBRARY_Localization::lmsg('firewall'),
822 + "function" => "wtsec_firewall_page",
823 + "vc_action" => "firewall-action",
824 + "vc_function" => "wtsec_firewall_function"
825 + ],
826 + ];
827 +}
828 +
829 +function wtsec_getCountryName($key){
830 + $countries = [
831 + 'AD' => 'Andorra',
832 + 'AE' => 'United Arab Emirates',
833 + 'AF' => 'Afghanistan',
834 + 'AG' => 'Antigua and Barbuda',
835 + 'AI' => 'Anguilla',
836 + 'AL' => 'Albania',
837 + 'AM' => 'Armenia',
838 + 'AN' => 'Netherlands Antilles',
839 + 'AO' => 'Angola',
840 + 'AP' => 'Asia/Pacific Region',
841 + 'AQ' => 'Antarctica',
842 + 'AR' => 'Argentina',
843 + 'AS' => 'American Samoa',
844 + 'AT' => 'Austria',
845 + 'AU' => 'Australia',
846 + 'AW' => 'Aruba',
847 + 'AZ' => 'Azerbaijan',
848 + 'BA' => 'Bosnia and Herz.',
849 + 'BB' => 'Barbados',
850 + 'BD' => 'Bangladesh',
851 + 'BE' => 'Belgium',
852 + 'BF' => 'Burkina Faso',
853 + 'BG' => 'Bulgaria',
854 + 'BH' => 'Brunei',
855 + 'BI' => 'Burundi',
856 + 'BJ' => 'Benin',
857 + 'BM' => 'Bermuda',
858 + 'BN' => 'Brunei Darussalam',
859 + 'BO' => 'Bolivia',
860 + 'BR' => 'Brazil',
861 + 'BS' => 'Bahamas',
862 + 'BT' => 'Bhutan',
863 + 'BV' => 'Bouvet Island',
864 + 'BW' => 'Botswana',
865 + 'BY' => 'Belarus',
866 + 'BZ' => 'Belize',
867 + 'CA' => 'Canada',
868 + 'CC' => 'Cocos (Keeling) Islands',
869 + 'CD' => 'Dem. Rep. Congo',
870 + 'CF' => 'Central African Rep.',
871 + 'CG' => 'Congo',
872 + 'CH' => 'Switzerland',
873 + 'CI' => 'Côte d\'Ivoire',
874 + 'CK' => 'Cook Islands',
875 + 'CL' => 'Chile',
876 + 'CM' => 'Cameroon',
877 + 'CN' => 'China',
878 + 'CO' => 'Colombia',
879 + 'CR' => 'Costa Rica',
880 + 'CS' => 'Serbia',
881 + 'CU' => 'Cuba',
882 + 'CV' => 'Cape Verde',
883 + 'CX' => 'Christmas Island',
884 + 'CY' => 'Cyprus',
885 + 'CZ' => 'Czech Rep.',
886 + 'DE' => 'Germany',
887 + 'DJ' => 'Djibouti',
888 + 'DK' => 'Denmark',
889 + 'DM' => 'Dominica',
890 + 'DO' => 'Dominican Rep.',
891 + 'DZ' => 'Algeria',
892 + 'EC' => 'Ecuador',
893 + 'EE' => 'Estonia',
894 + 'EG' => 'Egypt',
895 + 'EH' => 'W. Sahara',
896 + 'ER' => 'Eritrea',
897 + 'ES' => 'Spain',
898 + 'ET' => 'Ethiopia',
899 + 'EU' => 'Europe',
900 + 'FI' => 'Finland',
901 + 'FJ' => 'Fiji',
902 + 'FK' => 'Falkland Is.',
903 + 'FM' => 'Micronesia, Federated States of',
904 + 'FO' => 'Faroe Islands',
905 + 'FR' => 'France',
906 + 'FX' => 'France, Metropolitan',
907 + 'GA' => 'Gabon',
908 + 'GB' => 'United Kingdom',
909 + 'GD' => 'Grenada',
910 + 'GE' => 'Georgia',
911 + 'GF' => 'French Guiana',
912 + 'GH' => 'Ghana',
913 + 'GI' => 'Gibraltar',
914 + 'GL' => 'Greenland',
915 + 'GM' => 'Gambia',
916 + 'GN' => 'Guinea',
917 + 'GP' => 'Guadeloupe',
918 + 'GQ' => 'Eq. Guinea',
919 + 'GR' => 'Greece',
920 + 'GS' => 'South Georgia and the South Sandwich Islands',
921 + 'GT' => 'Guatemala',
922 + 'GU' => 'Guam',
923 + 'GW' => 'Guinea-Bissau',
924 + 'GY' => 'Guyana',
925 + 'HK' => 'Hong Kong',
926 + 'HM' => 'Heard Island and McDonald Islands',
927 + 'HN' => 'Honduras',
928 + 'HR' => 'Croatia',
929 + 'HT' => 'Haiti',
930 + 'HU' => 'Hungary',
931 + 'ID' => 'Indonesia',
932 + 'IE' => 'Ireland',
933 + 'IL' => 'Israel',
934 + 'IN' => 'India',
935 + 'IO' => 'British Indian Ocean Territory',
936 + 'IQ' => 'Iraq',
937 + 'IR' => 'Iran',
938 + 'IS' => 'Iceland',
939 + 'IT' => 'Italy',
940 + 'JM' => 'Jamaica',
941 + 'JO' => 'Jordan',
942 + 'JP' => 'Japan',
943 + 'KE' => 'Kenya',
944 + 'KG' => 'Kyrgyzstan',
945 + 'KH' => 'Cambodia',
946 + 'KI' => 'Kiribati',
947 + 'KM' => 'Comoros',
948 + 'KN' => 'Saint Kitts and Nevis',
949 + 'KP' => 'Dem. Rep. Korea',
950 + 'KR' => 'Korea',
951 + 'KW' => 'Kuwait',
952 + 'KY' => 'Cayman Islands',
953 + 'KZ' => 'Kazakhstan',
954 + 'LA' => 'Lao PDR',
955 + 'LB' => 'Lebanon',
956 + 'LC' => 'Saint Lucia',
957 + 'LI' => 'Liechtenstein',
958 + 'LK' => 'Sri Lanka',
959 + 'LR' => 'Liberia',
960 + 'LS' => 'Lesotho',
961 + 'LT' => 'Lithuania',
962 + 'LU' => 'Luxembourg',
963 + 'LV' => 'Latvia',
964 + 'LY' => 'Libya',
965 + 'MA' => 'Morocco',
966 + 'MC' => 'Monaco',
967 + 'MD' => 'Moldova',
968 + 'MG' => 'Madagascar',
969 + 'MH' => 'Marshall Islands',
970 + 'MK' => 'Macedonia',
971 + 'ML' => 'Mali',
972 + 'MM' => 'Myanmar',
973 + 'MN' => 'Mongolia',
974 + 'MO' => 'Macau',
975 + 'MP' => 'Northern Mariana Islands',
976 + 'MQ' => 'Martinique',
977 + 'MR' => 'Mauritania',
978 + 'MS' => 'Montserrat',
979 + 'MT' => 'Malta',
980 + 'MU' => 'Mauritius',
981 + 'MV' => 'Maldives',
982 + 'MW' => 'Malawi',
983 + 'MX' => 'Mexico',
984 + 'MY' => 'Malaysia',
985 + 'MZ' => 'Mozambique',
986 + 'NA' => 'Namibia',
987 + 'NC' => 'New Caledonia',
988 + 'NE' => 'Niger',
989 + 'NF' => 'Norfolk Island',
990 + 'NG' => 'Nigeria',
991 + 'NI' => 'Nicaragua',
992 + 'NL' => 'Netherlands',
993 + 'NO' => 'Norway',
994 + 'NP' => 'Nepal',
995 + 'NR' => 'Nauru',
996 + 'NU' => 'Niue',
997 + 'NZ' => 'New Zealand',
998 + 'OM' => 'Oman',
999 + 'PA' => 'Panama',
1000 + 'PE' => 'Peru',
1001 + 'PF' => 'French Polynesia',
1002 + 'PG' => 'Papua New Guinea',
1003 + 'PH' => 'Philippines',
1004 + 'PK' => 'Pakistan',
1005 + 'PL' => 'Poland',
1006 + 'PM' => 'Saint Pierre and Miquelon',
1007 + 'PN' => 'Pitcairn Islands',
1008 + 'PR' => 'Puerto Rico',
1009 + 'PS' => 'Palestine',
1010 + 'PT' => 'Portugal',
1011 + 'PW' => 'Palau',
1012 + 'PY' => 'Paraguay',
1013 + 'QA' => 'Qatar',
1014 + 'RE' => 'Reunion',
1015 + 'RO' => 'Romania',
1016 + 'RU' => 'Russia',
1017 + 'RW' => 'Rwanda',
1018 + 'SA' => 'Saudi Arabia',
1019 + 'SB' => 'Solomon Is.',
1020 + 'SC' => 'Seychelles',
1021 + 'SD' => 'Sudan',
1022 + 'SE' => 'Sweden',
1023 + 'SG' => 'Singapore',
1024 + 'SH' => 'Saint Helena',
1025 + 'SI' => 'Slovenia',
1026 + 'SJ' => 'Svalbard and Jan Mayen',
1027 + 'SK' => 'Slovakia',
1028 + 'SL' => 'Sierra Leone',
1029 + 'SM' => 'San Marino',
1030 + 'SN' => 'Senegal',
1031 + 'SO' => 'Somalia',
1032 + 'SR' => 'Suriname',
1033 + 'ST' => 'Sao Tome and Principe',
1034 + 'SV' => 'El Salvador',
1035 + 'SY' => 'Syria',
1036 + 'SZ' => 'Swaziland',
1037 + 'TC' => 'Turks and Caicos Islands',
1038 + 'TD' => 'Chad',
1039 + 'TF' => 'French Southern Territories',
1040 + 'TG' => 'Togo',
1041 + 'TH' => 'Thailand',
1042 + 'TJ' => 'Tajikistan',
1043 + 'TK' => 'Tokelau',
1044 + 'TM' => 'Turkmenistan',
1045 + 'TN' => 'Tunisia',
1046 + 'TO' => 'Tonga',
1047 + 'TP' => 'East Timor',
1048 + 'TR' => 'Turkey',
1049 + 'TT' => 'Trinidad and Tobago',
1050 + 'TV' => 'Tuvalu',
1051 + 'TW' => 'Taiwan',
1052 + 'TZ' => 'Tanzania',
1053 + 'UA' => 'Ukraine',
1054 + 'UG' => 'Uganda',
1055 + 'UM' => 'United States Minor Outlying Islands',
1056 + 'US' => 'United States',
1057 + 'UY' => 'Uruguay',
1058 + 'UZ' => 'Uzbekistan',
1059 + 'VA' => 'Holy See (Vatican City State)',
1060 + 'VC' => 'Saint Vincent and the Grenadines',
1061 + 'VE' => 'Venezuela',
1062 + 'VG' => 'Virgin Islands, British',
1063 + 'VI' => 'Virgin Islands, U.S.',
1064 + 'VN' => 'Vietnam',
1065 + 'VU' => 'Vanuatu',
1066 + 'WF' => 'Wallis and Futuna',
1067 + 'WS' => 'Samoa',
1068 + 'YE' => 'Yemen',
1069 + 'YT' => 'Mayotte',
1070 + 'ZA' => 'South Africa',
1071 + 'ZM' => 'Zambia',
1072 + 'ZR' => 'Zaire',
1073 + 'ZW' => 'Zimbabwe',
1074 + ];
1075 +
1076 + return $countries[$key];
1077 +}