60.2.50.91 admin.php,public/install.php · 52AMore/fastadmin - Gitee.com

/**

* FastAdmin安装程序

*

* 安装完成后建议删除此文件

* @author Karson

* @website http://www.fastadmin.net

*/

// 定义目录分隔符

define('DS', DIRECTORY_SEPARATOR);

// 定义根目录

define('ROOT_PATH', __DIR__ . DS . '..' . DS);

// 定义应用目录

define('APP_PATH', ROOT_PATH . 'application' . DS);

// 安装包目录

define('INSTALL_PATH', APP_PATH . 'admin' . DS . 'command' . DS . 'Install' . DS);

// 判断文件或目录是否有写的权限

function is_really_writable($file)

{

if (DIRECTORY_SEPARATOR == '/' AND @ ini_get("safe_mode") == FALSE)

{

return is_writable($file);

}

if (!is_file($file) OR ( $fp = @fopen($file, "r+")) === FALSE)

{

return FALSE;

}

fclose($fp);

return TRUE;

}

$sitename = "FastAdmin";

$link = array(

'qqun' => "https://jq.qq.com/?_wv=1027&k=487PNBb",

'osc' => 'https://git.oschina.net/karson/fastadmin/attach_files',

'home' => 'http://www.fastadmin.net?ref=install',

'forum' => 'http://forum.fastadmin.net?ref=install',

'doc' => 'http://doc.fastadmin.net?ref=install',

);

// 检测目录是否存在

$checkDirs = [

'thinkphp',

'vendor',

'public' . DS . 'assets' . DS . 'libs'

];

//缓存目录

$runtimeDir = APP_PATH . 'runtime';

//错误信息

$errInfo = '';

//数据库配置文件

$dbConfigFile = APP_PATH . 'database.php';

// 锁定的文件

$lockFile = INSTALL_PATH . 'install.lock';

if (is_file($lockFile))

{

$errInfo = "当前已经安装{$sitename},如果需要重新安装,请手动移除application/admin/command/Install/install.lock文件";

}

else if (version_compare(PHP_VERSION, '5.5.0', '

{

$errInfo = "当前版本(" . PHP_VERSION . ")过低,请使用PHP5.5以上版本";

}

else if (!extension_loaded("PDO"))

{

$errInfo = "当前未开启PDO,无法进行安装";

}

else if (!is_really_writable($dbConfigFile))

{

$errInfo = "当前权限不足,无法写入配置文件application/database.php";

}

else

{

$dirArr = [];

foreach ($checkDirs as $k => $v)

{

if (!is_dir(ROOT_PATH . $v))

{

$errInfo = '请先下载完整包覆盖后再安装,群共享下载 码云下载';

break;

}

}

}

// 当前是POST请求

if (!$errInfo && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST')

{

$err = '';

$mysqlHostname = isset($_POST['mysqlHost']) ? $_POST['mysqlHost'] : 'localhost';

$mysqlHostport = 3306;

$hostArr = explode(':', $mysqlHostname);

if (count($hostArr) > 1)

{

$mysqlHostname = $hostArr[0];

$mysqlHostport = $hostArr[1];

}

$mysqlUsername = isset($_POST['mysqlUsername']) ? $_POST['mysqlUsername'] : 'root';

$mysqlPassword = isset($_POST['mysqlPassword']) ? $_POST['mysqlPassword'] : '';

$mysqlDatabase = isset($_POST['mysqlDatabase']) ? $_POST['mysqlDatabase'] : 'fastadmin';

$adminUsername = isset($_POST['adminUsername']) ? $_POST['adminUsername'] : 'admin';

$adminPassword = isset($_POST['adminPassword']) ? $_POST['adminPassword'] : '123456';

$adminPasswordConfirmation = isset($_POST['adminPasswordConfirmation']) ? $_POST['adminPasswordConfirmation'] : '123456';

$adminEmail = isset($_POST['adminEmail']) ? $_POST['adminEmail'] : 'admin@admin.com';

if ($adminPassword !== $adminPasswordConfirmation)

{

echo "两次输入的密码不一致";

exit;

}

else if (!preg_match("/^\w+$/", $adminUsername))

{

echo "用户名只能输入字母、数字、下划线";

exit;

}

else if (!preg_match("/^[\S]+$/", $adminPassword))

{

echo "密码不能包含空格";

exit;

}

else if (strlen($adminUsername) < 3 || strlen($adminUsername) > 12)

{

echo "用户名请输入3~12位字符";

exit;

}

else if (strlen($adminPassword) < 6 || strlen($adminPassword) > 16)

{

echo "密码请输入6~16位字符";

exit;

}

try

{

//检测能否读取安装文件

$sql = @file_get_contents(INSTALL_PATH . 'fastadmin.sql');

if (!$sql)

{

throw new Exception("无法读取application/admin/command/Install/fastadmin.sql文件,请检查是否有读权限");

}

$pdo = new PDO("mysql:host={$mysqlHostname};port={$mysqlHostport}", $mysqlUsername, $mysqlPassword, array(

PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,

PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"

));

$pdo->query("CREATE DATABASE IF NOT EXISTS `{$mysqlDatabase}` CHARACTER SET utf8 COLLATE utf8_general_ci;");

$pdo->query("USE `{$mysqlDatabase}`");

$pdo->exec($sql);

$config = @file_get_contents($dbConfigFile);

$callback = function($matches) use($mysqlHostname, $mysqlHostport, $mysqlUsername, $mysqlPassword, $mysqlDatabase) {

$field = ucfirst($matches[1]);

$replace = ${"mysql{$field}"};

if ($matches[1] == 'hostport' && $mysqlHostport == 3306)

{

$replace = '';

}

return "'{$matches[1]}'{$matches[2]}=>{$matches[3]}'{$replace}',";

};

$config = preg_replace_callback("/'(hostname|database|username|password|hostport)'(\s+)=>(\s+)'(.*)'\,/", $callback, $config);

//检测能否成功写入数据库配置

$result = @file_put_contents($dbConfigFile, $config);

if (!$result)

{

throw new Exception("无法写入数据库信息到application/database.php文件,请检查是否有写权限");

}

//检测能否成功写入lock文件

$result = @file_put_contents($lockFile, 1);

if (!$result)

{

throw new Exception("无法写入安装锁定到application/admin/command/Install/install.lock文件,请检查是否有写权限");

}

$newSalt = substr(md5(uniqid(true)), 0, 6);

$newPassword = md5(md5($adminPassword) . $newSalt);

$pdo->query("UPDATE fa_admin SET username = '{$adminUsername}', email = '{$adminEmail}',password = '{$newPassword}', salt = '{$newSalt}' WHERE username = 'admin'");

echo "success";

}

catch (Exception $e)

{

$err = $e->getMessage();

}

catch (PDOException $e)

{

$err = $e->getMessage();

}

echo $err;

exit;

}

?>

安装<?php echo $sitename; ?>

body {

background: #fff;

margin: 0;

padding: 0;

line-height: 1.5;

}

body, input, button {

font-family: 'Open Sans', sans-serif;

font-size: 16px;

color: #7E96B3;

}

.container {

max-width: 515px;

margin: 0 auto;

padding: 20px;

text-align: center;

}

a {

color: #18bc9c;

text-decoration: none;

}

a:hover {

text-decoration: underline;

}

h1 {

margin-top:0;

margin-bottom: 10px;

}

h2 {

font-size: 28px;

font-weight: normal;

color: #3C5675;

margin-bottom: 0;

}

form {

margin-top: 40px;

}

.form-group {

margin-bottom: 20px;

}

.form-group .form-field:first-child input {

border-top-left-radius: 4px;

border-top-right-radius: 4px;

}

.form-group .form-field:last-child input {

border-bottom-left-radius: 4px;

border-bottom-right-radius: 4px;

}

.form-field input {

background: #EDF2F7;

margin: 0 0 1px;

border: 2px solid transparent;

transition: background 0.2s, border-color 0.2s, color 0.2s;

width: 100%;

padding: 15px 15px 15px 180px;

box-sizing: border-box;

}

.form-field input:focus {

border-color: #18bc9c;

background: #fff;

color: #444;

outline: none;

}

.form-field label {

float: left;

width: 160px;

text-align: right;

margin-right: -160px;

position: relative;

margin-top: 18px;

font-size: 14px;

pointer-events: none;

opacity: 0.7;

}

button,.btn {

background: #3C5675;

color: #fff;

border: 0;

font-weight: bold;

border-radius: 4px;

cursor: pointer;

padding: 15px 30px;

-webkit-appearance: none;

}

button[disabled] {

opacity: 0.5;

}

#error,.error,#success,.success {

background: #D83E3E;

color: #fff;

padding: 15px 20px;

border-radius: 4px;

margin-bottom: 20px;

}

#success {

background:#3C5675;

}

#error a, .error a {

color:white;

text-decoration: underline;

}

安装 <?php echo $sitename; ?>

若你在安装中遇到麻烦可点击 安装文档 交流论坛 QQ交流群

<?php echo $sitename; ?>还支持在命令行php think install一键安装

MySQL 数据库地址

MySQL 数据库名

MySQL 用户名

MySQL 密码

管理者用户名

管理者Email

管理者密码

重复密码

>点击安装

$(function () {

$('form :input:first').select();

$('form').on('submit', function (e) {

e.preventDefault();

var $button = $(this).find('button')

.text('安装中...')

.prop('disabled', true);

$.post('', $(this).serialize())

.done(function (ret) {

if (ret === 'success') {

$('#error').hide();

$("#success").text("安装成功!开始你的<?php echo $sitename; ?>之旅吧!").show();

$('访问首页 访问后台').insertAfter($button);

$button.remove();

} else {

$('#error').show().text(ret);

$button.prop('disabled', false).text('点击安装');

$("html,body").animate({

scrollTop: 0

}, 500);

}

})

.fail(function (data) {

$('#error').show().text('发生错误:\n\n' + data.responseText);

$button.prop('disabled', false).text('点击安装');

$("html,body").animate({

scrollTop: 0

}, 500);

});

return false;

});

});

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值