install repair
This commit is contained in:
parent
4aff159ee6
commit
a9f5deaf52
@ -43,7 +43,7 @@ function write_config($config)
|
|||||||
/**
|
/**
|
||||||
* 创建数据表
|
* 创建数据表
|
||||||
* @param resource $db 数据库连接资源
|
* @param resource $db 数据库连接资源
|
||||||
* @param string $prefix
|
* @param string $prefix 数据表前缀
|
||||||
*/
|
*/
|
||||||
function create_tables($db, $prefix = '') {
|
function create_tables($db, $prefix = '') {
|
||||||
// 导入sql数据并创建表
|
// 导入sql数据并创建表
|
||||||
@ -58,17 +58,12 @@ function create_tables($db, $prefix = '') {
|
|||||||
if (!empty($v)) {
|
if (!empty($v)) {
|
||||||
//$v=$v.';';
|
//$v=$v.';';
|
||||||
if (substr($v, 0, 12) == 'CREATE TABLE') {
|
if (substr($v, 0, 12) == 'CREATE TABLE') {
|
||||||
//echo 'ddddddddddddddddd';
|
|
||||||
$name = preg_replace("/^CREATE TABLE `(\w+)` .*/s", "\\1", $v);
|
$name = preg_replace("/^CREATE TABLE `(\w+)` .*/s", "\\1", $v);
|
||||||
$msg = "创建数据表{$name}";
|
$msg = "创建数据表{$name}";
|
||||||
if (false !== $db->query($v)) {
|
if (false !== $db->query($v)) {
|
||||||
//show_msg($msg . '...成功!');
|
//echo $msg.'成功';
|
||||||
//echo '成功';
|
|
||||||
} else {
|
} else {
|
||||||
echo '失败';
|
echo $msg.'失败';
|
||||||
|
|
||||||
//show_msg($msg . '...失败!', 'error');
|
|
||||||
//Session::set('error', true, 'install');
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$db->query($v);
|
$db->query($v);
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
// 数据库连接配置信息
|
|
||||||
'connections' => [
|
|
||||||
'mysql' => [
|
|
||||||
// 数据库类型
|
|
||||||
'type' => 'mysql',
|
|
||||||
// 服务器地址
|
|
||||||
'hostname' => '',
|
|
||||||
// 数据库名
|
|
||||||
'database' => '',
|
|
||||||
// 用户名
|
|
||||||
'username' => '',
|
|
||||||
// 密码
|
|
||||||
'password' => '',
|
|
||||||
// 端口
|
|
||||||
'hostport' => '',
|
|
||||||
// 数据库编码默认采用utf8
|
|
||||||
'charset' => 'utf8',
|
|
||||||
// 数据库表前缀
|
|
||||||
'prefix' => '',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
@ -55,11 +55,8 @@ class Index extends BaseController
|
|||||||
// return redirect('./create.html');
|
// return redirect('./create.html');
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// 判断是否为post
|
|
||||||
//if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
||||||
if(Request::isAjax()){
|
if(Request::isAjax()){
|
||||||
$data = Request::param();
|
$data = Request::param();
|
||||||
//$data = $_POST;
|
|
||||||
//var_dump($data);
|
//var_dump($data);
|
||||||
if (!preg_match("/^[a-zA-Z]{1}([0-9a-zA-Z]|[._]){4,19}$/", $data['admin_user'])) {
|
if (!preg_match("/^[a-zA-Z]{1}([0-9a-zA-Z]|[._]){4,19}$/", $data['admin_user'])) {
|
||||||
die("<script>alert('后台管理用户名不符合规范:至少包含4个字符,需以字母开头');history.go(-1)</script>");
|
die("<script>alert('后台管理用户名不符合规范:至少包含4个字符,需以字母开头');history.go(-1)</script>");
|
||||||
@ -70,69 +67,45 @@ class Index extends BaseController
|
|||||||
}
|
}
|
||||||
if ($data['admin_pass'] != $data['admin_pass2']) {
|
if ($data['admin_pass'] != $data['admin_pass2']) {
|
||||||
die("<script>alert('两次输入的密码不一致');history.go(-1)</script>");
|
die("<script>alert('两次输入的密码不一致');history.go(-1)</script>");
|
||||||
|
|
||||||
}
|
}
|
||||||
$_SESSION['adminusername'] = $data['admin_user'];
|
|
||||||
$email = $data['admin_email'];
|
$email = $data['admin_email'];
|
||||||
$user = $data['admin_user'];
|
$user = $data['admin_user'];
|
||||||
$create_time = time();
|
$create_time = time();
|
||||||
$salt = substr(md5($create_time),-6);
|
$salt = substr(md5($create_time),-6);
|
||||||
$pass = md5(substr_replace(md5($data['admin_pass']),$salt,0,6));
|
$pass = md5(substr_replace(md5($data['admin_pass']),$salt,0,6));
|
||||||
|
|
||||||
|
$dbhost = $data['DB_HOST'];
|
||||||
|
$dbuser = $data['DB_USER'];
|
||||||
|
$dbpass = $data['DB_PWD'];
|
||||||
|
$dbport = $data['DB_PORT'];
|
||||||
|
$dbname = $data['DB_NAME'];
|
||||||
|
$prefix = $data['DB_PREFIX'];
|
||||||
|
|
||||||
if ($data['DB_TYPE'] == 'mysql') {
|
if ($data['DB_TYPE'] == 'mysql') {
|
||||||
|
|
||||||
//数据库
|
//创建数据库
|
||||||
$db_s = <<<php
|
try {
|
||||||
<?php
|
$conn = new \PDO("mysql:host=$dbhost", $dbuser, $dbpass);
|
||||||
return [
|
|
||||||
// 数据库连接配置信息
|
|
||||||
'connections' => [
|
|
||||||
'mysql' => [
|
|
||||||
// 数据库类型
|
|
||||||
'type' => 'mysql',
|
|
||||||
// 服务器地址
|
|
||||||
'hostname' => '{$data['DB_HOST']}',
|
|
||||||
// 数据库名
|
|
||||||
'database' => '{$data['DB_NAME']}',
|
|
||||||
// 用户名
|
|
||||||
'username' => '{$data['DB_USER']}',
|
|
||||||
// 密码
|
|
||||||
'password' => '{$data['DB_PWD']}',
|
|
||||||
// 端口
|
|
||||||
'hostport' => '{$data['DB_PORT']}',
|
|
||||||
// 数据库编码默认采用utf8
|
|
||||||
'charset' => 'utf8',
|
|
||||||
// 数据库表前缀
|
|
||||||
'prefix' => '{$data['DB_PREFIX']}',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
php;
|
|
||||||
// 创建数据库链接配置文件
|
|
||||||
|
|
||||||
$fp = fopen('../app/install/config/database.php', "r+b");
|
|
||||||
fputs($fp, $db_s);
|
|
||||||
fclose($fp);
|
|
||||||
|
|
||||||
$db = Db::connect('mysql');
|
|
||||||
|
|
||||||
//$sql = 'CREATE DATABASE IF NOT EXISTS '.$data['DB_NAME'].' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci';
|
|
||||||
//$db->execute($sql);
|
|
||||||
|
|
||||||
//创建数据表
|
|
||||||
create_tables($db, $data['DB_PREFIX']);
|
|
||||||
|
|
||||||
$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()]);
|
|
||||||
|
|
||||||
Db::getConnection()->close();
|
|
||||||
}
|
}
|
||||||
|
catch(\PDOException $e)
|
||||||
|
{
|
||||||
|
return json(['code'=>-1,'msg'=>"数据库连接失败" . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = 'CREATE DATABASE IF NOT EXISTS '.$dbname.' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci';
|
||||||
|
|
||||||
|
// 使用 exec() ,没有结果返回
|
||||||
|
$conn->exec($sql);
|
||||||
|
//echo $dbname."数据库创建成功<br>";
|
||||||
|
|
||||||
|
$conn = null;
|
||||||
|
|
||||||
|
//写入数据表
|
||||||
|
$db = new \PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
|
||||||
|
create_tables($db,$prefix);
|
||||||
|
$db = null;
|
||||||
|
|
||||||
|
|
||||||
$db_str = <<<php
|
$db_str = <<<php
|
||||||
<?php
|
<?php
|
||||||
@ -189,13 +162,28 @@ return [
|
|||||||
];
|
];
|
||||||
php;
|
php;
|
||||||
// 创建数据库链接配置文件
|
// 创建数据库链接配置文件
|
||||||
$fp = fopen('../config/database.php', "r+b");
|
$fp = fopen("../config/database.php","w");
|
||||||
fwrite($fp, $db_str);
|
$res = fwrite($fp, $db_str);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
if(!$res){
|
||||||
|
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');
|
file_put_contents('../install.lock', 'lock');
|
||||||
Session::clear();
|
Session::clear();
|
||||||
//return View::fetch('complete');
|
|
||||||
return json(['code' => 0,'msg'=>'安装成功','url'=>'/install.php/success/complete']);
|
return json(['code' => 0,'msg'=>'安装成功','url'=>'/install.php/success/complete']);
|
||||||
} else {
|
} else {
|
||||||
return '请求失败!';
|
return '请求失败!';
|
||||||
|
@ -63,7 +63,7 @@
|
|||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">管理员用户名</label>
|
<label class="layui-form-label">管理员用户名</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="text" name="admin_user" placeholder="至少4字符" required lay-verify="required" autocomplete="off" class="layui-input">
|
<input type="text" name="admin_user" placeholder="至少5字符" required lay-verify="required" autocomplete="off" class="layui-input">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
|
Loading…
Reference in New Issue
Block a user