Browse Source

支持清理旧版本文件

tags/1.9
flucout 1 year ago
parent
commit
42974b2b47
  1. 104
      app/command/Clean.php
  2. 17
      app/controller/Api.php
  3. 13
      app/lib/Btapi.php
  4. 3
      app/lib/Plugins.php
  5. 9
      app/view/admin/set.html
  6. 1
      config/console.php
  7. 2
      route/app.php

104
app/command/Clean.php

@ -0,0 +1,104 @@
<?php
declare (strict_types = 1);
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Db;
use think\facade\Config;
use app\lib\Plugins;
class Clean extends Command
{
protected function configure()
{
$this->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;
}
}

17
app/controller/Api.php

@ -346,6 +346,23 @@ class Api extends BaseController
return json(['page'=>"<div><span class='Pcurrent'>1</span><span class='Pnumber'>1/0</span><span class='Pline'>从1-1000条</span><span class='Pcount'>共计0条数据</span></div>", 'data'=>[]]); return json(['page'=>"<div><span class='Pcurrent'>1</span><span class='Pnumber'>1/0</span><span class='Pline'>从1-1000条</span><span class='Pcount'>共计0条数据</span></div>", '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(){ private function checklist(){
if(config_get('whitelist') == 1){ if(config_get('whitelist') == 1){

13
app/lib/Btapi.php

@ -157,6 +157,19 @@ class Btapi
return $data; 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(){ private function GetKeyData(){
$now_time = time(); $now_time = time();

3
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('\'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('\'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); file_put_contents($main_filepath, $data);
} }

9
app/view/admin/set.html

@ -188,6 +188,15 @@
</form> </form>
</div> </div>
</div> </div>
<div class="panel panel-primary">
<div class="panel-heading"><h3 class="panel-title">清理旧版本插件工具</h3></div>
<div class="panel-body">
<form onsubmit="return saveAccount(this)" method="post" class="form" role="form">
<div class="alert alert-info" style="word-break:break-all;">使用以下命令可清理旧版本的插件文件,以释放空间占用。</div>
<div class="list-group-item" style="word-break:break-all;">php {:app()->getRootPath()}think clean</div><br/>
</form>
</div>
</div>
{/if} {/if}
<script src="//cdn.staticfile.org/layer/3.5.1/layer.js"></script> <script src="//cdn.staticfile.org/layer/3.5.1/layer.js"></script>
<script> <script>

1
config/console.php

@ -7,5 +7,6 @@ return [
'commands' => [ 'commands' => [
'updateall' => 'app\command\UpdateAll', 'updateall' => 'app\command\UpdateAll',
'decrypt' => 'app\command\DecryptFile', 'decrypt' => 'app\command\DecryptFile',
'clean' => 'app\command\Clean',
], ],
]; ];

2
route/app.php

@ -101,6 +101,8 @@ Route::group('api', function () {
Route::get('/panel/get_beta_logs', 'api/get_beta_logs'); Route::get('/panel/get_beta_logs', 'api/get_beta_logs');
Route::get('/wpanel/get_beta_logs', 'api/get_beta_logs'); Route::get('/wpanel/get_beta_logs', 'api/get_beta_logs');
Route::any('/bt_waf/getSpiders', 'api/btwaf_getspiders');
Route::miss('api/return_error'); Route::miss('api/return_error');
}); });

Loading…
Cancel
Save