From e01c84dbebd9526fc2e92ff987a575729bd0e739 Mon Sep 17 00:00:00 2001 From: hdm Date: Mon, 22 Feb 2021 23:43:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E5=A4=87=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/common.php | 13 ++ app/admin/controller/Admin.php | 2 +- app/admin/controller/Api.php | 4 +- app/admin/controller/Article.php | 4 +- app/admin/controller/Conf.php | 4 +- app/admin/controller/Database.php | 168 ++++++++++++++++++++++++ app/admin/controller/Keywords.php | 2 +- app/admin/controller/Menu.php | 2 +- app/admin/controller/Nav.php | 4 +- app/admin/controller/Role.php | 2 +- app/admin/controller/Rule.php | 2 +- app/admin/controller/Sitemap.php | 4 +- app/admin/controller/Slide.php | 4 +- app/admin/controller/User.php | 2 +- app/admin/view/common/base.html | 6 +- app/admin/view/conf/other.html | 64 +++++++++ app/admin/view/database/backuplist.html | 91 +++++++++++++ app/admin/view/database/database.html | 152 +++++++++++++++++++++ app/home/view/common/base.html | 8 +- app/home/view/index/index.html | 2 +- app/home/view/login/index.html | 2 +- app/home/view/login/reg.html | 2 +- app/install/data/gougucms.sql | 41 +++--- public/static/home/css/index.css | 2 +- 24 files changed, 543 insertions(+), 44 deletions(-) create mode 100644 app/admin/controller/Database.php create mode 100644 app/admin/view/conf/other.html create mode 100644 app/admin/view/database/backuplist.html create mode 100644 app/admin/view/database/database.html diff --git a/app/admin/common.php b/app/admin/common.php index c0d72f7..e706fde 100644 --- a/app/admin/common.php +++ b/app/admin/common.php @@ -20,6 +20,19 @@ function get_login_admin($key = "") } } +/** + * PHP格式化字节大小 + * @param number $size 字节数 + * @param string $delimiter 数字和单位分隔符 + * @return string 格式化后的带单位的大小 + */ +function format_bytes($size, $delimiter = '') +{ + $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); + for ($i = 0; $size >= 1024 && $i < 5; $i++) $size /= 1024; + return round($size, 2) . $delimiter . $units[$i]; +} + function list_to_tree($list, $pk = 'id', $pid = 'pid', $child = 'list', $root = 0) { // 创建Tree diff --git a/app/admin/controller/Admin.php b/app/admin/controller/Admin.php index 4320575..81dd6ad 100644 --- a/app/admin/controller/Admin.php +++ b/app/admin/controller/Admin.php @@ -104,7 +104,7 @@ class Admin extends BaseController //提交添加 public function post_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { diff --git a/app/admin/controller/Api.php b/app/admin/controller/Api.php index 5b8f99e..9dbe048 100644 --- a/app/admin/controller/Api.php +++ b/app/admin/controller/Api.php @@ -146,7 +146,7 @@ class Api extends BaseController //保存个人信息修改 public function personal_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); try { validate(AdminCheck::class)->scene('editPersonal')->check($param); @@ -176,7 +176,7 @@ class Api extends BaseController //保存密码修改 public function password_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); try { validate(AdminCheck::class)->scene('editpwd')->check($param); diff --git a/app/admin/controller/Article.php b/app/admin/controller/Article.php index e74737e..bea7e75 100644 --- a/app/admin/controller/Article.php +++ b/app/admin/controller/Article.php @@ -35,7 +35,7 @@ class Article extends BaseController //提交添加 public function cate_post_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { try { @@ -128,7 +128,7 @@ class Article extends BaseController //提交添加 public function post_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { try { diff --git a/app/admin/controller/Conf.php b/app/admin/controller/Conf.php index 940d565..4403db8 100644 --- a/app/admin/controller/Conf.php +++ b/app/admin/controller/Conf.php @@ -43,7 +43,7 @@ class Conf extends BaseController //提交添加 public function post_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); try { validate(ConfCheck::class)->check($param); @@ -93,7 +93,7 @@ class Conf extends BaseController //提交添加 public function conf_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); $data['content'] = serialize($param); $data['update_time'] = time(); diff --git a/app/admin/controller/Database.php b/app/admin/controller/Database.php new file mode 100644 index 0000000..1245e8c --- /dev/null +++ b/app/admin/controller/Database.php @@ -0,0 +1,168 @@ +config=array( + 'path' => './Backup/', // 数据库备份路径 + 'part' => 20971520, // 数据库备份卷大小 + 'compress' => 0, // 数据库备份文件是否启用压缩 0不压缩 1 压缩 + 'level' => 9 // 数据库备份文件压缩级别 1普通 4 一般 9最高 + ); + $this->db = new Backup($this->config); + } + + // 数据列表 + public function database() + { + if (request()->isAjax()) { + // 数据信息 + $list = $this->db->dataList(); + // 计算总大小 + $total = 0; + foreach ($list as $k => $v) { + $total += $v['data_length']; + $list[$k]['data_size'] = $v['data_length']; + $list[$k]['data_length'] = format_bytes($v['data_length']); + } + // 提示信息 + $dataTips = '数据库中共有 ' . count($list) . ' 张表,共计 ' . format_bytes($total) .'大小。'; + $data['data']=$list; + return table_assign(1, $dataTips,$data); + } + return view(); + } + + // 备份 + public function backup() + { + $tables = get_params('id'); + if (!empty($tables)) { + $tables = explode(',', $tables); + foreach ($tables as $table) { + $this->db->setFile()->backup($table, 0); + } + return to_assign(1, '备份成功!'); + } else { + return to_assign(0, '请选择要备份的表!'); + } + } + + // 优化 + public function optimize() { + $tables = get_params('id'); + if (empty($tables)) { + return to_assign(1,'请选择要优化的表!'); + } + $tables = explode(',',$tables); + if ($this->db->optimize($tables)) { + return to_assign(1, '数据表优化成功!'); + } else { + return to_assign(0, '数据表优化出错请重试!'); + } + } + + // 修复 + public function repair() { + $tables = get_params('id'); + if (empty($tables)) { + return to_assign(0,'请选择要修复的表!'); + } + $tables = explode(',',$tables); + if ($this->db->repair($tables)) { + return to_assign(1, '数据表修复成功!'); + } else { + return to_assign(0, '数据表修复出错请重试!'); + } + } + + // =========================== + + // 还原列表 + public function backuplist() + { + // 数据信息 + $list = $this->db->fileList(); + $listNew = []; + $indx=0; + foreach ($list as $k => $v) { + $listNew[$indx]['time'] = $k; + $listNew[$indx]['data'][] = $v; + $indx++; + // $listNew[$k]['list'] = $list[$k]; + } + $list = $listNew; + array_multisort(array_column($list, 'time'), SORT_DESC, $list); + return view('',['list' => $list]); + } + + // 执行还原数据库操作 + public function import(string $id) + { + $list = $this->db->getFile('timeverif', $id); + $this->db->setFile($list)->import(1); + return to_assign(1,'还原成功!'); + } + + // 下载 + public function downfile(string $name) + { + $file_name = $name; //得到文件名 + header("Content-type:text/html;charset=utf-8"); + $file_name = iconv("utf-8","gb2312",$file_name); // 转换编码 + $file_sub_path = CMS_ROOT . '/public'.$this->config['path']; //确保文件在这个路径下面,换成你文件所在的路径 + $file_path = $file_sub_path . $file_name; + # 将反斜杠 替换成正斜杠 + $file_path = str_replace('\\','/',$file_path); + if(!file_exists($file_path)){ + echo "下载文件不存在!";exit; //如果提示这个错误,很可能你的路径不对,可以打印$file_sub_path查看 + } + $fp = fopen($file_path,"r"); // 以可读的方式打开这个文件 + # 如果出现图片无法打开,可以在这个位置添加函数 + ob_clean(); # 清空擦掉,输出缓冲区。 + $file_size = filesize($file_path); + //下载文件需要用到的头 + Header("Content-type: application/octet-stream"); + Header("Accept-Ranges: bytes"); + Header("Accept-Length:".$file_size); + Header("Content-Disposition: attachment; filename = ". $file_name); + $buffer = 1024000; + $file_count = 0; + while(!feof($fp) && $file_count<$file_size){ + $file_con = fread($fp,$buffer); + $file_count += $buffer; + echo $file_con; + } + fclose($fp); //关闭这个打开的文件 + } + + // 删除sql文件 + public function del(string $id) + { + if (request()->isAjax()) { + if (strpos($id, ',') !== false) { + $idArr = explode(',', $id); + foreach ($idArr as $k => $v) { + $this->db->delFile($v); + } + return to_assign(1,"删除成功!"); + } + if ($this->db->delFile($id)) { + return to_assign(1,"删除成功!"); + } else { + return to_assign(0, "备份文件删除失败,请检查文件权限!"); + } + } + } + +} \ No newline at end of file diff --git a/app/admin/controller/Keywords.php b/app/admin/controller/Keywords.php index b9273aa..70b092f 100644 --- a/app/admin/controller/Keywords.php +++ b/app/admin/controller/Keywords.php @@ -47,7 +47,7 @@ class Keywords extends BaseController //提交添加 public function post_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { try { diff --git a/app/admin/controller/Menu.php b/app/admin/controller/Menu.php index 3a6e8bd..6976132 100644 --- a/app/admin/controller/Menu.php +++ b/app/admin/controller/Menu.php @@ -37,7 +37,7 @@ class Menu extends BaseController public function post_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if ($param['id'] > 0) { try { diff --git a/app/admin/controller/Nav.php b/app/admin/controller/Nav.php index a4670c0..6facb2e 100644 --- a/app/admin/controller/Nav.php +++ b/app/admin/controller/Nav.php @@ -52,7 +52,7 @@ class Nav extends BaseController public function post_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { try { @@ -148,7 +148,7 @@ class Nav extends BaseController public function nav_info_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { try { diff --git a/app/admin/controller/Role.php b/app/admin/controller/Role.php index 217f747..9ab9ba2 100644 --- a/app/admin/controller/Role.php +++ b/app/admin/controller/Role.php @@ -47,7 +47,7 @@ class Role extends BaseController //提交保存 public function post_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { diff --git a/app/admin/controller/Rule.php b/app/admin/controller/Rule.php index ce85129..78f7646 100644 --- a/app/admin/controller/Rule.php +++ b/app/admin/controller/Rule.php @@ -32,7 +32,7 @@ class Rule extends BaseController //提交添加 public function post_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if ($param['id'] > 0) { try { diff --git a/app/admin/controller/Sitemap.php b/app/admin/controller/Sitemap.php index fea5193..a3d7ca8 100644 --- a/app/admin/controller/Sitemap.php +++ b/app/admin/controller/Sitemap.php @@ -50,7 +50,7 @@ class Sitemap extends BaseController //提交添加 public function post_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { try { @@ -142,7 +142,7 @@ class Sitemap extends BaseController //保存网站地图添加 public function sitemap_info_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { try { diff --git a/app/admin/controller/Slide.php b/app/admin/controller/Slide.php index d048705..7011208 100644 --- a/app/admin/controller/Slide.php +++ b/app/admin/controller/Slide.php @@ -48,7 +48,7 @@ class Slide extends BaseController //提交添加 public function post_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { try { @@ -137,7 +137,7 @@ class Slide extends BaseController //保存幻灯片添加 public function slide_info_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { try { diff --git a/app/admin/controller/User.php b/app/admin/controller/User.php index 727d3c1..c6e58c6 100644 --- a/app/admin/controller/User.php +++ b/app/admin/controller/User.php @@ -62,7 +62,7 @@ class User extends BaseController //提交添加 public function post_submit() { - if ($this->request->isPost()) { + if (request()->isAjax()) { $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { $res = Db::name('user')->where(['id' => $param['id']])->strict(false)->field(true)->update($param); diff --git a/app/admin/view/common/base.html b/app/admin/view/common/base.html index 1eb522a..7d92c1f 100644 --- a/app/admin/view/common/base.html +++ b/app/admin/view/common/base.html @@ -9,11 +9,11 @@ {/block} {block name="title"} - {:get_config('webconfig.admin_title')} + {:get_system_config('web','admin_title')} {/block} {block name="keywords"} - - + + {/block} {block name="css"} diff --git a/app/admin/view/conf/other.html b/app/admin/view/conf/other.html new file mode 100644 index 0000000..df1092a --- /dev/null +++ b/app/admin/view/conf/other.html @@ -0,0 +1,64 @@ +{extend name="common/base"/} + +{block name="body"} +
+

其他配置

+ + + + + + + +
开发者 + + + 开发版本号 + + +
+ +
+ + +
+
+{/block} + + + +{block name="script"} + +{include file="common/layui" base='base' extend="[]" use="['form']" callback="init" /} +{/block} + \ No newline at end of file diff --git a/app/admin/view/database/backuplist.html b/app/admin/view/database/backuplist.html new file mode 100644 index 0000000..b733eba --- /dev/null +++ b/app/admin/view/database/backuplist.html @@ -0,0 +1,91 @@ +{extend name="common/base"/} + +{block name="body"} +
+ + + + + + + + + + {empty name="list"} + + + + {/empty} + {volist name="list" id="vo" key="k"} + + + + {volist name="vo.data" id="voo"} + + + + + + + + + {/volist} + {/volist} +
文件名称分卷文件大小文件格式分隔符操作
暂无备份数据
备份时间:{$vo.time}
+ {:date("Ymd",$voo.time)}{$voo.compress}{:date("His",$voo.time)}{$voo.compress}{$voo.part}.sql + {$voo.part}{:format_bytes($voo.size)}.sql{$voo.compress} + 数据还原 + 备份下载备份删除 +
+
+ +{/block} + + + +{block name="script"} + +{include file="common/layui" base='base' extend="[]" use="['table','form']" callback="init" /} +{/block} + diff --git a/app/admin/view/database/database.html b/app/admin/view/database/database.html new file mode 100644 index 0000000..5e6e3f5 --- /dev/null +++ b/app/admin/view/database/database.html @@ -0,0 +1,152 @@ +{extend name="common/base"/} + +{block name="body"} +
+
+
+ + +{/block} + + + +{block name="script"} + +{include file="common/layui" base='base' extend="[]" use="['table','form']" callback="init" /} +{/block} + diff --git a/app/home/view/common/base.html b/app/home/view/common/base.html index 0594b60..2aaef11 100644 --- a/app/home/view/common/base.html +++ b/app/home/view/common/base.html @@ -9,14 +9,14 @@ {/block} {block name="title"} - {:get_config('webconfig.admin_title')} + {:get_system_config('web','admin_title')} {/block} {block name="keywords"} - - + + {/block} {block name="css"} - + {/block} {block name="style"}{/block} {block name="js"} diff --git a/app/home/view/index/index.html b/app/home/view/index/index.html index fac4c36..bb4628b 100644 --- a/app/home/view/index/index.html +++ b/app/home/view/index/index.html @@ -10,7 +10,7 @@
勾股CMS,让WEB开发更简单!
-
勾股CMS是一套基于ThinkPHP6 + Layui + MySql打造的轻量级、高性能快速建站的内容管理系统。
后台管理模块,一目了然,操作简单,通用型后台权限管理框架,紧随潮流、极低门槛、开箱即用。
+
勾股CMS是一套基于ThinkPHP6 + Layui + MySql打造的轻量级、高性能快速建站的内容管理系统。
系统后台各管理模块,一目了然,操作简单;通用型的后台权限管理框架,紧随潮流、极低门槛、开箱即用。
系统易于功能扩展,代码维护,方便二次开发,帮助开发者简单高效降低二次开发成本,满足专注业务深度开发的需求。
diff --git a/app/home/view/login/index.html b/app/home/view/login/index.html index 2d5c0ca..e85efce 100644 --- a/app/home/view/login/index.html +++ b/app/home/view/login/index.html @@ -6,7 +6,7 @@ - {:get_config('webconfig.admin_title')} + {:get_system_config('web','admin_title')}