PluginProbe
WebTotem Security / 2.3.35
WebTotem Security v2.3.35
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 2.2.4 All 109 releases
wt-security / uninstall.php

uninstall.php in WebTotem Security 2.3.35, at uninstall.php

112 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if( ! defined('WP_UNINSTALL_PLUGIN') )
3 exit;
4
5 if( ! defined('WTSEC_PLUGIN_PREFIX') )
6 define("WTSEC_PLUGIN_PREFIX", 'wtsec_');
7
8 define("WTSEC_API_URL", 'https://api.wtotem.com/graphql');
9
10 $key = get_option(WTSEC_PLUGIN_PREFIX.'api_key_safe');
11 $key = $key ?: get_option(WTSEC_PLUGIN_PREFIX.'api_key');
12
13 if($key){
14 if(deleteAM($key)){
15 deleteOptions();
16 } else{
17 exit();
18 }
19 }
20
21 function auth($key){
22 $payload = '{"query":"mutation{ guest{ apiKeys{ auth(apiKey:\"' . $key . '\"),{ token{ value,refreshToken,expiresIn } } } } }"}';
23 return requestApi($payload, false);
24 }
25
26
27 function requestApi($payload, $token = false)
28 {
29 $args = [
30 'body' => $payload,
31 'timeout' => '60',
32 'sslverify' => false,
33 'headers' => ['Content-Type:application/json', 'Content-Type' => 'application/json', 'source:WORDPRESS', 'Accept: application/json'],
34 ];
35 if (!is_null($token) && $token) {
36 $authorization = "Bearer " . $token;
37 $args['headers'] = array_merge($args['headers'], ["Authorization" => $authorization]);
38 }
39 $response = wp_remote_post(WTSEC_API_URL, $args);
40 $httpcode = wp_remote_retrieve_response_code($response);
41
42 if ($httpcode < 200) {
43 exit();
44 }
45 $response = wp_remote_retrieve_body($response);
46 $result = json_decode($response, true);
47 if (isset($result['errors'][0]['message'])) {
48 exit();
49 }
50 return $result;
51 }
52
53
54 function getOwnSite($token)
55 {
56 $site_url = str_replace(['http://', 'https://', '//', '://', 'www.'], '', get_site_url());
57 $sites = [ $site_url, 'www.'.$site_url ];
58
59 foreach ($sites as $site){
60 $payload = '{"query":"query getSites { auth { viewer { sites { list( filter: {search: \"'.$site.'\"} ) { edges { node { id } } } } } } } "}';
61 $result = requestApi($payload, $token);
62
63 if (isset($result['data']['auth']['viewer']['sites']['list']['edges'][0]['node'])){
64 return $result['data']['auth']['viewer']['sites']['list']['edges'][0]['node'];
65 }
66 }
67 return [];
68 }
69
70 function deleteAM($key){
71
72 $token = false;
73 $result = auth($key);
74
75 if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) {
76 $token = $result['data']['guest']['apiKeys']['auth']['token']['value'];
77 }
78
79 if($token){
80 $host = getOwnSite($token);
81
82 if($host){
83 $payload = '{"query":"mutation { auth { am { delete(siteId: \"'.$host['id'].'\") } } }"}';
84 $result = requestApi($payload, $token);
85 if($result['data']['auth']['am']['delete']){
86 return true;
87 }
88 }
89 }
90
91 return false;
92 }
93
94 function deleteOptions(){
95 $options = [
96 'api_key', 'api_key_safe', 'api_key_activated', 'authorized', 'authToken',
97 'waf_installed_file','am_installed_file','am_installed', 'logout',
98 'av_installed', 'waf_installed', 'agents_installed',
99 'color_scheme','check_login_attempt','time_zone',
100 'token_expired','deactivated', 'antivirus_event','antivirus_permissions_changed',
101 'antivirus_endCursor', 'antivirus_hasNextPage',
102 'firewall_endCursor', 'firewall_hasNextPage',
103 'reports_endCursor', 'reports_hasNextPage'];
104
105 foreach ($options as $option) {
106 delete_option(WTSEC_PLUGIN_PREFIX.$option);
107 }
108 }
109
110
111
112