PluginProbe
WebTotem Security / 2.4.11
WebTotem Security v2.4.11
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 | lib/Helper.php +296 -892 trunk2.4.11 View file →
@@ -11,12 +11,8 @@
11 11 * WebTotem Base class for Wordpress.
12 12 */
13 13 class WebTotem {
14 14
15 - public static function log($notice){
16 - file_put_contents(WEBTOTEM_PLUGIN_PATH . '/wtotem_log.txt', date('Y-m-d H:i:s') . ' ' . $notice . PHP_EOL, FILE_APPEND);
17 - }
18 -
19 15 /**
20 16 * Returns an URL from the admin dashboard.
21 17 *
22 18 * @param string $url
@@ -45,12 +41,10 @@
45 41 $user_role = 0;
46 42 } else {
47 43 $roles = $current_user->roles;
48 44
49 - if(in_array('administrator', $roles)) {
45 + if(in_array('administrator', $roles)){
50 46 $user_role = 1;
51 - } elseif(in_array('editor', $roles) or current_user_can('publish_posts')) {
52 - $user_role = 2;
53 47 } else {
54 48 $user_role = 0;
55 49 }
56 50 }
@@ -66,29 +60,11 @@
66 60 * @return bool
67 61 * Either TRUE or FALSE in case WordPress is being used as a multi-site instance.
68 62 */
69 63 public static function isMultiSite() {
70 - return (bool) ( (function_exists('is_multisite') && is_multisite()) || (defined('MULTISITE') && MULTISITE == true) );
64 + return (bool) (function_exists('is_multisite') && is_multisite());
71 65 }
72 66
73 -
74 - /**
75 - * Get user email.
76 - *
77 - * @return string
78 - * Returns user email.
79 - */
80 - public static function getUserEmail() {
81 - $email = WebTotemOption::getOption( "user_email" );
82 - if(!$email){
83 - if(WebTotemOption::isActivated()) {
84 -// $email = WebTotemAPI::getEmail();
85 - }
86 - WebTotemOption::setOptions(['user_email' => $email]);
87 - }
88 - return $email;
89 - }
90 -
91 67 /**
92 68 * Returns the md5 hash representing the content of a file.
93 69 *
94 70 * @param string $file
@@ -100,197 +76,29 @@
100 76 return substr(md5_file(WEBTOTEM_PLUGIN_PATH . '/' . $file), 0, 7);
101 77 }
102 78
103 79 /**
104 - * Returns full path to image.
80 + * Returns the md5 hash representing the content of a file.
105 81 *
106 - * @param string $image
82 + * @param string $file
107 83 * Relative path to the file.
108 84 * @return string
109 - * Full path to image.
85 + * Seven first characters in the hash of the file.
110 86 */
111 87 public static function getImagePath($image) {
112 88 return WEBTOTEM_URL. '/includes/img/' . $image;
113 89 }
114 90
115 - /**
116 - * Checking whether the current domain belongs to the kz domain zone.
117 - *
118 - * @return bool
119 - * true is returned if the domain belongs to the kz domain zone.
120 - */
121 - public static function isKz() {
122 - $is_kz = json_decode(WebTotemOption::getOption('is_kz'), true);
123 - if(is_array($is_kz)){
124 - return $is_kz['value'];
125 - }
126 -
127 - if(function_exists('idn_to_utf')){
128 - $host = idn_to_utf8($_SERVER['HTTP_HOST']);
129 - } else {
130 - $host = $_SERVER['HTTP_HOST'];
131 - }
132 -
133 - $parts = explode('.', $host);
134 - $domain_zone = $parts[count($parts)-1];
135 -
136 - if($domain_zone === 'kz' or $domain_zone === 'қаз'){
137 - $is_kz['value'] = true;
138 - } else {
139 - $is_kz['value'] = false;
140 - }
141 -
142 - WebTotemOption::setOptions(['is_kz' => $is_kz]);
143 -
144 - return $is_kz['value'];
145 - }
146 -
147 - /**
148 - * Convert object to array.
149 - *
150 - * @param array $data
151 - * Array.
152 - * @return array
153 - * Returns array.
154 - */
155 - public static function convertObjectToArray($data){
156 -
157 - if(!is_array($data)) $data = (array)$data;
158 - array_walk_recursive($data, function(&$item){
159 - if(is_object($item)) $item = (array)$item;
160 - });
161 -
162 - return $data;
163 - }
164 -
165 - /**
166 - * Decodes a Base64URL-encoded string into a regular string.
167 - *
168 - * Base64URL is a URL-safe variant of Base64 commonly used in JWT and other web standards.
169 - * In Base64URL, the '+' and '/' characters are replaced with '-' and '_', and the '=' padding is often omitted.
170 - * This function converts Base64URL back to standard Base64 and then decodes it.
171 - *
172 - * @param string $data The input string encoded in Base64URL format.
173 - *
174 - * @return string|false Returns the decoded string, or false if decoding fails.
175 - */
176 - public static function base64UrlDecode($data) {
177 - $remainder = strlen($data) % 4;
178 - if ($remainder) {
179 - $data .= str_repeat('=', 4 - $remainder);
180 - }
181 - return base64_decode(strtr($data, '-_', '+/'));
182 - }
183 -
184 91 /**
185 - * Removing duplicates by one key.
186 - *
187 - * @param array $array
188 - * Array.
189 - * @param string $key
190 - * Delete duplicates with the same key.
191 - *
192 - * @return array
193 - * Returns array.
194 - */
195 - public static function arrayUniqueKey($array, $key) {
196 - $tmp = $key_array = array();
197 - $i = 0;
198 -
199 - foreach ($array as $val) {
200 - if (!in_array($val[$key], $key_array)) {
201 - $key_array[$i] = $val[$key];
202 - $tmp[$i] = $val;
203 - }
204 - $i++;
205 - }
206 - return $tmp;
207 - }
208 -
209 - /**
210 - * Returns user IP address.
211 - *
212 - * @return string
213 - * Returns user IP address.
214 - */
215 - public static function getUserIP() {
216 - $arr = [
217 - 'HTTP_CLIENT_IP',
218 - 'HTTP_X_FORWARDED_FOR',
219 - 'HTTP_X_FORWARDED',
220 - 'HTTP_X_CLUSTER_CLIENT_IP',
221 - 'HTTP_FORWARDED_FOR',
222 - 'HTTP_FORWARDED',
223 - 'HTTP_CF_CONNECTING_IP',
224 - 'REMOTE_ADDR'
225 - ];
226 -
227 - foreach ($arr as $key){
228 - if (array_key_exists($key, $_SERVER) === true) {
229 - foreach (explode(',', $_SERVER[$key]) as $ip) {
230 - $ip = trim($ip);
231 - $ip = filter_var($ip, FILTER_VALIDATE_IP);
232 - if (!empty($ip)) {
233 - return $ip;
234 - }
235 - }
236 - }
237 - }
238 - return false;
239 - }
240 -
241 - /**
242 - * Convert the file size to а human-readable format.
92 + * Check that the training period has passed for the firewall.
243 93 *
244 - * @param string $bytes
245 - * File size in bytes.
246 - * @param string $decimals
247 - * The number of characters after the decimal point.
94 + * @param string $created_at
95 + * Date when the waf configuration was created.
248 96 *
249 - * @return string
250 - * Returns the file size in a human-readable format.
251 - */
252 - public static function humanFilesize($bytes, $decimals = 2) {
253 - $factor = floor((strlen($bytes) - 1) / 3);
254 - $unit_of_measurement = ($factor > 0) ? substr("KMGT", $factor - 1, 1) : '';
255 - $size = sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $unit_of_measurement . 'B';
256 - return str_replace(".00", "", $size);
257 - }
258 -
259 - /**
260 - * Check whether the file is publicly accessible.
261 - *
262 - * @param string $url
263 - * http link to the file.
264 - * @param string $path
265 - * The path to the file.
266 - *
267 97 * @return bool
268 - */
269 - public static function isPubliclyAccessible($url, $path) {
270 - $response = wp_remote_get($url);
271 -
272 - if ((int) floor(((int) wp_remote_retrieve_response_code($response) / 100)) === 2) {
273 - $handle = @fopen($path, 'r');
274 - if ($handle) {
275 - $contents = fread($handle, 700);
276 - fclose($handle);
277 - $remoteContents = substr(wp_remote_retrieve_body($response), 0, 700);
278 -
279 - return $contents === $remoteContents;
280 - }
281 - }
282 - return false;
283 - }
284 -
285 - /**
286 - * Check that the training period has passed for the firewall.
287 - *
288 - * @return bool
289 98 * Returns boolean.
290 99 */
291 - public static function isWafTraining() {
292 - $created_at = WebTotemOption::getOption('am_created_at');
100 + public static function isWafTraining($created_at) {
293 101 if($created_at) {
294 102 $when_waf_trained = strtotime('+2 day', strtotime($created_at));
295 103 $today = strtotime('today');
296 104
@@ -298,70 +106,30 @@
298 106 }
299 107 return FALSE;
300 108 }
301 109
302 - /**
303 - * Check if the data for the period is available.
304 - *
305 - * @param string $created_at
306 - * Date when the agent manager was created.
307 - *
308 - * @return array
309 - * Returns an array with periods.
310 - */
311 - public static function isPeriodAvailable() {
110 + /**
111 + * Converting a date to the appropriate format.
112 + *
113 + * @param string $date
114 + * Date in any format.
115 + * @param string $format
116 + * The format to which you want to convert the date.
117 + *
118 + * @return string
119 + * Returns converted Date.
120 + */
121 + public static function dateFormatter($date, $format = 'M j, Y \/ H:i') {
122 + if (!$date) {
123 + return __('Unknown', 'wtotem');
124 + }
312 125
313 - $created_at = WebTotemOption::getOption('am_created_at');
314 - if(!$created_at){
315 - return [
316 - 'monthly' => false,
317 - 'yearly' => false,
318 - ];
319 - }
320 - $diff = strtotime(gmdate("Y-m-d H:i:s")) - strtotime($created_at);
321 - $daysCount = floor($diff / 86400);
126 + $time_zone = WebTotemOption::getOption('time_zone_offset');
127 + $user_time = ($time_zone) ? strtotime($time_zone . 'hours', strtotime($date)) : strtotime($date);
322 128
323 - return [
324 - 'monthly' => $daysCount > 7,
325 - 'yearly' => $daysCount > 30,
326 - ];
129 + return date_i18n($format, $user_time);
130 + }
327 131
328 - }
329 -
330 - /**
331 - * Converting a date to the appropriate format.
332 - *
333 - * @param string $date
334 - * Date in any format.
335 - * @param string $format
336 - * The format to which you want to convert the date.
337 - *
338 - * @return string
339 - * Returns converted Date.
340 - * @throws Exception
341 - */
342 - public static function dateFormatter($date, $format = 'M j, Y \/ H:i') {
343 - if (!$date) {
344 - return __('Unknown', 'wtotem');
345 - }
346 -
347 - if ( is_numeric($date) && (int)$date == $date ){
348 - $date = date('Y-m-d H:i', $date);
349 - }
350 -
351 - if($wp_timezone = wp_timezone()){
352 - $UTC = new DateTimeZone("UTC");
353 - $date = new DateTime( $date, $UTC );
354 - $date->setTimezone( new DateTimeZone($wp_timezone->getName()) );
355 - return date_i18n($format,strtotime($date->format('Y-m-d H:i')));
356 - }
357 -
358 - $time_zone = WebTotemOption::getOption('time_zone_offset');
359 - $user_time = ($time_zone) ? strtotime($time_zone . 'hours', strtotime($date)) : strtotime($date);
360 -
361 - return date_i18n($format, $user_time);
362 - }
363 -
364 132 /**
365 133 * Get theme mode data.
366 134 *
367 135 * @return array
@@ -406,24 +174,24 @@
406 174
407 175 case is_array($days):
408 176 $to = $days[1] ?: $days[0];
409 177 $period = [
410 - 'from' => date('Y-m-d 00:00:01', strtotime(self::formatDate($days[0]))),
411 - 'to' => date('Y-m-d 23:59:59', strtotime(self::formatDate($to))),
178 + 'from' => strtotime(date('Y-m-d 00:00:01', strtotime($days[0]))),
179 + 'to' => strtotime(date('Y-m-d 23:59:59', strtotime($to))),
412 180 ];
413 181 break;
414 182
415 183 case $days <= 1:
416 184 $period = [
417 - 'from' => date('Y-m-d H:m:i', strtotime('-24 hours')),
418 - 'to' => date('Y-m-d H:m:i', time()),
185 + 'from' => strtotime('-24 hours'),
186 + 'to' => time(),
419 187 ];
420 188 break;
421 189
422 190 default:
423 191 $period = [
424 - 'from' => date('Y-m-d H:m:i', time() - ($days * 86400)),
425 - 'to' => date('Y-m-d H:m:i'),
192 + 'from' => time() - ($days * 86400),
193 + 'to' => time(),
426 194 ];
427 195 }
428 196
429 197 return $period;
@@ -428,48 +196,8 @@
428 196
429 197 return $period;
430 198 }
431 199
432 - /**
433 - * Converting a date from "j M, Y" format to 'd-m-Y' format.
434 - *
435 - * @return string
436 - * Returns date in new format
437 - */
438 - public static function formatDate($date){
439 - $month = [
440 - 'Jan' => 'Янв',
441 - 'Feb' => 'Фев',
442 - 'Mar' => 'Мар',
443 - 'Apr' => 'Апр',
444 - 'May' => 'Май',
445 - 'Jun' => 'Июн',
446 - 'Jul' => 'Июл',
447 - 'Aug' => 'Авг',
448 - 'Sep' => 'Сен',
449 - 'Oct' => 'Окт',
450 - 'Nov' => 'Ноя',
451 - 'Dec' => 'Дек',
452 - ];
453 -
454 - foreach ($month as $key => $value) {
455 - if (strpos($date, $value)) {
456 - $date = str_replace($value, $key, $date);
457 - }
458 - }
459 -
460 - $pattern = '/^(\d{1,2})\s+([a-zA-Z]+),\s+(\d{4})$/';
461 -
462 - if (preg_match($pattern, $date, $matches)) {
463 - $monthNumber = date_parse($matches[2])['month'];
464 -
465 - return sprintf('%02d-%02d-%04d', $matches[1], $monthNumber, $matches[3]);
466 - }
467 -
468 - return $date;
469 -
470 - }
471 -
472 200 /**
473 201 * Convert an array to a string with quotation marks.
474 202 *
475 203 * @param array $array
@@ -539,12 +267,9 @@
539 267
540 268 case 'clean':
541 269 case 'up':
542 270 case 'installed':
543 - case 'available':
544 - case 'enable':
545 271 case 'working':
546 - case 'good':
547 272 $status_data = [
548 273 'class' => 'is--status--ok',
549 274 'image' => $path . 'check-mark.svg',
550 275 'icon' => $path . 'icon_success_status.svg',
@@ -571,9 +296,8 @@
571 296 case 'expired':
572 297 case 'no_cert':
573 298 case 'expires':
574 299 case 'open_ports':
575 - case 'warning':
576 300 case 'not_supported':
577 301 case 'not_registered':
578 302 $status_data = [
579 303 'class' => 'is--status--warning',
@@ -582,12 +306,8 @@
582 306 ];
583 307 break;
584 308
585 309 case 'invalid':
586 - case 'revoked':
587 - case 'untrusted':
588 - case 'not_found':
589 - case 'wrong_host':
590 310 case 'error':
591 311 case 'down':
592 312 case 'expires_today':
593 313 case 'infected':
@@ -673,14 +393,8 @@
673 393 "changed" => __('Changed', 'wtotem'),
674 394 "new" => __('New', 'wtotem'),
675 395 "scanned" => __('Scanned', 'wtotem'),
676 396 "quarantine" => __('In quarantine', 'wtotem'),
677 - "good" => __('Good', 'wtotem'),
678 - "wrong_host" => __('Wrong host', 'wtotem'),
679 - "revoked" => __('Revoked', 'wtotem'),
680 - "untrusted" => __('Untrusted', 'wtotem'),
681 - "not_found" => __('Not found', 'wtotem'),
682 - "enable" => __('Enable', 'wtotem'),
683 397 ];
684 398
685 399 return (array_key_exists($status, $statuses)) ? $statuses[$status] : $status;
686 400 }
@@ -717,12 +431,9 @@
717 431 'session_error' => __('This means that the agent did not create a secure session. Possible causes include network issues, wrong server configuration, third-party firewalls. Please contact our support..', 'wtotem'),
718 432 'internal_error' => __('It means that the server is overloaded or there might be some problems with the connection. Usually, the issue resolves itself within 10-15 minutes. If the status does not change during two hours, please cordially contact our support..', 'wtotem'),
719 433 'working' => __('Everything is alright.', 'wtotem'),
720 434 'installed' => __('Everything is alright.', 'wtotem'),
721 - 'available' => __('Everything is alright.', 'wtotem'),
722 435 'not_installed' => __('You need to install agent manager to activate antivirus and firewall.', 'wtotem'),
723 - 'enable' => __('Enabled — the module is active; information is being collected and updated.', 'wtotem'),
724 -
725 436 ];
726 437
727 438 return (array_key_exists($status, $tooltips)) ? $tooltips[$status] : '';
728 439 }
@@ -747,107 +458,37 @@
747 458 $domains[$domain] = $domain;
748 459 }
749 460
750 461 $sites = [];
751 - foreach ((array) $data as $site) {
752 - if (!is_array($site) || empty($site['name'])) {
753 - continue;
462 + if(array_key_exists('edges', $data)){
463 + foreach ($data['edges'] as $site) {
464 + $site = $site['node'];
465 + // Take sites only from the multisite network.
466 + if(array_key_exists($site['hostname'], $domains)) {
467 + unset($domains[$site['hostname']]);
468 + $sites[] = [
469 + 'hostname' => $site['hostname'],
470 + 'title' => $site['title'],
471 + 'main_host' => $main_host['id'] == $site['id'],
472 + 'host_id' => $site['id'],
473 + 'url' => admin_url('admin.php?page=wtotem_dashboard&hid=' . $site['id']),
474 + 'firewall' => [
475 + 'status' => self::getStatusData($site['firewall']['status']),
476 + ],
477 + 'antivirus' => [
478 + 'status' => self::getStatusData($site['antivirus']['status']),
479 + ],
480 + 'stacks' => self::getStacksData($site['maliciousScript']['stack']),
481 + 'services' => self::getSiteServicesData($site),
482 + ];
483 + }
754 484 }
755 485
756 - // Take sites only from the multisite network.
757 - if (!array_key_exists($site['name'], $domains)) {
758 - continue;
759 - }
760 -
761 - unset($domains[$site['name']]);
762 -
763 - $modules = self::getHostModuleStatuses($site);
764 -
765 - $sites[] = [
766 - 'hostname' => $site['name'],
767 - 'title' => $site['name'],
768 - 'main_host' => $main_host['id'] == $site['id'],
769 - 'host_id' => $site['id'],
770 - 'url' => admin_url('admin.php?page=wtotem_dashboard&hid=' . $site['id']),
771 - 'firewall' => [
772 - 'status' => self::getStatusData($modules['waf'] ?? ''),
773 - ],
774 - 'antivirus' => [
775 - 'status' => self::getStatusData($modules['av'] ?? ''),
776 - ],
777 - 'stacks' => self::getStacksData([]),
778 - 'services' => self::getSiteServicesData(self::getHostServices($site, $modules)),
779 - ];
780 486 }
781 -
782 487 return $sites;
783 488 }
784 489
785 490 /**
786 - * Index a host's module statuses by module name.
787 - *
788 - * @param array $host
789 - * A single host entry from the hosts endpoint.
790 - *
791 - * @return array
792 - * Module name => status.
793 - */
794 - protected static function getHostModuleStatuses(array $host) {
795 - $statuses = [];
796 -
797 - foreach ($host['modules'] ?? [] as $module) {
798 - if (!empty($module['name'])) {
799 - $statuses[$module['name']] = $module['status'] ?? '';
800 - }
801 - }
802 -
803 - return $statuses;
804 - }
805 -
806 - /**
807 - * Shape a host entry the way getSiteServicesData() expects it.
808 - *
809 - * @param array $host
810 - * A single host entry from the hosts endpoint.
811 - * @param array $modules
812 - * Module name => status, as returned by getHostModuleStatuses().
813 - *
814 - * @return array
815 - * Service name => ['status' => ...].
816 - */
817 - protected static function getHostServices(array $host, array $modules) {
818 - $map = [
819 - 'ssl' => 'ssl',
820 - 'availability' => 'wa',
821 - 'reputation' => 'rc',
822 - 'ports' => 'ps',
823 - 'deface' => 'dc',
824 - 'domain' => 'dec',
825 - ];
826 -
827 - $services = [];
828 - foreach ($map as $key => $module_name) {
829 - if (isset($modules[$module_name])) {
830 - $services[$key] = ['status' => $modules[$module_name]];
831 - }
832 - }
833 -
834 - if (isset($host['ssl_result']['status'])) {
835 - $services['ssl'] = ['status' => $host['ssl_result']['status']];
836 - }
837 -
838 - if (isset($host['reputation_result']['status'])) {
839 - $services['reputation'] = ['status' => $host['reputation_result']['status']];
840 - }
841 -
842 - if (isset($host['availability_result']['last_status'])) {
843 - $services['availability'] = ['status' => $host['availability_result']['last_status']];
844 - }
845 -
846 - return $services;
847 - }
848 -
849 - /**
850 491 * Converting stacks data.
851 492 *
852 493 * @param array $stacks
853 494 * Stacks data from WebTotem.
@@ -855,12 +496,8 @@
855 496 * @return array
856 497 * Converted data.
857 498 */
858 499 protected static function getStacksData($stacks) {
859 - if (!$stacks) {
860 - return ['list' => [], 'other' => ['count' => 0, 'names' => []]];
861 - }
862 -
863 500 $apps = file_get_contents(WEBTOTEM_PLUGIN_PATH . '/includes/js/apps.json');
864 501 $apps = json_decode($apps, true);
865 502
866 503 $path = 'https://assets.wtotem.net/images/apps/';
@@ -1039,8 +676,54 @@
1039 676 return $services[$service];
1040 677 }
1041 678
1042 679 /**
680 + * Get reports with modules list.
681 + *
682 + * @param array $edges
683 + * Data on generated reports.
684 + *
685 + * @return array
686 + * Returns an array with converted data.
687 + */
688 + public static function getReports(array $edges) {
689 + $modulesLang = [
690 + 'wa' => __('Availability log', 'wtotem'),
691 + 'dc' => __('Deface log', 'wtotem'),
692 + 'ps' => __('Port log', 'wtotem'),
693 + 'rc' => __('Reputation log', 'wtotem'),
694 + 'sc' => __('Evaluation log', 'wtotem'),
695 + 'av' => __('Antivirus log', 'wtotem'),
696 + 'waf' => __('Firewall log', 'wtotem'),
697 + ];
698 +
699 + $reports = [];
700 +
701 + foreach ($edges as $edge) {
702 + if (in_array(FALSE, $edge["node"])) {
703 + $arr = [];
704 + foreach ($edge["node"] as $module => $value) {
705 + if ($value == TRUE && array_key_exists($module, $modulesLang)) {
706 + $arr[] = $modulesLang[$module];
707 + }
708 + }
709 + $modules = implode(", ", $arr);
710 + }
711 + else {
712 + $modules = __('All modules', 'wtotem');
713 + }
714 +
715 + $reports[] = [
716 + 'id' => $edge["node"]['id'],
717 + 'modules' => $modules,
718 + 'created_at' => self::dateFormatter($edge["node"]['createdAt']),
719 + ];
720 + }
721 +
722 + return $reports;
723 + }
724 +
725 + /**
1043 726 * Get reputation status description.
1044 727 *
1045 728 * @param string $status
1046 729 * Reputation status.
@@ -1171,32 +854,16 @@
1171 854 */
1172 855 public static function wafLogs(array $logs_) {
1173 856 $logs = [];
1174 857 foreach ($logs_ as $key => $log) {
858 + $log = $log['node'];
1175 859
1176 860 $logs[$key]['ip'] = $log['ip'];
1177 - $logs[$key]['request'] = urldecode($log['request']);
1178 - $logs[$key]['time'] = self::dateFormatter($log['date']);
1179 - $logs[$key]['country_code'] = strtoupper($log['country']);
1180 - $logs[$key]['country'] = self::getCountryName($log['country']);
1181 - $logs[$key]['blocked'] = $log['blocked'] ? __('Blocked', 'wtotem') : __('Not blocked', 'wtotem');
1182 -
1183 - $more = [
1184 - 'ip' => $log['ip'],
1185 - 'proxy_ip' => $log['proxy_ip'],
1186 - 'source' => $log['source'],
1187 - 'request' => urldecode($log['request']),
1188 - 'user_agent' => $log['user_agent'],
1189 - 'time' => self::dateFormatter($log['date']),
1190 - 'type' => $log['type'],
1191 - 'category' => $log['signature_category'],
1192 - 'country' => self::getCountryName($log['country']),
1193 - 'payload' => urldecode($log['payload']),
1194 - 'hostname' => urldecode($log['hostname']),
1195 - 'is_trusted' => urldecode($log['is_trusted']),
1196 - ];
1197 -
1198 - $logs[$key]['more'] = json_encode($more);
861 + $logs[$key]['request'] = htmlspecialchars(urldecode($log['request']));
862 + $logs[$key]['time'] = self::dateFormatter($log['time']);
863 + $logs[$key]['country_code'] = strtolower($log['country']);
864 + $logs[$key]['country'] = $log['location']['country']['nameEn'];
865 + $logs[$key]['blocked'] = $log['blocked'] ? __('Blocked IP', 'wtotem') : __('Not blocked', 'wtotem');
1199 866 }
1200 867 return $logs;
1201 868 }
1202 869
@@ -1211,25 +878,38 @@
1211 878 */
1212 879 public static function generateWafChart(array $charts) {
1213 880 $sum = 0;
1214 881 foreach ($charts as $chart) {
1215 - $sum += $chart['total_attacks'];
882 + $sum += $chart['attacks'];
1216 883 }
1217 884 if ($sum == 0) {
1218 - return [
1219 - 'chart' => FALSE,
1220 - 'count_attacks' => 0,
1221 - 'count_blocks' => 0,
1222 - 'days' => 0,
1223 - ];
885 + return ['chart' => FALSE, 'count_attacks' => 0, 'count_blocks' => 0];
1224 886 }
1225 887
888 + // Get days count.
889 + $charts_ = $charts;
890 + $first = array_shift($charts_);
891 + $last = array_pop($charts_);
892 + $days = ceil((strtotime($last['time']) - strtotime($first['time'])) / 86400);
1226 893
1227 894 // Set variables.
1228 895 $count_attacks = $count_blocks = 0;
1229 896
1230 897 foreach ($charts as $chart) {
1231 - $result[$chart["type"]] = $chart["statistics"];
898 + if ($days <= 1) {
899 + $time_zone = WebTotemOption::getOption('time_zone_offset');
900 + $userTime = ($time_zone) ? strtotime($time_zone . ' hours', strtotime($chart['time'])) : strtotime($chart['time']);
901 + }
902 + if (($chart['attacks'] and $days == 2) or $days != 2) {
903 + $result[] = [
904 + 'date' => ($days <= 1) ? date("Y-m-d H:00:00", $userTime) : date("Y-m-d", strtotime($chart['time'])),
905 + 'count' => $chart['blocked'],
906 + 'attacks' => $chart['attacks'],
907 + 'blocked' => $chart['blocked'],
908 + ];
909 + $count_attacks += $chart['attacks'];
910 + $count_blocks += $chart['blocked'];
911 + }
1232 912 }
1233 913
1234 914 if (!isset($result)) {
1235 915 return [
@@ -1235,9 +915,8 @@
1235 915 return [
1236 916 'chart' => FALSE,
1237 917 'count_attacks' => 0,
1238 918 'count_blocks' => 0,
1239 - 'days' => 0,
1240 919 ];
1241 920 }
1242 921
1243 922 return [
@@ -1243,8 +922,9 @@
1243 922 return [
1244 923 'chart' => json_encode($result),
1245 924 'count_attacks' => $count_attacks,
1246 925 'count_blocks' => $count_blocks,
926 + 'days' => $days,
1247 927 ];
1248 928 }
1249 929
1250 930 /**
@@ -1296,11 +976,11 @@
1296 976 $attacks = [];
1297 977 $countries = [];
1298 978 $labels = [];
1299 979 foreach ($data as $value) {
1300 - $attacks[] = $value['total_attack'];
1301 - $labels[] = self::getCountryName($value['name']);
1302 - $countries[] = self::getCountryName($value['name'], 'en-US');
980 + $attacks[] = $value['attacks'];
981 + $labels[] = self::getCountryName($value['country']);
982 + $countries[] = $value['location']['country']['nameEn'];
1303 983 }
1304 984 $result = ['attacks' => $attacks, 'countries' => $countries, 'labels' => $labels];
1305 985
1306 986 if (!$attacks) {
@@ -1309,145 +989,72 @@
1309 989
1310 990 return json_encode($result, TRUE);
1311 991 }
1312 992
1313 - /**
1314 - * Reassembling the antivirus logs.
1315 - *
1316 - * @param array $logs_
1317 - * Antivirus logs from WebTotem.
1318 - *
1319 - * @return array
1320 - * Reassembled array of logs.
1321 - */
1322 - public static function getAntivirusLogsData(array $logs_) {
1323 - if(!$logs_){
1324 - return [];
1325 - }
1326 - $logs = [];
1327 - foreach ($logs_ as $key => $log) {
993 + /**
994 + * Reassembling the antivirus logs.
995 + *
996 + * @param array $logs_
997 + * Antivirus logs from WebTotem.
998 + *
999 + * @return array
1000 + * Reassembled array of logs.
1001 + */
1002 + public static function getAntivirusLogs(array $logs_) {
1003 + $logs = [];
1004 + foreach ($logs_ as $key => $log) {
1005 + $log = $log['node'];
1328 1006
1329 - if(isset($log['infectedNum']) and $log['infectedNum']){
1330 - $log['status_info'] = 'infected';
1331 - $log['status_name'] = __('Infected', 'wtotem');
1332 - } else {
1333 - $log['status_info'] = 'clean';
1334 - $log['status_name'] = __('Clean', 'wtotem');
1335 - }
1007 + $file_info = new SplFileInfo(urldecode($log['filePath']));
1336 1008
1337 - $log['date'] = self::dateFormatter($log['date'], 'd M Y');
1338 - $log['data'] = json_encode($log);
1009 + $log['original_path'] = $log['filePath'];
1010 + $log['file_path'] = $file_info->getPath() . '/';
1011 + $log['file_name'] = $file_info->getFilename();
1012 + $log['time'] = self::dateFormatter($log['time']);
1013 + $log['permissions_changed'] = $log['permissionsChanged'];
1014 + $log['status'] = self::getStatusData($log['event']);
1015 + $log['class'] = 'wt-text--green';
1339 1016
1340 - $logs[$key] = $log;
1341 - }
1342 - return $logs;
1343 - }
1017 + switch ($log['event']) {
1018 + case 'modified':
1019 + case 'quarantine':
1020 + $log['class'] = "wt-text--yellow";
1021 + break;
1344 1022
1345 - /**
1346 - * Reassembling the Infected Files logs.
1347 - *
1348 - * @param array $logs_
1349 - * Antivirus logs from WebTotem.
1350 - *
1351 - * @return array
1352 - * Reassembled array of Infected Files logs.
1353 - */
1354 - public static function getInfectedFilesData(array $logs_) {
1355 - $logs = [];
1356 - foreach ($logs_ as $key => $log) {
1357 - $full_path = urldecode($log['name']);
1358 - $log['file_name'] = $name = basename($full_path);
1359 - $log['file_path'] = str_replace($name, "", $full_path);
1023 + case 'deleted':
1024 + $log['class'] = "wt-text--light-gray";
1025 + break;
1360 1026
1361 - $logs[$key] = $log;
1362 - }
1363 - return $logs;
1364 - }
1027 + case 'infected':
1028 + $log['class'] = "wt-text--red";
1029 + break;
1030 + }
1365 1031
1366 - /**
1367 - * Reassembling the antivirus logs.
1368 - *
1369 - * @param array $logs_
1370 - * Antivirus logs from WebTotem.
1371 - *
1372 - * @return array
1373 - * Reassembled array of logs.
1374 - */
1375 - public static function getAntivirusAlerts(array $logs_) {
1376 - $logs = [];
1377 - foreach ($logs_ as $key => $log) {
1378 -
1379 - switch ($log['type']) {
1380 - case 'file':
1381 - $log['type_text'] = "Suspicious file";
1382 - break;
1383 -
1384 - case 'skippedPaths':
1385 - $log['type_text'] = "Unscanned Paths";
1386 - break;
1387 -
1388 - default:
1389 - $log['type_text'] = $log['type'];
1390 - }
1391 -
1392 - $logs[$key] = $log;
1393 - }
1394 - return $logs;
1032 + $logs[$key] = $log;
1395 1033 }
1034 + return $logs;
1035 + }
1396 1036
1397 - /**
1398 - * Get open path data.
1399 - *
1400 - * @param array $_ports
1401 - * Open ports array.
1402 - *
1403 - * @return array
1404 - * Reassembled array of open ports.
1405 - */
1406 - public static function getOpenPortsData($ports) {
1407 - if(!$ports){
1408 - return [];
1409 - }
1410 - foreach ($ports as $key => $port) {
1411 - $summary = '';
1412 - if($port['cves']){
1413 - foreach ($port['cves'] as $item){
1414 - $summary .= '<p>' . $item['summary'] . '</p>';
1415 - }
1416 - }
1417 - $ports[$key]['cve_summary'] = $summary;
1418 - }
1419 - return $ports;
1037 + /**
1038 + * Reassembling the quarantine logs.
1039 + *
1040 + * @param array $logs_
1041 + * Quarantine logs from WebTotem.
1042 + *
1043 + * @return array
1044 + * Reassembled array of logs.
1045 + */
1046 + public static function getQuarantineLogs(array $logs_) {
1047 + $logs = [];
1048 + foreach ($logs_ as $key => $log) {
1049 + $logs[$key] = $log;
1050 + $logs[$key]['path'] = urldecode($log['path']);
1051 + $logs[$key]['date'] = self::dateFormatter($log['date']);
1420 1052 }
1421 1053
1054 + return $logs;
1055 + }
1422 1056
1423 - /**
1424 - * Reassembling the Quarantine logs.
1425 - *
1426 - * @param array $list_
1427 - * Quarantine path list from WebTotem.
1428 - *
1429 - * @return array
1430 - * Reassembled array of Quarantine logs.
1431 - */
1432 - public static function getQuarantineListData(array $list_) {
1433 - if(!$list_){
1434 - return [];
1435 - }
1436 - $list = [];
1437 -
1438 - foreach ($list_ as $key => $log) {
1439 -
1440 - $full_path = urldecode($log['name']);
1441 - $log['path'] = $full_path;
1442 - $log['file_name'] = $name = basename($full_path);
1443 - $log['file_path'] = str_replace($name, "", $full_path);
1444 -
1445 - $list[$key] = $log;
1446 - }
1447 - return $list;
1448 - }
1449 -
1450 1057 /**
1451 1058 * Generate an array of IP address data.
1452 1059 *
1453 1060 * @param array $data
@@ -1461,9 +1068,11 @@
1461 1068 public static function getIpList(array $data, $list_name) {
1462 1069 $list = [];
1463 1070 foreach ($data as $item) {
1464 1071 $list[] = [
1465 - 'ip' => $item,
1072 + 'ip' => $item['ip'],
1073 + 'id' => $item['id'],
1074 + 'created_at' => self::dateFormatter($item['createdAt']),
1466 1075 'list_name' => $list_name,
1467 1076 ];
1468 1077 }
1469 1078 return $list;
@@ -1469,8 +1078,30 @@
1469 1078 return $list;
1470 1079 }
1471 1080
1472 1081 /**
1082 + * Generate an array of URL address data.
1083 + *
1084 + * @param array $data
1085 + * URL addresses data from WebTotem.
1086 + *
1087 + * @return array
1088 + * Returns array of data.
1089 + */
1090 + public static function getUrlAllowList(array $data) {
1091 + $list = [];
1092 + foreach ($data as $item) {
1093 + $list[] = [
1094 + 'url' => $item['url'],
1095 + 'id' => $item['id'],
1096 + 'created_at' => self::dateFormatter($item['createdAt']),
1097 + 'list_name' => 'url_allow',
1098 + ];
1099 + }
1100 + return $list;
1101 + }
1102 +
1103 + /**
1473 1104 * Convert IP list to be transferred to WebTotem.
1474 1105 *
1475 1106 * @param string $data
1476 1107 * IP list.
@@ -1482,48 +1113,26 @@
1482 1113 if (!$data) {
1483 1114 return FALSE;
1484 1115 }
1485 1116
1486 - return preg_split("/(?(?=[\s,])[^.]|^$)/", $data);
1117 + $ips = preg_split("/(?(?=[\s,])[^.]|^$)/", $data);
1487 1118
1488 - }
1489 - /**
1490 - * Validate Ip or Cidr.
1491 - *
1492 - * @param string $input
1493 - * IP address. (IPv4 / IPv6 + CIDR)
1494 - *
1495 - * @return bool
1496 - * Returns the converted string.
1497 - */
1498 - public static function validateIpOrCidr(string $input): bool {
1499 -
1500 - if (strpos($input, '/') !== false) {
1501 - [$ip, $mask] = explode('/', $input, 2);
1502 -
1503 - if (!filter_var($ip, FILTER_VALIDATE_IP)) {
1504 - return false;
1505 - }
1506 -
1507 - if (!ctype_digit($mask)) {
1508 - return false;
1509 - }
1510 -
1511 - $mask = (int)$mask;
1512 -
1513 - if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
1514 - return $mask >= 0 && $mask <= 32;
1515 - }
1516 -
1517 - if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
1518 - return $mask >= 0 && $mask <= 128;
1519 - }
1520 -
1521 - return false;
1119 + if (is_array($ips)) {
1120 + $ips_ = '[';
1121 + foreach ($ips as $ip) {
1122 + if (!empty($ip)) {
1123 + $ips_ .= '"' . $ip . '",';
1522 1124 }
1125 + }
1126 + $ips_ = substr($ips_, 0, -1);
1127 + $ips_ .= ']';
1128 + }
1129 + else {
1130 + $ips_ = '"' . $ips . '"';
1131 + }
1523 1132
1524 - return filter_var($input, FILTER_VALIDATE_IP) !== false;
1525 - }
1133 + return $ips_;
1134 + }
1526 1135
1527 1136 /**
1528 1137 * Get data of the country with the most attacks.
1529 1138 *
@@ -1528,8 +1137,10 @@
1528 1137 * Get data of the country with the most attacks.
1529 1138 *
1530 1139 * @param array $map
1531 1140 * Map logs from WebTotem.
1141 + * @param int $count_attacks
1142 + * Total attacks.
1532 1143 *
1533 1144 * @return array
1534 1145 * Returns array of data.
1535 1146 */
@@ -1535,13 +1146,13 @@
1535 1146 */
1536 1147 public static function getMostAttacksData($map) {
1537 1148
1538 1149 if ($map) {
1539 - $most_attacks_key = array_search(max(array_column($map, 'total_attack')), array_column($map, 'total_attack'));
1540 - $total_attacks = array_sum(array_column($map, 'total_attack'));
1150 + $most_attacks_key = array_search(max(array_column($map, 'attacks')), array_column($map, 'attacks'));
1151 + $total_attacks = array_sum(array_column($map, 'attacks'));
1541 1152
1542 - $data['percent'] = ($total_attacks) ? round($map[$most_attacks_key]['total_attack'] / $total_attacks * 100) : 0;
1543 - $data['country'] = self::getCountryName($map[$most_attacks_key]['name']);
1153 + $data['percent'] = ($total_attacks) ? round($map[$most_attacks_key]['attacks'] / $total_attacks * 100) : 0;
1154 + $data['country'] = self::getCountryName($map[$most_attacks_key]['country']);
1544 1155 $data['offset'] = 176 / 100 * (100 - $data['percent']);
1545 1156
1546 1157 return $data;
1547 1158 }
@@ -1557,19 +1168,16 @@
1557 1168 *
1558 1169 * @return string
1559 1170 * Returns country name.
1560 1171 */
1561 - public static function getCountryName($key, $lang = false) {
1562 - if($lang == 'en-US'){
1563 - $countries = WebTotemCountryManager::getCountiesNameByCode();
1564 - } else {
1565 - $countries = WebTotemCountryManager::getStandardList();
1566 - }
1172 + public static function getCountryName($key) {
1173 + $countries = WebTotemCountryManager::getStandardList();
1567 1174 $key = (string) $key;
1568 1175
1569 1176 return (array_key_exists($key, $countries)) ? $countries[$key] : $key;
1570 1177 }
1571 1178
1179 +
1572 1180 /**
1573 1181 * Get configs data.
1574 1182 *
1575 1183 * @param array $array
@@ -1600,44 +1208,25 @@
1600 1208 * @return array
1601 1209 * Configs data array.
1602 1210 */
1603 1211 public static function getWafSettingData(array $settings) {
1604 - $_settings['gdn']['checked'] = (isset($settings['global_defense_network']) && !$settings['global_defense_network']) ? '' : 'checked';
1212 + $_settings['gdn']['checked'] = (isset($settings['gdn']) && !$settings['gdn']) ? '' : 'checked';
1605 1213 $_settings['dos'] = [
1606 - 'checked' => (isset($settings['dos_protect']) && !$settings['dos_protect']) ? '' : 'checked',
1607 - 'visually' => (isset($settings['dos_protect']) && !$settings['dos_protect']) ? 'visually-hidden' : '',
1214 + 'checked' => (isset($settings['dosProtection']) && !$settings['dosProtection']) ? '' : 'checked',
1215 + 'visually' => (isset($settings['dosProtection']) && !$settings['dosProtection']) ? 'visually-hidden' : '',
1608 1216 ];
1609 - $_settings['dos_limit'] = $settings['dos_limit'] ?: 1000;
1217 + $_settings['dos_limit'] = $settings['dosLimit'] ?: 1000;
1610 1218
1611 1219 $_settings['login_attempt'] = [
1612 - 'checked' => (isset($settings['login_protect']) && !$settings['login_protect']) ? '' : 'checked',
1613 - 'visually' => (isset($settings['login_protect']) && !$settings['login_protect']) ? 'visually-hidden' : '',
1220 + 'checked' => (isset($settings['loginAttemptsProtection']) && !$settings['loginAttemptsProtection']) ? '' : 'checked',
1221 + 'visually' => (isset($settings['loginAttemptsProtection']) && !$settings['loginAttemptsProtection']) ? 'visually-hidden' : '',
1614 1222 ];
1615 - $_settings['login_attempt_limit'] = $settings['login_attempt_limit'] ?: 20;
1223 + $_settings['login_attempt_limit'] = $settings['loginAttemptsLimit'] ?: 20;
1616 1224
1617 1225 return $_settings;
1618 1226 }
1619 1227
1620 - /**
1621 - * Get plugin settings data.
1622 - *
1623 - * @return array
1624 - * Configs data array.
1625 - */
1626 - public static function getPluginSettingsData() {
1627 -
1628 - $settings = WebTotemOption::getPluginSettings();
1629 - $_settings = $settings;
1630 -
1631 - $_settings['hide_wp_version_checked'] = (array_key_exists('hide_wp_version', $settings) and $settings['hide_wp_version']) ? 'checked' : '';
1632 - $_settings['disable_user_enumeration_checked'] = (array_key_exists('disable_user_enumeration', $settings) and $settings['disable_user_enumeration']) ? 'checked' : '';
1633 - $_settings['recaptcha_checked'] = (array_key_exists('recaptcha', $settings) and $settings['recaptcha']) ? 'checked' : '';
1634 - $_settings['two_factor_checked'] = (array_key_exists('two_factor', $settings) and $settings['two_factor']) ? 'checked' : '';
1635 -
1636 - return $_settings;
1637 - }
1638 -
1639 - /**
1228 + /**
1640 1229 * Replace array indexes by key.
1641 1230 *
1642 1231 * @param array $array
1643 1232 * Original array.
@@ -1676,256 +1265,70 @@
1676 1265 return $randomString;
1677 1266 }
1678 1267
1679 1268 /**
1680 - * Encodes the less than, greater than, ampersand,double quote
1681 - * and single quote characters. Will never double encode entities.
1682 - *
1683 - * @see https://developer.wordpress.org/reference/functions/esc_attr/
1684 - *
1685 - * @param string $text
1686 - * The text which is to be encoded.
1687 - *
1688 - * @return string
1689 - * The encoded text with HTML entities.
1690 - */
1691 - public static function escape($text = '') {
1692 - return esc_attr($text);
1693 - }
1269 + * Encodes the less than, greater than, ampersand,double quote
1270 + * and single quote characters. Will never double encode entities.
1271 + *
1272 + * @see https://developer.wordpress.org/reference/functions/esc_attr/
1273 + *
1274 + * @param string $text
1275 + * The text which is to be encoded.
1276 + *
1277 + * @return string
1278 + * The encoded text with HTML entities.
1279 + */
1280 + public static function escape($text = '')
1281 + {
1282 + return esc_attr($text);
1283 + }
1694 1284
1695 - /**
1696 - * Throw generic exception.
1697 - *
1698 - * @throws Exception
1699 - *
1700 - * @param string $message
1701 - * Error or information message.
1702 - * @param string $type
1703 - * Either info or error.
1704 - *
1705 - * @return bool
1706 - * False all the time, used for debug.
1707 - */
1708 - public static function throwException($message, $type = 'error') {
1709 - if (defined('WTOTEM_THROW_EXCEPTIONS') && WTOTEM_THROW_EXCEPTIONS === true && is_string($message) ) {
1710 - $message = str_replace( '<strong>WebTotem:</strong>', ($type === 'error' ? __('Error:', 'wtotem') : __('Info:', 'wtotem')), $message );
1711 - throw new Exception($message, $type === 'error' ? 157 : 333);
1712 - }
1713 - return false;
1714 - }
1715 -
1716 - /**
1717 - * Get audit logs data
1718 - *
1719 - * @return array
1720 - */
1721 - public static function getAuditLogs($data, $dates_count) {
1722 - $logs = [];
1723 - foreach ($data as $datum){
1724 - $date_time = strtotime($datum['created_at']);
1725 - $date = self::dateFormatter($date_time, 'M j, Y');
1726 -
1727 - $logs[$date]['date'] = $date;
1728 - $logs[$date]['count'] = $dates_count[$date];
1729 - $logs[$date]['logs'][] = [
1730 - 'time' => self::dateFormatter($date_time,'H:i'),
1731 - 'user_name' => $datum['user_name'],
1732 - 'status' => $datum['status'],
1733 - 'title' => $datum['title'],
1734 - 'event' => $datum['event'],
1735 - 'description' => $datum['description'],
1736 - 'ip' => $datum['ip'],
1737 - 'viewed' => (int) !$datum['viewed']
1738 - ];
1739 - }
1740 - return $logs;
1741 - }
1742 -
1743 1285 /**
1744 - * Get confidential files data
1286 + * Get notifications array.
1745 1287 *
1746 1288 * @return array
1289 + * Returns notifications array.
1747 1290 */
1748 - public static function getConfidentialFiles($data) {
1749 - foreach ($data as $key => $datum){
1750 - $data[$key]['modified_at'] = date_i18n('M j, Y \/ H:i', strtotime($datum['modified_at']));
1751 - $data[$key]['size'] = self::humanFilesize($datum['size']);
1752 - $data[$key]['name'] = urldecode($datum['name']);
1753 - $data[$key]['path'] = urldecode($datum['path']);
1754 - }
1755 - return $data;
1756 - }
1291 + public static function getNotifications() {
1757 1292
1758 - /**
1759 - * Get confidential files data
1760 - *
1761 - * @return array
1762 - */
1763 - public static function prepareLinksData($data) {
1764 - foreach ($data as $key => $datum){
1293 + $notifications_data = WebTotemOption::getNotificationsData();
1294 + $notifications = [];
1765 1295
1766 - $content = $datum['content'];
1767 - $source = $datum['source'];
1768 - if(strpos($content, 'http://') !== 0 and strpos($content, 'https://') !== 0 and strpos($content, '//') !== 0){
1769 - $match = substr_count($content, '../');
1770 - $content = str_replace("../", "", $content);
1771 - $content = ltrim($content, '/');
1296 + foreach ($notifications_data as $notification) {
1297 + switch ($notification['type']) {
1298 + case 'error':
1299 + $image = 'alert-error.svg';
1300 + $class = 'wtotem_alert__title_red';
1301 + break;
1772 1302
1773 - for($i=0; $i < 1+$match; $i++){
1774 - $source = substr($source, 0, strrpos($source, "/"));
1775 - }
1776 - $data[$key]['link'] = $source . '/' . $content;
1777 - } else {
1778 - $data[$key]['link'] = $content;
1779 - }
1780 - }
1781 - return $data;
1782 - }
1303 + case 'warning':
1304 + $image = 'alert-warning.svg';
1305 + $class = 'wtotem_alert__title_yellow';
1306 + break;
1783 1307
1308 + case 'success':
1309 + $image = 'alert-success.svg';
1310 + $class = 'wtotem_alert__title_green';
1311 + break;
1784 1312
1785 - /**
1786 - * Building navigation and forming a template
1787 - *
1788 - * @param integer $limit
1789 - * number of entries per 1 page
1790 - * @param integer $count_all
1791 - * total number of all entries
1792 - * @param integer $currentPage
1793 - * the number of the page being viewed
1794 - * @param integer $nextPrev
1795 - * Show the "Forward" and "Back" buttons
1796 - * @return mixed
1797 - * Generated navigation template ready for output
1798 - */
1799 - public static function paginationBuild($limit, $count_all, $currentPage = 1, $nextPrev = true) {
1800 - if( $limit < 1 OR $count_all <= $limit ) return '';
1801 - $count_pages = ceil( $count_all / $limit );
1313 + case 'info':
1314 + $image = 'info-blue.svg';
1315 + $class = 'wtotem_alert__title_blue';
1316 + break;
1317 + }
1802 1318
1803 - $spread = 3;
1804 - $separator = "<i>...</i>";
1805 - $wrap = "<div class=\"wtotem_pagination\">{pages}</div>";
1806 -
1807 - $nextTitle = '←';
1808 - $prevTitle = '→';
1809 -
1810 - $currentPage = intval( $currentPage );
1811 - if( $currentPage < 1 ) $currentPage = 1;
1812 -
1813 - $shift_start = max( $currentPage - $spread, 2 );
1814 - $shift_end = min( $currentPage + $spread, $count_pages-1 );
1815 - if( $shift_end < $spread * 2 ) {
1816 - $shift_end = min( $spread * 2, $count_pages-1 );
1817 - }
1818 - if( $shift_end == $count_pages - 1 AND $shift_start > 3 ) {
1819 - $shift_start = max( 3, min( $count_pages - $spread * 2 + 1, $shift_start ) );
1820 - }
1821 -
1822 - $list = self::getPaginationItem( 1, $currentPage );
1823 -
1824 - if ($shift_start == 3) {
1825 - $list .= self::getPaginationItem( 2, $currentPage );
1826 - } elseif ( $shift_start > 3 ) {
1827 - $list .= $separator;
1828 - }
1829 -
1830 - for( $i = $shift_start; $i <= $shift_end; $i++ ) {
1831 - $list .= self::getPaginationItem( $i, $currentPage );
1832 - }
1833 -
1834 - $last_page = $count_pages - 1;
1835 - if( $shift_end == $last_page-1 ){
1836 - $list .= self::getPaginationItem( $last_page, $currentPage );
1837 - } elseif( $shift_end < $last_page ) {
1838 - $list .= $separator;
1839 - }
1840 -
1841 - $list .= self::getPaginationItem( $count_pages, $currentPage );
1842 -
1843 - if( $nextPrev ) {
1844 - $list = self::getPaginationItem(
1845 - $currentPage > 1 ? $currentPage - 1 : 0,
1846 - $currentPage,
1847 - $nextTitle)
1848 - . $list
1849 - . self::getPaginationItem(
1850 - $currentPage < $count_pages ? $currentPage + 1 : 0,
1851 - $currentPage,
1852 - $prevTitle
1853 - );
1854 - }
1855 -
1856 - return str_replace( "{pages}", $list, $wrap );
1319 + $notifications[] = [
1320 + "text" => $notification['notice'],
1321 + "id" => self::generateRandomString(8),
1322 + "type" => self::getStatusText($notification['type']),
1323 + "image" => $image,
1324 + "class" => $class,
1325 + ];
1857 1326 }
1858 1327
1859 - /**
1860 - * Button/Link Formation
1861 - * @param int $page_num
1862 - * page number
1863 - * @param string $currentPage
1864 - * current page
1865 - * @param string $page_name
1866 - * if specified, the text will be displayed instead of the page number
1867 - * @return string
1868 - * span block with active page or link.
1869 - */
1870 - public static function getPaginationItem( $page_num, $currentPage, $page_name = '' ) {
1871 - if($page_num === 0){return '';}
1872 - $page_name = $page_name ?: $page_num;
1328 + return $notifications;
1329 + }
1873 1330
1874 - if( $currentPage == $page_num ) {
1875 - return "<span class=\"wtotem_pagination__number wtotem_pagination__number_active\">{$page_name}</span>";
1876 - } else {
1877 - return "<a href=\"#\" data-page=\"{$page_num}\" class=\"wtotem_pagination__number\">{$page_name}</a>";
1878 - }
1879 - }
1880 -
1881 - /**
1882 - * Get notifications array.
1883 - *
1884 - * @return array
1885 - * Returns notifications array.
1886 - */
1887 - public static function getNotifications() {
1888 -
1889 - $notifications_data = WebTotemOption::getNotificationsData();
1890 - $notifications = [];
1891 -
1892 - foreach ($notifications_data as $notification) {
1893 - switch ($notification['type']) {
1894 - case 'error':
1895 - $image = 'alert-error.svg';
1896 - $class = 'wtotem_alert__title_red';
1897 - break;
1898 -
1899 - case 'warning':
1900 - $image = 'alert-warning.svg';
1901 - $class = 'wtotem_alert__title_yellow';
1902 - break;
1903 -
1904 - case 'success':
1905 - $image = 'alert-success.svg';
1906 - $class = 'wtotem_alert__title_green';
1907 - break;
1908 -
1909 - case 'info':
1910 - $image = 'info-blue.svg';
1911 - $class = 'wtotem_alert__title_blue';
1912 - break;
1913 - }
1914 -
1915 - $notifications[] = [
1916 - "text" => $notification['notice'],
1917 - "id" => self::generateRandomString(8),
1918 - "type" => self::getStatusText($notification['type']),
1919 - "type_raw" => $notification['type'],
1920 - "image" => $image,
1921 - "class" => $class,
1922 - ];
1923 - }
1924 -
1925 - return $notifications;
1926 - }
1927 -
1928 1331 /**
1929 1332 * Get current agent installation statuses.
1930 1333 *
1931 1334 * @param array $agents_statuses
@@ -1936,9 +1339,10 @@
1936 1339 */
1937 1340 public static function getAgentsStatuses(array $agents_statuses) {
1938 1341 $agents = ['am', 'waf', 'av'];
1939 1342 $installing_statuses = [
1940 - 'not_available',
1343 + 'not_installed',
1344 + 'installing',
1941 1345 'internal_error',
1942 1346 'update_error',
1943 1347 'config_error',
1944 1348 'session_error',
@@ -1952,9 +1356,9 @@
1952 1356 $option_statuses[$agent] = $status['option_status'] ?: FALSE;
1953 1357
1954 1358 if ($agent == 'am') {
1955 1359 if ($status['file_status']) {
1956 - $process_statuses[$agent] = 'available';
1360 + $process_statuses[$agent] = 'installed';
1957 1361 }
1958 1362 else {
1959 1363 $process_statuses[$agent] = 'failed';
1960 1364 }
@@ -1963,13 +1367,13 @@
1963 1367 if ($status['file_status']) {
1964 1368 if (in_array($agents_statuses[$agent], $installing_statuses)) {
1965 1369 $process_statuses[$agent] = 'installing';
1966 1370 }
1967 - elseif ($agents_statuses[$agent] == 'not_available') {
1371 + elseif ($agents_statuses[$agent] == 'agent_not_available') {
1968 1372 $process_statuses[$agent] = 'failed';
1969 1373 }
1970 1374 else {
1971 - $process_statuses[$agent] = 'available';
1375 + $process_statuses[$agent] = 'installed';
1972 1376 }
1973 1377 }
1974 1378 else {
1975 1379 $process_statuses[$agent] = 'installing';