From ad69d21d5d2b422189fbd0bb1f45f8369b3db81c Mon Sep 17 00:00:00 2001 From: Karson Date: Fri, 16 Jun 2017 16:57:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=89=E8=A3=85=E7=BD=91?= =?UTF-8?q?=E9=A1=B5=E7=AB=AF=E5=AE=89=E8=A3=85=20=E6=96=B0=E5=A2=9ECRUD?= =?UTF-8?q?=E4=B8=80=E9=94=AE=E7=94=9F=E6=88=90=E5=90=8E=E7=BB=A7=E7=BB=AD?= =?UTF-8?q?=E7=94=9F=E6=88=90=E8=8F=9C=E5=8D=95=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E5=85=B3=E7=9A=84selectpage.min.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/command/Crud.php | 16 +- public/index.php | 11 +- public/install.php | 390 +++++++++++++++++++++++++++++ selectpage.min.js | 0 4 files changed, 412 insertions(+), 5 deletions(-) create mode 100644 public/install.php delete mode 100644 selectpage.min.js diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php index e43e11f3..a60628a5 100644 --- a/application/admin/command/Crud.php +++ b/application/admin/command/Crud.php @@ -40,7 +40,7 @@ class Crud extends Command protected $intDateSuffix = 'time'; /** - * 开头后缀 + * 开关后缀 */ protected $switchSuffix = 'switch'; @@ -52,7 +52,6 @@ class Crud extends Command 'icon' => 'icon', 'flag' => 'flag', 'url' => 'url', - 'url' => 'url', 'image' => 'image', 'images' => 'images', 'time' => ['type' => ['int', 'timestamp'], 'name' => 'datetime'] @@ -98,6 +97,7 @@ class Crud extends Command ->addOption('relationprimarykey', 'p', Option::VALUE_OPTIONAL, 'relation primary key', null) ->addOption('mode', 'o', Option::VALUE_OPTIONAL, 'relation table mode,hasone or belongsto', 'belongsto') ->addOption('delete', 'd', Option::VALUE_OPTIONAL, 'delete all files generated by CRUD', null) + ->addOption('menu', 'u', Option::VALUE_OPTIONAL, 'create menu when CRUD completed', null) ->setDescription('Build CRUD controller and model from table'); } @@ -118,6 +118,8 @@ class Crud extends Command { throw new Exception('table name can\'t empty'); } + //是否生成菜单 + $menu = $input->getOption("menu"); //关联表 $relation = $input->getOption('relation'); //自定义关联表模型 @@ -204,7 +206,8 @@ class Crud extends Command } foreach ($readyFiles as $k => $v) { - unlink($v); + if (file_exists($v)) + unlink($v); } $output->info("Delete Successed"); @@ -689,6 +692,13 @@ class Crud extends Command { throw new Exception("Code: " . $e->getCode() . "\nLine: " . $e->getLine() . "\nMessage: " . $e->getMessage() . "\nFile: " . $e->getFile()); } + + //继续生成菜单 + if ($menu) + { + exec("php think menu -c {$controllerUrl}"); + } + $output->info("Build Successed"); } diff --git a/public/index.php b/public/index.php index cd1db182..9ebd9e3a 100755 --- a/public/index.php +++ b/public/index.php @@ -1,4 +1,5 @@ // +---------------------------------------------------------------------- - // [ 应用入口文件 ] - // 定义应用目录 define('APP_PATH', __DIR__ . '/../application/'); + +// 判断是否安装FastAdmin +if (!file_exists(APP_PATH . 'admin/command/Install/install.lock')) +{ + header("location:./install.php"); + exit; +} + // 加载框架引导文件 require __DIR__ . '/../thinkphp/start.php'; diff --git a/public/install.php b/public/install.php new file mode 100644 index 00000000..5ca1130d --- /dev/null +++ b/public/install.php @@ -0,0 +1,390 @@ + "https://jq.qq.com/?_wv=1027&k=487PNBb", + 'osc' => 'https://git.oschina.net/karson/fastadmin', + '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' +]; +$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_writeable($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'); + $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); + file_put_contents($dbConfigFile, $config); + + $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'"); + file_put_contents($lockFile, 1); + echo "success"; + } + catch (PDOException $e) + { + $err = $e->getMessage(); + } + echo $err; + exit; +} +?> + + + + + + 安装<?php echo $sitename; ?> + + + + + + +
+

+ + + +

+

安装

+
+ +

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

+

还支持在命令行php think install一键安装

+ +
+ +
+ +
+ + + + +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
+ +
+
+ + + +
+
+ + \ No newline at end of file diff --git a/selectpage.min.js b/selectpage.min.js deleted file mode 100644 index e69de29b..00000000