Files
YwxAppThink/public/install/index.php
T

74 lines
3.1 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
require __DIR__ . '/Installer.php';
$installer = new Installer();
// 已安装检测
if ($installer->isInstalled() && !isset($_GET['action'])) {
header('Content-Type: text/html; charset=utf-8');
echo '<!doctype html><html lang="zh-CN"><head><meta charset="utf-8">'
. '<title>系统已安装</title><style>'
. 'body{font-family:system-ui,-apple-system,"Microsoft YaHei",sans-serif;background:#f5f7fa;'
. 'display:flex;min-height:100vh;align-items:center;justify-content:center}'
. '.box{background:#fff;padding:40px 50px;border-radius:10px;box-shadow:0 5px 20px rgba(0,0,0,.08);'
. 'text-align:center;max-width:480px;line-height:1.7}h1{color:#e74c3c;margin:0 0 12px}'
. 'p{color:#666;margin:6px 0}.tip{margin-top:16px;font-size:13px;color:#999}</style></head>'
. '<body><div class="box"><h1>系统已安装</h1>'
. '<p>检测到安装锁文件 <code>install.lock</code>,系统已完成安装。</p>'
. '<p class="tip">如需重新安装,请先删除项目根目录下的 install.lock 并清空数据库,再访问本向导。</p>'
. '</div></body></html>';
exit;
}
$action = (string) ($_GET['action'] ?? ($_POST['action'] ?? ''));
if ($action === 'env') {
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['ok' => true, 'items' => $installer->checkEnv()]);
exit;
}
if ($action === 'dbtest') {
header('Content-Type: application/json; charset=utf-8');
echo json_encode($installer->testDb($installer->getDbConfig($_POST)));
exit;
}
if ($action === 'install') {
header('Content-Type: application/json; charset=utf-8');
$cfg = $installer->getDbConfig($_POST);
$test = $installer->testDb($cfg);
if (!$test['ok']) {
echo json_encode(['ok' => false, 'msg' => '数据库连接失败:' . ($test['msg'] ?? '')]);
exit;
}
try {
$installer->importSql($cfg);
$installer->createAdmin($cfg, [
'account' => $_POST['admin_account'] ?? '',
'password' => $_POST['admin_password'] ?? '',
'nickname' => $_POST['admin_nickname'] ?? '',
'email' => $_POST['admin_email'] ?? '',
'mobile' => $_POST['admin_mobile'] ?? '',
]);
$installer->writeEnv($cfg);
$installer->makeLock();
echo json_encode(['ok' => true, 'msg' => '安装完成']);
} catch (\Throwable $e) {
echo json_encode(['ok' => false, 'msg' => '安装失败:' . $e->getMessage()]);
}
exit;
}
// 默认:展示前端向导页
header('Content-Type: text/html; charset=utf-8');
include __DIR__ . '/index.html';