PluginProbe
WebTotem Security / 2.3.22
WebTotem Security v2.3.22
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
wt-security / library / WT.php

WT.php in WebTotem Security 2.3.22, at library/WT.php

507 lines 26.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php defined('ABSPATH') or die("Protected By WT!");
2
3
4 class WTSEC_LIBRARY_WT
5 {
6
7 const URL = "https://api.wtotem.com/graphql";
8
9 public static function auth($key)
10 {
11 $source = WTSEC_SITE_URL;
12 $payload = '{"query":"mutation{ guest{ apiKeys{ auth(apiKey:\"' . $key . '\", source:\"' . $source . '\"),{ token{ value,refreshToken,expiresIn } } } } }"}';
13 return self::requestApi($payload, false, true);
14 }
15
16 protected static function requestApi($payload, $token = false, $repeat = false)
17 {
18 if ($token) {
19 $token = WTSEC_LIBRARY_App::getToken();
20 }
21
22 $token_expired = wtsec_app()->get("token_expired");
23
24 if($token_expired <= time() && !$repeat){
25 $result = WTSEC_LIBRARY_WT::auth(wtsec_app()->get("api_key"));
26 if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) {
27 $expiresIn = $result['data']['guest']['apiKeys']['auth']['token']['expiresIn'];
28 $token_expired = time() + $expiresIn - 60;
29 wtsec_app()->set("token_expired", $token_expired);
30
31 $token_ = $result['data']['guest']['apiKeys']['auth']['token']['value'];
32 WTSEC_LIBRARY_App::login($token_);
33 return self::requestApi($payload, $token, true);
34 } else {
35 WTSEC_LIBRARY_App::logout();
36 }
37 }
38
39
40 $args = [
41 'body' => $payload,
42 'timeout' => '60',
43 'sslverify' => false,
44 'headers' => ['Content-Type:application/json', 'Content-Type' => 'application/json', 'source:WORDPRESS', 'Accept: application/json'],
45 ];
46 if (!is_null($token) && $token) {
47 $authorization = "Bearer " . $token;
48 $args['headers'] = array_merge($args['headers'], ["Authorization" => $authorization]);
49 }
50 $response = wp_remote_post(self::URL, $args);
51 $httpcode = wp_remote_retrieve_response_code($response);
52
53 if ($httpcode < 200) {
54 WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server'));
55 }
56 $response = wp_remote_retrieve_body($response);
57 $result = json_decode($response, true);
58 if (isset($result['errors'][0]['message'])) {
59 $message = self::diffMesageForHuman($result['errors'][0]['message']);
60 if (stripos($result['errors'][0]['message'], "token") !== false && !$repeat) {
61 $result = WTSEC_LIBRARY_WT::auth(wtsec_app()->get("api_key"));
62 if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) {
63 $token_ = $result['data']['guest']['apiKeys']['auth']['token']['value'];
64 WTSEC_LIBRARY_App::login($token_);
65 return self::requestApi($payload, $token, true);
66 } else {
67 WTSEC_LIBRARY_App::logout();
68 }
69 } else {
70 if ($message !== false) {
71 WTSEC_LIBRARY_Session::setNotification("warning", $message);
72 }
73 }
74 }
75 return $result;
76 }
77
78 public static function diffMesageForHuman($message)
79 {
80 $definition = $message;
81 $excepts = [
82 "RESOURCE_NOT_FOUND", "DUPLICATE_HOST", "INVALID_CREDENTIALS", "INVALID_API_KEY", "Invalid token",
83 ];
84 if (in_array($message, $excepts)) {
85 return false;
86 }
87 switch ($message) {
88 case 'HOSTS_LIMIT_EXCEEDED':
89 $definition = WTSEC_LIBRARY_Localization::lmsg('hosts_limit_exceed');
90 break;
91 case 'Invalid token':
92 $definition = WTSEC_LIBRARY_Localization::lmsg('invalid_token');
93 break;
94 case 'USER_ALREADY_REGISTERED':
95 $definition = WTSEC_LIBRARY_Localization::lmsg('user_already_exist');
96 break;
97 case 'DUPLICATE_HOST':
98 $definition = WTSEC_LIBRARY_Localization::lmsg('duplicate_host');
99 break;
100 case 'INVALID_DOMAIN_NAME':
101 $definition = WTSEC_LIBRARY_Localization::lmsg('invalid_domain_name');
102 break;
103 }
104 return $definition;
105 }
106
107 //del
108 public static function requestURL($url)
109 {
110 $args = [
111 'timeout' => '30',
112 'sslverify' => false,
113 ];
114 $response = wp_remote_get($url, $args);
115 $httpcode = wp_remote_retrieve_response_code($response);
116 if ($httpcode < 200) {
117 WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server')." requestURL");
118 }
119 $response = wp_remote_retrieve_body($response);
120 return $response;
121 }
122
123
124 public static function getFileByUrl($url, $fileName)
125 {
126 $url = $url.'/'.$fileName;
127 $args = [
128 'timeout' => '30',
129 'sslverify' => false,
130 ];
131 $response = wp_remote_get($url, $args);
132 $httpcode = wp_remote_retrieve_response_code($response);
133 if ($httpcode < 200) {
134 WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server')." getFileByUrl");
135 }
136
137 $response = wp_remote_retrieve_body($response);
138 return ["body" => $response, "filename" => $fileName];
139 }
140
141
142 public static function getEmail(){
143 $payload = '{"query":"query { auth { viewer { email __typename } __typename } }"}';
144 $result = self::requestApi($payload, true);
145
146 return $result['data']['auth']['viewer']['email'];
147 }
148
149 public static function getOwnSite($attempt = false)
150 {
151 $sites = [
152 WTSEC_LIBRARY_Idn::idn_to_utf8(WTSEC_SITE_URL),
153 WTSEC_LIBRARY_Idn::idn_to_utf8('www.'.WTSEC_SITE_URL)
154 ];
155
156 foreach ($sites as $site){
157 $payload = '{"query":"query getSites { auth { viewer { sites { ...sites } } } }fragment sites on SiteQueries { list( filter: {search: \"'.$site.'\"} ) { edges { node { id hostname title ssl { status } availability { status } reputation { status } ports { status } deface { status } domain { status } antivirus { status } firewall { status } maliciousScript { stack { name } } } } } }"}';
158 $result = self::requestApi($payload, true);
159
160 if (isset($result['data']['auth']['viewer']['sites']['list']['edges'][0]['node'])){
161 return $result['data']['auth']['viewer']['sites']['list']['edges'][0]['node'];
162 }
163 }
164
165 $add_site = self::addSite(WTSEC_SITE_URL);
166 if (isset($add_site['errors'])) {
167 return $result['data']['node'] = [];
168 } else {
169 if (!$attempt) {
170 return self::getOwnSite(true);
171 }
172 }
173
174 return [];
175 }
176
177 public static function addSite($url)
178 {
179 $payload = '{"variables":{"input":{"title":"' . $url . '","hostname":"' . $url . '","configs":{"scheme":"http","port":80,"wa":{},"dec":{},"ps":{}}}},"query":"mutation ($input: CreateSiteInput) { auth { sites { create(input: $input) { id hostname title } } }}"}';
180 return self::requestApi($payload, true);
181 }
182
183 public static function getAllChecks($host_id)
184 {
185 $from = time() - (60 * 60 * 24 * 7);
186 $to = time();
187 $from_waf = time() - (60 * 60 * 24 * 30);
188 $language = WTSEC_LANGUAGE;
189 $payload = '{"query":"query($id: ID!, $dateRange: DateRangeInput!, $language: Language!, $dateRangeWeek: DateRangeInput!, $wafLogFilter: WafLogFilter!) { auth { viewer { sites { one(id: $id) { ports { status ip tcp lastTest { time } } availability { status lastTest { time } responseTime downTime(dateRange: $dateRange) percent(dateRange: $dateRange) } deface { status lastTest { time } words count } domain { status registrar owner email createdDate expiredDate } ports { status lastTest { time } ip tcp country } ssl { status daysLeft expiryDate issueDate } reputation { status lastTest { time } virusList { virus{ type path } antiVirus } } firewall { lastTest { time } logs(wafLogFilter: $wafLogFilter){ edges{ node{ type blocked payload ip location{ country{ nameEn } } time request status country category } } } map(dateRange: $dateRange) { attacks, country } status chart(dateRange: $dateRange) { time attacks blocked } report(dateRange: $dateRange) { time attacks ip } } serverStatus { info { phpVersion phpServerUser phpServerSoftware phpGatewayInterface phpServerProtocol osInfo cpuCount cpuModel CpuFreq cpuFamily lsCpu maxExecTime mathLibraries } ramChart(dateRange: $dateRangeWeek){ total value time } cpuChart(dateRange: $dateRangeWeek){ value time } discUsage{ total free } status } maliciousScript { lastTest { time } status } scoring( language: $language ){ score lastTest{ time } result{ ip country isHigherThan }} agentManager{ createdAt } antivirus { status stats { changed deleted scaned infected error } lastTest { time } isFirstCheck } } } } } }","variables":{"id":"' . $host_id . '","dateRange":{"to":' . $to . ',"from":' . $from_waf . '}, "dateRangeWeek":{"to":' . $to . ',"from":' . $from . '}, "wafLogFilter": {"order":{"direction":"DESC","field":"time"},"pagination":{"first":5,"cursor":null}}, "language":"'.$language.'"}}';
190 $response = self::requestApi($payload, true);
191 if (isset($response['data']['auth']['viewer']['sites']['one'])) {
192 return $response['data']['auth']['viewer']['sites']['one'];
193 }
194 return [];
195 }
196
197 public static function getFirewall($host_id, $limit = 20, $cursor = null, $days = 365)
198 {
199 $from = (is_array($days)) ? $days['from'] : time() - (60 * 60 * 24 * $days);
200 $to = (is_array($days)) ? $days['to'] : time();
201 $cursor = ($cursor == null) ? 'null' : '"'.$cursor.'"';
202
203 $payload = '{"operationName":"FirewallAttackLog","variables":{"dateRange":{"to":'.$to.',"from":'.$from.'},"id":"'.$host_id.'","wafLogFilter":{"dateRange":{"to":'.$to.',"from":'.$from.'},"order":{"direction":"DESC","field":"time"},"pagination":{"first":'.$limit.',"cursor":' . $cursor . '}}},"query":"query FirewallAttackLog($id: ID!, $wafLogFilter: WafLogFilter!, $dateRange: DateRangeInput!) { auth { viewer { sites { one(id: $id) { firewall { lastTest { time } settings{ gdn dosProtection dosLimit loginAttemptsProtection loginAttemptsLimit } status... FirewallLogFragment map(dateRange: $dateRange) { attacks, country } __typename } __typename } __typename } __typename } __typename } } fragment FirewallLogFragment on Waf { logs(wafLogFilter: $wafLogFilter) { edges { cursor node { type blocked payload ip location { country { nameEn __typename } __typename } time request status country category __typename } __typename } pageInfo { endCursor hasNextPage __typename } __typename } __typename }"}';
204 $res = self::requestApi($payload, true);
205
206 return $res;
207 }
208
209 public static function getAntivirus($params)
210 {
211 $permissionsChanged = $params['permissionsChanged'] ? ' "permissionsChanged":true, ' : '';
212
213 $event = $params['event'] ?: 'new';
214 $event = $params['permissionsChanged'] ? '' : '"event":"'.$event.'", ';
215
216 $days = $params['days'];
217
218 $from = (is_array($days)) ? $days['from'] : time() - (60 * 60 * 24 * $days);
219 $to = (is_array($days)) ? $days['to'] : time();
220 $cursor = ($params['endCursor'] == null) ? 'null' : '"' . $params['endCursor'] . '"';
221 $payload = '{"operationName":null,"variables":{"id":"' . $params['host_id'] . '","avLogFilter":{'. $permissionsChanged . $event .' "dateRange":{"to":'.$to.',"from":'.$from.'},"order":{"direction":"DESC","field":"time"},"pagination":{"first":' . $params['limit'] . ',"cursor":' . $cursor . '}}},"query":"query ($id: ID!, $avLogFilter: AvLogFilter!) { auth { viewer { sites { one(id: $id) { id ... on Site { configs { ... on AvConfig { isActive id } } } antivirus { status log(avLogFilter: $avLogFilter) { edges { node { filePath matches event signatures time permissions permissionsChanged } } pageInfo { endCursor hasNextPage __typename } } lastTest { time } stats { changed deleted scaned infected } } } } } } }"}';
222 return self::requestApi($payload, true);
223 }
224
225 public static function getFirewallChart($host_id, $days = 7)
226 {
227 $to = time();
228 $from_waf = ($days <= 1) ? strtotime(date('Y-m-d 00:00:01')) : time() - (60 * 60 * 24 * $days);
229
230 $payload = '{ "query":"query($id: ID!, $dateRange: DateRangeInput!, $wafLogFilter: WafLogFilter!) { auth { viewer { sites { one(id: $id) { firewall { lastTest { time } status logs(wafLogFilter: $wafLogFilter) { edges { node { status country type userAgent } } } chart(dateRange: $dateRange) { time attacks blocked } report(dateRange: $dateRange) { time attacks ip } } } } } } }", "operationName":null,"variables":{"id":"' . $host_id . '","dateRange":{"to":' . $to . ',"from":' . $from_waf . '}, "wafLogFilter": { "dateRange": { "from": ' .$from_waf. ', "to": ' .$to. ' }, "pagination": { "cursor": null }, "order": { "direction": "DESC", "field": "time" } } } }';
231 $response = self::requestApi($payload, true);
232 return $response['data']['auth']['viewer']['sites']['one']['firewall']['chart'];
233 }
234
235 public static function forceCheck($host_id, $service)
236 {
237 $payload = '{"variables":{"id":"'.$host_id.'","service":"'.$service.'"},"query":"mutation ($id: ID!, $service: ForceCheckService!) { auth { sites { forceCheck(siteId: $id, service: $service) } } }"} ';
238 return self::requestApi($payload, true);
239 }
240
241 public static function avExport($host_id)
242 {
243 $from = time() - (60 * 60 * 24 * 30);
244 $to = time();
245 $payload = '{"variables":{ "input":{"siteId":"'.$host_id.'", "dateRange":{"to":'.$to.',"from":'.$from.'} }},"query":"mutation ($input: AvLogExportInput!) { auth { sites { av { export(input: $input) } } } }"} ';
246 return self::requestApi($payload, true);
247 }
248
249 public static function changeStatus($config_id, $host_id)
250 {
251 $payload = '{"query":"\n mutation {\n toggleServiceConfig(\n id: ' . $config_id . '\n userhostId: ' . $host_id . '\n ) {\n isActive\n }\n }\n "}';
252 return self::requestApi($payload, true);
253 }
254
255 public static function serviceConnect($id, $service)
256 {
257 $payload = '{"query":"mutation {\n auth {\n agents{\n check(siteId:\"' . $id . '\",service:' . strtolower($service) . ',plugin:WORDPRESS)\n }\n }\n}\n"}';
258 return self::requestApi($payload, true);
259 }
260
261 public static function generateFile($id, $service)
262 {
263 $payload = '{"query":"mutation {\n auth {\n agents{\n generate(siteId:\"' . $id . '\",service:' . strtolower($service) . '){\n agentName\n }\n }\n }\n}\n"}';
264 return self::requestApi($payload, true);
265 }
266
267 public static function generateAmFile($id)
268 {
269 $payload = '{ "operationName":null, "variables":{}, "query":"mutation { auth { am { install(siteId: \"'.$id.'\"){ downloadLink, amFilename, wafFilename, avFilename } } } }"}';
270 return self::requestApi($payload, true);
271 }
272
273 public static function deleteAm($id)
274 {
275 $payload = '{ "query":"mutation { auth { am { delete(siteId: \"'.$id.'\") } } }"}';
276 return self::requestApi($payload, true);
277 }
278
279 public static function checkStatus($id, $service)
280 {
281 $payload = '{"operationName":null,"variables":{"id":"' . $id . '"},"query":"query ($id: ID!) {\n auth {\n viewer {\n sites {\n one(id: $id) {\n ... on Site {\n configs {\n ... on ' . $service . 'Config {\n isActive\n id\n }\n }\n }\n }\n }\n }\n }\n}\n"}';
282 return self::requestApi($payload, true);
283 }
284
285
286 public static function getQuarantineList($host_id)
287 {
288 $payload = '{"query":"query{ auth{ viewer{ sites{ one(id:\"'.$host_id.'\"){ antivirus{ quarantine{ id path date } } } } } } } "}';
289 return self::requestApi($payload, true);
290 }
291
292 public static function moveToQuarantine($host_id, $path)
293 {
294 $payload = '{"query":"mutation{ auth{ sites{ av{ moveToQuarantine(input:{ siteId:\"'.$host_id.'\", path:\"'.$path.'\" }) } } } } "}';
295 return self::requestApi($payload, true);
296 }
297
298 public static function moveFromQuarantine($id)
299 {
300 $payload = '{"query":"mutation{ auth{ sites{ av{ moveFromQuarantine(id: \"'.$id.'\") } } } } "}';
301 return self::requestApi($payload, true);
302 }
303
304 public static function reportsList($host_id, $limit = 10, $cursor = null)
305 {
306 $cursor = ($cursor == null) ? 'null' : '"' . $cursor . '"';
307 $payload = '{"variables":{ "filter": { "order": { "direction": "DESC", "field": "created_at"}, "siteId":"'.$host_id.'", "pagination":{"first":' . $limit . ', "cursor":' . $cursor . '} } },"query":"query ReportsQuery($filter: ReportListFilter!) { auth { viewer { reports { list(filter: $filter) { edges { node { id site { hostname } createdAt wa dc ps rc sc av waf } cursor } pageInfo { endCursor hasNextPage } } } } } }"}';
308 return self::requestApi($payload, true);
309 }
310
311 public static function reportGenerate($host_id, $period, $services, $language = "en")
312 {
313 $from = (is_array($period)) ? $period['from'] : time() - (60 * 60 * 24 * $period);
314 $to = (is_array($period)) ? $period['to'] : time();
315 $payload = '{"query":"query ($input: GenerateReportInput) { auth { viewer { reports { generate(input: $input) } } } }", "variables":{ "input": { "siteId": "' . $host_id . '", "from": ' . $from . ', "to": ' . $to . ', "wa": '.$services['wa'].', "dc": '.$services['dc'].', "ps": '.$services['ps'].', "rc": '.$services['rc'].', "sc": '.$services['sc'].', "av": '.$services['av'].', "waf": '.$services['waf'].', "language": "'.$language.'" } } }';
316
317 return self::requestApi($payload, true);
318 }
319
320 public static function reportDownload($id)
321 {
322 $payload = '{"query": "query { auth { viewer { reports { download(id: \"' . $id . '\") } } } }"}';
323 return self::requestApi($payload, true);
324 }
325
326 public static function getConfigs($host_id)
327 {
328 $payload = '{"query":"query{ auth{ viewer{ sites{ one(id:\"'.$host_id.'\"){ configs{ ... on WaConfig { id service isActive } ... on AvConfig { id service isActive } ... on DcConfig { id service isActive } ... on DecConfig { id service isActive } ... on RcConfig { id service isActive } ... on CmsConfig { id service isActive } ... on PsConfig { id service isActive } ... on WafConfig { id service isActive } } } } } } } "}';
329 return self::requestApi($payload, true);
330 }
331
332 public static function toggleConfigs($service_id)
333 {
334 $payload = '{"query":"mutation{ auth{ configs{ toggle(id: \"'.$service_id.'\"){ ... on WaConfig { service isActive } ... on AvConfig { service isActive } ... on DcConfig { service isActive } ... on DecConfig { service isActive } ... on RcConfig { service isActive } ... on CmsConfig { service isActive } ... on PsConfig { service isActive } ... on WafConfig { service isActive } } } } } "}';
335 return self::requestApi($payload, true);
336 }
337
338 public static function wafSettings($host_id, $settings)
339 {
340 $payload = '{"variables":{"input": {"siteId": "'.$host_id.'", "gdn": '. $settings['gdn'] .', "dosProtection": '.$settings['dosProtection'].', "dosLimit": '.$settings['dosLimit'].', "loginAttemptsProtection": '.$settings['loginAttemptsProtection'].', "loginAttemptsLimit": '.$settings['loginAttemptsLimit'].'}},"query":"mutation WafSettings($input: WafSettingsInput!) { auth { sites { waf{ settings(input: $input) { gdn dosProtection loginAttemptsProtection dosLimit loginAttemptsLimit } } } } }"}';
341 return self::requestApi($payload, true);
342 }
343
344 public static function getServerStatusChart($host_id, $days = 7)
345 {
346 $to = time();
347 $from = ($days <= 1) ? strtotime(date('Y-m-d 00:00:01')) : time() - (60 * 60 * 24 * $days);
348
349 $payload = '{ "query":"query($id: ID!, $dateRange: DateRangeInput!) { auth { viewer { sites { one(id: $id) { serverStatus { ramChart(dateRange: $dateRange){ total value time } cpuChart(dateRange: $dateRange){ value time } } } } } } }", "variables":{"id":"' . $host_id . '","dateRange":{"to":' . $to . ',"from":' . $from . '} } }';
350
351 $response = self::requestApi($payload, true);
352 return $response['data']['auth']['viewer']['sites']['one']['serverStatus'];
353 }
354
355 public static function getStatusIcon($status)
356 {
357 $statuses = [
358 "clean" => [
359 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.ok'),
360 "color" => self::getColor("success"),
361 "image" => "check-mark.svg"
362 ],
363 "pending" => [
364 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.pending'),
365 "color" => self::getColor("grey"),
366 "image" => "loading.svg"
367 ],
368 "pause" => [
369 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.pause'),
370 "color" => self::getColor("grey"),
371 "image" => "warning.svg"
372 ],
373 "expired" => [
374 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.expired'),
375 "color" => self::getColor("orange"),
376 "image" => "warning.svg"
377
378 ],
379 "invalid" => [
380 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.invalid'),
381 "color" => self::getColor("error"),
382 "image" => "warning.svg"
383 ],
384 "no_cert" => [
385 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.no_cert'),
386 "color" => self::getColor("orange"),
387 "image" => "warning.svg"
388 ],
389 "error" => [
390 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.error'),
391 "color" => self::getColor("error"),
392 "image" => "warning.svg"
393 ],
394 "expires" => [
395 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.expires'),
396 "color" => self::getColor("orange"),
397 "image" => "warning.svg"
398 ],
399 "expires_today" => [
400 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.expires_today'),
401 "color" => self::getColor("error"),
402 "image" => "warning.svg"
403 ],
404 "down" => [
405 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.down'),
406 "color" => self::getColor("error"),
407 "image" => "warning.svg"
408 ],
409 "up" => [
410 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.up'),
411 "color" => self::getColor("success"),
412 "image" => "check-mark.svg"
413 ],
414 "infected" => [
415 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.infected'),
416 "color" => self::getColor("error"),
417 "image" => "warning.svg"
418 ],
419 "open_ports" => [
420 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.open'),
421 "color" => self::getColor("orange"),
422 "image" => "warning.svg"
423 ],
424 "deface" => [
425 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.deface'),
426 "color" => self::getColor("error"),
427 "image" => "warning.svg"
428 ],
429 "modified" => [
430 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.modified'),
431 "color" => self::getColor("grey"),
432 "image" => "warning.svg"
433 ],
434 "not_supported" => [
435 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.unsupported'),
436 "color" => self::getColor("orange"),
437 "image" => "warning.svg"
438 ],
439 "not_registered" => [
440 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.not_registered'),
441 "color" => self::getColor("orange"),
442 "image" => "warning.svg"
443 ],
444 "not_installed" => [
445 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.not_installed'),
446 "color" => self::getColor("error"),
447 "image" => "warning.svg"
448 ],
449 "working" => [
450 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.working'),
451 "color" => self::getColor("success"),
452 "image" => "check-mark.svg"
453 ],
454 ];
455 if (isset($statuses[$status])) {
456 $statuses[$status]['type'] = $status;
457 $statuses[$status]["text"] = "<span data-status='$status' class='" . $statuses[$status]["color"]["color"] . "'>" . $statuses[$status]["text"] . "</span>";
458 return $statuses[$status];
459 } else {
460 return ["image" => "warning.svg", "color" => "ww--status_unknow", "text" => "<span class='ww--status_unknow'>Unknown status</span>"];
461 }
462 }
463
464 public static function getColor($type)
465 {
466 $types = [
467 "green" => "is--status--ok",
468 "red" => "is--status--error",
469 "success" => "is--status--ok",
470 "error" => "is--status--error",
471 "orange" => "is--status--warning",
472 "warning" => "is--status--warning",
473 "grey" => "ww--status_unknow"
474 ];
475 $icon_types = [
476 "green" => "ww-icon--status_ok",
477 "red" => "ww-icon--status_error",
478 "success" => "ww-icon--status_ok",
479 "error" => "ww-icon--status_error",
480 "orange" => "ww-icon--status_warning",
481 "warning" => "ww-icon--status_warning",
482 "grey" => "ww-icon--status_unknow"
483 ];
484 return ["icon" => $icon_types[$type], "color" => $types[$type]];
485 }
486
487 public static function getConfigId($configs)
488 {
489 $id = 0;
490 $is_active = false;
491 foreach ($configs as &$config) {
492 if (!empty($config)) {
493 $id = $config['id'];
494 $is_active = $config['isActive'];
495 break;
496 }
497 }
498 return compact('id', 'is_active');
499 }
500
501 public static function getScore(){
502 return self::requestURL("https://api.wtotem.com/site/score?url=".WTSEC_SITE_URL);
503 }
504
505 }
506
507