PluginProbe
WebTotem Security / 2.3.24
WebTotem Security v2.3.24
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 | library/WT.php +199 -67 2.1.82.3.24 View file →
@@ -2,15 +2,16 @@
2 2
3 3
4 4 class WTSEC_LIBRARY_WT
5 5 {
6 - const URL = "https://api.wtotem.com/graphql";
7 -// const URL = "https://api-1.2ke2xgwx4.wtotem.com/graphql";
8 6
7 + const URL = "https://api.wtotem.com/graphql";
8 +
9 9 public static function auth($key)
10 10 {
11 - $payload = '{"query":"mutation{\n guest{\n apiKeys{\n auth(apiKey:\"' . $key . '\"),{\n token{\n value,refreshToken,expiresIn\n }\n }\n }\n }\n}"}';
12 - return self::requestApi($payload);
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);
13 14 }
14 15
15 16 protected static function requestApi($payload, $token = false, $repeat = false)
16 17 {
@@ -16,11 +17,30 @@
16 17 {
17 18 if ($token) {
18 19 $token = WTSEC_LIBRARY_App::getToken();
19 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 +
20 40 $args = [
21 41 'body' => $payload,
22 - 'timeout' => '30',
42 + 'timeout' => '60',
23 43 'sslverify' => false,
24 44 'headers' => ['Content-Type:application/json', 'Content-Type' => 'application/json', 'source:WORDPRESS', 'Accept: application/json'],
25 45 ];
26 46 if (!is_null($token) && $token) {
@@ -30,9 +50,9 @@
30 50 $response = wp_remote_post(self::URL, $args);
31 51 $httpcode = wp_remote_retrieve_response_code($response);
32 52
33 53 if ($httpcode < 200) {
34 - WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server')." requestApi");
54 + WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server'));
35 55 }
36 56 $response = wp_remote_retrieve_body($response);
37 57 $result = json_decode($response, true);
38 58 if (isset($result['errors'][0]['message'])) {
@@ -100,10 +120,11 @@
100 120 return $response;
101 121 }
102 122
103 123
104 - public static function getFileByUrl($url)
124 + public static function getFileByUrl($url, $fileName)
105 125 {
126 + $url = $url.'/'.$fileName;
106 127 $args = [
107 128 'timeout' => '30',
108 129 'sslverify' => false,
109 130 ];
@@ -111,67 +132,62 @@
111 132 $httpcode = wp_remote_retrieve_response_code($response);
112 133 if ($httpcode < 200) {
113 134 WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg('could_not_connect_to_the_server')." getFileByUrl");
114 135 }
115 - $filename = null;
116 - $metas = explode(";",$response['headers']["content-disposition"]);
117 - foreach ($metas as $meta){
118 - if(stripos($meta,"filename") !== false){
119 - $filename = trim(str_replace(["filename=","=","\""],"",$meta));
120 - }
121 - }
136 +
122 137 $response = wp_remote_retrieve_body($response);
123 - return ["body" => $response, "filename" => $filename];
138 + return ["body" => $response, "filename" => $fileName];
124 139 }
125 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 +
126 149 public static function getOwnSite($attempt = false)
127 150 {
128 - $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}"}';
151 + $sites = [
152 + WTSEC_LIBRARY_Idn::idn_to_utf8(WTSEC_SITE_URL),
153 + WTSEC_LIBRARY_Idn::idn_to_utf8('www.'.WTSEC_SITE_URL)
154 + ];
129 155
130 - $result = self::requestApi($payload, true);
131 - if (isset($result['data']['auth']['viewer']['sites']['list']['edges'])) {
132 - //mutator
133 - foreach ($result['data']['auth']['viewer']['sites']['list']['edges'] as &$m) {
134 - if (isset($m['node']['hostname'])) {
135 - $m['node']['hostname'] = WTSEC_LIBRARY_Idn::idn_to_utf8($m['node']['hostname']);
136 -// if ($m['node']['id'] == "c2l0ZV8yNTg=") {
137 -// return $m['node'];
138 -// }
139 - if (self::isSiteUrl($m['node']['hostname'])) {
140 - return $m['node'];
141 - }
142 - }
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'];
143 162 }
144 - $add_site = self::addSite(WTSEC_SITE_URL);
145 - if (isset($add_site['errors'])) {
146 - return $result['data']['node'] = [];
147 - } else {
148 - if (!$attempt) {
149 - return self::getOwnSite(true);
150 - }
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);
151 171 }
152 172 }
173 +
153 174 return [];
154 175 }
155 176
156 - public static function isSiteUrl($url)
157 - {
158 - return WTSEC_LIBRARY_Idn::idn_to_utf8(WTSEC_SITE_URL) === $url;
159 - }
160 -
161 177 public static function addSite($url)
162 178 {
163 - $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"}';
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 } } }}"}';
164 180 return self::requestApi($payload, true);
165 181 }
166 182
167 183 public static function getAllChecks($host_id)
168 184 {
169 - $from = time() - (60 * 60 * 24);
185 + $from = time() - (60 * 60 * 24 * 7);
170 186 $to = time();
171 - $from_waf = time() - (60 * 60 * 24 * 7);
172 - $payload = '{"query":"query($id: ID!, $dateRange:DateRangeInput!) {\n auth {\n viewer {\n sites {\n one(id: $id) {\n ports{\n status\n ip\n tcp\n lastTest{\n time\n }\n }\n availability {\n status\n lastTest {\n time\n }\n responseTime\n downTime(dateRange: $dateRange)\n percent(dateRange: $dateRange)\n }\n deface {\n status\n lastTest {\n time\n }\n words\n count\n }\n domain {\n status\n registrar\n owner\n email\n createdDate\n expiredDate\n }\n ports {\n status\n lastTest {\n time\n }\n ip\n tcp\n country\n }\n ssl {\n status\n daysLeft\n expiryDate\n issueDate\n }\n reputation {\n status\n lastTest {\n time\n }\n virusList {\n viruses\n antiVirus\n }\n }\n firewall {\n lastTest { \n time\n } \n status\n chart(dateRange: $dateRange) {\n time\n attacks\n blocked\n }\n report(dateRange: $dateRange) {\n time\n attacks\n ip\n }\n }\n maliciousScript{\n lastTest{\n time\n }\n status\n }\n antivirus{\n status \n stats { \n changed\n deleted\n scaned\n infected\n error\n } \n lastTest { \n time\n } \n isFirstCheck\n }\n }\n }\n }\n }\n}","variables":{"id":"' . $host_id . '","dateRange":{"to":' . $to . ',"from":' . $from_waf . '}}}';
173 -// $payload = '{"query":"query($id: ID!, $dateRange:DateRangeInput!) {\n auth {\n viewer {\n sites {\n one(id: $id) {\n ports{\n status\n ip\n tcp\n lastTest{\n time\n }\n }\n availability {\n status\n lastTest {\n time\n }\n responseTime\n downTime(dateRange: $dateRange)\n percent(dateRange: $dateRange)\n }\n deface {\n status\n lastTest {\n time\n }\n words\n count\n }\n domain {\n status\n registrar\n owner\n email\n createdDate\n expiredDate\n }\n ports {\n status\n lastTest {\n time\n }\n ip\n tcp\n country\n }\n ssl {\n status\n daysLeft\n expiryDate\n issueDate\n }\n reputation {\n status\n lastTest {\n time\n }\n virusList {\n viruses\n antiVirus\n }\n }\n firewall {\n lastTest { \n time\n } \n status\n logs{\n edges\n{\n node{\n status\n country\n type\n}\n}\n}\n chart(dateRange: $dateRange) {\n time\n attacks\n blocked\n }\n report(dateRange: $dateRange) {\n time\n attacks\n ip\n }\n }\n maliciousScript{\n lastTest{\n time\n }\n status\n }\n antivirus{\n status \n stats { \n changed\n deleted\n scaned\n infected\n error\n } \n lastTest { \n time\n } \n isFirstCheck\n }\n }\n }\n }\n }\n}","variables":{"id":"' . $host_id . '","dateRange":{"to":' . $to . ',"from":' . $from_waf . '}}}';
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.'"}}';
174 190 $response = self::requestApi($payload, true);
175 191 if (isset($response['data']['auth']['viewer']['sites']['one'])) {
176 192 return $response['data']['auth']['viewer']['sites']['one'];
177 193 }
@@ -177,8 +193,78 @@
177 193 }
178 194 return [];
179 195 }
180 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 wafGetIpList($host_id)
250 + {
251 + $payload = '{"variables":{ "id": "'.$host_id.'" },"query":"query($id: ID!) { auth { viewer { sites{ one(id: $id){ firewall{ blackList{ id ip createdAt } whiteList{ id ip createdAt } settings{ gdn dosProtection dosLimit loginAttemptsProtection loginAttemptsLimit } } } } } } }"} ';
252 + return self::requestApi($payload, true);
253 + }
254 +
255 + public static function wafAddIpToList($host_id, $ips, $color)
256 + {
257 + $payload = '{"variables":{ "input": { "siteId": "'.$host_id.'", "ips": "'.$ips.'", "color": "'.$color.'" } }, "query":"mutation($input: WafListInput!) { auth { sites { waf { addToList(input: $input) } } } }"} ';
258 + return self::requestApi($payload, true);
259 + }
260 +
261 + public static function wafRemoveIpToList($id)
262 + {
263 + $payload = '{"variables":{ "id": "'.$id.'" },"query":"mutation($id: ID!) { auth { sites { waf { removeFromList(id: $id) } } } }"} ';
264 + return self::requestApi($payload, true);
265 + }
266 +
181 267 public static function changeStatus($config_id, $host_id)
182 268 {
183 269 $payload = '{"query":"\n mutation {\n toggleServiceConfig(\n id: ' . $config_id . '\n userhostId: ' . $host_id . '\n ) {\n isActive\n }\n }\n "}';
184 270 return self::requestApi($payload, true);
@@ -197,12 +283,18 @@
197 283 }
198 284
199 285 public static function generateAmFile($id)
200 286 {
201 - $payload = '{"operationName":null,"variables":{},"query":"mutation {\n auth {\n am {\n install(siteId: \"'.$id.'\")\n }\n }\n}\n"}';
287 + $payload = '{ "operationName":null, "variables":{}, "query":"mutation { auth { am { install(siteId: \"'.$id.'\"){ downloadLink, amFilename, wafFilename, avFilename } } } }"}';
202 288 return self::requestApi($payload, true);
203 289 }
204 290
291 + public static function deleteAm($id)
292 + {
293 + $payload = '{ "query":"mutation { auth { am { delete(siteId: \"'.$id.'\") } } }"}';
294 + return self::requestApi($payload, true);
295 + }
296 +
205 297 public static function checkStatus($id, $service)
206 298 {
207 299 $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"}';
208 300 return self::requestApi($payload, true);
@@ -208,43 +300,75 @@
208 300 return self::requestApi($payload, true);
209 301 }
210 302
211 303
212 - public static function getAntivirus($host_id, $limit = 10, $cursor = null, $days = 365, $event = 'infected')
304 + public static function getQuarantineList($host_id)
213 305 {
214 - $from = (is_array($days)) ? $days['begin'] : time() - (60 * 60 * 24 * $days);
215 - $to = (is_array($days)) ? $days['end'] : time();
306 + $payload = '{"query":"query{ auth{ viewer{ sites{ one(id:\"'.$host_id.'\"){ antivirus{ quarantine{ id path date } } } } } } } "}';
307 + return self::requestApi($payload, true);
308 + }
309 +
310 + public static function moveToQuarantine($host_id, $path)
311 + {
312 + $payload = '{"query":"mutation{ auth{ sites{ av{ moveToQuarantine(input:{ siteId:\"'.$host_id.'\", path:\"'.$path.'\" }) } } } } "}';
313 + return self::requestApi($payload, true);
314 + }
315 +
316 + public static function moveFromQuarantine($id)
317 + {
318 + $payload = '{"query":"mutation{ auth{ sites{ av{ moveFromQuarantine(id: \"'.$id.'\") } } } } "}';
319 + return self::requestApi($payload, true);
320 + }
321 +
322 + public static function reportsList($host_id, $limit = 10, $cursor = null)
323 + {
216 324 $cursor = ($cursor == null) ? 'null' : '"' . $cursor . '"';
217 - $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 } } pageInfo { endCursor hasNextPage __typename } } lastTest { time } stats { changed deleted scaned infected } } } } } } }"}';
325 + $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 } } } } } }"}';
218 326 return self::requestApi($payload, true);
219 327 }
220 328
221 - public static function getOptions($host_id)
329 + public static function reportGenerate($host_id, $period, $services, $language = "en")
222 330 {
223 - $payload = '{"query":"query{\nuserHost(id:' . $host_id . '){\n id\n title\n hostname\n stack\n createdAt\n services {\n id\n name\n configs {\n id\n \tdata\n isActive\n }\n }\n }\n}"}';
331 + $from = (is_array($period)) ? $period['from'] : time() - (60 * 60 * 24 * $period);
332 + $to = (is_array($period)) ? $period['to'] : time();
333 + $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.'" } } }';
334 +
224 335 return self::requestApi($payload, true);
225 336 }
226 337
227 - public static function getFirewall($host_id, $limit = 20, $cursor = null, $days = 365)
338 + public static function reportDownload($id)
228 339 {
229 - $from = (is_array($days)) ? $days['begin'] : time() - (60 * 60 * 24 * $days);
230 - $to = (is_array($days)) ? $days['end'] : time();
231 - $cursor = ($cursor == null) ? 'null' : '"'.$cursor.'"';
340 + $payload = '{"query": "query { auth { viewer { reports { download(id: \"' . $id . '\") } } } }"}';
341 + return self::requestApi($payload, true);
342 + }
232 343
233 - $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 } 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 }"}';
234 - $res = self::requestApi($payload, true);
344 + public static function getConfigs($host_id)
345 + {
346 + $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 } } } } } } } "}';
347 + return self::requestApi($payload, true);
348 + }
235 349
236 - return $res;
350 + public static function toggleConfigs($service_id)
351 + {
352 + $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 } } } } } "}';
353 + return self::requestApi($payload, true);
237 354 }
238 355
239 - public static function getFirewallChart($host_id, $days = 7)
356 + public static function wafSettings($host_id, $settings)
240 357 {
358 + $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 } } } } }"}';
359 + return self::requestApi($payload, true);
360 + }
361 +
362 + public static function getServerStatusChart($host_id, $days = 7)
363 + {
241 364 $to = time();
242 - $from_waf = ($days <= 1) ? strtotime(date('Y-m-d 00:00:01')) : time() - (60 * 60 * 24 * $days);
365 + $from = ($days <= 1) ? strtotime(date('Y-m-d 00:00:01')) : time() - (60 * 60 * 24 * $days);
243 366
244 - $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" } } } }';
367 + $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 . '} } }';
245 368
246 - return self::requestApi($payload, true);
369 + $response = self::requestApi($payload, true);
370 + return $response['data']['auth']['viewer']['sites']['one']['serverStatus'];
247 371 }
248 372
249 373 public static function getStatusIcon($status)
250 374 {
@@ -258,8 +382,13 @@
258 382 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.pending'),
259 383 "color" => self::getColor("grey"),
260 384 "image" => "loading.svg"
261 385 ],
386 + "pause" => [
387 + "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.pause'),
388 + "color" => self::getColor("grey"),
389 + "image" => "warning.svg"
390 + ],
262 391 "expired" => [
263 392 "text" => WTSEC_LIBRARY_Localization::lmsg('statuses.expired'),
264 393 "color" => self::getColor("orange"),
265 394 "image" => "warning.svg"
@@ -341,11 +470,13 @@
341 470 "image" => "check-mark.svg"
342 471 ],
343 472 ];
344 473 if (isset($statuses[$status])) {
345 - return ["image" => $statuses[$status]["image"], "icon" => $statuses[$status]["color"]["icon"], "color" => $statuses[$status]["color"]["color"], "text" => "<span class='" . $statuses[$status]["color"]["color"] . "'>" . $statuses[$status]["text"] . "</span>"];
474 + $statuses[$status]['type'] = $status;
475 + $statuses[$status]["text"] = "<span data-status='$status' class='" . $statuses[$status]["color"]["color"] . "'>" . $statuses[$status]["text"] . "</span>";
476 + return $statuses[$status];
346 477 } else {
347 - return ["image" => "warning.svg", "icon" => "ww-icon--status_unknow", "color" => "ww--status_unknow", "text" => "<span class='ww--status_unknow'>Unknown status</span>"];
478 + return ["image" => "warning.svg", "color" => "ww--status_unknow", "text" => "<span class='ww--status_unknow'>Unknown status</span>"];
348 479 }
349 480 }
350 481
351 482 public static function getColor($type)
@@ -388,5 +519,6 @@
388 519 public static function getScore(){
389 520 return self::requestURL("https://api.wtotem.com/site/score?url=".WTSEC_SITE_URL);
390 521 }
391 522
392 -}
523 +}
524 +