From 3c91867ae9ef465c9b770f93ac72f5d691f98afe Mon Sep 17 00:00:00 2001 From: xiaoz Date: Tue, 6 Nov 2018 18:46:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E8=A3=85=E5=90=91=E5=AF=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.php => config-simple.php | 8 +- db/{imgurl.db3 => imgurl-simple.db3} | Bin functions/class/class.install.php | 173 +++++++++++++++++++++++++++ index.php | 9 ++ install.php | 41 +++++++ tpl/user/header.php | 4 +- tpl/user/install1.php | 45 +++++++ tpl/user/install2.php | 51 ++++++++ tpl/user/install3.php | 17 +++ 9 files changed, 343 insertions(+), 5 deletions(-) rename config.php => config-simple.php (82%) rename db/{imgurl.db3 => imgurl-simple.db3} (100%) create mode 100644 functions/class/class.install.php create mode 100644 install.php create mode 100644 tpl/user/install1.php create mode 100644 tpl/user/install2.php create mode 100644 tpl/user/install3.php diff --git a/config.php b/config-simple.php similarity index 82% rename from config.php rename to config-simple.php index b715659..88f8a3b 100644 --- a/config.php +++ b/config-simple.php @@ -1,14 +1,14 @@ "http://localhost/imgurl/", //站点地址 - "user" => "xiaoz", //管理员账号 - "password" => "xiaoz.me", //管理员密码 + "domain" => "https://imgurl.org/", //站点地址 + "user" => "imguser", //管理员账号 + "password" => "imgpass", //管理员密码 "limit" => 5, //游客上传数量限制 "watermark" => "imgurl.org", //图片文字水印 "userdir" => "temp", //游客上传目录,一般不用做修改 diff --git a/db/imgurl.db3 b/db/imgurl-simple.db3 similarity index 100% rename from db/imgurl.db3 rename to db/imgurl-simple.db3 diff --git a/functions/class/class.install.php b/functions/class/class.install.php new file mode 100644 index 0000000..8b03317 --- /dev/null +++ b/functions/class/class.install.php @@ -0,0 +1,173 @@ +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'] = '目录不可写!'; + + } + $checkarr['db'] = is_writable($homedir.'db'); + if($checkarr['db']){ + $statusarr['db'] = '通过'; + } + else{ + $statusarr['db'] = '目录不可写!'; + + } + //检测组建是否支持 + $ext = get_loaded_extensions(); + if(array_search('pdo_sqlite',$ext)){ + $statusarr['pdo'] = '支持'; + } + else{ + $statusarr['pdo'] = '不支持!'; + } + //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"); + } + + } + } +?> \ No newline at end of file diff --git a/index.php b/index.php index 46ac27f..ef4ef1b 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,15 @@
diff --git a/install.php b/install.php new file mode 100644 index 0000000..94fffca --- /dev/null +++ b/install.php @@ -0,0 +1,41 @@ +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; + } +?> \ No newline at end of file diff --git a/tpl/user/header.php b/tpl/user/header.php index f98bf3f..eca7200 100644 --- a/tpl/user/header.php +++ b/tpl/user/header.php @@ -1,4 +1,6 @@ - + diff --git a/tpl/user/install1.php b/tpl/user/install1.php new file mode 100644 index 0000000..04d1e17 --- /dev/null +++ b/tpl/user/install1.php @@ -0,0 +1,45 @@ +
+
+
+

ImgURL安装向导(1/3)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
目录要求检测结果
/读/写
/db读/写
组建pdo_sqlite
+ + +
+ 下一步 +
+ +
+
+
\ No newline at end of file diff --git a/tpl/user/install2.php b/tpl/user/install2.php new file mode 100644 index 0000000..bd1e81a --- /dev/null +++ b/tpl/user/install2.php @@ -0,0 +1,51 @@ +
+
+
+

ImgURL安装向导(2/3)

+ +
+
+ +
+ > +
+
+
+ +
+ > +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+ 上一步 + +
+
+
+ + + + +
+
+
\ No newline at end of file diff --git a/tpl/user/install3.php b/tpl/user/install3.php new file mode 100644 index 0000000..e2c4650 --- /dev/null +++ b/tpl/user/install3.php @@ -0,0 +1,17 @@ +
+
+
+

安装完成!(3/3)

+ + + +
+
+
\ No newline at end of file