mirror of https://github.com/helloxz/onenav.git
xiaoz
3 years ago
9 changed files with 302 additions and 17 deletions
@ -0,0 +1,110 @@
@@ -0,0 +1,110 @@
|
||||
<?php |
||||
/** |
||||
* name: OneNav安装初始化文件 |
||||
* author: xiaoz<xiaoz93@outlook.com> |
||||
*/ |
||||
|
||||
/** |
||||
* 安装前先检查环境 |
||||
*/ |
||||
function check_env() { |
||||
//获取组件信息 |
||||
$ext = get_loaded_extensions(); |
||||
//检查PHP版本,需要大于5.6小于8.0 |
||||
$php_version = floatval(PHP_VERSION); |
||||
|
||||
if( ( $php_version < 5.6 ) || ( $php_version > 8 ) ) { |
||||
exit("当前PHP版本{$php_version}不满足要求,需要5.6 <= PHP <= 7.4"); |
||||
} |
||||
|
||||
//检查是否支持pdo_sqlite |
||||
if ( !array_search('pdo_sqlite',$ext) ) { |
||||
exit("不支持PDO_SQLITE组件,请先开启!"); |
||||
} |
||||
//如果配置文件存在 |
||||
if( file_exists("data/config.php") ) { |
||||
exit("配置文件已存在,无需再次初始化!"); |
||||
} |
||||
return TRUE; |
||||
} |
||||
|
||||
/** |
||||
* 安装OneNav |
||||
*/ |
||||
function install() { |
||||
if( !file_exists('./data/config.php') ) { |
||||
//复制配置文件 |
||||
//加载初始化模板 |
||||
require("templates/admin/init.php"); |
||||
exit(); |
||||
} |
||||
else { |
||||
|
||||
} |
||||
} |
||||
|
||||
function err_msg($code,$err_msg){ |
||||
$data = [ |
||||
'code' => $code, |
||||
'err_msg' => $err_msg |
||||
]; |
||||
//返回json类型 |
||||
header('Content-Type:application/json; charset=utf-8'); |
||||
exit(json_encode($data)); |
||||
} |
||||
/** |
||||
* 初始化设置OneNav |
||||
*/ |
||||
function init($data){ |
||||
//判断参数是否为空 |
||||
if( empty($data['username']) || empty($data['password']) ) { |
||||
err_msg(-2000,'用户名或密码不能为空!'); |
||||
} |
||||
$config_file = "data/config.php"; |
||||
//检查配置文件是否存在,存在则不允许设置 |
||||
if( file_exists($config_file) ) { |
||||
err_msg(-2000,'配置文件已存在,无需再次初始化!'); |
||||
} |
||||
//复制配置文件 |
||||
|
||||
//读取配置文件内容 |
||||
$content = file_get_contents("config.simple.php"); |
||||
//替换内容 |
||||
$content = str_replace('{email}',$data['email'],$content); |
||||
$content = str_replace('{username}',$data['username'],$content); |
||||
$content = str_replace('{password}',$data['password'],$content); |
||||
|
||||
//写入配置文件 |
||||
if( !file_put_contents($config_file,$content) ) { |
||||
err_msg(-2000,'写入配置文件失败,请检查目录权限!'); |
||||
} |
||||
else{ |
||||
//成功并返回json格式 |
||||
$data = [ |
||||
'code' => 200, |
||||
'msg' => "初始化完成!" |
||||
]; |
||||
header('Content-Type:application/json; charset=utf-8'); |
||||
exit(json_encode($data)); |
||||
} |
||||
} |
||||
|
||||
$c = @$_GET['c']; |
||||
|
||||
check_env(); |
||||
|
||||
if ( $c == 'init' ) { |
||||
//接收POST参数 |
||||
$email = htmlspecialchars(trim($_POST['email'])); |
||||
$username = htmlspecialchars(trim($_POST['username'])); |
||||
$password = htmlspecialchars(trim($_POST['password'])); |
||||
$data = [ |
||||
"email" => $email, |
||||
"username" => $username, |
||||
"password" => $password |
||||
]; |
||||
init($data); |
||||
} |
||||
else{ |
||||
install(); |
||||
} |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html> |
||||
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml"> |
||||
<head> |
||||
<meta charset="utf-8" /> |
||||
<title>初始化OneNav用户名/密码</title> |
||||
<meta name="generator" content="EverEdit" /> |
||||
<meta name="author" content="" /> |
||||
<meta name="keywords" content="" /> |
||||
<meta name="description" content="" /> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> |
||||
<link rel='stylesheet' href='static/layui/css/layui.css'> |
||||
<link rel='stylesheet' href='templates/admin/static/style.css'> |
||||
<style> |
||||
body{ |
||||
/* background:url(templates/admin/static/bg.jpg); */ |
||||
background-color:rgba(0, 0, 51, 0.8); |
||||
|
||||
} |
||||
|
||||
</style> |
||||
</head> |
||||
<body> |
||||
|
||||
<div class="layui-container"> |
||||
<div class="layui-row"> |
||||
<div class="login-logo"> |
||||
<h1>初始化OneNav用户名/密码</h1> |
||||
</div> |
||||
<div class="layui-col-lg4 layui-col-md-offset4" style ="margin-top:4em;"> |
||||
<form class="layui-form layui-form-pane" action=""> |
||||
<div class="layui-form-item"> |
||||
<label class="layui-form-label">用户名</label> |
||||
<div class="layui-input-block"> |
||||
<input type="text" name="username" required lay-verify="required" placeholder="3-32位的字母或数字" autocomplete="off" class="layui-input"> |
||||
</div> |
||||
</div> |
||||
<div class="layui-form-item"> |
||||
<label class="layui-form-label">密码</label> |
||||
<div class="layui-input-block"> |
||||
<input type="password" name="password" required lay-verify="required" placeholder="6-16位字母、数字或特殊字符" autocomplete="off" class="layui-input"> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="layui-form-item"> |
||||
<label class="layui-form-label">确认密码</label> |
||||
<div class="layui-input-block"> |
||||
<input type="password" name="password2" required lay-verify="required" placeholder="6-16位字母、数字或特殊字符" autocomplete="off" class="layui-input"> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="layui-form-item"> |
||||
<button class="layui-btn" lay-submit lay-filter="init_onenav" style = "width:100%;">设置</button> |
||||
</div> |
||||
|
||||
</form> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
|
||||
<script src = 'static/js/jquery.min.js'></script> |
||||
<script src = 'static/layui/layui.js'></script> |
||||
<script src="templates/admin/static/embed.js"></script> |
||||
</body> |
||||
</html> |
Loading…
Reference in new issue