From 566d69765d639ce9219b540da655dbfea138b5f6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 23 Oct 2020 19:47:21 +0800 Subject: [PATCH 01/24] kun --- app/common/__init__.py | 35 ++- app/common/model.py | 23 +- app/config/app.py | 4 +- app/intapp/controller/index/admin.py | 48 +++ app/intapp/controller/index/role.txt | 5 +- .../controller/index/tpl/admin/admin.html | 263 +++++++++++++++++ .../controller/index/tpl/admin/adminlog.html | 156 ++++++++++ .../controller/index/tpl/admin/index.html | 278 ++++-------------- .../controller/index/tpl/admin/role.html | 15 +- .../controller/index/tpl/setup/startpage.html | 4 +- app/static/js/function.js | 33 +++ kcweb/app.py | 2 +- 12 files changed, 628 insertions(+), 238 deletions(-) create mode 100644 app/intapp/controller/index/tpl/admin/admin.html create mode 100644 app/intapp/controller/index/tpl/admin/adminlog.html diff --git a/app/common/__init__.py b/app/common/__init__.py index 5609cbc..5177540 100644 --- a/app/common/__init__.py +++ b/app/common/__init__.py @@ -97,7 +97,7 @@ def check_role(): break if not status: if 'GET' == request.HEADER.Method(): - return response.tpl("/common/html/error.html",title="无权访问",content="抱歉...,您当前没有此页面访问权限,请联系管理员",imgsrc=config.domain['kcwebimg']+"/icon/suo.png",status="401") + return response.tpl("/common/html/error.html",title="无权访问",content="抱歉...,您当前没有此页面访问权限,请联系管理员",imgsrc=config.domain['kcwebimg']+"/icon/suo.png",status="401 error") else: return errorjson(msg="您没有以下接口访问权限,可联系管理员申请。\r\n"+ts,status="401") def check_login(): @@ -122,9 +122,38 @@ def before_request(): """ if not config.app['cli']: return check_login() -def after_request(): +def after_request(body,status,resheader): "响应拦截" - pass + if status=='200 ok': + if G.userinfo: #记录操作日志 + + method=request.HEADER.Method() + if method!="GET": + t=request.getroutecomponent() + modular=t[1] + plug=t[2] + controller=t[3] + function=t[4] + routeparam=json_encode(list(t[5])) + t1=request.HEADER.URL().split("?") + if len(t1)>1: + getparam="?"+t1[1:][0] + else: + getparam="" + dataparam=request.get_data() + sqlite("admin_log",model_app_path).insert({ + "user_id":G.userinfo['id'], + "title":'', + "method":method, + "modular":modular, + "plug":plug, + "controller":controller, + "function":function, + "routeparam":routeparam, + "getparam":getparam, + "dataparam":dataparam, + "addtime":times() + }) def return_list(lists,count,pagenow,pagesize): """返回分页列表 diff --git a/app/common/model.py b/app/common/model.py index 44947a4..fb5eecc 100644 --- a/app/common/model.py +++ b/app/common/model.py @@ -47,7 +47,28 @@ except: model_admins=model_app_admin() model_admins.create_table() sqlite("admin",model_app_path).insert({"username":"kcw","password":md5("kcw"+str(password)),"phone":"","nickname":"kcw-linux控制板","name":"","role":1,"logintime":times(),"addtime":times()}) - +class model_app_admin_log(modelsqliteintapp): + "管理员操作日志" + table="admin_log" + fields={ + "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 + "user_id":model.dbtype.int(LEN=11,DEFAULT=0), #用户id(管理员id) + "title":model.dbtype.varchar(LEN=32,DEFAULT=''), #日志标题 + "method":model.dbtype.varchar(LEN=8,DEFAULT='GET'), #请求类型 + "modular":model.dbtype.varchar(LEN=32,DEFAULT=''), #请求模块 + "plug":model.dbtype.varchar(LEN=32,DEFAULT=''), #请求插件 + "controller":model.dbtype.varchar(LEN=32,DEFAULT=''), #请求控制器 + "function":model.dbtype.varchar(LEN=32,DEFAULT=''), #请求控制器方法 + "routeparam":model.dbtype.varchar(LEN=11,DEFAULT=''), #路由参数 + "getparam":model.dbtype.varchar(LEN=64,DEFAULT=''), #GET参数 + "dataparam":model.dbtype.varchar(LEN=8,DEFAULT=''), #body参数 + "addtime":model.dbtype.int(LEN=11,DEFAULT=0) #添加时间 + } +try: + sqlite('admin_log',model_app_path).find() +except: + model_app_admin_log=model_app_admin_log() + model_app_admin_log.create_table() class model_intapp_menu(modelsqliteintapp): "顶部和左边菜单 表" table="menu" diff --git a/app/config/app.py b/app/config/app.py index af79eb9..b962468 100644 --- a/app/config/app.py +++ b/app/config/app.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from .database import * -app['app_debug']=False #是否开启调试模式 +app['app_debug']=True #是否开启调试模式 app['tpl_folder']='./app' #设置模板文件目录名 注意:所有的配置目录都是以您的运行文件所在目录开始 app['before_request']='before_request' #设置请求前要执行的函数名 app['after_request']='after_request' #设置请求后要执行的函数名 @@ -41,7 +41,7 @@ route['defmodular']='intapp' #默认模块 当url不包括模块名时 route['defplug']='index' #默认插件 当url不包括插件名时 route['files']='index' #默认路由文件(控制器) 当url不包括控制器名时 route['funct']='index' #默认路由函数 (操作方法) 当url不包括操作方法名时 -route['methods']=['POST','GET'] #默认请求方式 +route['methods']=['POST','GET','DELETE','PUT'] #默认请求方式 diff --git a/app/intapp/controller/index/admin.py b/app/intapp/controller/index/admin.py index d2b4fee..c23bf42 100644 --- a/app/intapp/controller/index/admin.py +++ b/app/intapp/controller/index/admin.py @@ -4,11 +4,59 @@ def index(): return response.tpl("../tplm/admin/index") else: return response.tpl() +def admin(): + if sysisphone(): + return response.tpl("../tplm/admin/admin") + else: + return response.tpl() def role(): if sysisphone(): return response.tpl("../tplm/admin/role") else: return response.tpl() +def adminlog(): + if sysisphone(): + return response.tpl("../tplm/admin/adminlog") + else: + return response.tpl() +def loglist(): + "日志列表" + where="1=1" + kw=request.args.get('kw') + types=request.args.get('types') + method=request.args.get('method') + pagenow=request.args.get('pagenow') + pagesize=request.args.get('pagesize') + if kw: + where+=" and t2."+types+" like '%"+kw+"%'" + if method: + where+=" and method='"+method+"'" + if not pagenow: + pagenow=1 + else: + pagenow=int(pagenow) + if not pagesize: + pagesize=10 + else: + pagesize=int(pagesize) + print(where) + lists=sqlite("admin_log t1",model_app_path).order("t1.id desc").field("t1.*,t2.icon,t2.name,t2.phone").join("admin t2","t1.user_id=t2.id","LEFT").where(where).page(pagenow,pagesize).select() + count=sqlite("admin_log t1",model_app_path).join("admin t2","t1.user_id=t2.id","LEFT").where(where).count() + data=return_list(lists,count,pagenow,pagesize) + return successjson(data) +def deletelog(id=0): + "删除日志" + if id: + sqlite("admin_log",model_app_path).where('id',id).delete() + return successjson() + else: + try: + id=request.get_json() + sqlite("admin_log",model_app_path).where('id','in',id).delete() + except: + return errorjson(msg="失败") + else: + return successjson() def getpluglist(modular="intapp"): "本地插件列表" path="app/"+modular+"/controller/" diff --git a/app/intapp/controller/index/role.txt b/app/intapp/controller/index/role.txt index 9add180..aea63df 100644 --- a/app/intapp/controller/index/role.txt +++ b/app/intapp/controller/index/role.txt @@ -8,7 +8,9 @@ cpu和内存以及网络,/intapp/index/index/cpume shell执行能力,/intapp/index/index/shell 重启,/intapp/index/index/reboot -管理员页面,/intapp/index/admin/index +管理员页面,/intapp/index/admin/admin +权限页面,/intapp/index/admin/role +操作日志页面,/intapp/index/admin/adminlog 路由列表,/intapp/index/admin/getpluglist 管理员列表,/intapp/index/admin/getlist 添加管理员,/intapp/index/admin/insert @@ -16,7 +18,6 @@ shell执行能力,/intapp/index/index/shell 编辑管理员,/intapp/index/admin/update 设置管理员密码,/intapp/index/admin/setpwd 设置自己的密码,/intapp/index/admin/setmypwd -权限页面,/intapp/index/admin/role 角色列表,/intapp/index/admin/getrolelist 添加角色,/intapp/index/admin/insertrole 更新角色,/intapp/index/admin/updaterole diff --git a/app/intapp/controller/index/tpl/admin/admin.html b/app/intapp/controller/index/tpl/admin/admin.html new file mode 100644 index 0000000..c3b8353 --- /dev/null +++ b/app/intapp/controller/index/tpl/admin/admin.html @@ -0,0 +1,263 @@ + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+
+    + + + 搜索 + 添加管理员账户 + + + 清除所有会话 + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+    删除选中  + + +
+
+ +
+ + + + + + + 选择图片 + + + + + + + + + + + + + + + + {{item.title}} + + + + + 取 消 + 修改 + 添加 + +
+
+
+ + + diff --git a/app/intapp/controller/index/tpl/admin/adminlog.html b/app/intapp/controller/index/tpl/admin/adminlog.html new file mode 100644 index 0000000..59c4609 --- /dev/null +++ b/app/intapp/controller/index/tpl/admin/adminlog.html @@ -0,0 +1,156 @@ + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+
+    + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + +
+    删除选中  + + +
+
+
+ + + diff --git a/app/intapp/controller/index/tpl/admin/index.html b/app/intapp/controller/index/tpl/admin/index.html index d1fe2c7..887f951 100644 --- a/app/intapp/controller/index/tpl/admin/index.html +++ b/app/intapp/controller/index/tpl/admin/index.html @@ -1,5 +1,6 @@ + kcwebplus @@ -19,131 +20,49 @@ + - -
-
-    - - - 搜索 - 添加管理员账户 - - - 角色管理 - 清除所有会话 - - -
-
- - - - - - - - - - - - - - - - - - - - - - - -
-    删除选中  - - +
+ + 管理员列表 + 角色管理 + 操作日志 + +
+ +
+
+
+ +
+ +
+
- - - - - - - - 选择图片 - - - - - - - - - - - - - - - - {{item.title}} - - - - - - 取 消 - 修改 - 添加 - -
- + \ No newline at end of file diff --git a/app/intapp/controller/index/tpl/admin/role.html b/app/intapp/controller/index/tpl/admin/role.html index 30637bd..9d7b39a 100644 --- a/app/intapp/controller/index/tpl/admin/role.html +++ b/app/intapp/controller/index/tpl/admin/role.html @@ -64,10 +64,7 @@
- + @@ -75,7 +72,7 @@ -
+
{{item1.name}} @@ -85,8 +82,8 @@ 取 消 - 修改 - 添加 + 修改角色 + 添加角色
@@ -160,7 +157,7 @@ var vm = new Vue({ for(var i=0;i Date: Fri, 23 Oct 2020 20:00:01 +0800 Subject: [PATCH 02/24] kun --- app/common/model.py | 2 +- app/intapp/controller/index/role.txt | 2 ++ app/intapp/controller/index/tpl/admin/adminlog.html | 10 +++++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/common/model.py b/app/common/model.py index fb5eecc..a52aead 100644 --- a/app/common/model.py +++ b/app/common/model.py @@ -61,7 +61,7 @@ class model_app_admin_log(modelsqliteintapp): "function":model.dbtype.varchar(LEN=32,DEFAULT=''), #请求控制器方法 "routeparam":model.dbtype.varchar(LEN=11,DEFAULT=''), #路由参数 "getparam":model.dbtype.varchar(LEN=64,DEFAULT=''), #GET参数 - "dataparam":model.dbtype.varchar(LEN=8,DEFAULT=''), #body参数 + "dataparam":model.dbtype.text(), #body参数 "addtime":model.dbtype.int(LEN=11,DEFAULT=0) #添加时间 } try: diff --git a/app/intapp/controller/index/role.txt b/app/intapp/controller/index/role.txt index aea63df..9bca7d3 100644 --- a/app/intapp/controller/index/role.txt +++ b/app/intapp/controller/index/role.txt @@ -11,6 +11,8 @@ shell执行能力,/intapp/index/index/shell 管理员页面,/intapp/index/admin/admin 权限页面,/intapp/index/admin/role 操作日志页面,/intapp/index/admin/adminlog +日志列表,/intapp/index/admin/loglist +删除日志,/intapp/index/admin/deletelog 路由列表,/intapp/index/admin/getpluglist 管理员列表,/intapp/index/admin/getlist 添加管理员,/intapp/index/admin/insert diff --git a/app/intapp/controller/index/tpl/admin/adminlog.html b/app/intapp/controller/index/tpl/admin/adminlog.html index 59c4609..4eb54cb 100644 --- a/app/intapp/controller/index/tpl/admin/adminlog.html +++ b/app/intapp/controller/index/tpl/admin/adminlog.html @@ -65,11 +65,11 @@ {{scope.row.method}} - - - - - + + + + + -- Gitee From b3fca5a6c18710c65d95f809d7c634e68e663733 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 23 Oct 2020 20:04:50 +0800 Subject: [PATCH 03/24] kun --- app/intapp/controller/index/tpl/setup/basepage.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/intapp/controller/index/tpl/setup/basepage.html b/app/intapp/controller/index/tpl/setup/basepage.html index f514ae0..a1b87e7 100644 --- a/app/intapp/controller/index/tpl/setup/basepage.html +++ b/app/intapp/controller/index/tpl/setup/basepage.html @@ -135,18 +135,20 @@ Vues=new Vue({ }, setbaseconfig:function(types){ self=this - self.post("/intapp/index/setup/setbaseconfig/"+types,self.config,'请稍后...').then(function(res){ - if(types=='set'){ + if(types=='set'){ + self.put("/intapp/index/setup/setbaseconfig/"+types,self.config,'请稍后...').then(function(res){ self.$notify({title: '成功',duration:5000,message:res.msg,type: 'success'}); - }else{ + }) + }else{ + self.get("/intapp/index/setup/setbaseconfig/"+types,self.config,'请稍后...').then(function(res){ self.config=res.data if(!self.config.system){ self.config.system={ name:'',logo:'',kcwebuser:{} } } - } - }) + }) + } } } }); -- Gitee From 8aaded9c8ca30f2f4fe998b96428cc9e6c2ffaa9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 24 Oct 2020 09:48:48 +0800 Subject: [PATCH 04/24] kun --- app/common/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/common/__init__.py b/app/common/__init__.py index 5177540..124ee64 100644 --- a/app/common/__init__.py +++ b/app/common/__init__.py @@ -154,6 +154,7 @@ def after_request(body,status,resheader): "dataparam":dataparam, "addtime":times() }) + G.userinfo=None def return_list(lists,count,pagenow,pagesize): """返回分页列表 -- Gitee From a26c5dc6b17cbf19fd9d8eb5e9adbe08f368e087 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 24 Oct 2020 09:50:40 +0800 Subject: [PATCH 05/24] kun --- app/intapp/controller/index/admin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/intapp/controller/index/admin.py b/app/intapp/controller/index/admin.py index c23bf42..668f2c5 100644 --- a/app/intapp/controller/index/admin.py +++ b/app/intapp/controller/index/admin.py @@ -39,7 +39,6 @@ def loglist(): pagesize=10 else: pagesize=int(pagesize) - print(where) lists=sqlite("admin_log t1",model_app_path).order("t1.id desc").field("t1.*,t2.icon,t2.name,t2.phone").join("admin t2","t1.user_id=t2.id","LEFT").where(where).page(pagenow,pagesize).select() count=sqlite("admin_log t1",model_app_path).join("admin t2","t1.user_id=t2.id","LEFT").where(where).count() data=return_list(lists,count,pagenow,pagesize) -- Gitee From 2f37577a0de034f444128f19eeef0e79c48a3beb Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 24 Oct 2020 10:30:15 +0800 Subject: [PATCH 06/24] kun --- app/intapp/controller/index/admin.py | 5 ++ app/intapp/controller/index/role.txt | 1 + .../controller/index/tpl/admin/adminlog.html | 65 ++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/app/intapp/controller/index/admin.py b/app/intapp/controller/index/admin.py index 668f2c5..a7c1dce 100644 --- a/app/intapp/controller/index/admin.py +++ b/app/intapp/controller/index/admin.py @@ -19,6 +19,11 @@ def adminlog(): return response.tpl("../tplm/admin/adminlog") else: return response.tpl() +def logdeta(id): + "日志明细" + data=sqlite("admin_log t1",model_app_path).field("t1.*,t2.icon,t2.name,t2.phone").join("admin t2","t1.user_id=t2.id","LEFT").where("t1.id",id).find() + data['routeparamarr']=json_decode(data['routeparam']) + return successjson(data) def loglist(): "日志列表" where="1=1" diff --git a/app/intapp/controller/index/role.txt b/app/intapp/controller/index/role.txt index 9bca7d3..c8035a4 100644 --- a/app/intapp/controller/index/role.txt +++ b/app/intapp/controller/index/role.txt @@ -12,6 +12,7 @@ shell执行能力,/intapp/index/index/shell 权限页面,/intapp/index/admin/role 操作日志页面,/intapp/index/admin/adminlog 日志列表,/intapp/index/admin/loglist +日志明细,/intapp/index/admin/logdeta 删除日志,/intapp/index/admin/deletelog 路由列表,/intapp/index/admin/getpluglist 管理员列表,/intapp/index/admin/getlist diff --git a/app/intapp/controller/index/tpl/admin/adminlog.html b/app/intapp/controller/index/tpl/admin/adminlog.html index 4eb54cb..35fc90f 100644 --- a/app/intapp/controller/index/tpl/admin/adminlog.html +++ b/app/intapp/controller/index/tpl/admin/adminlog.html @@ -51,7 +51,7 @@ @@ -74,7 +74,17 @@ + + + + + +
   删除选中  @@ -85,6 +95,50 @@
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
用户头像
操作用户{{deta.name}}
用户手机{{deta.phone}}
操作类型 + 删除操作(DELETE) + 更新操作(PUT) + 提交操作(POST) + 获取操作(GET) + {{deta.method}} +
路由/{{deta.modular}}/{{deta.plug}}/{{deta.controller}}/{{deta.function}} + /{{item}} + {{deta.getparam}} +
post参数 + {{deta.dataparam}} +
+
+
@@ -17,6 +19,7 @@ +