From b3387c898190da244b0d0cc7d96f9f268d0b5b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Sat, 20 Mar 2021 02:03:34 +0800 Subject: [PATCH 01/19] kun --- kcweb/Events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kcweb/Events.py b/kcweb/Events.py index c52d4ef..45d8940 100644 --- a/kcweb/Events.py +++ b/kcweb/Events.py @@ -14,7 +14,7 @@ class MyFileSystemEventHander(FileSystemEventHandler): if time.time()-eventgtimexz > 3: eventgtimexz=time.time() # print('* 更新文件:%s' % event.src_path) - # time.sleep(2) + # time.sleep(20) time.sleep(0.2) self.restart() class Events: -- Gitee From 3c27971fa39fa45d28d28795b5ebd32f575849be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Sun, 21 Mar 2021 00:44:53 +0800 Subject: [PATCH 02/19] kun --- kcweb/Events.py | 2 +- kcweb/common/autoload.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kcweb/Events.py b/kcweb/Events.py index 45d8940..8799ffa 100644 --- a/kcweb/Events.py +++ b/kcweb/Events.py @@ -14,7 +14,7 @@ class MyFileSystemEventHander(FileSystemEventHandler): if time.time()-eventgtimexz > 3: eventgtimexz=time.time() # print('* 更新文件:%s' % event.src_path) - # time.sleep(20) + # time.sleep(200) time.sleep(0.2) self.restart() class Events: diff --git a/kcweb/common/autoload.py b/kcweb/common/autoload.py index a015f40..3a415d7 100644 --- a/kcweb/common/autoload.py +++ b/kcweb/common/autoload.py @@ -947,7 +947,7 @@ class create: i=0 j+=1 arr=arr['data'] - r=requests.get(arr['dowurl']) + r=requests.get(arr['dowurl'],verify=False) f = open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", "wb") for chunk in r.iter_content(chunk_size=512): if chunk: -- Gitee From 02c39814f37a2e77719ca2f389c9d37b5e8da54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Mon, 29 Mar 2021 18:11:53 +0800 Subject: [PATCH 03/19] kun --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index 4cd79c7..4560852 100644 --- a/server.py +++ b/server.py @@ -5,4 +5,4 @@ import app as application app=web(__name__,application) if __name__ == "__main__": #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3) - app.run(host="0.0.0.0",port="39001",name="python") \ No newline at end of file + app.run(host="0.0.0.0",port="39001",name="python3") \ No newline at end of file -- Gitee From f6a484ac48f72f7493fe53283213cf8b18fc98e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Sun, 18 Apr 2021 17:53:34 +0800 Subject: [PATCH 04/19] kun --- app/intapp/controller/index/admin.py | 22 ++++++++++++++++ app/intapp/controller/index/role.txt | 1 + app/intapp/controller/index/setup.py | 10 +++++++- .../controller/index/tpl/admin/role.html | 2 +- .../controller/index/tpl/setup/pythonrun.html | 25 +++++++++++-------- kcweb/Events.py | 2 +- server.py | 2 +- 7 files changed, 50 insertions(+), 14 deletions(-) diff --git a/app/intapp/controller/index/admin.py b/app/intapp/controller/index/admin.py index 0be0a19..2ec83b3 100644 --- a/app/intapp/controller/index/admin.py +++ b/app/intapp/controller/index/admin.py @@ -92,6 +92,28 @@ def getpluglist(modular="intapp"): # del data[i] i+=1 return successjson(data) +def getmypluglist(modular="intapp"): + "本地插件列表,当前用户拥有的权限" + path="app/"+modular+"/controller/" + lis=os.listdir(path) + lists=[] + for k in lis: + if not os.path.isfile(path+k) and '__' not in k: + lists.append(k) + data=sqlite('plug',model_app_path).select() + i=0 + for k in data: + role=json_decode(k['role']) + if G.userinfo['role']['id']==1: + data[i]['role']=role + else: + role1=[] + for k in role: + if k['value'] in G.userinfo['role']['roleroute']: + role1.append(k) + data[i]['role']=role1 + i+=1 + return successjson(data) def dellogin(): G.setadminlog="退出所有会话" shutil.rmtree(config.session['path']) diff --git a/app/intapp/controller/index/role.txt b/app/intapp/controller/index/role.txt index 4bbe306..80b233b 100644 --- a/app/intapp/controller/index/role.txt +++ b/app/intapp/controller/index/role.txt @@ -16,6 +16,7 @@ shell执行能力,/intapp/index/index/shell 日志明细,/intapp/index/admin/logdeta 删除日志,/intapp/index/admin/deletelog 路由列表,/intapp/index/admin/getpluglist +当前用户拥有的权限,/intapp/index/admin/getmypluglist 管理员列表,/intapp/index/admin/getlist 添加管理员,/intapp/index/admin/insert 删除管理员,/intapp/index/admin/delete diff --git a/app/intapp/controller/index/setup.py b/app/intapp/controller/index/setup.py index c532d57..064e114 100644 --- a/app/intapp/controller/index/setup.py +++ b/app/intapp/controller/index/setup.py @@ -38,6 +38,9 @@ def restart(types='stop'): if data['types']=='python3.6': if not os.path.isfile("/usr/bin/"+interpreter): os.system("ln -s /usr/local/python/python3.6/bin/python3 /usr/bin/"+interpreter) + elif data['types']=='npm': + if not os.path.isfile("/usr/bin/"+interpreter): + os.system("ln -s /usr/local/nodejs/nodejs14.16/bin/npm /usr/bin/"+interpreter) elif data['types']=='php7.2': if os.path.isfile("/usr/local/php/php7.2/bin/php"): os.system("ln -s /usr/local/php/php7.2/bin/php /usr/bin/"+interpreter) @@ -58,7 +61,10 @@ def restart(types='stop'): else: return errorjson(msg="启动失败") elif types=='stop': - os.system("pkill -9 "+interpreter[:12]) + if data['types']=='npm': + os.system("pkill -9 node") + else: + os.system("pkill -9 "+interpreter[:12]) return successjson() def setpythonrun(): "设置/添加项目管理" @@ -70,6 +76,8 @@ def setpythonrun(): if not os.path.isfile("/usr/bin/"+interpreter): if data['types']=='python3.6': os.system("ln -s /usr/local/python/python3.6/bin/python3 /usr/bin/"+interpreter) + elif data['types']=='npm': + os.system("ln -s /usr/local/nodejs/nodejs14.16/bin/npm /usr/bin/"+interpreter) elif data['types']=='php7.2': if os.path.isfile("/usr/local/php/php7.2/bin/php"): os.system("ln -s /usr/local/php/php7.2/bin/php /usr/bin/"+interpreter) diff --git a/app/intapp/controller/index/tpl/admin/role.html b/app/intapp/controller/index/tpl/admin/role.html index 4343f03..109339f 100644 --- a/app/intapp/controller/index/tpl/admin/role.html +++ b/app/intapp/controller/index/tpl/admin/role.html @@ -111,7 +111,7 @@ var vm = new Vue({ self=this self.get("/intapp/index/admin/getrolelist",{'kw':self.kw,'pagesize':self.data.pagesize,'pagenow':self.data.pagenow},'获取中...').then(function(res){ self.data=res.data - self.get("/intapp/index/admin/getpluglist").then(function(res){ + self.get("/intapp/index/admin/getmypluglist").then(function(res){ self.getpluglist=[] for(var i=0;i - - - - - - - - - python3.6解释器 + npm运行 php7.2解释器 php7.3解释器
您必须提前在“软件管理”中安装php7.2,已安装请忽略,其他安装方式将无效 您必须提前在“软件管理”中安装php7.3,已安装请忽略,其他安装方式将无效
+ + + + + + + + + + @@ -252,7 +254,10 @@ VUE = new Vue({ }, setpythonrun:function(){ self=this - if(!self.admin.types||!self.admin.paths||!self.admin.filename||!self.admin.title){ + if(self.admin.types=='npm'){ + self.filename=''; + } + if(!self.admin.types||!self.admin.paths||!self.admin.title){ self.$message({type: 'error',message: '输入不全!'}); return } self.post("/intapp/index/setup/setpythonrun",self.admin,"请稍后...").then(function(res){ diff --git a/kcweb/Events.py b/kcweb/Events.py index 8799ffa..1cba5fb 100644 --- a/kcweb/Events.py +++ b/kcweb/Events.py @@ -14,7 +14,7 @@ class MyFileSystemEventHander(FileSystemEventHandler): if time.time()-eventgtimexz > 3: eventgtimexz=time.time() # print('* 更新文件:%s' % event.src_path) - # time.sleep(200) + # time.sleep(10) time.sleep(0.2) self.restart() class Events: diff --git a/server.py b/server.py index 4560852..4cd79c7 100644 --- a/server.py +++ b/server.py @@ -5,4 +5,4 @@ import app as application app=web(__name__,application) if __name__ == "__main__": #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3) - app.run(host="0.0.0.0",port="39001",name="python3") \ No newline at end of file + app.run(host="0.0.0.0",port="39001",name="python") \ No newline at end of file -- Gitee From c9326792d087cf18957943852376548a52aa940e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Mon, 19 Apr 2021 21:52:20 +0800 Subject: [PATCH 05/19] kun --- app/common/model.py | 1 + app/intapp/controller/index/admin.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/common/model.py b/app/common/model.py index 6ec26a0..268efec 100644 --- a/app/common/model.py +++ b/app/common/model.py @@ -11,6 +11,7 @@ class model_app_role(modelsqliteintapp): table="role" fields={ "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 + "admin_id":model.dbtype.int(LEN=11,DEFAULT=0), "icon":model.dbtype.varchar(LEN=128,DEFAULT=''), "title":model.dbtype.varchar(LEN=128,DEFAULT=''), "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), diff --git a/app/intapp/controller/index/admin.py b/app/intapp/controller/index/admin.py index 2ec83b3..2ef2990 100644 --- a/app/intapp/controller/index/admin.py +++ b/app/intapp/controller/index/admin.py @@ -182,7 +182,13 @@ def update(id=0): del data['describes'] except:pass else: - sqlite("admin",model_app_path).where("id",id).update(data) + if G.userinfo['role']['id']==1: + sqlite("admin",model_app_path).where("id",id).update(data) + else: + if data['role']==G.userinfo['role']['id'] or sqlite("role",model_app_path).where("admin_id="+str(G.userinfo['id'])+" and id="+str(data['role'])).count(): + sqlite("admin",model_app_path).where("id",id).update(data) + else: + return errorjson(msg="您没有其他角色的权限") return successjson() def setpwd(): "设置管理员登录密码" @@ -208,12 +214,16 @@ def getrolelist(id=0): "获取角色" if id: return successjson(sqlite("role",model_app_path).find(id)) - where=None + if G.userinfo['role']['id']==1: + where='1=1' + else: + where="id="+str(G.userinfo['role']['id'])+" or admin_id="+str(G.userinfo['id']) kw=request.args.get('kw') pagenow=request.args.get('pagenow') pagesize=request.args.get('pagesize') if kw: - where=[("title","like","%"+str(kw)+"%")] + # where=[("title","like","%"+str(kw)+"%"),'and',('admin_id','eq',G.userinfo['id'])] + where+=" and title like '%"+str(kw)+"%'" if not pagenow: pagenow=1 else: @@ -232,6 +242,7 @@ def insertrole(): G.setadminlog="添加角色" try: data=request.get_json() + data['admin_id']=G.userinfo['id'] data.update(updtime=times(),addtime=times()) data['roleroute']=json_encode(data['roleroute']) sqlite("role",model_app_path).insert(data) -- Gitee From ce3d63487ddb833a314e7882287a661cf6f51c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Thu, 22 Apr 2021 16:36:14 +0800 Subject: [PATCH 06/19] kun --- app/intapp/controller/__init__.py | 3 +- app/intapp/controller/index/index.py | 11 +- app/intapp/controller/soft/__init__.py | 8 + app/intapp/controller/soft/common/SOFT.py | 248 ++++++++ app/intapp/controller/soft/common/__init__.py | 2 + app/intapp/controller/soft/common/autoload.py | 10 + .../soft/common/file/sqlite/.gitignore | 1 + .../soft/common/file/sqlite/php_exten | Bin 0 -> 24576 bytes app/intapp/controller/soft/common/file/time | 1 + app/intapp/controller/soft/common/model.py | 85 +++ app/intapp/controller/soft/frp.py | 138 +++++ app/intapp/controller/soft/index.py | 131 ++++ app/intapp/controller/soft/install.txt | 1 + app/intapp/controller/soft/mongodb.py | 253 ++++++++ app/intapp/controller/soft/mysql copy.py | 310 ++++++++++ app/intapp/controller/soft/mysql.py | 338 ++++++++++ app/intapp/controller/soft/nginx.py | 419 +++++++++++++ app/intapp/controller/soft/page.py | 34 + app/intapp/controller/soft/php.py | 272 ++++++++ app/intapp/controller/soft/redis.py | 71 +++ app/intapp/controller/soft/role.txt | 44 ++ .../controller/soft/tpl/index/home.html | 430 +++++++++++++ app/intapp/controller/soft/tpl/index/web.html | 582 ++++++++++++++++++ app/intapp/controller/soft/tpl/soft/frp.html | 250 ++++++++ app/intapp/controller/soft/tpl/soft/git.html | 69 +++ .../controller/soft/tpl/soft/kodexplorer.html | 88 +++ .../controller/soft/tpl/soft/mongodb.html | 436 +++++++++++++ .../controller/soft/tpl/soft/mysql.html | 257 ++++++++ .../controller/soft/tpl/soft/nginx.html | 171 +++++ app/intapp/controller/soft/tpl/soft/php.html | 415 +++++++++++++ .../controller/soft/tpl/soft/phpmyadmin.html | 90 +++ .../controller/soft/tpl/soft/redis.html | 182 ++++++ .../controller/soft/tplm/index/home.html | 297 +++++++++ .../controller/soft/tplm/index/web.html | 395 ++++++++++++ app/intapp/controller/soft/tplm/soft/frp.html | 250 ++++++++ app/intapp/controller/soft/tplm/soft/git.html | 69 +++ .../soft/tplm/soft/kodexplorer.html | 88 +++ .../controller/soft/tplm/soft/mongodb.html | 436 +++++++++++++ .../controller/soft/tplm/soft/mysql.html | 203 ++++++ .../controller/soft/tplm/soft/nginx.html | 171 +++++ app/intapp/controller/soft/tplm/soft/php.html | 415 +++++++++++++ .../controller/soft/tplm/soft/phpmyadmin.html | 90 +++ .../controller/soft/tplm/soft/redis.html | 182 ++++++ 43 files changed, 7940 insertions(+), 6 deletions(-) create mode 100644 app/intapp/controller/soft/__init__.py create mode 100644 app/intapp/controller/soft/common/SOFT.py create mode 100644 app/intapp/controller/soft/common/__init__.py create mode 100644 app/intapp/controller/soft/common/autoload.py create mode 100644 app/intapp/controller/soft/common/file/sqlite/.gitignore create mode 100644 app/intapp/controller/soft/common/file/sqlite/php_exten create mode 100644 app/intapp/controller/soft/common/file/time create mode 100644 app/intapp/controller/soft/common/model.py create mode 100644 app/intapp/controller/soft/frp.py create mode 100644 app/intapp/controller/soft/index.py create mode 100644 app/intapp/controller/soft/install.txt create mode 100644 app/intapp/controller/soft/mongodb.py create mode 100644 app/intapp/controller/soft/mysql copy.py create mode 100644 app/intapp/controller/soft/mysql.py create mode 100644 app/intapp/controller/soft/nginx.py create mode 100644 app/intapp/controller/soft/page.py create mode 100644 app/intapp/controller/soft/php.py create mode 100644 app/intapp/controller/soft/redis.py create mode 100644 app/intapp/controller/soft/role.txt create mode 100644 app/intapp/controller/soft/tpl/index/home.html create mode 100644 app/intapp/controller/soft/tpl/index/web.html create mode 100644 app/intapp/controller/soft/tpl/soft/frp.html create mode 100644 app/intapp/controller/soft/tpl/soft/git.html create mode 100644 app/intapp/controller/soft/tpl/soft/kodexplorer.html create mode 100644 app/intapp/controller/soft/tpl/soft/mongodb.html create mode 100644 app/intapp/controller/soft/tpl/soft/mysql.html create mode 100644 app/intapp/controller/soft/tpl/soft/nginx.html create mode 100644 app/intapp/controller/soft/tpl/soft/php.html create mode 100644 app/intapp/controller/soft/tpl/soft/phpmyadmin.html create mode 100644 app/intapp/controller/soft/tpl/soft/redis.html create mode 100644 app/intapp/controller/soft/tplm/index/home.html create mode 100644 app/intapp/controller/soft/tplm/index/web.html create mode 100644 app/intapp/controller/soft/tplm/soft/frp.html create mode 100644 app/intapp/controller/soft/tplm/soft/git.html create mode 100644 app/intapp/controller/soft/tplm/soft/kodexplorer.html create mode 100644 app/intapp/controller/soft/tplm/soft/mongodb.html create mode 100644 app/intapp/controller/soft/tplm/soft/mysql.html create mode 100644 app/intapp/controller/soft/tplm/soft/nginx.html create mode 100644 app/intapp/controller/soft/tplm/soft/php.html create mode 100644 app/intapp/controller/soft/tplm/soft/phpmyadmin.html create mode 100644 app/intapp/controller/soft/tplm/soft/redis.html diff --git a/app/intapp/controller/__init__.py b/app/intapp/controller/__init__.py index 90b3d04..cace474 100644 --- a/app/intapp/controller/__init__.py +++ b/app/intapp/controller/__init__.py @@ -9,4 +9,5 @@ def error(e,data): header={"Content-Type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"*"} header['Location']="/intapp/index/plug/index/intapp/"+plug return '{"code":1,"msg":"您访问的地址不存在","data":"'+str(e)+'"}','302 Found',header -from . import index \ No newline at end of file +from . import index +from . import soft \ No newline at end of file diff --git a/app/intapp/controller/index/index.py b/app/intapp/controller/index/index.py index 25f4344..4495464 100644 --- a/app/intapp/controller/index/index.py +++ b/app/intapp/controller/index/index.py @@ -85,11 +85,12 @@ def disk():#磁盘分区和使用情况 }) partitions=psutil.disk_partitions() for v in partitions: - disk_usage=psutil.disk_usage(v[0]) - if disk_usage[0]: - partition.append({ - 'name':v[0],'type':v[2],'count':disk_usage[0],'used':disk_usage[1],'free':disk_usage[2],'userate':disk_usage[3] - }) + if v[2]: + disk_usage=psutil.disk_usage(v[0]) + if disk_usage[0]: + partition.append({ + 'name':v[0],'type':v[2],'count':disk_usage[0],'used':disk_usage[1],'free':disk_usage[2],'userate':disk_usage[3] + }) return successjson({ 'partitions':partition, #磁盘分区和使用情况 'io':psutil.disk_io_counters() diff --git a/app/intapp/controller/soft/__init__.py b/app/intapp/controller/soft/__init__.py new file mode 100644 index 0000000..f7a8da3 --- /dev/null +++ b/app/intapp/controller/soft/__init__.py @@ -0,0 +1,8 @@ +from . import index +from . import page +from . import nginx +from . import mysql +from . import redis +from . import mongodb +from . import frp +from . import php \ No newline at end of file diff --git a/app/intapp/controller/soft/common/SOFT.py b/app/intapp/controller/soft/common/SOFT.py new file mode 100644 index 0000000..54ad594 --- /dev/null +++ b/app/intapp/controller/soft/common/SOFT.py @@ -0,0 +1,248 @@ +# -*- coding: utf-8 -*- +from .model import * +class SOFT: + def softlist(kw,pagenow,pagesize): + "软件列表" + if config.app['appmode']=='develop': + where="1=1" + else: + where="platform='"+get_sysinfo()['uname'][0]+"'" + if kw: + where+=" and title LIKE '%"+kw+"%' or describes LIKE '%"+kw+"%'" + lists=sqlite("soft",model_intapp_soft_path).where(where).page(pagenow,pagesize).select() + if len(lists) < 1: + SOFT.updatesoftlist() + lists=sqlite("soft",model_intapp_soft_path).where(where).page(pagenow,pagesize).select() + if 'Linux' in get_sysinfo()['platform']: + i=0 + for k in lists: + if k['status'] == 0 and k['platform']=='Linux': #检查软件是否已经安装 + if (os.path.exists(k['paths']+k['title']+k['edition'])) : + lists[i]['status']=4 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':lists[i]['status']}) + if (k['status'] == 10 or k['status'] == 4) and k['platform']=='Linux': #检查软件是否在运行中 + if 'nginx' in k['title'] : + if not get_process_id('nginx'): + if k['status'] == 10: + lists[i]['status']=4 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 + else: + if k['status'] == 4: + lists[i]['status']=10 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 + elif 'redis' in k['title']: + if not get_process_id('redis'): + if k['status'] == 10: + lists[i]['status']=4 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 + else: + if k['status'] == 4: + lists[i]['status']=10 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 + elif 'mysql' in k['title']: + if not os.path.isfile(k['paths']+"/mysql"+k['edition']+"/tmp/mysqld.pid"): + if k['status'] == 10: + lists[i]['status']=4 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 + else: + if k['status'] == 4: + lists[i]['status']=10 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 + elif 'php5' in k['title']+k['edition'] or 'php7' in k['title']+k['edition']: + title=k['title']+k['edition'] + # print("php",title,title.replace(".", "")+"-fpm") + if not get_process_id(title): + if k['status'] == 10: + lists[i]['status']=4 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 + else: + if k['status'] == 4: + lists[i]['status']=10 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 + elif 'tomcat' in k['title']: + if not get_process_id('tomcat'): + if k['status'] == 10: + lists[i]['status']=4 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 + else: + if k['status'] == 4: + lists[i]['status']=10 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 + i+=1 + count=sqlite("soft",model_intapp_soft_path).where(where).count() + data=return_list(lists,count,pagenow,pagesize) + return data + def updatesoftlist(): + "更新软件列表" + http=Http() + sqlite("soft",model_intapp_soft_path).where("1=1").delete() + def openkcweb(pagenow=1,pagesize=20): + http.openurl(config.domain['kcwebapi']+"/pub/soft_list","GET",params={ + "pagenow":pagenow,"pagesize":pagesize + }) + res=json_decode(http.get_text) + lists=[] + if res['code']==0: + for k in res['data']['lists']: + k['status']=0 + k['msg']='' + k['addtime']=times() + lists.append(k) + sqlite("soft",model_intapp_soft_path).insert(lists) + if pagenow "+arr['paths']+arr['title']+arr['edition']+"/out.log 2>&1 &",name="redis服务",icon=arr['icon']) + return True + elif 'mysql' in arr['title']: + if os.path.isfile(arr['paths']+arr['title']+arr['edition']+"/support-files/mysql.server"): + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":"安装成功"}) + system_start.insert_Boot_up("mysqld"+(arr['edition'].replace(".", ""))+"server start",name="mysqld"+(arr['edition'].replace(".", ""))+"服务",icon=arr['icon']) #edition + return True + elif 'frp' == arr['title']: + if os.path.isfile(arr['paths']+arr['title']+arr['edition']+"/frps") and os.path.isfile(arr['paths']+arr['title']+arr['edition']+"/frpc"): + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":"安装成功"}) + return True + else: + if os.path.exists(arr['paths']+arr['title']+arr['edition']): + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":"安装成功"}) + if 'tomcat' == arr['title']: + jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() + system_start.insert_Boot_up(cmd="export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition']+" && /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin/startup.sh start",name="tomcat服务",icon=arr['icon']) + return True + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"安装失败,目录不存在"+arr['paths']+arr['title']+arr['edition']}) + else: + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"安装失败"}) + else: + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"下载失败"}) + except Exception as e: + sqlite('soft',model_intapp_soft_path).where('id',id).update({'status':0,'msg':'安装失败'+str(e)}) + def start(id): + "启动软件服务" + arr=sqlite("soft",model_intapp_soft_path).where("id",id).find() + if arr['platform']=='Linux': ###############################LINUX + if 'nginx' == arr['title']: + os.system("nginx") + elif 'php' == arr['title']: + titleedition=arr['title']+arr['edition'] + fpmname=titleedition.replace(".", "")+"-fpm" + os.system(fpmname+" -c "+arr['paths']+arr['title']+arr['edition']+"/bin/php.ini -R") + # print("php启动",fpmname+" -c "+arr['paths']+arr['title']+arr['edition']+"/bin/php.ini -R") + elif 'redis' == arr['title']: + # os.system("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > log 2>&1 &") + os.system("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > "+arr['paths']+arr['title']+arr['edition']+"/out.log 2>&1 &") + elif 'mysql' == arr['title']: + if '5.6' == arr['edition']: + os.system("mysqld56server start") + elif '5.7' == arr['edition']: + os.system("mysqld57server start") + elif '8.0' == arr['edition']: + os.system("mysqld80server start") + elif 'tomcat' == arr['title']: + jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() + os.system("export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition'] +" && /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin/startup.sh start") + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":9,"msg":"","updtime":times()}) + time.sleep(10) + else: + os.system("cd "+arr['paths']+arr['title']+arr['edition']+" && bash start.sh") + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":10,"msg":"运行中"}) + else: + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":""}) + def stop(id): + arr=sqlite("soft",model_intapp_soft_path).where("id",id).find() + if arr['platform']=='Linux': ###############################LINUX + if 'nginx' == arr['title']: + os.system("pkill nginx") + elif 'php' == arr['title']: + titleedition=arr['title']+arr['edition'] + fpmname=titleedition.replace(".", "")+"-fpm" + os.system("pkill -9 "+fpmname) + elif 'redis' == arr['title']: + os.system("pkill -9 redis") + elif 'mysql' == arr['title']: + if '5.6' == arr['edition']: + os.system("mysqld56server stop") + elif '5.7' == arr['edition']: + os.system("mysqld57server stop") + elif '8.0' == arr['edition']: + os.system("mysqld80server stop") + elif 'tomcat' == arr['title']: + jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() + os.system("export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition'] +" && cd /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin && ./shutdown.sh") + # os.system("pkill -9 tomcat") + time.sleep(1) + elif 'mongo' == arr['title']: + os.system("pkill mongo") + else: + os.system("cd "+arr['paths']+arr['title']+arr['edition']+" && bash stop.sh") + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":""}) + def uninstall(id): + try: + arr=sqlite("soft",model_intapp_soft_path).where("id",id).find() + if arr['platform']=='Linux': ###############################LINUX + os.system("rm -rf "+arr['paths']+arr['title']+arr['edition']) + startpath="/usr/bin/" + if 'nginx' == arr['title']: + system_start.del_Boot_up("nginx") + os.system("pkill -9 nginx") + model_intapp_menu.delete(title="网站管理",sort=9000) + os.system("rm -rf "+startpath+"nginx") + elif 'redis' == arr['title']: + system_start.del_Boot_up("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > "+arr['paths']+arr['title']+arr['edition']+"/out.log 2>&1 &") + os.system("rm -rf "+startpath+"redis-server") + elif 'php' == arr['title']: + titleedition=arr['title']+arr['edition'] + fpmname=titleedition.replace(".", "")+"-fpm" + system_start.del_Boot_up(fpmname+" -c "+arr['paths']+arr['title']+arr['edition']+"/bin/php.ini -R") + os.system("rm -rf "+startpath+fpmname) + elif 'mysql' == arr['title']: + system_start.del_Boot_up("mysqld"+(arr['edition'].replace(".", ""))+"server start") + os.system("rm -rf "+startpath+"mysqld"+(arr['edition'].replace(".", ""))+" && rm -rf "+startpath+"mysql"+(arr['edition'].replace(".", ""))) + elif 'mongodb' == arr['title']: + system_start.del_Boot_up("mongo",True) + os.system("pkill -9 mongo") + os.system("rm -rf /data/mongodb") + elif 'frp' == arr['title']: + system_start.del_Boot_up("frps",True) + system_start.del_Boot_up("frpc",True) + os.system("pkill -9 frps") + os.system("pkill -9 frpc") + else: + if 'tomcat' == arr['title']: + jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() + system_start.del_Boot_up("export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition']+" && /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin/startup.sh start") + os.system("cd /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin && ./shutdown.sh") + if os.path.exists(arr['paths']+arr['title']+arr['edition']): + sqlite('soft',model_intapp_soft_path).where('id',id).update({'status':4,'msg':'卸载失败'}) + return + except Exception as e: + sqlite('soft',model_intapp_soft_path).where('id',id).update({'status':4,'msg':'卸载失败'+str(e)}) + else: + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"已卸载"}) \ No newline at end of file diff --git a/app/intapp/controller/soft/common/__init__.py b/app/intapp/controller/soft/common/__init__.py new file mode 100644 index 0000000..8879824 --- /dev/null +++ b/app/intapp/controller/soft/common/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from .SOFT import * \ No newline at end of file diff --git a/app/intapp/controller/soft/common/autoload.py b/app/intapp/controller/soft/common/autoload.py new file mode 100644 index 0000000..c4bee80 --- /dev/null +++ b/app/intapp/controller/soft/common/autoload.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +from app.intapp.common import * +import subprocess +def get_process_id(name): + try: + child = subprocess.Popen(['pgrep', '-f', name],stdout=subprocess.PIPE, shell=False) + response = child.communicate()[0] + return [int(pid) for pid in response.split()] + except: + return [] diff --git a/app/intapp/controller/soft/common/file/sqlite/.gitignore b/app/intapp/controller/soft/common/file/sqlite/.gitignore new file mode 100644 index 0000000..f3c316e --- /dev/null +++ b/app/intapp/controller/soft/common/file/sqlite/.gitignore @@ -0,0 +1 @@ +soft \ No newline at end of file diff --git a/app/intapp/controller/soft/common/file/sqlite/php_exten b/app/intapp/controller/soft/common/file/sqlite/php_exten new file mode 100644 index 0000000000000000000000000000000000000000..947090a468579685c0d9058dbd71817876cd9b6e GIT binary patch literal 24576 zcmeHPeQZ-)pm~U>pVC01x>inNzdYabyT5zhJ@?#m-fMcH-V<~RE?--VEhv~}b7XS4>={9j$z;tSDiHdT z!<#(%0si9W?|U`NDjxZx4$e~O*UI$W@Qb||1B?O20AqkLz!+c*Fa{U{i~+^~W8jC! zz!rt7c-b=fwxDgh*BN-#3z6i@0q3jj&Q^Q+N9FoPOHH#yXs%gTZxPbYUD9f6ahAh3 zm+ozq7ZjJ3$@eddx9NBLUv};aI$Kk36nC_fIxH;lIE1=}X3GXkqtLLqS!mc=UoUKF ztlL!6xJ`K8vQ4Pj+Pt~00lvM-($HKk_$N5OTnKuCUZ?P4P2>8FHH}M*rmCevt>xL8 zt@X{q;>D?U%LRusU~ltmcLq}DnpUow1a_p(GFF;a zOrpx>a0ETjU^)@yLc4$B|18Z1t5X=hM%z;v{%iPJ*RN~fJNW{wTXS7gqJCFh$Q|Go z6ntDztNLsHKk{qy_A0+p`IRdbgNkMH({i)y53+3&8m>#w%H$6(nsK;&tP93(kTq>h&g0{b*xE4rz<_h|AsSKI}9iO2PT`4Fk z?%;?TyVmA(cmm?t!O_7k@xXrZ(#g@mUyI$BBb{V)V87Ve6Fs%>d1uFyFWS8A&d7kBH!3Cjj)Mud0ZSN#@bdxBqeRZ_Mm&L?KA+bq4)2XzI{(EUA`V=Q zz1InEZhmw!vgbnVwNNzlMs(=R%{`|^!|#d1CnCqY1XG2nqB45;P~^ z#7l3*j_i%TOJMNCy%)tped7Krqk|tMhqM1uo{do|wuE0VP!e zm{Jr{T?}NFk`0MVSdG)7r`6@V8&a(6_hNTXr03x1&{ZI3Q{5&Dm{x>b2Dq`;&%?zK z{nf<;nPOizTqnj2@E4K*P$!1@M(Ax>AD~ux_YlmHbaKv z0Iad07z$Aq!GITfIHE;c-Qh?fOK1XoVBO-mebHkF#M2{U=zTQ2_#6!rNOrcj!vP4c zqkxa#aGG{M3Sf$0x;7vfdwbhBQ90;1wg)4!0>%BXRFiX;$CcLctZV?=gMJO7xE=yc z)YYkT>gp;Ju5RcP(DRAE5cE)2r>1Txm%XBGg0^!gt~t`4<S5~YVcX9*78XF+Qph4PNlE|m#{%@?Y{%>6Qpo#h%E{8q`6~)7={x3n#m;OA^ zLwycM{X^P_WHtV@P0)4&#if+?EQdZPK42JL^?!=ep#VK}X5}9I%nIs3?G+Tl$w4=D zcignQyOppS%YO=f<;}y~yxj1W41U;)F~AsL3@`>51B?O20AqkLz!+c*Fa{U{jDa5u z13I~~Ob(mkiMopCbSk%OZho!I(60Yh|E6BZS^i(;&byV`pkn#|Oe-5${vWFfq?ve@ z|DXCk|LTgn^8YHgyb1O_S^j^j)kl!HOjanc{Qte{v?_%=^8alt|9{`5ZY=+wajDxR zvn0#^LqR0kU8YrTEdP%sgHYr)i9xaa|6N65S>=CO{y&r0faU+QE*xk1{{Y5S;0h9@ z2*;ol;h0YG7g?#yD$`V{FKD~DTb#e(?*%WYZmM>w42B;4XZi-+W!(b)x7z<`=jQLp zyPbD5uSEG9Wu2l(-Yxs5%&NF?uZzXCV_qaTIv%K-{4H`dNjxiP}|0EOMPHKqH}*sd+xwPkm0{jl!Z zf_3X-6VJRI6)+{!%3$q-uMAGO13S#W_UXGlic~FzHC_ox-rb>@t#^0e?Y^m77(-3g zSg6Up2*!sl>NL4s)ESeDx=<}>f}16uKvPI2OEgo9U$R&t8OOtykP!eG$^3=V@I^Dz z;fs-mFQGDkS4NaS1-@wbqM63<#TXA?LOMX9Bh`;f!xs$=4$_vcvnG5oO2U`n?;xx6 zo%<(J3(svZVN3=S!(*Un4D0{r6li1yi~djgr*(b0jr?_fuC_}vrm?F3tzN_R7W}JV z7o5Oei~+^~V}LQh82C{#;C&94dhlcde4dEb=XbUS0$$iG|Ne*8U~)BizO-;D?J#`A zh5oJ5A(W0f)RugDiEcV#40tHQwO^u;s*Tc>zi#%f{8x;x{I5ZHbj?n<4L}>+xYNzR z#vQV_8HH3mD`k{Gw_%t5HkrR(8b9$f9Y2|A{1lD?yeLtw1HNed#7|@VWKN`iU>iRCIjOFZ z#!vigkDttv_$dtcc85RpKLa$<)CEt|3~BLS7I8UPdGbMHpe=;rss@cTDZ}S9bphSO z)J6DrD1`etD55hUKLazM8DPAPLin`+g{Cg}8A@FsoI@xbKLa$>qw>??QBn0y6jJrH Y)EB_w;ekF6EDOUmjr)RdBS3HbKNvJ$VgLXD literal 0 HcmV?d00001 diff --git a/app/intapp/controller/soft/common/file/time b/app/intapp/controller/soft/common/file/time new file mode 100644 index 0000000..818b173 --- /dev/null +++ b/app/intapp/controller/soft/common/file/time @@ -0,0 +1 @@ +1599551060 \ No newline at end of file diff --git a/app/intapp/controller/soft/common/model.py b/app/intapp/controller/soft/common/model.py new file mode 100644 index 0000000..87d168d --- /dev/null +++ b/app/intapp/controller/soft/common/model.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +from .autoload import * +# 初始化数据库 +model_intapp_soft_path=os.path.split(os.path.realpath(__file__))[0]+"/file/sqlite/soft" +class modelsqlitesoft(model.model): + config={'type':'sqlite'} + config={'type':'sqlite','db':model_intapp_soft_path} + model.dbtype.conf=config +class model_intapp_soft(modelsqlitesoft): + "软件表" + table="soft" + fields={ + "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 + "icon":model.dbtype.varchar(LEN=128,DEFAULT=''), #图标 + "title":model.dbtype.varchar(LEN=128,DEFAULT=''), #软件名称 + "edition":model.dbtype.varchar(LEN=128,DEFAULT=''), #软件版本 + "shell":model.dbtype.varchar(LEN=128,DEFAULT=''), #shell 命令 + "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件描述 + "paths":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件安装目录 卸载软件时用到 + "status":model.dbtype.int(LEN=2,DEFAULT=0), #0未安装 1等待中 2下载中 3安装中 4已安装 5卸载中 9启动中... 10运行中 11正在停止服务... + "filename":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件源文件地址 + "platform":model.dbtype.varchar(LEN=256,DEFAULT='Linux'),#支持的系统 + 'msg':model.dbtype.varchar(LEN=1024,DEFAULT=''), #最后一次执行结果信息 + "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 + "updtime":model.dbtype.int(LEN=11,DEFAULT=0) #更新时间 + } +try: + sqlite('soft',model_intapp_soft_path).find() +except: + model_soft=model_intapp_soft() + model_soft.create_table() + +class model_intapp_web(modelsqlitesoft): + "网站列表" + table="web" + fields={ + "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 + "domain":model.dbtype.varchar(LEN=512,DEFAULT=''), #域名 + "port":model.dbtype.varchar(LEN=8,DEFAULT='80'), #端口 + "icon":model.dbtype.varchar(LEN=128,DEFAULT=''), #图标 + "title":model.dbtype.varchar(LEN=128,DEFAULT=''), #名称 + "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), #描述 + "status":model.dbtype.int(LEN=1,DEFAULT=1), #网站状态 0停止 1开启 + "path":model.dbtype.varchar(LEN=256,DEFAULT=''), #网站目录 + "client_max_body_size":model.dbtype.int(LEN=11,DEFAULT=20),#上传限制 + "webtpl":model.dbtype.varchar(LEN=256,DEFAULT=''), #nginx配置文件模板名 + "servers":model.dbtype.varchar(LEN=256,DEFAULT=''), #服务器名字 nginx名字 + "only":model.dbtype.varchar(LEN=32,DEFAULT=''), #唯一字段 + "balancing":model.dbtype.varchar(LEN=2048,DEFAULT=''), #负载均衡服务器信息 + "proxy_set_header":model.dbtype.varchar(LEN=1024,DEFAULT=''),#自定义转发请求头 + "header":model.dbtype.varchar(LEN=1024,DEFAULT=''),#自定义响应头 + "ssl_certificate":model.dbtype.varchar(LEN=1024,DEFAULT=''), + "ssl_certificate_key":model.dbtype.varchar(LEN=1024,DEFAULT=''), + "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 + "updtime":model.dbtype.int(LEN=11,DEFAULT=0) #更新时间 + } +try: + sqlite('web',model_intapp_soft_path).find() +except: + model_intapp_web=model_intapp_web() + model_intapp_web.create_table() + +model_intapp_soft_php_exten_path=os.path.split(os.path.realpath(__file__))[0]+"/file/sqlite/php_exten" +class model_intapp_php_exten(model.model): + "php扩展表" + config={'type':'sqlite'} + config={'type':'sqlite','db':model_intapp_soft_php_exten_path} + model.dbtype.conf=config + table="php_exten" + fields={ + "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 + "pid":model.dbtype.int(LEN=11), #软件列表id + "title":model.dbtype.varchar(LEN=128,DEFAULT=''), #扩展名称 + "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), #扩展描述 + "status":model.dbtype.int(LEN=2,DEFAULT=0), #0未安装 1等待中 2下载中 3安装中 4已安装 5卸载中 + "filename":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件源文件地址 + 'msg':model.dbtype.varchar(LEN=1024,DEFAULT=''), #最后一次执行结果信息 + "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 + "updtime":model.dbtype.int(LEN=11,DEFAULT=0) #更新时间 + } +try: + sqlite('php_exten',model_intapp_soft_php_exten_path).find() +except: + model_intapp_php_exten=model_intapp_php_exten() + model_intapp_php_exten.create_table() \ No newline at end of file diff --git a/app/intapp/controller/soft/frp.py b/app/intapp/controller/soft/frp.py new file mode 100644 index 0000000..087feb0 --- /dev/null +++ b/app/intapp/controller/soft/frp.py @@ -0,0 +1,138 @@ +from .common import * +dar="/usr/local/frp/frp0.30" +# pkill frps && cd /usr/local/frp/frp0.30 && ./frps -c frps_full.ini & +def get_server(): + server={ + 'conf':file_get_content(dar+"/frps_full.ini"), + 'base':json_decode(file_get_content(dar+"/frps_full.conf")), + 'dar':dar + } + return successjson(server) +def run_status(): + "获取运行状态" + data={"frpc":0,"frps":0} + if get_process_id('frps'): + data['frps']=1 + if get_process_id('frpc'): + data['frpc']=1 + return successjson(data) +def restart(types='frps'): + "重启" + G.setadminlog="重启frp" + if not os.path.exists(dar+"/log"): + os.makedirs(dar+"/log") + if types=='frps': + cmd="cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &" + os.system("pkill -9 frps") + system_start.del_Boot_up(cmd) + time.sleep(1) + os.system(cmd) + time.sleep(1) + if not get_process_id('frps'): + return errorjson(msg="启动失败,请检查配置") + system_start.insert_Boot_up(cmd=cmd,name="frps服务端") + elif types=='frpc': + cmd="cd "+dar +" && ./frpc -c frpc.ini &" + os.system("pkill frpc") + system_start.del_Boot_up(cmd) + time.sleep(1) + os.system(cmd) + time.sleep(1) + if not get_process_id('frpc'): + return errorjson(msg="启动失败,请检查配置") + system_start.insert_Boot_up(cmd=cmd,name="frpc客户端") + return successjson() +def stop(types='all'): + "停止" + G.setadminlog="停止frp服务" + if types=='frps': + system_start.del_Boot_up("cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") + os.system("pkill -9 frps") + elif types=='frpc': + system_start.del_Boot_up("cd "+dar +" && nohup ./frpc -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") + os.system("pkill -9 frpc") + else: + system_start.del_Boot_up("cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") + system_start.del_Boot_up("cd "+dar +" && nohup ./frpc -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") + os.system("pkill -9 frps") + os.system("pkill -9 frpc") + return successjson() +def upd_server(types='ini'): + G.setadminlog="修改frp配置" + server=request.get_json() + if types=='ini': + file_set_content(dar+"/frps_full.ini",server['conf']) + elif types=='base': + base=server['base'] + f = open(dar+"/frps_full.ini") + con='' + while True: + line = f.readline() + if not line: + break + elif 'bind_addr = ' in line: + line="bind_addr = "+base['bind_addr']+"\n" + elif 'bind_port = ' in line: + line="bind_port = "+base['bind_port']+"\n" + elif 'bind_udp_port = ' in line: + line="bind_udp_port = "+base['bind_udp_port']+"\n" + elif 'kcp_bind_port = ' in line: + line="kcp_bind_port = "+base['kcp_bind_port']+"\n" + elif 'vhost_http_port = ' in line: + line="vhost_http_port = "+base['vhost_http_port']+"\n" + elif 'vhost_https_port = ' in line: + line="vhost_https_port = "+base['vhost_https_port']+"\n" + elif 'dashboard_addr = ' in line: + line="dashboard_addr = "+base['dashboard_addr']+"\n" + elif 'dashboard_port = ' in line: + line="dashboard_port = "+base['dashboard_port']+"\n" + elif 'dashboard_user = ' in line: + line="dashboard_user = "+base['dashboard_user']+"\n" + elif 'dashboard_pwd = ' in line: + line="dashboard_pwd = "+base['dashboard_pwd']+"\n" + elif 'log_level = ' in line: + line="log_level = "+base['log_level']+"\n" + elif 'log_max_days = ' in line: + line="log_max_days = "+base['log_max_days']+"\n" + elif 'disable_log_color = ' in line: + line="disable_log_color = "+base['disable_log_color']+"\n" + elif 'token = ' in line: + line="token = "+base['token']+"\n" + elif 'allow_ports = ' in line: + line="allow_ports = "+base['allow_ports']+"\n" + elif 'max_pool_count = ' in line: + line="max_pool_count = "+base['max_pool_count']+"\n" + elif 'max_ports_per_client = ' in line: + line="max_ports_per_client = "+base['max_ports_per_client']+"\n" + elif 'subdomain_host = ' in line: + line="subdomain_host = "+base['subdomain_host']+"\n" + elif 'tcp_mux = ' in line: + line="tcp_mux = "+base['tcp_mux']+"\n" + con=con+line + f.close() + file_set_content(dar+"/frps_full.ini",con) + file_set_content(dar+"/frps_full.conf",json_encode(base)) + os.system("pkill frps") + time.sleep(1) + os.system("cd "+dar +" && ./frps -c frps_full.ini &") + time.sleep(1) + if not get_process_id('frps'): + return errorjson(msg="启动失败,请检查配置") + return successjson() +def get_client(): + client={ + 'conf':file_get_content(dar+"/frpc.ini"), + 'base':json_decode(file_get_content(dar+"/frpc.conf")) + } + return successjson(client) +def upd_client(type='ini'): + G.setadminlog="修改frp客户端配置" + server=request.get_json() + file_set_content(dar+"/frpc.ini",server['conf']) + os.system("pkill frpc") + time.sleep(1) + os.system("cd "+dar +" && ./frpc -c frpc.ini &") + time.sleep(1) + if not get_process_id('frpc'): + return errorjson(code=1,msg="启动失败,请检查配置") + return successjson() \ No newline at end of file diff --git a/app/intapp/controller/soft/index.py b/app/intapp/controller/soft/index.py new file mode 100644 index 0000000..e48c782 --- /dev/null +++ b/app/intapp/controller/soft/index.py @@ -0,0 +1,131 @@ +from .common import * +def index(): + kw=request.args.get("kw") + if not kw: + kw='' + lefttext=request.args.get('lefttext') + if not lefttext: + lefttext='应用' + lefturl=request.args.get('lefturl') + if not lefturl: + lefturl='myapp' + lefttype=request.args.get('lefttype') + if not lefttype: + lefttype='lefturl' + if sysisphone(): + return response.tpl("../tplm/index/home",kw=kw,lefttext=lefttext,lefturl=lefturl,lefttype=lefttype) + else: + return response.tpl('index/home',kw=kw) +def gettitle(title,edition): + "获取软件信息" + return successjson(sqlite('soft',model_intapp_soft_path).where("title='"+title+"' and edition='"+edition+"' and platform='"+get_sysinfo()['uname'][0]+"' and status >=4").find()) +def softlist(): + kw=request.args.get("kw") + pagenow=int(request.args.get("pagenow")) + pagesize=int(request.args.get("pagesize")) + return successjson(SOFT.softlist(kw,pagenow,pagesize)) +def updatesoftlist(): + "更新软件列表" + G.setadminlog="更新软件列表" + SOFT.updatesoftlist() + return successjson() +def getstatus(id): + "获取软件状态和描述" + return successjson(sqlite("soft",model_intapp_soft_path).field("status,msg").where("id",id).find()) +def insert(id): + "安装软件" + G.setadminlog="安装软件" + tar=sqlite('soft',model_intapp_soft_path).where("id",id).field("title,edition").find() + title=tar['title'] + if 'nginx' == title: + ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','nginx'),'and',('status','gt',0)]).find() + if ass: + return errorjson(msg="您已安装其他nginx版本,卸载其他nginx版本后可安装此版本") + if 'mysql' == title: + if "5.7" == tar['edition']: + ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','mysql'),'and',('status','gt',0),'and',('edition','eq','8.0')]).find() + if ass: + return errorjson(msg="您已安装8.0版本mysql") + if "8.0" == tar['edition']: + ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','mysql'),'and',('status','gt',0),'and',('edition','eq','5.7')]).find() + if ass: + return errorjson(msg="您已安装5.7版本mysql") + elif 'jdk' == title: + ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','jdk'),'and',('status','gt',0)]).find() + if ass: + return errorjson(msg="您已安装其他jdk版本,卸载其他jdk版本后可安装此版本") + elif 'tomcat' == title: + ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','jdk'),'and',('status','gt',0)]).find() + if not ass: + return errorjson(msg="tomcat依赖于jdk,请先安装jdk") + elif 'kodexplorer' in title or 'phpmyadmin' in title: + if not sqlite('soft',model_intapp_soft_path).where([('title','like','%php%'),'and',('status','egt','4')]).count() or not sqlite('soft',model_intapp_soft_path).where([('title','like','%nginx%'),'and',('status','egt','4')]).count(): + return errorjson(msg="先安装nginx和php") + if 'phpmyadmin' in title: + if not sqlite('soft',model_intapp_soft_path).where([('title','like','%mysql%'),'and',('status','egt','4')]).count() or not sqlite('soft',model_intapp_soft_path).where([('title','like','%nginx%'),'and',('status','egt','4')]).count(): + return errorjson(msg="先安装mysql") + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":1,"msg":"安装中"}) + Queues.insert(target=SOFT.insert,args=(id,),title="安装软件:"+title) + return successjson() +def start(id): + "启动软件" + title=request.args.get('title') + if title=='tomcat': + Queues.insert(SOFT.start,args=(id,),title='启动tomcat服务') + time.sleep(2) + else: + SOFT.start(id) + return successjson() +def stop(id): + "停止软件" + SOFT.stop(id) + return successjson() +def restartnginx(): + """平滑重启nginx""" + os.system("nginx -s reload") + return successjson() + +def uninstall(id): + "卸载软件" + # title=request.args.get("title") + title=sqlite('soft',model_intapp_soft_path).where("id",id).field("title").find()['title'] + if 'nginx' == title: + sqlite("web",model_intapp_soft_path).where("1=1").update({"status":0}) + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":5,"msg":"卸载中"}) + Queues.insert(target=SOFT.uninstall,args=(id,),title="卸载软件:"+title) + return successjson() + + +def gitssh(): + 'gitssh公钥' + try: + data=file_get_content("/root/.ssh/id_rsa.pub") + except: + data='' + return successjson(data) + + + +def add(): + "添加内容" + try: + data=request.get_json() + data.update(updtime=times(),addtime=times()) + # print(data) + sqlite('software',config.sqlitesoftware).insert(data) + except: + return errorjson(msg="失败") + else: + return successjson() +def update(id=0): + "更新内容" + data=request.get_json() + if not id: + id=data['id'] + try: + data.pop('updtime') + data.pop('addtime') + except:pass + else: + sqlite('software',config.sqlitesoftware).where("id",id).update(data) + return successjson() \ No newline at end of file diff --git a/app/intapp/controller/soft/install.txt b/app/intapp/controller/soft/install.txt new file mode 100644 index 0000000..f75c93b --- /dev/null +++ b/app/intapp/controller/soft/install.txt @@ -0,0 +1 @@ +oss2>=2.12.0 \ No newline at end of file diff --git a/app/intapp/controller/soft/mongodb.py b/app/intapp/controller/soft/mongodb.py new file mode 100644 index 0000000..cc24fb8 --- /dev/null +++ b/app/intapp/controller/soft/mongodb.py @@ -0,0 +1,253 @@ +from .common import * +import base64 +WORK_DIR="/data/mongodb" +# if not os.path.exists(WORK_DIR): +# os.system("mkdir -p "+WORK_DIR) +def get_config(id): + '获取mongodb页面配置' + try: + data=json_decode(file_get_content(WORK_DIR+"/config.conf")) + except: + data={} + if not data: + data={} + if os.path.isfile(WORK_DIR+"/key/mongo.key"): + key=file_get_content(WORK_DIR+"/key/mongo.key") + else: + key='' + data['key']=key + data['get_local_ip']=get_local_ip() + data['WORK_DIR']=WORK_DIR + try: + data['configlist']=json_decode(file_get_content(WORK_DIR+"/serverconfig.conf")) + except: + data['configlist']={} + return successjson(data) +def upd_config(id): + '修改mongodb页面配置' + G.setadminlog="修改mongodb页面配置" + data=request.get_json() + os.system("mkdir -p "+WORK_DIR+"/key") + f=open(WORK_DIR+"/key/mongo.key","w") + f.write(data['key']) + f.close() + os.system("chmod 600 "+WORK_DIR+"/key/mongo.key") + data['key']='' + file_set_content(WORK_DIR+"/config.conf",json_encode(data)) + return successjson() + +def start_config(types='restart'): + '启动/停止config服务' + G.setadminlog="启动/停止config服务" + data=request.get_json() + data['key']='' + os.system("mkdir -p "+WORK_DIR+"/conf") + f=open(WORK_DIR+"/conf/config.conf","w") + f.write("logappend=true\n"+ + "fork=true\n"+ + "maxConns=5000\n"+ + "replSet=configs\n"+ + "keyFile="+WORK_DIR+"/key/mongo.key\n"+ + "configsvr=true") + f.close() + os.system("chmod 777 "+WORK_DIR+"/conf/config.conf") + # os.system("chmod 600 "+WORK_DIR+"/key/mongo.key") + i=1 + for k in data['configs']['server']: + os.system("mkdir -p "+WORK_DIR+"/config"+str(i)+"/data") + i+=1 + if types=='restart' or types=='stop': #停止服务 + i=1 + for k in data['configs']['server']: + pid=file_get_content(WORK_DIR+"/config"+str(i)+"/db.pid") + os.system("kill -9 "+str(pid)) + time.sleep(0.1) + i+=1 + data['configs']['serverstatus']=0 + if types=='restart' or types=='start': #启动服务 + i=1 + for k in data['configs']['server']: + startstatus=False + cmd="mongod --bind_ip "+str(k['ip'])+" --port "+str(k['port'])+" -f "+WORK_DIR+"/conf/config.conf --dbpath "+WORK_DIR+"/config"+str(i)+"/data --logpath "+WORK_DIR+"/config"+str(i)+"/log.log --pidfilepath "+WORK_DIR+"/config"+str(i)+"/db.pid" + result=os.popen(cmd) + res = result.read() + for line in res.splitlines(): + print("line",line) + if 'process started successfully' in line: + startstatus=True + break + if not startstatus: + return errorjson(code=1,msg="启动失败") + + i+=1 + data['configs']['serverstatus']=1 + file_set_content(WORK_DIR+"/config.conf",json_encode(data)) + return successjson() +def start_mongos(types='restart'): + '启动/停止路由服务' + G.setadminlog="启动/停止路由服务" + data=request.get_json() + data['key']='' + # for k in data + #创建配置文件 + os.system("mkdir -p "+WORK_DIR+"/conf && mkdir -p "+WORK_DIR+"/mongos") + f=open(WORK_DIR+"/conf/mongos.conf","w") + f.write("logappend = true\n"+ + "fork=true\n"+ + data['mongos']['configdb']+" #这里必须是公共网ip或内网ip,千万不能是127.0.0.1\n" + "keyFile="+WORK_DIR+"/key/mongo.key\n"+ + "maxConns=20000 #最大连接数") + f.close() + os.system("chmod 777 "+WORK_DIR+"/conf/mongos.conf") + os.system("mkdir -p "+WORK_DIR+"/mongos") + if types=='restart' or types=='stop': #停止服务 + i=1 + for k in data['mongos']['server']: + pid=file_get_content(WORK_DIR+"/mongos/db"+str(i)+".pid") + os.system("kill -9 "+str(pid)) + time.sleep(0.1) + i+=1 + data['mongos']['serverstatus']=0 + if types=='restart' or types=='start': #启动服务 + i=1 + for k in data['mongos']['server']: + startstatus=False + cmd="mongos --bind_ip "+str(k['ip'])+" --port "+str(k['port'])+" -f "+WORK_DIR+"/conf/mongos.conf --logpath "+WORK_DIR+"/mongos/log"+str(i)+".log --pidfilepath "+WORK_DIR+"/mongos/db"+str(i)+".pid" + print(cmd) + result=os.popen(cmd) + res = result.read() + for line in res.splitlines(): + print("line",line) + if 'process started successfully' in line: + startstatus=True + break + if not startstatus: + return errorjson(code=1,msg="启动失败") + i+=1 + data['mongos']['serverstatus']=1 + file_set_content(WORK_DIR+"/config.conf",json_encode(data)) + return successjson() +def start_shard(types='restart'): + '启动/停止分片服务' + G.setadminlog="启动/停止分片服务" + data=request.get_json() + data['key']='' + os.system("mkdir -p "+WORK_DIR+"/conf") + + j=1 + for shard in data['shard']:#分片列表 + f=open(WORK_DIR+"/conf/shard"+str(j)+".conf","w") + f.write("logappend=true\n"+ + "fork=true\n"+ + "maxConns=2000\n"+ + "storageEngine=mmapv1 #基于内存映射文件的存储引擎\n"+ + "shardsvr=true\n"+ + "replSet="+shard['servername']+"\n"+ + "keyFile="+WORK_DIR+"/key/mongo.key") + f.close() + i=1 + for k in shard['server']: + os.system("mkdir -p "+WORK_DIR+"/shard"+str(j)+"/data"+str(i)) + i+=1 + if types=='restart' or types=='stop': #停止服务 + i=1 + for k in shard['server']: + pid=file_get_content(WORK_DIR+"/shard"+str(j)+"/db"+str(i)+".pid") + os.system("kill -9 "+str(pid)) + time.sleep(0.1) + i+=1 + data['shard'][j-1]['serverstatus']=0 + if types=='restart' or types=='start': #启动服务 + i=1 + for k in shard['server']:#副本集列表 + startstatus=False + cmd="mongod --bind_ip "+str(k['ip'])+" --port "+str(k['port'])+" -f "+WORK_DIR+"/conf/shard"+str(j)+".conf --dbpath "+WORK_DIR+"/shard"+str(j)+"/data"+str(i)+" --logpath "+WORK_DIR+"/shard"+str(j)+"/log"+str(i)+".log --pidfilepath "+WORK_DIR+"/shard"+str(j)+"/db"+str(i)+".pid" + print("启动cmd:",cmd) + result=os.popen(cmd) + res = result.read() + for line in res.splitlines(): + print("line",line) + if 'process started successfully' in line: + startstatus=True + break + if not startstatus: + file_set_content(WORK_DIR+"/config.conf",json_encode(data)) + return errorjson(code=1,msg="启动失败") + i+=1 + data['shard'][j-1]['serverstatus']=1 + j+=1 + file_set_content(WORK_DIR+"/config.conf",json_encode(data)) + return successjson() + +# def config_init(id): +# "config副本集初始化," +# data=request.get_json() +# port=data['configs']['server'][0]['port'] +# replicaset=data['configs']['replicaset'] +# members=[] +# i=0 +# for k in replicaset: +# zd={'_id':i,'host':k['ip']+':'+str(k['port'])} +# members.append(zd) +# i+=1 +# f=open(config.path['path']+"app/linuxweb/config_init.sh","w") +# f.write("mongo --port "+str(port)+"\n"+ +# "use admin\n"+ +# "rs.initiate({_id:'configs',members:"+json_encode(members)+"})\n"+ +# "exit") +# f.close() +# os.system("cd "+config.path['path']+"app/linuxweb && bash config_init.sh") +# return successjson() + + + +#mongodb独立部署 /data/mongodb/server1/ +def setserverconfig(): + configlist=request.get_json() + for k in configlist: + if not os.path.exists(WORK_DIR+k['path']): + os.makedirs(WORK_DIR+k['path']) + if not os.path.exists(WORK_DIR+k['path']+"/data"): + os.makedirs(WORK_DIR+k['path']+"/data") + file_set_content(WORK_DIR+k['path']+"/mongod.config",''+ + 'systemLog:\n'+ + ' destination: file\n'+ + ' logAppend: true\n'+ + ' path: '+WORK_DIR+k['path']+'/mongodb.log #mongodb的日志文件路径\n'+ + 'storage:\n'+ + ' dbPath: '+WORK_DIR+k['path']+'/data/ #mongodb的数据文件路径\n'+ + ' journal:\n'+ + ' enabled: true\n'+ + 'processManagement:\n'+ + ' fork: true # fork and run in background\n'+ + ' pidFilePath: '+WORK_DIR+k['path']+'/mongod.pid # location of pidfile\n'+ + ' timeZoneInfo: /usr/share/zoneinfo\n'+ + 'net:\n'+ + ' port: '+str(k['port'])+' #mongodb1的进程号\n'+ + ' bindIp: '+k['bindIp']+' # Listen to local interface only, comment to listen on all interfaces') + file_set_content(WORK_DIR+"/serverconfig.conf",json_encode(configlist)) + return successjson() +def restartserver(types='start',index=0): + index=int(index) + configlist=json_decode(file_get_content(WORK_DIR+"/serverconfig.conf")) + cmd="mongod -f "+WORK_DIR+configlist[index]['path']+"/mongod.config" #启动命令 + if types=='start': + configlist[index]['status']=1 + system_start.insert_Boot_up(cmd=cmd,name="mongodb独立模式",icon="https://img.kwebapp.cn/icon/mongodb.png") + elif types=='stop': + configlist[index]['status']=0 + system_start.del_Boot_up(cmd) + cmd=cmd+" --shutdown" #停止命令 + result=os.popen(cmd) + res = result.read() + startstatus=False + for line in res.splitlines(): + print("line",line) + if 'process started successfully' in line or 'killing process with pid' in line: + startstatus=True + break + if startstatus: + file_set_content(WORK_DIR+"/serverconfig.conf",json_encode(configlist)) + return successjson() + else: + return errorjson(cmd,msg="失败") diff --git a/app/intapp/controller/soft/mysql copy.py b/app/intapp/controller/soft/mysql copy.py new file mode 100644 index 0000000..32e65f1 --- /dev/null +++ b/app/intapp/controller/soft/mysql copy.py @@ -0,0 +1,310 @@ +from .common import * +import oss2 +def get_data(id): + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + text=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") + conf=json_decode(text) + if not conf: + if ar['edition']=='5.7': + port=3306 + else: + port=3307 + conf={ + "base":{ + 'rootpassword':'intapppasswordtest', + 'path':ar['paths']+ar['title']+ar['edition']+'/data', + 'port':port, #监听端口 + 'max_connections':'200',#最大连接数 + 'max_allowed_packet':'16M', #最大接受的数据包大小 + 'expire_logs_days':'3',#日志保留时间天() + 'query_cache_limit':'1M',#指定单个查询可以使用的缓冲区的大小 + 'query_cache_size':'32M',#查询的缓存大小设置 + 'query_cache_type':'1',#设置缓存的类型, 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 + 'wait_timeout':'9000',#超时等待时间,单位秒,即一个connection在若干秒内无响应 + 'thread_cache_size':'256',# 用于缓存空闲的线程 + 'key_buffer_size':'16M' # 用于指定索引缓冲区的大小 + }, + } + if ar['edition']=='5.7': + mycnf=file_get_content("/etc/my.cnf") + else: + mycnf=file_get_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf") + data={ + 'conf':conf, + 'ar':ar, + "my":mycnf + } + return successjson(data) +def upd_my(id): + "修改配置文件" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + data=request.get_json() + if ar['edition']=='5.7': + file_set_content("/etc/my.cnf",data['text']) + else: + file_set_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf",data['text']) + return successjson() +def upd_data(id): + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + data=request.get_json() + filetext=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") + filedata=json_decode(filetext) + if not filedata or data['base']['rootpassword']!=filedata['base']['rootpassword']:#修改mysql密码 + os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart --skip-grant-tables") + cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -e " + cmd=cmd+'"use mysql;flush privileges;update user set authentication_string=password(' + cmd=cmd+"'"+str(data['base']['rootpassword']) + cmd=cmd+"'" + cmd=cmd+') where user=' + cmd=cmd+"'root';set password=password('"+str(data['base']['rootpassword'])+"');" + cmd=cmd+'"' + if '5.7' != ar['edition']: + cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -p3307 -S "+ar['paths']+ar['title']+ar['edition']+"/tmp/mysql.sock -e " + cmd+='"use mysql;flush privileges;grant all privileges on *.* to root@' + cmd+="'%'" + cmd+=" identified by 'root';update mysql.user set password=password('"+data['base']['rootpassword']+"') where user='root';update mysql.user set grant_priv='Y' where User='root';flush privileges" + cmd=cmd+'"' + # file_set_content("mysqlset",cmd) + pi=subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart") + print(type(strs),strs) + if 'error' in strs: + return errorjson(msg="密码修改失败"+strs) + + # mysqld restart --skip-grant-tables && mysql -uroot -e "flush privileges;update mysql.user set authentication_string=password('123456') where user = 'root'"; + # print(data['base']['rootpassword'],filedata['base']['rootpassword']) + if '5.7' == ar['edition']: + mycnf='/etc/my.cnf' + else: + mycnf=ar['paths']+ar['title']+ar['edition']+"/my.cnf" + f = open(mycnf) + con='' + while True: + line = f.readline() + if not line: + break + elif 'datadir=' in line: + line="datadir="+str(data['base']['path'])+"\n" + elif 'port=' in line or 'port =' in line: + line="port="+str(data['base']['port'])+"\n" + elif 'max_connections=' in line: + line="max_connections="+str(data['base']['max_connections'])+"\n" + elif 'max_allowed_packet=' in line: + line="max_allowed_packet="+str(data['base']['max_allowed_packet'])+"\n" + elif 'expire_logs_days=' in line: + line="expire_logs_days="+str(data['base']['expire_logs_days'])+"\n" + elif 'query_cache_limit=' in line: + line="query_cache_limit="+str(data['base']['query_cache_limit'])+"\n" + elif 'query_cache_size=' in line: + line="query_cache_size="+str(data['base']['query_cache_size'])+"\n" + elif 'query_cache_type=' in line: + line="query_cache_type="+str(data['base']['query_cache_type'])+"\n" + elif 'wait_timeout=' in line: + line="wait_timeout="+str(data['base']['wait_timeout'])+"\n" + elif 'thread_cache_size=' in line: + line="thread_cache_size="+str(data['base']['thread_cache_size'])+"\n" + elif 'key_buffer_size=' in line: + line="key_buffer_size="+str(data['base']['key_buffer_size'])+"\n" + con=con+line + f.close() + f= open(mycnf, "w") + f.write(con) + f.close() + time.sleep(1) + if not filedata or data['base']['path']!=filedata['base']['path']: #修改数据存放目录 + os.system('mysqld'+(ar['edition'].replace(".", ""))+'server stop') + os.system("mkdir -p "+str(data['base']['path'])) + # #mysql数据复制 + if not filedata: + print("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") + os.system("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") + else: + print("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") + os.system("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") + os.system("chown -R mysql "+data['base']['path']+" && chgrp -R mysql "+data['base']['path']) + os.system('mysqld'+(ar['edition'].replace(".", ""))+'server start') + text=json_encode(data) + file_set_content(ar['paths']+ar['title']+ar['edition']+"/config.conf",text) + + return successjson() +def backups(types='whole',db='bankup_all_databases',upload_aliyun=True): + "备份mysql5.7" + return BACKUP.backups(types,db,upload_aliyun) +def recovery(types='whole',upload_aliyun=True): + "恢复mysql5.7" + db=request.args.get("db") + Queues.insert(target=BACKUP.recovery,args=(types,db,upload_aliyun),title="恢复mysql") + return successjson(msg="正在恢复数据库,请在任务队列中查看恢复结果") +class BACKUP: + def recovery(types,db,upload_aliyun): + """恢复数据库""" + if not os.path.isfile("app/common/file/config.conf"): + print("在系统配置中保存备份目录") + return + fileconfig=json_decode(file_get_content("app/common/file/config.conf")) + if not fileconfig: + print("在系统配置中保存备份目录") + return + backpath=fileconfig['aliyun']['backpath'] + if backpath: + if backpath[:1]=='/': + backpath=backpath[1:] + if backpath[-1]=='/': + backpath=backpath[:-1] + else: + backpath="kcweb" + backmysqlpath="backup/mysql" #mysql备份目录 + if not os.path.exists(backmysqlpath): + os.makedirs(backmysqlpath) + mysqlpwd='intapppasswordtest' + mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql5.7/config.conf")) #mysql信息 + if mysqlconf: + mysqldatapath=mysqlconf['base']['path'] + mysqlpwd=mysqlconf['base']['rootpassword'] + conf={ + "mysql":{ + "username":"root","password":mysqlpwd,"host":"127.0.0.1",#mysql信息 + }, + } + if upload_aliyun: + auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) + bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) + bucket.get_object_to_file(db,backmysqlpath+"/database.sql.gz") + os.system("gzip -d "+backmysqlpath+"/database.sql.gz") + os.system("mysql -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" < "+backmysqlpath+"/database.sql") + os.remove(backmysqlpath+"/database.sql") + else: + os.system("gzip -d "+backmysqlpath+"/"+db+".sql.gz") + os.system("mysql -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" < "+backmysqlpath+"/"+db+".sql") + print("恢复完成") + def backups(types,db,upload_aliyun): + """备份mysql --cli运行 + types whole表示全量备份。 increment表示增量备份所有 + + db bankup_all_databases表示备份所有数据库。 否则备份指定数据库按逗号分隔 types=whole时有效 + """ + if not os.path.isfile("app/common/file/config.conf"): + print("在系统配置中保存备份目录") + return + fileconfig=json_decode(file_get_content("app/common/file/config.conf")) + if not fileconfig: + print("在系统配置中保存备份目录") + return + backpath=fileconfig['aliyun']['backpath'] + if backpath: + if backpath[:1]=='/': + backpath=backpath[1:] + if backpath[-1]=='/': + backpath=backpath[:-1] + else: + backpath="kcweb" + backmysqlpath="backup/mysql" #mysql备份目录 + if not os.path.exists(backmysqlpath): + os.makedirs(backmysqlpath) + mysqldatapath="/usr/local/mysql/mysql5.7/data" #mysql数据库存放目 + mysqlpwd='intapppasswordtest' + mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql5.7/config.conf")) #mysql信息 + if mysqlconf: + mysqldatapath=mysqlconf['base']['path'] + mysqlpwd=mysqlconf['base']['rootpassword'] + conf={ + "mysql":{ + "username":"root","password":mysqlpwd,"host":"127.0.0.1",#mysql信息 + }, + } + if upload_aliyun: + auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) + bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) + if types=='whole': #全量备份 + if not os.path.exists(backmysqlpath): + os.system("mkdir -p "+backmysqlpath) + if db=='bankup_all_databases':#备份所有 + print("全量备份所有数据库:"+db+".sql.gz") + os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+".sql.gz") + else:#备份指定数据库 + db=re.sub(","," ",db) + print("全量备份指定数据库:"+db+".sql.gz") + os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+".sql.gz") + if upload_aliyun: + print(backmysqlpath+"/"+db+".sql.gz","上传mysql备份目录文件到阿里云oss...") + oss2.resumable_upload(bucket, "backups/"+backpath+"/"+backmysqlpath+"/"+db+"/"+time.strftime("%Y%m%d-%H:%M:%S",time.localtime(times()))+".sql.gz",backmysqlpath+"/"+db+".sql.gz") + filelist=[] + for obj in oss2.ObjectIterator(bucket, prefix="backups/"+backpath+"/"+backmysqlpath+"/"+db+"/"): + filelist.append(obj.key) + i=0 + while True: + if len(filelist)-i <= 5: #在阿里云保留5个备份文件 其他上传 + break + bucket.delete_object(filelist[i]) + i+=1 + + # elif types=='increment': #增量备份所有 + # if not os.path.exists(backmysqlpath) or not os.path.isfile(backmysqlpath+"/"+db+".sql.gz"): + # os.system("mkdir -p "+backmysqlpath) + # print("全量备份所有数据库:"+db+".sql.gz") + # os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/increment_all_databases.sql.gz") + # print("备份mysql二进制文件...") + # t=os.listdir(backmysqlpath) + # lis=os.listdir(mysqldatapath) + # maxlist=[] + # for files in lis: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # maxlist.append(a) + # except:pass + # for files in lis: + # iscz=True #是否需要复制 + # if iscz: + # for k in t: + # if mysqldatapath+"/"+k == mysqldatapath+"/"+files: + # iscz=False + # print(mysqldatapath+"/"+k+"已存在") + # break + # if not iscz: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # if max(maxlist) == a: + # iscz=True + # print(mysqldatapath+"/"+files+"该文件是最后一个日志,已备份,(最后一个文件可能不是完整的)") + # except:pass + # if iscz: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # os.system("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files) + # print("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files,"复制成功") + # except:pass + # if upload_aliyun: + # print("上传mysql备份目录文件到阿里云oss...") + # t=os.listdir(backmysqlpath) + # maxlist=[] + # for files in t: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # maxlist.append(a) + # except:pass + # path=get_file(backmysqlpath,is_folder=False) + # for files in path: + # sc=True #是否需要上传 + # if bucket.object_exists("backups/"+files['path']):#如果文件已存在阿里云 + # if 'mysql-bin.' in files['name']: + # try: + # a=int(files['name'].replace("mysql-bin.", "")) + # if max(maxlist) == a: + # print(backmysqlpath+"/"+files['name']+"该文件是最后一个日志,所以要上传阿里云") + # else: + # print("文件已在阿里云oss存在") + # sc=False + # except:pass + # else: + # print("文件已在阿里云oss存在") + # sc=False + # if sc: + # oss2.resumable_upload(bucket, "backups/"+files['path'], files['path']) + print("备份完成") diff --git a/app/intapp/controller/soft/mysql.py b/app/intapp/controller/soft/mysql.py new file mode 100644 index 0000000..e0474c4 --- /dev/null +++ b/app/intapp/controller/soft/mysql.py @@ -0,0 +1,338 @@ +from .common import * +import oss2 +def get_data(id): + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + text=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") + conf=json_decode(text) + if not conf: + if ar['edition']=='5.7': + port=3306 + elif ar['edition']=='8.0': + port=3308 + else: + port=3307 + conf={ + "base":{ + 'rootpassword':'intapppasswordtest', + 'path':ar['paths']+ar['title']+ar['edition']+'/data', + 'port':port, #监听端口 + 'max_connections':'200',#最大连接数 + 'max_allowed_packet':'16M', #最大接受的数据包大小 + 'expire_logs_days':'3',#日志保留时间天() + 'query_cache_limit':'1M',#指定单个查询可以使用的缓冲区的大小 + 'query_cache_size':'32M',#查询的缓存大小设置 + 'query_cache_type':'1',#设置缓存的类型, 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 + 'wait_timeout':'9000',#超时等待时间,单位秒,即一个connection在若干秒内无响应 + 'thread_cache_size':'256',# 用于缓存空闲的线程 + 'key_buffer_size':'16M' # 用于指定索引缓冲区的大小 python3 kcw.py --app app --modular intapp --plug soft --uninstall + }, + } + if '5.6' == ar['edition']: + mycnf=file_get_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf") + else: + mycnf=file_get_content("/etc/my.cnf") + data={ + 'conf':conf, + 'ar':ar, + "my":mycnf + } + return successjson(data) +def upd_my(id): + "修改配置文件" + G.setadminlog="mysql修改配置文件" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + data=request.get_json() + if '5.6' == ar['edition']: + file_set_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf",data['text']) + else: + file_set_content("/etc/my.cnf",data['text']) + return successjson() +def upd_data(id): + G.setadminlog="mysql修改基本配置文件" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + data=request.get_json() + filetext=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") + filedata=json_decode(filetext) + if (ar['edition']=='5.7' or ar['edition']=='5.6') and (not filedata or data['base']['rootpassword']!=filedata['base']['rootpassword']):#修改mysql密码 + os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart --skip-grant-tables") + cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -e " + cmd=cmd+'"use mysql;flush privileges;update user set authentication_string=password(' + cmd=cmd+"'"+str(data['base']['rootpassword']) + cmd=cmd+"'" + cmd=cmd+') where user=' + cmd=cmd+"'root';set password=password('"+str(data['base']['rootpassword'])+"');" + cmd=cmd+'"' + if '5.7' != ar['edition']: + cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -p3307 -S "+ar['paths']+ar['title']+ar['edition']+"/tmp/mysql.sock -e " + cmd+='"use mysql;flush privileges;grant all privileges on *.* to root@' + cmd+="'%'" + cmd+=" identified by 'root';update mysql.user set password=password('"+data['base']['rootpassword']+"') where user='root';update mysql.user set grant_priv='Y' where User='root';flush privileges" + cmd=cmd+'"' + # file_set_content("mysqlset",cmd) + pi=subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart") + print(type(strs),strs) + if 'error' in strs: + return errorjson(msg="密码修改失败"+strs) + + # mysqld restart --skip-grant-tables && mysql -uroot -e "flush privileges;update mysql.user set authentication_string=password('123456') where user = 'root'"; + # print(data['base']['rootpassword'],filedata['base']['rootpassword']) + if '5.6' == ar['edition']: + mycnf=ar['paths']+ar['title']+ar['edition']+"/my.cnf" + else: + mycnf="/etc/my.cnf" + f = open(mycnf) + con='' + while True: + line = f.readline() + if not line: + break + elif 'datadir=' in line and data['base']['path']: + line="datadir="+str(data['base']['path'])+"\n" + elif ('port=' in line or 'port =' in line) and data['base']['port']: + line="port="+str(data['base']['port'])+"\n" + elif 'max_connections=' in line and data['base']['max_connections']: + line="max_connections="+str(data['base']['max_connections'])+"\n" + elif 'max_allowed_packet=' in line and data['base']['max_allowed_packet']: + line="max_allowed_packet="+str(data['base']['max_allowed_packet'])+"\n" + elif 'expire_logs_days=' in line and data['base']['expire_logs_days']: + line="expire_logs_days="+str(data['base']['expire_logs_days'])+"\n" + elif 'query_cache_limit=' in line and data['base']['query_cache_limit']: + line="query_cache_limit="+str(data['base']['query_cache_limit'])+"\n" + elif 'query_cache_size=' in line and data['base']['query_cache_size']: + line="query_cache_size="+str(data['base']['query_cache_size'])+"\n" + elif 'query_cache_type=' in line and data['base']['query_cache_type']: + line="query_cache_type="+str(data['base']['query_cache_type'])+"\n" + elif 'wait_timeout=' in line and data['base']['wait_timeout']: + line="wait_timeout="+str(data['base']['wait_timeout'])+"\n" + elif 'thread_cache_size=' in line and data['base']['thread_cache_size']: + line="thread_cache_size="+str(data['base']['thread_cache_size'])+"\n" + elif 'key_buffer_size=' in line and data['base']['key_buffer_size']: + line="key_buffer_size="+str(data['base']['key_buffer_size'])+"\n" + con=con+line + f.close() + f= open(mycnf, "w") + f.write(con) + f.close() + time.sleep(1) + if not filedata or data['base']['path']!=filedata['base']['path']: #修改数据存放目录 + os.system('mysqld'+(ar['edition'].replace(".", ""))+'server stop') + os.system("mkdir -p "+str(data['base']['path'])) + # #mysql数据复制 + if not filedata: + print("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") + os.system("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") + else: + print("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") + os.system("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") + os.system("chown -R mysql "+data['base']['path']+" && chgrp -R mysql "+data['base']['path']) + os.system('mysqld'+(ar['edition'].replace(".", ""))+'server start') + text=json_encode(data) + file_set_content(ar['paths']+ar['title']+ar['edition']+"/config.conf",text) + + return successjson() +def backups(types='whole',db='bankup_all_databases',upload_aliyun=True,edition='5.7'): + "备份mysql" + return BACKUP.backups(types,db,upload_aliyun,edition) +def recovery(types='whole',upload_aliyun=True,edition='5.7'): + "恢复mysql" + if config.app['cli']: + db="backups/kcweb/backup/mysql/bankup_all_databases5.6/20200909-02:51:23.sql.gz" + BACKUP.recovery(types,db,upload_aliyun,edition) + else: + db=request.args.get("db") + Queues.insert(target=BACKUP.recovery,args=(types,db,upload_aliyun,edition),title="恢复mysql"+edition) + return successjson(msg="正在恢复数据库,请在任务队列中查看恢复结果") +class BACKUP: + def recovery(types,db,upload_aliyun,edition): + """恢复数据库""" + if not os.path.isfile("app/common/file/config.conf"): + print("在系统配置中保存备份目录") + return + fileconfig=json_decode(file_get_content("app/common/file/config.conf")) + if not fileconfig: + print("在系统配置中保存备份目录") + return + backpath=fileconfig['aliyun']['backpath'] + if backpath: + if backpath[:1]=='/': + backpath=backpath[1:] + if backpath[-1]=='/': + backpath=backpath[:-1] + else: + backpath="kcweb" + backmysqlpath="backup/mysql" #mysql备份目录 + if not os.path.exists(backmysqlpath): + os.makedirs(backmysqlpath) + mysqlpwd='intapppasswordtest' + mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql"+edition+"/config.conf")) #mysql信息 + if mysqlconf: + mysqldatapath=mysqlconf['base']['path'] + mysqlpwd=mysqlconf['base']['rootpassword'] + port=str(mysqlconf['base']['port']) + else: + if edition=='5.6': + port="3307" + elif edition=='5.7': + port="3306" + elif edition=='8.0': + port="3308" + conf={ + "mysql":{ + "username":"root","password":mysqlpwd,"host":"127.0.0.1","port":port,#mysql信息 + }, + } + if upload_aliyun: + auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) + bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) + bucket.get_object_to_file(db,backmysqlpath+"/database.sql.gz") + os.system("gzip -d "+backmysqlpath+"/database.sql.gz") + os.system("mysql"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -P"+conf['mysql']['port']+" -h"+conf['mysql']['host']+" -p"+conf['mysql']['password']+" < "+backmysqlpath+"/database.sql") + # print("mysql"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -P"+conf['mysql']['port']+" -h"+conf['mysql']['host']+" -p"+conf['mysql']['password']+" < "+backmysqlpath+"/database.sql") + os.remove(backmysqlpath+"/database.sql") + else: + os.system("gzip -d "+backmysqlpath+"/"+db+".sql.gz") + os.system("mysql"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -P"+conf['mysql']['port']+" -h"+conf['mysql']['host']+" -p"+conf['mysql']['password']+" < "+backmysqlpath+"/"+db+".sql") + print("恢复完成") + + def backups(types,db,upload_aliyun,edition): + """备份mysql --cli运行 + types whole表示全量备份。 increment表示增量备份所有 + + db bankup_all_databases表示备份所有数据库。 否则备份指定数据库按逗号分隔 types=whole时有效 + """ + if not os.path.isfile("app/common/file/config.conf"): + print("在系统配置中保存备份目录") + return + fileconfig=json_decode(file_get_content("app/common/file/config.conf")) + if not fileconfig: + print("在系统配置中保存备份目录") + return + + backpath=fileconfig['aliyun']['backpath'] + if backpath: + if backpath[:1]=='/': + backpath=backpath[1:] + if backpath[-1]=='/': + backpath=backpath[:-1] + else: + backpath="kcweb" + backmysqlpath="backup/mysql" #mysql备份目录 + if not os.path.exists(backmysqlpath): + os.makedirs(backmysqlpath) + + mysqlpwd='intapppasswordtest' + mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql"+edition+"/config.conf")) #mysql信息 + if mysqlconf: + mysqldatapath=mysqlconf['base']['path'] + mysqlpwd=mysqlconf['base']['rootpassword'] + port=str(mysqlconf['base']['port']) + else: + if edition=='5.6': + port="3307" + elif edition=='5.7': + port="3306" + elif edition=='8.0': + port="3308" + mysqldatapath="/usr/local/mysql/mysql"+edition+"/data" #mysql数据库存放目 + conf={ + "mysql":{ + "username":"root","password":mysqlpwd,"host":"127.0.0.1","port":port,#mysql信息 + }, + } + if upload_aliyun: + auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) + bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) + if types=='whole': #全量备份 + if not os.path.exists(backmysqlpath): + os.system("mkdir -p "+backmysqlpath) + if db=='bankup_all_databases':#备份所有 + print("全量备份所有数据库:"+db+".sql.gz") + os.system("mysqldump"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" -P"+conf['mysql']['port']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+edition+".sql.gz") + else:#备份指定数据库 + db=re.sub(","," ",db) + print("全量备份指定数据库:"+db+".sql.gz") + os.system("mysqldump"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" -P"+conf['mysql']['port']+" --databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+edition+".sql.gz") + if upload_aliyun: + print(backmysqlpath+"/"+db+edition+".sql.gz","上传mysql备份目录文件到阿里云oss...") + oss2.resumable_upload(bucket, "backups/"+backpath+"/"+backmysqlpath+"/"+db+edition+"/"+time.strftime("%Y%m%d-%H:%M:%S",time.localtime(times()))+".sql.gz",backmysqlpath+"/"+db+edition+".sql.gz") + filelist=[] + for obj in oss2.ObjectIterator(bucket, prefix="backups/"+backpath+"/"+backmysqlpath+"/"+db+edition+"/"): + filelist.append(obj.key) + i=0 + while True: + if len(filelist)-i <= 30: #在阿里云保留30个备份文件 其他上传 + break + bucket.delete_object(filelist[i]) + i+=1 + + # elif types=='increment': #增量备份所有 + # if not os.path.exists(backmysqlpath) or not os.path.isfile(backmysqlpath+"/"+db+".sql.gz"): + # os.system("mkdir -p "+backmysqlpath) + # print("全量备份所有数据库:"+db+".sql.gz") + # os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/increment_all_databases.sql.gz") + # print("备份mysql二进制文件...") + # t=os.listdir(backmysqlpath) + # lis=os.listdir(mysqldatapath) + # maxlist=[] + # for files in lis: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # maxlist.append(a) + # except:pass + # for files in lis: + # iscz=True #是否需要复制 + # if iscz: + # for k in t: + # if mysqldatapath+"/"+k == mysqldatapath+"/"+files: + # iscz=False + # print(mysqldatapath+"/"+k+"已存在") + # break + # if not iscz: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # if max(maxlist) == a: + # iscz=True + # print(mysqldatapath+"/"+files+"该文件是最后一个日志,已备份,(最后一个文件可能不是完整的)") + # except:pass + # if iscz: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # os.system("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files) + # print("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files,"复制成功") + # except:pass + # if upload_aliyun: + # print("上传mysql备份目录文件到阿里云oss...") + # t=os.listdir(backmysqlpath) + # maxlist=[] + # for files in t: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # maxlist.append(a) + # except:pass + # path=get_file(backmysqlpath,is_folder=False) + # for files in path: + # sc=True #是否需要上传 + # if bucket.object_exists("backups/"+files['path']):#如果文件已存在阿里云 + # if 'mysql-bin.' in files['name']: + # try: + # a=int(files['name'].replace("mysql-bin.", "")) + # if max(maxlist) == a: + # print(backmysqlpath+"/"+files['name']+"该文件是最后一个日志,所以要上传阿里云") + # else: + # print("文件已在阿里云oss存在") + # sc=False + # except:pass + # else: + # print("文件已在阿里云oss存在") + # sc=False + # if sc: + # oss2.resumable_upload(bucket, "backups/"+files['path'], files['path']) + print("备份完成") diff --git a/app/intapp/controller/soft/nginx.py b/app/intapp/controller/soft/nginx.py new file mode 100644 index 0000000..bae9675 --- /dev/null +++ b/app/intapp/controller/soft/nginx.py @@ -0,0 +1,419 @@ +from .common import * +import traceback +def index(id='',types='getinfo'): + "nginx配置文件" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title'] + edition=ar['edition'] + if types=='getinfo': + if os.path.isfile(paths+filenames+edition+'/logs/error.log'): + # print(paths+filenames+'/logs/error.log') + # f=open(paths+filenames+'/logs/error.log','r') + # logserror=f.read() + # f.close() + logserror='' + else:logserror='' + if os.path.isfile(paths+filenames+edition+'/logs/access.log'): + # f=open(paths+filenames+'/logs/access.log','r',encoding="utf-8") + # logsaccess=f.read() + # f.close() + logsaccess='' + else:logsaccess='' + f=open(paths+filenames+edition+'/conf/nginx.conf','r',encoding="utf-8") + confnginx=f.read() + data={ + 'logs':{'error':logserror,'access':logsaccess}, + 'conf':{'nginx':confnginx}, + 'ar':ar, + } + return successjson(data) + elif types=='updconf': + con=request.get_json() + f=open(paths+filenames+edition+'/conf/nginx.conf','w',encoding="utf-8") + f.write(con['text']) + f.close() + return successjson() + else: + return errorjson(msg="未知类型") +def anphp(): + "已安装的php以及伪静态模板" + nginx=sqlite('soft',model_intapp_soft_path).where([('status','egt','4'),'and',('platform','eq',get_sysinfo()['uname'][0]),'and',('title','like','nginx%')]).find() + if nginx: + pseudo_static_tpl=get_file(nginx['paths']+nginx['title']+nginx['edition']+'/conf/vhost/webtpl/rewrite') #伪静态模板 + rewr=[] + for k in pseudo_static_tpl: + rewr.append({'name':k['name'],'text':file_get_content(k['path'])}) + data={ + "php":sqlite('soft',model_intapp_soft_path).where("title like '%php%' and (status=4 or status=10) and title not like '%phpmyadmin%'").select(), + "rewr":rewr + } + return successjson(data) + else: + return successjson() +def webdescribesfind(): + "获取指定网站信息" + title=request.args.get("title") + return successjson(sqlite("web",model_intapp_soft_path).where("title='"+title+"'").find()) +def weblist(): + "网站列表" + where=False + pagenow=int(request.args.get('pagenow')) + pagesize=int(request.args.get('pagesize')) + kw=request.args.get('kw') + if kw: + where=[("title","like","%"+str(kw)+"%"),'or',("describes","like","%"+str(kw)+"%"),'or',("domain","like","%"+str(kw)+"%")] + if not pagenow: + pagenow=1 + if not pagesize: + pagesize=10 + lists=sqlite("web",model_intapp_soft_path).where(where).page(pagenow,pagesize).select() + i=0 + for k in lists: + # lists[i]['domain']=k['domain'].split("\n") + lists[i]['balancing'] =json_decode(k['balancing']) + lists[i]['proxy_set_header'] =json_decode(k['proxy_set_header']) + lists[i]['header'] =json_decode(k['header']) + i+=1 + count=sqlite("web",model_intapp_soft_path).where(where).count() + return successjson(return_list(lists,count,pagenow,pagesize)) +def add_web(): + G.setadminlog="添加或更新nginx网站" + data=request.get_json() + status,msg=funadd_web(data) + if status: + return successjson(msg) + else: + return errorjson(msg=msg) +def _banddomain(id,types,domain): + G.setadminlog="绑定域名" + # domain=request.args.get('domain') + if '.' not in domain: + # return errorjson(msg="域名格式错误") + return False,'域名格式错误' + if not domain: + # return errorjson(msg="域名参数错误") + return False,'域名参数错误' + web=sqlite("web",model_intapp_soft_path).where("id",id).find() + if web: + if(sqlite("web",model_intapp_soft_path).where("domain like '%"+domain+"%'").count()): + if types=='add': + # return successjson(msg="该域名已被使用",code=1) + return True,'该域名已被使用' + data=web + if domain: + if types=='add': + data['domain']=data['domain']+"\n"+domain + elif types=='del': + data['domain']=data['domain'].replace("\n"+domain, "") + data['domain']=data['domain'].replace(domain, "") + # return errorjson(data) + else: + # return errorjson(msg="types错误") + return False,'types错误' + if data['header']: + data['header']=json_decode(data['header']) + data['proxy_set_header']=json_decode(data['proxy_set_header']) + data['balancing']=json_decode(data['balancing']) + return funadd_web(data,types) + # return status,msg + # if status: + # return successjson(msg) + # else: + # return errorjson(msg=msg) + else: + return False,'id错误' + # return errorjson(msg="id错误") +def funadd_web(data,types=""): + "添加或更新网站" + nginx=sqlite('soft',model_intapp_soft_path).where([('status','egt','4'),'and',('platform','eq',get_sysinfo()['uname'][0]),'and',('title','like','nginx%')]).find() + if not nginx: + return errorjson(msg='安装nginx服务器后才创建网站') + addtime=times() + + if data['domain']=='': + return False,"域名不能为空" + if data['port']=='': + return False,"端口不能为空" + if data['client_max_body_size']=='': + return False,"上传限制不能为空" + if data['path']=='': + data['path']="/www/wwwroot/" + paths=nginx['paths'] + try: + ttt1=data['domain'].split("\n") + if data['id'] and sqlite('web',model_intapp_soft_path).where("id",data['id']).count(): + # if types!='del': + # where="port="+str(data['port'])+" and id != "+str(data['id'])+" and (" #[('port','eq',data['port'])] + # for kk in ttt1: + # where=where+"domain like '"+kk+"%'"+" or " + # where=where[:-4]+")" + # ttt2=sqlite('web',model_intapp_soft_path).where(where).find() + # if ttt2: + # ttt2=ttt2['domain'].split("\n") + # for k in ttt2: + # for kk in ttt2: + # if k==kk: + # return False,k+"已在本服务器其他站点使用被使用" + domains=sqlite('web',model_intapp_soft_path).where("id",data['id']).field("only").find()['only'] + else: + data['id']='' + where="port="+data['port']+" and (" + for kk in ttt1: + where=where+"domain like '%"+kk+"%'"+" or " + where=where[:-4]+")" + domains=ttt1[0]+":"+str(data['port']) + data['only']=domains + ttt=sqlite('web',model_intapp_soft_path).where(where).find() + if ttt: + ttt=ttt['domain'].split("\n") + for k in ttt: + for kk in ttt1: + if k==kk: + return False,k+"已被使用" + ttt=data['domain'].split("\n") + server_name='' + for k in ttt: + server_name=str(server_name)+" "+str(k) + + if nginx['platform']=='Linux': + if data['webtpl']=='': + return False,"请选择配置文件模板" + filenames=nginx['title']+nginx['edition'] + servertpl=paths+filenames+'/conf/vhost/webtpl/'+data['webtpl'] + ssl_certificate="" + ssl_certificate_key="" + try: + ssl_certificate=data['ssl_certificate'] + ssl_certificate_key=data['ssl_certificate_key'] + except: + data['ssl_certificate']='' + data['ssl_certificate_key']='' + try: + data['header'] + except: + data['header']='' + try: + data['ssl'] + except: + data['ssl']='' + try: + data['rewrite'] + except: + data['rewrite']='' + if data['ssl']: + ssl=443 + if len(data['ssl_certificate'])>5 and len(data['ssl_certificate_key'])>5: + ssl_certificate=data['ssl_certificate'] + ssl_certificate_key=data['ssl_certificate_key'] + # print(ssl_certificate_key) + else: + key=paths+filenames+'/conf/vhost/rewrite/'+domains+".key" + pem=paths+filenames+'/conf/vhost/rewrite/'+domains+".pem" + file_set_content(key,data['key']) + file_set_content(pem,data['pem']) + ssl_certificate=paths+filenames+"/conf/vhost/rewrite/"+domains+".pem" + ssl_certificate_key=paths+filenames+"/conf/vhost/rewrite/"+domains+".key" + print(ssl_certificate) + else: + if os.path.isfile(paths+filenames+'/conf/vhost/rewrite/'+domains+".key") and os.path.isfile(paths+filenames+'/conf/vhost/rewrite/'+domains+".pem"): + sslttt1=file_get_content(paths+filenames+'/conf/vhost/rewrite/'+domains+".key") + sslttt2=file_get_content(paths+filenames+'/conf/vhost/rewrite/'+domains+".pem") + if len(sslttt1)>10 and len(sslttt2)>10: + ssl=443 + else: + ssl=False + else: + ssl=False + if not ssl_certificate or not ssl_certificate_key: + ssl='' + if 'php' in data['webtpl'] and len(data['rewrite'])>4:#php伪静态 + file_set_content(paths+filenames+"/conf/vhost/rewrite/"+domains,data['rewrite']) + elif not os.path.isfile(paths+filenames+"/conf/vhost/rewrite/"+domains): + file_set_content(paths+filenames+"/conf/vhost/rewrite/"+domains,'') + if data['webtpl']=='static' or data['webtpl']=='vue' or 'php' in data['webtpl']: + t=kcwTemplate(filename=servertpl) + text=t.render(client_max_body_size=data['client_max_body_size'],port=data['port'],ssl=ssl,ssl_certificate=ssl_certificate,ssl_certificate_key=ssl_certificate_key, + server_name=server_name,webpath=data['path'],rewrite=paths+filenames+"/conf/vhost/rewrite/"+domains,domains=domains,header=data['header']) + elif data['webtpl']=='balancing':#添加负载均衡 + balancing=data['balancing'] #负载均衡列表 + proxy_set_header=data['proxy_set_header'] #自定义转发请求头列表 + for k in data['balancing']: + if k['ip']=='' or k['port']=='': + return False,"请填写负载均衡ip和端口" + t=kcwTemplate(filename=servertpl) + text=t.render(client_max_body_size=data['client_max_body_size'],port=data['port'],ssl=ssl,balancing=balancing,proxy_set_header=proxy_set_header,ssl_certificate=ssl_certificate,ssl_certificate_key=ssl_certificate_key, + server_name=server_name,webpath=data['path'],rewrite=paths+filenames+"/conf/vhost/rewrite/"+domains,domains=domains,header=data['header']) + f=open(paths+filenames+"/conf/vhost/"+domains+'.conf','w',encoding="utf-8") + f.write(text) + f.close() + os.system("nginx -s reload") + if not os.path.exists(data['path']): + os.makedirs(data['path']) + f=open(data['path']+"/index.html",'w',encoding="utf-8") + f.write('网站创建成功

恭喜您!网站创建成功

') + f.close() + f=open(data['path']+"/index.php",'w',encoding="utf-8") + f.write("") + f.close() + try: + data['servers']=paths+filenames + except:pass + try: + del data['key'] + del data['pem'] + except:pass + del data['ssl'] + del data['rewrite'] + data['balancing'] =json_encode(data['balancing']) + data['proxy_set_header'] =json_encode(data['proxy_set_header']) + data['header'] =json_encode(data['header']) + if data['id']: + data['updtime']=addtime + data['status']=1 + try: + sqlite('web',model_intapp_soft_path).where("id",data['id']).update(data) + except: + pass + else: + pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + if len(strs) > 1: + return False,strs + else: + del data['id'] + data['addtime']=addtime + data['updtime']=addtime + sqlite('web',model_intapp_soft_path).insert(data) + data['id']=sqlite('web',model_intapp_soft_path).max("id") + except: + print(traceback.format_exc()) + file_set_content("server.log",traceback.format_exc()) + return False,"失败,检查参数是否有误" + else: + return True,data['id'] +def del_web(id=0,path=0): + #path=1 表示删除网站目录 ,linux和windows已完成 + "删除网站" + G.setadminlog="删除网站" + title=request.args.get("title") + if not id and title: + where="title = '"+title+"'" + else: + where="id='"+str(id)+"'" + nginx=sqlite('web',model_intapp_soft_path).where(where).find() + if not nginx: + return successjson(msg="不存在") + print(nginx) + filenames=nginx['servers'] + if get_sysinfo()['uname'][0]=='Linux': + if os.path.isfile(filenames+"/conf/vhost/"+nginx['only']+'.conf'): + os.remove(filenames+"/conf/vhost/"+nginx['only']+'.conf') + if os.path.isfile(filenames+"/conf/vhost/rewrite/"+nginx['only']): + os.remove(filenames+"/conf/vhost/rewrite/"+nginx['only']) + if os.path.isfile(filenames+"/logs/"+nginx['only']+".access.log"): + os.remove(filenames+"/logs/"+nginx['only']+".access.log") + if os.path.isfile(filenames+'/conf/vhost/rewrite/'+nginx['only']+".key"): + os.remove(filenames+'/conf/vhost/rewrite/'+nginx['only']+".key") + if os.path.isfile(filenames+'/conf/vhost/rewrite/'+nginx['only']+".pem"): + os.remove(filenames+'/conf/vhost/rewrite/'+nginx['only']+".pem") + pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + elif get_sysinfo()['uname'][0]=='Windows': + if os.path.isfile(filenames+"/conf/vhost/"+nginx['only']+'.conf'): + os.remove(filenames+"/conf/vhost/"+nginx['only']+'.conf') + if os.path.isfile(filenames+"/conf/vhost/rewrite/"+nginx['only']): + os.remove(filenames+"/conf/vhost/rewrite/"+nginx['only']) + if os.path.isfile(filenames+"/logs/"+nginx['only']+".access.log"): + os.remove(filenames+"/logs/"+nginx['only']+".access.log") + os.system("cd "+filenames+" & stop.bat") + time.sleep(3) + os.system("cd "+filenames+" & start.bat") + else: + return errorjson(msg="无法匹配系统") + if path=='1' and os.path.exists(nginx['path']): + shutil.rmtree(nginx['path']) + sqlite('web',model_intapp_soft_path).where(where).delete() + pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + if len(strs) > 1: + return errorjson(msg=strs) + return successjson() + +def getssl(id): + ar=sqlite('web',model_intapp_soft_path).where('id',id).find() + key=ar['servers']+'/conf/vhost/rewrite/'+ar['only']+".key" + pem=ar['servers']+'/conf/vhost/rewrite/'+ar['only']+".pem" + data={ + "key":file_get_content(key), + "pem":file_get_content(pem) + } + return successjson(data) +def getrewr(id): + "获取伪静态" + ar=sqlite('web',model_intapp_soft_path).where('id',id).find() + return successjson(file_get_content(ar['servers']+'/conf/vhost/rewrite/'+ar['only'])) +def getconfig(id,types='get'): + "获取配置文件" + ar=sqlite('web',model_intapp_soft_path).where('id',id).find() + if types=='get': + return successjson(file_get_content(ar['servers']+'/conf/vhost/'+ar['only']+".conf")) + elif types=='set': + data=request.get_json() + file_set_content(ar['servers']+'/conf/vhost/'+ar['only']+".conf",data['text']) + pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + if len(strs) > 1: + return errorjson(msg=strs) + return successjson() + + +def sslfolde(): + "Let's Encrypt证书夹" + paths="/etc/letsencrypt/live/" + if not os.path.exists(paths): + return errorjson(code=1,msg="Let's Encrypt证书夹不存在,在插件市场安装LetsEncrypt插件创建证书后再使用该功能") + try: + lis=os.listdir(paths) + except: + return errorjson(code=1,msg="无法打开"+str(paths)) + lists=[] + for files in lis: + types="folder" + config={} + if os.path.isfile(paths+"/"+files): + types="file" + else: + config=file_get_content(paths+"/"+files+"/config.conf") + if config: + config=json_decode(config) + zd={"name":files,"types":types,"config":config} + lists.append(zd) + data=return_list(lists,count=len(lis),pagenow=1,pagesize=len(lis)) + data['paths']=paths + "文件列表" + return successjson(data) +def ssltpl(): + "Let's Encrypt证书内容" + name=request.args.get("name") + paths="/etc/letsencrypt/live/"+name + chain=file_get_content(paths+"/chain.pem") + fullchain=file_get_content(paths+"/fullchain.pem") + privkey=file_get_content(paths+"/privkey.pem") + cert=file_get_content(paths+"/cert.pem") + data={ + "chain":chain, + "fullchain":fullchain, + "privkey":privkey, + "cert":cert + } + return successjson(data) + \ No newline at end of file diff --git a/app/intapp/controller/soft/page.py b/app/intapp/controller/soft/page.py new file mode 100644 index 0000000..9e87cb1 --- /dev/null +++ b/app/intapp/controller/soft/page.py @@ -0,0 +1,34 @@ +from .common import * +def home(): + if sysisphone(): + return response.tpl("../tplm/index/home") + else: + return response.tpl("index/home") +def pub(html): + if sysisphone(): + return response.tpl("../tplm/page/%s" % html) + else: + return response.tpl("page/%s" % html) +def s(fun,html): + id=request.args.get("id") + if sysisphone(): + lefttext=request.args.get('lefttext') + if not lefttext: + lefttext='应用' + lefturl=request.args.get('lefturl') + if not lefturl: + lefturl='myapp' + lefttype=request.args.get('lefttype') + if not lefttype: + lefttype='lefturl' + return response.tpl("../tplm/%s/%s" % (fun,html),id=id,lefttext=lefttext,lefturl=lefturl,lefttype=lefttype) + else: + return response.tpl("%s/%s" % (fun,html),id=id) +def soft(html): + id=request.args.get("id") + types=request.args.get("types") + data=sqlite("soft",model_intapp_soft_path).where("id",id).find() + if sysisphone(): + return response.tpl("../tplm/soft/%s" % html,id=id,data=data,types=types) + else: + return response.tpl("soft/%s" % html,id=id,data=data,types=types) \ No newline at end of file diff --git a/app/intapp/controller/soft/php.py b/app/intapp/controller/soft/php.py new file mode 100644 index 0000000..d3e9798 --- /dev/null +++ b/app/intapp/controller/soft/php.py @@ -0,0 +1,272 @@ +from .common import * +def ini(id,is_upd=0): + "php.ini配置文件" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + if ar['platform']=='Linux': + filepath=paths+filenames+"/bin/php.ini" + elif ar['platform']=='Windows': + filepath=paths+filenames+"/php.ini" + else: + return errorjson(code=1,msg="不支持此时平台") + if is_upd: #修改配置 + G.setadminlog="修改配置ini" + data=request.get_json() + file_set_content(filepath,data['text']) + return successjson() + else: + data={ + 'ini':file_get_content(filepath), + 'php':ar + } + return successjson(data) +def www_conf(id,is_upd=0): + "www.conf配置文件" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + if ar['platform']=='Linux': + filepath=paths+filenames+"/etc/php-fpm.d/www.conf" + if 'php5.6' in filenames: + filepath=paths+filenames+"/etc/php-fpm.conf" + elif ar['platform']=='Windows': + filepath='' + else: + return errorjson(code=1,msg="不支持此时平台") + if is_upd: #修改配置 + G.setadminlog="修改配置www.conf" + data=request.get_json() + file_set_content(filepath,data['text']) + return successjson() + else: + data={ + 'www_conf':file_get_content(filepath), + 'php':ar + } + return successjson(data) +def phpfpm(id,is_upd=0): + "phpfpm配置信息" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + if ar['platform']=='Linux': + if not os.path.exists(paths+filenames+"/bin/conf"): + os.makedirs(paths+filenames+"/bin/conf") + filepath=paths+filenames+"/bin/conf/phpfpm.conf" + phpfpmpath=paths+filenames+"/etc/php-fpm.d/www.conf" + if 'php5.6' in filenames: + phpfpmpath=paths+filenames+"/etc/php-fpm.conf" + else: + filepath='' + phpfpmpath='' + if is_upd: #修改php-fpm配置信息 + data=request.get_json() + f = open(phpfpmpath) + con='' + while True: + line = f.readline() + if not line: + break + elif 'pm = ' in line and '=' in line: #运行描述 + line="pm = "+data['text']['pm']+"\n" + elif 'pm.max_children' in line and '=' in line:# 允许创建的最大子进程数 + line="pm.max_children = "+data['text']['max_children']+"\n" + elif 'pm.start_servers' in line and '=' in line:# 起始进程数(服务启动后初始进程数量) + line="pm.start_servers = "+data['text']['start_servers']+"\n" + elif 'pm.min_spare_servers' in line and '=' in line:# 起始进程数(服务启动后初始进程数量) + line="pm.min_spare_servers = "+data['text']['min_spare_servers']+"\n" + elif 'pm.max_spare_servers' in line and '=' in line:# 最大空闲进程数(当空闲进程达到此值时清理) + line="pm.max_spare_servers = "+data['text']['max_spare_servers']+"\n" + con=con+line + f.close() + f= open(phpfpmpath, "w") + f.write(con) + f.close() + file_set_content(filepath,json_encode(data['text'])) + return successjson() + else: + phpfpm=json_decode(file_get_content(filepath)) + if not phpfpm: + phpfpm='' + data={ + 'phpfpm':phpfpm, + 'php':ar + } + return successjson(data) +def base(id,is_upd=0): + "基本配置信息" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + if ar['platform']=='Linux': + if not os.path.exists(paths+filenames+"/bin/conf"): + os.makedirs(paths+filenames+"/bin/conf") + filepath=paths+filenames+"/bin/conf/base.ini" + phpinipath=paths+filenames+"/bin/php.ini" + elif ar['platform']=='Windows': + if not os.path.exists(paths+filenames+"/conf"): + os.makedirs(paths+filenames+"/conf") + filepath=paths+filenames+"/conf/base.ini" + phpinipath=paths+filenames+"/php.ini" + if is_upd: #修改基本配置信息 + #修改php.ini配置 + G.setadminlog="修改php.ini配置" + data=request.get_json() + f = open(phpinipath) + con='' + while True: + line = f.readline() + if not line: + break + elif 'max_execution_time' in line and '=' in line:#最大执行时间 + line="max_execution_time = "+data['text']['max_execution_time']+"\n" + elif 'max_input_time' in line and '=' in line:#最大输入时间 + line="max_input_time = "+data['text']['max_input_time']+"\n" + elif 'memory_limit' in line and '=' in line:#内存限制 + line="memory_limit = "+data['text']['memory_limit']+"M\n" + elif 'file_uploads' == line[0:12] and '=' in line:#是否允许文件上传 + line="file_uploads = "+data['text']['file_uploads']+"\n" + elif 'upload_max_filesize' in line and '=' in line:#上传大小限制 + line="upload_max_filesize = "+data['text']['upload_max_filesize']+"M\n" + elif 'max_file_uploads' in line and '=' in line:#上传数量限制 + line="max_file_uploads = "+data['text']['max_file_uploads']+"\n" + elif 'post_max_size' in line and '=' in line:#上传数量限制 + line="post_max_size = "+data['text']['post_max_size']+"M\n" + elif 'allow_url_fopen' in line and '=' in line: + line="allow_url_fopen = "+data['text']['allow_url_fopen']+"\n" + elif 'allow_url_include' in line and '=' in line: + line="allow_url_include = "+data['text']['allow_url_include']+"\n" + elif 'default_socket_timeout' in line and '=' in line: + line="default_socket_timeout = "+data['text']['default_socket_timeout']+"\n" + con=con+line + f.close() + f= open(phpinipath, "w") + f.write(con) + f.close() + file_set_content(filepath,json_encode(data['text'])) + # print(data['text']) + return successjson() + else: + base=json_decode(file_get_content(filepath)) + if not base: + base='' + data={ + 'base':base, + 'php':ar + } + return successjson(data) +def extenlist(id,is_upd=0): + "php扩展信息列表" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + lists=sqlite('php_exten',model_intapp_soft_php_exten_path).where('pid',id).select() + data={ + 'extenlist':lists, + 'php':ar + } + return successjson(data) +def log(id): + "待完善" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + filename=ar['filename'] + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + if ar['platform']=='Linux': + filepath=paths+filenames+"" + elif ar['platform']=='Windows': + filepath=paths+filenames+"" + data={ + 'log':file_get_content(filepath), + 'php':ar + } + return successjson(data) + +def add_php_exten(): + "增加php扩展" + G.setadminlog="安装php扩展" + data=request.get_json() + data['addtime']=times() + data['updtime']=times() + sqlite('php_exten',model_intapp_soft_php_exten_path).insert(data) + return successjson() +def del_php_exten(id): + "删除php扩展" + G.setadminlog="删除php扩展" + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).delete() + return successjson() + +def installext(id): + is_del=False #是否删除成功 + "安装php扩展和下载扩展" + G.setadminlog="安装php扩展和下载扩展" + ar=sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).find() + if ar['status']==0: + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':1,'msg':''}) + Queues.insert(target=__installextqu,args=(ar,),title="安装php-"+ar['title']+"扩展") + elif ar['status']==4: + "卸载扩展" + paths=request.get_json()['paths'] + if get_sysinfo()['uname'][0]=='Linux': + if os.path.exists(paths): + + confile=paths+"bin/php.ini" + f= open(confile, "r") + con='' + while True: + line = f.readline() + if not line: + break + elif str(ar['title']) in line: + line="" + is_del=True + con=con+line + f.close() + f= open(confile, "w") + f.write(con) + f.close() + + # confile=paths+"bin/php.ini" + # f= open(confile, "r") + # con=f.read() + # f.close() + # con=con.replace("extension="+str(ar['title'])+".so\n","") + # f= open(confile, "w") + # f.write(con) + # f.close() + # if is_del: + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':0,'msg':''}) + if 'php7.0' in paths: + os.system("pkill php70-fpm && php70-fpm -c "+paths+"php7.0/etc/php.ini") + elif 'php7.1' in paths: + os.system("pkill php71-fpm && php71-fpm -c "+paths+"php7.1/etc/php.ini") + elif 'php7.2' in paths: + os.system("pkill php72-fpm && php72-fpm -c "+paths+"php7.2/etc/php.ini") + elif 'php7.3' in paths: + os.system("pkill php73-fpm && php73-fpm -c "+paths+"php7.3/etc/php.ini") + elif 'php7.4' in paths: + os.system("pkill php74-fpm && php74-fpm -c "+paths+"php7.4/etc/php.ini") + # else: + # return errorjson(code=1,msg='卸载失败') + else: + return errorjson(code=1,msg='php文件夹错误') + return successjson() +def get_exten(id): + return successjson(sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).find()) +def __installextqu(ar): + "安装php扩展" + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':3,'msg':''}) + try: + cmd="wget "+config.domain['kcwebfile']+"/"+ar['filename'] + # os.system(cmd) + print(cmd) + pi=subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + if 'success' in strs: + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':4,'msg':''}) + else: + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':0,'msg':'安装失败'}) + # sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':4,'msg':''}) + except Exception as e: + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':0,'msg':'安装失败'+str(e)}) \ No newline at end of file diff --git a/app/intapp/controller/soft/redis.py b/app/intapp/controller/soft/redis.py new file mode 100644 index 0000000..1464e6a --- /dev/null +++ b/app/intapp/controller/soft/redis.py @@ -0,0 +1,71 @@ +from .common import * +def conf(id,is_upd=0): + "redis配置文件信息" + is_upd=int(is_upd) + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + if ar['platform']=='Linux': + filepath=paths+filenames+"/redis.conf" + else: + return errorjson(code=1,msg="不支持此时平台") + if is_upd: #修改配置 + data=request.get_json() + if not data['text']: + return errorjson(code=1,msg='不允许清空配置文件') + file_set_content(filepath,data['text']) + return successjson() + else: + data=file_get_content(filepath) + # print(filepath) + return successjson(data) +def base(id,is_upd=0): + "redis配置文件信息" + is_upd=int(is_upd) + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + + if ar['platform']=='Linux': + filepath=paths+filenames+"/redis.conf" + jsonpath=paths+filenames+"/redis.json" + else: + return errorjson(code=1,msg="不支持此时平台") + if is_upd: #修改配置 + G.setadminlog="修改redis配置" + data=request.get_json() + f = open(filepath) + con='' + while True: + line = f.readline() + if not line: + break + elif 'bind ' in line and '\n' in line and '#' not in line: + line="bind "+data['bind']+"\n" + elif 'port ' in line and '\n' in line and '#' not in line: + line="port "+data['port']+"\n" + elif 'timeout ' in line and '\n' in line and '#' not in line: + line="timeout "+data['timeout']+"\n" + elif 'maxclients ' in line and '\n' in line: + line="maxclients "+data['maxclients']+"\n" + elif 'databases ' in line and '\n' in line and '#' not in line: + line="databases "+data['databases']+"\n" + elif 'requirepass ' in line and '\n' in line: + if data['requirepass']: + line="requirepass "+data['requirepass']+"\n" + else: + line="# requirepass "+data['requirepass']+"\n" + elif 'maxmemory ' in line and '\n' in line and len(line)<20: + line="maxmemory "+data['maxmemory']+"\n" + con=con+line + f.close() + f= open(filepath, "w") + f.write(con) + f.close() + file_set_content(jsonpath,json_encode(data)) + return successjson() + else: + v=file_get_content(jsonpath) + data=json_decode(v) + data['ar']=ar + return successjson(data) \ No newline at end of file diff --git a/app/intapp/controller/soft/role.txt b/app/intapp/controller/soft/role.txt new file mode 100644 index 0000000..1da7c1d --- /dev/null +++ b/app/intapp/controller/soft/role.txt @@ -0,0 +1,44 @@ +#以下是该插件的路由,index容器会自动把以下路由加入到权限管理中 该文件必须使用utf-8编码 +软件页面,/intapp/soft/index/index +软件信息,/intapp/soft/index/gettitle +软件列表,/intapp/soft/index/softlist +更新软件列表,/intapp/soft/index/updatesoftlist +软件状态描述,/intapp/soft/index/getstatus +安装软件,/intapp/soft/index/insert +启动软件,/intapp/soft/index/start +停止软件,/intapp/soft/index/stop +卸载软件,/intapp/soft/index/uninstall +gitssh公钥,/intapp/soft/index/gitssh +软件设置页面,/intapp/soft/page/soft + +frp服务端内容,/intapp/soft/frp/get_server +frp运行状态,/intapp/soft/frp/run_status +frp重启,/intapp/soft/frp/restart +frp停止,/intapp/soft/frp/stop +修改frp服务端配置,/intapp/soft/frp/upd_server +frp客户端内容,/intapp/soft/frp/get_client +修改frp客户端配置,/intapp/soft/frp/upd_client + +mongodb管理,/intapp/soft/mongodb + +获取mysql配置,/intapp/soft/mysql/get_data +修改mysql配置,/intapp/soft/mysql/upd_my +修改mysql密码,/intapp/soft/mysql/upd_data +备份mysql,/intapp/soft/mysql/backups + +nginx网站管理,/intapp/soft/page/s +修改nginx配置,/intapp/soft/nginx/index +nginx伪静态模板,/intapp/soft/nginx/anphp +nginx网站信息,/intapp/soft/nginx/webdescribesfind +nginx网站列表,/intapp/soft/nginx/weblist +添加更新nginx网站,/intapp/soft/nginx/add_web +删除nginx网站,/intapp/soft/nginx/del_web +获取ssl,/intapp/soft/nginx/getssl +获取伪静态内容,/intapp/soft/nginx/getrewr +获取配置文件,/intapp/soft/nginx/getconfig +证书夹,/intapp/soft/nginx/sslfolde +证书内容,/intapp/soft/nginx/ssltpl + +php管理,/intapp/soft/php + +redis管理,/intapp/soft/redis diff --git a/app/intapp/controller/soft/tpl/index/home.html b/app/intapp/controller/soft/tpl/index/home.html new file mode 100644 index 0000000..cc19803 --- /dev/null +++ b/app/intapp/controller/soft/tpl/index/home.html @@ -0,0 +1,430 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+
+ + + 搜索 + + + 更新软件列表 + +
+
+ + % if config.app['appmode']=='develop': + + + + % endif + + + + + + + + + + + + + + + + + + +
+
+ + +
+ + + + + + + + + + + + + + + 如:/usr/local/php/ + + + + + + + + + + 注:需要在后端接口上配置wget文件地址 + + + + Linux + Windows + + + + + + +
+ + + diff --git a/app/intapp/controller/soft/tpl/index/web.html b/app/intapp/controller/soft/tpl/index/web.html new file mode 100644 index 0000000..7d62981 --- /dev/null +++ b/app/intapp/controller/soft/tpl/index/web.html @@ -0,0 +1,582 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+
+    + + + 搜索 + 添加网站 + + + 下载数据 + + 上传intapp_soft.zip + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
域名
端口 + 上传限制:MB
网站名
配置文件模板 + + + + +
备注
网站目录 + + +
+
+ + + + + + + +
+ + + + + + + 如:Access-Control-Allow-Origin * + 如:403 /403.html + + +
+ 自定义配置:自定义响应或自定义错误页面 + +
+ +
+
+ + + + + + + + +
+ + + + + + + + + +   + + +
+ nginx负载均衡是一个代理均衡转发器 + +
+ +
+ + 取 消 + 修改添加 + +
+ + +
+
+ + +
+
+ 您已配置Let's证书


+ ssl_certificate :{{admin.ssl_certificate}}

+ ssl_certificate_key :{{admin.ssl_certificate_key}}

+ 使用自有证书 +
+
+
+ 密钥(KEY) + +
+
+ 证书(PEM格式) + +
+ 确定 +
+
+
+ + +
+ + + + + +
+ 保存
+ 选择伪静态模板就可以了,修改了记得要保存哦!重启nginx生效 +
+ +
+ + 确定 +
+
+ +
+ + + + + + + +
支持域名有效期
+ + {{item1.domain}}     + + + + {{time_date(item.config.createtime+7776000,true)}} + + + + 使用 + +
+
+
+
+ + + diff --git a/app/intapp/controller/soft/tpl/soft/frp.html b/app/intapp/controller/soft/tpl/soft/frp.html new file mode 100644 index 0000000..edfcb44 --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/frp.html @@ -0,0 +1,250 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+ + + + + 重启 + 停止 + + 保存 + + + + + + +
+ 重启 + 停止 + + + + 这是服端监听的地址 + + + + 这是服端监听的端口 + + + + 这是upd监听的端口 + + + + 这是kcp监听的端口 + + + + 这是http监听的端口 + + + + 这是https监听的端口 + + + + 这是dashboard监听的ip地址 + + + + 这是dashboard监听的端口 + + + + 这是dashboard监听的用户名 + + + + 这是dashboard监听的密码 + + + + 这是frp的验证机制 + + + + 这是frp的验证串的有效时间 + + + + + + + + 日志保持多少天 + + + + + + + + 白名单端口 + + + + 最大值进程数 + + + + + + + + + + + + + + + 保存 + + +
+ +
+ + + 保存 + +
+
+
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/git.html b/app/intapp/controller/soft/tpl/soft/git.html new file mode 100644 index 0000000..ce87f2d --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/git.html @@ -0,0 +1,69 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+
+ +
+ 您可以使用root身份执行以下命令生成ssh密钥

+ +
+
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/kodexplorer.html b/app/intapp/controller/soft/tpl/soft/kodexplorer.html new file mode 100644 index 0000000..6f38ff4 --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/kodexplorer.html @@ -0,0 +1,88 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + 添加 + +
+
+
+ + + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/mongodb.html b/app/intapp/controller/soft/tpl/soft/mongodb.html new file mode 100644 index 0000000..ebdbc92 --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/mongodb.html @@ -0,0 +1,436 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +

可以在终端中执行以下命令创建可以 +

+ WORK_DIR=/data/mongodb
+ mkdir -p $WORK_DIR/key/
+ cd $WORK_DIR/key/
+ openssl rand -base64 756 > mongo.key
+ chmod 600 mongo.key
+
+

+ 保存 +
+
+ +
+ config服务 (注:这是一个config服务) + + + + + + +
+ 通常生产环境每台机器应该只有一个,您可以在其他机器上开启config服务后手动添加到副本集中
+ +
+ 运行中 + 停止服务 + 重启服务 +
+
+ 已停止 + 启动服务 +
+
+ 待初始化 + 初始化 +
+

+
+ 副本集初始化(如果需要,生产环境应该是内网ip而不是127.0.0.1)
+
+ +
+增加副本集示例 +
+mongo --port {{data.configs.server[0]['port']}}
+use admin
+rs.add({_id:1,host:'{{data.get_local_ip}}:27002',priority:2})#增加主机 priority:优先级
+
+删除副本集示例 +
+mongo --port {{data.configs.server[0]['port']}}
+use admin
+rs.remove('{{data.get_local_ip}}:27002')
+
+
+ +
+
+ +
+ configdb: +
示例:configdb = configs/192.168.1.101:27001,192.168.1.102:27001,192.168.1.103:27001,则无法扩展外部服务器
+ 上述ip和端口是已经启动的配置服务,可以是其他机器上的mongodb配置服务 +
+ 路由服务 (注:这是一个路由服务) + + + + + + +
+ +
+
+ 运行中 + 停止服务 + 重启服务 +
+
+ 已停止 + 启动服务 +
+
+ 待初始化 + 初始化 +
+
+
+ 初始化用户
+
+ +
+ 在路由中添加分片,如下示例
+
+mongo --port {{data.mongos.server[0]['port']}}
+use admin
+db.auth('admin','admin')
+sh.addShard("shard1/192.168.1.101:29001,192.168.1.102:29001") #shard1是分片集群id
+sh.status()
+
+
+
+
+ +
+
+ 分片服务名{{indexs+1}}: + + + + + + + +
+ 通常生产环境每台机器应该只有一个,您可以在其他机器上开启分片服务后手动添加到副本集中
+ +
+ 运行中 + 停止服务 + 重启服务 +
+
+ 已停止 + 启动服务 +
+
+ 待初始化 + 初始化 +
+

+
+ 副本集初始化(生产环境应该是内网ip而不是127.0.0.1)
+ +
+
+ +
+
+
+ + + +
+ + + + + + + + + + + + + +
绑定ip端口服务目录
+ + 运行中 + 停止 + + + 已停止 + 启动 + + +
+
+ + 保存 +
+ +
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/mysql.html b/app/intapp/controller/soft/tpl/soft/mysql.html new file mode 100644 index 0000000..e31a335 --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/mysql.html @@ -0,0 +1,257 @@ + + + + + + + kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ + + + 8.0版本不支持可视化修改 + + + + 建议与mysql安装目录分开 + + + + port 监听器端口 + + + + max_connections 最大连接数 + + +
+ max_allowed_packet 最大接受数据的包大小 +
+ +
+ expire_logs_days 日志保留时间(天) +
+ +
+ query_cache_limit 指定单个查询可以使用的缓冲区的大小 +
+ +
+ query_cache_size 查询的缓存大小设置 +
+ +
+ query_cache_type 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 +
+ +
+ wait_timeout 超时等待时间,单位秒,即一个connection在若干秒内无响应 +
+ +
+ thread_cache_size 用于缓存空闲的线程 +
+ +
+ key_buffer_size 用于指定索引缓冲区的大小 +
+
+
+ 保存 + 加入开机启动 +
+ +
+ +
+                        
+                    
+
+ 保存 +
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/nginx.html b/app/intapp/controller/soft/tpl/soft/nginx.html new file mode 100644 index 0000000..1417261 --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/nginx.html @@ -0,0 +1,171 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+                    
+                
+
+ 保存 + 加入开机启动 + 该配置文件只对该网站有效,修改后重启nginx生效 +
+
+ +
+ +
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/php.html b/app/intapp/controller/soft/tpl/soft/php.html new file mode 100644 index 0000000..8085943 --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/php.html @@ -0,0 +1,415 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + MB + + + 单个请求上传的文件的最大数量 + + + 秒 + + + 秒 + + + MB + + + MB + + + + + + 是否允许将url(如http://或 ftp://)作为文件处理。 + + + + + + 是否允许include/require以文件形式打开url(如http://或 ftp://)。 + + + + 基于套接字的流的默认超时(秒) + + + 保存 +
+
+ +
+ + + + + + + + + + 允许创建的最大子进程数 + + + + 起始进程数(服务启动后初始进程数量) + + + + 最小空闲进程数(清理空闲进程后的保留数量) + + + + 最大空闲进程数(当空闲进程达到此值时清理) + + + 保存 + 加入开机启动 +
+
+ +
+ % if config.app['appmode']=='develop': + + % endif + + + + + + + + +
名称说明状态操作
{{item.title}}{{item.describes}} + % if config.app['appmode']=='develop': + {{item.filename}} + % endif + + + + + + 安装 + + + 等待下载 + + + 正在下载 + + + 正在安装 + + + 卸载 + + + 正在卸载... + + % if config.app['appmode']=='develop': + 删除 + % endif +
+
+
+ + + + +
+                
+            
+ 保存 + 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
+
+ + + +
+                
+            
+ 保存 + 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
+
+
+ + + + + + + + + + + + + + + + + + + 添加 + +
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/phpmyadmin.html b/app/intapp/controller/soft/tpl/soft/phpmyadmin.html new file mode 100644 index 0000000..053916a --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/phpmyadmin.html @@ -0,0 +1,90 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + 添加 + +
+
+
+ + + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/redis.html b/app/intapp/controller/soft/tpl/soft/redis.html new file mode 100644 index 0000000..4df6dbd --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/redis.html @@ -0,0 +1,182 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + 绑定IP + + + 端口 + + + 空闲连接超时时间,0表示不断开 + + + 最大连接数 + + + 数据库数量 + + + redis密码,留空代表没有设置密码 + + + MB,最大使用内存,0表示不限制 + + + 保存 + 加入开机启动 +
+
+ + + + +
+                
+            
+ 保存 + 修改后重启redis生效
+
+
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/index/home.html b/app/intapp/controller/soft/tplm/index/home.html new file mode 100644 index 0000000..361a9fb --- /dev/null +++ b/app/intapp/controller/soft/tplm/index/home.html @@ -0,0 +1,297 @@ + + + + +kcweb云管 + + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+ +
+
+ +
+ + +
+
+
+
+
{{item.title}}{{item.edition}}
+
{{item.describes}}
+
+
+
位置:{{item.paths}}{{item.title}}{{item.edition}}
+
+ +
+
+
+ 待安装 + 等待中 + 下载中 + 安装中 + 卸载中 + 正在启动 + 正在停止服务 + + + + 已停止 + 启动 + + + + 客户端 + 客户端 + 服务端 + 服务端 + + + + + + + 运行中 + 停止 + 重启 + + + +
+
+
更新于:{{time_date(item.updtime)}}
+
+
+
+
+ +
+
+ 加载中... +
+
+ 下一页 + 我已到底了 +
+
+
+
+ + + diff --git a/app/intapp/controller/soft/tplm/index/web.html b/app/intapp/controller/soft/tplm/index/web.html new file mode 100644 index 0000000..a38c9cf --- /dev/null +++ b/app/intapp/controller/soft/tplm/index/web.html @@ -0,0 +1,395 @@ + + + + +kcweb云管 + + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+ +
+
+ +
+ + +
+
+
+
+
{{item.title}}
+
运行在负载均衡代理转发器中
+
{{item.describes}}
+ php伪静态配置 +
+
+ + 运行中 + + + 已停止 + +
+
+
+
+ {{item1}} +
+
+
{{time_date(item.updtime)}}
+
+
+
+
+ +
+
+ 加载中... +
+
+ 下一页 + 暂无数据 + 我已到底了 +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+ 添加响应 + 自定义配置:自定义响应或自定义错误页面 +
+ +
+ +
+
+ +
+
+ + +
+
+ +
+
+ 添加负载均衡信息 + nginx负载均衡是一个代理均衡转发器 +
+
+ 修改 + 添加 +
+
+
+
+ +
+ Let's Encrypt证书夹 +
+
+ 您已配置Let's证书
+ ssl_certificate :{{admin.ssl_certificate}}
+ ssl_certificate_key :{{admin.ssl_certificate_key}}
+
+
+ + 保存 + + + + + +
fewaf
+
+ +
+ +
+
+
+ + + diff --git a/app/intapp/controller/soft/tplm/soft/frp.html b/app/intapp/controller/soft/tplm/soft/frp.html new file mode 100644 index 0000000..c137b73 --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/frp.html @@ -0,0 +1,250 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+ + + + + 重启 + 停止 + + 保存 + + + + + + +
+ 重启 + 停止 + + + + 这是服端监听的地址 + + + + 这是服端监听的端口 + + + + 这是upd监听的端口 + + + + 这是kcp监听的端口 + + + + 这是http监听的端口 + + + + 这是https监听的端口 + + + + 这是dashboard监听的ip地址 + + + + 这是dashboard监听的端口 + + + + 这是dashboard监听的用户名 + + + + 这是dashboard监听的密码 + + + + 这是frp的验证机制 + + + + 这是frp的验证串的有效时间 + + + + + + + + 日志保持多少天 + + + + + + + + 白名单端口 + + + + 最大值进程数 + + + + + + + + + + + + + + + 保存 + + +
+ +
+ + + 保存 + +
+
+
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/git.html b/app/intapp/controller/soft/tplm/soft/git.html new file mode 100644 index 0000000..ce87f2d --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/git.html @@ -0,0 +1,69 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+
+ +
+ 您可以使用root身份执行以下命令生成ssh密钥

+ +
+
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/kodexplorer.html b/app/intapp/controller/soft/tplm/soft/kodexplorer.html new file mode 100644 index 0000000..6f38ff4 --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/kodexplorer.html @@ -0,0 +1,88 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + 添加 + +
+
+
+ + + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/mongodb.html b/app/intapp/controller/soft/tplm/soft/mongodb.html new file mode 100644 index 0000000..417da13 --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/mongodb.html @@ -0,0 +1,436 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +

可以在终端中执行以下命令创建可以 +

+ WORK_DIR=/data/mongodb
+ mkdir -p $WORK_DIR/key/
+ cd $WORK_DIR/key/
+ openssl rand -base64 756 > mongo.key
+ chmod 600 mongo.key
+
+

+ 保存 +
+
+ +
+ config服务 (注:这是一个config服务) + + + + + + +
+ 通常生产环境每台机器应该只有一个,您可以在其他机器上开启config服务后手动添加到副本集中
+ +
+ 运行中 + 停止服务 + 重启服务 +
+
+ 已停止 + 启动服务 +
+
+ 待初始化 + 初始化 +
+

+
+ 副本集初始化(如果需要,生产环境应该是内网ip而不是127.0.0.1)
+
+ +
+增加副本集示例 +
+mongo --port {{data.configs.server[0]['port']}}
+use admin
+rs.add({_id:1,host:'{{data.get_local_ip}}:27002',priority:2})#增加主机 priority:优先级
+
+删除副本集示例 +
+mongo --port {{data.configs.server[0]['port']}}
+use admin
+rs.remove('{{data.get_local_ip}}:27002')
+
+
+ +
+
+ +
+ configdb: +
示例:configdb = configs/192.168.1.101:27001,192.168.1.102:27001,192.168.1.103:27001,则无法扩展外部服务器
+ 上述ip和端口是已经启动的配置服务,可以是其他机器上的mongodb配置服务 +
+ 路由服务 (注:这是一个路由服务) + + + + + + +
+ +
+
+ 运行中 + 停止服务 + 重启服务 +
+
+ 已停止 + 启动服务 +
+
+ 待初始化 + 初始化 +
+
+
+ 初始化用户
+
+ +
+ 在路由中添加分片,如下示例
+
+mongo --port {{data.mongos.server[0]['port']}}
+use admin
+db.auth('admin','admin')
+sh.addShard("shard1/192.168.1.101:29001,192.168.1.102:29001") #shard1是分片集群id
+sh.status()
+
+
+
+
+ +
+
+ 分片服务名{{indexs+1}}: + + + + + + + +
+ 通常生产环境每台机器应该只有一个,您可以在其他机器上开启分片服务后手动添加到副本集中
+ +
+ 运行中 + 停止服务 + 重启服务 +
+
+ 已停止 + 启动服务 +
+
+ 待初始化 + 初始化 +
+

+
+ 副本集初始化(生产环境应该是内网ip而不是127.0.0.1)
+ +
+
+ +
+
+
+ + + +
+ + + + + + + + + + + + + +
绑定ip端口服务目录
+ + 运行中 + 停止 + + + 已停止 + 启动 + + +
+
+ + 保存 +
+ +
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/mysql.html b/app/intapp/controller/soft/tplm/soft/mysql.html new file mode 100644 index 0000000..3603e82 --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/mysql.html @@ -0,0 +1,203 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ + + + + + + 建议与mysql安装目录分开 + + + + port 监听器端口 + + + + max_connections 最大连接数 + + +
+ max_allowed_packet 最大接受数据的包大小 +
+ +
+ expire_logs_days 日志保留时间(天) +
+ +
+ query_cache_limit 指定单个查询可以使用的缓冲区的大小 +
+ +
+ query_cache_size 查询的缓存大小设置 +
+ +
+ query_cache_type 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 +
+ +
+ wait_timeout 超时等待时间,单位秒,即一个connection在若干秒内无响应 +
+ +
+ thread_cache_size 用于缓存空闲的线程 +
+ +
+ key_buffer_size 用于指定索引缓冲区的大小 +
+
+
+ 保存 + 加入开机启动 +
+ +
+ +
+                        
+                    
+
+ 保存 +
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/nginx.html b/app/intapp/controller/soft/tplm/soft/nginx.html new file mode 100644 index 0000000..1417261 --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/nginx.html @@ -0,0 +1,171 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+                    
+                
+
+ 保存 + 加入开机启动 + 该配置文件只对该网站有效,修改后重启nginx生效 +
+
+ +
+ +
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/php.html b/app/intapp/controller/soft/tplm/soft/php.html new file mode 100644 index 0000000..8085943 --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/php.html @@ -0,0 +1,415 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + MB + + + 单个请求上传的文件的最大数量 + + + 秒 + + + 秒 + + + MB + + + MB + + + + + + 是否允许将url(如http://或 ftp://)作为文件处理。 + + + + + + 是否允许include/require以文件形式打开url(如http://或 ftp://)。 + + + + 基于套接字的流的默认超时(秒) + + + 保存 +
+
+ +
+ + + + + + + + + + 允许创建的最大子进程数 + + + + 起始进程数(服务启动后初始进程数量) + + + + 最小空闲进程数(清理空闲进程后的保留数量) + + + + 最大空闲进程数(当空闲进程达到此值时清理) + + + 保存 + 加入开机启动 +
+
+ +
+ % if config.app['appmode']=='develop': + + % endif + + + + + + + + +
名称说明状态操作
{{item.title}}{{item.describes}} + % if config.app['appmode']=='develop': + {{item.filename}} + % endif + + + + + + 安装 + + + 等待下载 + + + 正在下载 + + + 正在安装 + + + 卸载 + + + 正在卸载... + + % if config.app['appmode']=='develop': + 删除 + % endif +
+
+
+ + + + +
+                
+            
+ 保存 + 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
+
+ + + +
+                
+            
+ 保存 + 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
+
+
+ + + + + + + + + + + + + + + + + + + 添加 + +
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/phpmyadmin.html b/app/intapp/controller/soft/tplm/soft/phpmyadmin.html new file mode 100644 index 0000000..053916a --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/phpmyadmin.html @@ -0,0 +1,90 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + 添加 + +
+
+
+ + + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/redis.html b/app/intapp/controller/soft/tplm/soft/redis.html new file mode 100644 index 0000000..4df6dbd --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/redis.html @@ -0,0 +1,182 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + 绑定IP + + + 端口 + + + 空闲连接超时时间,0表示不断开 + + + 最大连接数 + + + 数据库数量 + + + redis密码,留空代表没有设置密码 + + + MB,最大使用内存,0表示不限制 + + + 保存 + 加入开机启动 +
+
+ + + + +
+                
+            
+ 保存 + 修改后重启redis生效
+
+
+
+ + + \ No newline at end of file -- Gitee From d7c58378db1c6f26057d616c68e8dfc0e31a53a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Thu, 22 Apr 2021 16:36:41 +0800 Subject: [PATCH 07/19] kun --- app/intapp/controller/__init__.py | 3 +- app/intapp/controller/soft/__init__.py | 8 - app/intapp/controller/soft/common/SOFT.py | 248 -------- app/intapp/controller/soft/common/__init__.py | 2 - app/intapp/controller/soft/common/autoload.py | 10 - .../soft/common/file/sqlite/.gitignore | 1 - .../soft/common/file/sqlite/php_exten | Bin 24576 -> 0 bytes app/intapp/controller/soft/common/file/time | 1 - app/intapp/controller/soft/common/model.py | 85 --- app/intapp/controller/soft/frp.py | 138 ----- app/intapp/controller/soft/index.py | 131 ---- app/intapp/controller/soft/install.txt | 1 - app/intapp/controller/soft/mongodb.py | 253 -------- app/intapp/controller/soft/mysql copy.py | 310 ---------- app/intapp/controller/soft/mysql.py | 338 ---------- app/intapp/controller/soft/nginx.py | 419 ------------- app/intapp/controller/soft/page.py | 34 - app/intapp/controller/soft/php.py | 272 -------- app/intapp/controller/soft/redis.py | 71 --- app/intapp/controller/soft/role.txt | 44 -- .../controller/soft/tpl/index/home.html | 430 ------------- app/intapp/controller/soft/tpl/index/web.html | 582 ------------------ app/intapp/controller/soft/tpl/soft/frp.html | 250 -------- app/intapp/controller/soft/tpl/soft/git.html | 69 --- .../controller/soft/tpl/soft/kodexplorer.html | 88 --- .../controller/soft/tpl/soft/mongodb.html | 436 ------------- .../controller/soft/tpl/soft/mysql.html | 257 -------- .../controller/soft/tpl/soft/nginx.html | 171 ----- app/intapp/controller/soft/tpl/soft/php.html | 415 ------------- .../controller/soft/tpl/soft/phpmyadmin.html | 90 --- .../controller/soft/tpl/soft/redis.html | 182 ------ .../controller/soft/tplm/index/home.html | 297 --------- .../controller/soft/tplm/index/web.html | 395 ------------ app/intapp/controller/soft/tplm/soft/frp.html | 250 -------- app/intapp/controller/soft/tplm/soft/git.html | 69 --- .../soft/tplm/soft/kodexplorer.html | 88 --- .../controller/soft/tplm/soft/mongodb.html | 436 ------------- .../controller/soft/tplm/soft/mysql.html | 203 ------ .../controller/soft/tplm/soft/nginx.html | 171 ----- app/intapp/controller/soft/tplm/soft/php.html | 415 ------------- .../controller/soft/tplm/soft/phpmyadmin.html | 90 --- .../controller/soft/tplm/soft/redis.html | 182 ------ 42 files changed, 1 insertion(+), 7934 deletions(-) delete mode 100644 app/intapp/controller/soft/__init__.py delete mode 100644 app/intapp/controller/soft/common/SOFT.py delete mode 100644 app/intapp/controller/soft/common/__init__.py delete mode 100644 app/intapp/controller/soft/common/autoload.py delete mode 100644 app/intapp/controller/soft/common/file/sqlite/.gitignore delete mode 100644 app/intapp/controller/soft/common/file/sqlite/php_exten delete mode 100644 app/intapp/controller/soft/common/file/time delete mode 100644 app/intapp/controller/soft/common/model.py delete mode 100644 app/intapp/controller/soft/frp.py delete mode 100644 app/intapp/controller/soft/index.py delete mode 100644 app/intapp/controller/soft/install.txt delete mode 100644 app/intapp/controller/soft/mongodb.py delete mode 100644 app/intapp/controller/soft/mysql copy.py delete mode 100644 app/intapp/controller/soft/mysql.py delete mode 100644 app/intapp/controller/soft/nginx.py delete mode 100644 app/intapp/controller/soft/page.py delete mode 100644 app/intapp/controller/soft/php.py delete mode 100644 app/intapp/controller/soft/redis.py delete mode 100644 app/intapp/controller/soft/role.txt delete mode 100644 app/intapp/controller/soft/tpl/index/home.html delete mode 100644 app/intapp/controller/soft/tpl/index/web.html delete mode 100644 app/intapp/controller/soft/tpl/soft/frp.html delete mode 100644 app/intapp/controller/soft/tpl/soft/git.html delete mode 100644 app/intapp/controller/soft/tpl/soft/kodexplorer.html delete mode 100644 app/intapp/controller/soft/tpl/soft/mongodb.html delete mode 100644 app/intapp/controller/soft/tpl/soft/mysql.html delete mode 100644 app/intapp/controller/soft/tpl/soft/nginx.html delete mode 100644 app/intapp/controller/soft/tpl/soft/php.html delete mode 100644 app/intapp/controller/soft/tpl/soft/phpmyadmin.html delete mode 100644 app/intapp/controller/soft/tpl/soft/redis.html delete mode 100644 app/intapp/controller/soft/tplm/index/home.html delete mode 100644 app/intapp/controller/soft/tplm/index/web.html delete mode 100644 app/intapp/controller/soft/tplm/soft/frp.html delete mode 100644 app/intapp/controller/soft/tplm/soft/git.html delete mode 100644 app/intapp/controller/soft/tplm/soft/kodexplorer.html delete mode 100644 app/intapp/controller/soft/tplm/soft/mongodb.html delete mode 100644 app/intapp/controller/soft/tplm/soft/mysql.html delete mode 100644 app/intapp/controller/soft/tplm/soft/nginx.html delete mode 100644 app/intapp/controller/soft/tplm/soft/php.html delete mode 100644 app/intapp/controller/soft/tplm/soft/phpmyadmin.html delete mode 100644 app/intapp/controller/soft/tplm/soft/redis.html diff --git a/app/intapp/controller/__init__.py b/app/intapp/controller/__init__.py index cace474..90b3d04 100644 --- a/app/intapp/controller/__init__.py +++ b/app/intapp/controller/__init__.py @@ -9,5 +9,4 @@ def error(e,data): header={"Content-Type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"*"} header['Location']="/intapp/index/plug/index/intapp/"+plug return '{"code":1,"msg":"您访问的地址不存在","data":"'+str(e)+'"}','302 Found',header -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/soft/__init__.py b/app/intapp/controller/soft/__init__.py deleted file mode 100644 index f7a8da3..0000000 --- a/app/intapp/controller/soft/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from . import index -from . import page -from . import nginx -from . import mysql -from . import redis -from . import mongodb -from . import frp -from . import php \ No newline at end of file diff --git a/app/intapp/controller/soft/common/SOFT.py b/app/intapp/controller/soft/common/SOFT.py deleted file mode 100644 index 54ad594..0000000 --- a/app/intapp/controller/soft/common/SOFT.py +++ /dev/null @@ -1,248 +0,0 @@ -# -*- coding: utf-8 -*- -from .model import * -class SOFT: - def softlist(kw,pagenow,pagesize): - "软件列表" - if config.app['appmode']=='develop': - where="1=1" - else: - where="platform='"+get_sysinfo()['uname'][0]+"'" - if kw: - where+=" and title LIKE '%"+kw+"%' or describes LIKE '%"+kw+"%'" - lists=sqlite("soft",model_intapp_soft_path).where(where).page(pagenow,pagesize).select() - if len(lists) < 1: - SOFT.updatesoftlist() - lists=sqlite("soft",model_intapp_soft_path).where(where).page(pagenow,pagesize).select() - if 'Linux' in get_sysinfo()['platform']: - i=0 - for k in lists: - if k['status'] == 0 and k['platform']=='Linux': #检查软件是否已经安装 - if (os.path.exists(k['paths']+k['title']+k['edition'])) : - lists[i]['status']=4 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':lists[i]['status']}) - if (k['status'] == 10 or k['status'] == 4) and k['platform']=='Linux': #检查软件是否在运行中 - if 'nginx' in k['title'] : - if not get_process_id('nginx'): - if k['status'] == 10: - lists[i]['status']=4 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 - else: - if k['status'] == 4: - lists[i]['status']=10 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 - elif 'redis' in k['title']: - if not get_process_id('redis'): - if k['status'] == 10: - lists[i]['status']=4 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 - else: - if k['status'] == 4: - lists[i]['status']=10 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 - elif 'mysql' in k['title']: - if not os.path.isfile(k['paths']+"/mysql"+k['edition']+"/tmp/mysqld.pid"): - if k['status'] == 10: - lists[i]['status']=4 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 - else: - if k['status'] == 4: - lists[i]['status']=10 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 - elif 'php5' in k['title']+k['edition'] or 'php7' in k['title']+k['edition']: - title=k['title']+k['edition'] - # print("php",title,title.replace(".", "")+"-fpm") - if not get_process_id(title): - if k['status'] == 10: - lists[i]['status']=4 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 - else: - if k['status'] == 4: - lists[i]['status']=10 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 - elif 'tomcat' in k['title']: - if not get_process_id('tomcat'): - if k['status'] == 10: - lists[i]['status']=4 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 - else: - if k['status'] == 4: - lists[i]['status']=10 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 - i+=1 - count=sqlite("soft",model_intapp_soft_path).where(where).count() - data=return_list(lists,count,pagenow,pagesize) - return data - def updatesoftlist(): - "更新软件列表" - http=Http() - sqlite("soft",model_intapp_soft_path).where("1=1").delete() - def openkcweb(pagenow=1,pagesize=20): - http.openurl(config.domain['kcwebapi']+"/pub/soft_list","GET",params={ - "pagenow":pagenow,"pagesize":pagesize - }) - res=json_decode(http.get_text) - lists=[] - if res['code']==0: - for k in res['data']['lists']: - k['status']=0 - k['msg']='' - k['addtime']=times() - lists.append(k) - sqlite("soft",model_intapp_soft_path).insert(lists) - if pagenow "+arr['paths']+arr['title']+arr['edition']+"/out.log 2>&1 &",name="redis服务",icon=arr['icon']) - return True - elif 'mysql' in arr['title']: - if os.path.isfile(arr['paths']+arr['title']+arr['edition']+"/support-files/mysql.server"): - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":"安装成功"}) - system_start.insert_Boot_up("mysqld"+(arr['edition'].replace(".", ""))+"server start",name="mysqld"+(arr['edition'].replace(".", ""))+"服务",icon=arr['icon']) #edition - return True - elif 'frp' == arr['title']: - if os.path.isfile(arr['paths']+arr['title']+arr['edition']+"/frps") and os.path.isfile(arr['paths']+arr['title']+arr['edition']+"/frpc"): - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":"安装成功"}) - return True - else: - if os.path.exists(arr['paths']+arr['title']+arr['edition']): - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":"安装成功"}) - if 'tomcat' == arr['title']: - jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() - system_start.insert_Boot_up(cmd="export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition']+" && /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin/startup.sh start",name="tomcat服务",icon=arr['icon']) - return True - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"安装失败,目录不存在"+arr['paths']+arr['title']+arr['edition']}) - else: - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"安装失败"}) - else: - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"下载失败"}) - except Exception as e: - sqlite('soft',model_intapp_soft_path).where('id',id).update({'status':0,'msg':'安装失败'+str(e)}) - def start(id): - "启动软件服务" - arr=sqlite("soft",model_intapp_soft_path).where("id",id).find() - if arr['platform']=='Linux': ###############################LINUX - if 'nginx' == arr['title']: - os.system("nginx") - elif 'php' == arr['title']: - titleedition=arr['title']+arr['edition'] - fpmname=titleedition.replace(".", "")+"-fpm" - os.system(fpmname+" -c "+arr['paths']+arr['title']+arr['edition']+"/bin/php.ini -R") - # print("php启动",fpmname+" -c "+arr['paths']+arr['title']+arr['edition']+"/bin/php.ini -R") - elif 'redis' == arr['title']: - # os.system("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > log 2>&1 &") - os.system("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > "+arr['paths']+arr['title']+arr['edition']+"/out.log 2>&1 &") - elif 'mysql' == arr['title']: - if '5.6' == arr['edition']: - os.system("mysqld56server start") - elif '5.7' == arr['edition']: - os.system("mysqld57server start") - elif '8.0' == arr['edition']: - os.system("mysqld80server start") - elif 'tomcat' == arr['title']: - jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() - os.system("export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition'] +" && /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin/startup.sh start") - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":9,"msg":"","updtime":times()}) - time.sleep(10) - else: - os.system("cd "+arr['paths']+arr['title']+arr['edition']+" && bash start.sh") - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":10,"msg":"运行中"}) - else: - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":""}) - def stop(id): - arr=sqlite("soft",model_intapp_soft_path).where("id",id).find() - if arr['platform']=='Linux': ###############################LINUX - if 'nginx' == arr['title']: - os.system("pkill nginx") - elif 'php' == arr['title']: - titleedition=arr['title']+arr['edition'] - fpmname=titleedition.replace(".", "")+"-fpm" - os.system("pkill -9 "+fpmname) - elif 'redis' == arr['title']: - os.system("pkill -9 redis") - elif 'mysql' == arr['title']: - if '5.6' == arr['edition']: - os.system("mysqld56server stop") - elif '5.7' == arr['edition']: - os.system("mysqld57server stop") - elif '8.0' == arr['edition']: - os.system("mysqld80server stop") - elif 'tomcat' == arr['title']: - jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() - os.system("export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition'] +" && cd /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin && ./shutdown.sh") - # os.system("pkill -9 tomcat") - time.sleep(1) - elif 'mongo' == arr['title']: - os.system("pkill mongo") - else: - os.system("cd "+arr['paths']+arr['title']+arr['edition']+" && bash stop.sh") - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":""}) - def uninstall(id): - try: - arr=sqlite("soft",model_intapp_soft_path).where("id",id).find() - if arr['platform']=='Linux': ###############################LINUX - os.system("rm -rf "+arr['paths']+arr['title']+arr['edition']) - startpath="/usr/bin/" - if 'nginx' == arr['title']: - system_start.del_Boot_up("nginx") - os.system("pkill -9 nginx") - model_intapp_menu.delete(title="网站管理",sort=9000) - os.system("rm -rf "+startpath+"nginx") - elif 'redis' == arr['title']: - system_start.del_Boot_up("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > "+arr['paths']+arr['title']+arr['edition']+"/out.log 2>&1 &") - os.system("rm -rf "+startpath+"redis-server") - elif 'php' == arr['title']: - titleedition=arr['title']+arr['edition'] - fpmname=titleedition.replace(".", "")+"-fpm" - system_start.del_Boot_up(fpmname+" -c "+arr['paths']+arr['title']+arr['edition']+"/bin/php.ini -R") - os.system("rm -rf "+startpath+fpmname) - elif 'mysql' == arr['title']: - system_start.del_Boot_up("mysqld"+(arr['edition'].replace(".", ""))+"server start") - os.system("rm -rf "+startpath+"mysqld"+(arr['edition'].replace(".", ""))+" && rm -rf "+startpath+"mysql"+(arr['edition'].replace(".", ""))) - elif 'mongodb' == arr['title']: - system_start.del_Boot_up("mongo",True) - os.system("pkill -9 mongo") - os.system("rm -rf /data/mongodb") - elif 'frp' == arr['title']: - system_start.del_Boot_up("frps",True) - system_start.del_Boot_up("frpc",True) - os.system("pkill -9 frps") - os.system("pkill -9 frpc") - else: - if 'tomcat' == arr['title']: - jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() - system_start.del_Boot_up("export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition']+" && /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin/startup.sh start") - os.system("cd /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin && ./shutdown.sh") - if os.path.exists(arr['paths']+arr['title']+arr['edition']): - sqlite('soft',model_intapp_soft_path).where('id',id).update({'status':4,'msg':'卸载失败'}) - return - except Exception as e: - sqlite('soft',model_intapp_soft_path).where('id',id).update({'status':4,'msg':'卸载失败'+str(e)}) - else: - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"已卸载"}) \ No newline at end of file diff --git a/app/intapp/controller/soft/common/__init__.py b/app/intapp/controller/soft/common/__init__.py deleted file mode 100644 index 8879824..0000000 --- a/app/intapp/controller/soft/common/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# -*- coding: utf-8 -*- -from .SOFT import * \ No newline at end of file diff --git a/app/intapp/controller/soft/common/autoload.py b/app/intapp/controller/soft/common/autoload.py deleted file mode 100644 index c4bee80..0000000 --- a/app/intapp/controller/soft/common/autoload.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -from app.intapp.common import * -import subprocess -def get_process_id(name): - try: - child = subprocess.Popen(['pgrep', '-f', name],stdout=subprocess.PIPE, shell=False) - response = child.communicate()[0] - return [int(pid) for pid in response.split()] - except: - return [] diff --git a/app/intapp/controller/soft/common/file/sqlite/.gitignore b/app/intapp/controller/soft/common/file/sqlite/.gitignore deleted file mode 100644 index f3c316e..0000000 --- a/app/intapp/controller/soft/common/file/sqlite/.gitignore +++ /dev/null @@ -1 +0,0 @@ -soft \ No newline at end of file diff --git a/app/intapp/controller/soft/common/file/sqlite/php_exten b/app/intapp/controller/soft/common/file/sqlite/php_exten deleted file mode 100644 index 947090a468579685c0d9058dbd71817876cd9b6e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 24576 zcmeHPeQZ-)pm~U>pVC01x>inNzdYabyT5zhJ@?#m-fMcH-V<~RE?--VEhv~}b7XS4>={9j$z;tSDiHdT z!<#(%0si9W?|U`NDjxZx4$e~O*UI$W@Qb||1B?O20AqkLz!+c*Fa{U{i~+^~W8jC! zz!rt7c-b=fwxDgh*BN-#3z6i@0q3jj&Q^Q+N9FoPOHH#yXs%gTZxPbYUD9f6ahAh3 zm+ozq7ZjJ3$@eddx9NBLUv};aI$Kk36nC_fIxH;lIE1=}X3GXkqtLLqS!mc=UoUKF ztlL!6xJ`K8vQ4Pj+Pt~00lvM-($HKk_$N5OTnKuCUZ?P4P2>8FHH}M*rmCevt>xL8 zt@X{q;>D?U%LRusU~ltmcLq}DnpUow1a_p(GFF;a zOrpx>a0ETjU^)@yLc4$B|18Z1t5X=hM%z;v{%iPJ*RN~fJNW{wTXS7gqJCFh$Q|Go z6ntDztNLsHKk{qy_A0+p`IRdbgNkMH({i)y53+3&8m>#w%H$6(nsK;&tP93(kTq>h&g0{b*xE4rz<_h|AsSKI}9iO2PT`4Fk z?%;?TyVmA(cmm?t!O_7k@xXrZ(#g@mUyI$BBb{V)V87Ve6Fs%>d1uFyFWS8A&d7kBH!3Cjj)Mud0ZSN#@bdxBqeRZ_Mm&L?KA+bq4)2XzI{(EUA`V=Q zz1InEZhmw!vgbnVwNNzlMs(=R%{`|^!|#d1CnCqY1XG2nqB45;P~^ z#7l3*j_i%TOJMNCy%)tped7Krqk|tMhqM1uo{do|wuE0VP!e zm{Jr{T?}NFk`0MVSdG)7r`6@V8&a(6_hNTXr03x1&{ZI3Q{5&Dm{x>b2Dq`;&%?zK z{nf<;nPOizTqnj2@E4K*P$!1@M(Ax>AD~ux_YlmHbaKv z0Iad07z$Aq!GITfIHE;c-Qh?fOK1XoVBO-mebHkF#M2{U=zTQ2_#6!rNOrcj!vP4c zqkxa#aGG{M3Sf$0x;7vfdwbhBQ90;1wg)4!0>%BXRFiX;$CcLctZV?=gMJO7xE=yc z)YYkT>gp;Ju5RcP(DRAE5cE)2r>1Txm%XBGg0^!gt~t`4<S5~YVcX9*78XF+Qph4PNlE|m#{%@?Y{%>6Qpo#h%E{8q`6~)7={x3n#m;OA^ zLwycM{X^P_WHtV@P0)4&#if+?EQdZPK42JL^?!=ep#VK}X5}9I%nIs3?G+Tl$w4=D zcignQyOppS%YO=f<;}y~yxj1W41U;)F~AsL3@`>51B?O20AqkLz!+c*Fa{U{jDa5u z13I~~Ob(mkiMopCbSk%OZho!I(60Yh|E6BZS^i(;&byV`pkn#|Oe-5${vWFfq?ve@ z|DXCk|LTgn^8YHgyb1O_S^j^j)kl!HOjanc{Qte{v?_%=^8alt|9{`5ZY=+wajDxR zvn0#^LqR0kU8YrTEdP%sgHYr)i9xaa|6N65S>=CO{y&r0faU+QE*xk1{{Y5S;0h9@ z2*;ol;h0YG7g?#yD$`V{FKD~DTb#e(?*%WYZmM>w42B;4XZi-+W!(b)x7z<`=jQLp zyPbD5uSEG9Wu2l(-Yxs5%&NF?uZzXCV_qaTIv%K-{4H`dNjxiP}|0EOMPHKqH}*sd+xwPkm0{jl!Z zf_3X-6VJRI6)+{!%3$q-uMAGO13S#W_UXGlic~FzHC_ox-rb>@t#^0e?Y^m77(-3g zSg6Up2*!sl>NL4s)ESeDx=<}>f}16uKvPI2OEgo9U$R&t8OOtykP!eG$^3=V@I^Dz z;fs-mFQGDkS4NaS1-@wbqM63<#TXA?LOMX9Bh`;f!xs$=4$_vcvnG5oO2U`n?;xx6 zo%<(J3(svZVN3=S!(*Un4D0{r6li1yi~djgr*(b0jr?_fuC_}vrm?F3tzN_R7W}JV z7o5Oei~+^~V}LQh82C{#;C&94dhlcde4dEb=XbUS0$$iG|Ne*8U~)BizO-;D?J#`A zh5oJ5A(W0f)RugDiEcV#40tHQwO^u;s*Tc>zi#%f{8x;x{I5ZHbj?n<4L}>+xYNzR z#vQV_8HH3mD`k{Gw_%t5HkrR(8b9$f9Y2|A{1lD?yeLtw1HNed#7|@VWKN`iU>iRCIjOFZ z#!vigkDttv_$dtcc85RpKLa$<)CEt|3~BLS7I8UPdGbMHpe=;rss@cTDZ}S9bphSO z)J6DrD1`etD55hUKLazM8DPAPLin`+g{Cg}8A@FsoI@xbKLa$>qw>??QBn0y6jJrH Y)EB_w;ekF6EDOUmjr)RdBS3HbKNvJ$VgLXD diff --git a/app/intapp/controller/soft/common/file/time b/app/intapp/controller/soft/common/file/time deleted file mode 100644 index 818b173..0000000 --- a/app/intapp/controller/soft/common/file/time +++ /dev/null @@ -1 +0,0 @@ -1599551060 \ No newline at end of file diff --git a/app/intapp/controller/soft/common/model.py b/app/intapp/controller/soft/common/model.py deleted file mode 100644 index 87d168d..0000000 --- a/app/intapp/controller/soft/common/model.py +++ /dev/null @@ -1,85 +0,0 @@ -# -*- coding: utf-8 -*- -from .autoload import * -# 初始化数据库 -model_intapp_soft_path=os.path.split(os.path.realpath(__file__))[0]+"/file/sqlite/soft" -class modelsqlitesoft(model.model): - config={'type':'sqlite'} - config={'type':'sqlite','db':model_intapp_soft_path} - model.dbtype.conf=config -class model_intapp_soft(modelsqlitesoft): - "软件表" - table="soft" - fields={ - "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 - "icon":model.dbtype.varchar(LEN=128,DEFAULT=''), #图标 - "title":model.dbtype.varchar(LEN=128,DEFAULT=''), #软件名称 - "edition":model.dbtype.varchar(LEN=128,DEFAULT=''), #软件版本 - "shell":model.dbtype.varchar(LEN=128,DEFAULT=''), #shell 命令 - "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件描述 - "paths":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件安装目录 卸载软件时用到 - "status":model.dbtype.int(LEN=2,DEFAULT=0), #0未安装 1等待中 2下载中 3安装中 4已安装 5卸载中 9启动中... 10运行中 11正在停止服务... - "filename":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件源文件地址 - "platform":model.dbtype.varchar(LEN=256,DEFAULT='Linux'),#支持的系统 - 'msg':model.dbtype.varchar(LEN=1024,DEFAULT=''), #最后一次执行结果信息 - "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 - "updtime":model.dbtype.int(LEN=11,DEFAULT=0) #更新时间 - } -try: - sqlite('soft',model_intapp_soft_path).find() -except: - model_soft=model_intapp_soft() - model_soft.create_table() - -class model_intapp_web(modelsqlitesoft): - "网站列表" - table="web" - fields={ - "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 - "domain":model.dbtype.varchar(LEN=512,DEFAULT=''), #域名 - "port":model.dbtype.varchar(LEN=8,DEFAULT='80'), #端口 - "icon":model.dbtype.varchar(LEN=128,DEFAULT=''), #图标 - "title":model.dbtype.varchar(LEN=128,DEFAULT=''), #名称 - "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), #描述 - "status":model.dbtype.int(LEN=1,DEFAULT=1), #网站状态 0停止 1开启 - "path":model.dbtype.varchar(LEN=256,DEFAULT=''), #网站目录 - "client_max_body_size":model.dbtype.int(LEN=11,DEFAULT=20),#上传限制 - "webtpl":model.dbtype.varchar(LEN=256,DEFAULT=''), #nginx配置文件模板名 - "servers":model.dbtype.varchar(LEN=256,DEFAULT=''), #服务器名字 nginx名字 - "only":model.dbtype.varchar(LEN=32,DEFAULT=''), #唯一字段 - "balancing":model.dbtype.varchar(LEN=2048,DEFAULT=''), #负载均衡服务器信息 - "proxy_set_header":model.dbtype.varchar(LEN=1024,DEFAULT=''),#自定义转发请求头 - "header":model.dbtype.varchar(LEN=1024,DEFAULT=''),#自定义响应头 - "ssl_certificate":model.dbtype.varchar(LEN=1024,DEFAULT=''), - "ssl_certificate_key":model.dbtype.varchar(LEN=1024,DEFAULT=''), - "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 - "updtime":model.dbtype.int(LEN=11,DEFAULT=0) #更新时间 - } -try: - sqlite('web',model_intapp_soft_path).find() -except: - model_intapp_web=model_intapp_web() - model_intapp_web.create_table() - -model_intapp_soft_php_exten_path=os.path.split(os.path.realpath(__file__))[0]+"/file/sqlite/php_exten" -class model_intapp_php_exten(model.model): - "php扩展表" - config={'type':'sqlite'} - config={'type':'sqlite','db':model_intapp_soft_php_exten_path} - model.dbtype.conf=config - table="php_exten" - fields={ - "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 - "pid":model.dbtype.int(LEN=11), #软件列表id - "title":model.dbtype.varchar(LEN=128,DEFAULT=''), #扩展名称 - "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), #扩展描述 - "status":model.dbtype.int(LEN=2,DEFAULT=0), #0未安装 1等待中 2下载中 3安装中 4已安装 5卸载中 - "filename":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件源文件地址 - 'msg':model.dbtype.varchar(LEN=1024,DEFAULT=''), #最后一次执行结果信息 - "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 - "updtime":model.dbtype.int(LEN=11,DEFAULT=0) #更新时间 - } -try: - sqlite('php_exten',model_intapp_soft_php_exten_path).find() -except: - model_intapp_php_exten=model_intapp_php_exten() - model_intapp_php_exten.create_table() \ No newline at end of file diff --git a/app/intapp/controller/soft/frp.py b/app/intapp/controller/soft/frp.py deleted file mode 100644 index 087feb0..0000000 --- a/app/intapp/controller/soft/frp.py +++ /dev/null @@ -1,138 +0,0 @@ -from .common import * -dar="/usr/local/frp/frp0.30" -# pkill frps && cd /usr/local/frp/frp0.30 && ./frps -c frps_full.ini & -def get_server(): - server={ - 'conf':file_get_content(dar+"/frps_full.ini"), - 'base':json_decode(file_get_content(dar+"/frps_full.conf")), - 'dar':dar - } - return successjson(server) -def run_status(): - "获取运行状态" - data={"frpc":0,"frps":0} - if get_process_id('frps'): - data['frps']=1 - if get_process_id('frpc'): - data['frpc']=1 - return successjson(data) -def restart(types='frps'): - "重启" - G.setadminlog="重启frp" - if not os.path.exists(dar+"/log"): - os.makedirs(dar+"/log") - if types=='frps': - cmd="cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &" - os.system("pkill -9 frps") - system_start.del_Boot_up(cmd) - time.sleep(1) - os.system(cmd) - time.sleep(1) - if not get_process_id('frps'): - return errorjson(msg="启动失败,请检查配置") - system_start.insert_Boot_up(cmd=cmd,name="frps服务端") - elif types=='frpc': - cmd="cd "+dar +" && ./frpc -c frpc.ini &" - os.system("pkill frpc") - system_start.del_Boot_up(cmd) - time.sleep(1) - os.system(cmd) - time.sleep(1) - if not get_process_id('frpc'): - return errorjson(msg="启动失败,请检查配置") - system_start.insert_Boot_up(cmd=cmd,name="frpc客户端") - return successjson() -def stop(types='all'): - "停止" - G.setadminlog="停止frp服务" - if types=='frps': - system_start.del_Boot_up("cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") - os.system("pkill -9 frps") - elif types=='frpc': - system_start.del_Boot_up("cd "+dar +" && nohup ./frpc -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") - os.system("pkill -9 frpc") - else: - system_start.del_Boot_up("cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") - system_start.del_Boot_up("cd "+dar +" && nohup ./frpc -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") - os.system("pkill -9 frps") - os.system("pkill -9 frpc") - return successjson() -def upd_server(types='ini'): - G.setadminlog="修改frp配置" - server=request.get_json() - if types=='ini': - file_set_content(dar+"/frps_full.ini",server['conf']) - elif types=='base': - base=server['base'] - f = open(dar+"/frps_full.ini") - con='' - while True: - line = f.readline() - if not line: - break - elif 'bind_addr = ' in line: - line="bind_addr = "+base['bind_addr']+"\n" - elif 'bind_port = ' in line: - line="bind_port = "+base['bind_port']+"\n" - elif 'bind_udp_port = ' in line: - line="bind_udp_port = "+base['bind_udp_port']+"\n" - elif 'kcp_bind_port = ' in line: - line="kcp_bind_port = "+base['kcp_bind_port']+"\n" - elif 'vhost_http_port = ' in line: - line="vhost_http_port = "+base['vhost_http_port']+"\n" - elif 'vhost_https_port = ' in line: - line="vhost_https_port = "+base['vhost_https_port']+"\n" - elif 'dashboard_addr = ' in line: - line="dashboard_addr = "+base['dashboard_addr']+"\n" - elif 'dashboard_port = ' in line: - line="dashboard_port = "+base['dashboard_port']+"\n" - elif 'dashboard_user = ' in line: - line="dashboard_user = "+base['dashboard_user']+"\n" - elif 'dashboard_pwd = ' in line: - line="dashboard_pwd = "+base['dashboard_pwd']+"\n" - elif 'log_level = ' in line: - line="log_level = "+base['log_level']+"\n" - elif 'log_max_days = ' in line: - line="log_max_days = "+base['log_max_days']+"\n" - elif 'disable_log_color = ' in line: - line="disable_log_color = "+base['disable_log_color']+"\n" - elif 'token = ' in line: - line="token = "+base['token']+"\n" - elif 'allow_ports = ' in line: - line="allow_ports = "+base['allow_ports']+"\n" - elif 'max_pool_count = ' in line: - line="max_pool_count = "+base['max_pool_count']+"\n" - elif 'max_ports_per_client = ' in line: - line="max_ports_per_client = "+base['max_ports_per_client']+"\n" - elif 'subdomain_host = ' in line: - line="subdomain_host = "+base['subdomain_host']+"\n" - elif 'tcp_mux = ' in line: - line="tcp_mux = "+base['tcp_mux']+"\n" - con=con+line - f.close() - file_set_content(dar+"/frps_full.ini",con) - file_set_content(dar+"/frps_full.conf",json_encode(base)) - os.system("pkill frps") - time.sleep(1) - os.system("cd "+dar +" && ./frps -c frps_full.ini &") - time.sleep(1) - if not get_process_id('frps'): - return errorjson(msg="启动失败,请检查配置") - return successjson() -def get_client(): - client={ - 'conf':file_get_content(dar+"/frpc.ini"), - 'base':json_decode(file_get_content(dar+"/frpc.conf")) - } - return successjson(client) -def upd_client(type='ini'): - G.setadminlog="修改frp客户端配置" - server=request.get_json() - file_set_content(dar+"/frpc.ini",server['conf']) - os.system("pkill frpc") - time.sleep(1) - os.system("cd "+dar +" && ./frpc -c frpc.ini &") - time.sleep(1) - if not get_process_id('frpc'): - return errorjson(code=1,msg="启动失败,请检查配置") - return successjson() \ No newline at end of file diff --git a/app/intapp/controller/soft/index.py b/app/intapp/controller/soft/index.py deleted file mode 100644 index e48c782..0000000 --- a/app/intapp/controller/soft/index.py +++ /dev/null @@ -1,131 +0,0 @@ -from .common import * -def index(): - kw=request.args.get("kw") - if not kw: - kw='' - lefttext=request.args.get('lefttext') - if not lefttext: - lefttext='应用' - lefturl=request.args.get('lefturl') - if not lefturl: - lefturl='myapp' - lefttype=request.args.get('lefttype') - if not lefttype: - lefttype='lefturl' - if sysisphone(): - return response.tpl("../tplm/index/home",kw=kw,lefttext=lefttext,lefturl=lefturl,lefttype=lefttype) - else: - return response.tpl('index/home',kw=kw) -def gettitle(title,edition): - "获取软件信息" - return successjson(sqlite('soft',model_intapp_soft_path).where("title='"+title+"' and edition='"+edition+"' and platform='"+get_sysinfo()['uname'][0]+"' and status >=4").find()) -def softlist(): - kw=request.args.get("kw") - pagenow=int(request.args.get("pagenow")) - pagesize=int(request.args.get("pagesize")) - return successjson(SOFT.softlist(kw,pagenow,pagesize)) -def updatesoftlist(): - "更新软件列表" - G.setadminlog="更新软件列表" - SOFT.updatesoftlist() - return successjson() -def getstatus(id): - "获取软件状态和描述" - return successjson(sqlite("soft",model_intapp_soft_path).field("status,msg").where("id",id).find()) -def insert(id): - "安装软件" - G.setadminlog="安装软件" - tar=sqlite('soft',model_intapp_soft_path).where("id",id).field("title,edition").find() - title=tar['title'] - if 'nginx' == title: - ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','nginx'),'and',('status','gt',0)]).find() - if ass: - return errorjson(msg="您已安装其他nginx版本,卸载其他nginx版本后可安装此版本") - if 'mysql' == title: - if "5.7" == tar['edition']: - ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','mysql'),'and',('status','gt',0),'and',('edition','eq','8.0')]).find() - if ass: - return errorjson(msg="您已安装8.0版本mysql") - if "8.0" == tar['edition']: - ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','mysql'),'and',('status','gt',0),'and',('edition','eq','5.7')]).find() - if ass: - return errorjson(msg="您已安装5.7版本mysql") - elif 'jdk' == title: - ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','jdk'),'and',('status','gt',0)]).find() - if ass: - return errorjson(msg="您已安装其他jdk版本,卸载其他jdk版本后可安装此版本") - elif 'tomcat' == title: - ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','jdk'),'and',('status','gt',0)]).find() - if not ass: - return errorjson(msg="tomcat依赖于jdk,请先安装jdk") - elif 'kodexplorer' in title or 'phpmyadmin' in title: - if not sqlite('soft',model_intapp_soft_path).where([('title','like','%php%'),'and',('status','egt','4')]).count() or not sqlite('soft',model_intapp_soft_path).where([('title','like','%nginx%'),'and',('status','egt','4')]).count(): - return errorjson(msg="先安装nginx和php") - if 'phpmyadmin' in title: - if not sqlite('soft',model_intapp_soft_path).where([('title','like','%mysql%'),'and',('status','egt','4')]).count() or not sqlite('soft',model_intapp_soft_path).where([('title','like','%nginx%'),'and',('status','egt','4')]).count(): - return errorjson(msg="先安装mysql") - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":1,"msg":"安装中"}) - Queues.insert(target=SOFT.insert,args=(id,),title="安装软件:"+title) - return successjson() -def start(id): - "启动软件" - title=request.args.get('title') - if title=='tomcat': - Queues.insert(SOFT.start,args=(id,),title='启动tomcat服务') - time.sleep(2) - else: - SOFT.start(id) - return successjson() -def stop(id): - "停止软件" - SOFT.stop(id) - return successjson() -def restartnginx(): - """平滑重启nginx""" - os.system("nginx -s reload") - return successjson() - -def uninstall(id): - "卸载软件" - # title=request.args.get("title") - title=sqlite('soft',model_intapp_soft_path).where("id",id).field("title").find()['title'] - if 'nginx' == title: - sqlite("web",model_intapp_soft_path).where("1=1").update({"status":0}) - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":5,"msg":"卸载中"}) - Queues.insert(target=SOFT.uninstall,args=(id,),title="卸载软件:"+title) - return successjson() - - -def gitssh(): - 'gitssh公钥' - try: - data=file_get_content("/root/.ssh/id_rsa.pub") - except: - data='' - return successjson(data) - - - -def add(): - "添加内容" - try: - data=request.get_json() - data.update(updtime=times(),addtime=times()) - # print(data) - sqlite('software',config.sqlitesoftware).insert(data) - except: - return errorjson(msg="失败") - else: - return successjson() -def update(id=0): - "更新内容" - data=request.get_json() - if not id: - id=data['id'] - try: - data.pop('updtime') - data.pop('addtime') - except:pass - else: - sqlite('software',config.sqlitesoftware).where("id",id).update(data) - return successjson() \ No newline at end of file diff --git a/app/intapp/controller/soft/install.txt b/app/intapp/controller/soft/install.txt deleted file mode 100644 index f75c93b..0000000 --- a/app/intapp/controller/soft/install.txt +++ /dev/null @@ -1 +0,0 @@ -oss2>=2.12.0 \ No newline at end of file diff --git a/app/intapp/controller/soft/mongodb.py b/app/intapp/controller/soft/mongodb.py deleted file mode 100644 index cc24fb8..0000000 --- a/app/intapp/controller/soft/mongodb.py +++ /dev/null @@ -1,253 +0,0 @@ -from .common import * -import base64 -WORK_DIR="/data/mongodb" -# if not os.path.exists(WORK_DIR): -# os.system("mkdir -p "+WORK_DIR) -def get_config(id): - '获取mongodb页面配置' - try: - data=json_decode(file_get_content(WORK_DIR+"/config.conf")) - except: - data={} - if not data: - data={} - if os.path.isfile(WORK_DIR+"/key/mongo.key"): - key=file_get_content(WORK_DIR+"/key/mongo.key") - else: - key='' - data['key']=key - data['get_local_ip']=get_local_ip() - data['WORK_DIR']=WORK_DIR - try: - data['configlist']=json_decode(file_get_content(WORK_DIR+"/serverconfig.conf")) - except: - data['configlist']={} - return successjson(data) -def upd_config(id): - '修改mongodb页面配置' - G.setadminlog="修改mongodb页面配置" - data=request.get_json() - os.system("mkdir -p "+WORK_DIR+"/key") - f=open(WORK_DIR+"/key/mongo.key","w") - f.write(data['key']) - f.close() - os.system("chmod 600 "+WORK_DIR+"/key/mongo.key") - data['key']='' - file_set_content(WORK_DIR+"/config.conf",json_encode(data)) - return successjson() - -def start_config(types='restart'): - '启动/停止config服务' - G.setadminlog="启动/停止config服务" - data=request.get_json() - data['key']='' - os.system("mkdir -p "+WORK_DIR+"/conf") - f=open(WORK_DIR+"/conf/config.conf","w") - f.write("logappend=true\n"+ - "fork=true\n"+ - "maxConns=5000\n"+ - "replSet=configs\n"+ - "keyFile="+WORK_DIR+"/key/mongo.key\n"+ - "configsvr=true") - f.close() - os.system("chmod 777 "+WORK_DIR+"/conf/config.conf") - # os.system("chmod 600 "+WORK_DIR+"/key/mongo.key") - i=1 - for k in data['configs']['server']: - os.system("mkdir -p "+WORK_DIR+"/config"+str(i)+"/data") - i+=1 - if types=='restart' or types=='stop': #停止服务 - i=1 - for k in data['configs']['server']: - pid=file_get_content(WORK_DIR+"/config"+str(i)+"/db.pid") - os.system("kill -9 "+str(pid)) - time.sleep(0.1) - i+=1 - data['configs']['serverstatus']=0 - if types=='restart' or types=='start': #启动服务 - i=1 - for k in data['configs']['server']: - startstatus=False - cmd="mongod --bind_ip "+str(k['ip'])+" --port "+str(k['port'])+" -f "+WORK_DIR+"/conf/config.conf --dbpath "+WORK_DIR+"/config"+str(i)+"/data --logpath "+WORK_DIR+"/config"+str(i)+"/log.log --pidfilepath "+WORK_DIR+"/config"+str(i)+"/db.pid" - result=os.popen(cmd) - res = result.read() - for line in res.splitlines(): - print("line",line) - if 'process started successfully' in line: - startstatus=True - break - if not startstatus: - return errorjson(code=1,msg="启动失败") - - i+=1 - data['configs']['serverstatus']=1 - file_set_content(WORK_DIR+"/config.conf",json_encode(data)) - return successjson() -def start_mongos(types='restart'): - '启动/停止路由服务' - G.setadminlog="启动/停止路由服务" - data=request.get_json() - data['key']='' - # for k in data - #创建配置文件 - os.system("mkdir -p "+WORK_DIR+"/conf && mkdir -p "+WORK_DIR+"/mongos") - f=open(WORK_DIR+"/conf/mongos.conf","w") - f.write("logappend = true\n"+ - "fork=true\n"+ - data['mongos']['configdb']+" #这里必须是公共网ip或内网ip,千万不能是127.0.0.1\n" - "keyFile="+WORK_DIR+"/key/mongo.key\n"+ - "maxConns=20000 #最大连接数") - f.close() - os.system("chmod 777 "+WORK_DIR+"/conf/mongos.conf") - os.system("mkdir -p "+WORK_DIR+"/mongos") - if types=='restart' or types=='stop': #停止服务 - i=1 - for k in data['mongos']['server']: - pid=file_get_content(WORK_DIR+"/mongos/db"+str(i)+".pid") - os.system("kill -9 "+str(pid)) - time.sleep(0.1) - i+=1 - data['mongos']['serverstatus']=0 - if types=='restart' or types=='start': #启动服务 - i=1 - for k in data['mongos']['server']: - startstatus=False - cmd="mongos --bind_ip "+str(k['ip'])+" --port "+str(k['port'])+" -f "+WORK_DIR+"/conf/mongos.conf --logpath "+WORK_DIR+"/mongos/log"+str(i)+".log --pidfilepath "+WORK_DIR+"/mongos/db"+str(i)+".pid" - print(cmd) - result=os.popen(cmd) - res = result.read() - for line in res.splitlines(): - print("line",line) - if 'process started successfully' in line: - startstatus=True - break - if not startstatus: - return errorjson(code=1,msg="启动失败") - i+=1 - data['mongos']['serverstatus']=1 - file_set_content(WORK_DIR+"/config.conf",json_encode(data)) - return successjson() -def start_shard(types='restart'): - '启动/停止分片服务' - G.setadminlog="启动/停止分片服务" - data=request.get_json() - data['key']='' - os.system("mkdir -p "+WORK_DIR+"/conf") - - j=1 - for shard in data['shard']:#分片列表 - f=open(WORK_DIR+"/conf/shard"+str(j)+".conf","w") - f.write("logappend=true\n"+ - "fork=true\n"+ - "maxConns=2000\n"+ - "storageEngine=mmapv1 #基于内存映射文件的存储引擎\n"+ - "shardsvr=true\n"+ - "replSet="+shard['servername']+"\n"+ - "keyFile="+WORK_DIR+"/key/mongo.key") - f.close() - i=1 - for k in shard['server']: - os.system("mkdir -p "+WORK_DIR+"/shard"+str(j)+"/data"+str(i)) - i+=1 - if types=='restart' or types=='stop': #停止服务 - i=1 - for k in shard['server']: - pid=file_get_content(WORK_DIR+"/shard"+str(j)+"/db"+str(i)+".pid") - os.system("kill -9 "+str(pid)) - time.sleep(0.1) - i+=1 - data['shard'][j-1]['serverstatus']=0 - if types=='restart' or types=='start': #启动服务 - i=1 - for k in shard['server']:#副本集列表 - startstatus=False - cmd="mongod --bind_ip "+str(k['ip'])+" --port "+str(k['port'])+" -f "+WORK_DIR+"/conf/shard"+str(j)+".conf --dbpath "+WORK_DIR+"/shard"+str(j)+"/data"+str(i)+" --logpath "+WORK_DIR+"/shard"+str(j)+"/log"+str(i)+".log --pidfilepath "+WORK_DIR+"/shard"+str(j)+"/db"+str(i)+".pid" - print("启动cmd:",cmd) - result=os.popen(cmd) - res = result.read() - for line in res.splitlines(): - print("line",line) - if 'process started successfully' in line: - startstatus=True - break - if not startstatus: - file_set_content(WORK_DIR+"/config.conf",json_encode(data)) - return errorjson(code=1,msg="启动失败") - i+=1 - data['shard'][j-1]['serverstatus']=1 - j+=1 - file_set_content(WORK_DIR+"/config.conf",json_encode(data)) - return successjson() - -# def config_init(id): -# "config副本集初始化," -# data=request.get_json() -# port=data['configs']['server'][0]['port'] -# replicaset=data['configs']['replicaset'] -# members=[] -# i=0 -# for k in replicaset: -# zd={'_id':i,'host':k['ip']+':'+str(k['port'])} -# members.append(zd) -# i+=1 -# f=open(config.path['path']+"app/linuxweb/config_init.sh","w") -# f.write("mongo --port "+str(port)+"\n"+ -# "use admin\n"+ -# "rs.initiate({_id:'configs',members:"+json_encode(members)+"})\n"+ -# "exit") -# f.close() -# os.system("cd "+config.path['path']+"app/linuxweb && bash config_init.sh") -# return successjson() - - - -#mongodb独立部署 /data/mongodb/server1/ -def setserverconfig(): - configlist=request.get_json() - for k in configlist: - if not os.path.exists(WORK_DIR+k['path']): - os.makedirs(WORK_DIR+k['path']) - if not os.path.exists(WORK_DIR+k['path']+"/data"): - os.makedirs(WORK_DIR+k['path']+"/data") - file_set_content(WORK_DIR+k['path']+"/mongod.config",''+ - 'systemLog:\n'+ - ' destination: file\n'+ - ' logAppend: true\n'+ - ' path: '+WORK_DIR+k['path']+'/mongodb.log #mongodb的日志文件路径\n'+ - 'storage:\n'+ - ' dbPath: '+WORK_DIR+k['path']+'/data/ #mongodb的数据文件路径\n'+ - ' journal:\n'+ - ' enabled: true\n'+ - 'processManagement:\n'+ - ' fork: true # fork and run in background\n'+ - ' pidFilePath: '+WORK_DIR+k['path']+'/mongod.pid # location of pidfile\n'+ - ' timeZoneInfo: /usr/share/zoneinfo\n'+ - 'net:\n'+ - ' port: '+str(k['port'])+' #mongodb1的进程号\n'+ - ' bindIp: '+k['bindIp']+' # Listen to local interface only, comment to listen on all interfaces') - file_set_content(WORK_DIR+"/serverconfig.conf",json_encode(configlist)) - return successjson() -def restartserver(types='start',index=0): - index=int(index) - configlist=json_decode(file_get_content(WORK_DIR+"/serverconfig.conf")) - cmd="mongod -f "+WORK_DIR+configlist[index]['path']+"/mongod.config" #启动命令 - if types=='start': - configlist[index]['status']=1 - system_start.insert_Boot_up(cmd=cmd,name="mongodb独立模式",icon="https://img.kwebapp.cn/icon/mongodb.png") - elif types=='stop': - configlist[index]['status']=0 - system_start.del_Boot_up(cmd) - cmd=cmd+" --shutdown" #停止命令 - result=os.popen(cmd) - res = result.read() - startstatus=False - for line in res.splitlines(): - print("line",line) - if 'process started successfully' in line or 'killing process with pid' in line: - startstatus=True - break - if startstatus: - file_set_content(WORK_DIR+"/serverconfig.conf",json_encode(configlist)) - return successjson() - else: - return errorjson(cmd,msg="失败") diff --git a/app/intapp/controller/soft/mysql copy.py b/app/intapp/controller/soft/mysql copy.py deleted file mode 100644 index 32e65f1..0000000 --- a/app/intapp/controller/soft/mysql copy.py +++ /dev/null @@ -1,310 +0,0 @@ -from .common import * -import oss2 -def get_data(id): - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - text=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") - conf=json_decode(text) - if not conf: - if ar['edition']=='5.7': - port=3306 - else: - port=3307 - conf={ - "base":{ - 'rootpassword':'intapppasswordtest', - 'path':ar['paths']+ar['title']+ar['edition']+'/data', - 'port':port, #监听端口 - 'max_connections':'200',#最大连接数 - 'max_allowed_packet':'16M', #最大接受的数据包大小 - 'expire_logs_days':'3',#日志保留时间天() - 'query_cache_limit':'1M',#指定单个查询可以使用的缓冲区的大小 - 'query_cache_size':'32M',#查询的缓存大小设置 - 'query_cache_type':'1',#设置缓存的类型, 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 - 'wait_timeout':'9000',#超时等待时间,单位秒,即一个connection在若干秒内无响应 - 'thread_cache_size':'256',# 用于缓存空闲的线程 - 'key_buffer_size':'16M' # 用于指定索引缓冲区的大小 - }, - } - if ar['edition']=='5.7': - mycnf=file_get_content("/etc/my.cnf") - else: - mycnf=file_get_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf") - data={ - 'conf':conf, - 'ar':ar, - "my":mycnf - } - return successjson(data) -def upd_my(id): - "修改配置文件" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - data=request.get_json() - if ar['edition']=='5.7': - file_set_content("/etc/my.cnf",data['text']) - else: - file_set_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf",data['text']) - return successjson() -def upd_data(id): - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - data=request.get_json() - filetext=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") - filedata=json_decode(filetext) - if not filedata or data['base']['rootpassword']!=filedata['base']['rootpassword']:#修改mysql密码 - os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart --skip-grant-tables") - cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -e " - cmd=cmd+'"use mysql;flush privileges;update user set authentication_string=password(' - cmd=cmd+"'"+str(data['base']['rootpassword']) - cmd=cmd+"'" - cmd=cmd+') where user=' - cmd=cmd+"'root';set password=password('"+str(data['base']['rootpassword'])+"');" - cmd=cmd+'"' - if '5.7' != ar['edition']: - cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -p3307 -S "+ar['paths']+ar['title']+ar['edition']+"/tmp/mysql.sock -e " - cmd+='"use mysql;flush privileges;grant all privileges on *.* to root@' - cmd+="'%'" - cmd+=" identified by 'root';update mysql.user set password=password('"+data['base']['rootpassword']+"') where user='root';update mysql.user set grant_priv='Y' where User='root';flush privileges" - cmd=cmd+'"' - # file_set_content("mysqlset",cmd) - pi=subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart") - print(type(strs),strs) - if 'error' in strs: - return errorjson(msg="密码修改失败"+strs) - - # mysqld restart --skip-grant-tables && mysql -uroot -e "flush privileges;update mysql.user set authentication_string=password('123456') where user = 'root'"; - # print(data['base']['rootpassword'],filedata['base']['rootpassword']) - if '5.7' == ar['edition']: - mycnf='/etc/my.cnf' - else: - mycnf=ar['paths']+ar['title']+ar['edition']+"/my.cnf" - f = open(mycnf) - con='' - while True: - line = f.readline() - if not line: - break - elif 'datadir=' in line: - line="datadir="+str(data['base']['path'])+"\n" - elif 'port=' in line or 'port =' in line: - line="port="+str(data['base']['port'])+"\n" - elif 'max_connections=' in line: - line="max_connections="+str(data['base']['max_connections'])+"\n" - elif 'max_allowed_packet=' in line: - line="max_allowed_packet="+str(data['base']['max_allowed_packet'])+"\n" - elif 'expire_logs_days=' in line: - line="expire_logs_days="+str(data['base']['expire_logs_days'])+"\n" - elif 'query_cache_limit=' in line: - line="query_cache_limit="+str(data['base']['query_cache_limit'])+"\n" - elif 'query_cache_size=' in line: - line="query_cache_size="+str(data['base']['query_cache_size'])+"\n" - elif 'query_cache_type=' in line: - line="query_cache_type="+str(data['base']['query_cache_type'])+"\n" - elif 'wait_timeout=' in line: - line="wait_timeout="+str(data['base']['wait_timeout'])+"\n" - elif 'thread_cache_size=' in line: - line="thread_cache_size="+str(data['base']['thread_cache_size'])+"\n" - elif 'key_buffer_size=' in line: - line="key_buffer_size="+str(data['base']['key_buffer_size'])+"\n" - con=con+line - f.close() - f= open(mycnf, "w") - f.write(con) - f.close() - time.sleep(1) - if not filedata or data['base']['path']!=filedata['base']['path']: #修改数据存放目录 - os.system('mysqld'+(ar['edition'].replace(".", ""))+'server stop') - os.system("mkdir -p "+str(data['base']['path'])) - # #mysql数据复制 - if not filedata: - print("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") - os.system("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") - else: - print("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") - os.system("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") - os.system("chown -R mysql "+data['base']['path']+" && chgrp -R mysql "+data['base']['path']) - os.system('mysqld'+(ar['edition'].replace(".", ""))+'server start') - text=json_encode(data) - file_set_content(ar['paths']+ar['title']+ar['edition']+"/config.conf",text) - - return successjson() -def backups(types='whole',db='bankup_all_databases',upload_aliyun=True): - "备份mysql5.7" - return BACKUP.backups(types,db,upload_aliyun) -def recovery(types='whole',upload_aliyun=True): - "恢复mysql5.7" - db=request.args.get("db") - Queues.insert(target=BACKUP.recovery,args=(types,db,upload_aliyun),title="恢复mysql") - return successjson(msg="正在恢复数据库,请在任务队列中查看恢复结果") -class BACKUP: - def recovery(types,db,upload_aliyun): - """恢复数据库""" - if not os.path.isfile("app/common/file/config.conf"): - print("在系统配置中保存备份目录") - return - fileconfig=json_decode(file_get_content("app/common/file/config.conf")) - if not fileconfig: - print("在系统配置中保存备份目录") - return - backpath=fileconfig['aliyun']['backpath'] - if backpath: - if backpath[:1]=='/': - backpath=backpath[1:] - if backpath[-1]=='/': - backpath=backpath[:-1] - else: - backpath="kcweb" - backmysqlpath="backup/mysql" #mysql备份目录 - if not os.path.exists(backmysqlpath): - os.makedirs(backmysqlpath) - mysqlpwd='intapppasswordtest' - mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql5.7/config.conf")) #mysql信息 - if mysqlconf: - mysqldatapath=mysqlconf['base']['path'] - mysqlpwd=mysqlconf['base']['rootpassword'] - conf={ - "mysql":{ - "username":"root","password":mysqlpwd,"host":"127.0.0.1",#mysql信息 - }, - } - if upload_aliyun: - auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) - bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) - bucket.get_object_to_file(db,backmysqlpath+"/database.sql.gz") - os.system("gzip -d "+backmysqlpath+"/database.sql.gz") - os.system("mysql -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" < "+backmysqlpath+"/database.sql") - os.remove(backmysqlpath+"/database.sql") - else: - os.system("gzip -d "+backmysqlpath+"/"+db+".sql.gz") - os.system("mysql -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" < "+backmysqlpath+"/"+db+".sql") - print("恢复完成") - def backups(types,db,upload_aliyun): - """备份mysql --cli运行 - types whole表示全量备份。 increment表示增量备份所有 - - db bankup_all_databases表示备份所有数据库。 否则备份指定数据库按逗号分隔 types=whole时有效 - """ - if not os.path.isfile("app/common/file/config.conf"): - print("在系统配置中保存备份目录") - return - fileconfig=json_decode(file_get_content("app/common/file/config.conf")) - if not fileconfig: - print("在系统配置中保存备份目录") - return - backpath=fileconfig['aliyun']['backpath'] - if backpath: - if backpath[:1]=='/': - backpath=backpath[1:] - if backpath[-1]=='/': - backpath=backpath[:-1] - else: - backpath="kcweb" - backmysqlpath="backup/mysql" #mysql备份目录 - if not os.path.exists(backmysqlpath): - os.makedirs(backmysqlpath) - mysqldatapath="/usr/local/mysql/mysql5.7/data" #mysql数据库存放目 - mysqlpwd='intapppasswordtest' - mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql5.7/config.conf")) #mysql信息 - if mysqlconf: - mysqldatapath=mysqlconf['base']['path'] - mysqlpwd=mysqlconf['base']['rootpassword'] - conf={ - "mysql":{ - "username":"root","password":mysqlpwd,"host":"127.0.0.1",#mysql信息 - }, - } - if upload_aliyun: - auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) - bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) - if types=='whole': #全量备份 - if not os.path.exists(backmysqlpath): - os.system("mkdir -p "+backmysqlpath) - if db=='bankup_all_databases':#备份所有 - print("全量备份所有数据库:"+db+".sql.gz") - os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+".sql.gz") - else:#备份指定数据库 - db=re.sub(","," ",db) - print("全量备份指定数据库:"+db+".sql.gz") - os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+".sql.gz") - if upload_aliyun: - print(backmysqlpath+"/"+db+".sql.gz","上传mysql备份目录文件到阿里云oss...") - oss2.resumable_upload(bucket, "backups/"+backpath+"/"+backmysqlpath+"/"+db+"/"+time.strftime("%Y%m%d-%H:%M:%S",time.localtime(times()))+".sql.gz",backmysqlpath+"/"+db+".sql.gz") - filelist=[] - for obj in oss2.ObjectIterator(bucket, prefix="backups/"+backpath+"/"+backmysqlpath+"/"+db+"/"): - filelist.append(obj.key) - i=0 - while True: - if len(filelist)-i <= 5: #在阿里云保留5个备份文件 其他上传 - break - bucket.delete_object(filelist[i]) - i+=1 - - # elif types=='increment': #增量备份所有 - # if not os.path.exists(backmysqlpath) or not os.path.isfile(backmysqlpath+"/"+db+".sql.gz"): - # os.system("mkdir -p "+backmysqlpath) - # print("全量备份所有数据库:"+db+".sql.gz") - # os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/increment_all_databases.sql.gz") - # print("备份mysql二进制文件...") - # t=os.listdir(backmysqlpath) - # lis=os.listdir(mysqldatapath) - # maxlist=[] - # for files in lis: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # maxlist.append(a) - # except:pass - # for files in lis: - # iscz=True #是否需要复制 - # if iscz: - # for k in t: - # if mysqldatapath+"/"+k == mysqldatapath+"/"+files: - # iscz=False - # print(mysqldatapath+"/"+k+"已存在") - # break - # if not iscz: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # if max(maxlist) == a: - # iscz=True - # print(mysqldatapath+"/"+files+"该文件是最后一个日志,已备份,(最后一个文件可能不是完整的)") - # except:pass - # if iscz: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # os.system("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files) - # print("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files,"复制成功") - # except:pass - # if upload_aliyun: - # print("上传mysql备份目录文件到阿里云oss...") - # t=os.listdir(backmysqlpath) - # maxlist=[] - # for files in t: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # maxlist.append(a) - # except:pass - # path=get_file(backmysqlpath,is_folder=False) - # for files in path: - # sc=True #是否需要上传 - # if bucket.object_exists("backups/"+files['path']):#如果文件已存在阿里云 - # if 'mysql-bin.' in files['name']: - # try: - # a=int(files['name'].replace("mysql-bin.", "")) - # if max(maxlist) == a: - # print(backmysqlpath+"/"+files['name']+"该文件是最后一个日志,所以要上传阿里云") - # else: - # print("文件已在阿里云oss存在") - # sc=False - # except:pass - # else: - # print("文件已在阿里云oss存在") - # sc=False - # if sc: - # oss2.resumable_upload(bucket, "backups/"+files['path'], files['path']) - print("备份完成") diff --git a/app/intapp/controller/soft/mysql.py b/app/intapp/controller/soft/mysql.py deleted file mode 100644 index e0474c4..0000000 --- a/app/intapp/controller/soft/mysql.py +++ /dev/null @@ -1,338 +0,0 @@ -from .common import * -import oss2 -def get_data(id): - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - text=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") - conf=json_decode(text) - if not conf: - if ar['edition']=='5.7': - port=3306 - elif ar['edition']=='8.0': - port=3308 - else: - port=3307 - conf={ - "base":{ - 'rootpassword':'intapppasswordtest', - 'path':ar['paths']+ar['title']+ar['edition']+'/data', - 'port':port, #监听端口 - 'max_connections':'200',#最大连接数 - 'max_allowed_packet':'16M', #最大接受的数据包大小 - 'expire_logs_days':'3',#日志保留时间天() - 'query_cache_limit':'1M',#指定单个查询可以使用的缓冲区的大小 - 'query_cache_size':'32M',#查询的缓存大小设置 - 'query_cache_type':'1',#设置缓存的类型, 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 - 'wait_timeout':'9000',#超时等待时间,单位秒,即一个connection在若干秒内无响应 - 'thread_cache_size':'256',# 用于缓存空闲的线程 - 'key_buffer_size':'16M' # 用于指定索引缓冲区的大小 python3 kcw.py --app app --modular intapp --plug soft --uninstall - }, - } - if '5.6' == ar['edition']: - mycnf=file_get_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf") - else: - mycnf=file_get_content("/etc/my.cnf") - data={ - 'conf':conf, - 'ar':ar, - "my":mycnf - } - return successjson(data) -def upd_my(id): - "修改配置文件" - G.setadminlog="mysql修改配置文件" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - data=request.get_json() - if '5.6' == ar['edition']: - file_set_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf",data['text']) - else: - file_set_content("/etc/my.cnf",data['text']) - return successjson() -def upd_data(id): - G.setadminlog="mysql修改基本配置文件" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - data=request.get_json() - filetext=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") - filedata=json_decode(filetext) - if (ar['edition']=='5.7' or ar['edition']=='5.6') and (not filedata or data['base']['rootpassword']!=filedata['base']['rootpassword']):#修改mysql密码 - os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart --skip-grant-tables") - cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -e " - cmd=cmd+'"use mysql;flush privileges;update user set authentication_string=password(' - cmd=cmd+"'"+str(data['base']['rootpassword']) - cmd=cmd+"'" - cmd=cmd+') where user=' - cmd=cmd+"'root';set password=password('"+str(data['base']['rootpassword'])+"');" - cmd=cmd+'"' - if '5.7' != ar['edition']: - cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -p3307 -S "+ar['paths']+ar['title']+ar['edition']+"/tmp/mysql.sock -e " - cmd+='"use mysql;flush privileges;grant all privileges on *.* to root@' - cmd+="'%'" - cmd+=" identified by 'root';update mysql.user set password=password('"+data['base']['rootpassword']+"') where user='root';update mysql.user set grant_priv='Y' where User='root';flush privileges" - cmd=cmd+'"' - # file_set_content("mysqlset",cmd) - pi=subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart") - print(type(strs),strs) - if 'error' in strs: - return errorjson(msg="密码修改失败"+strs) - - # mysqld restart --skip-grant-tables && mysql -uroot -e "flush privileges;update mysql.user set authentication_string=password('123456') where user = 'root'"; - # print(data['base']['rootpassword'],filedata['base']['rootpassword']) - if '5.6' == ar['edition']: - mycnf=ar['paths']+ar['title']+ar['edition']+"/my.cnf" - else: - mycnf="/etc/my.cnf" - f = open(mycnf) - con='' - while True: - line = f.readline() - if not line: - break - elif 'datadir=' in line and data['base']['path']: - line="datadir="+str(data['base']['path'])+"\n" - elif ('port=' in line or 'port =' in line) and data['base']['port']: - line="port="+str(data['base']['port'])+"\n" - elif 'max_connections=' in line and data['base']['max_connections']: - line="max_connections="+str(data['base']['max_connections'])+"\n" - elif 'max_allowed_packet=' in line and data['base']['max_allowed_packet']: - line="max_allowed_packet="+str(data['base']['max_allowed_packet'])+"\n" - elif 'expire_logs_days=' in line and data['base']['expire_logs_days']: - line="expire_logs_days="+str(data['base']['expire_logs_days'])+"\n" - elif 'query_cache_limit=' in line and data['base']['query_cache_limit']: - line="query_cache_limit="+str(data['base']['query_cache_limit'])+"\n" - elif 'query_cache_size=' in line and data['base']['query_cache_size']: - line="query_cache_size="+str(data['base']['query_cache_size'])+"\n" - elif 'query_cache_type=' in line and data['base']['query_cache_type']: - line="query_cache_type="+str(data['base']['query_cache_type'])+"\n" - elif 'wait_timeout=' in line and data['base']['wait_timeout']: - line="wait_timeout="+str(data['base']['wait_timeout'])+"\n" - elif 'thread_cache_size=' in line and data['base']['thread_cache_size']: - line="thread_cache_size="+str(data['base']['thread_cache_size'])+"\n" - elif 'key_buffer_size=' in line and data['base']['key_buffer_size']: - line="key_buffer_size="+str(data['base']['key_buffer_size'])+"\n" - con=con+line - f.close() - f= open(mycnf, "w") - f.write(con) - f.close() - time.sleep(1) - if not filedata or data['base']['path']!=filedata['base']['path']: #修改数据存放目录 - os.system('mysqld'+(ar['edition'].replace(".", ""))+'server stop') - os.system("mkdir -p "+str(data['base']['path'])) - # #mysql数据复制 - if not filedata: - print("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") - os.system("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") - else: - print("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") - os.system("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") - os.system("chown -R mysql "+data['base']['path']+" && chgrp -R mysql "+data['base']['path']) - os.system('mysqld'+(ar['edition'].replace(".", ""))+'server start') - text=json_encode(data) - file_set_content(ar['paths']+ar['title']+ar['edition']+"/config.conf",text) - - return successjson() -def backups(types='whole',db='bankup_all_databases',upload_aliyun=True,edition='5.7'): - "备份mysql" - return BACKUP.backups(types,db,upload_aliyun,edition) -def recovery(types='whole',upload_aliyun=True,edition='5.7'): - "恢复mysql" - if config.app['cli']: - db="backups/kcweb/backup/mysql/bankup_all_databases5.6/20200909-02:51:23.sql.gz" - BACKUP.recovery(types,db,upload_aliyun,edition) - else: - db=request.args.get("db") - Queues.insert(target=BACKUP.recovery,args=(types,db,upload_aliyun,edition),title="恢复mysql"+edition) - return successjson(msg="正在恢复数据库,请在任务队列中查看恢复结果") -class BACKUP: - def recovery(types,db,upload_aliyun,edition): - """恢复数据库""" - if not os.path.isfile("app/common/file/config.conf"): - print("在系统配置中保存备份目录") - return - fileconfig=json_decode(file_get_content("app/common/file/config.conf")) - if not fileconfig: - print("在系统配置中保存备份目录") - return - backpath=fileconfig['aliyun']['backpath'] - if backpath: - if backpath[:1]=='/': - backpath=backpath[1:] - if backpath[-1]=='/': - backpath=backpath[:-1] - else: - backpath="kcweb" - backmysqlpath="backup/mysql" #mysql备份目录 - if not os.path.exists(backmysqlpath): - os.makedirs(backmysqlpath) - mysqlpwd='intapppasswordtest' - mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql"+edition+"/config.conf")) #mysql信息 - if mysqlconf: - mysqldatapath=mysqlconf['base']['path'] - mysqlpwd=mysqlconf['base']['rootpassword'] - port=str(mysqlconf['base']['port']) - else: - if edition=='5.6': - port="3307" - elif edition=='5.7': - port="3306" - elif edition=='8.0': - port="3308" - conf={ - "mysql":{ - "username":"root","password":mysqlpwd,"host":"127.0.0.1","port":port,#mysql信息 - }, - } - if upload_aliyun: - auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) - bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) - bucket.get_object_to_file(db,backmysqlpath+"/database.sql.gz") - os.system("gzip -d "+backmysqlpath+"/database.sql.gz") - os.system("mysql"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -P"+conf['mysql']['port']+" -h"+conf['mysql']['host']+" -p"+conf['mysql']['password']+" < "+backmysqlpath+"/database.sql") - # print("mysql"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -P"+conf['mysql']['port']+" -h"+conf['mysql']['host']+" -p"+conf['mysql']['password']+" < "+backmysqlpath+"/database.sql") - os.remove(backmysqlpath+"/database.sql") - else: - os.system("gzip -d "+backmysqlpath+"/"+db+".sql.gz") - os.system("mysql"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -P"+conf['mysql']['port']+" -h"+conf['mysql']['host']+" -p"+conf['mysql']['password']+" < "+backmysqlpath+"/"+db+".sql") - print("恢复完成") - - def backups(types,db,upload_aliyun,edition): - """备份mysql --cli运行 - types whole表示全量备份。 increment表示增量备份所有 - - db bankup_all_databases表示备份所有数据库。 否则备份指定数据库按逗号分隔 types=whole时有效 - """ - if not os.path.isfile("app/common/file/config.conf"): - print("在系统配置中保存备份目录") - return - fileconfig=json_decode(file_get_content("app/common/file/config.conf")) - if not fileconfig: - print("在系统配置中保存备份目录") - return - - backpath=fileconfig['aliyun']['backpath'] - if backpath: - if backpath[:1]=='/': - backpath=backpath[1:] - if backpath[-1]=='/': - backpath=backpath[:-1] - else: - backpath="kcweb" - backmysqlpath="backup/mysql" #mysql备份目录 - if not os.path.exists(backmysqlpath): - os.makedirs(backmysqlpath) - - mysqlpwd='intapppasswordtest' - mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql"+edition+"/config.conf")) #mysql信息 - if mysqlconf: - mysqldatapath=mysqlconf['base']['path'] - mysqlpwd=mysqlconf['base']['rootpassword'] - port=str(mysqlconf['base']['port']) - else: - if edition=='5.6': - port="3307" - elif edition=='5.7': - port="3306" - elif edition=='8.0': - port="3308" - mysqldatapath="/usr/local/mysql/mysql"+edition+"/data" #mysql数据库存放目 - conf={ - "mysql":{ - "username":"root","password":mysqlpwd,"host":"127.0.0.1","port":port,#mysql信息 - }, - } - if upload_aliyun: - auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) - bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) - if types=='whole': #全量备份 - if not os.path.exists(backmysqlpath): - os.system("mkdir -p "+backmysqlpath) - if db=='bankup_all_databases':#备份所有 - print("全量备份所有数据库:"+db+".sql.gz") - os.system("mysqldump"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" -P"+conf['mysql']['port']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+edition+".sql.gz") - else:#备份指定数据库 - db=re.sub(","," ",db) - print("全量备份指定数据库:"+db+".sql.gz") - os.system("mysqldump"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" -P"+conf['mysql']['port']+" --databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+edition+".sql.gz") - if upload_aliyun: - print(backmysqlpath+"/"+db+edition+".sql.gz","上传mysql备份目录文件到阿里云oss...") - oss2.resumable_upload(bucket, "backups/"+backpath+"/"+backmysqlpath+"/"+db+edition+"/"+time.strftime("%Y%m%d-%H:%M:%S",time.localtime(times()))+".sql.gz",backmysqlpath+"/"+db+edition+".sql.gz") - filelist=[] - for obj in oss2.ObjectIterator(bucket, prefix="backups/"+backpath+"/"+backmysqlpath+"/"+db+edition+"/"): - filelist.append(obj.key) - i=0 - while True: - if len(filelist)-i <= 30: #在阿里云保留30个备份文件 其他上传 - break - bucket.delete_object(filelist[i]) - i+=1 - - # elif types=='increment': #增量备份所有 - # if not os.path.exists(backmysqlpath) or not os.path.isfile(backmysqlpath+"/"+db+".sql.gz"): - # os.system("mkdir -p "+backmysqlpath) - # print("全量备份所有数据库:"+db+".sql.gz") - # os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/increment_all_databases.sql.gz") - # print("备份mysql二进制文件...") - # t=os.listdir(backmysqlpath) - # lis=os.listdir(mysqldatapath) - # maxlist=[] - # for files in lis: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # maxlist.append(a) - # except:pass - # for files in lis: - # iscz=True #是否需要复制 - # if iscz: - # for k in t: - # if mysqldatapath+"/"+k == mysqldatapath+"/"+files: - # iscz=False - # print(mysqldatapath+"/"+k+"已存在") - # break - # if not iscz: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # if max(maxlist) == a: - # iscz=True - # print(mysqldatapath+"/"+files+"该文件是最后一个日志,已备份,(最后一个文件可能不是完整的)") - # except:pass - # if iscz: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # os.system("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files) - # print("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files,"复制成功") - # except:pass - # if upload_aliyun: - # print("上传mysql备份目录文件到阿里云oss...") - # t=os.listdir(backmysqlpath) - # maxlist=[] - # for files in t: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # maxlist.append(a) - # except:pass - # path=get_file(backmysqlpath,is_folder=False) - # for files in path: - # sc=True #是否需要上传 - # if bucket.object_exists("backups/"+files['path']):#如果文件已存在阿里云 - # if 'mysql-bin.' in files['name']: - # try: - # a=int(files['name'].replace("mysql-bin.", "")) - # if max(maxlist) == a: - # print(backmysqlpath+"/"+files['name']+"该文件是最后一个日志,所以要上传阿里云") - # else: - # print("文件已在阿里云oss存在") - # sc=False - # except:pass - # else: - # print("文件已在阿里云oss存在") - # sc=False - # if sc: - # oss2.resumable_upload(bucket, "backups/"+files['path'], files['path']) - print("备份完成") diff --git a/app/intapp/controller/soft/nginx.py b/app/intapp/controller/soft/nginx.py deleted file mode 100644 index bae9675..0000000 --- a/app/intapp/controller/soft/nginx.py +++ /dev/null @@ -1,419 +0,0 @@ -from .common import * -import traceback -def index(id='',types='getinfo'): - "nginx配置文件" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title'] - edition=ar['edition'] - if types=='getinfo': - if os.path.isfile(paths+filenames+edition+'/logs/error.log'): - # print(paths+filenames+'/logs/error.log') - # f=open(paths+filenames+'/logs/error.log','r') - # logserror=f.read() - # f.close() - logserror='' - else:logserror='' - if os.path.isfile(paths+filenames+edition+'/logs/access.log'): - # f=open(paths+filenames+'/logs/access.log','r',encoding="utf-8") - # logsaccess=f.read() - # f.close() - logsaccess='' - else:logsaccess='' - f=open(paths+filenames+edition+'/conf/nginx.conf','r',encoding="utf-8") - confnginx=f.read() - data={ - 'logs':{'error':logserror,'access':logsaccess}, - 'conf':{'nginx':confnginx}, - 'ar':ar, - } - return successjson(data) - elif types=='updconf': - con=request.get_json() - f=open(paths+filenames+edition+'/conf/nginx.conf','w',encoding="utf-8") - f.write(con['text']) - f.close() - return successjson() - else: - return errorjson(msg="未知类型") -def anphp(): - "已安装的php以及伪静态模板" - nginx=sqlite('soft',model_intapp_soft_path).where([('status','egt','4'),'and',('platform','eq',get_sysinfo()['uname'][0]),'and',('title','like','nginx%')]).find() - if nginx: - pseudo_static_tpl=get_file(nginx['paths']+nginx['title']+nginx['edition']+'/conf/vhost/webtpl/rewrite') #伪静态模板 - rewr=[] - for k in pseudo_static_tpl: - rewr.append({'name':k['name'],'text':file_get_content(k['path'])}) - data={ - "php":sqlite('soft',model_intapp_soft_path).where("title like '%php%' and (status=4 or status=10) and title not like '%phpmyadmin%'").select(), - "rewr":rewr - } - return successjson(data) - else: - return successjson() -def webdescribesfind(): - "获取指定网站信息" - title=request.args.get("title") - return successjson(sqlite("web",model_intapp_soft_path).where("title='"+title+"'").find()) -def weblist(): - "网站列表" - where=False - pagenow=int(request.args.get('pagenow')) - pagesize=int(request.args.get('pagesize')) - kw=request.args.get('kw') - if kw: - where=[("title","like","%"+str(kw)+"%"),'or',("describes","like","%"+str(kw)+"%"),'or',("domain","like","%"+str(kw)+"%")] - if not pagenow: - pagenow=1 - if not pagesize: - pagesize=10 - lists=sqlite("web",model_intapp_soft_path).where(where).page(pagenow,pagesize).select() - i=0 - for k in lists: - # lists[i]['domain']=k['domain'].split("\n") - lists[i]['balancing'] =json_decode(k['balancing']) - lists[i]['proxy_set_header'] =json_decode(k['proxy_set_header']) - lists[i]['header'] =json_decode(k['header']) - i+=1 - count=sqlite("web",model_intapp_soft_path).where(where).count() - return successjson(return_list(lists,count,pagenow,pagesize)) -def add_web(): - G.setadminlog="添加或更新nginx网站" - data=request.get_json() - status,msg=funadd_web(data) - if status: - return successjson(msg) - else: - return errorjson(msg=msg) -def _banddomain(id,types,domain): - G.setadminlog="绑定域名" - # domain=request.args.get('domain') - if '.' not in domain: - # return errorjson(msg="域名格式错误") - return False,'域名格式错误' - if not domain: - # return errorjson(msg="域名参数错误") - return False,'域名参数错误' - web=sqlite("web",model_intapp_soft_path).where("id",id).find() - if web: - if(sqlite("web",model_intapp_soft_path).where("domain like '%"+domain+"%'").count()): - if types=='add': - # return successjson(msg="该域名已被使用",code=1) - return True,'该域名已被使用' - data=web - if domain: - if types=='add': - data['domain']=data['domain']+"\n"+domain - elif types=='del': - data['domain']=data['domain'].replace("\n"+domain, "") - data['domain']=data['domain'].replace(domain, "") - # return errorjson(data) - else: - # return errorjson(msg="types错误") - return False,'types错误' - if data['header']: - data['header']=json_decode(data['header']) - data['proxy_set_header']=json_decode(data['proxy_set_header']) - data['balancing']=json_decode(data['balancing']) - return funadd_web(data,types) - # return status,msg - # if status: - # return successjson(msg) - # else: - # return errorjson(msg=msg) - else: - return False,'id错误' - # return errorjson(msg="id错误") -def funadd_web(data,types=""): - "添加或更新网站" - nginx=sqlite('soft',model_intapp_soft_path).where([('status','egt','4'),'and',('platform','eq',get_sysinfo()['uname'][0]),'and',('title','like','nginx%')]).find() - if not nginx: - return errorjson(msg='安装nginx服务器后才创建网站') - addtime=times() - - if data['domain']=='': - return False,"域名不能为空" - if data['port']=='': - return False,"端口不能为空" - if data['client_max_body_size']=='': - return False,"上传限制不能为空" - if data['path']=='': - data['path']="/www/wwwroot/" - paths=nginx['paths'] - try: - ttt1=data['domain'].split("\n") - if data['id'] and sqlite('web',model_intapp_soft_path).where("id",data['id']).count(): - # if types!='del': - # where="port="+str(data['port'])+" and id != "+str(data['id'])+" and (" #[('port','eq',data['port'])] - # for kk in ttt1: - # where=where+"domain like '"+kk+"%'"+" or " - # where=where[:-4]+")" - # ttt2=sqlite('web',model_intapp_soft_path).where(where).find() - # if ttt2: - # ttt2=ttt2['domain'].split("\n") - # for k in ttt2: - # for kk in ttt2: - # if k==kk: - # return False,k+"已在本服务器其他站点使用被使用" - domains=sqlite('web',model_intapp_soft_path).where("id",data['id']).field("only").find()['only'] - else: - data['id']='' - where="port="+data['port']+" and (" - for kk in ttt1: - where=where+"domain like '%"+kk+"%'"+" or " - where=where[:-4]+")" - domains=ttt1[0]+":"+str(data['port']) - data['only']=domains - ttt=sqlite('web',model_intapp_soft_path).where(where).find() - if ttt: - ttt=ttt['domain'].split("\n") - for k in ttt: - for kk in ttt1: - if k==kk: - return False,k+"已被使用" - ttt=data['domain'].split("\n") - server_name='' - for k in ttt: - server_name=str(server_name)+" "+str(k) - - if nginx['platform']=='Linux': - if data['webtpl']=='': - return False,"请选择配置文件模板" - filenames=nginx['title']+nginx['edition'] - servertpl=paths+filenames+'/conf/vhost/webtpl/'+data['webtpl'] - ssl_certificate="" - ssl_certificate_key="" - try: - ssl_certificate=data['ssl_certificate'] - ssl_certificate_key=data['ssl_certificate_key'] - except: - data['ssl_certificate']='' - data['ssl_certificate_key']='' - try: - data['header'] - except: - data['header']='' - try: - data['ssl'] - except: - data['ssl']='' - try: - data['rewrite'] - except: - data['rewrite']='' - if data['ssl']: - ssl=443 - if len(data['ssl_certificate'])>5 and len(data['ssl_certificate_key'])>5: - ssl_certificate=data['ssl_certificate'] - ssl_certificate_key=data['ssl_certificate_key'] - # print(ssl_certificate_key) - else: - key=paths+filenames+'/conf/vhost/rewrite/'+domains+".key" - pem=paths+filenames+'/conf/vhost/rewrite/'+domains+".pem" - file_set_content(key,data['key']) - file_set_content(pem,data['pem']) - ssl_certificate=paths+filenames+"/conf/vhost/rewrite/"+domains+".pem" - ssl_certificate_key=paths+filenames+"/conf/vhost/rewrite/"+domains+".key" - print(ssl_certificate) - else: - if os.path.isfile(paths+filenames+'/conf/vhost/rewrite/'+domains+".key") and os.path.isfile(paths+filenames+'/conf/vhost/rewrite/'+domains+".pem"): - sslttt1=file_get_content(paths+filenames+'/conf/vhost/rewrite/'+domains+".key") - sslttt2=file_get_content(paths+filenames+'/conf/vhost/rewrite/'+domains+".pem") - if len(sslttt1)>10 and len(sslttt2)>10: - ssl=443 - else: - ssl=False - else: - ssl=False - if not ssl_certificate or not ssl_certificate_key: - ssl='' - if 'php' in data['webtpl'] and len(data['rewrite'])>4:#php伪静态 - file_set_content(paths+filenames+"/conf/vhost/rewrite/"+domains,data['rewrite']) - elif not os.path.isfile(paths+filenames+"/conf/vhost/rewrite/"+domains): - file_set_content(paths+filenames+"/conf/vhost/rewrite/"+domains,'') - if data['webtpl']=='static' or data['webtpl']=='vue' or 'php' in data['webtpl']: - t=kcwTemplate(filename=servertpl) - text=t.render(client_max_body_size=data['client_max_body_size'],port=data['port'],ssl=ssl,ssl_certificate=ssl_certificate,ssl_certificate_key=ssl_certificate_key, - server_name=server_name,webpath=data['path'],rewrite=paths+filenames+"/conf/vhost/rewrite/"+domains,domains=domains,header=data['header']) - elif data['webtpl']=='balancing':#添加负载均衡 - balancing=data['balancing'] #负载均衡列表 - proxy_set_header=data['proxy_set_header'] #自定义转发请求头列表 - for k in data['balancing']: - if k['ip']=='' or k['port']=='': - return False,"请填写负载均衡ip和端口" - t=kcwTemplate(filename=servertpl) - text=t.render(client_max_body_size=data['client_max_body_size'],port=data['port'],ssl=ssl,balancing=balancing,proxy_set_header=proxy_set_header,ssl_certificate=ssl_certificate,ssl_certificate_key=ssl_certificate_key, - server_name=server_name,webpath=data['path'],rewrite=paths+filenames+"/conf/vhost/rewrite/"+domains,domains=domains,header=data['header']) - f=open(paths+filenames+"/conf/vhost/"+domains+'.conf','w',encoding="utf-8") - f.write(text) - f.close() - os.system("nginx -s reload") - if not os.path.exists(data['path']): - os.makedirs(data['path']) - f=open(data['path']+"/index.html",'w',encoding="utf-8") - f.write('网站创建成功

恭喜您!网站创建成功

') - f.close() - f=open(data['path']+"/index.php",'w',encoding="utf-8") - f.write("") - f.close() - try: - data['servers']=paths+filenames - except:pass - try: - del data['key'] - del data['pem'] - except:pass - del data['ssl'] - del data['rewrite'] - data['balancing'] =json_encode(data['balancing']) - data['proxy_set_header'] =json_encode(data['proxy_set_header']) - data['header'] =json_encode(data['header']) - if data['id']: - data['updtime']=addtime - data['status']=1 - try: - sqlite('web',model_intapp_soft_path).where("id",data['id']).update(data) - except: - pass - else: - pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - if len(strs) > 1: - return False,strs - else: - del data['id'] - data['addtime']=addtime - data['updtime']=addtime - sqlite('web',model_intapp_soft_path).insert(data) - data['id']=sqlite('web',model_intapp_soft_path).max("id") - except: - print(traceback.format_exc()) - file_set_content("server.log",traceback.format_exc()) - return False,"失败,检查参数是否有误" - else: - return True,data['id'] -def del_web(id=0,path=0): - #path=1 表示删除网站目录 ,linux和windows已完成 - "删除网站" - G.setadminlog="删除网站" - title=request.args.get("title") - if not id and title: - where="title = '"+title+"'" - else: - where="id='"+str(id)+"'" - nginx=sqlite('web',model_intapp_soft_path).where(where).find() - if not nginx: - return successjson(msg="不存在") - print(nginx) - filenames=nginx['servers'] - if get_sysinfo()['uname'][0]=='Linux': - if os.path.isfile(filenames+"/conf/vhost/"+nginx['only']+'.conf'): - os.remove(filenames+"/conf/vhost/"+nginx['only']+'.conf') - if os.path.isfile(filenames+"/conf/vhost/rewrite/"+nginx['only']): - os.remove(filenames+"/conf/vhost/rewrite/"+nginx['only']) - if os.path.isfile(filenames+"/logs/"+nginx['only']+".access.log"): - os.remove(filenames+"/logs/"+nginx['only']+".access.log") - if os.path.isfile(filenames+'/conf/vhost/rewrite/'+nginx['only']+".key"): - os.remove(filenames+'/conf/vhost/rewrite/'+nginx['only']+".key") - if os.path.isfile(filenames+'/conf/vhost/rewrite/'+nginx['only']+".pem"): - os.remove(filenames+'/conf/vhost/rewrite/'+nginx['only']+".pem") - pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - elif get_sysinfo()['uname'][0]=='Windows': - if os.path.isfile(filenames+"/conf/vhost/"+nginx['only']+'.conf'): - os.remove(filenames+"/conf/vhost/"+nginx['only']+'.conf') - if os.path.isfile(filenames+"/conf/vhost/rewrite/"+nginx['only']): - os.remove(filenames+"/conf/vhost/rewrite/"+nginx['only']) - if os.path.isfile(filenames+"/logs/"+nginx['only']+".access.log"): - os.remove(filenames+"/logs/"+nginx['only']+".access.log") - os.system("cd "+filenames+" & stop.bat") - time.sleep(3) - os.system("cd "+filenames+" & start.bat") - else: - return errorjson(msg="无法匹配系统") - if path=='1' and os.path.exists(nginx['path']): - shutil.rmtree(nginx['path']) - sqlite('web',model_intapp_soft_path).where(where).delete() - pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - if len(strs) > 1: - return errorjson(msg=strs) - return successjson() - -def getssl(id): - ar=sqlite('web',model_intapp_soft_path).where('id',id).find() - key=ar['servers']+'/conf/vhost/rewrite/'+ar['only']+".key" - pem=ar['servers']+'/conf/vhost/rewrite/'+ar['only']+".pem" - data={ - "key":file_get_content(key), - "pem":file_get_content(pem) - } - return successjson(data) -def getrewr(id): - "获取伪静态" - ar=sqlite('web',model_intapp_soft_path).where('id',id).find() - return successjson(file_get_content(ar['servers']+'/conf/vhost/rewrite/'+ar['only'])) -def getconfig(id,types='get'): - "获取配置文件" - ar=sqlite('web',model_intapp_soft_path).where('id',id).find() - if types=='get': - return successjson(file_get_content(ar['servers']+'/conf/vhost/'+ar['only']+".conf")) - elif types=='set': - data=request.get_json() - file_set_content(ar['servers']+'/conf/vhost/'+ar['only']+".conf",data['text']) - pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - if len(strs) > 1: - return errorjson(msg=strs) - return successjson() - - -def sslfolde(): - "Let's Encrypt证书夹" - paths="/etc/letsencrypt/live/" - if not os.path.exists(paths): - return errorjson(code=1,msg="Let's Encrypt证书夹不存在,在插件市场安装LetsEncrypt插件创建证书后再使用该功能") - try: - lis=os.listdir(paths) - except: - return errorjson(code=1,msg="无法打开"+str(paths)) - lists=[] - for files in lis: - types="folder" - config={} - if os.path.isfile(paths+"/"+files): - types="file" - else: - config=file_get_content(paths+"/"+files+"/config.conf") - if config: - config=json_decode(config) - zd={"name":files,"types":types,"config":config} - lists.append(zd) - data=return_list(lists,count=len(lis),pagenow=1,pagesize=len(lis)) - data['paths']=paths - "文件列表" - return successjson(data) -def ssltpl(): - "Let's Encrypt证书内容" - name=request.args.get("name") - paths="/etc/letsencrypt/live/"+name - chain=file_get_content(paths+"/chain.pem") - fullchain=file_get_content(paths+"/fullchain.pem") - privkey=file_get_content(paths+"/privkey.pem") - cert=file_get_content(paths+"/cert.pem") - data={ - "chain":chain, - "fullchain":fullchain, - "privkey":privkey, - "cert":cert - } - return successjson(data) - \ No newline at end of file diff --git a/app/intapp/controller/soft/page.py b/app/intapp/controller/soft/page.py deleted file mode 100644 index 9e87cb1..0000000 --- a/app/intapp/controller/soft/page.py +++ /dev/null @@ -1,34 +0,0 @@ -from .common import * -def home(): - if sysisphone(): - return response.tpl("../tplm/index/home") - else: - return response.tpl("index/home") -def pub(html): - if sysisphone(): - return response.tpl("../tplm/page/%s" % html) - else: - return response.tpl("page/%s" % html) -def s(fun,html): - id=request.args.get("id") - if sysisphone(): - lefttext=request.args.get('lefttext') - if not lefttext: - lefttext='应用' - lefturl=request.args.get('lefturl') - if not lefturl: - lefturl='myapp' - lefttype=request.args.get('lefttype') - if not lefttype: - lefttype='lefturl' - return response.tpl("../tplm/%s/%s" % (fun,html),id=id,lefttext=lefttext,lefturl=lefturl,lefttype=lefttype) - else: - return response.tpl("%s/%s" % (fun,html),id=id) -def soft(html): - id=request.args.get("id") - types=request.args.get("types") - data=sqlite("soft",model_intapp_soft_path).where("id",id).find() - if sysisphone(): - return response.tpl("../tplm/soft/%s" % html,id=id,data=data,types=types) - else: - return response.tpl("soft/%s" % html,id=id,data=data,types=types) \ No newline at end of file diff --git a/app/intapp/controller/soft/php.py b/app/intapp/controller/soft/php.py deleted file mode 100644 index d3e9798..0000000 --- a/app/intapp/controller/soft/php.py +++ /dev/null @@ -1,272 +0,0 @@ -from .common import * -def ini(id,is_upd=0): - "php.ini配置文件" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - if ar['platform']=='Linux': - filepath=paths+filenames+"/bin/php.ini" - elif ar['platform']=='Windows': - filepath=paths+filenames+"/php.ini" - else: - return errorjson(code=1,msg="不支持此时平台") - if is_upd: #修改配置 - G.setadminlog="修改配置ini" - data=request.get_json() - file_set_content(filepath,data['text']) - return successjson() - else: - data={ - 'ini':file_get_content(filepath), - 'php':ar - } - return successjson(data) -def www_conf(id,is_upd=0): - "www.conf配置文件" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - if ar['platform']=='Linux': - filepath=paths+filenames+"/etc/php-fpm.d/www.conf" - if 'php5.6' in filenames: - filepath=paths+filenames+"/etc/php-fpm.conf" - elif ar['platform']=='Windows': - filepath='' - else: - return errorjson(code=1,msg="不支持此时平台") - if is_upd: #修改配置 - G.setadminlog="修改配置www.conf" - data=request.get_json() - file_set_content(filepath,data['text']) - return successjson() - else: - data={ - 'www_conf':file_get_content(filepath), - 'php':ar - } - return successjson(data) -def phpfpm(id,is_upd=0): - "phpfpm配置信息" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - if ar['platform']=='Linux': - if not os.path.exists(paths+filenames+"/bin/conf"): - os.makedirs(paths+filenames+"/bin/conf") - filepath=paths+filenames+"/bin/conf/phpfpm.conf" - phpfpmpath=paths+filenames+"/etc/php-fpm.d/www.conf" - if 'php5.6' in filenames: - phpfpmpath=paths+filenames+"/etc/php-fpm.conf" - else: - filepath='' - phpfpmpath='' - if is_upd: #修改php-fpm配置信息 - data=request.get_json() - f = open(phpfpmpath) - con='' - while True: - line = f.readline() - if not line: - break - elif 'pm = ' in line and '=' in line: #运行描述 - line="pm = "+data['text']['pm']+"\n" - elif 'pm.max_children' in line and '=' in line:# 允许创建的最大子进程数 - line="pm.max_children = "+data['text']['max_children']+"\n" - elif 'pm.start_servers' in line and '=' in line:# 起始进程数(服务启动后初始进程数量) - line="pm.start_servers = "+data['text']['start_servers']+"\n" - elif 'pm.min_spare_servers' in line and '=' in line:# 起始进程数(服务启动后初始进程数量) - line="pm.min_spare_servers = "+data['text']['min_spare_servers']+"\n" - elif 'pm.max_spare_servers' in line and '=' in line:# 最大空闲进程数(当空闲进程达到此值时清理) - line="pm.max_spare_servers = "+data['text']['max_spare_servers']+"\n" - con=con+line - f.close() - f= open(phpfpmpath, "w") - f.write(con) - f.close() - file_set_content(filepath,json_encode(data['text'])) - return successjson() - else: - phpfpm=json_decode(file_get_content(filepath)) - if not phpfpm: - phpfpm='' - data={ - 'phpfpm':phpfpm, - 'php':ar - } - return successjson(data) -def base(id,is_upd=0): - "基本配置信息" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - if ar['platform']=='Linux': - if not os.path.exists(paths+filenames+"/bin/conf"): - os.makedirs(paths+filenames+"/bin/conf") - filepath=paths+filenames+"/bin/conf/base.ini" - phpinipath=paths+filenames+"/bin/php.ini" - elif ar['platform']=='Windows': - if not os.path.exists(paths+filenames+"/conf"): - os.makedirs(paths+filenames+"/conf") - filepath=paths+filenames+"/conf/base.ini" - phpinipath=paths+filenames+"/php.ini" - if is_upd: #修改基本配置信息 - #修改php.ini配置 - G.setadminlog="修改php.ini配置" - data=request.get_json() - f = open(phpinipath) - con='' - while True: - line = f.readline() - if not line: - break - elif 'max_execution_time' in line and '=' in line:#最大执行时间 - line="max_execution_time = "+data['text']['max_execution_time']+"\n" - elif 'max_input_time' in line and '=' in line:#最大输入时间 - line="max_input_time = "+data['text']['max_input_time']+"\n" - elif 'memory_limit' in line and '=' in line:#内存限制 - line="memory_limit = "+data['text']['memory_limit']+"M\n" - elif 'file_uploads' == line[0:12] and '=' in line:#是否允许文件上传 - line="file_uploads = "+data['text']['file_uploads']+"\n" - elif 'upload_max_filesize' in line and '=' in line:#上传大小限制 - line="upload_max_filesize = "+data['text']['upload_max_filesize']+"M\n" - elif 'max_file_uploads' in line and '=' in line:#上传数量限制 - line="max_file_uploads = "+data['text']['max_file_uploads']+"\n" - elif 'post_max_size' in line and '=' in line:#上传数量限制 - line="post_max_size = "+data['text']['post_max_size']+"M\n" - elif 'allow_url_fopen' in line and '=' in line: - line="allow_url_fopen = "+data['text']['allow_url_fopen']+"\n" - elif 'allow_url_include' in line and '=' in line: - line="allow_url_include = "+data['text']['allow_url_include']+"\n" - elif 'default_socket_timeout' in line and '=' in line: - line="default_socket_timeout = "+data['text']['default_socket_timeout']+"\n" - con=con+line - f.close() - f= open(phpinipath, "w") - f.write(con) - f.close() - file_set_content(filepath,json_encode(data['text'])) - # print(data['text']) - return successjson() - else: - base=json_decode(file_get_content(filepath)) - if not base: - base='' - data={ - 'base':base, - 'php':ar - } - return successjson(data) -def extenlist(id,is_upd=0): - "php扩展信息列表" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - lists=sqlite('php_exten',model_intapp_soft_php_exten_path).where('pid',id).select() - data={ - 'extenlist':lists, - 'php':ar - } - return successjson(data) -def log(id): - "待完善" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - filename=ar['filename'] - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - if ar['platform']=='Linux': - filepath=paths+filenames+"" - elif ar['platform']=='Windows': - filepath=paths+filenames+"" - data={ - 'log':file_get_content(filepath), - 'php':ar - } - return successjson(data) - -def add_php_exten(): - "增加php扩展" - G.setadminlog="安装php扩展" - data=request.get_json() - data['addtime']=times() - data['updtime']=times() - sqlite('php_exten',model_intapp_soft_php_exten_path).insert(data) - return successjson() -def del_php_exten(id): - "删除php扩展" - G.setadminlog="删除php扩展" - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).delete() - return successjson() - -def installext(id): - is_del=False #是否删除成功 - "安装php扩展和下载扩展" - G.setadminlog="安装php扩展和下载扩展" - ar=sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).find() - if ar['status']==0: - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':1,'msg':''}) - Queues.insert(target=__installextqu,args=(ar,),title="安装php-"+ar['title']+"扩展") - elif ar['status']==4: - "卸载扩展" - paths=request.get_json()['paths'] - if get_sysinfo()['uname'][0]=='Linux': - if os.path.exists(paths): - - confile=paths+"bin/php.ini" - f= open(confile, "r") - con='' - while True: - line = f.readline() - if not line: - break - elif str(ar['title']) in line: - line="" - is_del=True - con=con+line - f.close() - f= open(confile, "w") - f.write(con) - f.close() - - # confile=paths+"bin/php.ini" - # f= open(confile, "r") - # con=f.read() - # f.close() - # con=con.replace("extension="+str(ar['title'])+".so\n","") - # f= open(confile, "w") - # f.write(con) - # f.close() - # if is_del: - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':0,'msg':''}) - if 'php7.0' in paths: - os.system("pkill php70-fpm && php70-fpm -c "+paths+"php7.0/etc/php.ini") - elif 'php7.1' in paths: - os.system("pkill php71-fpm && php71-fpm -c "+paths+"php7.1/etc/php.ini") - elif 'php7.2' in paths: - os.system("pkill php72-fpm && php72-fpm -c "+paths+"php7.2/etc/php.ini") - elif 'php7.3' in paths: - os.system("pkill php73-fpm && php73-fpm -c "+paths+"php7.3/etc/php.ini") - elif 'php7.4' in paths: - os.system("pkill php74-fpm && php74-fpm -c "+paths+"php7.4/etc/php.ini") - # else: - # return errorjson(code=1,msg='卸载失败') - else: - return errorjson(code=1,msg='php文件夹错误') - return successjson() -def get_exten(id): - return successjson(sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).find()) -def __installextqu(ar): - "安装php扩展" - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':3,'msg':''}) - try: - cmd="wget "+config.domain['kcwebfile']+"/"+ar['filename'] - # os.system(cmd) - print(cmd) - pi=subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - if 'success' in strs: - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':4,'msg':''}) - else: - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':0,'msg':'安装失败'}) - # sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':4,'msg':''}) - except Exception as e: - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':0,'msg':'安装失败'+str(e)}) \ No newline at end of file diff --git a/app/intapp/controller/soft/redis.py b/app/intapp/controller/soft/redis.py deleted file mode 100644 index 1464e6a..0000000 --- a/app/intapp/controller/soft/redis.py +++ /dev/null @@ -1,71 +0,0 @@ -from .common import * -def conf(id,is_upd=0): - "redis配置文件信息" - is_upd=int(is_upd) - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - if ar['platform']=='Linux': - filepath=paths+filenames+"/redis.conf" - else: - return errorjson(code=1,msg="不支持此时平台") - if is_upd: #修改配置 - data=request.get_json() - if not data['text']: - return errorjson(code=1,msg='不允许清空配置文件') - file_set_content(filepath,data['text']) - return successjson() - else: - data=file_get_content(filepath) - # print(filepath) - return successjson(data) -def base(id,is_upd=0): - "redis配置文件信息" - is_upd=int(is_upd) - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - - if ar['platform']=='Linux': - filepath=paths+filenames+"/redis.conf" - jsonpath=paths+filenames+"/redis.json" - else: - return errorjson(code=1,msg="不支持此时平台") - if is_upd: #修改配置 - G.setadminlog="修改redis配置" - data=request.get_json() - f = open(filepath) - con='' - while True: - line = f.readline() - if not line: - break - elif 'bind ' in line and '\n' in line and '#' not in line: - line="bind "+data['bind']+"\n" - elif 'port ' in line and '\n' in line and '#' not in line: - line="port "+data['port']+"\n" - elif 'timeout ' in line and '\n' in line and '#' not in line: - line="timeout "+data['timeout']+"\n" - elif 'maxclients ' in line and '\n' in line: - line="maxclients "+data['maxclients']+"\n" - elif 'databases ' in line and '\n' in line and '#' not in line: - line="databases "+data['databases']+"\n" - elif 'requirepass ' in line and '\n' in line: - if data['requirepass']: - line="requirepass "+data['requirepass']+"\n" - else: - line="# requirepass "+data['requirepass']+"\n" - elif 'maxmemory ' in line and '\n' in line and len(line)<20: - line="maxmemory "+data['maxmemory']+"\n" - con=con+line - f.close() - f= open(filepath, "w") - f.write(con) - f.close() - file_set_content(jsonpath,json_encode(data)) - return successjson() - else: - v=file_get_content(jsonpath) - data=json_decode(v) - data['ar']=ar - return successjson(data) \ No newline at end of file diff --git a/app/intapp/controller/soft/role.txt b/app/intapp/controller/soft/role.txt deleted file mode 100644 index 1da7c1d..0000000 --- a/app/intapp/controller/soft/role.txt +++ /dev/null @@ -1,44 +0,0 @@ -#以下是该插件的路由,index容器会自动把以下路由加入到权限管理中 该文件必须使用utf-8编码 -软件页面,/intapp/soft/index/index -软件信息,/intapp/soft/index/gettitle -软件列表,/intapp/soft/index/softlist -更新软件列表,/intapp/soft/index/updatesoftlist -软件状态描述,/intapp/soft/index/getstatus -安装软件,/intapp/soft/index/insert -启动软件,/intapp/soft/index/start -停止软件,/intapp/soft/index/stop -卸载软件,/intapp/soft/index/uninstall -gitssh公钥,/intapp/soft/index/gitssh -软件设置页面,/intapp/soft/page/soft - -frp服务端内容,/intapp/soft/frp/get_server -frp运行状态,/intapp/soft/frp/run_status -frp重启,/intapp/soft/frp/restart -frp停止,/intapp/soft/frp/stop -修改frp服务端配置,/intapp/soft/frp/upd_server -frp客户端内容,/intapp/soft/frp/get_client -修改frp客户端配置,/intapp/soft/frp/upd_client - -mongodb管理,/intapp/soft/mongodb - -获取mysql配置,/intapp/soft/mysql/get_data -修改mysql配置,/intapp/soft/mysql/upd_my -修改mysql密码,/intapp/soft/mysql/upd_data -备份mysql,/intapp/soft/mysql/backups - -nginx网站管理,/intapp/soft/page/s -修改nginx配置,/intapp/soft/nginx/index -nginx伪静态模板,/intapp/soft/nginx/anphp -nginx网站信息,/intapp/soft/nginx/webdescribesfind -nginx网站列表,/intapp/soft/nginx/weblist -添加更新nginx网站,/intapp/soft/nginx/add_web -删除nginx网站,/intapp/soft/nginx/del_web -获取ssl,/intapp/soft/nginx/getssl -获取伪静态内容,/intapp/soft/nginx/getrewr -获取配置文件,/intapp/soft/nginx/getconfig -证书夹,/intapp/soft/nginx/sslfolde -证书内容,/intapp/soft/nginx/ssltpl - -php管理,/intapp/soft/php - -redis管理,/intapp/soft/redis diff --git a/app/intapp/controller/soft/tpl/index/home.html b/app/intapp/controller/soft/tpl/index/home.html deleted file mode 100644 index cc19803..0000000 --- a/app/intapp/controller/soft/tpl/index/home.html +++ /dev/null @@ -1,430 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
-
- - - 搜索 - - - 更新软件列表 - -
-
- - % if config.app['appmode']=='develop': - - - - % endif - - - - - - - - - - - - - - - - - - -
-
- - -
- - - - - - - - - - - - - - - 如:/usr/local/php/ - - - - - - - - - - 注:需要在后端接口上配置wget文件地址 - - - - Linux - Windows - - - - - - -
- - - diff --git a/app/intapp/controller/soft/tpl/index/web.html b/app/intapp/controller/soft/tpl/index/web.html deleted file mode 100644 index 7d62981..0000000 --- a/app/intapp/controller/soft/tpl/index/web.html +++ /dev/null @@ -1,582 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
-
-    - - - 搜索 - 添加网站 - - - 下载数据 - - 上传intapp_soft.zip - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
域名
端口 - 上传限制:MB
网站名
配置文件模板 - - - - -
备注
网站目录 - - -
-
- - - - - - - -
- - - - - - - 如:Access-Control-Allow-Origin * - 如:403 /403.html - - -
- 自定义配置:自定义响应或自定义错误页面 - -
- -
-
- - - - - - - - -
- - - - - - - - - -   - - -
- nginx负载均衡是一个代理均衡转发器 - -
- -
- - 取 消 - 修改添加 - -
- - -
-
- - -
-
- 您已配置Let's证书


- ssl_certificate :{{admin.ssl_certificate}}

- ssl_certificate_key :{{admin.ssl_certificate_key}}

- 使用自有证书 -
-
-
- 密钥(KEY) - -
-
- 证书(PEM格式) - -
- 确定 -
-
-
- - -
- - - - - -
- 保存
- 选择伪静态模板就可以了,修改了记得要保存哦!重启nginx生效 -
- -
- - 确定 -
-
- -
- - - - - - - -
支持域名有效期
- - {{item1.domain}}     - - - - {{time_date(item.config.createtime+7776000,true)}} - - - - 使用 - -
-
-
-
- - - diff --git a/app/intapp/controller/soft/tpl/soft/frp.html b/app/intapp/controller/soft/tpl/soft/frp.html deleted file mode 100644 index edfcb44..0000000 --- a/app/intapp/controller/soft/tpl/soft/frp.html +++ /dev/null @@ -1,250 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
- - - - - 重启 - 停止 - - 保存 - - - - - - -
- 重启 - 停止 - - - - 这是服端监听的地址 - - - - 这是服端监听的端口 - - - - 这是upd监听的端口 - - - - 这是kcp监听的端口 - - - - 这是http监听的端口 - - - - 这是https监听的端口 - - - - 这是dashboard监听的ip地址 - - - - 这是dashboard监听的端口 - - - - 这是dashboard监听的用户名 - - - - 这是dashboard监听的密码 - - - - 这是frp的验证机制 - - - - 这是frp的验证串的有效时间 - - - - - - - - 日志保持多少天 - - - - - - - - 白名单端口 - - - - 最大值进程数 - - - - - - - - - - - - - - - 保存 - - -
- -
- - - 保存 - -
-
-
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/git.html b/app/intapp/controller/soft/tpl/soft/git.html deleted file mode 100644 index ce87f2d..0000000 --- a/app/intapp/controller/soft/tpl/soft/git.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
-
- -
- 您可以使用root身份执行以下命令生成ssh密钥

- -
-
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/kodexplorer.html b/app/intapp/controller/soft/tpl/soft/kodexplorer.html deleted file mode 100644 index 6f38ff4..0000000 --- a/app/intapp/controller/soft/tpl/soft/kodexplorer.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - -
-
-
- - - - - - - - - - - - 添加 - -
-
-
- - - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/mongodb.html b/app/intapp/controller/soft/tpl/soft/mongodb.html deleted file mode 100644 index ebdbc92..0000000 --- a/app/intapp/controller/soft/tpl/soft/mongodb.html +++ /dev/null @@ -1,436 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
- - - -
- -

可以在终端中执行以下命令创建可以 -

- WORK_DIR=/data/mongodb
- mkdir -p $WORK_DIR/key/
- cd $WORK_DIR/key/
- openssl rand -base64 756 > mongo.key
- chmod 600 mongo.key
-
-

- 保存 -
-
- -
- config服务 (注:这是一个config服务) - - - - - - -
- 通常生产环境每台机器应该只有一个,您可以在其他机器上开启config服务后手动添加到副本集中
- -
- 运行中 - 停止服务 - 重启服务 -
-
- 已停止 - 启动服务 -
-
- 待初始化 - 初始化 -
-

-
- 副本集初始化(如果需要,生产环境应该是内网ip而不是127.0.0.1)
-
- -
-增加副本集示例 -
-mongo --port {{data.configs.server[0]['port']}}
-use admin
-rs.add({_id:1,host:'{{data.get_local_ip}}:27002',priority:2})#增加主机 priority:优先级
-
-删除副本集示例 -
-mongo --port {{data.configs.server[0]['port']}}
-use admin
-rs.remove('{{data.get_local_ip}}:27002')
-
-
- -
-
- -
- configdb: -
示例:configdb = configs/192.168.1.101:27001,192.168.1.102:27001,192.168.1.103:27001,则无法扩展外部服务器
- 上述ip和端口是已经启动的配置服务,可以是其他机器上的mongodb配置服务 -
- 路由服务 (注:这是一个路由服务) - - - - - - -
- -
-
- 运行中 - 停止服务 - 重启服务 -
-
- 已停止 - 启动服务 -
-
- 待初始化 - 初始化 -
-
-
- 初始化用户
-
- -
- 在路由中添加分片,如下示例
-
-mongo --port {{data.mongos.server[0]['port']}}
-use admin
-db.auth('admin','admin')
-sh.addShard("shard1/192.168.1.101:29001,192.168.1.102:29001") #shard1是分片集群id
-sh.status()
-
-
-
-
- -
-
- 分片服务名{{indexs+1}}: - - - - - - - -
- 通常生产环境每台机器应该只有一个,您可以在其他机器上开启分片服务后手动添加到副本集中
- -
- 运行中 - 停止服务 - 重启服务 -
-
- 已停止 - 启动服务 -
-
- 待初始化 - 初始化 -
-

-
- 副本集初始化(生产环境应该是内网ip而不是127.0.0.1)
- -
-
- -
-
-
- - - -
- - - - - - - - - - - - - -
绑定ip端口服务目录
- - 运行中 - 停止 - - - 已停止 - 启动 - - -
-
- - 保存 -
- -
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/mysql.html b/app/intapp/controller/soft/tpl/soft/mysql.html deleted file mode 100644 index e31a335..0000000 --- a/app/intapp/controller/soft/tpl/soft/mysql.html +++ /dev/null @@ -1,257 +0,0 @@ - - - - - - - kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - -
- - - - 8.0版本不支持可视化修改 - - - - 建议与mysql安装目录分开 - - - - port 监听器端口 - - - - max_connections 最大连接数 - - -
- max_allowed_packet 最大接受数据的包大小 -
- -
- expire_logs_days 日志保留时间(天) -
- -
- query_cache_limit 指定单个查询可以使用的缓冲区的大小 -
- -
- query_cache_size 查询的缓存大小设置 -
- -
- query_cache_type 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 -
- -
- wait_timeout 超时等待时间,单位秒,即一个connection在若干秒内无响应 -
- -
- thread_cache_size 用于缓存空闲的线程 -
- -
- key_buffer_size 用于指定索引缓冲区的大小 -
-
-
- 保存 - 加入开机启动 -
- -
- -
-                        
-                    
-
- 保存 -
-
-
-
-
-
- - - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/nginx.html b/app/intapp/controller/soft/tpl/soft/nginx.html deleted file mode 100644 index 1417261..0000000 --- a/app/intapp/controller/soft/tpl/soft/nginx.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - - - -
-                    
-                
-
- 保存 - 加入开机启动 - 该配置文件只对该网站有效,修改后重启nginx生效 -
-
- -
- -
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/php.html b/app/intapp/controller/soft/tpl/soft/php.html deleted file mode 100644 index 8085943..0000000 --- a/app/intapp/controller/soft/tpl/soft/php.html +++ /dev/null @@ -1,415 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - - - - - - - MB - - - 单个请求上传的文件的最大数量 - - - 秒 - - - 秒 - - - MB - - - MB - - - - - - 是否允许将url(如http://或 ftp://)作为文件处理。 - - - - - - 是否允许include/require以文件形式打开url(如http://或 ftp://)。 - - - - 基于套接字的流的默认超时(秒) - - - 保存 -
-
- -
- - - - - - - - - - 允许创建的最大子进程数 - - - - 起始进程数(服务启动后初始进程数量) - - - - 最小空闲进程数(清理空闲进程后的保留数量) - - - - 最大空闲进程数(当空闲进程达到此值时清理) - - - 保存 - 加入开机启动 -
-
- -
- % if config.app['appmode']=='develop': - - % endif - - - - - - - - -
名称说明状态操作
{{item.title}}{{item.describes}} - % if config.app['appmode']=='develop': - {{item.filename}} - % endif - - - - - - 安装 - - - 等待下载 - - - 正在下载 - - - 正在安装 - - - 卸载 - - - 正在卸载... - - % if config.app['appmode']=='develop': - 删除 - % endif -
-
-
- - - - -
-                
-            
- 保存 - 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
-
- - - -
-                
-            
- 保存 - 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
-
-
- - - - - - - - - - - - - - - - - - - 添加 - -
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/phpmyadmin.html b/app/intapp/controller/soft/tpl/soft/phpmyadmin.html deleted file mode 100644 index 053916a..0000000 --- a/app/intapp/controller/soft/tpl/soft/phpmyadmin.html +++ /dev/null @@ -1,90 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - -
-
-
- - - - - - - - - - - - 添加 - -
-
-
- - - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/redis.html b/app/intapp/controller/soft/tpl/soft/redis.html deleted file mode 100644 index 4df6dbd..0000000 --- a/app/intapp/controller/soft/tpl/soft/redis.html +++ /dev/null @@ -1,182 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- - - 绑定IP - - - 端口 - - - 空闲连接超时时间,0表示不断开 - - - 最大连接数 - - - 数据库数量 - - - redis密码,留空代表没有设置密码 - - - MB,最大使用内存,0表示不限制 - - - 保存 - 加入开机启动 -
-
- - - - -
-                
-            
- 保存 - 修改后重启redis生效
-
-
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/index/home.html b/app/intapp/controller/soft/tplm/index/home.html deleted file mode 100644 index 361a9fb..0000000 --- a/app/intapp/controller/soft/tplm/index/home.html +++ /dev/null @@ -1,297 +0,0 @@ - - - - -kcweb云管 - - - - - - - - - - - - - - - - - - -
-
- - - -
-
- -
-
- -
- - -
-
-
-
-
{{item.title}}{{item.edition}}
-
{{item.describes}}
-
-
-
位置:{{item.paths}}{{item.title}}{{item.edition}}
-
- -
-
-
- 待安装 - 等待中 - 下载中 - 安装中 - 卸载中 - 正在启动 - 正在停止服务 - - - - 已停止 - 启动 - - - - 客户端 - 客户端 - 服务端 - 服务端 - - - - - - - 运行中 - 停止 - 重启 - - - -
-
-
更新于:{{time_date(item.updtime)}}
-
-
-
-
- -
-
- 加载中... -
-
- 下一页 - 我已到底了 -
-
-
-
- - - diff --git a/app/intapp/controller/soft/tplm/index/web.html b/app/intapp/controller/soft/tplm/index/web.html deleted file mode 100644 index a38c9cf..0000000 --- a/app/intapp/controller/soft/tplm/index/web.html +++ /dev/null @@ -1,395 +0,0 @@ - - - - -kcweb云管 - - - - - - - - - - - - - - - - - - -
-
- - - -
-
- -
-
- -
- - -
-
-
-
-
{{item.title}}
-
运行在负载均衡代理转发器中
-
{{item.describes}}
- php伪静态配置 -
-
- - 运行中 - - - 已停止 - -
-
-
-
- {{item1}} -
-
-
{{time_date(item.updtime)}}
-
-
-
-
- -
-
- 加载中... -
-
- 下一页 - 暂无数据 - 我已到底了 -
-
- -
- - - - - - - - - - - - - - - - - - - - - -
- -
-
- -
-
- -
-
- 添加响应 - 自定义配置:自定义响应或自定义错误页面 -
- -
- -
-
- -
-
- - -
-
- -
-
- 添加负载均衡信息 - nginx负载均衡是一个代理均衡转发器 -
-
- 修改 - 添加 -
-
-
-
- -
- Let's Encrypt证书夹 -
-
- 您已配置Let's证书
- ssl_certificate :{{admin.ssl_certificate}}
- ssl_certificate_key :{{admin.ssl_certificate_key}}
-
-
- - 保存 - - - - - -
fewaf
-
- -
- -
-
-
- - - diff --git a/app/intapp/controller/soft/tplm/soft/frp.html b/app/intapp/controller/soft/tplm/soft/frp.html deleted file mode 100644 index c137b73..0000000 --- a/app/intapp/controller/soft/tplm/soft/frp.html +++ /dev/null @@ -1,250 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
- - - - - 重启 - 停止 - - 保存 - - - - - - -
- 重启 - 停止 - - - - 这是服端监听的地址 - - - - 这是服端监听的端口 - - - - 这是upd监听的端口 - - - - 这是kcp监听的端口 - - - - 这是http监听的端口 - - - - 这是https监听的端口 - - - - 这是dashboard监听的ip地址 - - - - 这是dashboard监听的端口 - - - - 这是dashboard监听的用户名 - - - - 这是dashboard监听的密码 - - - - 这是frp的验证机制 - - - - 这是frp的验证串的有效时间 - - - - - - - - 日志保持多少天 - - - - - - - - 白名单端口 - - - - 最大值进程数 - - - - - - - - - - - - - - - 保存 - - -
- -
- - - 保存 - -
-
-
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/git.html b/app/intapp/controller/soft/tplm/soft/git.html deleted file mode 100644 index ce87f2d..0000000 --- a/app/intapp/controller/soft/tplm/soft/git.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
-
- -
- 您可以使用root身份执行以下命令生成ssh密钥

- -
-
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/kodexplorer.html b/app/intapp/controller/soft/tplm/soft/kodexplorer.html deleted file mode 100644 index 6f38ff4..0000000 --- a/app/intapp/controller/soft/tplm/soft/kodexplorer.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - -
-
-
- - - - - - - - - - - - 添加 - -
-
-
- - - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/mongodb.html b/app/intapp/controller/soft/tplm/soft/mongodb.html deleted file mode 100644 index 417da13..0000000 --- a/app/intapp/controller/soft/tplm/soft/mongodb.html +++ /dev/null @@ -1,436 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
- - - -
- -

可以在终端中执行以下命令创建可以 -

- WORK_DIR=/data/mongodb
- mkdir -p $WORK_DIR/key/
- cd $WORK_DIR/key/
- openssl rand -base64 756 > mongo.key
- chmod 600 mongo.key
-
-

- 保存 -
-
- -
- config服务 (注:这是一个config服务) - - - - - - -
- 通常生产环境每台机器应该只有一个,您可以在其他机器上开启config服务后手动添加到副本集中
- -
- 运行中 - 停止服务 - 重启服务 -
-
- 已停止 - 启动服务 -
-
- 待初始化 - 初始化 -
-

-
- 副本集初始化(如果需要,生产环境应该是内网ip而不是127.0.0.1)
-
- -
-增加副本集示例 -
-mongo --port {{data.configs.server[0]['port']}}
-use admin
-rs.add({_id:1,host:'{{data.get_local_ip}}:27002',priority:2})#增加主机 priority:优先级
-
-删除副本集示例 -
-mongo --port {{data.configs.server[0]['port']}}
-use admin
-rs.remove('{{data.get_local_ip}}:27002')
-
-
- -
-
- -
- configdb: -
示例:configdb = configs/192.168.1.101:27001,192.168.1.102:27001,192.168.1.103:27001,则无法扩展外部服务器
- 上述ip和端口是已经启动的配置服务,可以是其他机器上的mongodb配置服务 -
- 路由服务 (注:这是一个路由服务) - - - - - - -
- -
-
- 运行中 - 停止服务 - 重启服务 -
-
- 已停止 - 启动服务 -
-
- 待初始化 - 初始化 -
-
-
- 初始化用户
-
- -
- 在路由中添加分片,如下示例
-
-mongo --port {{data.mongos.server[0]['port']}}
-use admin
-db.auth('admin','admin')
-sh.addShard("shard1/192.168.1.101:29001,192.168.1.102:29001") #shard1是分片集群id
-sh.status()
-
-
-
-
- -
-
- 分片服务名{{indexs+1}}: - - - - - - - -
- 通常生产环境每台机器应该只有一个,您可以在其他机器上开启分片服务后手动添加到副本集中
- -
- 运行中 - 停止服务 - 重启服务 -
-
- 已停止 - 启动服务 -
-
- 待初始化 - 初始化 -
-

-
- 副本集初始化(生产环境应该是内网ip而不是127.0.0.1)
- -
-
- -
-
-
- - - -
- - - - - - - - - - - - - -
绑定ip端口服务目录
- - 运行中 - 停止 - - - 已停止 - 启动 - - -
-
- - 保存 -
- -
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/mysql.html b/app/intapp/controller/soft/tplm/soft/mysql.html deleted file mode 100644 index 3603e82..0000000 --- a/app/intapp/controller/soft/tplm/soft/mysql.html +++ /dev/null @@ -1,203 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - -
- - - - - - - 建议与mysql安装目录分开 - - - - port 监听器端口 - - - - max_connections 最大连接数 - - -
- max_allowed_packet 最大接受数据的包大小 -
- -
- expire_logs_days 日志保留时间(天) -
- -
- query_cache_limit 指定单个查询可以使用的缓冲区的大小 -
- -
- query_cache_size 查询的缓存大小设置 -
- -
- query_cache_type 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 -
- -
- wait_timeout 超时等待时间,单位秒,即一个connection在若干秒内无响应 -
- -
- thread_cache_size 用于缓存空闲的线程 -
- -
- key_buffer_size 用于指定索引缓冲区的大小 -
-
-
- 保存 - 加入开机启动 -
- -
- -
-                        
-                    
-
- 保存 -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/nginx.html b/app/intapp/controller/soft/tplm/soft/nginx.html deleted file mode 100644 index 1417261..0000000 --- a/app/intapp/controller/soft/tplm/soft/nginx.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - - - -
-                    
-                
-
- 保存 - 加入开机启动 - 该配置文件只对该网站有效,修改后重启nginx生效 -
-
- -
- -
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/php.html b/app/intapp/controller/soft/tplm/soft/php.html deleted file mode 100644 index 8085943..0000000 --- a/app/intapp/controller/soft/tplm/soft/php.html +++ /dev/null @@ -1,415 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - - - - - - - MB - - - 单个请求上传的文件的最大数量 - - - 秒 - - - 秒 - - - MB - - - MB - - - - - - 是否允许将url(如http://或 ftp://)作为文件处理。 - - - - - - 是否允许include/require以文件形式打开url(如http://或 ftp://)。 - - - - 基于套接字的流的默认超时(秒) - - - 保存 -
-
- -
- - - - - - - - - - 允许创建的最大子进程数 - - - - 起始进程数(服务启动后初始进程数量) - - - - 最小空闲进程数(清理空闲进程后的保留数量) - - - - 最大空闲进程数(当空闲进程达到此值时清理) - - - 保存 - 加入开机启动 -
-
- -
- % if config.app['appmode']=='develop': - - % endif - - - - - - - - -
名称说明状态操作
{{item.title}}{{item.describes}} - % if config.app['appmode']=='develop': - {{item.filename}} - % endif - - - - - - 安装 - - - 等待下载 - - - 正在下载 - - - 正在安装 - - - 卸载 - - - 正在卸载... - - % if config.app['appmode']=='develop': - 删除 - % endif -
-
-
- - - - -
-                
-            
- 保存 - 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
-
- - - -
-                
-            
- 保存 - 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
-
-
- - - - - - - - - - - - - - - - - - - 添加 - -
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/phpmyadmin.html b/app/intapp/controller/soft/tplm/soft/phpmyadmin.html deleted file mode 100644 index 053916a..0000000 --- a/app/intapp/controller/soft/tplm/soft/phpmyadmin.html +++ /dev/null @@ -1,90 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - -
-
-
- - - - - - - - - - - - 添加 - -
-
-
- - - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/redis.html b/app/intapp/controller/soft/tplm/soft/redis.html deleted file mode 100644 index 4df6dbd..0000000 --- a/app/intapp/controller/soft/tplm/soft/redis.html +++ /dev/null @@ -1,182 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- - - 绑定IP - - - 端口 - - - 空闲连接超时时间,0表示不断开 - - - 最大连接数 - - - 数据库数量 - - - redis密码,留空代表没有设置密码 - - - MB,最大使用内存,0表示不限制 - - - 保存 - 加入开机启动 -
-
- - - - -
-                
-            
- 保存 - 修改后重启redis生效
-
-
-
- - - \ No newline at end of file -- Gitee From ccad50702634dc33e5cb54592ef8ca3a331bdef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Sun, 25 Apr 2021 22:10:12 +0800 Subject: [PATCH 08/19] kun --- app/intapp/controller/index/admin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/intapp/controller/index/admin.py b/app/intapp/controller/index/admin.py index 2ef2990..a31f7db 100644 --- a/app/intapp/controller/index/admin.py +++ b/app/intapp/controller/index/admin.py @@ -265,6 +265,7 @@ def updaterole(id=0): data['roleroute']=json_encode(data['roleroute']) except:pass else: + del data['admin_id'] sqlite("role",model_app_path).where("id",id).update(data) return successjson() def deleterole(): -- Gitee From 56bb2caca8a5645a4cabac937779c7eaf5326c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Tue, 27 Apr 2021 00:20:53 +0800 Subject: [PATCH 09/19] kun --- app/intapp/controller/index/admin.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/intapp/controller/index/admin.py b/app/intapp/controller/index/admin.py index a31f7db..ca8a0df 100644 --- a/app/intapp/controller/index/admin.py +++ b/app/intapp/controller/index/admin.py @@ -178,6 +178,14 @@ def update(id=0): data.pop('logintime') data.pop('addtime') data.pop('password') + if G.userinfo['role']['id']!=1: + del data['phone'] + del data['username'] + del data['nickname'] + del data['name'] + del data['logintime'] + del data['icon'] + del data['addtime'] del data['title'] del data['describes'] except:pass -- Gitee From cec55f2913c15ac426faae7dac99a14504ca081d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Sat, 22 May 2021 01:00:03 +0800 Subject: [PATCH 10/19] k --- app/intapp/controller/__init__.py | 3 +- app/intapp/controller/soft/__init__.py | 8 + app/intapp/controller/soft/common/SOFT.py | 248 ++++++++ app/intapp/controller/soft/common/__init__.py | 2 + app/intapp/controller/soft/common/autoload.py | 10 + .../soft/common/file/sqlite/.gitignore | 1 + .../soft/common/file/sqlite/php_exten | Bin 0 -> 24576 bytes app/intapp/controller/soft/common/file/time | 1 + app/intapp/controller/soft/common/model.py | 85 +++ app/intapp/controller/soft/frp.py | 138 +++++ app/intapp/controller/soft/index.py | 131 ++++ app/intapp/controller/soft/install.txt | 1 + app/intapp/controller/soft/mongodb.py | 253 ++++++++ app/intapp/controller/soft/mysql copy.py | 310 ++++++++++ app/intapp/controller/soft/mysql.py | 338 ++++++++++ app/intapp/controller/soft/nginx.py | 419 +++++++++++++ app/intapp/controller/soft/page.py | 34 + app/intapp/controller/soft/php.py | 272 ++++++++ app/intapp/controller/soft/redis.py | 71 +++ app/intapp/controller/soft/role.txt | 44 ++ .../controller/soft/tpl/index/home.html | 430 +++++++++++++ app/intapp/controller/soft/tpl/index/web.html | 582 ++++++++++++++++++ app/intapp/controller/soft/tpl/soft/frp.html | 250 ++++++++ app/intapp/controller/soft/tpl/soft/git.html | 69 +++ .../controller/soft/tpl/soft/kodexplorer.html | 88 +++ .../controller/soft/tpl/soft/mongodb.html | 436 +++++++++++++ .../controller/soft/tpl/soft/mysql.html | 257 ++++++++ .../controller/soft/tpl/soft/nginx.html | 171 +++++ app/intapp/controller/soft/tpl/soft/php.html | 415 +++++++++++++ .../controller/soft/tpl/soft/phpmyadmin.html | 90 +++ .../controller/soft/tpl/soft/redis.html | 182 ++++++ .../controller/soft/tplm/index/home.html | 297 +++++++++ .../controller/soft/tplm/index/web.html | 395 ++++++++++++ app/intapp/controller/soft/tplm/soft/frp.html | 250 ++++++++ app/intapp/controller/soft/tplm/soft/git.html | 69 +++ .../soft/tplm/soft/kodexplorer.html | 88 +++ .../controller/soft/tplm/soft/mongodb.html | 436 +++++++++++++ .../controller/soft/tplm/soft/mysql.html | 203 ++++++ .../controller/soft/tplm/soft/nginx.html | 171 +++++ app/intapp/controller/soft/tplm/soft/php.html | 415 +++++++++++++ .../controller/soft/tplm/soft/phpmyadmin.html | 90 +++ .../controller/soft/tplm/soft/redis.html | 182 ++++++ 42 files changed, 7934 insertions(+), 1 deletion(-) create mode 100644 app/intapp/controller/soft/__init__.py create mode 100644 app/intapp/controller/soft/common/SOFT.py create mode 100644 app/intapp/controller/soft/common/__init__.py create mode 100644 app/intapp/controller/soft/common/autoload.py create mode 100644 app/intapp/controller/soft/common/file/sqlite/.gitignore create mode 100644 app/intapp/controller/soft/common/file/sqlite/php_exten create mode 100644 app/intapp/controller/soft/common/file/time create mode 100644 app/intapp/controller/soft/common/model.py create mode 100644 app/intapp/controller/soft/frp.py create mode 100644 app/intapp/controller/soft/index.py create mode 100644 app/intapp/controller/soft/install.txt create mode 100644 app/intapp/controller/soft/mongodb.py create mode 100644 app/intapp/controller/soft/mysql copy.py create mode 100644 app/intapp/controller/soft/mysql.py create mode 100644 app/intapp/controller/soft/nginx.py create mode 100644 app/intapp/controller/soft/page.py create mode 100644 app/intapp/controller/soft/php.py create mode 100644 app/intapp/controller/soft/redis.py create mode 100644 app/intapp/controller/soft/role.txt create mode 100644 app/intapp/controller/soft/tpl/index/home.html create mode 100644 app/intapp/controller/soft/tpl/index/web.html create mode 100644 app/intapp/controller/soft/tpl/soft/frp.html create mode 100644 app/intapp/controller/soft/tpl/soft/git.html create mode 100644 app/intapp/controller/soft/tpl/soft/kodexplorer.html create mode 100644 app/intapp/controller/soft/tpl/soft/mongodb.html create mode 100644 app/intapp/controller/soft/tpl/soft/mysql.html create mode 100644 app/intapp/controller/soft/tpl/soft/nginx.html create mode 100644 app/intapp/controller/soft/tpl/soft/php.html create mode 100644 app/intapp/controller/soft/tpl/soft/phpmyadmin.html create mode 100644 app/intapp/controller/soft/tpl/soft/redis.html create mode 100644 app/intapp/controller/soft/tplm/index/home.html create mode 100644 app/intapp/controller/soft/tplm/index/web.html create mode 100644 app/intapp/controller/soft/tplm/soft/frp.html create mode 100644 app/intapp/controller/soft/tplm/soft/git.html create mode 100644 app/intapp/controller/soft/tplm/soft/kodexplorer.html create mode 100644 app/intapp/controller/soft/tplm/soft/mongodb.html create mode 100644 app/intapp/controller/soft/tplm/soft/mysql.html create mode 100644 app/intapp/controller/soft/tplm/soft/nginx.html create mode 100644 app/intapp/controller/soft/tplm/soft/php.html create mode 100644 app/intapp/controller/soft/tplm/soft/phpmyadmin.html create mode 100644 app/intapp/controller/soft/tplm/soft/redis.html diff --git a/app/intapp/controller/__init__.py b/app/intapp/controller/__init__.py index 90b3d04..cace474 100644 --- a/app/intapp/controller/__init__.py +++ b/app/intapp/controller/__init__.py @@ -9,4 +9,5 @@ def error(e,data): header={"Content-Type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"*"} header['Location']="/intapp/index/plug/index/intapp/"+plug return '{"code":1,"msg":"您访问的地址不存在","data":"'+str(e)+'"}','302 Found',header -from . import index \ No newline at end of file +from . import index +from . import soft \ No newline at end of file diff --git a/app/intapp/controller/soft/__init__.py b/app/intapp/controller/soft/__init__.py new file mode 100644 index 0000000..f7a8da3 --- /dev/null +++ b/app/intapp/controller/soft/__init__.py @@ -0,0 +1,8 @@ +from . import index +from . import page +from . import nginx +from . import mysql +from . import redis +from . import mongodb +from . import frp +from . import php \ No newline at end of file diff --git a/app/intapp/controller/soft/common/SOFT.py b/app/intapp/controller/soft/common/SOFT.py new file mode 100644 index 0000000..54ad594 --- /dev/null +++ b/app/intapp/controller/soft/common/SOFT.py @@ -0,0 +1,248 @@ +# -*- coding: utf-8 -*- +from .model import * +class SOFT: + def softlist(kw,pagenow,pagesize): + "软件列表" + if config.app['appmode']=='develop': + where="1=1" + else: + where="platform='"+get_sysinfo()['uname'][0]+"'" + if kw: + where+=" and title LIKE '%"+kw+"%' or describes LIKE '%"+kw+"%'" + lists=sqlite("soft",model_intapp_soft_path).where(where).page(pagenow,pagesize).select() + if len(lists) < 1: + SOFT.updatesoftlist() + lists=sqlite("soft",model_intapp_soft_path).where(where).page(pagenow,pagesize).select() + if 'Linux' in get_sysinfo()['platform']: + i=0 + for k in lists: + if k['status'] == 0 and k['platform']=='Linux': #检查软件是否已经安装 + if (os.path.exists(k['paths']+k['title']+k['edition'])) : + lists[i]['status']=4 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':lists[i]['status']}) + if (k['status'] == 10 or k['status'] == 4) and k['platform']=='Linux': #检查软件是否在运行中 + if 'nginx' in k['title'] : + if not get_process_id('nginx'): + if k['status'] == 10: + lists[i]['status']=4 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 + else: + if k['status'] == 4: + lists[i]['status']=10 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 + elif 'redis' in k['title']: + if not get_process_id('redis'): + if k['status'] == 10: + lists[i]['status']=4 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 + else: + if k['status'] == 4: + lists[i]['status']=10 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 + elif 'mysql' in k['title']: + if not os.path.isfile(k['paths']+"/mysql"+k['edition']+"/tmp/mysqld.pid"): + if k['status'] == 10: + lists[i]['status']=4 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 + else: + if k['status'] == 4: + lists[i]['status']=10 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 + elif 'php5' in k['title']+k['edition'] or 'php7' in k['title']+k['edition']: + title=k['title']+k['edition'] + # print("php",title,title.replace(".", "")+"-fpm") + if not get_process_id(title): + if k['status'] == 10: + lists[i]['status']=4 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 + else: + if k['status'] == 4: + lists[i]['status']=10 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 + elif 'tomcat' in k['title']: + if not get_process_id('tomcat'): + if k['status'] == 10: + lists[i]['status']=4 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 + else: + if k['status'] == 4: + lists[i]['status']=10 + sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 + i+=1 + count=sqlite("soft",model_intapp_soft_path).where(where).count() + data=return_list(lists,count,pagenow,pagesize) + return data + def updatesoftlist(): + "更新软件列表" + http=Http() + sqlite("soft",model_intapp_soft_path).where("1=1").delete() + def openkcweb(pagenow=1,pagesize=20): + http.openurl(config.domain['kcwebapi']+"/pub/soft_list","GET",params={ + "pagenow":pagenow,"pagesize":pagesize + }) + res=json_decode(http.get_text) + lists=[] + if res['code']==0: + for k in res['data']['lists']: + k['status']=0 + k['msg']='' + k['addtime']=times() + lists.append(k) + sqlite("soft",model_intapp_soft_path).insert(lists) + if pagenow "+arr['paths']+arr['title']+arr['edition']+"/out.log 2>&1 &",name="redis服务",icon=arr['icon']) + return True + elif 'mysql' in arr['title']: + if os.path.isfile(arr['paths']+arr['title']+arr['edition']+"/support-files/mysql.server"): + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":"安装成功"}) + system_start.insert_Boot_up("mysqld"+(arr['edition'].replace(".", ""))+"server start",name="mysqld"+(arr['edition'].replace(".", ""))+"服务",icon=arr['icon']) #edition + return True + elif 'frp' == arr['title']: + if os.path.isfile(arr['paths']+arr['title']+arr['edition']+"/frps") and os.path.isfile(arr['paths']+arr['title']+arr['edition']+"/frpc"): + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":"安装成功"}) + return True + else: + if os.path.exists(arr['paths']+arr['title']+arr['edition']): + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":"安装成功"}) + if 'tomcat' == arr['title']: + jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() + system_start.insert_Boot_up(cmd="export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition']+" && /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin/startup.sh start",name="tomcat服务",icon=arr['icon']) + return True + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"安装失败,目录不存在"+arr['paths']+arr['title']+arr['edition']}) + else: + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"安装失败"}) + else: + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"下载失败"}) + except Exception as e: + sqlite('soft',model_intapp_soft_path).where('id',id).update({'status':0,'msg':'安装失败'+str(e)}) + def start(id): + "启动软件服务" + arr=sqlite("soft",model_intapp_soft_path).where("id",id).find() + if arr['platform']=='Linux': ###############################LINUX + if 'nginx' == arr['title']: + os.system("nginx") + elif 'php' == arr['title']: + titleedition=arr['title']+arr['edition'] + fpmname=titleedition.replace(".", "")+"-fpm" + os.system(fpmname+" -c "+arr['paths']+arr['title']+arr['edition']+"/bin/php.ini -R") + # print("php启动",fpmname+" -c "+arr['paths']+arr['title']+arr['edition']+"/bin/php.ini -R") + elif 'redis' == arr['title']: + # os.system("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > log 2>&1 &") + os.system("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > "+arr['paths']+arr['title']+arr['edition']+"/out.log 2>&1 &") + elif 'mysql' == arr['title']: + if '5.6' == arr['edition']: + os.system("mysqld56server start") + elif '5.7' == arr['edition']: + os.system("mysqld57server start") + elif '8.0' == arr['edition']: + os.system("mysqld80server start") + elif 'tomcat' == arr['title']: + jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() + os.system("export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition'] +" && /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin/startup.sh start") + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":9,"msg":"","updtime":times()}) + time.sleep(10) + else: + os.system("cd "+arr['paths']+arr['title']+arr['edition']+" && bash start.sh") + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":10,"msg":"运行中"}) + else: + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":""}) + def stop(id): + arr=sqlite("soft",model_intapp_soft_path).where("id",id).find() + if arr['platform']=='Linux': ###############################LINUX + if 'nginx' == arr['title']: + os.system("pkill nginx") + elif 'php' == arr['title']: + titleedition=arr['title']+arr['edition'] + fpmname=titleedition.replace(".", "")+"-fpm" + os.system("pkill -9 "+fpmname) + elif 'redis' == arr['title']: + os.system("pkill -9 redis") + elif 'mysql' == arr['title']: + if '5.6' == arr['edition']: + os.system("mysqld56server stop") + elif '5.7' == arr['edition']: + os.system("mysqld57server stop") + elif '8.0' == arr['edition']: + os.system("mysqld80server stop") + elif 'tomcat' == arr['title']: + jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() + os.system("export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition'] +" && cd /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin && ./shutdown.sh") + # os.system("pkill -9 tomcat") + time.sleep(1) + elif 'mongo' == arr['title']: + os.system("pkill mongo") + else: + os.system("cd "+arr['paths']+arr['title']+arr['edition']+" && bash stop.sh") + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":""}) + def uninstall(id): + try: + arr=sqlite("soft",model_intapp_soft_path).where("id",id).find() + if arr['platform']=='Linux': ###############################LINUX + os.system("rm -rf "+arr['paths']+arr['title']+arr['edition']) + startpath="/usr/bin/" + if 'nginx' == arr['title']: + system_start.del_Boot_up("nginx") + os.system("pkill -9 nginx") + model_intapp_menu.delete(title="网站管理",sort=9000) + os.system("rm -rf "+startpath+"nginx") + elif 'redis' == arr['title']: + system_start.del_Boot_up("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > "+arr['paths']+arr['title']+arr['edition']+"/out.log 2>&1 &") + os.system("rm -rf "+startpath+"redis-server") + elif 'php' == arr['title']: + titleedition=arr['title']+arr['edition'] + fpmname=titleedition.replace(".", "")+"-fpm" + system_start.del_Boot_up(fpmname+" -c "+arr['paths']+arr['title']+arr['edition']+"/bin/php.ini -R") + os.system("rm -rf "+startpath+fpmname) + elif 'mysql' == arr['title']: + system_start.del_Boot_up("mysqld"+(arr['edition'].replace(".", ""))+"server start") + os.system("rm -rf "+startpath+"mysqld"+(arr['edition'].replace(".", ""))+" && rm -rf "+startpath+"mysql"+(arr['edition'].replace(".", ""))) + elif 'mongodb' == arr['title']: + system_start.del_Boot_up("mongo",True) + os.system("pkill -9 mongo") + os.system("rm -rf /data/mongodb") + elif 'frp' == arr['title']: + system_start.del_Boot_up("frps",True) + system_start.del_Boot_up("frpc",True) + os.system("pkill -9 frps") + os.system("pkill -9 frpc") + else: + if 'tomcat' == arr['title']: + jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() + system_start.del_Boot_up("export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition']+" && /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin/startup.sh start") + os.system("cd /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin && ./shutdown.sh") + if os.path.exists(arr['paths']+arr['title']+arr['edition']): + sqlite('soft',model_intapp_soft_path).where('id',id).update({'status':4,'msg':'卸载失败'}) + return + except Exception as e: + sqlite('soft',model_intapp_soft_path).where('id',id).update({'status':4,'msg':'卸载失败'+str(e)}) + else: + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"已卸载"}) \ No newline at end of file diff --git a/app/intapp/controller/soft/common/__init__.py b/app/intapp/controller/soft/common/__init__.py new file mode 100644 index 0000000..8879824 --- /dev/null +++ b/app/intapp/controller/soft/common/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from .SOFT import * \ No newline at end of file diff --git a/app/intapp/controller/soft/common/autoload.py b/app/intapp/controller/soft/common/autoload.py new file mode 100644 index 0000000..c4bee80 --- /dev/null +++ b/app/intapp/controller/soft/common/autoload.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +from app.intapp.common import * +import subprocess +def get_process_id(name): + try: + child = subprocess.Popen(['pgrep', '-f', name],stdout=subprocess.PIPE, shell=False) + response = child.communicate()[0] + return [int(pid) for pid in response.split()] + except: + return [] diff --git a/app/intapp/controller/soft/common/file/sqlite/.gitignore b/app/intapp/controller/soft/common/file/sqlite/.gitignore new file mode 100644 index 0000000..f3c316e --- /dev/null +++ b/app/intapp/controller/soft/common/file/sqlite/.gitignore @@ -0,0 +1 @@ +soft \ No newline at end of file diff --git a/app/intapp/controller/soft/common/file/sqlite/php_exten b/app/intapp/controller/soft/common/file/sqlite/php_exten new file mode 100644 index 0000000000000000000000000000000000000000..947090a468579685c0d9058dbd71817876cd9b6e GIT binary patch literal 24576 zcmeHPeQZ-)pm~U>pVC01x>inNzdYabyT5zhJ@?#m-fMcH-V<~RE?--VEhv~}b7XS4>={9j$z;tSDiHdT z!<#(%0si9W?|U`NDjxZx4$e~O*UI$W@Qb||1B?O20AqkLz!+c*Fa{U{i~+^~W8jC! zz!rt7c-b=fwxDgh*BN-#3z6i@0q3jj&Q^Q+N9FoPOHH#yXs%gTZxPbYUD9f6ahAh3 zm+ozq7ZjJ3$@eddx9NBLUv};aI$Kk36nC_fIxH;lIE1=}X3GXkqtLLqS!mc=UoUKF ztlL!6xJ`K8vQ4Pj+Pt~00lvM-($HKk_$N5OTnKuCUZ?P4P2>8FHH}M*rmCevt>xL8 zt@X{q;>D?U%LRusU~ltmcLq}DnpUow1a_p(GFF;a zOrpx>a0ETjU^)@yLc4$B|18Z1t5X=hM%z;v{%iPJ*RN~fJNW{wTXS7gqJCFh$Q|Go z6ntDztNLsHKk{qy_A0+p`IRdbgNkMH({i)y53+3&8m>#w%H$6(nsK;&tP93(kTq>h&g0{b*xE4rz<_h|AsSKI}9iO2PT`4Fk z?%;?TyVmA(cmm?t!O_7k@xXrZ(#g@mUyI$BBb{V)V87Ve6Fs%>d1uFyFWS8A&d7kBH!3Cjj)Mud0ZSN#@bdxBqeRZ_Mm&L?KA+bq4)2XzI{(EUA`V=Q zz1InEZhmw!vgbnVwNNzlMs(=R%{`|^!|#d1CnCqY1XG2nqB45;P~^ z#7l3*j_i%TOJMNCy%)tped7Krqk|tMhqM1uo{do|wuE0VP!e zm{Jr{T?}NFk`0MVSdG)7r`6@V8&a(6_hNTXr03x1&{ZI3Q{5&Dm{x>b2Dq`;&%?zK z{nf<;nPOizTqnj2@E4K*P$!1@M(Ax>AD~ux_YlmHbaKv z0Iad07z$Aq!GITfIHE;c-Qh?fOK1XoVBO-mebHkF#M2{U=zTQ2_#6!rNOrcj!vP4c zqkxa#aGG{M3Sf$0x;7vfdwbhBQ90;1wg)4!0>%BXRFiX;$CcLctZV?=gMJO7xE=yc z)YYkT>gp;Ju5RcP(DRAE5cE)2r>1Txm%XBGg0^!gt~t`4<S5~YVcX9*78XF+Qph4PNlE|m#{%@?Y{%>6Qpo#h%E{8q`6~)7={x3n#m;OA^ zLwycM{X^P_WHtV@P0)4&#if+?EQdZPK42JL^?!=ep#VK}X5}9I%nIs3?G+Tl$w4=D zcignQyOppS%YO=f<;}y~yxj1W41U;)F~AsL3@`>51B?O20AqkLz!+c*Fa{U{jDa5u z13I~~Ob(mkiMopCbSk%OZho!I(60Yh|E6BZS^i(;&byV`pkn#|Oe-5${vWFfq?ve@ z|DXCk|LTgn^8YHgyb1O_S^j^j)kl!HOjanc{Qte{v?_%=^8alt|9{`5ZY=+wajDxR zvn0#^LqR0kU8YrTEdP%sgHYr)i9xaa|6N65S>=CO{y&r0faU+QE*xk1{{Y5S;0h9@ z2*;ol;h0YG7g?#yD$`V{FKD~DTb#e(?*%WYZmM>w42B;4XZi-+W!(b)x7z<`=jQLp zyPbD5uSEG9Wu2l(-Yxs5%&NF?uZzXCV_qaTIv%K-{4H`dNjxiP}|0EOMPHKqH}*sd+xwPkm0{jl!Z zf_3X-6VJRI6)+{!%3$q-uMAGO13S#W_UXGlic~FzHC_ox-rb>@t#^0e?Y^m77(-3g zSg6Up2*!sl>NL4s)ESeDx=<}>f}16uKvPI2OEgo9U$R&t8OOtykP!eG$^3=V@I^Dz z;fs-mFQGDkS4NaS1-@wbqM63<#TXA?LOMX9Bh`;f!xs$=4$_vcvnG5oO2U`n?;xx6 zo%<(J3(svZVN3=S!(*Un4D0{r6li1yi~djgr*(b0jr?_fuC_}vrm?F3tzN_R7W}JV z7o5Oei~+^~V}LQh82C{#;C&94dhlcde4dEb=XbUS0$$iG|Ne*8U~)BizO-;D?J#`A zh5oJ5A(W0f)RugDiEcV#40tHQwO^u;s*Tc>zi#%f{8x;x{I5ZHbj?n<4L}>+xYNzR z#vQV_8HH3mD`k{Gw_%t5HkrR(8b9$f9Y2|A{1lD?yeLtw1HNed#7|@VWKN`iU>iRCIjOFZ z#!vigkDttv_$dtcc85RpKLa$<)CEt|3~BLS7I8UPdGbMHpe=;rss@cTDZ}S9bphSO z)J6DrD1`etD55hUKLazM8DPAPLin`+g{Cg}8A@FsoI@xbKLa$>qw>??QBn0y6jJrH Y)EB_w;ekF6EDOUmjr)RdBS3HbKNvJ$VgLXD literal 0 HcmV?d00001 diff --git a/app/intapp/controller/soft/common/file/time b/app/intapp/controller/soft/common/file/time new file mode 100644 index 0000000..818b173 --- /dev/null +++ b/app/intapp/controller/soft/common/file/time @@ -0,0 +1 @@ +1599551060 \ No newline at end of file diff --git a/app/intapp/controller/soft/common/model.py b/app/intapp/controller/soft/common/model.py new file mode 100644 index 0000000..87d168d --- /dev/null +++ b/app/intapp/controller/soft/common/model.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +from .autoload import * +# 初始化数据库 +model_intapp_soft_path=os.path.split(os.path.realpath(__file__))[0]+"/file/sqlite/soft" +class modelsqlitesoft(model.model): + config={'type':'sqlite'} + config={'type':'sqlite','db':model_intapp_soft_path} + model.dbtype.conf=config +class model_intapp_soft(modelsqlitesoft): + "软件表" + table="soft" + fields={ + "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 + "icon":model.dbtype.varchar(LEN=128,DEFAULT=''), #图标 + "title":model.dbtype.varchar(LEN=128,DEFAULT=''), #软件名称 + "edition":model.dbtype.varchar(LEN=128,DEFAULT=''), #软件版本 + "shell":model.dbtype.varchar(LEN=128,DEFAULT=''), #shell 命令 + "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件描述 + "paths":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件安装目录 卸载软件时用到 + "status":model.dbtype.int(LEN=2,DEFAULT=0), #0未安装 1等待中 2下载中 3安装中 4已安装 5卸载中 9启动中... 10运行中 11正在停止服务... + "filename":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件源文件地址 + "platform":model.dbtype.varchar(LEN=256,DEFAULT='Linux'),#支持的系统 + 'msg':model.dbtype.varchar(LEN=1024,DEFAULT=''), #最后一次执行结果信息 + "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 + "updtime":model.dbtype.int(LEN=11,DEFAULT=0) #更新时间 + } +try: + sqlite('soft',model_intapp_soft_path).find() +except: + model_soft=model_intapp_soft() + model_soft.create_table() + +class model_intapp_web(modelsqlitesoft): + "网站列表" + table="web" + fields={ + "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 + "domain":model.dbtype.varchar(LEN=512,DEFAULT=''), #域名 + "port":model.dbtype.varchar(LEN=8,DEFAULT='80'), #端口 + "icon":model.dbtype.varchar(LEN=128,DEFAULT=''), #图标 + "title":model.dbtype.varchar(LEN=128,DEFAULT=''), #名称 + "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), #描述 + "status":model.dbtype.int(LEN=1,DEFAULT=1), #网站状态 0停止 1开启 + "path":model.dbtype.varchar(LEN=256,DEFAULT=''), #网站目录 + "client_max_body_size":model.dbtype.int(LEN=11,DEFAULT=20),#上传限制 + "webtpl":model.dbtype.varchar(LEN=256,DEFAULT=''), #nginx配置文件模板名 + "servers":model.dbtype.varchar(LEN=256,DEFAULT=''), #服务器名字 nginx名字 + "only":model.dbtype.varchar(LEN=32,DEFAULT=''), #唯一字段 + "balancing":model.dbtype.varchar(LEN=2048,DEFAULT=''), #负载均衡服务器信息 + "proxy_set_header":model.dbtype.varchar(LEN=1024,DEFAULT=''),#自定义转发请求头 + "header":model.dbtype.varchar(LEN=1024,DEFAULT=''),#自定义响应头 + "ssl_certificate":model.dbtype.varchar(LEN=1024,DEFAULT=''), + "ssl_certificate_key":model.dbtype.varchar(LEN=1024,DEFAULT=''), + "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 + "updtime":model.dbtype.int(LEN=11,DEFAULT=0) #更新时间 + } +try: + sqlite('web',model_intapp_soft_path).find() +except: + model_intapp_web=model_intapp_web() + model_intapp_web.create_table() + +model_intapp_soft_php_exten_path=os.path.split(os.path.realpath(__file__))[0]+"/file/sqlite/php_exten" +class model_intapp_php_exten(model.model): + "php扩展表" + config={'type':'sqlite'} + config={'type':'sqlite','db':model_intapp_soft_php_exten_path} + model.dbtype.conf=config + table="php_exten" + fields={ + "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 + "pid":model.dbtype.int(LEN=11), #软件列表id + "title":model.dbtype.varchar(LEN=128,DEFAULT=''), #扩展名称 + "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), #扩展描述 + "status":model.dbtype.int(LEN=2,DEFAULT=0), #0未安装 1等待中 2下载中 3安装中 4已安装 5卸载中 + "filename":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件源文件地址 + 'msg':model.dbtype.varchar(LEN=1024,DEFAULT=''), #最后一次执行结果信息 + "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 + "updtime":model.dbtype.int(LEN=11,DEFAULT=0) #更新时间 + } +try: + sqlite('php_exten',model_intapp_soft_php_exten_path).find() +except: + model_intapp_php_exten=model_intapp_php_exten() + model_intapp_php_exten.create_table() \ No newline at end of file diff --git a/app/intapp/controller/soft/frp.py b/app/intapp/controller/soft/frp.py new file mode 100644 index 0000000..087feb0 --- /dev/null +++ b/app/intapp/controller/soft/frp.py @@ -0,0 +1,138 @@ +from .common import * +dar="/usr/local/frp/frp0.30" +# pkill frps && cd /usr/local/frp/frp0.30 && ./frps -c frps_full.ini & +def get_server(): + server={ + 'conf':file_get_content(dar+"/frps_full.ini"), + 'base':json_decode(file_get_content(dar+"/frps_full.conf")), + 'dar':dar + } + return successjson(server) +def run_status(): + "获取运行状态" + data={"frpc":0,"frps":0} + if get_process_id('frps'): + data['frps']=1 + if get_process_id('frpc'): + data['frpc']=1 + return successjson(data) +def restart(types='frps'): + "重启" + G.setadminlog="重启frp" + if not os.path.exists(dar+"/log"): + os.makedirs(dar+"/log") + if types=='frps': + cmd="cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &" + os.system("pkill -9 frps") + system_start.del_Boot_up(cmd) + time.sleep(1) + os.system(cmd) + time.sleep(1) + if not get_process_id('frps'): + return errorjson(msg="启动失败,请检查配置") + system_start.insert_Boot_up(cmd=cmd,name="frps服务端") + elif types=='frpc': + cmd="cd "+dar +" && ./frpc -c frpc.ini &" + os.system("pkill frpc") + system_start.del_Boot_up(cmd) + time.sleep(1) + os.system(cmd) + time.sleep(1) + if not get_process_id('frpc'): + return errorjson(msg="启动失败,请检查配置") + system_start.insert_Boot_up(cmd=cmd,name="frpc客户端") + return successjson() +def stop(types='all'): + "停止" + G.setadminlog="停止frp服务" + if types=='frps': + system_start.del_Boot_up("cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") + os.system("pkill -9 frps") + elif types=='frpc': + system_start.del_Boot_up("cd "+dar +" && nohup ./frpc -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") + os.system("pkill -9 frpc") + else: + system_start.del_Boot_up("cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") + system_start.del_Boot_up("cd "+dar +" && nohup ./frpc -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") + os.system("pkill -9 frps") + os.system("pkill -9 frpc") + return successjson() +def upd_server(types='ini'): + G.setadminlog="修改frp配置" + server=request.get_json() + if types=='ini': + file_set_content(dar+"/frps_full.ini",server['conf']) + elif types=='base': + base=server['base'] + f = open(dar+"/frps_full.ini") + con='' + while True: + line = f.readline() + if not line: + break + elif 'bind_addr = ' in line: + line="bind_addr = "+base['bind_addr']+"\n" + elif 'bind_port = ' in line: + line="bind_port = "+base['bind_port']+"\n" + elif 'bind_udp_port = ' in line: + line="bind_udp_port = "+base['bind_udp_port']+"\n" + elif 'kcp_bind_port = ' in line: + line="kcp_bind_port = "+base['kcp_bind_port']+"\n" + elif 'vhost_http_port = ' in line: + line="vhost_http_port = "+base['vhost_http_port']+"\n" + elif 'vhost_https_port = ' in line: + line="vhost_https_port = "+base['vhost_https_port']+"\n" + elif 'dashboard_addr = ' in line: + line="dashboard_addr = "+base['dashboard_addr']+"\n" + elif 'dashboard_port = ' in line: + line="dashboard_port = "+base['dashboard_port']+"\n" + elif 'dashboard_user = ' in line: + line="dashboard_user = "+base['dashboard_user']+"\n" + elif 'dashboard_pwd = ' in line: + line="dashboard_pwd = "+base['dashboard_pwd']+"\n" + elif 'log_level = ' in line: + line="log_level = "+base['log_level']+"\n" + elif 'log_max_days = ' in line: + line="log_max_days = "+base['log_max_days']+"\n" + elif 'disable_log_color = ' in line: + line="disable_log_color = "+base['disable_log_color']+"\n" + elif 'token = ' in line: + line="token = "+base['token']+"\n" + elif 'allow_ports = ' in line: + line="allow_ports = "+base['allow_ports']+"\n" + elif 'max_pool_count = ' in line: + line="max_pool_count = "+base['max_pool_count']+"\n" + elif 'max_ports_per_client = ' in line: + line="max_ports_per_client = "+base['max_ports_per_client']+"\n" + elif 'subdomain_host = ' in line: + line="subdomain_host = "+base['subdomain_host']+"\n" + elif 'tcp_mux = ' in line: + line="tcp_mux = "+base['tcp_mux']+"\n" + con=con+line + f.close() + file_set_content(dar+"/frps_full.ini",con) + file_set_content(dar+"/frps_full.conf",json_encode(base)) + os.system("pkill frps") + time.sleep(1) + os.system("cd "+dar +" && ./frps -c frps_full.ini &") + time.sleep(1) + if not get_process_id('frps'): + return errorjson(msg="启动失败,请检查配置") + return successjson() +def get_client(): + client={ + 'conf':file_get_content(dar+"/frpc.ini"), + 'base':json_decode(file_get_content(dar+"/frpc.conf")) + } + return successjson(client) +def upd_client(type='ini'): + G.setadminlog="修改frp客户端配置" + server=request.get_json() + file_set_content(dar+"/frpc.ini",server['conf']) + os.system("pkill frpc") + time.sleep(1) + os.system("cd "+dar +" && ./frpc -c frpc.ini &") + time.sleep(1) + if not get_process_id('frpc'): + return errorjson(code=1,msg="启动失败,请检查配置") + return successjson() \ No newline at end of file diff --git a/app/intapp/controller/soft/index.py b/app/intapp/controller/soft/index.py new file mode 100644 index 0000000..e48c782 --- /dev/null +++ b/app/intapp/controller/soft/index.py @@ -0,0 +1,131 @@ +from .common import * +def index(): + kw=request.args.get("kw") + if not kw: + kw='' + lefttext=request.args.get('lefttext') + if not lefttext: + lefttext='应用' + lefturl=request.args.get('lefturl') + if not lefturl: + lefturl='myapp' + lefttype=request.args.get('lefttype') + if not lefttype: + lefttype='lefturl' + if sysisphone(): + return response.tpl("../tplm/index/home",kw=kw,lefttext=lefttext,lefturl=lefturl,lefttype=lefttype) + else: + return response.tpl('index/home',kw=kw) +def gettitle(title,edition): + "获取软件信息" + return successjson(sqlite('soft',model_intapp_soft_path).where("title='"+title+"' and edition='"+edition+"' and platform='"+get_sysinfo()['uname'][0]+"' and status >=4").find()) +def softlist(): + kw=request.args.get("kw") + pagenow=int(request.args.get("pagenow")) + pagesize=int(request.args.get("pagesize")) + return successjson(SOFT.softlist(kw,pagenow,pagesize)) +def updatesoftlist(): + "更新软件列表" + G.setadminlog="更新软件列表" + SOFT.updatesoftlist() + return successjson() +def getstatus(id): + "获取软件状态和描述" + return successjson(sqlite("soft",model_intapp_soft_path).field("status,msg").where("id",id).find()) +def insert(id): + "安装软件" + G.setadminlog="安装软件" + tar=sqlite('soft',model_intapp_soft_path).where("id",id).field("title,edition").find() + title=tar['title'] + if 'nginx' == title: + ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','nginx'),'and',('status','gt',0)]).find() + if ass: + return errorjson(msg="您已安装其他nginx版本,卸载其他nginx版本后可安装此版本") + if 'mysql' == title: + if "5.7" == tar['edition']: + ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','mysql'),'and',('status','gt',0),'and',('edition','eq','8.0')]).find() + if ass: + return errorjson(msg="您已安装8.0版本mysql") + if "8.0" == tar['edition']: + ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','mysql'),'and',('status','gt',0),'and',('edition','eq','5.7')]).find() + if ass: + return errorjson(msg="您已安装5.7版本mysql") + elif 'jdk' == title: + ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','jdk'),'and',('status','gt',0)]).find() + if ass: + return errorjson(msg="您已安装其他jdk版本,卸载其他jdk版本后可安装此版本") + elif 'tomcat' == title: + ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','jdk'),'and',('status','gt',0)]).find() + if not ass: + return errorjson(msg="tomcat依赖于jdk,请先安装jdk") + elif 'kodexplorer' in title or 'phpmyadmin' in title: + if not sqlite('soft',model_intapp_soft_path).where([('title','like','%php%'),'and',('status','egt','4')]).count() or not sqlite('soft',model_intapp_soft_path).where([('title','like','%nginx%'),'and',('status','egt','4')]).count(): + return errorjson(msg="先安装nginx和php") + if 'phpmyadmin' in title: + if not sqlite('soft',model_intapp_soft_path).where([('title','like','%mysql%'),'and',('status','egt','4')]).count() or not sqlite('soft',model_intapp_soft_path).where([('title','like','%nginx%'),'and',('status','egt','4')]).count(): + return errorjson(msg="先安装mysql") + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":1,"msg":"安装中"}) + Queues.insert(target=SOFT.insert,args=(id,),title="安装软件:"+title) + return successjson() +def start(id): + "启动软件" + title=request.args.get('title') + if title=='tomcat': + Queues.insert(SOFT.start,args=(id,),title='启动tomcat服务') + time.sleep(2) + else: + SOFT.start(id) + return successjson() +def stop(id): + "停止软件" + SOFT.stop(id) + return successjson() +def restartnginx(): + """平滑重启nginx""" + os.system("nginx -s reload") + return successjson() + +def uninstall(id): + "卸载软件" + # title=request.args.get("title") + title=sqlite('soft',model_intapp_soft_path).where("id",id).field("title").find()['title'] + if 'nginx' == title: + sqlite("web",model_intapp_soft_path).where("1=1").update({"status":0}) + sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":5,"msg":"卸载中"}) + Queues.insert(target=SOFT.uninstall,args=(id,),title="卸载软件:"+title) + return successjson() + + +def gitssh(): + 'gitssh公钥' + try: + data=file_get_content("/root/.ssh/id_rsa.pub") + except: + data='' + return successjson(data) + + + +def add(): + "添加内容" + try: + data=request.get_json() + data.update(updtime=times(),addtime=times()) + # print(data) + sqlite('software',config.sqlitesoftware).insert(data) + except: + return errorjson(msg="失败") + else: + return successjson() +def update(id=0): + "更新内容" + data=request.get_json() + if not id: + id=data['id'] + try: + data.pop('updtime') + data.pop('addtime') + except:pass + else: + sqlite('software',config.sqlitesoftware).where("id",id).update(data) + return successjson() \ No newline at end of file diff --git a/app/intapp/controller/soft/install.txt b/app/intapp/controller/soft/install.txt new file mode 100644 index 0000000..f75c93b --- /dev/null +++ b/app/intapp/controller/soft/install.txt @@ -0,0 +1 @@ +oss2>=2.12.0 \ No newline at end of file diff --git a/app/intapp/controller/soft/mongodb.py b/app/intapp/controller/soft/mongodb.py new file mode 100644 index 0000000..cc24fb8 --- /dev/null +++ b/app/intapp/controller/soft/mongodb.py @@ -0,0 +1,253 @@ +from .common import * +import base64 +WORK_DIR="/data/mongodb" +# if not os.path.exists(WORK_DIR): +# os.system("mkdir -p "+WORK_DIR) +def get_config(id): + '获取mongodb页面配置' + try: + data=json_decode(file_get_content(WORK_DIR+"/config.conf")) + except: + data={} + if not data: + data={} + if os.path.isfile(WORK_DIR+"/key/mongo.key"): + key=file_get_content(WORK_DIR+"/key/mongo.key") + else: + key='' + data['key']=key + data['get_local_ip']=get_local_ip() + data['WORK_DIR']=WORK_DIR + try: + data['configlist']=json_decode(file_get_content(WORK_DIR+"/serverconfig.conf")) + except: + data['configlist']={} + return successjson(data) +def upd_config(id): + '修改mongodb页面配置' + G.setadminlog="修改mongodb页面配置" + data=request.get_json() + os.system("mkdir -p "+WORK_DIR+"/key") + f=open(WORK_DIR+"/key/mongo.key","w") + f.write(data['key']) + f.close() + os.system("chmod 600 "+WORK_DIR+"/key/mongo.key") + data['key']='' + file_set_content(WORK_DIR+"/config.conf",json_encode(data)) + return successjson() + +def start_config(types='restart'): + '启动/停止config服务' + G.setadminlog="启动/停止config服务" + data=request.get_json() + data['key']='' + os.system("mkdir -p "+WORK_DIR+"/conf") + f=open(WORK_DIR+"/conf/config.conf","w") + f.write("logappend=true\n"+ + "fork=true\n"+ + "maxConns=5000\n"+ + "replSet=configs\n"+ + "keyFile="+WORK_DIR+"/key/mongo.key\n"+ + "configsvr=true") + f.close() + os.system("chmod 777 "+WORK_DIR+"/conf/config.conf") + # os.system("chmod 600 "+WORK_DIR+"/key/mongo.key") + i=1 + for k in data['configs']['server']: + os.system("mkdir -p "+WORK_DIR+"/config"+str(i)+"/data") + i+=1 + if types=='restart' or types=='stop': #停止服务 + i=1 + for k in data['configs']['server']: + pid=file_get_content(WORK_DIR+"/config"+str(i)+"/db.pid") + os.system("kill -9 "+str(pid)) + time.sleep(0.1) + i+=1 + data['configs']['serverstatus']=0 + if types=='restart' or types=='start': #启动服务 + i=1 + for k in data['configs']['server']: + startstatus=False + cmd="mongod --bind_ip "+str(k['ip'])+" --port "+str(k['port'])+" -f "+WORK_DIR+"/conf/config.conf --dbpath "+WORK_DIR+"/config"+str(i)+"/data --logpath "+WORK_DIR+"/config"+str(i)+"/log.log --pidfilepath "+WORK_DIR+"/config"+str(i)+"/db.pid" + result=os.popen(cmd) + res = result.read() + for line in res.splitlines(): + print("line",line) + if 'process started successfully' in line: + startstatus=True + break + if not startstatus: + return errorjson(code=1,msg="启动失败") + + i+=1 + data['configs']['serverstatus']=1 + file_set_content(WORK_DIR+"/config.conf",json_encode(data)) + return successjson() +def start_mongos(types='restart'): + '启动/停止路由服务' + G.setadminlog="启动/停止路由服务" + data=request.get_json() + data['key']='' + # for k in data + #创建配置文件 + os.system("mkdir -p "+WORK_DIR+"/conf && mkdir -p "+WORK_DIR+"/mongos") + f=open(WORK_DIR+"/conf/mongos.conf","w") + f.write("logappend = true\n"+ + "fork=true\n"+ + data['mongos']['configdb']+" #这里必须是公共网ip或内网ip,千万不能是127.0.0.1\n" + "keyFile="+WORK_DIR+"/key/mongo.key\n"+ + "maxConns=20000 #最大连接数") + f.close() + os.system("chmod 777 "+WORK_DIR+"/conf/mongos.conf") + os.system("mkdir -p "+WORK_DIR+"/mongos") + if types=='restart' or types=='stop': #停止服务 + i=1 + for k in data['mongos']['server']: + pid=file_get_content(WORK_DIR+"/mongos/db"+str(i)+".pid") + os.system("kill -9 "+str(pid)) + time.sleep(0.1) + i+=1 + data['mongos']['serverstatus']=0 + if types=='restart' or types=='start': #启动服务 + i=1 + for k in data['mongos']['server']: + startstatus=False + cmd="mongos --bind_ip "+str(k['ip'])+" --port "+str(k['port'])+" -f "+WORK_DIR+"/conf/mongos.conf --logpath "+WORK_DIR+"/mongos/log"+str(i)+".log --pidfilepath "+WORK_DIR+"/mongos/db"+str(i)+".pid" + print(cmd) + result=os.popen(cmd) + res = result.read() + for line in res.splitlines(): + print("line",line) + if 'process started successfully' in line: + startstatus=True + break + if not startstatus: + return errorjson(code=1,msg="启动失败") + i+=1 + data['mongos']['serverstatus']=1 + file_set_content(WORK_DIR+"/config.conf",json_encode(data)) + return successjson() +def start_shard(types='restart'): + '启动/停止分片服务' + G.setadminlog="启动/停止分片服务" + data=request.get_json() + data['key']='' + os.system("mkdir -p "+WORK_DIR+"/conf") + + j=1 + for shard in data['shard']:#分片列表 + f=open(WORK_DIR+"/conf/shard"+str(j)+".conf","w") + f.write("logappend=true\n"+ + "fork=true\n"+ + "maxConns=2000\n"+ + "storageEngine=mmapv1 #基于内存映射文件的存储引擎\n"+ + "shardsvr=true\n"+ + "replSet="+shard['servername']+"\n"+ + "keyFile="+WORK_DIR+"/key/mongo.key") + f.close() + i=1 + for k in shard['server']: + os.system("mkdir -p "+WORK_DIR+"/shard"+str(j)+"/data"+str(i)) + i+=1 + if types=='restart' or types=='stop': #停止服务 + i=1 + for k in shard['server']: + pid=file_get_content(WORK_DIR+"/shard"+str(j)+"/db"+str(i)+".pid") + os.system("kill -9 "+str(pid)) + time.sleep(0.1) + i+=1 + data['shard'][j-1]['serverstatus']=0 + if types=='restart' or types=='start': #启动服务 + i=1 + for k in shard['server']:#副本集列表 + startstatus=False + cmd="mongod --bind_ip "+str(k['ip'])+" --port "+str(k['port'])+" -f "+WORK_DIR+"/conf/shard"+str(j)+".conf --dbpath "+WORK_DIR+"/shard"+str(j)+"/data"+str(i)+" --logpath "+WORK_DIR+"/shard"+str(j)+"/log"+str(i)+".log --pidfilepath "+WORK_DIR+"/shard"+str(j)+"/db"+str(i)+".pid" + print("启动cmd:",cmd) + result=os.popen(cmd) + res = result.read() + for line in res.splitlines(): + print("line",line) + if 'process started successfully' in line: + startstatus=True + break + if not startstatus: + file_set_content(WORK_DIR+"/config.conf",json_encode(data)) + return errorjson(code=1,msg="启动失败") + i+=1 + data['shard'][j-1]['serverstatus']=1 + j+=1 + file_set_content(WORK_DIR+"/config.conf",json_encode(data)) + return successjson() + +# def config_init(id): +# "config副本集初始化," +# data=request.get_json() +# port=data['configs']['server'][0]['port'] +# replicaset=data['configs']['replicaset'] +# members=[] +# i=0 +# for k in replicaset: +# zd={'_id':i,'host':k['ip']+':'+str(k['port'])} +# members.append(zd) +# i+=1 +# f=open(config.path['path']+"app/linuxweb/config_init.sh","w") +# f.write("mongo --port "+str(port)+"\n"+ +# "use admin\n"+ +# "rs.initiate({_id:'configs',members:"+json_encode(members)+"})\n"+ +# "exit") +# f.close() +# os.system("cd "+config.path['path']+"app/linuxweb && bash config_init.sh") +# return successjson() + + + +#mongodb独立部署 /data/mongodb/server1/ +def setserverconfig(): + configlist=request.get_json() + for k in configlist: + if not os.path.exists(WORK_DIR+k['path']): + os.makedirs(WORK_DIR+k['path']) + if not os.path.exists(WORK_DIR+k['path']+"/data"): + os.makedirs(WORK_DIR+k['path']+"/data") + file_set_content(WORK_DIR+k['path']+"/mongod.config",''+ + 'systemLog:\n'+ + ' destination: file\n'+ + ' logAppend: true\n'+ + ' path: '+WORK_DIR+k['path']+'/mongodb.log #mongodb的日志文件路径\n'+ + 'storage:\n'+ + ' dbPath: '+WORK_DIR+k['path']+'/data/ #mongodb的数据文件路径\n'+ + ' journal:\n'+ + ' enabled: true\n'+ + 'processManagement:\n'+ + ' fork: true # fork and run in background\n'+ + ' pidFilePath: '+WORK_DIR+k['path']+'/mongod.pid # location of pidfile\n'+ + ' timeZoneInfo: /usr/share/zoneinfo\n'+ + 'net:\n'+ + ' port: '+str(k['port'])+' #mongodb1的进程号\n'+ + ' bindIp: '+k['bindIp']+' # Listen to local interface only, comment to listen on all interfaces') + file_set_content(WORK_DIR+"/serverconfig.conf",json_encode(configlist)) + return successjson() +def restartserver(types='start',index=0): + index=int(index) + configlist=json_decode(file_get_content(WORK_DIR+"/serverconfig.conf")) + cmd="mongod -f "+WORK_DIR+configlist[index]['path']+"/mongod.config" #启动命令 + if types=='start': + configlist[index]['status']=1 + system_start.insert_Boot_up(cmd=cmd,name="mongodb独立模式",icon="https://img.kwebapp.cn/icon/mongodb.png") + elif types=='stop': + configlist[index]['status']=0 + system_start.del_Boot_up(cmd) + cmd=cmd+" --shutdown" #停止命令 + result=os.popen(cmd) + res = result.read() + startstatus=False + for line in res.splitlines(): + print("line",line) + if 'process started successfully' in line or 'killing process with pid' in line: + startstatus=True + break + if startstatus: + file_set_content(WORK_DIR+"/serverconfig.conf",json_encode(configlist)) + return successjson() + else: + return errorjson(cmd,msg="失败") diff --git a/app/intapp/controller/soft/mysql copy.py b/app/intapp/controller/soft/mysql copy.py new file mode 100644 index 0000000..32e65f1 --- /dev/null +++ b/app/intapp/controller/soft/mysql copy.py @@ -0,0 +1,310 @@ +from .common import * +import oss2 +def get_data(id): + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + text=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") + conf=json_decode(text) + if not conf: + if ar['edition']=='5.7': + port=3306 + else: + port=3307 + conf={ + "base":{ + 'rootpassword':'intapppasswordtest', + 'path':ar['paths']+ar['title']+ar['edition']+'/data', + 'port':port, #监听端口 + 'max_connections':'200',#最大连接数 + 'max_allowed_packet':'16M', #最大接受的数据包大小 + 'expire_logs_days':'3',#日志保留时间天() + 'query_cache_limit':'1M',#指定单个查询可以使用的缓冲区的大小 + 'query_cache_size':'32M',#查询的缓存大小设置 + 'query_cache_type':'1',#设置缓存的类型, 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 + 'wait_timeout':'9000',#超时等待时间,单位秒,即一个connection在若干秒内无响应 + 'thread_cache_size':'256',# 用于缓存空闲的线程 + 'key_buffer_size':'16M' # 用于指定索引缓冲区的大小 + }, + } + if ar['edition']=='5.7': + mycnf=file_get_content("/etc/my.cnf") + else: + mycnf=file_get_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf") + data={ + 'conf':conf, + 'ar':ar, + "my":mycnf + } + return successjson(data) +def upd_my(id): + "修改配置文件" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + data=request.get_json() + if ar['edition']=='5.7': + file_set_content("/etc/my.cnf",data['text']) + else: + file_set_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf",data['text']) + return successjson() +def upd_data(id): + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + data=request.get_json() + filetext=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") + filedata=json_decode(filetext) + if not filedata or data['base']['rootpassword']!=filedata['base']['rootpassword']:#修改mysql密码 + os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart --skip-grant-tables") + cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -e " + cmd=cmd+'"use mysql;flush privileges;update user set authentication_string=password(' + cmd=cmd+"'"+str(data['base']['rootpassword']) + cmd=cmd+"'" + cmd=cmd+') where user=' + cmd=cmd+"'root';set password=password('"+str(data['base']['rootpassword'])+"');" + cmd=cmd+'"' + if '5.7' != ar['edition']: + cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -p3307 -S "+ar['paths']+ar['title']+ar['edition']+"/tmp/mysql.sock -e " + cmd+='"use mysql;flush privileges;grant all privileges on *.* to root@' + cmd+="'%'" + cmd+=" identified by 'root';update mysql.user set password=password('"+data['base']['rootpassword']+"') where user='root';update mysql.user set grant_priv='Y' where User='root';flush privileges" + cmd=cmd+'"' + # file_set_content("mysqlset",cmd) + pi=subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart") + print(type(strs),strs) + if 'error' in strs: + return errorjson(msg="密码修改失败"+strs) + + # mysqld restart --skip-grant-tables && mysql -uroot -e "flush privileges;update mysql.user set authentication_string=password('123456') where user = 'root'"; + # print(data['base']['rootpassword'],filedata['base']['rootpassword']) + if '5.7' == ar['edition']: + mycnf='/etc/my.cnf' + else: + mycnf=ar['paths']+ar['title']+ar['edition']+"/my.cnf" + f = open(mycnf) + con='' + while True: + line = f.readline() + if not line: + break + elif 'datadir=' in line: + line="datadir="+str(data['base']['path'])+"\n" + elif 'port=' in line or 'port =' in line: + line="port="+str(data['base']['port'])+"\n" + elif 'max_connections=' in line: + line="max_connections="+str(data['base']['max_connections'])+"\n" + elif 'max_allowed_packet=' in line: + line="max_allowed_packet="+str(data['base']['max_allowed_packet'])+"\n" + elif 'expire_logs_days=' in line: + line="expire_logs_days="+str(data['base']['expire_logs_days'])+"\n" + elif 'query_cache_limit=' in line: + line="query_cache_limit="+str(data['base']['query_cache_limit'])+"\n" + elif 'query_cache_size=' in line: + line="query_cache_size="+str(data['base']['query_cache_size'])+"\n" + elif 'query_cache_type=' in line: + line="query_cache_type="+str(data['base']['query_cache_type'])+"\n" + elif 'wait_timeout=' in line: + line="wait_timeout="+str(data['base']['wait_timeout'])+"\n" + elif 'thread_cache_size=' in line: + line="thread_cache_size="+str(data['base']['thread_cache_size'])+"\n" + elif 'key_buffer_size=' in line: + line="key_buffer_size="+str(data['base']['key_buffer_size'])+"\n" + con=con+line + f.close() + f= open(mycnf, "w") + f.write(con) + f.close() + time.sleep(1) + if not filedata or data['base']['path']!=filedata['base']['path']: #修改数据存放目录 + os.system('mysqld'+(ar['edition'].replace(".", ""))+'server stop') + os.system("mkdir -p "+str(data['base']['path'])) + # #mysql数据复制 + if not filedata: + print("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") + os.system("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") + else: + print("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") + os.system("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") + os.system("chown -R mysql "+data['base']['path']+" && chgrp -R mysql "+data['base']['path']) + os.system('mysqld'+(ar['edition'].replace(".", ""))+'server start') + text=json_encode(data) + file_set_content(ar['paths']+ar['title']+ar['edition']+"/config.conf",text) + + return successjson() +def backups(types='whole',db='bankup_all_databases',upload_aliyun=True): + "备份mysql5.7" + return BACKUP.backups(types,db,upload_aliyun) +def recovery(types='whole',upload_aliyun=True): + "恢复mysql5.7" + db=request.args.get("db") + Queues.insert(target=BACKUP.recovery,args=(types,db,upload_aliyun),title="恢复mysql") + return successjson(msg="正在恢复数据库,请在任务队列中查看恢复结果") +class BACKUP: + def recovery(types,db,upload_aliyun): + """恢复数据库""" + if not os.path.isfile("app/common/file/config.conf"): + print("在系统配置中保存备份目录") + return + fileconfig=json_decode(file_get_content("app/common/file/config.conf")) + if not fileconfig: + print("在系统配置中保存备份目录") + return + backpath=fileconfig['aliyun']['backpath'] + if backpath: + if backpath[:1]=='/': + backpath=backpath[1:] + if backpath[-1]=='/': + backpath=backpath[:-1] + else: + backpath="kcweb" + backmysqlpath="backup/mysql" #mysql备份目录 + if not os.path.exists(backmysqlpath): + os.makedirs(backmysqlpath) + mysqlpwd='intapppasswordtest' + mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql5.7/config.conf")) #mysql信息 + if mysqlconf: + mysqldatapath=mysqlconf['base']['path'] + mysqlpwd=mysqlconf['base']['rootpassword'] + conf={ + "mysql":{ + "username":"root","password":mysqlpwd,"host":"127.0.0.1",#mysql信息 + }, + } + if upload_aliyun: + auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) + bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) + bucket.get_object_to_file(db,backmysqlpath+"/database.sql.gz") + os.system("gzip -d "+backmysqlpath+"/database.sql.gz") + os.system("mysql -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" < "+backmysqlpath+"/database.sql") + os.remove(backmysqlpath+"/database.sql") + else: + os.system("gzip -d "+backmysqlpath+"/"+db+".sql.gz") + os.system("mysql -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" < "+backmysqlpath+"/"+db+".sql") + print("恢复完成") + def backups(types,db,upload_aliyun): + """备份mysql --cli运行 + types whole表示全量备份。 increment表示增量备份所有 + + db bankup_all_databases表示备份所有数据库。 否则备份指定数据库按逗号分隔 types=whole时有效 + """ + if not os.path.isfile("app/common/file/config.conf"): + print("在系统配置中保存备份目录") + return + fileconfig=json_decode(file_get_content("app/common/file/config.conf")) + if not fileconfig: + print("在系统配置中保存备份目录") + return + backpath=fileconfig['aliyun']['backpath'] + if backpath: + if backpath[:1]=='/': + backpath=backpath[1:] + if backpath[-1]=='/': + backpath=backpath[:-1] + else: + backpath="kcweb" + backmysqlpath="backup/mysql" #mysql备份目录 + if not os.path.exists(backmysqlpath): + os.makedirs(backmysqlpath) + mysqldatapath="/usr/local/mysql/mysql5.7/data" #mysql数据库存放目 + mysqlpwd='intapppasswordtest' + mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql5.7/config.conf")) #mysql信息 + if mysqlconf: + mysqldatapath=mysqlconf['base']['path'] + mysqlpwd=mysqlconf['base']['rootpassword'] + conf={ + "mysql":{ + "username":"root","password":mysqlpwd,"host":"127.0.0.1",#mysql信息 + }, + } + if upload_aliyun: + auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) + bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) + if types=='whole': #全量备份 + if not os.path.exists(backmysqlpath): + os.system("mkdir -p "+backmysqlpath) + if db=='bankup_all_databases':#备份所有 + print("全量备份所有数据库:"+db+".sql.gz") + os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+".sql.gz") + else:#备份指定数据库 + db=re.sub(","," ",db) + print("全量备份指定数据库:"+db+".sql.gz") + os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+".sql.gz") + if upload_aliyun: + print(backmysqlpath+"/"+db+".sql.gz","上传mysql备份目录文件到阿里云oss...") + oss2.resumable_upload(bucket, "backups/"+backpath+"/"+backmysqlpath+"/"+db+"/"+time.strftime("%Y%m%d-%H:%M:%S",time.localtime(times()))+".sql.gz",backmysqlpath+"/"+db+".sql.gz") + filelist=[] + for obj in oss2.ObjectIterator(bucket, prefix="backups/"+backpath+"/"+backmysqlpath+"/"+db+"/"): + filelist.append(obj.key) + i=0 + while True: + if len(filelist)-i <= 5: #在阿里云保留5个备份文件 其他上传 + break + bucket.delete_object(filelist[i]) + i+=1 + + # elif types=='increment': #增量备份所有 + # if not os.path.exists(backmysqlpath) or not os.path.isfile(backmysqlpath+"/"+db+".sql.gz"): + # os.system("mkdir -p "+backmysqlpath) + # print("全量备份所有数据库:"+db+".sql.gz") + # os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/increment_all_databases.sql.gz") + # print("备份mysql二进制文件...") + # t=os.listdir(backmysqlpath) + # lis=os.listdir(mysqldatapath) + # maxlist=[] + # for files in lis: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # maxlist.append(a) + # except:pass + # for files in lis: + # iscz=True #是否需要复制 + # if iscz: + # for k in t: + # if mysqldatapath+"/"+k == mysqldatapath+"/"+files: + # iscz=False + # print(mysqldatapath+"/"+k+"已存在") + # break + # if not iscz: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # if max(maxlist) == a: + # iscz=True + # print(mysqldatapath+"/"+files+"该文件是最后一个日志,已备份,(最后一个文件可能不是完整的)") + # except:pass + # if iscz: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # os.system("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files) + # print("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files,"复制成功") + # except:pass + # if upload_aliyun: + # print("上传mysql备份目录文件到阿里云oss...") + # t=os.listdir(backmysqlpath) + # maxlist=[] + # for files in t: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # maxlist.append(a) + # except:pass + # path=get_file(backmysqlpath,is_folder=False) + # for files in path: + # sc=True #是否需要上传 + # if bucket.object_exists("backups/"+files['path']):#如果文件已存在阿里云 + # if 'mysql-bin.' in files['name']: + # try: + # a=int(files['name'].replace("mysql-bin.", "")) + # if max(maxlist) == a: + # print(backmysqlpath+"/"+files['name']+"该文件是最后一个日志,所以要上传阿里云") + # else: + # print("文件已在阿里云oss存在") + # sc=False + # except:pass + # else: + # print("文件已在阿里云oss存在") + # sc=False + # if sc: + # oss2.resumable_upload(bucket, "backups/"+files['path'], files['path']) + print("备份完成") diff --git a/app/intapp/controller/soft/mysql.py b/app/intapp/controller/soft/mysql.py new file mode 100644 index 0000000..e0474c4 --- /dev/null +++ b/app/intapp/controller/soft/mysql.py @@ -0,0 +1,338 @@ +from .common import * +import oss2 +def get_data(id): + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + text=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") + conf=json_decode(text) + if not conf: + if ar['edition']=='5.7': + port=3306 + elif ar['edition']=='8.0': + port=3308 + else: + port=3307 + conf={ + "base":{ + 'rootpassword':'intapppasswordtest', + 'path':ar['paths']+ar['title']+ar['edition']+'/data', + 'port':port, #监听端口 + 'max_connections':'200',#最大连接数 + 'max_allowed_packet':'16M', #最大接受的数据包大小 + 'expire_logs_days':'3',#日志保留时间天() + 'query_cache_limit':'1M',#指定单个查询可以使用的缓冲区的大小 + 'query_cache_size':'32M',#查询的缓存大小设置 + 'query_cache_type':'1',#设置缓存的类型, 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 + 'wait_timeout':'9000',#超时等待时间,单位秒,即一个connection在若干秒内无响应 + 'thread_cache_size':'256',# 用于缓存空闲的线程 + 'key_buffer_size':'16M' # 用于指定索引缓冲区的大小 python3 kcw.py --app app --modular intapp --plug soft --uninstall + }, + } + if '5.6' == ar['edition']: + mycnf=file_get_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf") + else: + mycnf=file_get_content("/etc/my.cnf") + data={ + 'conf':conf, + 'ar':ar, + "my":mycnf + } + return successjson(data) +def upd_my(id): + "修改配置文件" + G.setadminlog="mysql修改配置文件" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + data=request.get_json() + if '5.6' == ar['edition']: + file_set_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf",data['text']) + else: + file_set_content("/etc/my.cnf",data['text']) + return successjson() +def upd_data(id): + G.setadminlog="mysql修改基本配置文件" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + data=request.get_json() + filetext=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") + filedata=json_decode(filetext) + if (ar['edition']=='5.7' or ar['edition']=='5.6') and (not filedata or data['base']['rootpassword']!=filedata['base']['rootpassword']):#修改mysql密码 + os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart --skip-grant-tables") + cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -e " + cmd=cmd+'"use mysql;flush privileges;update user set authentication_string=password(' + cmd=cmd+"'"+str(data['base']['rootpassword']) + cmd=cmd+"'" + cmd=cmd+') where user=' + cmd=cmd+"'root';set password=password('"+str(data['base']['rootpassword'])+"');" + cmd=cmd+'"' + if '5.7' != ar['edition']: + cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -p3307 -S "+ar['paths']+ar['title']+ar['edition']+"/tmp/mysql.sock -e " + cmd+='"use mysql;flush privileges;grant all privileges on *.* to root@' + cmd+="'%'" + cmd+=" identified by 'root';update mysql.user set password=password('"+data['base']['rootpassword']+"') where user='root';update mysql.user set grant_priv='Y' where User='root';flush privileges" + cmd=cmd+'"' + # file_set_content("mysqlset",cmd) + pi=subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart") + print(type(strs),strs) + if 'error' in strs: + return errorjson(msg="密码修改失败"+strs) + + # mysqld restart --skip-grant-tables && mysql -uroot -e "flush privileges;update mysql.user set authentication_string=password('123456') where user = 'root'"; + # print(data['base']['rootpassword'],filedata['base']['rootpassword']) + if '5.6' == ar['edition']: + mycnf=ar['paths']+ar['title']+ar['edition']+"/my.cnf" + else: + mycnf="/etc/my.cnf" + f = open(mycnf) + con='' + while True: + line = f.readline() + if not line: + break + elif 'datadir=' in line and data['base']['path']: + line="datadir="+str(data['base']['path'])+"\n" + elif ('port=' in line or 'port =' in line) and data['base']['port']: + line="port="+str(data['base']['port'])+"\n" + elif 'max_connections=' in line and data['base']['max_connections']: + line="max_connections="+str(data['base']['max_connections'])+"\n" + elif 'max_allowed_packet=' in line and data['base']['max_allowed_packet']: + line="max_allowed_packet="+str(data['base']['max_allowed_packet'])+"\n" + elif 'expire_logs_days=' in line and data['base']['expire_logs_days']: + line="expire_logs_days="+str(data['base']['expire_logs_days'])+"\n" + elif 'query_cache_limit=' in line and data['base']['query_cache_limit']: + line="query_cache_limit="+str(data['base']['query_cache_limit'])+"\n" + elif 'query_cache_size=' in line and data['base']['query_cache_size']: + line="query_cache_size="+str(data['base']['query_cache_size'])+"\n" + elif 'query_cache_type=' in line and data['base']['query_cache_type']: + line="query_cache_type="+str(data['base']['query_cache_type'])+"\n" + elif 'wait_timeout=' in line and data['base']['wait_timeout']: + line="wait_timeout="+str(data['base']['wait_timeout'])+"\n" + elif 'thread_cache_size=' in line and data['base']['thread_cache_size']: + line="thread_cache_size="+str(data['base']['thread_cache_size'])+"\n" + elif 'key_buffer_size=' in line and data['base']['key_buffer_size']: + line="key_buffer_size="+str(data['base']['key_buffer_size'])+"\n" + con=con+line + f.close() + f= open(mycnf, "w") + f.write(con) + f.close() + time.sleep(1) + if not filedata or data['base']['path']!=filedata['base']['path']: #修改数据存放目录 + os.system('mysqld'+(ar['edition'].replace(".", ""))+'server stop') + os.system("mkdir -p "+str(data['base']['path'])) + # #mysql数据复制 + if not filedata: + print("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") + os.system("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") + else: + print("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") + os.system("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") + os.system("chown -R mysql "+data['base']['path']+" && chgrp -R mysql "+data['base']['path']) + os.system('mysqld'+(ar['edition'].replace(".", ""))+'server start') + text=json_encode(data) + file_set_content(ar['paths']+ar['title']+ar['edition']+"/config.conf",text) + + return successjson() +def backups(types='whole',db='bankup_all_databases',upload_aliyun=True,edition='5.7'): + "备份mysql" + return BACKUP.backups(types,db,upload_aliyun,edition) +def recovery(types='whole',upload_aliyun=True,edition='5.7'): + "恢复mysql" + if config.app['cli']: + db="backups/kcweb/backup/mysql/bankup_all_databases5.6/20200909-02:51:23.sql.gz" + BACKUP.recovery(types,db,upload_aliyun,edition) + else: + db=request.args.get("db") + Queues.insert(target=BACKUP.recovery,args=(types,db,upload_aliyun,edition),title="恢复mysql"+edition) + return successjson(msg="正在恢复数据库,请在任务队列中查看恢复结果") +class BACKUP: + def recovery(types,db,upload_aliyun,edition): + """恢复数据库""" + if not os.path.isfile("app/common/file/config.conf"): + print("在系统配置中保存备份目录") + return + fileconfig=json_decode(file_get_content("app/common/file/config.conf")) + if not fileconfig: + print("在系统配置中保存备份目录") + return + backpath=fileconfig['aliyun']['backpath'] + if backpath: + if backpath[:1]=='/': + backpath=backpath[1:] + if backpath[-1]=='/': + backpath=backpath[:-1] + else: + backpath="kcweb" + backmysqlpath="backup/mysql" #mysql备份目录 + if not os.path.exists(backmysqlpath): + os.makedirs(backmysqlpath) + mysqlpwd='intapppasswordtest' + mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql"+edition+"/config.conf")) #mysql信息 + if mysqlconf: + mysqldatapath=mysqlconf['base']['path'] + mysqlpwd=mysqlconf['base']['rootpassword'] + port=str(mysqlconf['base']['port']) + else: + if edition=='5.6': + port="3307" + elif edition=='5.7': + port="3306" + elif edition=='8.0': + port="3308" + conf={ + "mysql":{ + "username":"root","password":mysqlpwd,"host":"127.0.0.1","port":port,#mysql信息 + }, + } + if upload_aliyun: + auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) + bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) + bucket.get_object_to_file(db,backmysqlpath+"/database.sql.gz") + os.system("gzip -d "+backmysqlpath+"/database.sql.gz") + os.system("mysql"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -P"+conf['mysql']['port']+" -h"+conf['mysql']['host']+" -p"+conf['mysql']['password']+" < "+backmysqlpath+"/database.sql") + # print("mysql"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -P"+conf['mysql']['port']+" -h"+conf['mysql']['host']+" -p"+conf['mysql']['password']+" < "+backmysqlpath+"/database.sql") + os.remove(backmysqlpath+"/database.sql") + else: + os.system("gzip -d "+backmysqlpath+"/"+db+".sql.gz") + os.system("mysql"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -P"+conf['mysql']['port']+" -h"+conf['mysql']['host']+" -p"+conf['mysql']['password']+" < "+backmysqlpath+"/"+db+".sql") + print("恢复完成") + + def backups(types,db,upload_aliyun,edition): + """备份mysql --cli运行 + types whole表示全量备份。 increment表示增量备份所有 + + db bankup_all_databases表示备份所有数据库。 否则备份指定数据库按逗号分隔 types=whole时有效 + """ + if not os.path.isfile("app/common/file/config.conf"): + print("在系统配置中保存备份目录") + return + fileconfig=json_decode(file_get_content("app/common/file/config.conf")) + if not fileconfig: + print("在系统配置中保存备份目录") + return + + backpath=fileconfig['aliyun']['backpath'] + if backpath: + if backpath[:1]=='/': + backpath=backpath[1:] + if backpath[-1]=='/': + backpath=backpath[:-1] + else: + backpath="kcweb" + backmysqlpath="backup/mysql" #mysql备份目录 + if not os.path.exists(backmysqlpath): + os.makedirs(backmysqlpath) + + mysqlpwd='intapppasswordtest' + mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql"+edition+"/config.conf")) #mysql信息 + if mysqlconf: + mysqldatapath=mysqlconf['base']['path'] + mysqlpwd=mysqlconf['base']['rootpassword'] + port=str(mysqlconf['base']['port']) + else: + if edition=='5.6': + port="3307" + elif edition=='5.7': + port="3306" + elif edition=='8.0': + port="3308" + mysqldatapath="/usr/local/mysql/mysql"+edition+"/data" #mysql数据库存放目 + conf={ + "mysql":{ + "username":"root","password":mysqlpwd,"host":"127.0.0.1","port":port,#mysql信息 + }, + } + if upload_aliyun: + auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) + bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) + if types=='whole': #全量备份 + if not os.path.exists(backmysqlpath): + os.system("mkdir -p "+backmysqlpath) + if db=='bankup_all_databases':#备份所有 + print("全量备份所有数据库:"+db+".sql.gz") + os.system("mysqldump"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" -P"+conf['mysql']['port']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+edition+".sql.gz") + else:#备份指定数据库 + db=re.sub(","," ",db) + print("全量备份指定数据库:"+db+".sql.gz") + os.system("mysqldump"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" -P"+conf['mysql']['port']+" --databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+edition+".sql.gz") + if upload_aliyun: + print(backmysqlpath+"/"+db+edition+".sql.gz","上传mysql备份目录文件到阿里云oss...") + oss2.resumable_upload(bucket, "backups/"+backpath+"/"+backmysqlpath+"/"+db+edition+"/"+time.strftime("%Y%m%d-%H:%M:%S",time.localtime(times()))+".sql.gz",backmysqlpath+"/"+db+edition+".sql.gz") + filelist=[] + for obj in oss2.ObjectIterator(bucket, prefix="backups/"+backpath+"/"+backmysqlpath+"/"+db+edition+"/"): + filelist.append(obj.key) + i=0 + while True: + if len(filelist)-i <= 30: #在阿里云保留30个备份文件 其他上传 + break + bucket.delete_object(filelist[i]) + i+=1 + + # elif types=='increment': #增量备份所有 + # if not os.path.exists(backmysqlpath) or not os.path.isfile(backmysqlpath+"/"+db+".sql.gz"): + # os.system("mkdir -p "+backmysqlpath) + # print("全量备份所有数据库:"+db+".sql.gz") + # os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/increment_all_databases.sql.gz") + # print("备份mysql二进制文件...") + # t=os.listdir(backmysqlpath) + # lis=os.listdir(mysqldatapath) + # maxlist=[] + # for files in lis: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # maxlist.append(a) + # except:pass + # for files in lis: + # iscz=True #是否需要复制 + # if iscz: + # for k in t: + # if mysqldatapath+"/"+k == mysqldatapath+"/"+files: + # iscz=False + # print(mysqldatapath+"/"+k+"已存在") + # break + # if not iscz: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # if max(maxlist) == a: + # iscz=True + # print(mysqldatapath+"/"+files+"该文件是最后一个日志,已备份,(最后一个文件可能不是完整的)") + # except:pass + # if iscz: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # os.system("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files) + # print("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files,"复制成功") + # except:pass + # if upload_aliyun: + # print("上传mysql备份目录文件到阿里云oss...") + # t=os.listdir(backmysqlpath) + # maxlist=[] + # for files in t: + # if 'mysql-bin.' in files: + # try: + # a=int(files.replace("mysql-bin.", "")) + # maxlist.append(a) + # except:pass + # path=get_file(backmysqlpath,is_folder=False) + # for files in path: + # sc=True #是否需要上传 + # if bucket.object_exists("backups/"+files['path']):#如果文件已存在阿里云 + # if 'mysql-bin.' in files['name']: + # try: + # a=int(files['name'].replace("mysql-bin.", "")) + # if max(maxlist) == a: + # print(backmysqlpath+"/"+files['name']+"该文件是最后一个日志,所以要上传阿里云") + # else: + # print("文件已在阿里云oss存在") + # sc=False + # except:pass + # else: + # print("文件已在阿里云oss存在") + # sc=False + # if sc: + # oss2.resumable_upload(bucket, "backups/"+files['path'], files['path']) + print("备份完成") diff --git a/app/intapp/controller/soft/nginx.py b/app/intapp/controller/soft/nginx.py new file mode 100644 index 0000000..bae9675 --- /dev/null +++ b/app/intapp/controller/soft/nginx.py @@ -0,0 +1,419 @@ +from .common import * +import traceback +def index(id='',types='getinfo'): + "nginx配置文件" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title'] + edition=ar['edition'] + if types=='getinfo': + if os.path.isfile(paths+filenames+edition+'/logs/error.log'): + # print(paths+filenames+'/logs/error.log') + # f=open(paths+filenames+'/logs/error.log','r') + # logserror=f.read() + # f.close() + logserror='' + else:logserror='' + if os.path.isfile(paths+filenames+edition+'/logs/access.log'): + # f=open(paths+filenames+'/logs/access.log','r',encoding="utf-8") + # logsaccess=f.read() + # f.close() + logsaccess='' + else:logsaccess='' + f=open(paths+filenames+edition+'/conf/nginx.conf','r',encoding="utf-8") + confnginx=f.read() + data={ + 'logs':{'error':logserror,'access':logsaccess}, + 'conf':{'nginx':confnginx}, + 'ar':ar, + } + return successjson(data) + elif types=='updconf': + con=request.get_json() + f=open(paths+filenames+edition+'/conf/nginx.conf','w',encoding="utf-8") + f.write(con['text']) + f.close() + return successjson() + else: + return errorjson(msg="未知类型") +def anphp(): + "已安装的php以及伪静态模板" + nginx=sqlite('soft',model_intapp_soft_path).where([('status','egt','4'),'and',('platform','eq',get_sysinfo()['uname'][0]),'and',('title','like','nginx%')]).find() + if nginx: + pseudo_static_tpl=get_file(nginx['paths']+nginx['title']+nginx['edition']+'/conf/vhost/webtpl/rewrite') #伪静态模板 + rewr=[] + for k in pseudo_static_tpl: + rewr.append({'name':k['name'],'text':file_get_content(k['path'])}) + data={ + "php":sqlite('soft',model_intapp_soft_path).where("title like '%php%' and (status=4 or status=10) and title not like '%phpmyadmin%'").select(), + "rewr":rewr + } + return successjson(data) + else: + return successjson() +def webdescribesfind(): + "获取指定网站信息" + title=request.args.get("title") + return successjson(sqlite("web",model_intapp_soft_path).where("title='"+title+"'").find()) +def weblist(): + "网站列表" + where=False + pagenow=int(request.args.get('pagenow')) + pagesize=int(request.args.get('pagesize')) + kw=request.args.get('kw') + if kw: + where=[("title","like","%"+str(kw)+"%"),'or',("describes","like","%"+str(kw)+"%"),'or',("domain","like","%"+str(kw)+"%")] + if not pagenow: + pagenow=1 + if not pagesize: + pagesize=10 + lists=sqlite("web",model_intapp_soft_path).where(where).page(pagenow,pagesize).select() + i=0 + for k in lists: + # lists[i]['domain']=k['domain'].split("\n") + lists[i]['balancing'] =json_decode(k['balancing']) + lists[i]['proxy_set_header'] =json_decode(k['proxy_set_header']) + lists[i]['header'] =json_decode(k['header']) + i+=1 + count=sqlite("web",model_intapp_soft_path).where(where).count() + return successjson(return_list(lists,count,pagenow,pagesize)) +def add_web(): + G.setadminlog="添加或更新nginx网站" + data=request.get_json() + status,msg=funadd_web(data) + if status: + return successjson(msg) + else: + return errorjson(msg=msg) +def _banddomain(id,types,domain): + G.setadminlog="绑定域名" + # domain=request.args.get('domain') + if '.' not in domain: + # return errorjson(msg="域名格式错误") + return False,'域名格式错误' + if not domain: + # return errorjson(msg="域名参数错误") + return False,'域名参数错误' + web=sqlite("web",model_intapp_soft_path).where("id",id).find() + if web: + if(sqlite("web",model_intapp_soft_path).where("domain like '%"+domain+"%'").count()): + if types=='add': + # return successjson(msg="该域名已被使用",code=1) + return True,'该域名已被使用' + data=web + if domain: + if types=='add': + data['domain']=data['domain']+"\n"+domain + elif types=='del': + data['domain']=data['domain'].replace("\n"+domain, "") + data['domain']=data['domain'].replace(domain, "") + # return errorjson(data) + else: + # return errorjson(msg="types错误") + return False,'types错误' + if data['header']: + data['header']=json_decode(data['header']) + data['proxy_set_header']=json_decode(data['proxy_set_header']) + data['balancing']=json_decode(data['balancing']) + return funadd_web(data,types) + # return status,msg + # if status: + # return successjson(msg) + # else: + # return errorjson(msg=msg) + else: + return False,'id错误' + # return errorjson(msg="id错误") +def funadd_web(data,types=""): + "添加或更新网站" + nginx=sqlite('soft',model_intapp_soft_path).where([('status','egt','4'),'and',('platform','eq',get_sysinfo()['uname'][0]),'and',('title','like','nginx%')]).find() + if not nginx: + return errorjson(msg='安装nginx服务器后才创建网站') + addtime=times() + + if data['domain']=='': + return False,"域名不能为空" + if data['port']=='': + return False,"端口不能为空" + if data['client_max_body_size']=='': + return False,"上传限制不能为空" + if data['path']=='': + data['path']="/www/wwwroot/" + paths=nginx['paths'] + try: + ttt1=data['domain'].split("\n") + if data['id'] and sqlite('web',model_intapp_soft_path).where("id",data['id']).count(): + # if types!='del': + # where="port="+str(data['port'])+" and id != "+str(data['id'])+" and (" #[('port','eq',data['port'])] + # for kk in ttt1: + # where=where+"domain like '"+kk+"%'"+" or " + # where=where[:-4]+")" + # ttt2=sqlite('web',model_intapp_soft_path).where(where).find() + # if ttt2: + # ttt2=ttt2['domain'].split("\n") + # for k in ttt2: + # for kk in ttt2: + # if k==kk: + # return False,k+"已在本服务器其他站点使用被使用" + domains=sqlite('web',model_intapp_soft_path).where("id",data['id']).field("only").find()['only'] + else: + data['id']='' + where="port="+data['port']+" and (" + for kk in ttt1: + where=where+"domain like '%"+kk+"%'"+" or " + where=where[:-4]+")" + domains=ttt1[0]+":"+str(data['port']) + data['only']=domains + ttt=sqlite('web',model_intapp_soft_path).where(where).find() + if ttt: + ttt=ttt['domain'].split("\n") + for k in ttt: + for kk in ttt1: + if k==kk: + return False,k+"已被使用" + ttt=data['domain'].split("\n") + server_name='' + for k in ttt: + server_name=str(server_name)+" "+str(k) + + if nginx['platform']=='Linux': + if data['webtpl']=='': + return False,"请选择配置文件模板" + filenames=nginx['title']+nginx['edition'] + servertpl=paths+filenames+'/conf/vhost/webtpl/'+data['webtpl'] + ssl_certificate="" + ssl_certificate_key="" + try: + ssl_certificate=data['ssl_certificate'] + ssl_certificate_key=data['ssl_certificate_key'] + except: + data['ssl_certificate']='' + data['ssl_certificate_key']='' + try: + data['header'] + except: + data['header']='' + try: + data['ssl'] + except: + data['ssl']='' + try: + data['rewrite'] + except: + data['rewrite']='' + if data['ssl']: + ssl=443 + if len(data['ssl_certificate'])>5 and len(data['ssl_certificate_key'])>5: + ssl_certificate=data['ssl_certificate'] + ssl_certificate_key=data['ssl_certificate_key'] + # print(ssl_certificate_key) + else: + key=paths+filenames+'/conf/vhost/rewrite/'+domains+".key" + pem=paths+filenames+'/conf/vhost/rewrite/'+domains+".pem" + file_set_content(key,data['key']) + file_set_content(pem,data['pem']) + ssl_certificate=paths+filenames+"/conf/vhost/rewrite/"+domains+".pem" + ssl_certificate_key=paths+filenames+"/conf/vhost/rewrite/"+domains+".key" + print(ssl_certificate) + else: + if os.path.isfile(paths+filenames+'/conf/vhost/rewrite/'+domains+".key") and os.path.isfile(paths+filenames+'/conf/vhost/rewrite/'+domains+".pem"): + sslttt1=file_get_content(paths+filenames+'/conf/vhost/rewrite/'+domains+".key") + sslttt2=file_get_content(paths+filenames+'/conf/vhost/rewrite/'+domains+".pem") + if len(sslttt1)>10 and len(sslttt2)>10: + ssl=443 + else: + ssl=False + else: + ssl=False + if not ssl_certificate or not ssl_certificate_key: + ssl='' + if 'php' in data['webtpl'] and len(data['rewrite'])>4:#php伪静态 + file_set_content(paths+filenames+"/conf/vhost/rewrite/"+domains,data['rewrite']) + elif not os.path.isfile(paths+filenames+"/conf/vhost/rewrite/"+domains): + file_set_content(paths+filenames+"/conf/vhost/rewrite/"+domains,'') + if data['webtpl']=='static' or data['webtpl']=='vue' or 'php' in data['webtpl']: + t=kcwTemplate(filename=servertpl) + text=t.render(client_max_body_size=data['client_max_body_size'],port=data['port'],ssl=ssl,ssl_certificate=ssl_certificate,ssl_certificate_key=ssl_certificate_key, + server_name=server_name,webpath=data['path'],rewrite=paths+filenames+"/conf/vhost/rewrite/"+domains,domains=domains,header=data['header']) + elif data['webtpl']=='balancing':#添加负载均衡 + balancing=data['balancing'] #负载均衡列表 + proxy_set_header=data['proxy_set_header'] #自定义转发请求头列表 + for k in data['balancing']: + if k['ip']=='' or k['port']=='': + return False,"请填写负载均衡ip和端口" + t=kcwTemplate(filename=servertpl) + text=t.render(client_max_body_size=data['client_max_body_size'],port=data['port'],ssl=ssl,balancing=balancing,proxy_set_header=proxy_set_header,ssl_certificate=ssl_certificate,ssl_certificate_key=ssl_certificate_key, + server_name=server_name,webpath=data['path'],rewrite=paths+filenames+"/conf/vhost/rewrite/"+domains,domains=domains,header=data['header']) + f=open(paths+filenames+"/conf/vhost/"+domains+'.conf','w',encoding="utf-8") + f.write(text) + f.close() + os.system("nginx -s reload") + if not os.path.exists(data['path']): + os.makedirs(data['path']) + f=open(data['path']+"/index.html",'w',encoding="utf-8") + f.write('网站创建成功

恭喜您!网站创建成功

') + f.close() + f=open(data['path']+"/index.php",'w',encoding="utf-8") + f.write("") + f.close() + try: + data['servers']=paths+filenames + except:pass + try: + del data['key'] + del data['pem'] + except:pass + del data['ssl'] + del data['rewrite'] + data['balancing'] =json_encode(data['balancing']) + data['proxy_set_header'] =json_encode(data['proxy_set_header']) + data['header'] =json_encode(data['header']) + if data['id']: + data['updtime']=addtime + data['status']=1 + try: + sqlite('web',model_intapp_soft_path).where("id",data['id']).update(data) + except: + pass + else: + pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + if len(strs) > 1: + return False,strs + else: + del data['id'] + data['addtime']=addtime + data['updtime']=addtime + sqlite('web',model_intapp_soft_path).insert(data) + data['id']=sqlite('web',model_intapp_soft_path).max("id") + except: + print(traceback.format_exc()) + file_set_content("server.log",traceback.format_exc()) + return False,"失败,检查参数是否有误" + else: + return True,data['id'] +def del_web(id=0,path=0): + #path=1 表示删除网站目录 ,linux和windows已完成 + "删除网站" + G.setadminlog="删除网站" + title=request.args.get("title") + if not id and title: + where="title = '"+title+"'" + else: + where="id='"+str(id)+"'" + nginx=sqlite('web',model_intapp_soft_path).where(where).find() + if not nginx: + return successjson(msg="不存在") + print(nginx) + filenames=nginx['servers'] + if get_sysinfo()['uname'][0]=='Linux': + if os.path.isfile(filenames+"/conf/vhost/"+nginx['only']+'.conf'): + os.remove(filenames+"/conf/vhost/"+nginx['only']+'.conf') + if os.path.isfile(filenames+"/conf/vhost/rewrite/"+nginx['only']): + os.remove(filenames+"/conf/vhost/rewrite/"+nginx['only']) + if os.path.isfile(filenames+"/logs/"+nginx['only']+".access.log"): + os.remove(filenames+"/logs/"+nginx['only']+".access.log") + if os.path.isfile(filenames+'/conf/vhost/rewrite/'+nginx['only']+".key"): + os.remove(filenames+'/conf/vhost/rewrite/'+nginx['only']+".key") + if os.path.isfile(filenames+'/conf/vhost/rewrite/'+nginx['only']+".pem"): + os.remove(filenames+'/conf/vhost/rewrite/'+nginx['only']+".pem") + pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + elif get_sysinfo()['uname'][0]=='Windows': + if os.path.isfile(filenames+"/conf/vhost/"+nginx['only']+'.conf'): + os.remove(filenames+"/conf/vhost/"+nginx['only']+'.conf') + if os.path.isfile(filenames+"/conf/vhost/rewrite/"+nginx['only']): + os.remove(filenames+"/conf/vhost/rewrite/"+nginx['only']) + if os.path.isfile(filenames+"/logs/"+nginx['only']+".access.log"): + os.remove(filenames+"/logs/"+nginx['only']+".access.log") + os.system("cd "+filenames+" & stop.bat") + time.sleep(3) + os.system("cd "+filenames+" & start.bat") + else: + return errorjson(msg="无法匹配系统") + if path=='1' and os.path.exists(nginx['path']): + shutil.rmtree(nginx['path']) + sqlite('web',model_intapp_soft_path).where(where).delete() + pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + if len(strs) > 1: + return errorjson(msg=strs) + return successjson() + +def getssl(id): + ar=sqlite('web',model_intapp_soft_path).where('id',id).find() + key=ar['servers']+'/conf/vhost/rewrite/'+ar['only']+".key" + pem=ar['servers']+'/conf/vhost/rewrite/'+ar['only']+".pem" + data={ + "key":file_get_content(key), + "pem":file_get_content(pem) + } + return successjson(data) +def getrewr(id): + "获取伪静态" + ar=sqlite('web',model_intapp_soft_path).where('id',id).find() + return successjson(file_get_content(ar['servers']+'/conf/vhost/rewrite/'+ar['only'])) +def getconfig(id,types='get'): + "获取配置文件" + ar=sqlite('web',model_intapp_soft_path).where('id',id).find() + if types=='get': + return successjson(file_get_content(ar['servers']+'/conf/vhost/'+ar['only']+".conf")) + elif types=='set': + data=request.get_json() + file_set_content(ar['servers']+'/conf/vhost/'+ar['only']+".conf",data['text']) + pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + if len(strs) > 1: + return errorjson(msg=strs) + return successjson() + + +def sslfolde(): + "Let's Encrypt证书夹" + paths="/etc/letsencrypt/live/" + if not os.path.exists(paths): + return errorjson(code=1,msg="Let's Encrypt证书夹不存在,在插件市场安装LetsEncrypt插件创建证书后再使用该功能") + try: + lis=os.listdir(paths) + except: + return errorjson(code=1,msg="无法打开"+str(paths)) + lists=[] + for files in lis: + types="folder" + config={} + if os.path.isfile(paths+"/"+files): + types="file" + else: + config=file_get_content(paths+"/"+files+"/config.conf") + if config: + config=json_decode(config) + zd={"name":files,"types":types,"config":config} + lists.append(zd) + data=return_list(lists,count=len(lis),pagenow=1,pagesize=len(lis)) + data['paths']=paths + "文件列表" + return successjson(data) +def ssltpl(): + "Let's Encrypt证书内容" + name=request.args.get("name") + paths="/etc/letsencrypt/live/"+name + chain=file_get_content(paths+"/chain.pem") + fullchain=file_get_content(paths+"/fullchain.pem") + privkey=file_get_content(paths+"/privkey.pem") + cert=file_get_content(paths+"/cert.pem") + data={ + "chain":chain, + "fullchain":fullchain, + "privkey":privkey, + "cert":cert + } + return successjson(data) + \ No newline at end of file diff --git a/app/intapp/controller/soft/page.py b/app/intapp/controller/soft/page.py new file mode 100644 index 0000000..9e87cb1 --- /dev/null +++ b/app/intapp/controller/soft/page.py @@ -0,0 +1,34 @@ +from .common import * +def home(): + if sysisphone(): + return response.tpl("../tplm/index/home") + else: + return response.tpl("index/home") +def pub(html): + if sysisphone(): + return response.tpl("../tplm/page/%s" % html) + else: + return response.tpl("page/%s" % html) +def s(fun,html): + id=request.args.get("id") + if sysisphone(): + lefttext=request.args.get('lefttext') + if not lefttext: + lefttext='应用' + lefturl=request.args.get('lefturl') + if not lefturl: + lefturl='myapp' + lefttype=request.args.get('lefttype') + if not lefttype: + lefttype='lefturl' + return response.tpl("../tplm/%s/%s" % (fun,html),id=id,lefttext=lefttext,lefturl=lefturl,lefttype=lefttype) + else: + return response.tpl("%s/%s" % (fun,html),id=id) +def soft(html): + id=request.args.get("id") + types=request.args.get("types") + data=sqlite("soft",model_intapp_soft_path).where("id",id).find() + if sysisphone(): + return response.tpl("../tplm/soft/%s" % html,id=id,data=data,types=types) + else: + return response.tpl("soft/%s" % html,id=id,data=data,types=types) \ No newline at end of file diff --git a/app/intapp/controller/soft/php.py b/app/intapp/controller/soft/php.py new file mode 100644 index 0000000..d3e9798 --- /dev/null +++ b/app/intapp/controller/soft/php.py @@ -0,0 +1,272 @@ +from .common import * +def ini(id,is_upd=0): + "php.ini配置文件" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + if ar['platform']=='Linux': + filepath=paths+filenames+"/bin/php.ini" + elif ar['platform']=='Windows': + filepath=paths+filenames+"/php.ini" + else: + return errorjson(code=1,msg="不支持此时平台") + if is_upd: #修改配置 + G.setadminlog="修改配置ini" + data=request.get_json() + file_set_content(filepath,data['text']) + return successjson() + else: + data={ + 'ini':file_get_content(filepath), + 'php':ar + } + return successjson(data) +def www_conf(id,is_upd=0): + "www.conf配置文件" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + if ar['platform']=='Linux': + filepath=paths+filenames+"/etc/php-fpm.d/www.conf" + if 'php5.6' in filenames: + filepath=paths+filenames+"/etc/php-fpm.conf" + elif ar['platform']=='Windows': + filepath='' + else: + return errorjson(code=1,msg="不支持此时平台") + if is_upd: #修改配置 + G.setadminlog="修改配置www.conf" + data=request.get_json() + file_set_content(filepath,data['text']) + return successjson() + else: + data={ + 'www_conf':file_get_content(filepath), + 'php':ar + } + return successjson(data) +def phpfpm(id,is_upd=0): + "phpfpm配置信息" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + if ar['platform']=='Linux': + if not os.path.exists(paths+filenames+"/bin/conf"): + os.makedirs(paths+filenames+"/bin/conf") + filepath=paths+filenames+"/bin/conf/phpfpm.conf" + phpfpmpath=paths+filenames+"/etc/php-fpm.d/www.conf" + if 'php5.6' in filenames: + phpfpmpath=paths+filenames+"/etc/php-fpm.conf" + else: + filepath='' + phpfpmpath='' + if is_upd: #修改php-fpm配置信息 + data=request.get_json() + f = open(phpfpmpath) + con='' + while True: + line = f.readline() + if not line: + break + elif 'pm = ' in line and '=' in line: #运行描述 + line="pm = "+data['text']['pm']+"\n" + elif 'pm.max_children' in line and '=' in line:# 允许创建的最大子进程数 + line="pm.max_children = "+data['text']['max_children']+"\n" + elif 'pm.start_servers' in line and '=' in line:# 起始进程数(服务启动后初始进程数量) + line="pm.start_servers = "+data['text']['start_servers']+"\n" + elif 'pm.min_spare_servers' in line and '=' in line:# 起始进程数(服务启动后初始进程数量) + line="pm.min_spare_servers = "+data['text']['min_spare_servers']+"\n" + elif 'pm.max_spare_servers' in line and '=' in line:# 最大空闲进程数(当空闲进程达到此值时清理) + line="pm.max_spare_servers = "+data['text']['max_spare_servers']+"\n" + con=con+line + f.close() + f= open(phpfpmpath, "w") + f.write(con) + f.close() + file_set_content(filepath,json_encode(data['text'])) + return successjson() + else: + phpfpm=json_decode(file_get_content(filepath)) + if not phpfpm: + phpfpm='' + data={ + 'phpfpm':phpfpm, + 'php':ar + } + return successjson(data) +def base(id,is_upd=0): + "基本配置信息" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + if ar['platform']=='Linux': + if not os.path.exists(paths+filenames+"/bin/conf"): + os.makedirs(paths+filenames+"/bin/conf") + filepath=paths+filenames+"/bin/conf/base.ini" + phpinipath=paths+filenames+"/bin/php.ini" + elif ar['platform']=='Windows': + if not os.path.exists(paths+filenames+"/conf"): + os.makedirs(paths+filenames+"/conf") + filepath=paths+filenames+"/conf/base.ini" + phpinipath=paths+filenames+"/php.ini" + if is_upd: #修改基本配置信息 + #修改php.ini配置 + G.setadminlog="修改php.ini配置" + data=request.get_json() + f = open(phpinipath) + con='' + while True: + line = f.readline() + if not line: + break + elif 'max_execution_time' in line and '=' in line:#最大执行时间 + line="max_execution_time = "+data['text']['max_execution_time']+"\n" + elif 'max_input_time' in line and '=' in line:#最大输入时间 + line="max_input_time = "+data['text']['max_input_time']+"\n" + elif 'memory_limit' in line and '=' in line:#内存限制 + line="memory_limit = "+data['text']['memory_limit']+"M\n" + elif 'file_uploads' == line[0:12] and '=' in line:#是否允许文件上传 + line="file_uploads = "+data['text']['file_uploads']+"\n" + elif 'upload_max_filesize' in line and '=' in line:#上传大小限制 + line="upload_max_filesize = "+data['text']['upload_max_filesize']+"M\n" + elif 'max_file_uploads' in line and '=' in line:#上传数量限制 + line="max_file_uploads = "+data['text']['max_file_uploads']+"\n" + elif 'post_max_size' in line and '=' in line:#上传数量限制 + line="post_max_size = "+data['text']['post_max_size']+"M\n" + elif 'allow_url_fopen' in line and '=' in line: + line="allow_url_fopen = "+data['text']['allow_url_fopen']+"\n" + elif 'allow_url_include' in line and '=' in line: + line="allow_url_include = "+data['text']['allow_url_include']+"\n" + elif 'default_socket_timeout' in line and '=' in line: + line="default_socket_timeout = "+data['text']['default_socket_timeout']+"\n" + con=con+line + f.close() + f= open(phpinipath, "w") + f.write(con) + f.close() + file_set_content(filepath,json_encode(data['text'])) + # print(data['text']) + return successjson() + else: + base=json_decode(file_get_content(filepath)) + if not base: + base='' + data={ + 'base':base, + 'php':ar + } + return successjson(data) +def extenlist(id,is_upd=0): + "php扩展信息列表" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + lists=sqlite('php_exten',model_intapp_soft_php_exten_path).where('pid',id).select() + data={ + 'extenlist':lists, + 'php':ar + } + return successjson(data) +def log(id): + "待完善" + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + filename=ar['filename'] + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + if ar['platform']=='Linux': + filepath=paths+filenames+"" + elif ar['platform']=='Windows': + filepath=paths+filenames+"" + data={ + 'log':file_get_content(filepath), + 'php':ar + } + return successjson(data) + +def add_php_exten(): + "增加php扩展" + G.setadminlog="安装php扩展" + data=request.get_json() + data['addtime']=times() + data['updtime']=times() + sqlite('php_exten',model_intapp_soft_php_exten_path).insert(data) + return successjson() +def del_php_exten(id): + "删除php扩展" + G.setadminlog="删除php扩展" + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).delete() + return successjson() + +def installext(id): + is_del=False #是否删除成功 + "安装php扩展和下载扩展" + G.setadminlog="安装php扩展和下载扩展" + ar=sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).find() + if ar['status']==0: + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':1,'msg':''}) + Queues.insert(target=__installextqu,args=(ar,),title="安装php-"+ar['title']+"扩展") + elif ar['status']==4: + "卸载扩展" + paths=request.get_json()['paths'] + if get_sysinfo()['uname'][0]=='Linux': + if os.path.exists(paths): + + confile=paths+"bin/php.ini" + f= open(confile, "r") + con='' + while True: + line = f.readline() + if not line: + break + elif str(ar['title']) in line: + line="" + is_del=True + con=con+line + f.close() + f= open(confile, "w") + f.write(con) + f.close() + + # confile=paths+"bin/php.ini" + # f= open(confile, "r") + # con=f.read() + # f.close() + # con=con.replace("extension="+str(ar['title'])+".so\n","") + # f= open(confile, "w") + # f.write(con) + # f.close() + # if is_del: + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':0,'msg':''}) + if 'php7.0' in paths: + os.system("pkill php70-fpm && php70-fpm -c "+paths+"php7.0/etc/php.ini") + elif 'php7.1' in paths: + os.system("pkill php71-fpm && php71-fpm -c "+paths+"php7.1/etc/php.ini") + elif 'php7.2' in paths: + os.system("pkill php72-fpm && php72-fpm -c "+paths+"php7.2/etc/php.ini") + elif 'php7.3' in paths: + os.system("pkill php73-fpm && php73-fpm -c "+paths+"php7.3/etc/php.ini") + elif 'php7.4' in paths: + os.system("pkill php74-fpm && php74-fpm -c "+paths+"php7.4/etc/php.ini") + # else: + # return errorjson(code=1,msg='卸载失败') + else: + return errorjson(code=1,msg='php文件夹错误') + return successjson() +def get_exten(id): + return successjson(sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).find()) +def __installextqu(ar): + "安装php扩展" + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':3,'msg':''}) + try: + cmd="wget "+config.domain['kcwebfile']+"/"+ar['filename'] + # os.system(cmd) + print(cmd) + pi=subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + ars=pi.stdout.read().decode() + ars=ars.split("\n") + strs=ars[len(ars)-2] + if 'success' in strs: + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':4,'msg':''}) + else: + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':0,'msg':'安装失败'}) + # sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':4,'msg':''}) + except Exception as e: + sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':0,'msg':'安装失败'+str(e)}) \ No newline at end of file diff --git a/app/intapp/controller/soft/redis.py b/app/intapp/controller/soft/redis.py new file mode 100644 index 0000000..1464e6a --- /dev/null +++ b/app/intapp/controller/soft/redis.py @@ -0,0 +1,71 @@ +from .common import * +def conf(id,is_upd=0): + "redis配置文件信息" + is_upd=int(is_upd) + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + if ar['platform']=='Linux': + filepath=paths+filenames+"/redis.conf" + else: + return errorjson(code=1,msg="不支持此时平台") + if is_upd: #修改配置 + data=request.get_json() + if not data['text']: + return errorjson(code=1,msg='不允许清空配置文件') + file_set_content(filepath,data['text']) + return successjson() + else: + data=file_get_content(filepath) + # print(filepath) + return successjson(data) +def base(id,is_upd=0): + "redis配置文件信息" + is_upd=int(is_upd) + ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() + paths=ar['paths'] + filenames=ar['title']+ar['edition'] + + if ar['platform']=='Linux': + filepath=paths+filenames+"/redis.conf" + jsonpath=paths+filenames+"/redis.json" + else: + return errorjson(code=1,msg="不支持此时平台") + if is_upd: #修改配置 + G.setadminlog="修改redis配置" + data=request.get_json() + f = open(filepath) + con='' + while True: + line = f.readline() + if not line: + break + elif 'bind ' in line and '\n' in line and '#' not in line: + line="bind "+data['bind']+"\n" + elif 'port ' in line and '\n' in line and '#' not in line: + line="port "+data['port']+"\n" + elif 'timeout ' in line and '\n' in line and '#' not in line: + line="timeout "+data['timeout']+"\n" + elif 'maxclients ' in line and '\n' in line: + line="maxclients "+data['maxclients']+"\n" + elif 'databases ' in line and '\n' in line and '#' not in line: + line="databases "+data['databases']+"\n" + elif 'requirepass ' in line and '\n' in line: + if data['requirepass']: + line="requirepass "+data['requirepass']+"\n" + else: + line="# requirepass "+data['requirepass']+"\n" + elif 'maxmemory ' in line and '\n' in line and len(line)<20: + line="maxmemory "+data['maxmemory']+"\n" + con=con+line + f.close() + f= open(filepath, "w") + f.write(con) + f.close() + file_set_content(jsonpath,json_encode(data)) + return successjson() + else: + v=file_get_content(jsonpath) + data=json_decode(v) + data['ar']=ar + return successjson(data) \ No newline at end of file diff --git a/app/intapp/controller/soft/role.txt b/app/intapp/controller/soft/role.txt new file mode 100644 index 0000000..1da7c1d --- /dev/null +++ b/app/intapp/controller/soft/role.txt @@ -0,0 +1,44 @@ +#以下是该插件的路由,index容器会自动把以下路由加入到权限管理中 该文件必须使用utf-8编码 +软件页面,/intapp/soft/index/index +软件信息,/intapp/soft/index/gettitle +软件列表,/intapp/soft/index/softlist +更新软件列表,/intapp/soft/index/updatesoftlist +软件状态描述,/intapp/soft/index/getstatus +安装软件,/intapp/soft/index/insert +启动软件,/intapp/soft/index/start +停止软件,/intapp/soft/index/stop +卸载软件,/intapp/soft/index/uninstall +gitssh公钥,/intapp/soft/index/gitssh +软件设置页面,/intapp/soft/page/soft + +frp服务端内容,/intapp/soft/frp/get_server +frp运行状态,/intapp/soft/frp/run_status +frp重启,/intapp/soft/frp/restart +frp停止,/intapp/soft/frp/stop +修改frp服务端配置,/intapp/soft/frp/upd_server +frp客户端内容,/intapp/soft/frp/get_client +修改frp客户端配置,/intapp/soft/frp/upd_client + +mongodb管理,/intapp/soft/mongodb + +获取mysql配置,/intapp/soft/mysql/get_data +修改mysql配置,/intapp/soft/mysql/upd_my +修改mysql密码,/intapp/soft/mysql/upd_data +备份mysql,/intapp/soft/mysql/backups + +nginx网站管理,/intapp/soft/page/s +修改nginx配置,/intapp/soft/nginx/index +nginx伪静态模板,/intapp/soft/nginx/anphp +nginx网站信息,/intapp/soft/nginx/webdescribesfind +nginx网站列表,/intapp/soft/nginx/weblist +添加更新nginx网站,/intapp/soft/nginx/add_web +删除nginx网站,/intapp/soft/nginx/del_web +获取ssl,/intapp/soft/nginx/getssl +获取伪静态内容,/intapp/soft/nginx/getrewr +获取配置文件,/intapp/soft/nginx/getconfig +证书夹,/intapp/soft/nginx/sslfolde +证书内容,/intapp/soft/nginx/ssltpl + +php管理,/intapp/soft/php + +redis管理,/intapp/soft/redis diff --git a/app/intapp/controller/soft/tpl/index/home.html b/app/intapp/controller/soft/tpl/index/home.html new file mode 100644 index 0000000..cc19803 --- /dev/null +++ b/app/intapp/controller/soft/tpl/index/home.html @@ -0,0 +1,430 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+
+ + + 搜索 + + + 更新软件列表 + +
+
+ + % if config.app['appmode']=='develop': + + + + % endif + + + + + + + + + + + + + + + + + + +
+
+ + +
+ + + + + + + + + + + + + + + 如:/usr/local/php/ + + + + + + + + + + 注:需要在后端接口上配置wget文件地址 + + + + Linux + Windows + + + + + + +
+ + + diff --git a/app/intapp/controller/soft/tpl/index/web.html b/app/intapp/controller/soft/tpl/index/web.html new file mode 100644 index 0000000..7d62981 --- /dev/null +++ b/app/intapp/controller/soft/tpl/index/web.html @@ -0,0 +1,582 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+
+    + + + 搜索 + 添加网站 + + + 下载数据 + + 上传intapp_soft.zip + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
域名
端口 + 上传限制:MB
网站名
配置文件模板 + + + + +
备注
网站目录 + + +
+
+ + + + + + + +
+ + + + + + + 如:Access-Control-Allow-Origin * + 如:403 /403.html + + +
+ 自定义配置:自定义响应或自定义错误页面 + +
+ +
+
+ + + + + + + + +
+ + + + + + + + + +   + + +
+ nginx负载均衡是一个代理均衡转发器 + +
+ +
+ + 取 消 + 修改添加 + +
+ + +
+
+ + +
+
+ 您已配置Let's证书


+ ssl_certificate :{{admin.ssl_certificate}}

+ ssl_certificate_key :{{admin.ssl_certificate_key}}

+ 使用自有证书 +
+
+
+ 密钥(KEY) + +
+
+ 证书(PEM格式) + +
+ 确定 +
+
+
+ + +
+ + + + + +
+ 保存
+ 选择伪静态模板就可以了,修改了记得要保存哦!重启nginx生效 +
+ +
+ + 确定 +
+
+ +
+ + + + + + + +
支持域名有效期
+ + {{item1.domain}}     + + + + {{time_date(item.config.createtime+7776000,true)}} + + + + 使用 + +
+
+
+
+ + + diff --git a/app/intapp/controller/soft/tpl/soft/frp.html b/app/intapp/controller/soft/tpl/soft/frp.html new file mode 100644 index 0000000..edfcb44 --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/frp.html @@ -0,0 +1,250 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+ + + + + 重启 + 停止 + + 保存 + + + + + + +
+ 重启 + 停止 + + + + 这是服端监听的地址 + + + + 这是服端监听的端口 + + + + 这是upd监听的端口 + + + + 这是kcp监听的端口 + + + + 这是http监听的端口 + + + + 这是https监听的端口 + + + + 这是dashboard监听的ip地址 + + + + 这是dashboard监听的端口 + + + + 这是dashboard监听的用户名 + + + + 这是dashboard监听的密码 + + + + 这是frp的验证机制 + + + + 这是frp的验证串的有效时间 + + + + + + + + 日志保持多少天 + + + + + + + + 白名单端口 + + + + 最大值进程数 + + + + + + + + + + + + + + + 保存 + + +
+ +
+ + + 保存 + +
+
+
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/git.html b/app/intapp/controller/soft/tpl/soft/git.html new file mode 100644 index 0000000..ce87f2d --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/git.html @@ -0,0 +1,69 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+
+ +
+ 您可以使用root身份执行以下命令生成ssh密钥

+ +
+
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/kodexplorer.html b/app/intapp/controller/soft/tpl/soft/kodexplorer.html new file mode 100644 index 0000000..6f38ff4 --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/kodexplorer.html @@ -0,0 +1,88 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + 添加 + +
+
+
+ + + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/mongodb.html b/app/intapp/controller/soft/tpl/soft/mongodb.html new file mode 100644 index 0000000..ebdbc92 --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/mongodb.html @@ -0,0 +1,436 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +

可以在终端中执行以下命令创建可以 +

+ WORK_DIR=/data/mongodb
+ mkdir -p $WORK_DIR/key/
+ cd $WORK_DIR/key/
+ openssl rand -base64 756 > mongo.key
+ chmod 600 mongo.key
+
+

+ 保存 +
+
+ +
+ config服务 (注:这是一个config服务) + + + + + + +
+ 通常生产环境每台机器应该只有一个,您可以在其他机器上开启config服务后手动添加到副本集中
+ +
+ 运行中 + 停止服务 + 重启服务 +
+
+ 已停止 + 启动服务 +
+
+ 待初始化 + 初始化 +
+

+
+ 副本集初始化(如果需要,生产环境应该是内网ip而不是127.0.0.1)
+
+ +
+增加副本集示例 +
+mongo --port {{data.configs.server[0]['port']}}
+use admin
+rs.add({_id:1,host:'{{data.get_local_ip}}:27002',priority:2})#增加主机 priority:优先级
+
+删除副本集示例 +
+mongo --port {{data.configs.server[0]['port']}}
+use admin
+rs.remove('{{data.get_local_ip}}:27002')
+
+
+ +
+
+ +
+ configdb: +
示例:configdb = configs/192.168.1.101:27001,192.168.1.102:27001,192.168.1.103:27001,则无法扩展外部服务器
+ 上述ip和端口是已经启动的配置服务,可以是其他机器上的mongodb配置服务 +
+ 路由服务 (注:这是一个路由服务) + + + + + + +
+ +
+
+ 运行中 + 停止服务 + 重启服务 +
+
+ 已停止 + 启动服务 +
+
+ 待初始化 + 初始化 +
+
+
+ 初始化用户
+
+ +
+ 在路由中添加分片,如下示例
+
+mongo --port {{data.mongos.server[0]['port']}}
+use admin
+db.auth('admin','admin')
+sh.addShard("shard1/192.168.1.101:29001,192.168.1.102:29001") #shard1是分片集群id
+sh.status()
+
+
+
+
+ +
+
+ 分片服务名{{indexs+1}}: + + + + + + + +
+ 通常生产环境每台机器应该只有一个,您可以在其他机器上开启分片服务后手动添加到副本集中
+ +
+ 运行中 + 停止服务 + 重启服务 +
+
+ 已停止 + 启动服务 +
+
+ 待初始化 + 初始化 +
+

+
+ 副本集初始化(生产环境应该是内网ip而不是127.0.0.1)
+ +
+
+ +
+
+
+ + + +
+ + + + + + + + + + + + + +
绑定ip端口服务目录
+ + 运行中 + 停止 + + + 已停止 + 启动 + + +
+
+ + 保存 +
+ +
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/mysql.html b/app/intapp/controller/soft/tpl/soft/mysql.html new file mode 100644 index 0000000..e31a335 --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/mysql.html @@ -0,0 +1,257 @@ + + + + + + + kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ + + + 8.0版本不支持可视化修改 + + + + 建议与mysql安装目录分开 + + + + port 监听器端口 + + + + max_connections 最大连接数 + + +
+ max_allowed_packet 最大接受数据的包大小 +
+ +
+ expire_logs_days 日志保留时间(天) +
+ +
+ query_cache_limit 指定单个查询可以使用的缓冲区的大小 +
+ +
+ query_cache_size 查询的缓存大小设置 +
+ +
+ query_cache_type 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 +
+ +
+ wait_timeout 超时等待时间,单位秒,即一个connection在若干秒内无响应 +
+ +
+ thread_cache_size 用于缓存空闲的线程 +
+ +
+ key_buffer_size 用于指定索引缓冲区的大小 +
+
+
+ 保存 + 加入开机启动 +
+ +
+ +
+                        
+                    
+
+ 保存 +
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/nginx.html b/app/intapp/controller/soft/tpl/soft/nginx.html new file mode 100644 index 0000000..1417261 --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/nginx.html @@ -0,0 +1,171 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+                    
+                
+
+ 保存 + 加入开机启动 + 该配置文件只对该网站有效,修改后重启nginx生效 +
+
+ +
+ +
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/php.html b/app/intapp/controller/soft/tpl/soft/php.html new file mode 100644 index 0000000..8085943 --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/php.html @@ -0,0 +1,415 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + MB + + + 单个请求上传的文件的最大数量 + + + 秒 + + + 秒 + + + MB + + + MB + + + + + + 是否允许将url(如http://或 ftp://)作为文件处理。 + + + + + + 是否允许include/require以文件形式打开url(如http://或 ftp://)。 + + + + 基于套接字的流的默认超时(秒) + + + 保存 +
+
+ +
+ + + + + + + + + + 允许创建的最大子进程数 + + + + 起始进程数(服务启动后初始进程数量) + + + + 最小空闲进程数(清理空闲进程后的保留数量) + + + + 最大空闲进程数(当空闲进程达到此值时清理) + + + 保存 + 加入开机启动 +
+
+ +
+ % if config.app['appmode']=='develop': + + % endif + + + + + + + + +
名称说明状态操作
{{item.title}}{{item.describes}} + % if config.app['appmode']=='develop': + {{item.filename}} + % endif + + + + + + 安装 + + + 等待下载 + + + 正在下载 + + + 正在安装 + + + 卸载 + + + 正在卸载... + + % if config.app['appmode']=='develop': + 删除 + % endif +
+
+
+ + + + +
+                
+            
+ 保存 + 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
+
+ + + +
+                
+            
+ 保存 + 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
+
+
+ + + + + + + + + + + + + + + + + + + 添加 + +
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/phpmyadmin.html b/app/intapp/controller/soft/tpl/soft/phpmyadmin.html new file mode 100644 index 0000000..053916a --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/phpmyadmin.html @@ -0,0 +1,90 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + 添加 + +
+
+
+ + + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/redis.html b/app/intapp/controller/soft/tpl/soft/redis.html new file mode 100644 index 0000000..4df6dbd --- /dev/null +++ b/app/intapp/controller/soft/tpl/soft/redis.html @@ -0,0 +1,182 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + 绑定IP + + + 端口 + + + 空闲连接超时时间,0表示不断开 + + + 最大连接数 + + + 数据库数量 + + + redis密码,留空代表没有设置密码 + + + MB,最大使用内存,0表示不限制 + + + 保存 + 加入开机启动 +
+
+ + + + +
+                
+            
+ 保存 + 修改后重启redis生效
+
+
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/index/home.html b/app/intapp/controller/soft/tplm/index/home.html new file mode 100644 index 0000000..361a9fb --- /dev/null +++ b/app/intapp/controller/soft/tplm/index/home.html @@ -0,0 +1,297 @@ + + + + +kcweb云管 + + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+ +
+
+ +
+ + +
+
+
+
+
{{item.title}}{{item.edition}}
+
{{item.describes}}
+
+
+
位置:{{item.paths}}{{item.title}}{{item.edition}}
+
+ +
+
+
+ 待安装 + 等待中 + 下载中 + 安装中 + 卸载中 + 正在启动 + 正在停止服务 + + + + 已停止 + 启动 + + + + 客户端 + 客户端 + 服务端 + 服务端 + + + + + + + 运行中 + 停止 + 重启 + + + +
+
+
更新于:{{time_date(item.updtime)}}
+
+
+
+
+ +
+
+ 加载中... +
+
+ 下一页 + 我已到底了 +
+
+
+
+ + + diff --git a/app/intapp/controller/soft/tplm/index/web.html b/app/intapp/controller/soft/tplm/index/web.html new file mode 100644 index 0000000..a38c9cf --- /dev/null +++ b/app/intapp/controller/soft/tplm/index/web.html @@ -0,0 +1,395 @@ + + + + +kcweb云管 + + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+ +
+
+ +
+ + +
+
+
+
+
{{item.title}}
+
运行在负载均衡代理转发器中
+
{{item.describes}}
+ php伪静态配置 +
+
+ + 运行中 + + + 已停止 + +
+
+
+
+ {{item1}} +
+
+
{{time_date(item.updtime)}}
+
+
+
+
+ +
+
+ 加载中... +
+
+ 下一页 + 暂无数据 + 我已到底了 +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+ 添加响应 + 自定义配置:自定义响应或自定义错误页面 +
+ +
+ +
+
+ +
+
+ + +
+
+ +
+
+ 添加负载均衡信息 + nginx负载均衡是一个代理均衡转发器 +
+
+ 修改 + 添加 +
+
+
+
+ +
+ Let's Encrypt证书夹 +
+
+ 您已配置Let's证书
+ ssl_certificate :{{admin.ssl_certificate}}
+ ssl_certificate_key :{{admin.ssl_certificate_key}}
+
+
+ + 保存 + + + + + +
fewaf
+
+ +
+ +
+
+
+ + + diff --git a/app/intapp/controller/soft/tplm/soft/frp.html b/app/intapp/controller/soft/tplm/soft/frp.html new file mode 100644 index 0000000..c137b73 --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/frp.html @@ -0,0 +1,250 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+ + + + + 重启 + 停止 + + 保存 + + + + + + +
+ 重启 + 停止 + + + + 这是服端监听的地址 + + + + 这是服端监听的端口 + + + + 这是upd监听的端口 + + + + 这是kcp监听的端口 + + + + 这是http监听的端口 + + + + 这是https监听的端口 + + + + 这是dashboard监听的ip地址 + + + + 这是dashboard监听的端口 + + + + 这是dashboard监听的用户名 + + + + 这是dashboard监听的密码 + + + + 这是frp的验证机制 + + + + 这是frp的验证串的有效时间 + + + + + + + + 日志保持多少天 + + + + + + + + 白名单端口 + + + + 最大值进程数 + + + + + + + + + + + + + + + 保存 + + +
+ +
+ + + 保存 + +
+
+
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/git.html b/app/intapp/controller/soft/tplm/soft/git.html new file mode 100644 index 0000000..ce87f2d --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/git.html @@ -0,0 +1,69 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+
+ +
+ 您可以使用root身份执行以下命令生成ssh密钥

+ +
+
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/kodexplorer.html b/app/intapp/controller/soft/tplm/soft/kodexplorer.html new file mode 100644 index 0000000..6f38ff4 --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/kodexplorer.html @@ -0,0 +1,88 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + 添加 + +
+
+
+ + + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/mongodb.html b/app/intapp/controller/soft/tplm/soft/mongodb.html new file mode 100644 index 0000000..417da13 --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/mongodb.html @@ -0,0 +1,436 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +

可以在终端中执行以下命令创建可以 +

+ WORK_DIR=/data/mongodb
+ mkdir -p $WORK_DIR/key/
+ cd $WORK_DIR/key/
+ openssl rand -base64 756 > mongo.key
+ chmod 600 mongo.key
+
+

+ 保存 +
+
+ +
+ config服务 (注:这是一个config服务) + + + + + + +
+ 通常生产环境每台机器应该只有一个,您可以在其他机器上开启config服务后手动添加到副本集中
+ +
+ 运行中 + 停止服务 + 重启服务 +
+
+ 已停止 + 启动服务 +
+
+ 待初始化 + 初始化 +
+

+
+ 副本集初始化(如果需要,生产环境应该是内网ip而不是127.0.0.1)
+
+ +
+增加副本集示例 +
+mongo --port {{data.configs.server[0]['port']}}
+use admin
+rs.add({_id:1,host:'{{data.get_local_ip}}:27002',priority:2})#增加主机 priority:优先级
+
+删除副本集示例 +
+mongo --port {{data.configs.server[0]['port']}}
+use admin
+rs.remove('{{data.get_local_ip}}:27002')
+
+
+ +
+
+ +
+ configdb: +
示例:configdb = configs/192.168.1.101:27001,192.168.1.102:27001,192.168.1.103:27001,则无法扩展外部服务器
+ 上述ip和端口是已经启动的配置服务,可以是其他机器上的mongodb配置服务 +
+ 路由服务 (注:这是一个路由服务) + + + + + + +
+ +
+
+ 运行中 + 停止服务 + 重启服务 +
+
+ 已停止 + 启动服务 +
+
+ 待初始化 + 初始化 +
+
+
+ 初始化用户
+
+ +
+ 在路由中添加分片,如下示例
+
+mongo --port {{data.mongos.server[0]['port']}}
+use admin
+db.auth('admin','admin')
+sh.addShard("shard1/192.168.1.101:29001,192.168.1.102:29001") #shard1是分片集群id
+sh.status()
+
+
+
+
+ +
+
+ 分片服务名{{indexs+1}}: + + + + + + + +
+ 通常生产环境每台机器应该只有一个,您可以在其他机器上开启分片服务后手动添加到副本集中
+ +
+ 运行中 + 停止服务 + 重启服务 +
+
+ 已停止 + 启动服务 +
+
+ 待初始化 + 初始化 +
+

+
+ 副本集初始化(生产环境应该是内网ip而不是127.0.0.1)
+ +
+
+ +
+
+
+ + + +
+ + + + + + + + + + + + + +
绑定ip端口服务目录
+ + 运行中 + 停止 + + + 已停止 + 启动 + + +
+
+ + 保存 +
+ +
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/mysql.html b/app/intapp/controller/soft/tplm/soft/mysql.html new file mode 100644 index 0000000..3603e82 --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/mysql.html @@ -0,0 +1,203 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ + + + + + + 建议与mysql安装目录分开 + + + + port 监听器端口 + + + + max_connections 最大连接数 + + +
+ max_allowed_packet 最大接受数据的包大小 +
+ +
+ expire_logs_days 日志保留时间(天) +
+ +
+ query_cache_limit 指定单个查询可以使用的缓冲区的大小 +
+ +
+ query_cache_size 查询的缓存大小设置 +
+ +
+ query_cache_type 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 +
+ +
+ wait_timeout 超时等待时间,单位秒,即一个connection在若干秒内无响应 +
+ +
+ thread_cache_size 用于缓存空闲的线程 +
+ +
+ key_buffer_size 用于指定索引缓冲区的大小 +
+
+
+ 保存 + 加入开机启动 +
+ +
+ +
+                        
+                    
+
+ 保存 +
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/nginx.html b/app/intapp/controller/soft/tplm/soft/nginx.html new file mode 100644 index 0000000..1417261 --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/nginx.html @@ -0,0 +1,171 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + +
+                    
+                
+
+ 保存 + 加入开机启动 + 该配置文件只对该网站有效,修改后重启nginx生效 +
+
+ +
+ +
+
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/php.html b/app/intapp/controller/soft/tplm/soft/php.html new file mode 100644 index 0000000..8085943 --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/php.html @@ -0,0 +1,415 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + MB + + + 单个请求上传的文件的最大数量 + + + 秒 + + + 秒 + + + MB + + + MB + + + + + + 是否允许将url(如http://或 ftp://)作为文件处理。 + + + + + + 是否允许include/require以文件形式打开url(如http://或 ftp://)。 + + + + 基于套接字的流的默认超时(秒) + + + 保存 +
+
+ +
+ + + + + + + + + + 允许创建的最大子进程数 + + + + 起始进程数(服务启动后初始进程数量) + + + + 最小空闲进程数(清理空闲进程后的保留数量) + + + + 最大空闲进程数(当空闲进程达到此值时清理) + + + 保存 + 加入开机启动 +
+
+ +
+ % if config.app['appmode']=='develop': + + % endif + + + + + + + + +
名称说明状态操作
{{item.title}}{{item.describes}} + % if config.app['appmode']=='develop': + {{item.filename}} + % endif + + + + + + 安装 + + + 等待下载 + + + 正在下载 + + + 正在安装 + + + 卸载 + + + 正在卸载... + + % if config.app['appmode']=='develop': + 删除 + % endif +
+
+
+ + + + +
+                
+            
+ 保存 + 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
+
+ + + +
+                
+            
+ 保存 + 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
+
+
+ + + + + + + + + + + + + + + + + + + 添加 + +
+ + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/phpmyadmin.html b/app/intapp/controller/soft/tplm/soft/phpmyadmin.html new file mode 100644 index 0000000..053916a --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/phpmyadmin.html @@ -0,0 +1,90 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + 添加 + +
+
+
+ + + + \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/redis.html b/app/intapp/controller/soft/tplm/soft/redis.html new file mode 100644 index 0000000..4df6dbd --- /dev/null +++ b/app/intapp/controller/soft/tplm/soft/redis.html @@ -0,0 +1,182 @@ + + + + + +kcwebplus + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + 绑定IP + + + 端口 + + + 空闲连接超时时间,0表示不断开 + + + 最大连接数 + + + 数据库数量 + + + redis密码,留空代表没有设置密码 + + + MB,最大使用内存,0表示不限制 + + + 保存 + 加入开机启动 +
+
+ + + + +
+                
+            
+ 保存 + 修改后重启redis生效
+
+
+
+ + + \ No newline at end of file -- Gitee From 028f4aed0188e3a4ef05941ae1f302bf4f6e1048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Sat, 22 May 2021 01:01:46 +0800 Subject: [PATCH 11/19] k --- app/intapp/controller/__init__.py | 3 +- app/intapp/controller/soft/__init__.py | 8 - app/intapp/controller/soft/common/SOFT.py | 248 -------- app/intapp/controller/soft/common/__init__.py | 2 - app/intapp/controller/soft/common/autoload.py | 10 - .../soft/common/file/sqlite/.gitignore | 1 - .../soft/common/file/sqlite/php_exten | Bin 24576 -> 0 bytes app/intapp/controller/soft/common/file/time | 1 - app/intapp/controller/soft/common/model.py | 85 --- app/intapp/controller/soft/frp.py | 138 ----- app/intapp/controller/soft/index.py | 131 ---- app/intapp/controller/soft/install.txt | 1 - app/intapp/controller/soft/mongodb.py | 253 -------- app/intapp/controller/soft/mysql copy.py | 310 ---------- app/intapp/controller/soft/mysql.py | 338 ---------- app/intapp/controller/soft/nginx.py | 419 ------------- app/intapp/controller/soft/page.py | 34 - app/intapp/controller/soft/php.py | 272 -------- app/intapp/controller/soft/redis.py | 71 --- app/intapp/controller/soft/role.txt | 44 -- .../controller/soft/tpl/index/home.html | 430 ------------- app/intapp/controller/soft/tpl/index/web.html | 582 ------------------ app/intapp/controller/soft/tpl/soft/frp.html | 250 -------- app/intapp/controller/soft/tpl/soft/git.html | 69 --- .../controller/soft/tpl/soft/kodexplorer.html | 88 --- .../controller/soft/tpl/soft/mongodb.html | 436 ------------- .../controller/soft/tpl/soft/mysql.html | 257 -------- .../controller/soft/tpl/soft/nginx.html | 171 ----- app/intapp/controller/soft/tpl/soft/php.html | 415 ------------- .../controller/soft/tpl/soft/phpmyadmin.html | 90 --- .../controller/soft/tpl/soft/redis.html | 182 ------ .../controller/soft/tplm/index/home.html | 297 --------- .../controller/soft/tplm/index/web.html | 395 ------------ app/intapp/controller/soft/tplm/soft/frp.html | 250 -------- app/intapp/controller/soft/tplm/soft/git.html | 69 --- .../soft/tplm/soft/kodexplorer.html | 88 --- .../controller/soft/tplm/soft/mongodb.html | 436 ------------- .../controller/soft/tplm/soft/mysql.html | 203 ------ .../controller/soft/tplm/soft/nginx.html | 171 ----- app/intapp/controller/soft/tplm/soft/php.html | 415 ------------- .../controller/soft/tplm/soft/phpmyadmin.html | 90 --- .../controller/soft/tplm/soft/redis.html | 182 ------ 42 files changed, 1 insertion(+), 7934 deletions(-) delete mode 100644 app/intapp/controller/soft/__init__.py delete mode 100644 app/intapp/controller/soft/common/SOFT.py delete mode 100644 app/intapp/controller/soft/common/__init__.py delete mode 100644 app/intapp/controller/soft/common/autoload.py delete mode 100644 app/intapp/controller/soft/common/file/sqlite/.gitignore delete mode 100644 app/intapp/controller/soft/common/file/sqlite/php_exten delete mode 100644 app/intapp/controller/soft/common/file/time delete mode 100644 app/intapp/controller/soft/common/model.py delete mode 100644 app/intapp/controller/soft/frp.py delete mode 100644 app/intapp/controller/soft/index.py delete mode 100644 app/intapp/controller/soft/install.txt delete mode 100644 app/intapp/controller/soft/mongodb.py delete mode 100644 app/intapp/controller/soft/mysql copy.py delete mode 100644 app/intapp/controller/soft/mysql.py delete mode 100644 app/intapp/controller/soft/nginx.py delete mode 100644 app/intapp/controller/soft/page.py delete mode 100644 app/intapp/controller/soft/php.py delete mode 100644 app/intapp/controller/soft/redis.py delete mode 100644 app/intapp/controller/soft/role.txt delete mode 100644 app/intapp/controller/soft/tpl/index/home.html delete mode 100644 app/intapp/controller/soft/tpl/index/web.html delete mode 100644 app/intapp/controller/soft/tpl/soft/frp.html delete mode 100644 app/intapp/controller/soft/tpl/soft/git.html delete mode 100644 app/intapp/controller/soft/tpl/soft/kodexplorer.html delete mode 100644 app/intapp/controller/soft/tpl/soft/mongodb.html delete mode 100644 app/intapp/controller/soft/tpl/soft/mysql.html delete mode 100644 app/intapp/controller/soft/tpl/soft/nginx.html delete mode 100644 app/intapp/controller/soft/tpl/soft/php.html delete mode 100644 app/intapp/controller/soft/tpl/soft/phpmyadmin.html delete mode 100644 app/intapp/controller/soft/tpl/soft/redis.html delete mode 100644 app/intapp/controller/soft/tplm/index/home.html delete mode 100644 app/intapp/controller/soft/tplm/index/web.html delete mode 100644 app/intapp/controller/soft/tplm/soft/frp.html delete mode 100644 app/intapp/controller/soft/tplm/soft/git.html delete mode 100644 app/intapp/controller/soft/tplm/soft/kodexplorer.html delete mode 100644 app/intapp/controller/soft/tplm/soft/mongodb.html delete mode 100644 app/intapp/controller/soft/tplm/soft/mysql.html delete mode 100644 app/intapp/controller/soft/tplm/soft/nginx.html delete mode 100644 app/intapp/controller/soft/tplm/soft/php.html delete mode 100644 app/intapp/controller/soft/tplm/soft/phpmyadmin.html delete mode 100644 app/intapp/controller/soft/tplm/soft/redis.html diff --git a/app/intapp/controller/__init__.py b/app/intapp/controller/__init__.py index cace474..90b3d04 100644 --- a/app/intapp/controller/__init__.py +++ b/app/intapp/controller/__init__.py @@ -9,5 +9,4 @@ def error(e,data): header={"Content-Type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"*"} header['Location']="/intapp/index/plug/index/intapp/"+plug return '{"code":1,"msg":"您访问的地址不存在","data":"'+str(e)+'"}','302 Found',header -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/soft/__init__.py b/app/intapp/controller/soft/__init__.py deleted file mode 100644 index f7a8da3..0000000 --- a/app/intapp/controller/soft/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from . import index -from . import page -from . import nginx -from . import mysql -from . import redis -from . import mongodb -from . import frp -from . import php \ No newline at end of file diff --git a/app/intapp/controller/soft/common/SOFT.py b/app/intapp/controller/soft/common/SOFT.py deleted file mode 100644 index 54ad594..0000000 --- a/app/intapp/controller/soft/common/SOFT.py +++ /dev/null @@ -1,248 +0,0 @@ -# -*- coding: utf-8 -*- -from .model import * -class SOFT: - def softlist(kw,pagenow,pagesize): - "软件列表" - if config.app['appmode']=='develop': - where="1=1" - else: - where="platform='"+get_sysinfo()['uname'][0]+"'" - if kw: - where+=" and title LIKE '%"+kw+"%' or describes LIKE '%"+kw+"%'" - lists=sqlite("soft",model_intapp_soft_path).where(where).page(pagenow,pagesize).select() - if len(lists) < 1: - SOFT.updatesoftlist() - lists=sqlite("soft",model_intapp_soft_path).where(where).page(pagenow,pagesize).select() - if 'Linux' in get_sysinfo()['platform']: - i=0 - for k in lists: - if k['status'] == 0 and k['platform']=='Linux': #检查软件是否已经安装 - if (os.path.exists(k['paths']+k['title']+k['edition'])) : - lists[i]['status']=4 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':lists[i]['status']}) - if (k['status'] == 10 or k['status'] == 4) and k['platform']=='Linux': #检查软件是否在运行中 - if 'nginx' in k['title'] : - if not get_process_id('nginx'): - if k['status'] == 10: - lists[i]['status']=4 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 - else: - if k['status'] == 4: - lists[i]['status']=10 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 - elif 'redis' in k['title']: - if not get_process_id('redis'): - if k['status'] == 10: - lists[i]['status']=4 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 - else: - if k['status'] == 4: - lists[i]['status']=10 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 - elif 'mysql' in k['title']: - if not os.path.isfile(k['paths']+"/mysql"+k['edition']+"/tmp/mysqld.pid"): - if k['status'] == 10: - lists[i]['status']=4 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 - else: - if k['status'] == 4: - lists[i]['status']=10 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 - elif 'php5' in k['title']+k['edition'] or 'php7' in k['title']+k['edition']: - title=k['title']+k['edition'] - # print("php",title,title.replace(".", "")+"-fpm") - if not get_process_id(title): - if k['status'] == 10: - lists[i]['status']=4 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 - else: - if k['status'] == 4: - lists[i]['status']=10 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 - elif 'tomcat' in k['title']: - if not get_process_id('tomcat'): - if k['status'] == 10: - lists[i]['status']=4 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':4}) #停止 - else: - if k['status'] == 4: - lists[i]['status']=10 - sqlite("soft",model_intapp_soft_path).where('id',k['id']).update({'status':10}) #运行中 - i+=1 - count=sqlite("soft",model_intapp_soft_path).where(where).count() - data=return_list(lists,count,pagenow,pagesize) - return data - def updatesoftlist(): - "更新软件列表" - http=Http() - sqlite("soft",model_intapp_soft_path).where("1=1").delete() - def openkcweb(pagenow=1,pagesize=20): - http.openurl(config.domain['kcwebapi']+"/pub/soft_list","GET",params={ - "pagenow":pagenow,"pagesize":pagesize - }) - res=json_decode(http.get_text) - lists=[] - if res['code']==0: - for k in res['data']['lists']: - k['status']=0 - k['msg']='' - k['addtime']=times() - lists.append(k) - sqlite("soft",model_intapp_soft_path).insert(lists) - if pagenow "+arr['paths']+arr['title']+arr['edition']+"/out.log 2>&1 &",name="redis服务",icon=arr['icon']) - return True - elif 'mysql' in arr['title']: - if os.path.isfile(arr['paths']+arr['title']+arr['edition']+"/support-files/mysql.server"): - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":"安装成功"}) - system_start.insert_Boot_up("mysqld"+(arr['edition'].replace(".", ""))+"server start",name="mysqld"+(arr['edition'].replace(".", ""))+"服务",icon=arr['icon']) #edition - return True - elif 'frp' == arr['title']: - if os.path.isfile(arr['paths']+arr['title']+arr['edition']+"/frps") and os.path.isfile(arr['paths']+arr['title']+arr['edition']+"/frpc"): - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":"安装成功"}) - return True - else: - if os.path.exists(arr['paths']+arr['title']+arr['edition']): - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":"安装成功"}) - if 'tomcat' == arr['title']: - jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() - system_start.insert_Boot_up(cmd="export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition']+" && /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin/startup.sh start",name="tomcat服务",icon=arr['icon']) - return True - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"安装失败,目录不存在"+arr['paths']+arr['title']+arr['edition']}) - else: - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"安装失败"}) - else: - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"下载失败"}) - except Exception as e: - sqlite('soft',model_intapp_soft_path).where('id',id).update({'status':0,'msg':'安装失败'+str(e)}) - def start(id): - "启动软件服务" - arr=sqlite("soft",model_intapp_soft_path).where("id",id).find() - if arr['platform']=='Linux': ###############################LINUX - if 'nginx' == arr['title']: - os.system("nginx") - elif 'php' == arr['title']: - titleedition=arr['title']+arr['edition'] - fpmname=titleedition.replace(".", "")+"-fpm" - os.system(fpmname+" -c "+arr['paths']+arr['title']+arr['edition']+"/bin/php.ini -R") - # print("php启动",fpmname+" -c "+arr['paths']+arr['title']+arr['edition']+"/bin/php.ini -R") - elif 'redis' == arr['title']: - # os.system("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > log 2>&1 &") - os.system("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > "+arr['paths']+arr['title']+arr['edition']+"/out.log 2>&1 &") - elif 'mysql' == arr['title']: - if '5.6' == arr['edition']: - os.system("mysqld56server start") - elif '5.7' == arr['edition']: - os.system("mysqld57server start") - elif '8.0' == arr['edition']: - os.system("mysqld80server start") - elif 'tomcat' == arr['title']: - jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() - os.system("export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition'] +" && /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin/startup.sh start") - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":9,"msg":"","updtime":times()}) - time.sleep(10) - else: - os.system("cd "+arr['paths']+arr['title']+arr['edition']+" && bash start.sh") - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":10,"msg":"运行中"}) - else: - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":""}) - def stop(id): - arr=sqlite("soft",model_intapp_soft_path).where("id",id).find() - if arr['platform']=='Linux': ###############################LINUX - if 'nginx' == arr['title']: - os.system("pkill nginx") - elif 'php' == arr['title']: - titleedition=arr['title']+arr['edition'] - fpmname=titleedition.replace(".", "")+"-fpm" - os.system("pkill -9 "+fpmname) - elif 'redis' == arr['title']: - os.system("pkill -9 redis") - elif 'mysql' == arr['title']: - if '5.6' == arr['edition']: - os.system("mysqld56server stop") - elif '5.7' == arr['edition']: - os.system("mysqld57server stop") - elif '8.0' == arr['edition']: - os.system("mysqld80server stop") - elif 'tomcat' == arr['title']: - jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() - os.system("export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition'] +" && cd /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin && ./shutdown.sh") - # os.system("pkill -9 tomcat") - time.sleep(1) - elif 'mongo' == arr['title']: - os.system("pkill mongo") - else: - os.system("cd "+arr['paths']+arr['title']+arr['edition']+" && bash stop.sh") - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":4,"msg":""}) - def uninstall(id): - try: - arr=sqlite("soft",model_intapp_soft_path).where("id",id).find() - if arr['platform']=='Linux': ###############################LINUX - os.system("rm -rf "+arr['paths']+arr['title']+arr['edition']) - startpath="/usr/bin/" - if 'nginx' == arr['title']: - system_start.del_Boot_up("nginx") - os.system("pkill -9 nginx") - model_intapp_menu.delete(title="网站管理",sort=9000) - os.system("rm -rf "+startpath+"nginx") - elif 'redis' == arr['title']: - system_start.del_Boot_up("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > "+arr['paths']+arr['title']+arr['edition']+"/out.log 2>&1 &") - os.system("rm -rf "+startpath+"redis-server") - elif 'php' == arr['title']: - titleedition=arr['title']+arr['edition'] - fpmname=titleedition.replace(".", "")+"-fpm" - system_start.del_Boot_up(fpmname+" -c "+arr['paths']+arr['title']+arr['edition']+"/bin/php.ini -R") - os.system("rm -rf "+startpath+fpmname) - elif 'mysql' == arr['title']: - system_start.del_Boot_up("mysqld"+(arr['edition'].replace(".", ""))+"server start") - os.system("rm -rf "+startpath+"mysqld"+(arr['edition'].replace(".", ""))+" && rm -rf "+startpath+"mysql"+(arr['edition'].replace(".", ""))) - elif 'mongodb' == arr['title']: - system_start.del_Boot_up("mongo",True) - os.system("pkill -9 mongo") - os.system("rm -rf /data/mongodb") - elif 'frp' == arr['title']: - system_start.del_Boot_up("frps",True) - system_start.del_Boot_up("frpc",True) - os.system("pkill -9 frps") - os.system("pkill -9 frpc") - else: - if 'tomcat' == arr['title']: - jdk=sqlite("soft",model_intapp_soft_path).where("title","jdk").find() - system_start.del_Boot_up("export JAVA_HOME=/usr/local/jdk/"+jdk['title']+jdk['edition']+" && /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin/startup.sh start") - os.system("cd /usr/local/"+arr['title']+"/"+arr['title']+arr['edition']+"/bin && ./shutdown.sh") - if os.path.exists(arr['paths']+arr['title']+arr['edition']): - sqlite('soft',model_intapp_soft_path).where('id',id).update({'status':4,'msg':'卸载失败'}) - return - except Exception as e: - sqlite('soft',model_intapp_soft_path).where('id',id).update({'status':4,'msg':'卸载失败'+str(e)}) - else: - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":0,"msg":"已卸载"}) \ No newline at end of file diff --git a/app/intapp/controller/soft/common/__init__.py b/app/intapp/controller/soft/common/__init__.py deleted file mode 100644 index 8879824..0000000 --- a/app/intapp/controller/soft/common/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# -*- coding: utf-8 -*- -from .SOFT import * \ No newline at end of file diff --git a/app/intapp/controller/soft/common/autoload.py b/app/intapp/controller/soft/common/autoload.py deleted file mode 100644 index c4bee80..0000000 --- a/app/intapp/controller/soft/common/autoload.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -from app.intapp.common import * -import subprocess -def get_process_id(name): - try: - child = subprocess.Popen(['pgrep', '-f', name],stdout=subprocess.PIPE, shell=False) - response = child.communicate()[0] - return [int(pid) for pid in response.split()] - except: - return [] diff --git a/app/intapp/controller/soft/common/file/sqlite/.gitignore b/app/intapp/controller/soft/common/file/sqlite/.gitignore deleted file mode 100644 index f3c316e..0000000 --- a/app/intapp/controller/soft/common/file/sqlite/.gitignore +++ /dev/null @@ -1 +0,0 @@ -soft \ No newline at end of file diff --git a/app/intapp/controller/soft/common/file/sqlite/php_exten b/app/intapp/controller/soft/common/file/sqlite/php_exten deleted file mode 100644 index 947090a468579685c0d9058dbd71817876cd9b6e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 24576 zcmeHPeQZ-)pm~U>pVC01x>inNzdYabyT5zhJ@?#m-fMcH-V<~RE?--VEhv~}b7XS4>={9j$z;tSDiHdT z!<#(%0si9W?|U`NDjxZx4$e~O*UI$W@Qb||1B?O20AqkLz!+c*Fa{U{i~+^~W8jC! zz!rt7c-b=fwxDgh*BN-#3z6i@0q3jj&Q^Q+N9FoPOHH#yXs%gTZxPbYUD9f6ahAh3 zm+ozq7ZjJ3$@eddx9NBLUv};aI$Kk36nC_fIxH;lIE1=}X3GXkqtLLqS!mc=UoUKF ztlL!6xJ`K8vQ4Pj+Pt~00lvM-($HKk_$N5OTnKuCUZ?P4P2>8FHH}M*rmCevt>xL8 zt@X{q;>D?U%LRusU~ltmcLq}DnpUow1a_p(GFF;a zOrpx>a0ETjU^)@yLc4$B|18Z1t5X=hM%z;v{%iPJ*RN~fJNW{wTXS7gqJCFh$Q|Go z6ntDztNLsHKk{qy_A0+p`IRdbgNkMH({i)y53+3&8m>#w%H$6(nsK;&tP93(kTq>h&g0{b*xE4rz<_h|AsSKI}9iO2PT`4Fk z?%;?TyVmA(cmm?t!O_7k@xXrZ(#g@mUyI$BBb{V)V87Ve6Fs%>d1uFyFWS8A&d7kBH!3Cjj)Mud0ZSN#@bdxBqeRZ_Mm&L?KA+bq4)2XzI{(EUA`V=Q zz1InEZhmw!vgbnVwNNzlMs(=R%{`|^!|#d1CnCqY1XG2nqB45;P~^ z#7l3*j_i%TOJMNCy%)tped7Krqk|tMhqM1uo{do|wuE0VP!e zm{Jr{T?}NFk`0MVSdG)7r`6@V8&a(6_hNTXr03x1&{ZI3Q{5&Dm{x>b2Dq`;&%?zK z{nf<;nPOizTqnj2@E4K*P$!1@M(Ax>AD~ux_YlmHbaKv z0Iad07z$Aq!GITfIHE;c-Qh?fOK1XoVBO-mebHkF#M2{U=zTQ2_#6!rNOrcj!vP4c zqkxa#aGG{M3Sf$0x;7vfdwbhBQ90;1wg)4!0>%BXRFiX;$CcLctZV?=gMJO7xE=yc z)YYkT>gp;Ju5RcP(DRAE5cE)2r>1Txm%XBGg0^!gt~t`4<S5~YVcX9*78XF+Qph4PNlE|m#{%@?Y{%>6Qpo#h%E{8q`6~)7={x3n#m;OA^ zLwycM{X^P_WHtV@P0)4&#if+?EQdZPK42JL^?!=ep#VK}X5}9I%nIs3?G+Tl$w4=D zcignQyOppS%YO=f<;}y~yxj1W41U;)F~AsL3@`>51B?O20AqkLz!+c*Fa{U{jDa5u z13I~~Ob(mkiMopCbSk%OZho!I(60Yh|E6BZS^i(;&byV`pkn#|Oe-5${vWFfq?ve@ z|DXCk|LTgn^8YHgyb1O_S^j^j)kl!HOjanc{Qte{v?_%=^8alt|9{`5ZY=+wajDxR zvn0#^LqR0kU8YrTEdP%sgHYr)i9xaa|6N65S>=CO{y&r0faU+QE*xk1{{Y5S;0h9@ z2*;ol;h0YG7g?#yD$`V{FKD~DTb#e(?*%WYZmM>w42B;4XZi-+W!(b)x7z<`=jQLp zyPbD5uSEG9Wu2l(-Yxs5%&NF?uZzXCV_qaTIv%K-{4H`dNjxiP}|0EOMPHKqH}*sd+xwPkm0{jl!Z zf_3X-6VJRI6)+{!%3$q-uMAGO13S#W_UXGlic~FzHC_ox-rb>@t#^0e?Y^m77(-3g zSg6Up2*!sl>NL4s)ESeDx=<}>f}16uKvPI2OEgo9U$R&t8OOtykP!eG$^3=V@I^Dz z;fs-mFQGDkS4NaS1-@wbqM63<#TXA?LOMX9Bh`;f!xs$=4$_vcvnG5oO2U`n?;xx6 zo%<(J3(svZVN3=S!(*Un4D0{r6li1yi~djgr*(b0jr?_fuC_}vrm?F3tzN_R7W}JV z7o5Oei~+^~V}LQh82C{#;C&94dhlcde4dEb=XbUS0$$iG|Ne*8U~)BizO-;D?J#`A zh5oJ5A(W0f)RugDiEcV#40tHQwO^u;s*Tc>zi#%f{8x;x{I5ZHbj?n<4L}>+xYNzR z#vQV_8HH3mD`k{Gw_%t5HkrR(8b9$f9Y2|A{1lD?yeLtw1HNed#7|@VWKN`iU>iRCIjOFZ z#!vigkDttv_$dtcc85RpKLa$<)CEt|3~BLS7I8UPdGbMHpe=;rss@cTDZ}S9bphSO z)J6DrD1`etD55hUKLazM8DPAPLin`+g{Cg}8A@FsoI@xbKLa$>qw>??QBn0y6jJrH Y)EB_w;ekF6EDOUmjr)RdBS3HbKNvJ$VgLXD diff --git a/app/intapp/controller/soft/common/file/time b/app/intapp/controller/soft/common/file/time deleted file mode 100644 index 818b173..0000000 --- a/app/intapp/controller/soft/common/file/time +++ /dev/null @@ -1 +0,0 @@ -1599551060 \ No newline at end of file diff --git a/app/intapp/controller/soft/common/model.py b/app/intapp/controller/soft/common/model.py deleted file mode 100644 index 87d168d..0000000 --- a/app/intapp/controller/soft/common/model.py +++ /dev/null @@ -1,85 +0,0 @@ -# -*- coding: utf-8 -*- -from .autoload import * -# 初始化数据库 -model_intapp_soft_path=os.path.split(os.path.realpath(__file__))[0]+"/file/sqlite/soft" -class modelsqlitesoft(model.model): - config={'type':'sqlite'} - config={'type':'sqlite','db':model_intapp_soft_path} - model.dbtype.conf=config -class model_intapp_soft(modelsqlitesoft): - "软件表" - table="soft" - fields={ - "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 - "icon":model.dbtype.varchar(LEN=128,DEFAULT=''), #图标 - "title":model.dbtype.varchar(LEN=128,DEFAULT=''), #软件名称 - "edition":model.dbtype.varchar(LEN=128,DEFAULT=''), #软件版本 - "shell":model.dbtype.varchar(LEN=128,DEFAULT=''), #shell 命令 - "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件描述 - "paths":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件安装目录 卸载软件时用到 - "status":model.dbtype.int(LEN=2,DEFAULT=0), #0未安装 1等待中 2下载中 3安装中 4已安装 5卸载中 9启动中... 10运行中 11正在停止服务... - "filename":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件源文件地址 - "platform":model.dbtype.varchar(LEN=256,DEFAULT='Linux'),#支持的系统 - 'msg':model.dbtype.varchar(LEN=1024,DEFAULT=''), #最后一次执行结果信息 - "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 - "updtime":model.dbtype.int(LEN=11,DEFAULT=0) #更新时间 - } -try: - sqlite('soft',model_intapp_soft_path).find() -except: - model_soft=model_intapp_soft() - model_soft.create_table() - -class model_intapp_web(modelsqlitesoft): - "网站列表" - table="web" - fields={ - "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 - "domain":model.dbtype.varchar(LEN=512,DEFAULT=''), #域名 - "port":model.dbtype.varchar(LEN=8,DEFAULT='80'), #端口 - "icon":model.dbtype.varchar(LEN=128,DEFAULT=''), #图标 - "title":model.dbtype.varchar(LEN=128,DEFAULT=''), #名称 - "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), #描述 - "status":model.dbtype.int(LEN=1,DEFAULT=1), #网站状态 0停止 1开启 - "path":model.dbtype.varchar(LEN=256,DEFAULT=''), #网站目录 - "client_max_body_size":model.dbtype.int(LEN=11,DEFAULT=20),#上传限制 - "webtpl":model.dbtype.varchar(LEN=256,DEFAULT=''), #nginx配置文件模板名 - "servers":model.dbtype.varchar(LEN=256,DEFAULT=''), #服务器名字 nginx名字 - "only":model.dbtype.varchar(LEN=32,DEFAULT=''), #唯一字段 - "balancing":model.dbtype.varchar(LEN=2048,DEFAULT=''), #负载均衡服务器信息 - "proxy_set_header":model.dbtype.varchar(LEN=1024,DEFAULT=''),#自定义转发请求头 - "header":model.dbtype.varchar(LEN=1024,DEFAULT=''),#自定义响应头 - "ssl_certificate":model.dbtype.varchar(LEN=1024,DEFAULT=''), - "ssl_certificate_key":model.dbtype.varchar(LEN=1024,DEFAULT=''), - "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 - "updtime":model.dbtype.int(LEN=11,DEFAULT=0) #更新时间 - } -try: - sqlite('web',model_intapp_soft_path).find() -except: - model_intapp_web=model_intapp_web() - model_intapp_web.create_table() - -model_intapp_soft_php_exten_path=os.path.split(os.path.realpath(__file__))[0]+"/file/sqlite/php_exten" -class model_intapp_php_exten(model.model): - "php扩展表" - config={'type':'sqlite'} - config={'type':'sqlite','db':model_intapp_soft_php_exten_path} - model.dbtype.conf=config - table="php_exten" - fields={ - "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 - "pid":model.dbtype.int(LEN=11), #软件列表id - "title":model.dbtype.varchar(LEN=128,DEFAULT=''), #扩展名称 - "describes":model.dbtype.varchar(LEN=256,DEFAULT=''), #扩展描述 - "status":model.dbtype.int(LEN=2,DEFAULT=0), #0未安装 1等待中 2下载中 3安装中 4已安装 5卸载中 - "filename":model.dbtype.varchar(LEN=256,DEFAULT=''), #软件源文件地址 - 'msg':model.dbtype.varchar(LEN=1024,DEFAULT=''), #最后一次执行结果信息 - "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 - "updtime":model.dbtype.int(LEN=11,DEFAULT=0) #更新时间 - } -try: - sqlite('php_exten',model_intapp_soft_php_exten_path).find() -except: - model_intapp_php_exten=model_intapp_php_exten() - model_intapp_php_exten.create_table() \ No newline at end of file diff --git a/app/intapp/controller/soft/frp.py b/app/intapp/controller/soft/frp.py deleted file mode 100644 index 087feb0..0000000 --- a/app/intapp/controller/soft/frp.py +++ /dev/null @@ -1,138 +0,0 @@ -from .common import * -dar="/usr/local/frp/frp0.30" -# pkill frps && cd /usr/local/frp/frp0.30 && ./frps -c frps_full.ini & -def get_server(): - server={ - 'conf':file_get_content(dar+"/frps_full.ini"), - 'base':json_decode(file_get_content(dar+"/frps_full.conf")), - 'dar':dar - } - return successjson(server) -def run_status(): - "获取运行状态" - data={"frpc":0,"frps":0} - if get_process_id('frps'): - data['frps']=1 - if get_process_id('frpc'): - data['frpc']=1 - return successjson(data) -def restart(types='frps'): - "重启" - G.setadminlog="重启frp" - if not os.path.exists(dar+"/log"): - os.makedirs(dar+"/log") - if types=='frps': - cmd="cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &" - os.system("pkill -9 frps") - system_start.del_Boot_up(cmd) - time.sleep(1) - os.system(cmd) - time.sleep(1) - if not get_process_id('frps'): - return errorjson(msg="启动失败,请检查配置") - system_start.insert_Boot_up(cmd=cmd,name="frps服务端") - elif types=='frpc': - cmd="cd "+dar +" && ./frpc -c frpc.ini &" - os.system("pkill frpc") - system_start.del_Boot_up(cmd) - time.sleep(1) - os.system(cmd) - time.sleep(1) - if not get_process_id('frpc'): - return errorjson(msg="启动失败,请检查配置") - system_start.insert_Boot_up(cmd=cmd,name="frpc客户端") - return successjson() -def stop(types='all'): - "停止" - G.setadminlog="停止frp服务" - if types=='frps': - system_start.del_Boot_up("cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") - os.system("pkill -9 frps") - elif types=='frpc': - system_start.del_Boot_up("cd "+dar +" && nohup ./frpc -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") - os.system("pkill -9 frpc") - else: - system_start.del_Boot_up("cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") - system_start.del_Boot_up("cd "+dar +" && nohup ./frpc -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") - os.system("pkill -9 frps") - os.system("pkill -9 frpc") - return successjson() -def upd_server(types='ini'): - G.setadminlog="修改frp配置" - server=request.get_json() - if types=='ini': - file_set_content(dar+"/frps_full.ini",server['conf']) - elif types=='base': - base=server['base'] - f = open(dar+"/frps_full.ini") - con='' - while True: - line = f.readline() - if not line: - break - elif 'bind_addr = ' in line: - line="bind_addr = "+base['bind_addr']+"\n" - elif 'bind_port = ' in line: - line="bind_port = "+base['bind_port']+"\n" - elif 'bind_udp_port = ' in line: - line="bind_udp_port = "+base['bind_udp_port']+"\n" - elif 'kcp_bind_port = ' in line: - line="kcp_bind_port = "+base['kcp_bind_port']+"\n" - elif 'vhost_http_port = ' in line: - line="vhost_http_port = "+base['vhost_http_port']+"\n" - elif 'vhost_https_port = ' in line: - line="vhost_https_port = "+base['vhost_https_port']+"\n" - elif 'dashboard_addr = ' in line: - line="dashboard_addr = "+base['dashboard_addr']+"\n" - elif 'dashboard_port = ' in line: - line="dashboard_port = "+base['dashboard_port']+"\n" - elif 'dashboard_user = ' in line: - line="dashboard_user = "+base['dashboard_user']+"\n" - elif 'dashboard_pwd = ' in line: - line="dashboard_pwd = "+base['dashboard_pwd']+"\n" - elif 'log_level = ' in line: - line="log_level = "+base['log_level']+"\n" - elif 'log_max_days = ' in line: - line="log_max_days = "+base['log_max_days']+"\n" - elif 'disable_log_color = ' in line: - line="disable_log_color = "+base['disable_log_color']+"\n" - elif 'token = ' in line: - line="token = "+base['token']+"\n" - elif 'allow_ports = ' in line: - line="allow_ports = "+base['allow_ports']+"\n" - elif 'max_pool_count = ' in line: - line="max_pool_count = "+base['max_pool_count']+"\n" - elif 'max_ports_per_client = ' in line: - line="max_ports_per_client = "+base['max_ports_per_client']+"\n" - elif 'subdomain_host = ' in line: - line="subdomain_host = "+base['subdomain_host']+"\n" - elif 'tcp_mux = ' in line: - line="tcp_mux = "+base['tcp_mux']+"\n" - con=con+line - f.close() - file_set_content(dar+"/frps_full.ini",con) - file_set_content(dar+"/frps_full.conf",json_encode(base)) - os.system("pkill frps") - time.sleep(1) - os.system("cd "+dar +" && ./frps -c frps_full.ini &") - time.sleep(1) - if not get_process_id('frps'): - return errorjson(msg="启动失败,请检查配置") - return successjson() -def get_client(): - client={ - 'conf':file_get_content(dar+"/frpc.ini"), - 'base':json_decode(file_get_content(dar+"/frpc.conf")) - } - return successjson(client) -def upd_client(type='ini'): - G.setadminlog="修改frp客户端配置" - server=request.get_json() - file_set_content(dar+"/frpc.ini",server['conf']) - os.system("pkill frpc") - time.sleep(1) - os.system("cd "+dar +" && ./frpc -c frpc.ini &") - time.sleep(1) - if not get_process_id('frpc'): - return errorjson(code=1,msg="启动失败,请检查配置") - return successjson() \ No newline at end of file diff --git a/app/intapp/controller/soft/index.py b/app/intapp/controller/soft/index.py deleted file mode 100644 index e48c782..0000000 --- a/app/intapp/controller/soft/index.py +++ /dev/null @@ -1,131 +0,0 @@ -from .common import * -def index(): - kw=request.args.get("kw") - if not kw: - kw='' - lefttext=request.args.get('lefttext') - if not lefttext: - lefttext='应用' - lefturl=request.args.get('lefturl') - if not lefturl: - lefturl='myapp' - lefttype=request.args.get('lefttype') - if not lefttype: - lefttype='lefturl' - if sysisphone(): - return response.tpl("../tplm/index/home",kw=kw,lefttext=lefttext,lefturl=lefturl,lefttype=lefttype) - else: - return response.tpl('index/home',kw=kw) -def gettitle(title,edition): - "获取软件信息" - return successjson(sqlite('soft',model_intapp_soft_path).where("title='"+title+"' and edition='"+edition+"' and platform='"+get_sysinfo()['uname'][0]+"' and status >=4").find()) -def softlist(): - kw=request.args.get("kw") - pagenow=int(request.args.get("pagenow")) - pagesize=int(request.args.get("pagesize")) - return successjson(SOFT.softlist(kw,pagenow,pagesize)) -def updatesoftlist(): - "更新软件列表" - G.setadminlog="更新软件列表" - SOFT.updatesoftlist() - return successjson() -def getstatus(id): - "获取软件状态和描述" - return successjson(sqlite("soft",model_intapp_soft_path).field("status,msg").where("id",id).find()) -def insert(id): - "安装软件" - G.setadminlog="安装软件" - tar=sqlite('soft',model_intapp_soft_path).where("id",id).field("title,edition").find() - title=tar['title'] - if 'nginx' == title: - ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','nginx'),'and',('status','gt',0)]).find() - if ass: - return errorjson(msg="您已安装其他nginx版本,卸载其他nginx版本后可安装此版本") - if 'mysql' == title: - if "5.7" == tar['edition']: - ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','mysql'),'and',('status','gt',0),'and',('edition','eq','8.0')]).find() - if ass: - return errorjson(msg="您已安装8.0版本mysql") - if "8.0" == tar['edition']: - ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','mysql'),'and',('status','gt',0),'and',('edition','eq','5.7')]).find() - if ass: - return errorjson(msg="您已安装5.7版本mysql") - elif 'jdk' == title: - ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','jdk'),'and',('status','gt',0)]).find() - if ass: - return errorjson(msg="您已安装其他jdk版本,卸载其他jdk版本后可安装此版本") - elif 'tomcat' == title: - ass=sqlite('soft',model_intapp_soft_path).where([('title','eq','jdk'),'and',('status','gt',0)]).find() - if not ass: - return errorjson(msg="tomcat依赖于jdk,请先安装jdk") - elif 'kodexplorer' in title or 'phpmyadmin' in title: - if not sqlite('soft',model_intapp_soft_path).where([('title','like','%php%'),'and',('status','egt','4')]).count() or not sqlite('soft',model_intapp_soft_path).where([('title','like','%nginx%'),'and',('status','egt','4')]).count(): - return errorjson(msg="先安装nginx和php") - if 'phpmyadmin' in title: - if not sqlite('soft',model_intapp_soft_path).where([('title','like','%mysql%'),'and',('status','egt','4')]).count() or not sqlite('soft',model_intapp_soft_path).where([('title','like','%nginx%'),'and',('status','egt','4')]).count(): - return errorjson(msg="先安装mysql") - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":1,"msg":"安装中"}) - Queues.insert(target=SOFT.insert,args=(id,),title="安装软件:"+title) - return successjson() -def start(id): - "启动软件" - title=request.args.get('title') - if title=='tomcat': - Queues.insert(SOFT.start,args=(id,),title='启动tomcat服务') - time.sleep(2) - else: - SOFT.start(id) - return successjson() -def stop(id): - "停止软件" - SOFT.stop(id) - return successjson() -def restartnginx(): - """平滑重启nginx""" - os.system("nginx -s reload") - return successjson() - -def uninstall(id): - "卸载软件" - # title=request.args.get("title") - title=sqlite('soft',model_intapp_soft_path).where("id",id).field("title").find()['title'] - if 'nginx' == title: - sqlite("web",model_intapp_soft_path).where("1=1").update({"status":0}) - sqlite("soft",model_intapp_soft_path).where("id",id).update({"status":5,"msg":"卸载中"}) - Queues.insert(target=SOFT.uninstall,args=(id,),title="卸载软件:"+title) - return successjson() - - -def gitssh(): - 'gitssh公钥' - try: - data=file_get_content("/root/.ssh/id_rsa.pub") - except: - data='' - return successjson(data) - - - -def add(): - "添加内容" - try: - data=request.get_json() - data.update(updtime=times(),addtime=times()) - # print(data) - sqlite('software',config.sqlitesoftware).insert(data) - except: - return errorjson(msg="失败") - else: - return successjson() -def update(id=0): - "更新内容" - data=request.get_json() - if not id: - id=data['id'] - try: - data.pop('updtime') - data.pop('addtime') - except:pass - else: - sqlite('software',config.sqlitesoftware).where("id",id).update(data) - return successjson() \ No newline at end of file diff --git a/app/intapp/controller/soft/install.txt b/app/intapp/controller/soft/install.txt deleted file mode 100644 index f75c93b..0000000 --- a/app/intapp/controller/soft/install.txt +++ /dev/null @@ -1 +0,0 @@ -oss2>=2.12.0 \ No newline at end of file diff --git a/app/intapp/controller/soft/mongodb.py b/app/intapp/controller/soft/mongodb.py deleted file mode 100644 index cc24fb8..0000000 --- a/app/intapp/controller/soft/mongodb.py +++ /dev/null @@ -1,253 +0,0 @@ -from .common import * -import base64 -WORK_DIR="/data/mongodb" -# if not os.path.exists(WORK_DIR): -# os.system("mkdir -p "+WORK_DIR) -def get_config(id): - '获取mongodb页面配置' - try: - data=json_decode(file_get_content(WORK_DIR+"/config.conf")) - except: - data={} - if not data: - data={} - if os.path.isfile(WORK_DIR+"/key/mongo.key"): - key=file_get_content(WORK_DIR+"/key/mongo.key") - else: - key='' - data['key']=key - data['get_local_ip']=get_local_ip() - data['WORK_DIR']=WORK_DIR - try: - data['configlist']=json_decode(file_get_content(WORK_DIR+"/serverconfig.conf")) - except: - data['configlist']={} - return successjson(data) -def upd_config(id): - '修改mongodb页面配置' - G.setadminlog="修改mongodb页面配置" - data=request.get_json() - os.system("mkdir -p "+WORK_DIR+"/key") - f=open(WORK_DIR+"/key/mongo.key","w") - f.write(data['key']) - f.close() - os.system("chmod 600 "+WORK_DIR+"/key/mongo.key") - data['key']='' - file_set_content(WORK_DIR+"/config.conf",json_encode(data)) - return successjson() - -def start_config(types='restart'): - '启动/停止config服务' - G.setadminlog="启动/停止config服务" - data=request.get_json() - data['key']='' - os.system("mkdir -p "+WORK_DIR+"/conf") - f=open(WORK_DIR+"/conf/config.conf","w") - f.write("logappend=true\n"+ - "fork=true\n"+ - "maxConns=5000\n"+ - "replSet=configs\n"+ - "keyFile="+WORK_DIR+"/key/mongo.key\n"+ - "configsvr=true") - f.close() - os.system("chmod 777 "+WORK_DIR+"/conf/config.conf") - # os.system("chmod 600 "+WORK_DIR+"/key/mongo.key") - i=1 - for k in data['configs']['server']: - os.system("mkdir -p "+WORK_DIR+"/config"+str(i)+"/data") - i+=1 - if types=='restart' or types=='stop': #停止服务 - i=1 - for k in data['configs']['server']: - pid=file_get_content(WORK_DIR+"/config"+str(i)+"/db.pid") - os.system("kill -9 "+str(pid)) - time.sleep(0.1) - i+=1 - data['configs']['serverstatus']=0 - if types=='restart' or types=='start': #启动服务 - i=1 - for k in data['configs']['server']: - startstatus=False - cmd="mongod --bind_ip "+str(k['ip'])+" --port "+str(k['port'])+" -f "+WORK_DIR+"/conf/config.conf --dbpath "+WORK_DIR+"/config"+str(i)+"/data --logpath "+WORK_DIR+"/config"+str(i)+"/log.log --pidfilepath "+WORK_DIR+"/config"+str(i)+"/db.pid" - result=os.popen(cmd) - res = result.read() - for line in res.splitlines(): - print("line",line) - if 'process started successfully' in line: - startstatus=True - break - if not startstatus: - return errorjson(code=1,msg="启动失败") - - i+=1 - data['configs']['serverstatus']=1 - file_set_content(WORK_DIR+"/config.conf",json_encode(data)) - return successjson() -def start_mongos(types='restart'): - '启动/停止路由服务' - G.setadminlog="启动/停止路由服务" - data=request.get_json() - data['key']='' - # for k in data - #创建配置文件 - os.system("mkdir -p "+WORK_DIR+"/conf && mkdir -p "+WORK_DIR+"/mongos") - f=open(WORK_DIR+"/conf/mongos.conf","w") - f.write("logappend = true\n"+ - "fork=true\n"+ - data['mongos']['configdb']+" #这里必须是公共网ip或内网ip,千万不能是127.0.0.1\n" - "keyFile="+WORK_DIR+"/key/mongo.key\n"+ - "maxConns=20000 #最大连接数") - f.close() - os.system("chmod 777 "+WORK_DIR+"/conf/mongos.conf") - os.system("mkdir -p "+WORK_DIR+"/mongos") - if types=='restart' or types=='stop': #停止服务 - i=1 - for k in data['mongos']['server']: - pid=file_get_content(WORK_DIR+"/mongos/db"+str(i)+".pid") - os.system("kill -9 "+str(pid)) - time.sleep(0.1) - i+=1 - data['mongos']['serverstatus']=0 - if types=='restart' or types=='start': #启动服务 - i=1 - for k in data['mongos']['server']: - startstatus=False - cmd="mongos --bind_ip "+str(k['ip'])+" --port "+str(k['port'])+" -f "+WORK_DIR+"/conf/mongos.conf --logpath "+WORK_DIR+"/mongos/log"+str(i)+".log --pidfilepath "+WORK_DIR+"/mongos/db"+str(i)+".pid" - print(cmd) - result=os.popen(cmd) - res = result.read() - for line in res.splitlines(): - print("line",line) - if 'process started successfully' in line: - startstatus=True - break - if not startstatus: - return errorjson(code=1,msg="启动失败") - i+=1 - data['mongos']['serverstatus']=1 - file_set_content(WORK_DIR+"/config.conf",json_encode(data)) - return successjson() -def start_shard(types='restart'): - '启动/停止分片服务' - G.setadminlog="启动/停止分片服务" - data=request.get_json() - data['key']='' - os.system("mkdir -p "+WORK_DIR+"/conf") - - j=1 - for shard in data['shard']:#分片列表 - f=open(WORK_DIR+"/conf/shard"+str(j)+".conf","w") - f.write("logappend=true\n"+ - "fork=true\n"+ - "maxConns=2000\n"+ - "storageEngine=mmapv1 #基于内存映射文件的存储引擎\n"+ - "shardsvr=true\n"+ - "replSet="+shard['servername']+"\n"+ - "keyFile="+WORK_DIR+"/key/mongo.key") - f.close() - i=1 - for k in shard['server']: - os.system("mkdir -p "+WORK_DIR+"/shard"+str(j)+"/data"+str(i)) - i+=1 - if types=='restart' or types=='stop': #停止服务 - i=1 - for k in shard['server']: - pid=file_get_content(WORK_DIR+"/shard"+str(j)+"/db"+str(i)+".pid") - os.system("kill -9 "+str(pid)) - time.sleep(0.1) - i+=1 - data['shard'][j-1]['serverstatus']=0 - if types=='restart' or types=='start': #启动服务 - i=1 - for k in shard['server']:#副本集列表 - startstatus=False - cmd="mongod --bind_ip "+str(k['ip'])+" --port "+str(k['port'])+" -f "+WORK_DIR+"/conf/shard"+str(j)+".conf --dbpath "+WORK_DIR+"/shard"+str(j)+"/data"+str(i)+" --logpath "+WORK_DIR+"/shard"+str(j)+"/log"+str(i)+".log --pidfilepath "+WORK_DIR+"/shard"+str(j)+"/db"+str(i)+".pid" - print("启动cmd:",cmd) - result=os.popen(cmd) - res = result.read() - for line in res.splitlines(): - print("line",line) - if 'process started successfully' in line: - startstatus=True - break - if not startstatus: - file_set_content(WORK_DIR+"/config.conf",json_encode(data)) - return errorjson(code=1,msg="启动失败") - i+=1 - data['shard'][j-1]['serverstatus']=1 - j+=1 - file_set_content(WORK_DIR+"/config.conf",json_encode(data)) - return successjson() - -# def config_init(id): -# "config副本集初始化," -# data=request.get_json() -# port=data['configs']['server'][0]['port'] -# replicaset=data['configs']['replicaset'] -# members=[] -# i=0 -# for k in replicaset: -# zd={'_id':i,'host':k['ip']+':'+str(k['port'])} -# members.append(zd) -# i+=1 -# f=open(config.path['path']+"app/linuxweb/config_init.sh","w") -# f.write("mongo --port "+str(port)+"\n"+ -# "use admin\n"+ -# "rs.initiate({_id:'configs',members:"+json_encode(members)+"})\n"+ -# "exit") -# f.close() -# os.system("cd "+config.path['path']+"app/linuxweb && bash config_init.sh") -# return successjson() - - - -#mongodb独立部署 /data/mongodb/server1/ -def setserverconfig(): - configlist=request.get_json() - for k in configlist: - if not os.path.exists(WORK_DIR+k['path']): - os.makedirs(WORK_DIR+k['path']) - if not os.path.exists(WORK_DIR+k['path']+"/data"): - os.makedirs(WORK_DIR+k['path']+"/data") - file_set_content(WORK_DIR+k['path']+"/mongod.config",''+ - 'systemLog:\n'+ - ' destination: file\n'+ - ' logAppend: true\n'+ - ' path: '+WORK_DIR+k['path']+'/mongodb.log #mongodb的日志文件路径\n'+ - 'storage:\n'+ - ' dbPath: '+WORK_DIR+k['path']+'/data/ #mongodb的数据文件路径\n'+ - ' journal:\n'+ - ' enabled: true\n'+ - 'processManagement:\n'+ - ' fork: true # fork and run in background\n'+ - ' pidFilePath: '+WORK_DIR+k['path']+'/mongod.pid # location of pidfile\n'+ - ' timeZoneInfo: /usr/share/zoneinfo\n'+ - 'net:\n'+ - ' port: '+str(k['port'])+' #mongodb1的进程号\n'+ - ' bindIp: '+k['bindIp']+' # Listen to local interface only, comment to listen on all interfaces') - file_set_content(WORK_DIR+"/serverconfig.conf",json_encode(configlist)) - return successjson() -def restartserver(types='start',index=0): - index=int(index) - configlist=json_decode(file_get_content(WORK_DIR+"/serverconfig.conf")) - cmd="mongod -f "+WORK_DIR+configlist[index]['path']+"/mongod.config" #启动命令 - if types=='start': - configlist[index]['status']=1 - system_start.insert_Boot_up(cmd=cmd,name="mongodb独立模式",icon="https://img.kwebapp.cn/icon/mongodb.png") - elif types=='stop': - configlist[index]['status']=0 - system_start.del_Boot_up(cmd) - cmd=cmd+" --shutdown" #停止命令 - result=os.popen(cmd) - res = result.read() - startstatus=False - for line in res.splitlines(): - print("line",line) - if 'process started successfully' in line or 'killing process with pid' in line: - startstatus=True - break - if startstatus: - file_set_content(WORK_DIR+"/serverconfig.conf",json_encode(configlist)) - return successjson() - else: - return errorjson(cmd,msg="失败") diff --git a/app/intapp/controller/soft/mysql copy.py b/app/intapp/controller/soft/mysql copy.py deleted file mode 100644 index 32e65f1..0000000 --- a/app/intapp/controller/soft/mysql copy.py +++ /dev/null @@ -1,310 +0,0 @@ -from .common import * -import oss2 -def get_data(id): - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - text=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") - conf=json_decode(text) - if not conf: - if ar['edition']=='5.7': - port=3306 - else: - port=3307 - conf={ - "base":{ - 'rootpassword':'intapppasswordtest', - 'path':ar['paths']+ar['title']+ar['edition']+'/data', - 'port':port, #监听端口 - 'max_connections':'200',#最大连接数 - 'max_allowed_packet':'16M', #最大接受的数据包大小 - 'expire_logs_days':'3',#日志保留时间天() - 'query_cache_limit':'1M',#指定单个查询可以使用的缓冲区的大小 - 'query_cache_size':'32M',#查询的缓存大小设置 - 'query_cache_type':'1',#设置缓存的类型, 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 - 'wait_timeout':'9000',#超时等待时间,单位秒,即一个connection在若干秒内无响应 - 'thread_cache_size':'256',# 用于缓存空闲的线程 - 'key_buffer_size':'16M' # 用于指定索引缓冲区的大小 - }, - } - if ar['edition']=='5.7': - mycnf=file_get_content("/etc/my.cnf") - else: - mycnf=file_get_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf") - data={ - 'conf':conf, - 'ar':ar, - "my":mycnf - } - return successjson(data) -def upd_my(id): - "修改配置文件" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - data=request.get_json() - if ar['edition']=='5.7': - file_set_content("/etc/my.cnf",data['text']) - else: - file_set_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf",data['text']) - return successjson() -def upd_data(id): - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - data=request.get_json() - filetext=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") - filedata=json_decode(filetext) - if not filedata or data['base']['rootpassword']!=filedata['base']['rootpassword']:#修改mysql密码 - os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart --skip-grant-tables") - cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -e " - cmd=cmd+'"use mysql;flush privileges;update user set authentication_string=password(' - cmd=cmd+"'"+str(data['base']['rootpassword']) - cmd=cmd+"'" - cmd=cmd+') where user=' - cmd=cmd+"'root';set password=password('"+str(data['base']['rootpassword'])+"');" - cmd=cmd+'"' - if '5.7' != ar['edition']: - cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -p3307 -S "+ar['paths']+ar['title']+ar['edition']+"/tmp/mysql.sock -e " - cmd+='"use mysql;flush privileges;grant all privileges on *.* to root@' - cmd+="'%'" - cmd+=" identified by 'root';update mysql.user set password=password('"+data['base']['rootpassword']+"') where user='root';update mysql.user set grant_priv='Y' where User='root';flush privileges" - cmd=cmd+'"' - # file_set_content("mysqlset",cmd) - pi=subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart") - print(type(strs),strs) - if 'error' in strs: - return errorjson(msg="密码修改失败"+strs) - - # mysqld restart --skip-grant-tables && mysql -uroot -e "flush privileges;update mysql.user set authentication_string=password('123456') where user = 'root'"; - # print(data['base']['rootpassword'],filedata['base']['rootpassword']) - if '5.7' == ar['edition']: - mycnf='/etc/my.cnf' - else: - mycnf=ar['paths']+ar['title']+ar['edition']+"/my.cnf" - f = open(mycnf) - con='' - while True: - line = f.readline() - if not line: - break - elif 'datadir=' in line: - line="datadir="+str(data['base']['path'])+"\n" - elif 'port=' in line or 'port =' in line: - line="port="+str(data['base']['port'])+"\n" - elif 'max_connections=' in line: - line="max_connections="+str(data['base']['max_connections'])+"\n" - elif 'max_allowed_packet=' in line: - line="max_allowed_packet="+str(data['base']['max_allowed_packet'])+"\n" - elif 'expire_logs_days=' in line: - line="expire_logs_days="+str(data['base']['expire_logs_days'])+"\n" - elif 'query_cache_limit=' in line: - line="query_cache_limit="+str(data['base']['query_cache_limit'])+"\n" - elif 'query_cache_size=' in line: - line="query_cache_size="+str(data['base']['query_cache_size'])+"\n" - elif 'query_cache_type=' in line: - line="query_cache_type="+str(data['base']['query_cache_type'])+"\n" - elif 'wait_timeout=' in line: - line="wait_timeout="+str(data['base']['wait_timeout'])+"\n" - elif 'thread_cache_size=' in line: - line="thread_cache_size="+str(data['base']['thread_cache_size'])+"\n" - elif 'key_buffer_size=' in line: - line="key_buffer_size="+str(data['base']['key_buffer_size'])+"\n" - con=con+line - f.close() - f= open(mycnf, "w") - f.write(con) - f.close() - time.sleep(1) - if not filedata or data['base']['path']!=filedata['base']['path']: #修改数据存放目录 - os.system('mysqld'+(ar['edition'].replace(".", ""))+'server stop') - os.system("mkdir -p "+str(data['base']['path'])) - # #mysql数据复制 - if not filedata: - print("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") - os.system("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") - else: - print("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") - os.system("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") - os.system("chown -R mysql "+data['base']['path']+" && chgrp -R mysql "+data['base']['path']) - os.system('mysqld'+(ar['edition'].replace(".", ""))+'server start') - text=json_encode(data) - file_set_content(ar['paths']+ar['title']+ar['edition']+"/config.conf",text) - - return successjson() -def backups(types='whole',db='bankup_all_databases',upload_aliyun=True): - "备份mysql5.7" - return BACKUP.backups(types,db,upload_aliyun) -def recovery(types='whole',upload_aliyun=True): - "恢复mysql5.7" - db=request.args.get("db") - Queues.insert(target=BACKUP.recovery,args=(types,db,upload_aliyun),title="恢复mysql") - return successjson(msg="正在恢复数据库,请在任务队列中查看恢复结果") -class BACKUP: - def recovery(types,db,upload_aliyun): - """恢复数据库""" - if not os.path.isfile("app/common/file/config.conf"): - print("在系统配置中保存备份目录") - return - fileconfig=json_decode(file_get_content("app/common/file/config.conf")) - if not fileconfig: - print("在系统配置中保存备份目录") - return - backpath=fileconfig['aliyun']['backpath'] - if backpath: - if backpath[:1]=='/': - backpath=backpath[1:] - if backpath[-1]=='/': - backpath=backpath[:-1] - else: - backpath="kcweb" - backmysqlpath="backup/mysql" #mysql备份目录 - if not os.path.exists(backmysqlpath): - os.makedirs(backmysqlpath) - mysqlpwd='intapppasswordtest' - mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql5.7/config.conf")) #mysql信息 - if mysqlconf: - mysqldatapath=mysqlconf['base']['path'] - mysqlpwd=mysqlconf['base']['rootpassword'] - conf={ - "mysql":{ - "username":"root","password":mysqlpwd,"host":"127.0.0.1",#mysql信息 - }, - } - if upload_aliyun: - auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) - bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) - bucket.get_object_to_file(db,backmysqlpath+"/database.sql.gz") - os.system("gzip -d "+backmysqlpath+"/database.sql.gz") - os.system("mysql -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" < "+backmysqlpath+"/database.sql") - os.remove(backmysqlpath+"/database.sql") - else: - os.system("gzip -d "+backmysqlpath+"/"+db+".sql.gz") - os.system("mysql -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" < "+backmysqlpath+"/"+db+".sql") - print("恢复完成") - def backups(types,db,upload_aliyun): - """备份mysql --cli运行 - types whole表示全量备份。 increment表示增量备份所有 - - db bankup_all_databases表示备份所有数据库。 否则备份指定数据库按逗号分隔 types=whole时有效 - """ - if not os.path.isfile("app/common/file/config.conf"): - print("在系统配置中保存备份目录") - return - fileconfig=json_decode(file_get_content("app/common/file/config.conf")) - if not fileconfig: - print("在系统配置中保存备份目录") - return - backpath=fileconfig['aliyun']['backpath'] - if backpath: - if backpath[:1]=='/': - backpath=backpath[1:] - if backpath[-1]=='/': - backpath=backpath[:-1] - else: - backpath="kcweb" - backmysqlpath="backup/mysql" #mysql备份目录 - if not os.path.exists(backmysqlpath): - os.makedirs(backmysqlpath) - mysqldatapath="/usr/local/mysql/mysql5.7/data" #mysql数据库存放目 - mysqlpwd='intapppasswordtest' - mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql5.7/config.conf")) #mysql信息 - if mysqlconf: - mysqldatapath=mysqlconf['base']['path'] - mysqlpwd=mysqlconf['base']['rootpassword'] - conf={ - "mysql":{ - "username":"root","password":mysqlpwd,"host":"127.0.0.1",#mysql信息 - }, - } - if upload_aliyun: - auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) - bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) - if types=='whole': #全量备份 - if not os.path.exists(backmysqlpath): - os.system("mkdir -p "+backmysqlpath) - if db=='bankup_all_databases':#备份所有 - print("全量备份所有数据库:"+db+".sql.gz") - os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+".sql.gz") - else:#备份指定数据库 - db=re.sub(","," ",db) - print("全量备份指定数据库:"+db+".sql.gz") - os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+".sql.gz") - if upload_aliyun: - print(backmysqlpath+"/"+db+".sql.gz","上传mysql备份目录文件到阿里云oss...") - oss2.resumable_upload(bucket, "backups/"+backpath+"/"+backmysqlpath+"/"+db+"/"+time.strftime("%Y%m%d-%H:%M:%S",time.localtime(times()))+".sql.gz",backmysqlpath+"/"+db+".sql.gz") - filelist=[] - for obj in oss2.ObjectIterator(bucket, prefix="backups/"+backpath+"/"+backmysqlpath+"/"+db+"/"): - filelist.append(obj.key) - i=0 - while True: - if len(filelist)-i <= 5: #在阿里云保留5个备份文件 其他上传 - break - bucket.delete_object(filelist[i]) - i+=1 - - # elif types=='increment': #增量备份所有 - # if not os.path.exists(backmysqlpath) or not os.path.isfile(backmysqlpath+"/"+db+".sql.gz"): - # os.system("mkdir -p "+backmysqlpath) - # print("全量备份所有数据库:"+db+".sql.gz") - # os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/increment_all_databases.sql.gz") - # print("备份mysql二进制文件...") - # t=os.listdir(backmysqlpath) - # lis=os.listdir(mysqldatapath) - # maxlist=[] - # for files in lis: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # maxlist.append(a) - # except:pass - # for files in lis: - # iscz=True #是否需要复制 - # if iscz: - # for k in t: - # if mysqldatapath+"/"+k == mysqldatapath+"/"+files: - # iscz=False - # print(mysqldatapath+"/"+k+"已存在") - # break - # if not iscz: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # if max(maxlist) == a: - # iscz=True - # print(mysqldatapath+"/"+files+"该文件是最后一个日志,已备份,(最后一个文件可能不是完整的)") - # except:pass - # if iscz: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # os.system("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files) - # print("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files,"复制成功") - # except:pass - # if upload_aliyun: - # print("上传mysql备份目录文件到阿里云oss...") - # t=os.listdir(backmysqlpath) - # maxlist=[] - # for files in t: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # maxlist.append(a) - # except:pass - # path=get_file(backmysqlpath,is_folder=False) - # for files in path: - # sc=True #是否需要上传 - # if bucket.object_exists("backups/"+files['path']):#如果文件已存在阿里云 - # if 'mysql-bin.' in files['name']: - # try: - # a=int(files['name'].replace("mysql-bin.", "")) - # if max(maxlist) == a: - # print(backmysqlpath+"/"+files['name']+"该文件是最后一个日志,所以要上传阿里云") - # else: - # print("文件已在阿里云oss存在") - # sc=False - # except:pass - # else: - # print("文件已在阿里云oss存在") - # sc=False - # if sc: - # oss2.resumable_upload(bucket, "backups/"+files['path'], files['path']) - print("备份完成") diff --git a/app/intapp/controller/soft/mysql.py b/app/intapp/controller/soft/mysql.py deleted file mode 100644 index e0474c4..0000000 --- a/app/intapp/controller/soft/mysql.py +++ /dev/null @@ -1,338 +0,0 @@ -from .common import * -import oss2 -def get_data(id): - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - text=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") - conf=json_decode(text) - if not conf: - if ar['edition']=='5.7': - port=3306 - elif ar['edition']=='8.0': - port=3308 - else: - port=3307 - conf={ - "base":{ - 'rootpassword':'intapppasswordtest', - 'path':ar['paths']+ar['title']+ar['edition']+'/data', - 'port':port, #监听端口 - 'max_connections':'200',#最大连接数 - 'max_allowed_packet':'16M', #最大接受的数据包大小 - 'expire_logs_days':'3',#日志保留时间天() - 'query_cache_limit':'1M',#指定单个查询可以使用的缓冲区的大小 - 'query_cache_size':'32M',#查询的缓存大小设置 - 'query_cache_type':'1',#设置缓存的类型, 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 - 'wait_timeout':'9000',#超时等待时间,单位秒,即一个connection在若干秒内无响应 - 'thread_cache_size':'256',# 用于缓存空闲的线程 - 'key_buffer_size':'16M' # 用于指定索引缓冲区的大小 python3 kcw.py --app app --modular intapp --plug soft --uninstall - }, - } - if '5.6' == ar['edition']: - mycnf=file_get_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf") - else: - mycnf=file_get_content("/etc/my.cnf") - data={ - 'conf':conf, - 'ar':ar, - "my":mycnf - } - return successjson(data) -def upd_my(id): - "修改配置文件" - G.setadminlog="mysql修改配置文件" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - data=request.get_json() - if '5.6' == ar['edition']: - file_set_content(ar['paths']+ar['title']+ar['edition']+"/my.cnf",data['text']) - else: - file_set_content("/etc/my.cnf",data['text']) - return successjson() -def upd_data(id): - G.setadminlog="mysql修改基本配置文件" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - data=request.get_json() - filetext=file_get_content(ar['paths']+ar['title']+ar['edition']+"/config.conf") - filedata=json_decode(filetext) - if (ar['edition']=='5.7' or ar['edition']=='5.6') and (not filedata or data['base']['rootpassword']!=filedata['base']['rootpassword']):#修改mysql密码 - os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart --skip-grant-tables") - cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -e " - cmd=cmd+'"use mysql;flush privileges;update user set authentication_string=password(' - cmd=cmd+"'"+str(data['base']['rootpassword']) - cmd=cmd+"'" - cmd=cmd+') where user=' - cmd=cmd+"'root';set password=password('"+str(data['base']['rootpassword'])+"');" - cmd=cmd+'"' - if '5.7' != ar['edition']: - cmd="mysql"+(ar['edition'].replace(".", ""))+" -uroot -p3307 -S "+ar['paths']+ar['title']+ar['edition']+"/tmp/mysql.sock -e " - cmd+='"use mysql;flush privileges;grant all privileges on *.* to root@' - cmd+="'%'" - cmd+=" identified by 'root';update mysql.user set password=password('"+data['base']['rootpassword']+"') where user='root';update mysql.user set grant_priv='Y' where User='root';flush privileges" - cmd=cmd+'"' - # file_set_content("mysqlset",cmd) - pi=subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - os.system("mysqld"+(ar['edition'].replace(".", ""))+"server restart") - print(type(strs),strs) - if 'error' in strs: - return errorjson(msg="密码修改失败"+strs) - - # mysqld restart --skip-grant-tables && mysql -uroot -e "flush privileges;update mysql.user set authentication_string=password('123456') where user = 'root'"; - # print(data['base']['rootpassword'],filedata['base']['rootpassword']) - if '5.6' == ar['edition']: - mycnf=ar['paths']+ar['title']+ar['edition']+"/my.cnf" - else: - mycnf="/etc/my.cnf" - f = open(mycnf) - con='' - while True: - line = f.readline() - if not line: - break - elif 'datadir=' in line and data['base']['path']: - line="datadir="+str(data['base']['path'])+"\n" - elif ('port=' in line or 'port =' in line) and data['base']['port']: - line="port="+str(data['base']['port'])+"\n" - elif 'max_connections=' in line and data['base']['max_connections']: - line="max_connections="+str(data['base']['max_connections'])+"\n" - elif 'max_allowed_packet=' in line and data['base']['max_allowed_packet']: - line="max_allowed_packet="+str(data['base']['max_allowed_packet'])+"\n" - elif 'expire_logs_days=' in line and data['base']['expire_logs_days']: - line="expire_logs_days="+str(data['base']['expire_logs_days'])+"\n" - elif 'query_cache_limit=' in line and data['base']['query_cache_limit']: - line="query_cache_limit="+str(data['base']['query_cache_limit'])+"\n" - elif 'query_cache_size=' in line and data['base']['query_cache_size']: - line="query_cache_size="+str(data['base']['query_cache_size'])+"\n" - elif 'query_cache_type=' in line and data['base']['query_cache_type']: - line="query_cache_type="+str(data['base']['query_cache_type'])+"\n" - elif 'wait_timeout=' in line and data['base']['wait_timeout']: - line="wait_timeout="+str(data['base']['wait_timeout'])+"\n" - elif 'thread_cache_size=' in line and data['base']['thread_cache_size']: - line="thread_cache_size="+str(data['base']['thread_cache_size'])+"\n" - elif 'key_buffer_size=' in line and data['base']['key_buffer_size']: - line="key_buffer_size="+str(data['base']['key_buffer_size'])+"\n" - con=con+line - f.close() - f= open(mycnf, "w") - f.write(con) - f.close() - time.sleep(1) - if not filedata or data['base']['path']!=filedata['base']['path']: #修改数据存放目录 - os.system('mysqld'+(ar['edition'].replace(".", ""))+'server stop') - os.system("mkdir -p "+str(data['base']['path'])) - # #mysql数据复制 - if not filedata: - print("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") - os.system("cp -r "+ar['paths']+ar['title']+ar['edition']+"/data/. "+data['base']['path']+"/") - else: - print("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") - os.system("cp -r "+filedata['base']['path']+"/. "+data['base']['path']+"/") - os.system("chown -R mysql "+data['base']['path']+" && chgrp -R mysql "+data['base']['path']) - os.system('mysqld'+(ar['edition'].replace(".", ""))+'server start') - text=json_encode(data) - file_set_content(ar['paths']+ar['title']+ar['edition']+"/config.conf",text) - - return successjson() -def backups(types='whole',db='bankup_all_databases',upload_aliyun=True,edition='5.7'): - "备份mysql" - return BACKUP.backups(types,db,upload_aliyun,edition) -def recovery(types='whole',upload_aliyun=True,edition='5.7'): - "恢复mysql" - if config.app['cli']: - db="backups/kcweb/backup/mysql/bankup_all_databases5.6/20200909-02:51:23.sql.gz" - BACKUP.recovery(types,db,upload_aliyun,edition) - else: - db=request.args.get("db") - Queues.insert(target=BACKUP.recovery,args=(types,db,upload_aliyun,edition),title="恢复mysql"+edition) - return successjson(msg="正在恢复数据库,请在任务队列中查看恢复结果") -class BACKUP: - def recovery(types,db,upload_aliyun,edition): - """恢复数据库""" - if not os.path.isfile("app/common/file/config.conf"): - print("在系统配置中保存备份目录") - return - fileconfig=json_decode(file_get_content("app/common/file/config.conf")) - if not fileconfig: - print("在系统配置中保存备份目录") - return - backpath=fileconfig['aliyun']['backpath'] - if backpath: - if backpath[:1]=='/': - backpath=backpath[1:] - if backpath[-1]=='/': - backpath=backpath[:-1] - else: - backpath="kcweb" - backmysqlpath="backup/mysql" #mysql备份目录 - if not os.path.exists(backmysqlpath): - os.makedirs(backmysqlpath) - mysqlpwd='intapppasswordtest' - mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql"+edition+"/config.conf")) #mysql信息 - if mysqlconf: - mysqldatapath=mysqlconf['base']['path'] - mysqlpwd=mysqlconf['base']['rootpassword'] - port=str(mysqlconf['base']['port']) - else: - if edition=='5.6': - port="3307" - elif edition=='5.7': - port="3306" - elif edition=='8.0': - port="3308" - conf={ - "mysql":{ - "username":"root","password":mysqlpwd,"host":"127.0.0.1","port":port,#mysql信息 - }, - } - if upload_aliyun: - auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) - bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) - bucket.get_object_to_file(db,backmysqlpath+"/database.sql.gz") - os.system("gzip -d "+backmysqlpath+"/database.sql.gz") - os.system("mysql"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -P"+conf['mysql']['port']+" -h"+conf['mysql']['host']+" -p"+conf['mysql']['password']+" < "+backmysqlpath+"/database.sql") - # print("mysql"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -P"+conf['mysql']['port']+" -h"+conf['mysql']['host']+" -p"+conf['mysql']['password']+" < "+backmysqlpath+"/database.sql") - os.remove(backmysqlpath+"/database.sql") - else: - os.system("gzip -d "+backmysqlpath+"/"+db+".sql.gz") - os.system("mysql"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -P"+conf['mysql']['port']+" -h"+conf['mysql']['host']+" -p"+conf['mysql']['password']+" < "+backmysqlpath+"/"+db+".sql") - print("恢复完成") - - def backups(types,db,upload_aliyun,edition): - """备份mysql --cli运行 - types whole表示全量备份。 increment表示增量备份所有 - - db bankup_all_databases表示备份所有数据库。 否则备份指定数据库按逗号分隔 types=whole时有效 - """ - if not os.path.isfile("app/common/file/config.conf"): - print("在系统配置中保存备份目录") - return - fileconfig=json_decode(file_get_content("app/common/file/config.conf")) - if not fileconfig: - print("在系统配置中保存备份目录") - return - - backpath=fileconfig['aliyun']['backpath'] - if backpath: - if backpath[:1]=='/': - backpath=backpath[1:] - if backpath[-1]=='/': - backpath=backpath[:-1] - else: - backpath="kcweb" - backmysqlpath="backup/mysql" #mysql备份目录 - if not os.path.exists(backmysqlpath): - os.makedirs(backmysqlpath) - - mysqlpwd='intapppasswordtest' - mysqlconf=json_decode(file_get_content("/usr/local/mysql/mysql"+edition+"/config.conf")) #mysql信息 - if mysqlconf: - mysqldatapath=mysqlconf['base']['path'] - mysqlpwd=mysqlconf['base']['rootpassword'] - port=str(mysqlconf['base']['port']) - else: - if edition=='5.6': - port="3307" - elif edition=='5.7': - port="3306" - elif edition=='8.0': - port="3308" - mysqldatapath="/usr/local/mysql/mysql"+edition+"/data" #mysql数据库存放目 - conf={ - "mysql":{ - "username":"root","password":mysqlpwd,"host":"127.0.0.1","port":port,#mysql信息 - }, - } - if upload_aliyun: - auth = oss2.Auth(fileconfig['aliyun']['access_key'],fileconfig['aliyun']['access_key_secret']) - bucket = oss2.Bucket(auth,fileconfig['aliyun']['address'],fileconfig['aliyun']['bucket']) - if types=='whole': #全量备份 - if not os.path.exists(backmysqlpath): - os.system("mkdir -p "+backmysqlpath) - if db=='bankup_all_databases':#备份所有 - print("全量备份所有数据库:"+db+".sql.gz") - os.system("mysqldump"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" -P"+conf['mysql']['port']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+edition+".sql.gz") - else:#备份指定数据库 - db=re.sub(","," ",db) - print("全量备份指定数据库:"+db+".sql.gz") - os.system("mysqldump"+edition.replace(".", "")+" -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" -P"+conf['mysql']['port']+" --databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/"+db+edition+".sql.gz") - if upload_aliyun: - print(backmysqlpath+"/"+db+edition+".sql.gz","上传mysql备份目录文件到阿里云oss...") - oss2.resumable_upload(bucket, "backups/"+backpath+"/"+backmysqlpath+"/"+db+edition+"/"+time.strftime("%Y%m%d-%H:%M:%S",time.localtime(times()))+".sql.gz",backmysqlpath+"/"+db+edition+".sql.gz") - filelist=[] - for obj in oss2.ObjectIterator(bucket, prefix="backups/"+backpath+"/"+backmysqlpath+"/"+db+edition+"/"): - filelist.append(obj.key) - i=0 - while True: - if len(filelist)-i <= 30: #在阿里云保留30个备份文件 其他上传 - break - bucket.delete_object(filelist[i]) - i+=1 - - # elif types=='increment': #增量备份所有 - # if not os.path.exists(backmysqlpath) or not os.path.isfile(backmysqlpath+"/"+db+".sql.gz"): - # os.system("mkdir -p "+backmysqlpath) - # print("全量备份所有数据库:"+db+".sql.gz") - # os.system("mysqldump -u"+conf['mysql']['username']+" -p"+conf['mysql']['password']+" -h"+conf['mysql']['host']+" --all-databases --flush-logs --delete-master-logs --single-transaction | gzip >> "+backmysqlpath+"/increment_all_databases.sql.gz") - # print("备份mysql二进制文件...") - # t=os.listdir(backmysqlpath) - # lis=os.listdir(mysqldatapath) - # maxlist=[] - # for files in lis: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # maxlist.append(a) - # except:pass - # for files in lis: - # iscz=True #是否需要复制 - # if iscz: - # for k in t: - # if mysqldatapath+"/"+k == mysqldatapath+"/"+files: - # iscz=False - # print(mysqldatapath+"/"+k+"已存在") - # break - # if not iscz: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # if max(maxlist) == a: - # iscz=True - # print(mysqldatapath+"/"+files+"该文件是最后一个日志,已备份,(最后一个文件可能不是完整的)") - # except:pass - # if iscz: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # os.system("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files) - # print("cp -f "+mysqldatapath+"/"+files+" "+backmysqlpath+"/"+files,"复制成功") - # except:pass - # if upload_aliyun: - # print("上传mysql备份目录文件到阿里云oss...") - # t=os.listdir(backmysqlpath) - # maxlist=[] - # for files in t: - # if 'mysql-bin.' in files: - # try: - # a=int(files.replace("mysql-bin.", "")) - # maxlist.append(a) - # except:pass - # path=get_file(backmysqlpath,is_folder=False) - # for files in path: - # sc=True #是否需要上传 - # if bucket.object_exists("backups/"+files['path']):#如果文件已存在阿里云 - # if 'mysql-bin.' in files['name']: - # try: - # a=int(files['name'].replace("mysql-bin.", "")) - # if max(maxlist) == a: - # print(backmysqlpath+"/"+files['name']+"该文件是最后一个日志,所以要上传阿里云") - # else: - # print("文件已在阿里云oss存在") - # sc=False - # except:pass - # else: - # print("文件已在阿里云oss存在") - # sc=False - # if sc: - # oss2.resumable_upload(bucket, "backups/"+files['path'], files['path']) - print("备份完成") diff --git a/app/intapp/controller/soft/nginx.py b/app/intapp/controller/soft/nginx.py deleted file mode 100644 index bae9675..0000000 --- a/app/intapp/controller/soft/nginx.py +++ /dev/null @@ -1,419 +0,0 @@ -from .common import * -import traceback -def index(id='',types='getinfo'): - "nginx配置文件" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title'] - edition=ar['edition'] - if types=='getinfo': - if os.path.isfile(paths+filenames+edition+'/logs/error.log'): - # print(paths+filenames+'/logs/error.log') - # f=open(paths+filenames+'/logs/error.log','r') - # logserror=f.read() - # f.close() - logserror='' - else:logserror='' - if os.path.isfile(paths+filenames+edition+'/logs/access.log'): - # f=open(paths+filenames+'/logs/access.log','r',encoding="utf-8") - # logsaccess=f.read() - # f.close() - logsaccess='' - else:logsaccess='' - f=open(paths+filenames+edition+'/conf/nginx.conf','r',encoding="utf-8") - confnginx=f.read() - data={ - 'logs':{'error':logserror,'access':logsaccess}, - 'conf':{'nginx':confnginx}, - 'ar':ar, - } - return successjson(data) - elif types=='updconf': - con=request.get_json() - f=open(paths+filenames+edition+'/conf/nginx.conf','w',encoding="utf-8") - f.write(con['text']) - f.close() - return successjson() - else: - return errorjson(msg="未知类型") -def anphp(): - "已安装的php以及伪静态模板" - nginx=sqlite('soft',model_intapp_soft_path).where([('status','egt','4'),'and',('platform','eq',get_sysinfo()['uname'][0]),'and',('title','like','nginx%')]).find() - if nginx: - pseudo_static_tpl=get_file(nginx['paths']+nginx['title']+nginx['edition']+'/conf/vhost/webtpl/rewrite') #伪静态模板 - rewr=[] - for k in pseudo_static_tpl: - rewr.append({'name':k['name'],'text':file_get_content(k['path'])}) - data={ - "php":sqlite('soft',model_intapp_soft_path).where("title like '%php%' and (status=4 or status=10) and title not like '%phpmyadmin%'").select(), - "rewr":rewr - } - return successjson(data) - else: - return successjson() -def webdescribesfind(): - "获取指定网站信息" - title=request.args.get("title") - return successjson(sqlite("web",model_intapp_soft_path).where("title='"+title+"'").find()) -def weblist(): - "网站列表" - where=False - pagenow=int(request.args.get('pagenow')) - pagesize=int(request.args.get('pagesize')) - kw=request.args.get('kw') - if kw: - where=[("title","like","%"+str(kw)+"%"),'or',("describes","like","%"+str(kw)+"%"),'or',("domain","like","%"+str(kw)+"%")] - if not pagenow: - pagenow=1 - if not pagesize: - pagesize=10 - lists=sqlite("web",model_intapp_soft_path).where(where).page(pagenow,pagesize).select() - i=0 - for k in lists: - # lists[i]['domain']=k['domain'].split("\n") - lists[i]['balancing'] =json_decode(k['balancing']) - lists[i]['proxy_set_header'] =json_decode(k['proxy_set_header']) - lists[i]['header'] =json_decode(k['header']) - i+=1 - count=sqlite("web",model_intapp_soft_path).where(where).count() - return successjson(return_list(lists,count,pagenow,pagesize)) -def add_web(): - G.setadminlog="添加或更新nginx网站" - data=request.get_json() - status,msg=funadd_web(data) - if status: - return successjson(msg) - else: - return errorjson(msg=msg) -def _banddomain(id,types,domain): - G.setadminlog="绑定域名" - # domain=request.args.get('domain') - if '.' not in domain: - # return errorjson(msg="域名格式错误") - return False,'域名格式错误' - if not domain: - # return errorjson(msg="域名参数错误") - return False,'域名参数错误' - web=sqlite("web",model_intapp_soft_path).where("id",id).find() - if web: - if(sqlite("web",model_intapp_soft_path).where("domain like '%"+domain+"%'").count()): - if types=='add': - # return successjson(msg="该域名已被使用",code=1) - return True,'该域名已被使用' - data=web - if domain: - if types=='add': - data['domain']=data['domain']+"\n"+domain - elif types=='del': - data['domain']=data['domain'].replace("\n"+domain, "") - data['domain']=data['domain'].replace(domain, "") - # return errorjson(data) - else: - # return errorjson(msg="types错误") - return False,'types错误' - if data['header']: - data['header']=json_decode(data['header']) - data['proxy_set_header']=json_decode(data['proxy_set_header']) - data['balancing']=json_decode(data['balancing']) - return funadd_web(data,types) - # return status,msg - # if status: - # return successjson(msg) - # else: - # return errorjson(msg=msg) - else: - return False,'id错误' - # return errorjson(msg="id错误") -def funadd_web(data,types=""): - "添加或更新网站" - nginx=sqlite('soft',model_intapp_soft_path).where([('status','egt','4'),'and',('platform','eq',get_sysinfo()['uname'][0]),'and',('title','like','nginx%')]).find() - if not nginx: - return errorjson(msg='安装nginx服务器后才创建网站') - addtime=times() - - if data['domain']=='': - return False,"域名不能为空" - if data['port']=='': - return False,"端口不能为空" - if data['client_max_body_size']=='': - return False,"上传限制不能为空" - if data['path']=='': - data['path']="/www/wwwroot/" - paths=nginx['paths'] - try: - ttt1=data['domain'].split("\n") - if data['id'] and sqlite('web',model_intapp_soft_path).where("id",data['id']).count(): - # if types!='del': - # where="port="+str(data['port'])+" and id != "+str(data['id'])+" and (" #[('port','eq',data['port'])] - # for kk in ttt1: - # where=where+"domain like '"+kk+"%'"+" or " - # where=where[:-4]+")" - # ttt2=sqlite('web',model_intapp_soft_path).where(where).find() - # if ttt2: - # ttt2=ttt2['domain'].split("\n") - # for k in ttt2: - # for kk in ttt2: - # if k==kk: - # return False,k+"已在本服务器其他站点使用被使用" - domains=sqlite('web',model_intapp_soft_path).where("id",data['id']).field("only").find()['only'] - else: - data['id']='' - where="port="+data['port']+" and (" - for kk in ttt1: - where=where+"domain like '%"+kk+"%'"+" or " - where=where[:-4]+")" - domains=ttt1[0]+":"+str(data['port']) - data['only']=domains - ttt=sqlite('web',model_intapp_soft_path).where(where).find() - if ttt: - ttt=ttt['domain'].split("\n") - for k in ttt: - for kk in ttt1: - if k==kk: - return False,k+"已被使用" - ttt=data['domain'].split("\n") - server_name='' - for k in ttt: - server_name=str(server_name)+" "+str(k) - - if nginx['platform']=='Linux': - if data['webtpl']=='': - return False,"请选择配置文件模板" - filenames=nginx['title']+nginx['edition'] - servertpl=paths+filenames+'/conf/vhost/webtpl/'+data['webtpl'] - ssl_certificate="" - ssl_certificate_key="" - try: - ssl_certificate=data['ssl_certificate'] - ssl_certificate_key=data['ssl_certificate_key'] - except: - data['ssl_certificate']='' - data['ssl_certificate_key']='' - try: - data['header'] - except: - data['header']='' - try: - data['ssl'] - except: - data['ssl']='' - try: - data['rewrite'] - except: - data['rewrite']='' - if data['ssl']: - ssl=443 - if len(data['ssl_certificate'])>5 and len(data['ssl_certificate_key'])>5: - ssl_certificate=data['ssl_certificate'] - ssl_certificate_key=data['ssl_certificate_key'] - # print(ssl_certificate_key) - else: - key=paths+filenames+'/conf/vhost/rewrite/'+domains+".key" - pem=paths+filenames+'/conf/vhost/rewrite/'+domains+".pem" - file_set_content(key,data['key']) - file_set_content(pem,data['pem']) - ssl_certificate=paths+filenames+"/conf/vhost/rewrite/"+domains+".pem" - ssl_certificate_key=paths+filenames+"/conf/vhost/rewrite/"+domains+".key" - print(ssl_certificate) - else: - if os.path.isfile(paths+filenames+'/conf/vhost/rewrite/'+domains+".key") and os.path.isfile(paths+filenames+'/conf/vhost/rewrite/'+domains+".pem"): - sslttt1=file_get_content(paths+filenames+'/conf/vhost/rewrite/'+domains+".key") - sslttt2=file_get_content(paths+filenames+'/conf/vhost/rewrite/'+domains+".pem") - if len(sslttt1)>10 and len(sslttt2)>10: - ssl=443 - else: - ssl=False - else: - ssl=False - if not ssl_certificate or not ssl_certificate_key: - ssl='' - if 'php' in data['webtpl'] and len(data['rewrite'])>4:#php伪静态 - file_set_content(paths+filenames+"/conf/vhost/rewrite/"+domains,data['rewrite']) - elif not os.path.isfile(paths+filenames+"/conf/vhost/rewrite/"+domains): - file_set_content(paths+filenames+"/conf/vhost/rewrite/"+domains,'') - if data['webtpl']=='static' or data['webtpl']=='vue' or 'php' in data['webtpl']: - t=kcwTemplate(filename=servertpl) - text=t.render(client_max_body_size=data['client_max_body_size'],port=data['port'],ssl=ssl,ssl_certificate=ssl_certificate,ssl_certificate_key=ssl_certificate_key, - server_name=server_name,webpath=data['path'],rewrite=paths+filenames+"/conf/vhost/rewrite/"+domains,domains=domains,header=data['header']) - elif data['webtpl']=='balancing':#添加负载均衡 - balancing=data['balancing'] #负载均衡列表 - proxy_set_header=data['proxy_set_header'] #自定义转发请求头列表 - for k in data['balancing']: - if k['ip']=='' or k['port']=='': - return False,"请填写负载均衡ip和端口" - t=kcwTemplate(filename=servertpl) - text=t.render(client_max_body_size=data['client_max_body_size'],port=data['port'],ssl=ssl,balancing=balancing,proxy_set_header=proxy_set_header,ssl_certificate=ssl_certificate,ssl_certificate_key=ssl_certificate_key, - server_name=server_name,webpath=data['path'],rewrite=paths+filenames+"/conf/vhost/rewrite/"+domains,domains=domains,header=data['header']) - f=open(paths+filenames+"/conf/vhost/"+domains+'.conf','w',encoding="utf-8") - f.write(text) - f.close() - os.system("nginx -s reload") - if not os.path.exists(data['path']): - os.makedirs(data['path']) - f=open(data['path']+"/index.html",'w',encoding="utf-8") - f.write('网站创建成功

恭喜您!网站创建成功

') - f.close() - f=open(data['path']+"/index.php",'w',encoding="utf-8") - f.write("") - f.close() - try: - data['servers']=paths+filenames - except:pass - try: - del data['key'] - del data['pem'] - except:pass - del data['ssl'] - del data['rewrite'] - data['balancing'] =json_encode(data['balancing']) - data['proxy_set_header'] =json_encode(data['proxy_set_header']) - data['header'] =json_encode(data['header']) - if data['id']: - data['updtime']=addtime - data['status']=1 - try: - sqlite('web',model_intapp_soft_path).where("id",data['id']).update(data) - except: - pass - else: - pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - if len(strs) > 1: - return False,strs - else: - del data['id'] - data['addtime']=addtime - data['updtime']=addtime - sqlite('web',model_intapp_soft_path).insert(data) - data['id']=sqlite('web',model_intapp_soft_path).max("id") - except: - print(traceback.format_exc()) - file_set_content("server.log",traceback.format_exc()) - return False,"失败,检查参数是否有误" - else: - return True,data['id'] -def del_web(id=0,path=0): - #path=1 表示删除网站目录 ,linux和windows已完成 - "删除网站" - G.setadminlog="删除网站" - title=request.args.get("title") - if not id and title: - where="title = '"+title+"'" - else: - where="id='"+str(id)+"'" - nginx=sqlite('web',model_intapp_soft_path).where(where).find() - if not nginx: - return successjson(msg="不存在") - print(nginx) - filenames=nginx['servers'] - if get_sysinfo()['uname'][0]=='Linux': - if os.path.isfile(filenames+"/conf/vhost/"+nginx['only']+'.conf'): - os.remove(filenames+"/conf/vhost/"+nginx['only']+'.conf') - if os.path.isfile(filenames+"/conf/vhost/rewrite/"+nginx['only']): - os.remove(filenames+"/conf/vhost/rewrite/"+nginx['only']) - if os.path.isfile(filenames+"/logs/"+nginx['only']+".access.log"): - os.remove(filenames+"/logs/"+nginx['only']+".access.log") - if os.path.isfile(filenames+'/conf/vhost/rewrite/'+nginx['only']+".key"): - os.remove(filenames+'/conf/vhost/rewrite/'+nginx['only']+".key") - if os.path.isfile(filenames+'/conf/vhost/rewrite/'+nginx['only']+".pem"): - os.remove(filenames+'/conf/vhost/rewrite/'+nginx['only']+".pem") - pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - elif get_sysinfo()['uname'][0]=='Windows': - if os.path.isfile(filenames+"/conf/vhost/"+nginx['only']+'.conf'): - os.remove(filenames+"/conf/vhost/"+nginx['only']+'.conf') - if os.path.isfile(filenames+"/conf/vhost/rewrite/"+nginx['only']): - os.remove(filenames+"/conf/vhost/rewrite/"+nginx['only']) - if os.path.isfile(filenames+"/logs/"+nginx['only']+".access.log"): - os.remove(filenames+"/logs/"+nginx['only']+".access.log") - os.system("cd "+filenames+" & stop.bat") - time.sleep(3) - os.system("cd "+filenames+" & start.bat") - else: - return errorjson(msg="无法匹配系统") - if path=='1' and os.path.exists(nginx['path']): - shutil.rmtree(nginx['path']) - sqlite('web',model_intapp_soft_path).where(where).delete() - pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - if len(strs) > 1: - return errorjson(msg=strs) - return successjson() - -def getssl(id): - ar=sqlite('web',model_intapp_soft_path).where('id',id).find() - key=ar['servers']+'/conf/vhost/rewrite/'+ar['only']+".key" - pem=ar['servers']+'/conf/vhost/rewrite/'+ar['only']+".pem" - data={ - "key":file_get_content(key), - "pem":file_get_content(pem) - } - return successjson(data) -def getrewr(id): - "获取伪静态" - ar=sqlite('web',model_intapp_soft_path).where('id',id).find() - return successjson(file_get_content(ar['servers']+'/conf/vhost/rewrite/'+ar['only'])) -def getconfig(id,types='get'): - "获取配置文件" - ar=sqlite('web',model_intapp_soft_path).where('id',id).find() - if types=='get': - return successjson(file_get_content(ar['servers']+'/conf/vhost/'+ar['only']+".conf")) - elif types=='set': - data=request.get_json() - file_set_content(ar['servers']+'/conf/vhost/'+ar['only']+".conf",data['text']) - pi=subprocess.Popen('nginx -s reload',shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - if len(strs) > 1: - return errorjson(msg=strs) - return successjson() - - -def sslfolde(): - "Let's Encrypt证书夹" - paths="/etc/letsencrypt/live/" - if not os.path.exists(paths): - return errorjson(code=1,msg="Let's Encrypt证书夹不存在,在插件市场安装LetsEncrypt插件创建证书后再使用该功能") - try: - lis=os.listdir(paths) - except: - return errorjson(code=1,msg="无法打开"+str(paths)) - lists=[] - for files in lis: - types="folder" - config={} - if os.path.isfile(paths+"/"+files): - types="file" - else: - config=file_get_content(paths+"/"+files+"/config.conf") - if config: - config=json_decode(config) - zd={"name":files,"types":types,"config":config} - lists.append(zd) - data=return_list(lists,count=len(lis),pagenow=1,pagesize=len(lis)) - data['paths']=paths - "文件列表" - return successjson(data) -def ssltpl(): - "Let's Encrypt证书内容" - name=request.args.get("name") - paths="/etc/letsencrypt/live/"+name - chain=file_get_content(paths+"/chain.pem") - fullchain=file_get_content(paths+"/fullchain.pem") - privkey=file_get_content(paths+"/privkey.pem") - cert=file_get_content(paths+"/cert.pem") - data={ - "chain":chain, - "fullchain":fullchain, - "privkey":privkey, - "cert":cert - } - return successjson(data) - \ No newline at end of file diff --git a/app/intapp/controller/soft/page.py b/app/intapp/controller/soft/page.py deleted file mode 100644 index 9e87cb1..0000000 --- a/app/intapp/controller/soft/page.py +++ /dev/null @@ -1,34 +0,0 @@ -from .common import * -def home(): - if sysisphone(): - return response.tpl("../tplm/index/home") - else: - return response.tpl("index/home") -def pub(html): - if sysisphone(): - return response.tpl("../tplm/page/%s" % html) - else: - return response.tpl("page/%s" % html) -def s(fun,html): - id=request.args.get("id") - if sysisphone(): - lefttext=request.args.get('lefttext') - if not lefttext: - lefttext='应用' - lefturl=request.args.get('lefturl') - if not lefturl: - lefturl='myapp' - lefttype=request.args.get('lefttype') - if not lefttype: - lefttype='lefturl' - return response.tpl("../tplm/%s/%s" % (fun,html),id=id,lefttext=lefttext,lefturl=lefturl,lefttype=lefttype) - else: - return response.tpl("%s/%s" % (fun,html),id=id) -def soft(html): - id=request.args.get("id") - types=request.args.get("types") - data=sqlite("soft",model_intapp_soft_path).where("id",id).find() - if sysisphone(): - return response.tpl("../tplm/soft/%s" % html,id=id,data=data,types=types) - else: - return response.tpl("soft/%s" % html,id=id,data=data,types=types) \ No newline at end of file diff --git a/app/intapp/controller/soft/php.py b/app/intapp/controller/soft/php.py deleted file mode 100644 index d3e9798..0000000 --- a/app/intapp/controller/soft/php.py +++ /dev/null @@ -1,272 +0,0 @@ -from .common import * -def ini(id,is_upd=0): - "php.ini配置文件" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - if ar['platform']=='Linux': - filepath=paths+filenames+"/bin/php.ini" - elif ar['platform']=='Windows': - filepath=paths+filenames+"/php.ini" - else: - return errorjson(code=1,msg="不支持此时平台") - if is_upd: #修改配置 - G.setadminlog="修改配置ini" - data=request.get_json() - file_set_content(filepath,data['text']) - return successjson() - else: - data={ - 'ini':file_get_content(filepath), - 'php':ar - } - return successjson(data) -def www_conf(id,is_upd=0): - "www.conf配置文件" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - if ar['platform']=='Linux': - filepath=paths+filenames+"/etc/php-fpm.d/www.conf" - if 'php5.6' in filenames: - filepath=paths+filenames+"/etc/php-fpm.conf" - elif ar['platform']=='Windows': - filepath='' - else: - return errorjson(code=1,msg="不支持此时平台") - if is_upd: #修改配置 - G.setadminlog="修改配置www.conf" - data=request.get_json() - file_set_content(filepath,data['text']) - return successjson() - else: - data={ - 'www_conf':file_get_content(filepath), - 'php':ar - } - return successjson(data) -def phpfpm(id,is_upd=0): - "phpfpm配置信息" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - if ar['platform']=='Linux': - if not os.path.exists(paths+filenames+"/bin/conf"): - os.makedirs(paths+filenames+"/bin/conf") - filepath=paths+filenames+"/bin/conf/phpfpm.conf" - phpfpmpath=paths+filenames+"/etc/php-fpm.d/www.conf" - if 'php5.6' in filenames: - phpfpmpath=paths+filenames+"/etc/php-fpm.conf" - else: - filepath='' - phpfpmpath='' - if is_upd: #修改php-fpm配置信息 - data=request.get_json() - f = open(phpfpmpath) - con='' - while True: - line = f.readline() - if not line: - break - elif 'pm = ' in line and '=' in line: #运行描述 - line="pm = "+data['text']['pm']+"\n" - elif 'pm.max_children' in line and '=' in line:# 允许创建的最大子进程数 - line="pm.max_children = "+data['text']['max_children']+"\n" - elif 'pm.start_servers' in line and '=' in line:# 起始进程数(服务启动后初始进程数量) - line="pm.start_servers = "+data['text']['start_servers']+"\n" - elif 'pm.min_spare_servers' in line and '=' in line:# 起始进程数(服务启动后初始进程数量) - line="pm.min_spare_servers = "+data['text']['min_spare_servers']+"\n" - elif 'pm.max_spare_servers' in line and '=' in line:# 最大空闲进程数(当空闲进程达到此值时清理) - line="pm.max_spare_servers = "+data['text']['max_spare_servers']+"\n" - con=con+line - f.close() - f= open(phpfpmpath, "w") - f.write(con) - f.close() - file_set_content(filepath,json_encode(data['text'])) - return successjson() - else: - phpfpm=json_decode(file_get_content(filepath)) - if not phpfpm: - phpfpm='' - data={ - 'phpfpm':phpfpm, - 'php':ar - } - return successjson(data) -def base(id,is_upd=0): - "基本配置信息" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - if ar['platform']=='Linux': - if not os.path.exists(paths+filenames+"/bin/conf"): - os.makedirs(paths+filenames+"/bin/conf") - filepath=paths+filenames+"/bin/conf/base.ini" - phpinipath=paths+filenames+"/bin/php.ini" - elif ar['platform']=='Windows': - if not os.path.exists(paths+filenames+"/conf"): - os.makedirs(paths+filenames+"/conf") - filepath=paths+filenames+"/conf/base.ini" - phpinipath=paths+filenames+"/php.ini" - if is_upd: #修改基本配置信息 - #修改php.ini配置 - G.setadminlog="修改php.ini配置" - data=request.get_json() - f = open(phpinipath) - con='' - while True: - line = f.readline() - if not line: - break - elif 'max_execution_time' in line and '=' in line:#最大执行时间 - line="max_execution_time = "+data['text']['max_execution_time']+"\n" - elif 'max_input_time' in line and '=' in line:#最大输入时间 - line="max_input_time = "+data['text']['max_input_time']+"\n" - elif 'memory_limit' in line and '=' in line:#内存限制 - line="memory_limit = "+data['text']['memory_limit']+"M\n" - elif 'file_uploads' == line[0:12] and '=' in line:#是否允许文件上传 - line="file_uploads = "+data['text']['file_uploads']+"\n" - elif 'upload_max_filesize' in line and '=' in line:#上传大小限制 - line="upload_max_filesize = "+data['text']['upload_max_filesize']+"M\n" - elif 'max_file_uploads' in line and '=' in line:#上传数量限制 - line="max_file_uploads = "+data['text']['max_file_uploads']+"\n" - elif 'post_max_size' in line and '=' in line:#上传数量限制 - line="post_max_size = "+data['text']['post_max_size']+"M\n" - elif 'allow_url_fopen' in line and '=' in line: - line="allow_url_fopen = "+data['text']['allow_url_fopen']+"\n" - elif 'allow_url_include' in line and '=' in line: - line="allow_url_include = "+data['text']['allow_url_include']+"\n" - elif 'default_socket_timeout' in line and '=' in line: - line="default_socket_timeout = "+data['text']['default_socket_timeout']+"\n" - con=con+line - f.close() - f= open(phpinipath, "w") - f.write(con) - f.close() - file_set_content(filepath,json_encode(data['text'])) - # print(data['text']) - return successjson() - else: - base=json_decode(file_get_content(filepath)) - if not base: - base='' - data={ - 'base':base, - 'php':ar - } - return successjson(data) -def extenlist(id,is_upd=0): - "php扩展信息列表" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - lists=sqlite('php_exten',model_intapp_soft_php_exten_path).where('pid',id).select() - data={ - 'extenlist':lists, - 'php':ar - } - return successjson(data) -def log(id): - "待完善" - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - filename=ar['filename'] - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - if ar['platform']=='Linux': - filepath=paths+filenames+"" - elif ar['platform']=='Windows': - filepath=paths+filenames+"" - data={ - 'log':file_get_content(filepath), - 'php':ar - } - return successjson(data) - -def add_php_exten(): - "增加php扩展" - G.setadminlog="安装php扩展" - data=request.get_json() - data['addtime']=times() - data['updtime']=times() - sqlite('php_exten',model_intapp_soft_php_exten_path).insert(data) - return successjson() -def del_php_exten(id): - "删除php扩展" - G.setadminlog="删除php扩展" - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).delete() - return successjson() - -def installext(id): - is_del=False #是否删除成功 - "安装php扩展和下载扩展" - G.setadminlog="安装php扩展和下载扩展" - ar=sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).find() - if ar['status']==0: - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':1,'msg':''}) - Queues.insert(target=__installextqu,args=(ar,),title="安装php-"+ar['title']+"扩展") - elif ar['status']==4: - "卸载扩展" - paths=request.get_json()['paths'] - if get_sysinfo()['uname'][0]=='Linux': - if os.path.exists(paths): - - confile=paths+"bin/php.ini" - f= open(confile, "r") - con='' - while True: - line = f.readline() - if not line: - break - elif str(ar['title']) in line: - line="" - is_del=True - con=con+line - f.close() - f= open(confile, "w") - f.write(con) - f.close() - - # confile=paths+"bin/php.ini" - # f= open(confile, "r") - # con=f.read() - # f.close() - # con=con.replace("extension="+str(ar['title'])+".so\n","") - # f= open(confile, "w") - # f.write(con) - # f.close() - # if is_del: - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':0,'msg':''}) - if 'php7.0' in paths: - os.system("pkill php70-fpm && php70-fpm -c "+paths+"php7.0/etc/php.ini") - elif 'php7.1' in paths: - os.system("pkill php71-fpm && php71-fpm -c "+paths+"php7.1/etc/php.ini") - elif 'php7.2' in paths: - os.system("pkill php72-fpm && php72-fpm -c "+paths+"php7.2/etc/php.ini") - elif 'php7.3' in paths: - os.system("pkill php73-fpm && php73-fpm -c "+paths+"php7.3/etc/php.ini") - elif 'php7.4' in paths: - os.system("pkill php74-fpm && php74-fpm -c "+paths+"php7.4/etc/php.ini") - # else: - # return errorjson(code=1,msg='卸载失败') - else: - return errorjson(code=1,msg='php文件夹错误') - return successjson() -def get_exten(id): - return successjson(sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).find()) -def __installextqu(ar): - "安装php扩展" - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':3,'msg':''}) - try: - cmd="wget "+config.domain['kcwebfile']+"/"+ar['filename'] - # os.system(cmd) - print(cmd) - pi=subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) - ars=pi.stdout.read().decode() - ars=ars.split("\n") - strs=ars[len(ars)-2] - if 'success' in strs: - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':4,'msg':''}) - else: - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':0,'msg':'安装失败'}) - # sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':4,'msg':''}) - except Exception as e: - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',ar['id']).update({'status':0,'msg':'安装失败'+str(e)}) \ No newline at end of file diff --git a/app/intapp/controller/soft/redis.py b/app/intapp/controller/soft/redis.py deleted file mode 100644 index 1464e6a..0000000 --- a/app/intapp/controller/soft/redis.py +++ /dev/null @@ -1,71 +0,0 @@ -from .common import * -def conf(id,is_upd=0): - "redis配置文件信息" - is_upd=int(is_upd) - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - if ar['platform']=='Linux': - filepath=paths+filenames+"/redis.conf" - else: - return errorjson(code=1,msg="不支持此时平台") - if is_upd: #修改配置 - data=request.get_json() - if not data['text']: - return errorjson(code=1,msg='不允许清空配置文件') - file_set_content(filepath,data['text']) - return successjson() - else: - data=file_get_content(filepath) - # print(filepath) - return successjson(data) -def base(id,is_upd=0): - "redis配置文件信息" - is_upd=int(is_upd) - ar=sqlite('soft',model_intapp_soft_path).where('id',id).find() - paths=ar['paths'] - filenames=ar['title']+ar['edition'] - - if ar['platform']=='Linux': - filepath=paths+filenames+"/redis.conf" - jsonpath=paths+filenames+"/redis.json" - else: - return errorjson(code=1,msg="不支持此时平台") - if is_upd: #修改配置 - G.setadminlog="修改redis配置" - data=request.get_json() - f = open(filepath) - con='' - while True: - line = f.readline() - if not line: - break - elif 'bind ' in line and '\n' in line and '#' not in line: - line="bind "+data['bind']+"\n" - elif 'port ' in line and '\n' in line and '#' not in line: - line="port "+data['port']+"\n" - elif 'timeout ' in line and '\n' in line and '#' not in line: - line="timeout "+data['timeout']+"\n" - elif 'maxclients ' in line and '\n' in line: - line="maxclients "+data['maxclients']+"\n" - elif 'databases ' in line and '\n' in line and '#' not in line: - line="databases "+data['databases']+"\n" - elif 'requirepass ' in line and '\n' in line: - if data['requirepass']: - line="requirepass "+data['requirepass']+"\n" - else: - line="# requirepass "+data['requirepass']+"\n" - elif 'maxmemory ' in line and '\n' in line and len(line)<20: - line="maxmemory "+data['maxmemory']+"\n" - con=con+line - f.close() - f= open(filepath, "w") - f.write(con) - f.close() - file_set_content(jsonpath,json_encode(data)) - return successjson() - else: - v=file_get_content(jsonpath) - data=json_decode(v) - data['ar']=ar - return successjson(data) \ No newline at end of file diff --git a/app/intapp/controller/soft/role.txt b/app/intapp/controller/soft/role.txt deleted file mode 100644 index 1da7c1d..0000000 --- a/app/intapp/controller/soft/role.txt +++ /dev/null @@ -1,44 +0,0 @@ -#以下是该插件的路由,index容器会自动把以下路由加入到权限管理中 该文件必须使用utf-8编码 -软件页面,/intapp/soft/index/index -软件信息,/intapp/soft/index/gettitle -软件列表,/intapp/soft/index/softlist -更新软件列表,/intapp/soft/index/updatesoftlist -软件状态描述,/intapp/soft/index/getstatus -安装软件,/intapp/soft/index/insert -启动软件,/intapp/soft/index/start -停止软件,/intapp/soft/index/stop -卸载软件,/intapp/soft/index/uninstall -gitssh公钥,/intapp/soft/index/gitssh -软件设置页面,/intapp/soft/page/soft - -frp服务端内容,/intapp/soft/frp/get_server -frp运行状态,/intapp/soft/frp/run_status -frp重启,/intapp/soft/frp/restart -frp停止,/intapp/soft/frp/stop -修改frp服务端配置,/intapp/soft/frp/upd_server -frp客户端内容,/intapp/soft/frp/get_client -修改frp客户端配置,/intapp/soft/frp/upd_client - -mongodb管理,/intapp/soft/mongodb - -获取mysql配置,/intapp/soft/mysql/get_data -修改mysql配置,/intapp/soft/mysql/upd_my -修改mysql密码,/intapp/soft/mysql/upd_data -备份mysql,/intapp/soft/mysql/backups - -nginx网站管理,/intapp/soft/page/s -修改nginx配置,/intapp/soft/nginx/index -nginx伪静态模板,/intapp/soft/nginx/anphp -nginx网站信息,/intapp/soft/nginx/webdescribesfind -nginx网站列表,/intapp/soft/nginx/weblist -添加更新nginx网站,/intapp/soft/nginx/add_web -删除nginx网站,/intapp/soft/nginx/del_web -获取ssl,/intapp/soft/nginx/getssl -获取伪静态内容,/intapp/soft/nginx/getrewr -获取配置文件,/intapp/soft/nginx/getconfig -证书夹,/intapp/soft/nginx/sslfolde -证书内容,/intapp/soft/nginx/ssltpl - -php管理,/intapp/soft/php - -redis管理,/intapp/soft/redis diff --git a/app/intapp/controller/soft/tpl/index/home.html b/app/intapp/controller/soft/tpl/index/home.html deleted file mode 100644 index cc19803..0000000 --- a/app/intapp/controller/soft/tpl/index/home.html +++ /dev/null @@ -1,430 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
-
- - - 搜索 - - - 更新软件列表 - -
-
- - % if config.app['appmode']=='develop': - - - - % endif - - - - - - - - - - - - - - - - - - -
-
- - -
- - - - - - - - - - - - - - - 如:/usr/local/php/ - - - - - - - - - - 注:需要在后端接口上配置wget文件地址 - - - - Linux - Windows - - - - - - -
- - - diff --git a/app/intapp/controller/soft/tpl/index/web.html b/app/intapp/controller/soft/tpl/index/web.html deleted file mode 100644 index 7d62981..0000000 --- a/app/intapp/controller/soft/tpl/index/web.html +++ /dev/null @@ -1,582 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
-
-    - - - 搜索 - 添加网站 - - - 下载数据 - - 上传intapp_soft.zip - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
域名
端口 - 上传限制:MB
网站名
配置文件模板 - - - - -
备注
网站目录 - - -
-
- - - - - - - -
- - - - - - - 如:Access-Control-Allow-Origin * - 如:403 /403.html - - -
- 自定义配置:自定义响应或自定义错误页面 - -
- -
-
- - - - - - - - -
- - - - - - - - - -   - - -
- nginx负载均衡是一个代理均衡转发器 - -
- -
- - 取 消 - 修改添加 - -
- - -
-
- - -
-
- 您已配置Let's证书


- ssl_certificate :{{admin.ssl_certificate}}

- ssl_certificate_key :{{admin.ssl_certificate_key}}

- 使用自有证书 -
-
-
- 密钥(KEY) - -
-
- 证书(PEM格式) - -
- 确定 -
-
-
- - -
- - - - - -
- 保存
- 选择伪静态模板就可以了,修改了记得要保存哦!重启nginx生效 -
- -
- - 确定 -
-
- -
- - - - - - - -
支持域名有效期
- - {{item1.domain}}     - - - - {{time_date(item.config.createtime+7776000,true)}} - - - - 使用 - -
-
-
-
- - - diff --git a/app/intapp/controller/soft/tpl/soft/frp.html b/app/intapp/controller/soft/tpl/soft/frp.html deleted file mode 100644 index edfcb44..0000000 --- a/app/intapp/controller/soft/tpl/soft/frp.html +++ /dev/null @@ -1,250 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
- - - - - 重启 - 停止 - - 保存 - - - - - - -
- 重启 - 停止 - - - - 这是服端监听的地址 - - - - 这是服端监听的端口 - - - - 这是upd监听的端口 - - - - 这是kcp监听的端口 - - - - 这是http监听的端口 - - - - 这是https监听的端口 - - - - 这是dashboard监听的ip地址 - - - - 这是dashboard监听的端口 - - - - 这是dashboard监听的用户名 - - - - 这是dashboard监听的密码 - - - - 这是frp的验证机制 - - - - 这是frp的验证串的有效时间 - - - - - - - - 日志保持多少天 - - - - - - - - 白名单端口 - - - - 最大值进程数 - - - - - - - - - - - - - - - 保存 - - -
- -
- - - 保存 - -
-
-
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/git.html b/app/intapp/controller/soft/tpl/soft/git.html deleted file mode 100644 index ce87f2d..0000000 --- a/app/intapp/controller/soft/tpl/soft/git.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
-
- -
- 您可以使用root身份执行以下命令生成ssh密钥

- -
-
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/kodexplorer.html b/app/intapp/controller/soft/tpl/soft/kodexplorer.html deleted file mode 100644 index 6f38ff4..0000000 --- a/app/intapp/controller/soft/tpl/soft/kodexplorer.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - -
-
-
- - - - - - - - - - - - 添加 - -
-
-
- - - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/mongodb.html b/app/intapp/controller/soft/tpl/soft/mongodb.html deleted file mode 100644 index ebdbc92..0000000 --- a/app/intapp/controller/soft/tpl/soft/mongodb.html +++ /dev/null @@ -1,436 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
- - - -
- -

可以在终端中执行以下命令创建可以 -

- WORK_DIR=/data/mongodb
- mkdir -p $WORK_DIR/key/
- cd $WORK_DIR/key/
- openssl rand -base64 756 > mongo.key
- chmod 600 mongo.key
-
-

- 保存 -
-
- -
- config服务 (注:这是一个config服务) - - - - - - -
- 通常生产环境每台机器应该只有一个,您可以在其他机器上开启config服务后手动添加到副本集中
- -
- 运行中 - 停止服务 - 重启服务 -
-
- 已停止 - 启动服务 -
-
- 待初始化 - 初始化 -
-

-
- 副本集初始化(如果需要,生产环境应该是内网ip而不是127.0.0.1)
-
- -
-增加副本集示例 -
-mongo --port {{data.configs.server[0]['port']}}
-use admin
-rs.add({_id:1,host:'{{data.get_local_ip}}:27002',priority:2})#增加主机 priority:优先级
-
-删除副本集示例 -
-mongo --port {{data.configs.server[0]['port']}}
-use admin
-rs.remove('{{data.get_local_ip}}:27002')
-
-
- -
-
- -
- configdb: -
示例:configdb = configs/192.168.1.101:27001,192.168.1.102:27001,192.168.1.103:27001,则无法扩展外部服务器
- 上述ip和端口是已经启动的配置服务,可以是其他机器上的mongodb配置服务 -
- 路由服务 (注:这是一个路由服务) - - - - - - -
- -
-
- 运行中 - 停止服务 - 重启服务 -
-
- 已停止 - 启动服务 -
-
- 待初始化 - 初始化 -
-
-
- 初始化用户
-
- -
- 在路由中添加分片,如下示例
-
-mongo --port {{data.mongos.server[0]['port']}}
-use admin
-db.auth('admin','admin')
-sh.addShard("shard1/192.168.1.101:29001,192.168.1.102:29001") #shard1是分片集群id
-sh.status()
-
-
-
-
- -
-
- 分片服务名{{indexs+1}}: - - - - - - - -
- 通常生产环境每台机器应该只有一个,您可以在其他机器上开启分片服务后手动添加到副本集中
- -
- 运行中 - 停止服务 - 重启服务 -
-
- 已停止 - 启动服务 -
-
- 待初始化 - 初始化 -
-

-
- 副本集初始化(生产环境应该是内网ip而不是127.0.0.1)
- -
-
- -
-
-
- - - -
- - - - - - - - - - - - - -
绑定ip端口服务目录
- - 运行中 - 停止 - - - 已停止 - 启动 - - -
-
- - 保存 -
- -
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/mysql.html b/app/intapp/controller/soft/tpl/soft/mysql.html deleted file mode 100644 index e31a335..0000000 --- a/app/intapp/controller/soft/tpl/soft/mysql.html +++ /dev/null @@ -1,257 +0,0 @@ - - - - - - - kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - -
- - - - 8.0版本不支持可视化修改 - - - - 建议与mysql安装目录分开 - - - - port 监听器端口 - - - - max_connections 最大连接数 - - -
- max_allowed_packet 最大接受数据的包大小 -
- -
- expire_logs_days 日志保留时间(天) -
- -
- query_cache_limit 指定单个查询可以使用的缓冲区的大小 -
- -
- query_cache_size 查询的缓存大小设置 -
- -
- query_cache_type 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 -
- -
- wait_timeout 超时等待时间,单位秒,即一个connection在若干秒内无响应 -
- -
- thread_cache_size 用于缓存空闲的线程 -
- -
- key_buffer_size 用于指定索引缓冲区的大小 -
-
-
- 保存 - 加入开机启动 -
- -
- -
-                        
-                    
-
- 保存 -
-
-
-
-
-
- - - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/nginx.html b/app/intapp/controller/soft/tpl/soft/nginx.html deleted file mode 100644 index 1417261..0000000 --- a/app/intapp/controller/soft/tpl/soft/nginx.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - - - -
-                    
-                
-
- 保存 - 加入开机启动 - 该配置文件只对该网站有效,修改后重启nginx生效 -
-
- -
- -
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/php.html b/app/intapp/controller/soft/tpl/soft/php.html deleted file mode 100644 index 8085943..0000000 --- a/app/intapp/controller/soft/tpl/soft/php.html +++ /dev/null @@ -1,415 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - - - - - - - MB - - - 单个请求上传的文件的最大数量 - - - 秒 - - - 秒 - - - MB - - - MB - - - - - - 是否允许将url(如http://或 ftp://)作为文件处理。 - - - - - - 是否允许include/require以文件形式打开url(如http://或 ftp://)。 - - - - 基于套接字的流的默认超时(秒) - - - 保存 -
-
- -
- - - - - - - - - - 允许创建的最大子进程数 - - - - 起始进程数(服务启动后初始进程数量) - - - - 最小空闲进程数(清理空闲进程后的保留数量) - - - - 最大空闲进程数(当空闲进程达到此值时清理) - - - 保存 - 加入开机启动 -
-
- -
- % if config.app['appmode']=='develop': - - % endif - - - - - - - - -
名称说明状态操作
{{item.title}}{{item.describes}} - % if config.app['appmode']=='develop': - {{item.filename}} - % endif - - - - - - 安装 - - - 等待下载 - - - 正在下载 - - - 正在安装 - - - 卸载 - - - 正在卸载... - - % if config.app['appmode']=='develop': - 删除 - % endif -
-
-
- - - - -
-                
-            
- 保存 - 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
-
- - - -
-                
-            
- 保存 - 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
-
-
- - - - - - - - - - - - - - - - - - - 添加 - -
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/phpmyadmin.html b/app/intapp/controller/soft/tpl/soft/phpmyadmin.html deleted file mode 100644 index 053916a..0000000 --- a/app/intapp/controller/soft/tpl/soft/phpmyadmin.html +++ /dev/null @@ -1,90 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - -
-
-
- - - - - - - - - - - - 添加 - -
-
-
- - - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tpl/soft/redis.html b/app/intapp/controller/soft/tpl/soft/redis.html deleted file mode 100644 index 4df6dbd..0000000 --- a/app/intapp/controller/soft/tpl/soft/redis.html +++ /dev/null @@ -1,182 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- - - 绑定IP - - - 端口 - - - 空闲连接超时时间,0表示不断开 - - - 最大连接数 - - - 数据库数量 - - - redis密码,留空代表没有设置密码 - - - MB,最大使用内存,0表示不限制 - - - 保存 - 加入开机启动 -
-
- - - - -
-                
-            
- 保存 - 修改后重启redis生效
-
-
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/index/home.html b/app/intapp/controller/soft/tplm/index/home.html deleted file mode 100644 index 361a9fb..0000000 --- a/app/intapp/controller/soft/tplm/index/home.html +++ /dev/null @@ -1,297 +0,0 @@ - - - - -kcweb云管 - - - - - - - - - - - - - - - - - - -
-
- - - -
-
- -
-
- -
- - -
-
-
-
-
{{item.title}}{{item.edition}}
-
{{item.describes}}
-
-
-
位置:{{item.paths}}{{item.title}}{{item.edition}}
-
- -
-
-
- 待安装 - 等待中 - 下载中 - 安装中 - 卸载中 - 正在启动 - 正在停止服务 - - - - 已停止 - 启动 - - - - 客户端 - 客户端 - 服务端 - 服务端 - - - - - - - 运行中 - 停止 - 重启 - - - -
-
-
更新于:{{time_date(item.updtime)}}
-
-
-
-
- -
-
- 加载中... -
-
- 下一页 - 我已到底了 -
-
-
-
- - - diff --git a/app/intapp/controller/soft/tplm/index/web.html b/app/intapp/controller/soft/tplm/index/web.html deleted file mode 100644 index a38c9cf..0000000 --- a/app/intapp/controller/soft/tplm/index/web.html +++ /dev/null @@ -1,395 +0,0 @@ - - - - -kcweb云管 - - - - - - - - - - - - - - - - - - -
-
- - - -
-
- -
-
- -
- - -
-
-
-
-
{{item.title}}
-
运行在负载均衡代理转发器中
-
{{item.describes}}
- php伪静态配置 -
-
- - 运行中 - - - 已停止 - -
-
-
-
- {{item1}} -
-
-
{{time_date(item.updtime)}}
-
-
-
-
- -
-
- 加载中... -
-
- 下一页 - 暂无数据 - 我已到底了 -
-
- -
- - - - - - - - - - - - - - - - - - - - - -
- -
-
- -
-
- -
-
- 添加响应 - 自定义配置:自定义响应或自定义错误页面 -
- -
- -
-
- -
-
- - -
-
- -
-
- 添加负载均衡信息 - nginx负载均衡是一个代理均衡转发器 -
-
- 修改 - 添加 -
-
-
-
- -
- Let's Encrypt证书夹 -
-
- 您已配置Let's证书
- ssl_certificate :{{admin.ssl_certificate}}
- ssl_certificate_key :{{admin.ssl_certificate_key}}
-
-
- - 保存 - - - - - -
fewaf
-
- -
- -
-
-
- - - diff --git a/app/intapp/controller/soft/tplm/soft/frp.html b/app/intapp/controller/soft/tplm/soft/frp.html deleted file mode 100644 index c137b73..0000000 --- a/app/intapp/controller/soft/tplm/soft/frp.html +++ /dev/null @@ -1,250 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
- - - - - 重启 - 停止 - - 保存 - - - - - - -
- 重启 - 停止 - - - - 这是服端监听的地址 - - - - 这是服端监听的端口 - - - - 这是upd监听的端口 - - - - 这是kcp监听的端口 - - - - 这是http监听的端口 - - - - 这是https监听的端口 - - - - 这是dashboard监听的ip地址 - - - - 这是dashboard监听的端口 - - - - 这是dashboard监听的用户名 - - - - 这是dashboard监听的密码 - - - - 这是frp的验证机制 - - - - 这是frp的验证串的有效时间 - - - - - - - - 日志保持多少天 - - - - - - - - 白名单端口 - - - - 最大值进程数 - - - - - - - - - - - - - - - 保存 - - -
- -
- - - 保存 - -
-
-
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/git.html b/app/intapp/controller/soft/tplm/soft/git.html deleted file mode 100644 index ce87f2d..0000000 --- a/app/intapp/controller/soft/tplm/soft/git.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
-
- -
- 您可以使用root身份执行以下命令生成ssh密钥

- -
-
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/kodexplorer.html b/app/intapp/controller/soft/tplm/soft/kodexplorer.html deleted file mode 100644 index 6f38ff4..0000000 --- a/app/intapp/controller/soft/tplm/soft/kodexplorer.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - -
-
-
- - - - - - - - - - - - 添加 - -
-
-
- - - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/mongodb.html b/app/intapp/controller/soft/tplm/soft/mongodb.html deleted file mode 100644 index 417da13..0000000 --- a/app/intapp/controller/soft/tplm/soft/mongodb.html +++ /dev/null @@ -1,436 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
- - - -
- -

可以在终端中执行以下命令创建可以 -

- WORK_DIR=/data/mongodb
- mkdir -p $WORK_DIR/key/
- cd $WORK_DIR/key/
- openssl rand -base64 756 > mongo.key
- chmod 600 mongo.key
-
-

- 保存 -
-
- -
- config服务 (注:这是一个config服务) - - - - - - -
- 通常生产环境每台机器应该只有一个,您可以在其他机器上开启config服务后手动添加到副本集中
- -
- 运行中 - 停止服务 - 重启服务 -
-
- 已停止 - 启动服务 -
-
- 待初始化 - 初始化 -
-

-
- 副本集初始化(如果需要,生产环境应该是内网ip而不是127.0.0.1)
-
- -
-增加副本集示例 -
-mongo --port {{data.configs.server[0]['port']}}
-use admin
-rs.add({_id:1,host:'{{data.get_local_ip}}:27002',priority:2})#增加主机 priority:优先级
-
-删除副本集示例 -
-mongo --port {{data.configs.server[0]['port']}}
-use admin
-rs.remove('{{data.get_local_ip}}:27002')
-
-
- -
-
- -
- configdb: -
示例:configdb = configs/192.168.1.101:27001,192.168.1.102:27001,192.168.1.103:27001,则无法扩展外部服务器
- 上述ip和端口是已经启动的配置服务,可以是其他机器上的mongodb配置服务 -
- 路由服务 (注:这是一个路由服务) - - - - - - -
- -
-
- 运行中 - 停止服务 - 重启服务 -
-
- 已停止 - 启动服务 -
-
- 待初始化 - 初始化 -
-
-
- 初始化用户
-
- -
- 在路由中添加分片,如下示例
-
-mongo --port {{data.mongos.server[0]['port']}}
-use admin
-db.auth('admin','admin')
-sh.addShard("shard1/192.168.1.101:29001,192.168.1.102:29001") #shard1是分片集群id
-sh.status()
-
-
-
-
- -
-
- 分片服务名{{indexs+1}}: - - - - - - - -
- 通常生产环境每台机器应该只有一个,您可以在其他机器上开启分片服务后手动添加到副本集中
- -
- 运行中 - 停止服务 - 重启服务 -
-
- 已停止 - 启动服务 -
-
- 待初始化 - 初始化 -
-

-
- 副本集初始化(生产环境应该是内网ip而不是127.0.0.1)
- -
-
- -
-
-
- - - -
- - - - - - - - - - - - - -
绑定ip端口服务目录
- - 运行中 - 停止 - - - 已停止 - 启动 - - -
-
- - 保存 -
- -
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/mysql.html b/app/intapp/controller/soft/tplm/soft/mysql.html deleted file mode 100644 index 3603e82..0000000 --- a/app/intapp/controller/soft/tplm/soft/mysql.html +++ /dev/null @@ -1,203 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - -
- - - - - - - 建议与mysql安装目录分开 - - - - port 监听器端口 - - - - max_connections 最大连接数 - - -
- max_allowed_packet 最大接受数据的包大小 -
- -
- expire_logs_days 日志保留时间(天) -
- -
- query_cache_limit 指定单个查询可以使用的缓冲区的大小 -
- -
- query_cache_size 查询的缓存大小设置 -
- -
- query_cache_type 设置成0,表示禁用缓存;设置成1,表示缓存所有结果;设置成2,表示只缓存在select语句中通过SQL_CACHE指定需要缓存的查询 -
- -
- wait_timeout 超时等待时间,单位秒,即一个connection在若干秒内无响应 -
- -
- thread_cache_size 用于缓存空闲的线程 -
- -
- key_buffer_size 用于指定索引缓冲区的大小 -
-
-
- 保存 - 加入开机启动 -
- -
- -
-                        
-                    
-
- 保存 -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/nginx.html b/app/intapp/controller/soft/tplm/soft/nginx.html deleted file mode 100644 index 1417261..0000000 --- a/app/intapp/controller/soft/tplm/soft/nginx.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - - - -
-                    
-                
-
- 保存 - 加入开机启动 - 该配置文件只对该网站有效,修改后重启nginx生效 -
-
- -
- -
-
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/php.html b/app/intapp/controller/soft/tplm/soft/php.html deleted file mode 100644 index 8085943..0000000 --- a/app/intapp/controller/soft/tplm/soft/php.html +++ /dev/null @@ -1,415 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - - - - - - - MB - - - 单个请求上传的文件的最大数量 - - - 秒 - - - 秒 - - - MB - - - MB - - - - - - 是否允许将url(如http://或 ftp://)作为文件处理。 - - - - - - 是否允许include/require以文件形式打开url(如http://或 ftp://)。 - - - - 基于套接字的流的默认超时(秒) - - - 保存 -
-
- -
- - - - - - - - - - 允许创建的最大子进程数 - - - - 起始进程数(服务启动后初始进程数量) - - - - 最小空闲进程数(清理空闲进程后的保留数量) - - - - 最大空闲进程数(当空闲进程达到此值时清理) - - - 保存 - 加入开机启动 -
-
- -
- % if config.app['appmode']=='develop': - - % endif - - - - - - - - -
名称说明状态操作
{{item.title}}{{item.describes}} - % if config.app['appmode']=='develop': - {{item.filename}} - % endif - - - - - - 安装 - - - 等待下载 - - - 正在下载 - - - 正在安装 - - - 卸载 - - - 正在卸载... - - % if config.app['appmode']=='develop': - 删除 - % endif -
-
-
- - - - -
-                
-            
- 保存 - 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
-
- - - -
-                
-            
- 保存 - 该配置文件只对{{data.php.title}}有效,修改后重启{{data.php.title}}生效
-
-
- - - - - - - - - - - - - - - - - - - 添加 - -
- - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/phpmyadmin.html b/app/intapp/controller/soft/tplm/soft/phpmyadmin.html deleted file mode 100644 index 053916a..0000000 --- a/app/intapp/controller/soft/tplm/soft/phpmyadmin.html +++ /dev/null @@ -1,90 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - -
-
-
- - - - - - - - - - - - 添加 - -
-
-
- - - - \ No newline at end of file diff --git a/app/intapp/controller/soft/tplm/soft/redis.html b/app/intapp/controller/soft/tplm/soft/redis.html deleted file mode 100644 index 4df6dbd..0000000 --- a/app/intapp/controller/soft/tplm/soft/redis.html +++ /dev/null @@ -1,182 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- - - 绑定IP - - - 端口 - - - 空闲连接超时时间,0表示不断开 - - - 最大连接数 - - - 数据库数量 - - - redis密码,留空代表没有设置密码 - - - MB,最大使用内存,0表示不限制 - - - 保存 - 加入开机启动 -
-
- - - - -
-                
-            
- 保存 - 修改后重启redis生效
-
-
-
- - - \ No newline at end of file -- Gitee From 8961a529857a64a098639d3857fe536f094e03cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Wed, 26 May 2021 06:43:23 +0800 Subject: [PATCH 12/19] k --- app/intapp/controller/index/admin.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/intapp/controller/index/admin.py b/app/intapp/controller/index/admin.py index ca8a0df..18143db 100644 --- a/app/intapp/controller/index/admin.py +++ b/app/intapp/controller/index/admin.py @@ -10,16 +10,19 @@ def setadminpwd(): else: return successjson({"username":username,"password":password}) def index(): + G.setadminlog="管理员入口" if sysisphone(): return response.tpl("../tplm/admin/index") else: return response.tpl() def admin(): + G.setadminlog="管理员页面" if sysisphone(): return response.tpl("../tplm/admin/admin") else: return response.tpl() def role(): + G.setadminlog="权限页面" if sysisphone(): return response.tpl("../tplm/admin/role") else: @@ -30,13 +33,13 @@ def adminlog(): else: return response.tpl() def logdeta(id): - "日志明细" + G.setadminlog="日志明细" 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']) data['dataparamarr']=json_decode(data['dataparam']) return successjson(data) def loglist(): - "日志列表" + G.setadminlog="日志列表" where="1=1" kw=request.args.get('kw') types=request.args.get('types') @@ -60,7 +63,6 @@ def loglist(): data=return_list(lists,count,pagenow,pagesize) return successjson(data) def deletelog(id=0): - "删除日志" G.setadminlog="删除日志" if id: sqlite("admin_log",model_app_path).where('id',id).delete() @@ -74,7 +76,7 @@ def deletelog(id=0): else: return successjson() def getpluglist(modular="intapp"): - "本地插件列表" + G.setadminlog="本地插件列表" path="app/"+modular+"/controller/" lis=os.listdir(path) lists=[] -- Gitee From 496010d4c259c982864c5bdb9215eb7557dd5bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Wed, 26 May 2021 06:54:15 +0800 Subject: [PATCH 13/19] k --- app/common/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/model.py b/app/common/model.py index 268efec..c042775 100644 --- a/app/common/model.py +++ b/app/common/model.py @@ -25,7 +25,7 @@ try: except: model_app_role=model_app_role() model_app_role.create_table() - sqlite("role",model_app_path).insert({"icon":"","title":"开拓者","describes":"该角色具备了所有的权限,甚至可以毁灭整个系统","types":"system","roleroute":"[]","updtime":times(),"addtime":times()}) + sqlite("role",model_app_path).insert({"icon":"","admin_id":0,"title":"开拓者","describes":"该角色具备了所有的权限,甚至可以毁灭整个系统","types":"system","roleroute":"[]","updtime":times(),"addtime":times()}) class model_app_admin(modelsqliteintapp): "管理员" table="admin" -- Gitee From ad34291e1a860ac15fcd4c35cb5dcdacbcc3670c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Thu, 10 Jun 2021 18:38:49 +0800 Subject: [PATCH 14/19] k --- app/intapp/controller/index/admin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/intapp/controller/index/admin.py b/app/intapp/controller/index/admin.py index 18143db..e1dcb27 100644 --- a/app/intapp/controller/index/admin.py +++ b/app/intapp/controller/index/admin.py @@ -146,6 +146,8 @@ def insert(): G.setadminlog="添加管理员" try: data=request.get_json() + if sqlite("admin",model_app_path).where("phone",data['phone']).count(): + return return errorjson(msg="该手机已添加") if not data['username'] or not data['password']: return errorjson(msg="请输入用户名或密码") data.update(logintime=times(),addtime=times()) -- Gitee From b120cc3e742cb65db385e6a23ae3b0727c7d19bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Thu, 10 Jun 2021 19:12:11 +0800 Subject: [PATCH 15/19] k --- app/intapp/controller/index/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/intapp/controller/index/admin.py b/app/intapp/controller/index/admin.py index e1dcb27..778be87 100644 --- a/app/intapp/controller/index/admin.py +++ b/app/intapp/controller/index/admin.py @@ -147,7 +147,7 @@ def insert(): try: data=request.get_json() if sqlite("admin",model_app_path).where("phone",data['phone']).count(): - return return errorjson(msg="该手机已添加") + return errorjson(msg="该手机已添加") if not data['username'] or not data['password']: return errorjson(msg="请输入用户名或密码") data.update(logintime=times(),addtime=times()) -- Gitee From 1b083a8b07a10f5cd52e61a09975f5cee3b03d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Thu, 24 Jun 2021 00:57:21 +0800 Subject: [PATCH 16/19] k --- app/intapp/controller/index/admin.py | 48 +++++++++++++++---- .../controller/index/tpl/admin/admin.html | 12 +++-- .../controller/index/tpl/admin/role.html | 14 ++++-- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/app/intapp/controller/index/admin.py b/app/intapp/controller/index/admin.py index 778be87..4b9240c 100644 --- a/app/intapp/controller/index/admin.py +++ b/app/intapp/controller/index/admin.py @@ -222,20 +222,22 @@ def setmypwd(): return errorjson(msg="设置失败") else: return successjson() -def getrolelist(id=0): +def getrolelist(id=0,roleroute=1): "获取角色" + id=int(id) + roleroute=int(roleroute) if id: return successjson(sqlite("role",model_app_path).find(id)) if G.userinfo['role']['id']==1: where='1=1' else: - where="id="+str(G.userinfo['role']['id'])+" or admin_id="+str(G.userinfo['id']) + where="t1.id="+str(G.userinfo['role']['id'])+" or t1.admin_id="+str(G.userinfo['id']) kw=request.args.get('kw') pagenow=request.args.get('pagenow') pagesize=request.args.get('pagesize') if kw: # where=[("title","like","%"+str(kw)+"%"),'and',('admin_id','eq',G.userinfo['id'])] - where+=" and title like '%"+str(kw)+"%'" + where+=" and t1.title like '%"+str(kw)+"%'" if not pagenow: pagenow=1 else: @@ -244,10 +246,14 @@ def getrolelist(id=0): pagesize=10 else: pagesize=int(pagesize) - lists=sqlite("role",model_app_path).where(where).page(pagenow,pagesize).select() - for k in lists: - k['roleroute']=json_decode(k['roleroute']) - count=sqlite("role",model_app_path).where(where).count() + if roleroute: + lists=sqlite("role t1",model_app_path).join("admin t2","t1.admin_id=t2.id","left").field("t1.*,t2.name").page(pagenow,pagesize).select() + else: + lists=sqlite("role t1",model_app_path).join("admin t2","t1.admin_id=t2.id","left").field("t1.id,t1.admin_id,t1.icon,t1.title,t1.describes,t1.types,t1.updtime,t1.addtime,t2.name").where(where).select() + if roleroute: + for k in lists: + k['roleroute']=json_decode(k['roleroute']) + count=sqlite("role t1",model_app_path).where(where).count() data=return_list(lists,count,pagenow,pagesize) return successjson(data) def insertrole(): @@ -256,16 +262,42 @@ def insertrole(): data=request.get_json() data['admin_id']=G.userinfo['id'] data.update(updtime=times(),addtime=times()) + data['roleroute']=list(set(data['roleroute'])) data['roleroute']=json_encode(data['roleroute']) sqlite("role",model_app_path).insert(data) except: return errorjson(msg="失败") else: return successjson() +# def aa(): +# a=[1,2,3,4] +# i=0 +# for k in a: +# if k==3: +# del a[i] +# i+=1 +# print(a) def updaterole(id=0): "更新内容" G.setadminlog="修改角色权限" data=request.get_json() + del data['name'] + del data['admin_id'] + data['roleroute']=list(set(data['roleroute'])) + plug=sqlite('plug',model_app_path).select() + i=0 + for d in data['roleroute']: + t=False + for k in plug: + role=json_decode(k['role']) + for kk in role: + if d==kk['value']: + t=True + if not t: + del data['roleroute'][i] + i+=1 + + if not id: id=data['id'] id=int(id) @@ -274,10 +306,10 @@ def updaterole(id=0): try: data.pop('updtime') data.pop('addtime') + data['roleroute']=json_encode(data['roleroute']) except:pass else: - del data['admin_id'] sqlite("role",model_app_path).where("id",id).update(data) return successjson() def deleterole(): diff --git a/app/intapp/controller/index/tpl/admin/admin.html b/app/intapp/controller/index/tpl/admin/admin.html index ef6bb2a..aaff5d5 100644 --- a/app/intapp/controller/index/tpl/admin/admin.html +++ b/app/intapp/controller/index/tpl/admin/admin.html @@ -41,8 +41,8 @@ @@ -99,7 +99,11 @@ - {{item.title}} + + {{item.name}} + 系统 +  创建的=>  + {{item.title}} @@ -198,7 +202,7 @@ var vm = new Vue({ }, getrolelist:function(){ self=this - self.get("/intapp/index/admin/getrolelist",{'kw':self.kw,'pagesize':self.data.pagesize,'pagenow':self.data.pagenow},'获取中...').then(function(res){ + self.get("/intapp/index/admin/getrolelist/0/0",{'kw':self.kw,'pagesize':self.data.pagesize,'pagenow':self.data.pagenow},'获取中...').then(function(res){ self.rolelist=res.data.lists self.getlist() }) diff --git a/app/intapp/controller/index/tpl/admin/role.html b/app/intapp/controller/index/tpl/admin/role.html index 109339f..1d38e12 100644 --- a/app/intapp/controller/index/tpl/admin/role.html +++ b/app/intapp/controller/index/tpl/admin/role.html @@ -21,13 +21,19 @@ 搜索 - 添加角色 + 添加角色
+ + + @@ -47,7 +53,7 @@    删除选中 
@@ -177,11 +183,11 @@ var vm = new Vue({ handleSizeChange:function(val) { self=this self.data.pagesize=val - // self.obtain() + self.getlist() }, handleCurrentChange:function(val) { self.data.pagenow=val - // self.obtain() + self.getlist() } } }); -- Gitee From ab3ac49566340774750c048e30dccc80ccfc208f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Thu, 24 Jun 2021 02:05:23 +0800 Subject: [PATCH 17/19] k --- app/intapp/controller/index/admin.py | 54 +++++++++++++------ app/intapp/controller/index/role.txt | 3 +- .../controller/index/tpl/admin/adminlog.html | 47 +++++++++------- 3 files changed, 68 insertions(+), 36 deletions(-) diff --git a/app/intapp/controller/index/admin.py b/app/intapp/controller/index/admin.py index 4b9240c..fd82b76 100644 --- a/app/intapp/controller/index/admin.py +++ b/app/intapp/controller/index/admin.py @@ -62,19 +62,27 @@ def loglist(): 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): - G.setadminlog="删除日志" +def deletelogs(id=0): + G.setadminlog="清空日志" 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() + sqlite("admin_log",model_app_path).where("1=1").delete() except: return errorjson(msg="失败") else: return successjson() +def deletelog30(id=0): + G.setadminlog="删除30天前的日志" + try: + id=request.get_json() + sqlite("admin_log",model_app_path).where('addtime','<',times()-86400*30).delete() + except: + return errorjson(msg="失败") + else: + return successjson() def getpluglist(modular="intapp"): G.setadminlog="本地插件列表" path="app/"+modular+"/controller/" @@ -148,6 +156,8 @@ def insert(): data=request.get_json() if sqlite("admin",model_app_path).where("phone",data['phone']).count(): return errorjson(msg="该手机已添加") + if sqlite("admin",model_app_path).where("username",data['username']).count(): + return errorjson(msg="该用户名已添加") if not data['username'] or not data['password']: return errorjson(msg="请输入用户名或密码") data.update(logintime=times(),addtime=times()) @@ -179,24 +189,26 @@ def update(id=0): if not id: id=data['id'] try: - data.pop('logintime') - data.pop('addtime') - data.pop('password') + del data['title'] + del data['describes'] + del data['logintime'] + del data['addtime'] + del data['password'] if G.userinfo['role']['id']!=1: del data['phone'] del data['username'] del data['nickname'] del data['name'] - del data['logintime'] del data['icon'] - del data['addtime'] - del data['title'] - del data['describes'] - except:pass + + except Exception as e: + return errorjson(msg="失败"+str(e)) else: if G.userinfo['role']['id']==1: sqlite("admin",model_app_path).where("id",id).update(data) else: + if id==1: + return errorjson(msg="您没有权限修改此账号") if data['role']==G.userinfo['role']['id'] or sqlite("role",model_app_path).where("admin_id="+str(G.userinfo['id'])+" and id="+str(data['role'])).count(): sqlite("admin",model_app_path).where("id",id).update(data) else: @@ -247,7 +259,7 @@ def getrolelist(id=0,roleroute=1): else: pagesize=int(pagesize) if roleroute: - lists=sqlite("role t1",model_app_path).join("admin t2","t1.admin_id=t2.id","left").field("t1.*,t2.name").page(pagenow,pagesize).select() + lists=sqlite("role t1",model_app_path).join("admin t2","t1.admin_id=t2.id","left").field("t1.*,t2.name").where(where).page(pagenow,pagesize).select() else: lists=sqlite("role t1",model_app_path).join("admin t2","t1.admin_id=t2.id","left").field("t1.id,t1.admin_id,t1.icon,t1.title,t1.describes,t1.types,t1.updtime,t1.addtime,t2.name").where(where).select() if roleroute: @@ -310,7 +322,13 @@ def updaterole(id=0): data['roleroute']=json_encode(data['roleroute']) except:pass else: - sqlite("role",model_app_path).where("id",id).update(data) + if G.userinfo['role']['id']==1: + sqlite("role",model_app_path).where("id",id).update(data) + else: + if sqlite("role",model_app_path).where("id="+str(id)+" and admin_id="+str(G.userinfo['id'])).update(data): + return successjson() + else: + return errorjson(msg="该记录权限不足") return successjson() def deleterole(): "批量删除" @@ -320,7 +338,13 @@ def deleterole(): try: id.remove(1) except:pass - sqlite("role",model_app_path).where('id','in',id).delete() + if G.userinfo['role']['id']==1: + sqlite("role",model_app_path).where('id','in',id).delete() + else: + ids='0' + for k in id: + ids+=","+str(k) + sqlite("role",model_app_path).where("id in ("+ids+") and admin_id="+str(G.userinfo['id'])).delete() except: return errorjson(msg="失败") else: diff --git a/app/intapp/controller/index/role.txt b/app/intapp/controller/index/role.txt index 80b233b..15c561b 100644 --- a/app/intapp/controller/index/role.txt +++ b/app/intapp/controller/index/role.txt @@ -14,7 +14,8 @@ shell执行能力,/intapp/index/index/shell 操作日志页面,/intapp/index/admin/adminlog 日志列表,/intapp/index/admin/loglist 日志明细,/intapp/index/admin/logdeta -删除日志,/intapp/index/admin/deletelog +清空日志,/intapp/index/admin/deletelogs +删除30天前的日志,/intapp/index/admin/deletelog30 路由列表,/intapp/index/admin/getpluglist 当前用户拥有的权限,/intapp/index/admin/getmypluglist 管理员列表,/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 b69e6d9..5ab5f3b 100644 --- a/app/intapp/controller/index/tpl/admin/adminlog.html +++ b/app/intapp/controller/index/tpl/admin/adminlog.html @@ -76,7 +76,8 @@
-    删除选中  +    清空  +    删除30天前的日志  Date: Thu, 24 Jun 2021 02:05:50 +0800 Subject: [PATCH 18/19] k --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4147191..22d4f4b 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,6 @@ python server.py ```` 生产环境下运行命令 -```` +```` bash server.sh ```` \ No newline at end of file -- Gitee From 5c8e586b2bc4f2198a495509f266d758e1f353fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E6=A0=91=E5=9D=A4?= Date: Thu, 24 Jun 2021 02:08:04 +0800 Subject: [PATCH 19/19] k --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 22d4f4b..4147191 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,6 @@ python server.py ```` 生产环境下运行命令 -```` +```` bash server.sh ```` \ No newline at end of file -- Gitee