From 50ef089cd727f9fb6db784fcd7225bee29c2e5b9 Mon Sep 17 00:00:00 2001 From: Soul Dark <1012179378@qq.com> Date: Sun, 15 Jul 2018 21:47:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BD=E6=97=97bug?= =?UTF-8?q?=E3=80=82=E8=B0=83=E6=95=B4=E6=9B=B4=E6=96=B0=E6=9C=BA=E5=88=B6?= =?UTF-8?q?=EF=BC=88=E9=93=BA=E8=B7=AF=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- app/Command/XCat.php | 81 +------------------ app/Controllers/UserController.php | 11 +-- app/Utils/Update.php | 121 +++++++++++++++++++++++++++++ config/.config.php.example | 1 + 5 files changed, 131 insertions(+), 85 deletions(-) create mode 100644 app/Utils/Update.php diff --git a/README.md b/README.md index 23bed320..cd6e6e36 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ telegtam 频道 :https://t.me/sspanel_Uim 管理模式参考91yun管理 [支持开发者请点我](https://github.com/NimaQu/ss-panel-v3-mod_UIM#%E5%85%B3%E4%BA%8E%E6%8D%90%E8%B5%A0) -本面板在[宝塔面板5.6.0](www.bt.cn),宝塔安装版 nginx1.12,php 7.1 ,mysql 5.7 上全部功能测试通过 +本面板在[宝塔面板5.6.0](https://www.bt.cn),宝塔安装版 nginx1.12,php 7.1 ,mysql 5.7 上全部功能测试通过 ## 搭建教程 diff --git a/app/Command/XCat.php b/app/Command/XCat.php index d85e4a16..cbaebd6a 100644 --- a/app/Command/XCat.php +++ b/app/Command/XCat.php @@ -15,6 +15,7 @@ use App\Services\Config; use App\Utils\GA; use App\Utils\QRcode; +use App\Utils\Update; class XCat { @@ -85,7 +86,7 @@ class XCat case("resetAllPort"): return $this->resetAllPort(); case("migrateConfig"): - return $this->migrateConfig(); + return Update::update(); default: return $this->defaultAction(); } @@ -136,84 +137,6 @@ class XCat } } - public function migrateConfig() - { - global $System_Config; - $copy_result=copy(BASE_PATH."/config/.config.php",BASE_PATH."/config/.config.php.bak"); - if($copy_result==true){ - echo('备份成功!'.PHP_EOL); - } - else{ - echo('备份失败!迁移终止'.PHP_EOL); - return false; - } - echo(PHP_EOL); - - //将旧config迁移到新config上 - $config_old=file_get_contents(BASE_PATH."/config/.config.php"); - $config_new=file_get_contents(BASE_PATH."/config/.config.php.example"); - $migrated=array(); - foreach($System_Config as $key => $value_reserve){ - if($key=='config_migrate_notice'){ - continue; - } - - $regex='/System_Config\[\''.$key.'\'\].*?;/s'; - $matches_new=array(); - preg_match($regex,$config_new,$matches_new); - if(isset($matches_new[0])==false){ - echo('未找到配置项:'.$key.' 未能在新config文件中找到,可能已被更名或废弃'.PHP_EOL); - continue; - } - - $matches_old=array(); - preg_match($regex,$config_old,$matches_old); - - $config_new=str_replace($matches_new[0],$matches_old[0],$config_new); - array_push($migrated,'System_Config[\''.$key.'\']'); - } - echo(PHP_EOL); - - //检查新增了哪些config - $regex_new='/System_Config\[\'.*?\'\]/s'; - $matches_new_all=array(); - preg_match_all($regex_new,$config_new,$matches_new_all); - $new_all=$matches_new_all[0]; - $differences=array_diff($new_all,$migrated); - foreach($differences as $difference){ - //裁去首位 - $difference=substr($difference,15); - $difference=substr($difference, 0, -2); - - echo('新增配置项:'.$difference.PHP_EOL); - } - echo('新增配置项通常带有默认值,因此通常即使不作任何改动网站也可以正常运行'.PHP_EOL); - - //输出notice - $regex_notice='/System_Config\[\'config_migrate_notice\'\].*?(?=\';)/s'; - $matches_notice=array(); - preg_match($regex_notice,$config_new,$matches_notice); - $notice_new=$matches_notice[0]; - $notice_new=substr( - $notice_new,strpos( - $notice_new,'\'',strpos($notice_new,'=') //查找'='之后的第一个'\'',然后substr其后面的notice - )+1 - ); - echo('以下是迁移附注:'); - if(isset($System_Config['config_migrate_notice'])==true){ - if($System_Config['config_migrate_notice']!=$notice_new){ - echo($notice_new); - } - } - else{ - echo($notice_new); - } - echo(PHP_EOL); - - file_put_contents(BASE_PATH."/config/.config.php",$config_new); - echo(PHP_EOL.'迁移完成!'.PHP_EOL); - } - public function cleanRelayRule() { $rules = Relay::all(); diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index e11e4b2c..7d7f6d45 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -744,11 +744,12 @@ class UserController extends BaseController array_push($node_prefix[$name_cheif], $node); - $regex=Config::get('flag_regex'); - $matches=array(); - preg_match($regex,$name_cheif,$matches); - $node_flag_file[$name_cheif]=$matches[0]; - + if(Config::get('enable_flag')==true){ + $regex=Config::get('flag_regex'); + $matches=array(); + preg_match($regex,$name_cheif,$matches); + $node_flag_file[$name_cheif]=$matches[0]; + } } } $node_prefix=(object)$node_prefix; diff --git a/app/Utils/Update.php b/app/Utils/Update.php new file mode 100644 index 00000000..d51f29a6 --- /dev/null +++ b/app/Utils/Update.php @@ -0,0 +1,121 @@ + $value_reserve){ + if($key=='config_migrate_notice'||$key=='version'){ + continue; + } + + $regex='/System_Config\[\''.$key.'\'\].*?;/s'; + $matches_new=array(); + preg_match($regex,$config_new,$matches_new); + if(isset($matches_new[0])==false){ + echo('未找到配置项:'.$key.' 未能在新config文件中找到,可能已被更名或废弃'.PHP_EOL); + continue; + } + + $matches_old=array(); + preg_match($regex,$config_old,$matches_old); + + $config_new=str_replace($matches_new[0],$matches_old[0],$config_new); + array_push($migrated,'System_Config[\''.$key.'\']'); + } + echo(PHP_EOL); + + //检查新增了哪些config + $regex_new='/System_Config\[\'.*?\'\]/s'; + $matches_new_all=array(); + preg_match_all($regex_new,$config_new,$matches_new_all); + $differences=array_diff($new_all,$migrated); + foreach($differences as $difference){ + //匹配注释 + $regex_comment='/'.$difference.'.*/'; + $regex_comment=str_replace('[','\[',$regex_new); + $regex_comment=str_replace(']','\]',$regex_new); + $matches_comment=array(); + preg_match($regex_comment,$config_new,$matches_comment); + $comment=$matches_comment[0]; + $comment=substr( + $comment,strpos( + $comment,'//',strpos($comment,';') //查找';'之后的第一个'//',然后substr其后面的comment + )+2 + ); + + //裁去首尾 + $difference=substr($difference,15); + $difference=substr($difference, 0, -2); + + echo('新增配置项:'.$difference.':'.$comment.PHP_EOL); + } + echo('新增配置项通常带有默认值,因此通常即使不作任何改动网站也可以正常运行'.PHP_EOL); + + //输出notice + $regex_notice='/System_Config\[\'config_migrate_notice\'\].*?(?=\';)/s'; + $matches_notice=array(); + preg_match($regex_notice,$config_new,$matches_notice); + $notice_new=$matches_notice[0]; + $notice_new=substr( + $notice_new,strpos( + $notice_new,'\'',strpos($notice_new,'=') //查找'='之后的第一个'\'',然后substr其后面的notice + )+1 + ); + echo('以下是迁移附注:'); + if(isset($System_Config['config_migrate_notice'])==true){ + if($System_Config['config_migrate_notice']!=$notice_new){ + echo($notice_new); + } + } + else{ + echo($notice_new); + } + echo(PHP_EOL); + + file_put_contents(BASE_PATH."/config/.config.php",$config_new); + echo(PHP_EOL.'迁移完成!'.PHP_EOL); + } + + public static function old_to_new($version_old) + { + if($version_old<=0){ + + } + } +} diff --git a/config/.config.php.example b/config/.config.php.example index 7e1cedf4..d4c115a2 100644 --- a/config/.config.php.example +++ b/config/.config.php.example @@ -9,6 +9,7 @@ $System_Config['config_migrate_notice']= 自动备份改用crontab进行,以实现每隔20分钟备份一次之类的操作, 详情请看本wiki底部: https://github.com/NimaQu/ss-panel-v3-mod_Uim/wiki/前端安装'; +$System_Config['version']='0'; //仅当涉及【需要修改config以外的文件】时才需要+1 //基本设置-----------------------------------------------------------------------