<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="gb2312">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<title>ᲩͰװ</title>
<style>
body {
background: #444;
font-family: "Lucida Sans Unicode", Helvetica, "Microsoft Yahei", "Microsoft JhengHei", STHei, "Meiryo UI";
height:100%;color:#fff
}
a{color:#fff}
.abt{border: 1px solid #EFEFEF;
border-radius: 5px;
padding: 6px;
cursor: pointer; background: #fff;color:#000}
.txt{}
.green{color:#28a745;}
.red{color:red;}
.ft{margin-top:80px;}
</style>
</head>
<body>
<div style="padding:60px 0 0 0;line-height:30px;max-width:750px;margin:0 auto">
<h1>ӭʹ</h1>
<p class="txt">ᲩһPHP+Sqliteļõĸ΢ϵͳ(miniblog)Ϊṩ١ȶʹּ򵥡ʵĲͷ</p>
<?php
install();
function endfoot(){
     echo '<p class="ft" align="center">Powered by <a href="https://fpx.ink/" target="_blank">Ჩ</a> V4 ,  Design by <a href="https://www.4jax.net/" target="_blank">www.4jax.net</a></p>';
     exit('</div></body></html>');      
}
function install(){
$cfg = ROOT_PATH.'app/class/config.php';
 if(!isset($_GET['install'])){ 
		  $err = 0;
		   
  if(PHP_VERSION>=5.6)
  {
   echo '<p class="green">ǰPHP汾'.PHP_VERSION.' []</p>';
  }
else
  {
    echo '<p class="red">PHP汾Ҫ5.6ǰ汾'.PHP_VERSION.'[]</p>';
    $err++;
  }


  if(is_writable(ROOT_PATH.'app/db/'))
  {
  echo '<p class="green">ݿĿ¼д[]</p>';
  }
else
  {
    echo '<p class="red">'.ROOT_PATH.'app/db/ݿĿ¼д[]</p>';
    $err++;
  }
  if(extension_loaded("pdo_sqlite")){
     echo '<p class="green">PDO_SQLITEã[]</p>';
  }else{
    echo '<p class="red">PDO_SQLITEݿⲻ֧֣[]</p>';
    $err++;
  }
if(is_writable($cfg))
  {
    echo '<p class="green">ļд[]</p>';
  }
else
  {
	echo '<p class="red">'.$cfg.'ļд[]</p>';
    $err++;
}     if($err>0){echo 'װ/Ȩ޲㣬޷ʹ';endfoot();}
		   echo '<a class="abt" href="?install=1">ʼװ</a>';
           endfoot();
      }
      $key =  md5(time().'XXGMSG');
      $p = 'admin'.substr($key,2,4);
      $db = substr($key,16,12);
      $key = substr($key,10,6);	  
	  $f = file_get_contents($cfg);
	  $ckey = "define('KEY','$key');";
	  $cdb = "define('DB',ROOT_PATH.'app/db/$db.db');";
      $f = preg_replace("/define\('KEY','.+?'\);/i",$ckey,$f);
      $f = preg_replace("/define\('DB',.+?;/i",$cdb,$f);
	  $f = preg_replace("/\/\*install-start\*\/.+?\/\*install-end\*\//is","define('INSTALL','TRUE');",$f);
	  rename(DB,ROOT_PATH."app/db/".$db.".db");
	  $f = file_put_contents($cfg,$f);
	  $_SESSION[$key.'set'] = array();
          $_SESSION[$key.'admin'] = 1;	  
	  $webpss = md5(md5($key.$p));
	  try{ 
            $dbh = new PDO('sqlite:'.ROOT_PATH."app/db/".$db.".db");
            $dbh->exec("update [set] set webpass='{$webpss}' where id=1");
          }catch (PDOException $e)
          {
            exit('<p>ݿʧܣݿʧܣ</p>');
          }
          echo '<p>ϵͳʼɣΪ'.$p.'</p>' ;
	  echo '<p><a class="abt" href="?ok">ʼʹ</a></p>';	   
	  unlink('app/class/install.txt');
	  endfoot();   
} 
?>