修复国旗bug。调整更新机制(铺路)

master
Soul Dark 8 years ago
parent 6d5bd5182e
commit 50ef089cd7

@ -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 上全部功能测试通过
## 搭建教程

@ -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();

@ -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;

@ -0,0 +1,121 @@
<?php
namespace App\Utils;
use App\Services\Config;
use Ozdemir\Datatables\Datatables;
use App\Utils\DatatablesHelper;
class Update
{
public static function update()
{
Update::migrateConfig();
}
public static 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_old=file_get_contents(BASE_PATH."/config/.config.php");
$config_new=file_get_contents(BASE_PATH."/config/.config.php.example");
//执行版本升级
$version_old=0;
if(isset(Config::get('version')){
$version_old=Config::get('version');
}
Update::old_to_new($version_old);
//将旧config迁移到新config上
$migrated=array();
foreach($System_Config as $key => $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){
}
}
}

@ -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
//基本设置-----------------------------------------------------------------------

Loading…
Cancel
Save