diff --git a/app/common/__init__.py b/app/common/__init__.py index 0b39d29a979a19d9e68eccea9b5235161a17291c..4c5d8937a923e5e96c9afeaee13305cbd476458c 100644 --- a/app/common/__init__.py +++ b/app/common/__init__.py @@ -21,19 +21,20 @@ def serlogin(username,sign,timestamp,random,types="session"): types 登录类型 session浏览器默认会话登录 否则返回account_token """ + account_token='' if (times()-int(timestamp))>3600 or times()-int(timestamp)<-3600: - return False,3,"时间戳错误" + return False,3,"时间戳错误",account_token inifo=sqlite('admin',model_app_path).where([('username','eq',username),'or',('phone','eq',username)]).find() if not inifo: - return False,2,"用户名错误" + return False,2,"用户名错误",account_token if inifo['id']>100: return False,-1,"您不是管理员账号" usign=md5(str(inifo['username'])+str(inifo['password'])+str(timestamp)+str(random)) if usign!=sign: - return False,2,"密码错误" + return False,2,"密码错误",account_token inifo['role']=sqlite("role",model_app_path).where('id',inifo['role']).find() sqlite('admin',model_app_path).where('id',inifo['id']).update({'logintime':times()}) - account_token='' + if types=='session': #如果使用sess登录,要分配系统菜单权限 #根据权限给当前登录用户初始化菜单 systemrolelist=[ #系统菜单权限 @@ -105,9 +106,9 @@ def check_login(): G.userinfo=get_session("userinfo") if not G.userinfo: if 'GET' == request.HEADER.Method(): - return response.tpl('pub/login') + return response.tpl('/common/html/login.html') else: - return errorjson(code=-1,msg='登录失效,请重新登录') + return errorjson(code=-1,msg='登录失效,请登录后操作') return check_role() def before_request(): """请求拦截, @@ -214,40 +215,57 @@ def file_set_content(k,data): f.write(data) f.close() return True -def insert_Boot_up(cmd): - "添加开机启动命令" - if 'Linux' in get_sysinfo()['uname'][0]: - f=open("/usr/bin/startkcweb","a") - f.write("\n"+cmd+"\n") - f.close() - return True - else: - return False -def del_Boot_up(cmd,vague=False): - """删除开机启动命令 - - vague 是否模糊匹配 - """ - if 'Linux' in get_sysinfo()['uname'][0]: - if vague: - f = open("/usr/bin/startkcweb") - con='' - while True: - line = f.readline() - if not line: - break - if 'cmd' in line: - line='' - con=con+line +class system_start: + "系统启动项" + def lists(pagenow=1,pagesize=20,where=None): + "启动项列表" + lists=sqlite().connect(model_app_path).where(where).table("start").order("id asc").page(pagenow,pagesize).select() + count=sqlite().connect(model_app_path).where(where).table("start").count() + return lists,count + def insert_Boot_up(cmd,name="系统添加",types="shell",icon="",admin_id=0): + "添加开机启动命令" + if 'Linux' in get_sysinfo()['uname'][0]: + f=open("/usr/bin/startkcweb","a") + f.write("\n"+cmd+"\n") f.close() - file_set_content("/usr/bin/startkcweb",con) + if sqlite("start").connect(model_app_path).where("value",cmd).count(): + return False + sqlite("start").connect(model_app_path).insert({"name":name,"types":types,"value":cmd,"icon":icon,"admin_id":admin_id,"addtime":times(),"updtime":times()}) + return True else: - content=file_get_content("/usr/bin/startkcweb") - content=content.replace("\n"+cmd+"\n","") - file_set_content("/usr/bin/startkcweb",content) - return True - else: - return False + return False + def del_Boot_up(cmd,vague=False,id=False): + """删除开机启动命令 + + vague 是否模糊匹配 + """ + if id: + where=[("id","eq",id),"and",("admin_id","gt",0)] + if 'Linux' in get_sysinfo()['uname'][0]: + if vague: + f = open("/usr/bin/startkcweb") + con='' + while True: + line = f.readline() + if not line: + break + if 'cmd' in line: + line='cmd' + con=con+line + f.close() + file_set_content("/usr/bin/startkcweb",con) + if not id: + where=[("value","like","%"+str(cmd)+"%")] + else: + content=file_get_content("/usr/bin/startkcweb") + content=content.replace("\n"+cmd+"\n","") + file_set_content("/usr/bin/startkcweb",content) + if not id: + where=[("value","eq",cmd)] + sqlite("start").connect(model_app_path).where(where).delete() + return True + else: + return False g_local_ip='' def get_local_ip(): "获取内网ip" diff --git a/app/intapp/controller/soft/tpl/soft/git.html b/app/common/html/login.html similarity index 39% rename from app/intapp/controller/soft/tpl/soft/git.html rename to app/common/html/login.html index 9f6b6b0c2e3b8361183f526edd61e6341087ba10..09094684a4199a77c5826e6899730801536b3028 100644 --- a/app/intapp/controller/soft/tpl/soft/git.html +++ b/app/common/html/login.html @@ -1,15 +1,13 @@ - -kcwebplus +kcweb - @@ -17,53 +15,64 @@ - - - -
-
- -
- 您可以使用以下命令生成ssh密钥

- +
+
+
+
+

+

kcweb   

+
+
+ +
+
+ +
+
+ 登录 +
+
+
-
-
+ +
- \ No newline at end of file + diff --git a/app/common/model.py b/app/common/model.py index 12897f1e00f1c62001a12ef9f6c71b6c534e5f75..7c60028f43c889376ec2e8e25647bcdb79235b1b 100644 --- a/app/common/model.py +++ b/app/common/model.py @@ -61,19 +61,22 @@ class model_intapp_menu(modelsqliteintapp): "url":model.dbtype.varchar(LEN=32,DEFAULT=''), #菜单地址 "types":model.dbtype.varchar(LEN=11,DEFAULT=''), # left,header } - def add(title,icon,url,types='left',pid=0,admin_id=0): + def add(title,icon,url,types='left',pid=0,admin_id=0,sort=2000): "添加菜单" - sqlite('menu',model_app_path).insert({'title':title,'icon':icon,'url':url,"types":types,"pid":pid,"admin_id":admin_id,"sort":0}) - def delete(id='',title='',types="left",pid=0,admin_id=0): + sqlite('menu',model_app_path).insert({'title':title,'icon':icon,'url':url,"types":types,"pid":pid,"admin_id":admin_id,"sort":sort}) + def delete(id='',title='',types="left",pid=0,admin_id=0,sort=2000): "删除菜单" if id: sqlite('menu',model_app_path).where("id="+str(id)+"").delete() elif title and pid: sqlite('menu',model_app_path).where("title='"+title+"' and pid="+str(pid)).delete() + elif title and sort: + sqlite('menu',model_app_path).where("title='"+title+"' and sort='"+str(sort)+"'").delete() elif title and types: sqlite('menu',model_app_path).where("title='"+title+"' and types='"+types+"'").delete() elif title and admin_id: sqlite('menu',model_app_path).where("title='"+title+"' and admin_id='"+str(admin_id)+"'").delete() + try: sqlite('menu',model_app_path).find() @@ -123,4 +126,23 @@ except: "icon":'', "role":json_encode(role), "addtime":times() - }) \ No newline at end of file + }) + +class model_app_start(modelsqliteintapp): + "启动项" + table="start" + fields={ + "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 + "name":model.dbtype.varchar(LEN=128,DEFAULT=''), #名字 + "icon":model.dbtype.varchar(LEN=128,DEFAULT=''), + "types":model.dbtype.varchar(LEN=128,DEFAULT='shell'), #类型 + "value":model.dbtype.varchar(LEN=512,DEFAULT=''), + "admin_id":model.dbtype.int(LEN=11), + "updtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 + "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 + } +try: + sqlite('start',model_app_path).find() +except: + model_app_start=model_app_start() + model_app_start.create_table() \ No newline at end of file diff --git a/app/intapp/controller/__init__.py b/app/intapp/controller/__init__.py index f4dbb41806865dbf404d8e22172a59b9a51cb25a..6a0389200c3dbfe0c77443814666268ed08060c3 100644 --- a/app/intapp/controller/__init__.py +++ b/app/intapp/controller/__init__.py @@ -1,3 +1,2 @@ -from . import index -from . import soft \ No newline at end of file +from . import index \ No newline at end of file diff --git a/app/intapp/controller/index/common/plantask.py b/app/intapp/controller/index/common/plantask.py index 017ed102283759bb7ffa0642497ddf05266e1fd9..65abec8df951af844231ac4b187204ec846d59f5 100644 --- a/app/intapp/controller/index/common/plantask.py +++ b/app/intapp/controller/index/common/plantask.py @@ -146,16 +146,18 @@ class PLANTASK(): try: if not PLANTASK.BlockingSchedulers: PLANTASK.BlockingSchedulers = BlockingScheduler() - #进程可能影响cli运行 - multiprocessing.Process(target=PLANTASK.plantaskdsfsdfsafdsafsd,args=(PLANTASK.BlockingSchedulers,func,targger,args,year,month,week,day_of_week,day,hour,minute,second,iden)).start() - # t=threading.Thread(target=PLANTASK.plantaskdsfsdfsafdsafsd,args=(PLANTASK.BlockingSchedulers,func,targger,args,year,month,week,day_of_week,day,hour,minute,second,iden)) - # t.daemon=True - # t.start() - # print("添加",data) - + if 'Linux' in get_sysinfo()['platform']: + mu=multiprocessing.Process(target=PLANTASK.plantaskdsfsdfsafdsafsd,args=(PLANTASK.BlockingSchedulers,func,targger,args,year,month,week,day_of_week,day,hour,minute,second,iden)) + mu.daemon=True + mu.start() + elif 'Windows' in get_sysinfo()['platform']: + t=threading.Thread(target=PLANTASK.plantaskdsfsdfsafdsafsd,args=(PLANTASK.BlockingSchedulers,func,targger,args,year,month,week,day_of_week,day,hour,minute,second,iden)) + t.daemon=True + t.start() except: return False - return True + else: + return True #这里是初始化计划任务 if not config.app['cli']: #判断运行方式 try: @@ -165,5 +167,4 @@ if not config.app['cli']: #判断运行方式 serverserverinterval['updtime']=times() sqlite("interval",model_intapp_index_path).where("id",serverserverinterval['id']).update(serverserverinterval) PLANTASK.plantask(serverserverinterval) #添加计划任务 - # print(serverserverinterval) except:pass \ No newline at end of file diff --git a/app/intapp/controller/index/plug.py b/app/intapp/controller/index/plug.py index b7e201331355f12995acb51fca562e5e626d6c75..eb3fd7133ee72b1678460aa369bf5146dc9f24a6 100644 --- a/app/intapp/controller/index/plug.py +++ b/app/intapp/controller/index/plug.py @@ -130,8 +130,8 @@ def uninstallplug(): dirname="app/"+arr['modular']+"/controller/"+arr['name']+"/common/file" if not os.path.exists("backup/"+dirname): os.makedirs("backup/"+dirname) - zip.packzip(dirname,"backup/"+dirname+"/backup.zip") - file_set_content("backup/"+dirname+"/time",str(times())) + zip.packzip(dirname,"backup/"+dirname+"/backup.zip") + file_set_content("backup/"+dirname+"/time",str(times())) sqlite("menu",model_app_path).where("url='/"+arr['modular']+'/'+arr['name']+"'").delete() sqlite('plug',model_app_path).where("name='"+arr['name']+"' and modular='"+arr['modular']+"'").delete() diff --git a/app/intapp/controller/index/setup.py b/app/intapp/controller/index/setup.py index 9294b0a7964e0c6d7e3953a485215bb7b42fbffa..261071256a92687821cad5d9255b30160953a511 100644 --- a/app/intapp/controller/index/setup.py +++ b/app/intapp/controller/index/setup.py @@ -1,7 +1,38 @@ from .common import * def index(): return response.tpl() - +def addstart(): + "添加启动项" + data=request.get_json() + if sqlite("start").connect(model_app_path).where("value",data['value']).count(): + return errorjson(msg="禁止重复添加") + if system_start.insert_Boot_up(cmd=data['value'],name=data['name'],types=data['types'],admin_id=G.userinfo['id']): + return successjson() + else: + return errorjson(msg="添加失败,该系统支不支持") +def delstart(): + data=request.get_json() + if system_start.del_Boot_up(cmd=data['value'],id=data['id']): + return successjson() + else: + return errorjson() +def startlist(): + "启动项列表" + pagenow=request.args.get('pagenow') + pagesize=request.args.get('pagesize') + if not pagenow: + pagenow=1 + else: + pagenow=int(pagenow) + if not pagesize: + pagesize=10 + else: + pagesize=int(pagesize) + yz=system_start.lists(pagenow,pagesize) + lists=yz[0] + count=yz[1] + data=return_list(lists,count,pagenow,pagesize) + return successjson(data) def backup(): "备份" dirname=request.args.get("dirname") @@ -56,7 +87,7 @@ def recovery(): return successjson() else: return errorjson(msg="备份文件不存在") - else: + elif os.path.exists("backup"): filelist=get_file("backup") for k in filelist: if k['type']=='file' and 'backup.zip' in k['path']: @@ -64,6 +95,8 @@ def recovery(): dirname=re.sub("/backup.zip","",dirname) zip.unzip_file("backup/"+dirname+"/backup.zip",dirname) return successjson("恢复所有") + else: + return errorjson(msg="备份目录不存在") def download(name=""): "下载备份文件" if os.path.exists("backup"): diff --git a/app/intapp/controller/index/tpl/index/index.html b/app/intapp/controller/index/tpl/index/index.html index 01010bd526429b57559a4799fd857f170b846da0..ee605a0afe13619a40ddf8bd978592ff67cf7b31 100644 --- a/app/intapp/controller/index/tpl/index/index.html +++ b/app/intapp/controller/index/tpl/index/index.html @@ -36,7 +36,7 @@ - +
diff --git a/app/intapp/controller/index/tpl/setup/index.html b/app/intapp/controller/index/tpl/setup/index.html index 1ff58d7e23ada8bc1ff681b4593b8470f9450682..8bf3c8c8bd124a5790336a174be1148a0a8b762a 100644 --- a/app/intapp/controller/index/tpl/setup/index.html +++ b/app/intapp/controller/index/tpl/setup/index.html @@ -23,22 +23,49 @@
+ +
+    + + 添加启动项 + +
+ + + + + + + + + + + + + +
- 恢复所有备份
@@ -53,6 +80,23 @@ + + + + + + + + + + + 取 消 + 添加 + +
@@ -71,7 +115,13 @@ Vues=new Vue({ el: '#app', data:{ winheight:document.documentElement.clientHeight,winwidth:document.documentElement.clientWidth, - activeName: 'pack' + activeName: 'start', + admin:{value:'',name:'',types:''},admindialog:{status:false,title:'添加启动项'}, + data:{ + 'count':0, + 'pagenow':1, + 'lists':[] + }, }, mounted:function(){ self=this @@ -79,8 +129,36 @@ Vues=new Vue({ self.winheight=document.documentElement.clientHeight self.winwidth=document.documentElement.clientWidth } + self.obtain() }, methods: { + obtain:function(){ + self=this + self.get("/intapp/index/setup/startlist",{pagenow:self.data.pagenow},'获取中...').then(function(res){ + self.data=res.data + }) + },addstart:function(){ + self=this + self.post("/intapp/index/setup/addstart",self.admin,"请稍后...").then(function(res){ + self.admindialog.status=false + self.obtain() + }).catch(function(err){ + self.admindialog.status=false + }) + },delstart:function(item){ + self=this + self=this + self.$confirm("警告", '该操作会上传启动项', { + confirmButtonText: '删除', + cancelButtonText: '取消', + type: 'warning' + }).then(function(){ + self.post("/intapp/index/setup/delstart",item,"请稍后...").then(function(res){ + self.obtain() + }) + }).catch(function(){}); + + }, download:function(){ window.location.href="/intapp/index/setup/download/backup"; }, diff --git a/app/intapp/controller/index/tpl/task/index.html b/app/intapp/controller/index/tpl/task/index.html index 2f5754e5a8aa180b191fb18fb78137943429c9c0..cf1d3d4e73bb6991b8342f14d2dbcb0b3cb880fb 100644 --- a/app/intapp/controller/index/tpl/task/index.html +++ b/app/intapp/controller/index/tpl/task/index.html @@ -45,7 +45,7 @@