PluginProbe
WebTotem Security / 2.3.13
WebTotem Security v2.3.13
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.13, at library/WT.php

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