Browse Source

安装向导

1.x
xiaoz 6 years ago
parent
commit
3c91867ae9
  1. 8
      config-simple.php
  2. 0
      db/imgurl-simple.db3
  3. 173
      functions/class/class.install.php
  4. 9
      index.php
  5. 41
      install.php
  6. 4
      tpl/user/header.php
  7. 45
      tpl/user/install1.php
  8. 51
      tpl/user/install2.php
  9. 17
      tpl/user/install3.php

8
config.php → config-simple.php

@ -1,14 +1,14 @@
<?php <?php
//项目绝对路径 //项目绝对路径
define("APP","D:/wwwroot/imgurl/"); define("APP","homedir");
//载入数据库类 //载入数据库类
include_once(APP."functions/class/Medoo.php"); include_once(APP."functions/class/Medoo.php");
$config = array( $config = array(
"domain" => "http://localhost/imgurl/", //站点地址 "domain" => "https://imgurl.org/", //站点地址
"user" => "xiaoz", //管理员账号 "user" => "imguser", //管理员账号
"password" => "xiaoz.me", //管理员密码 "password" => "imgpass", //管理员密码
"limit" => 5, //游客上传数量限制 "limit" => 5, //游客上传数量限制
"watermark" => "imgurl.org", //图片文字水印 "watermark" => "imgurl.org", //图片文字水印
"userdir" => "temp", //游客上传目录,一般不用做修改 "userdir" => "temp", //游客上传目录,一般不用做修改

0
db/imgurl.db3 → db/imgurl-simple.db3

173
functions/class/class.install.php

@ -0,0 +1,173 @@
<?php
class Install{
public $homedir;
public $domain;
//构造函数
public function __construct(){
//获取项目绝对路径
$thedir = __DIR__;
$homedir = str_replace("\\","/",$thedir);
$homedir = str_replace("functions/class","",$homedir);
$this->homedir = $homedir;
//获取当前域名
//获取当前端口
$port = $_SERVER["SERVER_PORT"];
//对端口进行判断
switch ( $port )
{
case 80:
$protocol = "http://";
$port = '';
break;
case 443:
$protocol = "https://";
$port = '';
break;
default:
$protocol = "http://";
$port = ":".$port;
break;
}
$uri = $_SERVER["REQUEST_URI"];
$uri = str_replace("check.php","",$uri);
//组合为完整的URL
$domain = $protocol.$_SERVER['SERVER_NAME'].$port.$uri;
$domain = str_replace("install.php?setup=2","",$domain);
$this->domain = $domain;
}
//检查环境是否符合条件
public function check(){
$homedir = $this->homedir;
//echo $homedir.'db';
//检查根目录是否可写,结果写入到一个数组
//echo $thedir;
$checkarr['home'] = is_writable($homedir);
if($checkarr['home']){
$statusarr['home'] = '通过';
}
else{
$statusarr['home'] = '<span style = "color:red;">目录不可写!</span>';
}
$checkarr['db'] = is_writable($homedir.'db');
if($checkarr['db']){
$statusarr['db'] = '通过';
}
else{
$statusarr['db'] = '<span style = "color:red;">目录不可写!</span>';
}
//检测组建是否支持
$ext = get_loaded_extensions();
if(array_search('pdo_sqlite',$ext)){
$statusarr['pdo'] = '支持';
}
else{
$statusarr['pdo'] = '<span style = "color:red;">不支持!</span>';
}
//return $checkarr;
return $statusarr;
}
//获取站点信息
public function info(){
$homedir = $this->homedir;
$info = array(
"homedir" => $this->homedir,
"domain" => $this->domain
);
return $info;
}
//验证函数
protected function verify($data,$type){
switch ($type) {
//检查用户名
case 'user':
$pattern = '/^[a-zA-Z0-9]+$/';
if($data == ''){
echo '请填写用户名!';
exit;
}
if(!preg_match($pattern,$data)){
echo '用户名格式有误!';
exit;
}
break;
case 'pass':
$pattern = '/^[a-zA-Z0-9!@#$%^&*.]+$/';
if(!preg_match($pattern,$data)){
echo '密码格式有误!';
exit;
}
break;
case 'pass2':
$pass1 = $data['pass1'];
$pass2 = $data['pass2'];
if($pass1 != $pass2){
echo '两次密码不一致!';
exit;
}
break;
case 'domain':
$domain = $data['domain'];
if(!filter_var($domain, FILTER_VALIDATE_URL)){
echo '域名格式有误!(需要包含https://)';
exit;
}
break;
default:
# code...
break;
}
}
//安装
public function setup($data){
$homedir = $this->homedir;
$dbpath = $this->homedir.'db/';
$user = $data['user'];
$pass1 = $data['pass1'];
$pass2 = $data['pass2'];
$this->verify($user,'user');
$this->verify($pass1,'pass');
$this->verify($data,'pass2');
$this->verify($data,'domain');
//复制一份数据库
copy($dbpath."imgurl-simple.db3",$dbpath."imgurl.db3");
//复制一份配置文件
if(copy($homedir."config-simple.php",$homedir."config.php")){
$configdir = $homedir."config.php";
$myfile = fopen($homedir."config.php", "r") or die("Unable to open file!");
$content = fread($myfile,filesize($configdir));
//执行替换
$content = str_replace("imguser",$user,$content);
$content = str_replace("imgpass",$pass2,$content);
$content = str_replace("homedir",$data['homedir'],$content);
$content = str_replace("https://imgurl.org/",$data['domain'],$content);
//var_dump($content);
//写入文件
$myfile = fopen($homedir."config.php", "w+") or die("Unable to open file!");
fwrite($myfile, $content);
//关闭
fclose($myfile);
//更名安装文件
rename($homedir."install.php",$homedir."install.php.bak");
}
}
}
?>

9
index.php

@ -1,6 +1,15 @@
<?php <?php
$title = "ImgURL - 简单、纯粹的图床程序。"; $title = "ImgURL - 简单、纯粹的图床程序。";
include_once("./tpl/user/header.php"); include_once("./tpl/user/header.php");
//判断程序是否已安装
$homedir = __DIR__;
$homedir = str_replace("\\","/",$homedir);
//$homedir = str_replace("tpl/user","",$homedir);
$lockfile = $homedir.'/config.php';
if(!file_exists($lockfile)){
header("location:./install.php?setup=1");
}
?> ?>
<div class="layui-container"> <div class="layui-container">

41
install.php

@ -0,0 +1,41 @@
<?php
//载入类
//echo __DIR__."/functions/class/class.install.php";
include_once(__DIR__."/functions/class/class.install.php");
@$setup = (int)$_GET['setup'];
$install = new Install;
$statusarr = $install->check();
$info = $install->info();
switch ($setup) {
case 1:
//载入模板
include_once("./tpl/user/header.php");
include_once("./tpl/user/install1.php");
include_once("./tpl/user/footer.php");
break;
case 2:
include_once("./tpl/user/header.php");
include_once("./tpl/user/install2.php");
include_once("./tpl/user/footer.php");
break;
case 3:
//获取用户名
@$data['user'] = $_POST['user'];
//获取用户密码
@$data['pass1'] = $_POST['pass1'];
@$data['pass2'] = $_POST['pass2'];
@$data['domain'] = $_POST['domain'];
@$data['homedir'] = $_POST['homedir'];
$install->setup($data);
include_once("./tpl/user/header.php");
include_once("./tpl/user/install3.php");
include_once("./tpl/user/footer.php");
break;
default:
header("location:./install.php?setup=1");
break;
}
?>

4
tpl/user/header.php

@ -1,4 +1,6 @@
<?php error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED); ?> <?php
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED);
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh-cmn-Hans" xmlns="http://www.w3.org/1999/xhtml"> <html lang="zh-cmn-Hans" xmlns="http://www.w3.org/1999/xhtml">
<head> <head>

45
tpl/user/install1.php

@ -0,0 +1,45 @@
<div class="layui-container">
<div class="layui-row" style = "margin-top:2em;">
<div class="layui-col-lg8 layui-col-md-offset2">
<center style = "margin-bottom:2em;"><h1>ImgURL安装向导(1/3)</h1></center>
<!-- 检测结果表格 -->
<table class="layui-table">
<colgroup>
<col width="220">
<col width="220">
<col>
</colgroup>
<thead>
<tr>
<th>目录</th>
<th>要求</th>
<th>检测结果</th>
</tr>
</thead>
<tbody>
<tr>
<td>/</td>
<td>读/写</td>
<td><?php echo $statusarr['home']; ?></td>
</tr>
<tr>
<td>/db</td>
<td>读/写</td>
<td><?php echo $statusarr['db']; ?></td>
</tr>
<tr>
<td>组建</td>
<td>pdo_sqlite </td>
<td><?php echo $statusarr['pdo']; ?></td>
</tr>
</tbody>
</table>
<!-- 检测结果表格EDN -->
<!-- 下一步按钮 -->
<div>
<a href="./install.php?setup=2" class="layui-btn">下一步</a>
</div>
<!-- 下一步按钮END -->
</div>
</div>
</div>

51
tpl/user/install2.php

@ -0,0 +1,51 @@
<div class="layui-container">
<div class="layui-row" style = "margin-top:2em;">
<div class="layui-col-lg8 layui-col-md-offset2">
<center style = "margin-bottom:2em;"><h1>ImgURL安装向导(2/3)</h1></center>
<!-- 表单 -->
<form class="layui-form" action="./install.php?setup=3" method = "post">
<div class="layui-form-item">
<label class="layui-form-label">站点路径</label>
<div class="layui-input-block">
<input type="text" name="homedir" required lay-verify="required" placeholder="一般保持默认" autocomplete="off" class="layui-input" value = <?php echo $info['homedir']; ?>>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">站点域名</label>
<div class="layui-input-block">
<input type="text" name="domain" required lay-verify="required" placeholder="一般保持默认" autocomplete="off" class="layui-input" value = <?php echo $info['domain']; ?>>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">用户名</label>
<div class="layui-input-block">
<input type="text" name="user" required lay-verify="required" placeholder="字母或数字组合" 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="pass1" required lay-verify="required" placeholder="设置密码" 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="pass2" required lay-verify="required" placeholder="再次确认密码" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<a href="./install.php?setup=1" class="layui-btn">上一步</a>
<button class="layui-btn" lay-submit lay-filter="formDemo">开始安装</button>
</div>
</div>
</form>
<!-- 表单EDN -->
<!-- 下一步按钮 -->
<!-- 下一步按钮END -->
</div>
</div>
</div>

17
tpl/user/install3.php

@ -0,0 +1,17 @@
<div class="layui-container">
<div class="layui-row" style = "margin-top:2em;">
<div class="layui-col-lg8 layui-col-md-offset2">
<center style = "margin-bottom:2em;"><h1>安装完成!(3/3)</h1></center>
<!-- 安装完成 -->
<div style = "text-align:center;">
<div class="layui-btn-group">
<a href="./" class="layui-btn">返回首页</a>
<a href="./admin/login.php" class="layui-btn">登录后台</a>
<a class="layui-btn" href="https://doc.xiaoz.me/#/imgurl/">查看帮助文档</a>
<a class="layui-btn" href="https://dwz.ovh/imgurl" rel = "nofollow" target = "_blank">打赏支持</a>
</div>
</div>
<!-- 安装完成END -->
</div>
</div>
</div>
Loading…
Cancel
Save