| 1 |
<?php defined('ABSPATH') or die("Protected By WT!"); |
| 2 |
|
| 3 |
|
| 4 |
class WTSEC_LIBRARY_App |
| 5 |
{ |
| 6 |
|
| 7 |
public function __construct() |
| 8 |
{ |
| 9 |
$this->auth(); |
| 10 |
} |
| 11 |
|
| 12 |
public function auth(){ |
| 13 |
|
| 14 |
if(self::getSiteOption('authorized') === false && is_user_logged_in() && stripos(wtsec_request()->page,WTSEC_PAGE_PREFIX) ){ |
| 15 |
wp_safe_redirect(admin_url('admin.php?page=' . WTSEC_PAGE_PREFIX . 'login')); |
| 16 |
exit; |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
public static function authorized(){ |
| 21 |
return (boolean) self::getSiteOption('authorized'); |
| 22 |
} |
| 23 |
|
| 24 |
public static function login($token){ |
| 25 |
self::setSiteOption('authorized', true); |
| 26 |
self::setSiteOption('authToken', $token); |
| 27 |
} |
| 28 |
|
| 29 |
public static function logout(){ |
| 30 |
$options = [ |
| 31 |
'api_key', 'api_key_safe', 'api_key_activated', 'authorized', 'authToken', |
| 32 |
'waf_installed_file','am_installed_file','am_installed', |
| 33 |
'av_installed', 'waf_installed', 'agents_installed', 'api_url', |
| 34 |
'color_scheme', 'time_zone', |
| 35 |
'token_expired','deactivated', 'antivirus_event', 'antivirus_permissions_changed', |
| 36 |
'antivirus_endCursor', 'antivirus_hasNextPage', |
| 37 |
'firewall_endCursor', 'firewall_hasNextPage', |
| 38 |
'reports_endCursor', 'reports_hasNextPage']; |
| 39 |
|
| 40 |
self::_delete($options); |
| 41 |
self::_set('logout', true); |
| 42 |
//self::_set('am_installed', false); |
| 43 |
} |
| 44 |
|
| 45 |
public function getLocalDomains(){ |
| 46 |
return []; |
| 47 |
} |
| 48 |
|
| 49 |
public static function _set($name,$value){ |
| 50 |
return update_option(WTSEC_PLUGIN_PREFIX.$name,$value); |
| 51 |
} |
| 52 |
|
| 53 |
public static function _get($name){ |
| 54 |
return get_option(WTSEC_PLUGIN_PREFIX.$name); |
| 55 |
} |
| 56 |
|
| 57 |
public static function _delete($options){ |
| 58 |
if(is_array($options)){ |
| 59 |
foreach ($options as $option) { |
| 60 |
delete_option(WTSEC_PLUGIN_PREFIX.$option); |
| 61 |
delete_site_option(WTSEC_PLUGIN_PREFIX.$option); |
| 62 |
} |
| 63 |
} else{ |
| 64 |
delete_option(WTSEC_PLUGIN_PREFIX.$options); |
| 65 |
delete_site_option(WTSEC_PLUGIN_PREFIX.$options); |
| 66 |
} |
| 67 |
return true; |
| 68 |
} |
| 69 |
|
| 70 |
public function set($name,$value){ |
| 71 |
return update_option(WTSEC_PLUGIN_PREFIX.$name,$value); |
| 72 |
} |
| 73 |
|
| 74 |
public function get($name){ |
| 75 |
return get_option(WTSEC_PLUGIN_PREFIX.$name); |
| 76 |
} |
| 77 |
|
| 78 |
public static function getOption($name){ |
| 79 |
return get_option(WTSEC_PLUGIN_PREFIX.$name); |
| 80 |
} |
| 81 |
|
| 82 |
public static function getSiteOption($name){ |
| 83 |
return get_site_option(WTSEC_PLUGIN_PREFIX.$name); |
| 84 |
} |
| 85 |
|
| 86 |
public static function setSiteOption($name,$value){ |
| 87 |
return update_site_option(WTSEC_PLUGIN_PREFIX.$name,$value); |
| 88 |
} |
| 89 |
|
| 90 |
public static function deleteOption($name){ |
| 91 |
return delete_option(WTSEC_PLUGIN_PREFIX.$name); |
| 92 |
} |
| 93 |
|
| 94 |
public static function getToken(){ |
| 95 |
return self::getSiteOption('authToken'); |
| 96 |
} |
| 97 |
|
| 98 |
public static function getName(){ |
| 99 |
return self::getOption('username'); |
| 100 |
} |
| 101 |
|
| 102 |
} |