Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
flucout committed Aug 13, 2024
1 parent 5e1f19d commit aba885f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 58 deletions.
29 changes: 1 addition & 28 deletions app/command/Clean.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,37 +68,10 @@ private function clean_plugins(Input $input, Output $output, $os){
if($file == '.' || $file == '..') continue;
if(!in_array($file, $file_list)){
$filepath = $data_dir . 'folder/' . $file;
$this->delete_dir($filepath);
deleteDir($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;
}
}
26 changes: 26 additions & 0 deletions app/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,30 @@ function makeSelfSignSSL(string $commonName, array $domainList, $validity = 3650
unlink($opensslConfigFile);

return ['cert' => $certificate, 'key' => $privateKey];
}

function deleteDir($dir){
$rd = opendir($dir);
if (!$rd) {
return false;
}

while (($file = readdir($rd)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}

$file = $dir . '/' . $file;

if (is_dir($file)) {
deleteDir($file);
}
else {
unlink($file);
}
}

closedir($rd);
rmdir($dir);
return true;
}
57 changes: 32 additions & 25 deletions app/controller/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function download_plugin(){
if(!preg_match('/^[a-zA-Z0-9_]+$/', $plugin_name) || !preg_match('/^[0-9.]+$/', $version)){
return '参数不正确';
}
if(!$this->checklist()) '你的服务器被禁止使用此云端';
if(!$this->checklist()) return '你的服务器被禁止使用此云端';
$filepath = get_data_dir($os).'plugins/package/'.$plugin_name.'-'.$version.'.zip';
if(file_exists($filepath)){
$filename = $plugin_name.'.zip';
Expand All @@ -70,19 +70,21 @@ public function download_plugin_main(){
if(!preg_match('/^[a-zA-Z0-9_]+$/', $plugin_name) || !preg_match('/^[0-9.]+$/', $version)){
return '参数不正确';
}
if(!$this->checklist()) '你的服务器被禁止使用此云端';
$filepath = get_data_dir($os).'plugins/main/'.$plugin_name.'-'.$version.'.dat';
if(file_exists($filepath)){
if(!$this->checklist()) return '你的服务器被禁止使用此云端';
$filepath = get_data_dir($os).'plugins/package/'.$plugin_name.'-'.$version.'.zip';
$mainfilepath = get_data_dir($os).'plugins/folder/'.$plugin_name.'-'.$version.'/'.$plugin_name.'/'.$plugin_name.'_main.py';
if(file_exists($mainfilepath)){
$filename = $plugin_name.'_main.py';
$this->output_file($filepath, $filename);
}else{
$filepath = get_data_dir($os).'plugins/folder/'.$plugin_name.'-'.$version.'/'.$plugin_name.'/'.$plugin_name.'_main.py';
if(file_exists($filepath)){
$filename = $plugin_name.'_main.py';
$this->output_file($filepath, $filename);
$this->output_file($mainfilepath, $filename);
}elseif(file_exists($filepath)){
$zip = new \ZipArchive;
if ($zip->open($filepath) === true){
echo $zip->getFromName($plugin_name.'/'.$plugin_name.'_main.py');
}else{
return '云端不存在该插件主文件';
return '插件包解压缩失败';
}
}else{
return '云端不存在该插件主文件';
}
}

Expand Down Expand Up @@ -469,26 +471,31 @@ public function logerror(){
public function bt_cert(){
$data = input('post.data');
$param = json_decode($data, true);
if(!$param || !isset($param['domain'])) return json(['status'=>false, 'msg'=>'参数错误']);
if(!$param || !isset($param['action']) || !isset($param['domain'])) return json(['status'=>false, 'msg'=>'参数错误']);

$dir = app()->getBasePath().'script/';
$ssl_path = app()->getRootPath().'public/ssl/baota_root.pfx';
$isca = file_exists($dir.'ca.crt') && file_exists($dir.'ca.key') && file_exists($ssl_path);
if(!$isca) return json(['status'=>false, 'msg'=>'CA证书不存在']);

$domain = $param['domain'];
if(empty($domain)) return json(['status'=>false, 'msg'=>'域名不能为空']);
$domain_list = explode(',', $domain);
foreach($domain_list as $d){
if(!checkDomain($d)) return json(['status'=>false, 'msg'=>'域名或IP格式不正确:'.$d]);
}
$common_name = $domain_list[0];
$validity = 3650;
$result = makeSelfSignSSL($common_name, $domain_list, $validity);
if(!$result){
return json(['status'=>false, 'msg'=>'生成证书失败']);
if($param['action'] == 'get_domain_cert'){
if(!$this->checklist()) return json(['status'=>false, 'msg'=>'你的服务器被禁止使用此云端']);
$domain = $param['domain'];
if(empty($domain)) return json(['status'=>false, 'msg'=>'域名不能为空']);
$domain_list = explode(',', $domain);
foreach($domain_list as $d){
if(!checkDomain($d)) return json(['status'=>false, 'msg'=>'域名或IP格式不正确:'.$d]);
}
$common_name = $domain_list[0];
$validity = 3650;
$result = makeSelfSignSSL($common_name, $domain_list, $validity);
if(!$result){
return json(['status'=>false, 'msg'=>'生成证书失败']);
}
$ca_pfx = base64_encode(file_get_contents($ssl_path));
return json(['status'=>true, 'msg'=>'生成证书成功', 'cert'=>$result['cert'], 'key'=>$result['key'], 'pfx'=>$ca_pfx, 'password'=>'']);
}else{
return json(['status'=>false, 'msg'=>'不支持当前操作']);
}
$ca_pfx = base64_encode(file_get_contents($ssl_path));
return json(['status'=>true, 'msg'=>'生成证书成功', 'cert'=>$result['cert'], 'key'=>$result['key'], 'pfx'=>$ca_pfx, 'password'=>'']);
}
}
10 changes: 7 additions & 3 deletions app/lib/BtPlugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BtPlugins
private $os;

//需屏蔽的插件名称列表
private static $block_plugins = ['dns'];
private static $block_plugins = ['dns','bt_boce','ssl_verify'];

public function __construct($os){
$this->os = $os;
Expand Down Expand Up @@ -72,9 +72,10 @@ private function download_plugin_package($plugin_name, $version){
$zip = new ZipArchive;
if ($zip->open($filepath) === true)
{
$zip->extractTo(get_data_dir($this->os).'plugins/folder/'.$plugin_name.'-'.$version);
$plugins_dir = get_data_dir($this->os).'plugins/folder/'.$plugin_name.'-'.$version;
$zip->extractTo($plugins_dir, $plugin_name.'/'.$plugin_name.'_main.py');
$zip->close();
$main_filepath = get_data_dir($this->os).'plugins/folder/'.$plugin_name.'-'.$version.'/'.$plugin_name.'/'.$plugin_name.'_main.py';
$main_filepath = $plugins_dir.'/'.$plugin_name.'/'.$plugin_name.'_main.py';
if(file_exists($main_filepath) && filesize($main_filepath)>10){
if(!strpos(file_get_contents($main_filepath), 'import ')){ //加密py文件,需要解密
$this->decode_plugin_main($plugin_name, $version, $main_filepath);
Expand All @@ -84,6 +85,7 @@ private function download_plugin_package($plugin_name, $version){
$zip->close();
}
}
deleteDir($plugins_dir);
}else{
unlink($filepath);
throw new Exception('插件包解压缩失败');
Expand Down Expand Up @@ -197,6 +199,8 @@ private function noauth_plugin_main($main_filepath){
$data = str_replace('\'https://www.bt.cn/api/bt_waf/reportInterceptFail', 'public.GetConfigValue(\'home\')+\'/api/bt_waf/reportInterceptFail', $data);
$data = str_replace('\'https://www.bt.cn/api/v2/contact/nps/questions', 'public.GetConfigValue(\'home\')+\'/panel/notpro', $data);
$data = str_replace('\'https://www.bt.cn/api/v2/contact/nps/submit', 'public.GetConfigValue(\'home\')+\'/panel/notpro', $data);
$data = str_replace('\'http://www.bt.cn/api/Auth', 'public.GetConfigValue(\'home\')+\'/api/Auth', $data);
$data = str_replace('\'https://www.bt.cn/api/Auth', 'public.GetConfigValue(\'home\')+\'/api/Auth', $data);

file_put_contents($main_filepath, $data);
}
Expand Down
1 change: 0 additions & 1 deletion app/lib/ThirdPlugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ private function download_plugin_package($plugin_name, $version){
$zip = new ZipArchive;
if ($zip->open($filepath) === true)
{
$zip->extractTo(get_data_dir($this->os).'plugins/folder/'.$plugin_name.'-'.$version);
$zip->close();
return true;
}else{
Expand Down
7 changes: 6 additions & 1 deletion app/view/admin/plugins.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,13 @@ <h4 class="modal-title">帮助</h4>
layer.alert('成功下载'+$.downloadCount+'个插件包!', {icon:1}, function(){layer.closeAll();searchSubmit();});
return;
}
$.downloadCount++;
var plugin = $.preDownload[0];
if(plugin.name == 'firewall'){
$.preDownload.shift();
download_item();
return;
}
$.downloadCount++;
var ii = layer.msg('['+$.downloadCount+'/'+$.preDownloadCount+']正在下载'+plugin.name+'-'+plugin.version, {icon: 16, shade:0.1, time: 0});
$.ajax({
type : 'POST',
Expand Down
4 changes: 4 additions & 0 deletions route/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
Route::post('/bt_waf/reportInterceptFail', 'api/return_empty');
Route::any('/panel/get_spider', 'api/get_spider');

Route::post('/Auth/GetSocre', 'api/get_ssl_list');
Route::post('/Auth/SetSocre', 'api/get_ssl_list');
Route::post('/Auth/SubmitScore', 'api/get_ssl_list');

Route::miss('api/return_error');
});

Expand Down

0 comments on commit aba885f

Please sign in to comment.