Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
添加安装时的后台指定功能
添加导入表数量检查机制
  • Loading branch information
yumusb committed Sep 5, 2021
1 parent a3d268b commit 38a6eb2
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 15 deletions.
1 change: 1 addition & 0 deletions application/modules/Install/controllers/Last.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function indexAction()
{
if(file_exists(INSTALL_LOCK)){
$data = array();
$data['admindir'] = $this->getSession('AdminDir');
$this->getView()->assign($data);
}else{
$this->redirect("/install/");
Expand Down
58 changes: 53 additions & 5 deletions application/modules/Install/controllers/Setptwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,41 @@ public function ajaxAction()
$user = $this->getPost('user');
$password = $this->getPost('password');
$dbname = $this->getPost('dbname');
$admindir = $this->getPost('admindir');

// 2021 09 05 新增安装时修改后台功能
if(!preg_match("/^[A-Z][a-z]{3,10}$/",$admindir)){
$data = array('code' => 1001, 'msg' =>"后台目录只能以大写字母开头,并且后面跟3-10位的小写字母");
Helper::response($data);
}

$this->setSession('AdminDir', $admindir);
$basedir = dirname(dirname($_SERVER['SCRIPT_FILENAME']));
$applicationini = file_get_contents($basedir.'/conf/application.ini');
$init = file_get_contents($basedir.'/application/init.php');
$findadminpath = 0;
foreach(scandir($basedir."/application/modules/") as $p){
if(file_exists($basedir.'/application/modules/'.$p.'/controllers/Payment.php')){
$nowadminpath = $p;
$findadminpath = 1;
break;
}
}
if($findadminpath = 1){
if(rename($basedir.'/application/modules/'.$nowadminpath,$basedir.'/application/modules/'.$admindir)){
file_put_contents($basedir.'/conf/application.ini',preg_replace('/application.modules.*/i', 'application.modules = "Index,Member,Product,'.$admindir.',Crontab,Install"', $applicationini));
file_put_contents($basedir.'/application/init.php',preg_replace("/.*'ADMIN_DIR.*;/i","define('ADMIN_DIR','$admindir');",$init));
}else {
$data = array('code' => 1001, 'msg' =>"修改后台目录失败");
Helper::response($data);
}
}else{
$data = array('code' => 1001, 'msg' =>"获取后台目录失败");
Helper::response($data);
}




$data = array();

Expand Down Expand Up @@ -91,12 +126,25 @@ public function ajaxAction()
'product : common' => ['READ_HOST' => $host,'WRITE_HOST' => $host,'READ_PORT' => $port,'WRITE_PORT' => $port,'READ_USER' => $user,'WRITE_USER' => $user,'READ_PSWD' => $password,'WRITE_PSWD' => $password,'Default' => $dbname]
]);
$ini->write();

$result = @file_put_contents(INSTALL_LOCK,VERSION,LOCK_EX);
if (!$result){
$data = array('code' => 1004, 'msg' =>"无法写入安装锁定到".INSTALL_LOCK."文件,请检查是否有写权限");

$querytableline = $pdo->prepare("SELECT COUNT(TABLE_NAME) as count FROM information_schema.TABLES WHERE TABLE_SCHEMA = ?");
$querytableline->execute(array($dbname));
$remotetableline = intval($querytableline->fetchAll(PDO::FETCH_ASSOC)[0]['count']);

preg_match_all('/`(t_.*?)`/',file_get_contents($this->install_sql),$sqlfilelines);
$sqlfiletableline=count(array_unique($sqlfilelines[1])));

if($remotetableline>=$sqlfiletableline){
$result = @file_put_contents(INSTALL_LOCK,VERSION,LOCK_EX);
if (!$result){
$data = array('code' => 1004, 'msg' =>"无法写入安装锁定到".INSTALL_LOCK."文件,请检查是否有写权限");
}else{
$data = array('code' => 1, 'msg' =>"SUCCESS");
}
}else{
$data = array('code' => 1004, 'msg' =>"导入表异常,请检查或者手动导入");
}
$data = array('code' => 1, 'msg' =>"SUCCESS");

} catch (PDOException $e) {
$data = array('code' => 1001, 'msg' =>"失败:".$e->getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion application/modules/Install/views/last/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<div class="layui-form-pane layui-tab-item layui-show">
<blockquote class="layui-elem-quote layui-text">
<p>恭喜您,已经完成项目安装;</p>
<p>请登录<a href="/admin">管理后台</a>(1.4.5版本以上的后台路径为用户自定义),进行基础配置。默认管理账户:[email protected],密码:123456</p>
<p>请登录<a href="/<?php echo isset($admindir)?$admindir:'admin'?>">管理后台</a>,进行基础配置。默认管理账户:[email protected],密码:123456</p>
<p>如有疑问,请加QQ交流群:<a target="_blank" href="//shang.qq.com/wpa/qunwpa?idkey=00975ec2a71a8f2469b0f1d2d0b630735edf7f6f0cc703695a0f9c32a1bad120"><img border="0" src="//pub.idqqimg.com/wpa/images/group.png" alt="资料空白-开源程序群" title="资料空白-开源程序群"></a> </p>
</blockquote>

Expand Down
10 changes: 8 additions & 2 deletions application/modules/Install/views/setptwo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<div class="layui-container fly-marginTop fly-user-main">
<div class="layui-row layui-col-space15">
<div class="layui-card" style="color:#000000;">
<div class="layui-card-header">3.安装数据库</div>
<div class="layui-card-header">3.安装数据库与设置后台目录</div>
<div class="layui-card-body">
<div class="layui-form-pane layui-tab-item layui-show">
<form class="layui-form" method="post">
Expand Down Expand Up @@ -69,7 +69,13 @@
</div>
</div>
<div class="layui-form-item">
<button class="layui-btn" key="set-mine" lay-filter="setptwo" lay-submit>安装数据库</button>
<label for="admindir" class="layui-form-label">后台目录</label>
<div class="layui-input-inline">
<input type="text" id="admindir" name="admindir" required lay-verify="required|admindir" autocomplete="off" class="layui-input" value="Goadmin">
</div>
</div>
<div class="layui-form-item">
<button class="layui-btn" key="set-mine" lay-filter="setptwo" lay-submit>安装数据库与设置后台目录</button>
</div>
</form>
</div>
Expand Down
4 changes: 2 additions & 2 deletions change.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
exit();
}
$todir = trim($argv[1]);
if(!preg_match('/^[A-Z][a-z]{5,10}$/',$todir)){
echo "[-]Your dir format is wrong. Please use [A-Z][a-z]{5,10}".PHP_EOL;
if(!preg_match('/^[A-Z][a-z]{3,10}$/',$todir)){
echo "[-]Your dir format is wrong. Please use [A-Z][a-z]{3,10}".PHP_EOL;
exit();
}

Expand Down
10 changes: 5 additions & 5 deletions public/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
echo "<div style=\"border: 1px dashed #cc0000;font-family:Tahoma;background-color:#FBEEEB;width:100%;padding:10px;color:#cc0000;\"><strong>警告:</strong><br>请按照安装要求配置yaf.use_namespace=1</div>";
exit();
}
//4.必须修改后台地址
if(file_exists(APP_PATH.'/application/modules/Admin')){
echo "<div style=\"border: 1px dashed #cc0000;font-family:Tahoma;background-color:#FBEEEB;width:100%;padding:10px;color:#cc0000;\"><strong>警告:</strong><br>请修改后台目录。打开SSH或者CMD终端,进入到【".APP_PATH."/】目录下,然后执行【php change.php Yourdir】,其中Yourdir是你将要修改的后台目录,应为一个大写字母后跟5-10个小写字母的字符串。</div>";
exit();
}
// //4.必须修改后台地址
// if(file_exists(APP_PATH.'/application/modules/Admin')){
// echo "<div style=\"border: 1px dashed #cc0000;font-family:Tahoma;background-color:#FBEEEB;width:100%;padding:10px;color:#cc0000;\"><strong>警告:</strong><br>请修改后台目录。打开SSH或者CMD终端,进入到【".APP_PATH."/】目录下,然后执行【php change.php Yourdir】,其中Yourdir是你将要修改的后台目录,应为一个大写字母后跟5-10个小写字母的字符串。</div>";
// exit();
// }
}

0 comments on commit 38a6eb2

Please sign in to comment.