'请输入数据库地址', 'db_u' => '请输入数据库用户名', 'db_p' => '请输入数据库密码', 'db_name' => '请输入数据库名', 'adm_u' => '请输入管理员账号', 'adm_p' => '请输入管理员密码' ]; foreach ($error as $key => $val) { if (!array_isset($_POST, $key)) { $error_msg = $val; break; } } if (!$error_msg) { $app_user = $_POST['adm_u']; $app_pass = $_POST['adm_p']; $app_cookie = md5($app_user.$app_pass.time()); $db_pre = isset($_POST['db_pre']) ? addslashes($_POST['db_pre']) : ''; $conn = @mysqli_connect($_POST['db_server'], $_POST['db_u'], $_POST['db_p']); mysqli_query($conn,"set names utf8"); if ($conn) { if (@mysqli_select_db($conn, $_POST['db_name'])) { require_once 'eruyi_1.7.php';//引入数据表 foreach($sql as $value){ // die($value); mysqli_query($conn,$value); } $config = file_get_contents($web_mulu.'/include/db.config.php'); $config = preg_replace("/define\('DB_HOST','.*?'\)/", "define('DB_HOST','{$_POST['db_server']}')", $config); $config = preg_replace("/define\('DB_USER','.*?'\)/", "define('DB_USER','{$_POST['db_u']}')", $config); $config = preg_replace("/define\('DB_PASSWD','.*?'\)/", "define('DB_PASSWD','{$_POST['db_p']}')", $config); $config = preg_replace("/define\('DB_NAME','.*?'\)/", "define('DB_NAME','{$_POST['db_name']}')", $config); $config = preg_replace("/define\('DB_PRE','.*?'\)/", "define('DB_PRE','{$db_pre}')", $config); file_put_contents('../include/db.config.php', $config); $userdata = file_get_contents($web_mulu.'/admin/userdata.php'); $userdata = preg_replace('/\$user = \'.*?\'/', '$user = \'' . $_POST['adm_u'] . '\'', $userdata); $userdata = preg_replace('/\$pass = \'.*?\'/', '$pass = \'' . $_POST['adm_p'] . '\'', $userdata); $userdata = preg_replace('/\$cookie = \'.*?\'/', '$cookie = \'' . md5($_POST['adm_u'].$_POST['adm_p'].time()) . '\'', $userdata); file_put_contents($web_mulu.'/admin/userdata.php', $userdata); $content = file_get_contents($web_mulu.'/app/api.json'); $content = str_replace('http://itvbox0.lvdoui.net', $web_url, $content); file_put_contents($web_mulu.'/app/api.json', $content); $content = file_get_contents($web_mulu.'/admin/ajax.php'); $content = str_replace('json(201,\'对不起~演示数据,请勿修改数据\');', "", $content); file_put_contents($web_mulu.'/admin/ajax.php', $content); $content = file_get_contents($web_mulu.'/app/signer.sh'); $content = str_replace('/www/wwwroot/itvbox.lvdoui.net/app', $web_mulu.'/app', $content); file_put_contents($web_mulu.'/app/signer.sh', $content); //-------生成唯一随机串防CSRF攻击 $state = md5(uniqid(rand(),TRUE)); setcookie('install_state', $state, time() + 3600, '/'); header("Location: ./?a=2&s={$state}"); } else { $error_msg = '未找到数据库'; } } else { $error_msg = '错误的数据库信息,连接失败'; } } } if($a==2){ if(!isset($_GET['s']) or !isset($_COOKIE['install_state']) or $_GET['s'] != $_COOKIE['install_state']){ header("Location: ../"); } } function array_isset($arr, $key){ return isset($arr[$key]) && !empty($arr[$key]); } ?>