install-upgrade
This commit is contained in:
parent
f3da92ba8f
commit
8272f4398a
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
\app\middleware\Install::class,
|
||||
//app\middleware\LoginCheck::class,
|
||||
//app\middleware\CheckRegister::class,
|
||||
//'logedcheck' => \app\middleware\logedCheck::class,
|
||||
|
@ -34,7 +34,7 @@ class Index extends BaseController
|
||||
Session::set('install',2);
|
||||
return View::fetch('test');
|
||||
} else {
|
||||
return redirect('./index.html');
|
||||
return redirect('index.html');
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ class Index extends BaseController
|
||||
Session::set('install',3);
|
||||
return View::fetch('create');
|
||||
} else {
|
||||
return redirect('./test.html');
|
||||
return redirect('test.html');
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,6 +74,8 @@ class Index extends BaseController
|
||||
$create_time = time();
|
||||
$salt = substr(md5($create_time),-6);
|
||||
$pass = md5(substr_replace(md5($data['admin_pass']),$salt,0,6));
|
||||
$webtitle = $data['webtitle'];
|
||||
$webname = $data['webname'];
|
||||
|
||||
$dbhost = $data['DB_HOST'];
|
||||
$dbuser = $data['DB_USER'];
|
||||
@ -98,12 +100,42 @@ class Index extends BaseController
|
||||
// 使用 exec() ,没有结果返回
|
||||
$conn->exec($sql);
|
||||
//echo $dbname."数据库创建成功<br>";
|
||||
|
||||
$conn = null;
|
||||
|
||||
//写入数据表
|
||||
$db = new \PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
|
||||
//创建数据库
|
||||
try {
|
||||
$db = new \PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
|
||||
}
|
||||
catch(\PDOException $e)
|
||||
{
|
||||
return json(['code'=>-1,'msg'=>"PDO数据库连接失败" . $e->getMessage()]);
|
||||
}
|
||||
|
||||
create_tables($db,$prefix);
|
||||
|
||||
//写入初始配置
|
||||
$table_admin = $data['DB_PREFIX'] . "admin";
|
||||
$table_user = $data['DB_PREFIX'] . "user";
|
||||
$table_system = $data['DB_PREFIX'] . "system";
|
||||
|
||||
$sql_a = "UPDATE $table_admin SET username='{$user}',email='{$email}',password='{$pass}',status=1,auth_group_id=1,create_time='{$create_time}' WHERE id = 1";
|
||||
$sql_u = "UPDATE $table_user SET name='{$user}',email='{$email}',password='{$pass}',auth=1,status=1,create_time='{$create_time}' WHERE id = 1";
|
||||
$sql_s = "UPDATE $table_system SET webname='{$webname}',webtitle='{$webtitle}',domain='{Request::domain()}',create_time='{$create_time}' WHERE id = 1";
|
||||
|
||||
$res_a = $db->exec($sql_a);
|
||||
//var_dump($db->errorInfo());
|
||||
if($res_a == 0){
|
||||
return json(['code'=>-1,'msg'=>"管理员账号写入失败"]);
|
||||
}
|
||||
$res_u = $db->exec($sql_u);
|
||||
if($res_u == 0){
|
||||
return json(['code'=>-1,'msg'=>"前台管理员写入失败"]);
|
||||
}
|
||||
$res_s = $db->exec($sql_s);
|
||||
if($res_s == 0){
|
||||
return json(['code'=>-1,'msg'=>"网站配置写入失败"]);
|
||||
}
|
||||
$db = null;
|
||||
|
||||
|
||||
@ -169,22 +201,13 @@ php;
|
||||
echo '数据库配置文件创建失败!';
|
||||
}
|
||||
|
||||
//写入初始配置
|
||||
$table_admin = $data['DB_PREFIX'] . "admin";
|
||||
$table_user = $data['DB_PREFIX'] . "user";
|
||||
$table_system = $data['DB_PREFIX'] . "system";
|
||||
|
||||
$res_a = Db::table($table_admin)->where('id',1)->update(['username'=>$user,'email'=>$email,'password'=>$pass,'status'=>1,'auth_group_id'=>1,'create_time'=>$create_time]);
|
||||
$res_u = Db::table($table_user)->where('id',1)->update(['name'=>$user,'email'=>$email,'password'=>$pass,'auth'=>1,'status'=>1,'create_time'=>$create_time]);
|
||||
$res_s = Db::table($table_system)->where('id',1)->update(['webname'=>$data['webname'],'webtitle'=>$data['webtitle'],'domain'=>Request::domain(),'create_time'=>time()]);
|
||||
|
||||
}
|
||||
|
||||
//安装上锁
|
||||
file_put_contents('../install.lock', 'lock');
|
||||
Session::clear();
|
||||
|
||||
return json(['code' => 0,'msg'=>'安装成功','url'=>'/install.php/success/complete']);
|
||||
return json(['code' => 0,'msg'=>'安装成功','url'=>'/install/success/complete']);
|
||||
} else {
|
||||
return '请求失败!';
|
||||
}
|
||||
|
16
app/middleware/Install.php
Normal file
16
app/middleware/Install.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\middleware;
|
||||
use think\facade\Request;
|
||||
|
||||
class Install
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
if(!file_exists('../install.lock')){
|
||||
return redirect('/install/index');
|
||||
//header('Location:'.Request::domain().'/install.php');
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
@ -23,7 +23,4 @@ $response = $http->run();
|
||||
|
||||
$response->send();
|
||||
|
||||
$http->end($response);
|
||||
if(file_exists('../install.lock') != 'true'){
|
||||
header('Location:'.Request::domain().'/install.php');
|
||||
}
|
||||
$http->end($response);
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// [ 应用入口文件 ]
|
||||
namespace think;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// 执行HTTP应用并响应
|
||||
$http = (new App())->http;
|
||||
|
||||
$response = $http->run();
|
||||
|
||||
$response->send();
|
||||
|
||||
$http->end($response);
|
@ -18,7 +18,7 @@
|
||||
<a>拒绝安装</a>
|
||||
</div>
|
||||
<div class="inout2">
|
||||
<a href="{:url('/index/test')}">同意安装</a>
|
||||
<a href="{:url('index/test')}">同意安装</a>
|
||||
</div>
|
||||
</div>
|
||||
</br>
|
||||
|
@ -85,7 +85,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="inout1">
|
||||
<a href="{:url('/index/test')}">上一步</a>
|
||||
<a href="{:url('index/test')}">上一步</a>
|
||||
</div>
|
||||
<div class="inout2">
|
||||
<input type="submit" lay-submit lay-filter="formDemo" value="确认安装">
|
||||
@ -106,7 +106,7 @@
|
||||
|
||||
$.ajax({
|
||||
type:"post",
|
||||
url:"{:url('/index/install')}",
|
||||
url:"{:url('index/install')}",
|
||||
data:{"DB_TYPE":field.DB_TYPE,"DB_HOST":field.DB_HOST,"DB_USER":field.DB_USER,"DB_PWD":field.DB_PWD,"DB_PORT":field.DB_PORT,"DB_NAME":field.DB_NAME,"DB_PREFIX":field.DB_PREFIX,"webname":field.webname,"webtitle":field.webtitle,"admin_user":field.admin_user,"admin_email":field.admin_email,"admin_pass":field.admin_pass,"admin_pass2":field.admin_pass2},
|
||||
daType:"json",
|
||||
success:function (data){
|
||||
|
@ -85,7 +85,7 @@
|
||||
</tr>
|
||||
</table>
|
||||
<div class="inout1">
|
||||
<a href="{:url('/index/index')}">上一步</a>
|
||||
<a href="{:url('index/index')}">上一步</a>
|
||||
</div>
|
||||
<div class="inout2">
|
||||
<a href="javascript:;" onclick="testClick()">下一步</a>
|
||||
@ -97,7 +97,7 @@
|
||||
if ($('.yes').length != 5) {
|
||||
alert('您的配置或权限不符合要求');
|
||||
} else {
|
||||
location.href = '{:url('/index/create')}';
|
||||
location.href = '{:url('index/create')}';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user