diff --git a/app/command/Clean.php b/app/command/Clean.php new file mode 100644 index 0000000..35286d2 --- /dev/null +++ b/app/command/Clean.php @@ -0,0 +1,104 @@ +setName('clean') + ->setDescription('the clean command'); + } + + protected function execute(Input $input, Output $output) + { + $res = Db::name('config')->cache('configs',0)->column('value','key'); + Config::set($res, 'sys'); + + if(config_get('bt_url')){ + $this->clean_plugins($input, $output, 'Linux'); + } + if(config_get('wbt_url')){ + $this->clean_plugins($input, $output, 'Windows'); + } + + config_set('cleantime', date('Y-m-d H:i:s')); + } + + private function clean_plugins(Input $input, Output $output, $os){ + $data_dir = get_data_dir($os) . 'plugins/'; + $file_list = []; + $json_arr = Plugins::get_plugin_list($os); + if(count($json_arr['list']) == 0) return; + foreach($json_arr['list'] as $plugin){ + foreach($plugin['versions'] as $version){ + $ver = $version['m_version'].'.'.$version['version']; + if(!isset($version['download'])){ + $file_list[] = $plugin['name'].'-'.$ver; + } + } + } + + $count = 0; + $dir = opendir($data_dir.'package'); + while(false !== ( $file = readdir($dir)) ) { + if($file == '.' || $file == '..') continue; + $name = str_replace('.zip', '', $file); + if(!in_array($name, $file_list)){ + $filepath = $data_dir . 'package/' . $file; + unlink($filepath); + $count++; + } + } + $output->writeln($os.'成功清理'.$count.'个历史版本插件包'); + + $count = 0; + $dir = opendir($data_dir.'folder'); + while(false !== ( $file = readdir($dir)) ) { + if($file == '.' || $file == '..') continue; + if(!in_array($file, $file_list)){ + $filepath = $data_dir . 'folder/' . $file; + $this->delete_dir($filepath); + $count++; + } + } + $output->writeln($os.'成功清理'.$count.'个历史版本插件目录'); + } + + // 删除文件夹 + private function delete_dir($dir){ + $rd = opendir($dir); + if (!$rd) { + return false; + } + + while (($file = readdir($rd)) !== false) { + if ($file == '.' || $file == '..') { + continue; + } + + $file = $dir . '/' . $file; + + if (is_dir($file)) { + $this->delete_dir($file); + } + else { + unlink($file); + } + } + + closedir($rd); + rmdir($dir); + return true; + } +} diff --git a/app/controller/Api.php b/app/controller/Api.php index 1044606..2630588 100644 --- a/app/controller/Api.php +++ b/app/controller/Api.php @@ -346,6 +346,23 @@ class Api extends BaseController return json(['page'=>"
11/0从1-1000条共计0条数据
", 'data'=>[]]); } + public function btwaf_getspiders(){ + $result = cache('btwaf_getspiders'); + if($result){ + return json($result); + } + $bt_url = config_get('bt_url'); + $bt_key = config_get('bt_key'); + if(!$bt_url || !$bt_key) return json([]); + $btapi = new \app\lib\Btapi($bt_url, $bt_key); + $result = $btapi->btwaf_getspiders(); + if(isset($result['status']) && $result['status']){ + cache('btwaf_getspiders', $result['data'], 3600 * 24 * 3); + return json($result['data']); + } + return json($result); + } + //检查黑白名单 private function checklist(){ if(config_get('whitelist') == 1){ diff --git a/app/lib/Btapi.php b/app/lib/Btapi.php index 691f493..56de844 100644 --- a/app/lib/Btapi.php +++ b/app/lib/Btapi.php @@ -156,6 +156,19 @@ class Btapi $data = json_decode($result,true); return $data; } + + //BTWAF-获取蜘蛛列表 + public function btwaf_getspiders(){ + $url = $this->BT_PANEL.'/plugin?action=a&name=kaixin&s=btwaf_getspiders'; + + $p_data = $this->GetKeyData(); + + $result = $this->curl($url,$p_data); + $result = str_replace("\u0000", '', $result); + + $data = json_decode($result,true); + return $data; + } private function GetKeyData(){ diff --git a/app/lib/Plugins.php b/app/lib/Plugins.php index b698e85..e8b055e 100644 --- a/app/lib/Plugins.php +++ b/app/lib/Plugins.php @@ -255,6 +255,9 @@ class Plugins $data = str_replace('\'http://www.bt.cn/api/wpanel/notpro', 'public.GetConfigValue(\'home\')+\'/api/wpanel/notpro', $data); $data = str_replace('\'https://www.bt.cn/api/wpanel/notpro', 'public.GetConfigValue(\'home\')+\'/api/wpanel/notpro', $data); + $data = str_replace('\'http://www.bt.cn/api/bt_waf/getSpiders', 'public.GetConfigValue(\'home\')+\'/api/bt_waf/getSpiders', $data); + $data = str_replace('\'https://www.bt.cn/api/bt_waf/getSpiders', 'public.GetConfigValue(\'home\')+\'/api/bt_waf/getSpiders', $data); + file_put_contents($main_filepath, $data); } diff --git a/app/view/admin/set.html b/app/view/admin/set.html index 96ee497..154000f 100644 --- a/app/view/admin/set.html +++ b/app/view/admin/set.html @@ -188,6 +188,15 @@ +
+

清理旧版本插件工具

+
+
+
使用以下命令可清理旧版本的插件文件,以释放空间占用。
+
php {:app()->getRootPath()}think clean

+
+
+
{/if}