From bc59509a8cd49544331de19565f7559ec04c8824 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 21 Jul 2020 10:22:32 +0800 Subject: [PATCH 01/38] kun --- app/common/__init__.py | 9 +- app/intapp/controller/__init__.py | 3 +- app/intapp/controller/soft/__init__.py | 8 - app/intapp/controller/soft/common/SOFT.py | 213 -------- app/intapp/controller/soft/common/__init__.py | 2 - app/intapp/controller/soft/common/autoload.py | 10 - app/intapp/controller/soft/common/file/soft | Bin 16384 -> 0 bytes .../soft/common/file/sqlite/.gitignore | 1 - .../soft/common/file/sqlite/php_exten | Bin 24576 -> 0 bytes app/intapp/controller/soft/common/model.py | 84 --- app/intapp/controller/soft/frp.py | 133 ----- app/intapp/controller/soft/index.py | 83 --- app/intapp/controller/soft/install.txt | 1 - app/intapp/controller/soft/mongodb.py | 245 --------- app/intapp/controller/soft/mysql.py | 205 -------- app/intapp/controller/soft/nginx.py | 331 ------------ app/intapp/controller/soft/page.py | 13 - app/intapp/controller/soft/php.py | 266 ---------- app/intapp/controller/soft/redis.py | 69 --- .../controller/soft/tpl/index/home.html | 420 --------------- app/intapp/controller/soft/tpl/index/web.html | 479 ------------------ app/intapp/controller/soft/tpl/soft/frp.html | 250 --------- app/intapp/controller/soft/tpl/soft/git.html | 69 --- .../controller/soft/tpl/soft/kodexplorer.html | 89 ---- .../controller/soft/tpl/soft/mongodb.html | 436 ---------------- .../controller/soft/tpl/soft/mysql.html | 106 ---- .../controller/soft/tpl/soft/nginx.html | 113 ----- app/intapp/controller/soft/tpl/soft/php.html | 331 ------------ .../controller/soft/tpl/soft/phpmyadmin.html | 91 ---- .../controller/soft/tpl/soft/redis.html | 127 ----- 30 files changed, 6 insertions(+), 4181 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/soft 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/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.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/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 diff --git a/app/common/__init__.py b/app/common/__init__.py index 0b39d29..69d04a3 100644 --- a/app/common/__init__.py +++ b/app/common/__init__.py @@ -21,19 +21,20 @@ def serlogin(username,sign,timestamp,random,types="session"): types 登录类型 session浏览器默认会话登录 否则返回account_token """ + account_token='' if (times()-int(timestamp))>3600 or times()-int(timestamp)<-3600: - return False,3,"时间戳错误" + return False,3,"时间戳错误",account_token inifo=sqlite('admin',model_app_path).where([('username','eq',username),'or',('phone','eq',username)]).find() if not inifo: - return False,2,"用户名错误" + return False,2,"用户名错误",account_token if inifo['id']>100: return False,-1,"您不是管理员账号" usign=md5(str(inifo['username'])+str(inifo['password'])+str(timestamp)+str(random)) if usign!=sign: - return False,2,"密码错误" + return False,2,"密码错误",account_token inifo['role']=sqlite("role",model_app_path).where('id',inifo['role']).find() sqlite('admin',model_app_path).where('id',inifo['id']).update({'logintime':times()}) - account_token='' + if types=='session': #如果使用sess登录,要分配系统菜单权限 #根据权限给当前登录用户初始化菜单 systemrolelist=[ #系统菜单权限 diff --git a/app/intapp/controller/__init__.py b/app/intapp/controller/__init__.py index f4dbb41..6a03892 100644 --- a/app/intapp/controller/__init__.py +++ b/app/intapp/controller/__init__.py @@ -1,3 +1,2 @@ -from . import index -from . import soft \ No newline at end of file +from . import index \ No newline at end of file diff --git a/app/intapp/controller/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 d9a1ce6..0000000 --- a/app/intapp/controller/soft/common/SOFT.py +++ /dev/null @@ -1,213 +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 get_process_id('mysql'): - 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}) #运行中 - 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","POST",{ - "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 log 2>&1 &") - return True - elif 'mysql' == 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":"安装成功"}) - insert_Boot_up("mysqld start") - 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":"安装成功"}) - 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 &") - elif 'mysql' == arr['title']: - os.system("mysqld start") - 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 redis") - elif 'mysql' == arr['title']: - os.system("mysqld stop") - 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']: - del_Boot_up("nginx") - os.system("pkill -9 nginx") - model_intapp_menu.delete(title="网站",types="left") - os.system("rm -rf "+startpath+"nginx") - elif 'redis' == arr['title']: - del_Boot_up("nohup redis-server "+arr['paths']+arr['title']+arr['edition']+"/redis.conf > log 2>&1 &") - os.system("rm -rf "+startpath+"redis-server") - elif 'php' == arr['title']: - titleedition=arr['title']+arr['edition'] - fpmname=titleedition.replace(".", "")+"-fpm" - 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']: - del_Boot_up("mysqld start") - os.system("rm -rf "+startpath+"mysqld && rm -rf "+startpath+"mysql && rm -rf /etc/my.cnf") - elif 'mongodb' == arr['title']: - del_Boot_up("mongo",True) - os.system("pkill -9 mongo") - os.system("rm -rf /data/mongodb") - elif 'frp' == arr['title']: - del_Boot_up("frps",True) - del_Boot_up("frpc",True) - os.system("pkill -9 frps") - os.system("pkill -9 frpc") - else: - 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/soft b/app/intapp/controller/soft/common/file/soft deleted file mode 100644 index 6653475e90ae0b4d5f804f4d9be25ea4ceadfde8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 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 ZjZ{6U_66{LZ>IW!$}wLMZUpL${{^4#H% "+dar+"/log/frpslog 2>&1 &" - os.system("pkill -9 frps") - del_Boot_up(cmd) - time.sleep(1) - os.system(cmd) - time.sleep(1) - if not get_process_id('frps'): - return errorjson(msg="启动失败,请检查配置") - insert_Boot_up(cmd) - elif types=='frpc': - cmd="cd "+dar +" && nohup ./frpc -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &" - os.system("pkill frpc") - del_Boot_up(cmd) - time.sleep(1) - os.system(cmd) - time.sleep(1) - if not get_process_id('frpc'): - return errorjson(msg="启动失败,请检查配置") - insert_Boot_up(cmd) - return successjson() -def stop(types='all'): - "停止" - if types=='frps': - del_Boot_up("cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") - os.system("pkill -9 frps") - elif types=='frpc': - del_Boot_up("cd "+dar +" && nohup ./frpc -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") - os.system("pkill -9 frpc") - else: - del_Boot_up("cd "+dar +" && nohup ./frps -c frps_full.ini > "+dar+"/log/frpslog 2>&1 &") - 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'): - 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'): - 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 77bbc05..0000000 --- a/app/intapp/controller/soft/index.py +++ /dev/null @@ -1,83 +0,0 @@ -from .common import * -def index(): - return response.tpl('index/home') -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(): - "更新软件列表" - 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): - "安装软件" - title=sqlite('soft',model_intapp_soft_path).where("id",id).field("title").find()['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 '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): - "启动软件" - SOFT.start(id) - return successjson() -def stop(id): - "停止软件" - SOFT.stop(id) - 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公钥' - data=file_get_content("/root/.ssh/id_rsa.pub") - 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 6b996d3..0000000 --- a/app/intapp/controller/soft/install.txt +++ /dev/null @@ -1 +0,0 @@ -oss2>=2.11.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 f7223a1..0000000 --- a/app/intapp/controller/soft/mongodb.py +++ /dev/null @@ -1,245 +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页面配置' - data=json_decode(file_get_content(WORK_DIR+"/config.conf")) - try: - key=file_get_content(WORK_DIR+"/key/mongo.key") - except: - key="" - if not data: - data={} - data['key']=key - data['get_local_ip']=get_local_ip() - data['WORK_DIR']=WORK_DIR - data['configlist']=json_decode(file_get_content(WORK_DIR+"/serverconfig.conf")) - return successjson(data) -def upd_config(id): - '修改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服务' - 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'): - '启动/停止路由服务' - 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'): - '启动/停止分片服务' - 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 - insert_Boot_up(cmd) - # sqlite('start_command').insert({'title':'mongodb启动'+str(index),'describes':'系统创建,请务删除','status':0,'command':cmd,'addtime':times()})#添加自启 - elif types=='stop': - # sqlite('start_command').where('title','mongodb启动'+str(index)).delete()#删除自启 - configlist[index]['status']=0 - 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.py b/app/intapp/controller/soft/mysql.py deleted file mode 100644 index 3abcb49..0000000 --- a/app/intapp/controller/soft/mysql.py +++ /dev/null @@ -1,205 +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: - conf={ - "base":{'rootpassword':'intapppasswordtest','path':ar['paths']+ar['title']+ar['edition']+'/data'}, - } - data={ - 'conf':conf, - 'ar':ar, - "my":file_get_content("/etc/my.cnf") - } - return successjson(data) -def upd_my(): - "修改配置文件" - data=request.get_json() - file_set_content("/etc/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 restart --skip-grant-tables") - cmd="mysql -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+'"' - 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 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 not filedata or data['base']['path']!=filedata['base']['path']: - os.system('mysqld stop') - os.system("mkdir -p "+str(data['base']['path'])) - 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 "+str(data['base']['path'])+" && chgrp -R mysql "+str(data['base']['path'])) - - f = open('/etc/my.cnf') - con='' - while True: - line = f.readline() - if not line: - break - elif 'datadir=' in line: - line="datadir="+str(data['base']['path'])+"\n" - con=con+line - f.close() - f= open('/etc/my.cnf', "w") - f.write(con) - f.close() - time.sleep(1) - os.system('mysqld 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=False): - return BACKUP.backups(types,db,upload_aliyun) - # title="备份数据库" - # describes="" - # if types=='whole' and db=='bankup_all_databases': - # title="全量备份所有数据库:"+db+".sql.gz" - # describes="全量备份所有数据库:"+db+".sql.gz" - # elif types=='whole': - # title="全量备份指定数据库:"+db+".sql.gz" - # describes="全量备份指定数据库:"+db+".sql.gz" - # else: - # title="增量备份所有数据库:"+db+".sql.gz" - # describes="增量备份所有数据库:"+db+".sql.gz" - # Queues.insert(target=BACKUP.backups,args=(types,db,upload_aliyun),title=title,describes=describes) - # return successjson() -class BACKUP: - def backups(types='whole',db='bankup_all_databases',upload_aliyun=False): - """备份mysql --cli运行 - types whole表示全量备份。 increment表示增量备份所有 - - db bankup_all_databases表示备份所有数据库。 否则备份指定数据库按逗号分隔 types=whole时有效 - """ - indexconfigpathfile=os.path.split(os.path.realpath(__file__))[0]+"/../index/common/file/sqlite/strconfig" - configfile=json_decode(file_get_content(indexconfigpathfile)) - if not configfile: - print("请先在计划中保存备份目录") - return - if configfile['backmysqlpath'][:1]=='/': - backmysqlpath="backup"+configfile['backmysqlpath'] #mysql备份目录 - else: - backmysqlpath="backup/"+configfile['backmysqlpath'] #mysql备份目录 - if backmysqlpath[-1]=='/': - backmysqlpath=backmysqlpath[:-1] - 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(configfile['access_key_id'],configfile['access_key_secret']) - bucket = oss2.Bucket(auth,configfile['endpoint'],configfile['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/"+backmysqlpath+"/"+db+".sql.gz",backmysqlpath+"/"+db+".sql.gz") - - - 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 4a2c048..0000000 --- a/app/intapp/controller/soft/nginx.py +++ /dev/null @@ -1,331 +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}, - } - 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() - 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) -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']) - i+=1 - count=sqlite("web",model_intapp_soft_path).where(where).count() - return successjson(return_list(lists,count,pagenow,pagesize)) -def add_web(): - "添加或更新网站" - 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() - data=request.get_json() - if data['domain']=='': - return errorjson(msg="域名不能为空") - if data['port']=='': - return errorjson(msg="端口不能为空") - if data['client_max_body_size']=='': - return errorjson(msg="上传限制不能为空") - if data['path']=='': - return errorjson(msg="网站目录不能为空") - paths=nginx['paths'] - try: - ttt1=data['domain'].split("\n") - if data['id']: - 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 errorjson(msg=k+"已在本服务器其他站点使用被使用") - domains=sqlite('web',model_intapp_soft_path).where("id",data['id']).field("only").find()['only'] - else: - 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 errorjson(msg=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 errorjson(msg="请选择配置文件模板") - filenames=nginx['title']+nginx['edition'] - servertpl=paths+filenames+'/conf/vhost/webtpl/'+data['webtpl'] - ssl_certificate=data['ssl_certificate'] - ssl_certificate_key=data['ssl_certificate_key'] - 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'] - 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" - 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 'php' in data['webtpl'] and len(data['rewrite'])>4:#php伪静态 - file_set_content(paths+filenames+"/conf/vhost/rewrite/"+domains,data['rewrite']) - elif not data['id']: - file_set_content(paths+filenames+"/conf/vhost/rewrite/"+domains,'') - if data['webtpl']=='static' or data['webtpl']=='vue' or 'php' in data['webtpl']: - text=Templates(servertpl,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) - 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 errorjson(msg="请填写负载均衡ip和端口") - text=Templates(servertpl,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) - 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 - del data['ssl'] - del data['key'] - del data['pem'] - del data['rewrite'] - data['balancing'] =json_encode(data['balancing']) - data['proxy_set_header'] =json_encode(data['proxy_set_header']) - if data['id']: - data['updtime']=addtime - data['status']=1 - sqlite('web',model_intapp_soft_path).where("id",data['id']).update(data) - 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) - else: - del data['id'] - data['addtime']=addtime - data['updtime']=addtime - sqlite('web',model_intapp_soft_path).insert(data) - except: - print(traceback.format_exc()) - return errorjson(msg="失败,检查参数是否有误") - else: - return successjson() -def del_web(id=0,path=0): - #path=1 表示删除网站目录 ,linux和windows已完成 - "删除网站" - 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 0dc48f6..0000000 --- a/app/intapp/controller/soft/page.py +++ /dev/null @@ -1,13 +0,0 @@ -from .common import * -def home(): - return response.tpl("index/home") -def pub(html): - return response.tpl("page/%s" % html) -def s(fun,html): - id=request.args.get("id") - 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() - 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 5c1e94b..0000000 --- a/app/intapp/controller/soft/php.py +++ /dev/null @@ -1,266 +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: #修改配置 - 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: #修改配置 - 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配置 - 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扩展" - 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扩展" - sqlite('php_exten',model_intapp_soft_php_exten_path).where('id',id).delete() - return successjson() - -def installext(id): - is_del=False #是否删除成功 - "安装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 df44a4d..0000000 --- a/app/intapp/controller/soft/redis.py +++ /dev/null @@ -1,69 +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: #修改配置 - 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) - return successjson(data) \ No newline at end of file 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 3e542d2..0000000 --- a/app/intapp/controller/soft/tpl/index/home.html +++ /dev/null @@ -1,420 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
-
- - - 搜索 - - 备份、网站 、软件列表、php扩展 - 恢复 - 更新软件列表 - -
-
- - % 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 53d06a9..0000000 --- a/app/intapp/controller/soft/tpl/index/web.html +++ /dev/null @@ -1,479 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
-
-    - - - 搜索 - 添加网站 - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
域名
端口 - 上传限制:MB
网站名
配置文件模板 - - - - -
备注
网站目录
-
- - - - - - - - -
- - - - - - - - - -   - - -
- 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 c137b73..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 9f6b6b0..0000000 --- a/app/intapp/controller/soft/tpl/soft/git.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
-
- -
- 您可以使用以下命令生成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 6fb3f59..0000000 --- a/app/intapp/controller/soft/tpl/soft/kodexplorer.html +++ /dev/null @@ -1,89 +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 417da13..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 ebeb98f..0000000 --- a/app/intapp/controller/soft/tpl/soft/mysql.html +++ /dev/null @@ -1,106 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
-
- - - - - - - - 建议与mysql安装目录分开 - - 保存 - - - -
- - 保存 -
-
-
-
-
- - - \ 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 8956ac7..0000000 --- a/app/intapp/controller/soft/tpl/soft/nginx.html +++ /dev/null @@ -1,113 +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 f281a40..0000000 --- a/app/intapp/controller/soft/tpl/soft/php.html +++ /dev/null @@ -1,331 +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 5dd49d6..0000000 --- a/app/intapp/controller/soft/tpl/soft/phpmyadmin.html +++ /dev/null @@ -1,91 +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 64eac89..0000000 --- a/app/intapp/controller/soft/tpl/soft/redis.html +++ /dev/null @@ -1,127 +0,0 @@ - - - - - -kcwebplus - - - - - - - - - - - - - - - - - - - -
- - -
- - - 绑定IP - - - 端口 - - - 空闲连接超时时间,0表示不断开 - - - 最大连接数 - - - 数据库数量 - - - redis密码,留空代表没有设置密码 - - - MB,最大使用内存,0表示不限制 - - - 保存 -
-
- - - - - 保存 - 修改后重启redis生效
-
-
-
- - - \ No newline at end of file -- Gitee From 3a17d9f01213e08f75a9f044e87c36d0825fce89 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 21 Jul 2020 10:49:33 +0800 Subject: [PATCH 02/38] kun --- app/intapp/controller/index/common/plantask.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/intapp/controller/index/common/plantask.py b/app/intapp/controller/index/common/plantask.py index 017ed10..270aa57 100644 --- a/app/intapp/controller/index/common/plantask.py +++ b/app/intapp/controller/index/common/plantask.py @@ -147,10 +147,10 @@ class PLANTASK(): if not PLANTASK.BlockingSchedulers: PLANTASK.BlockingSchedulers = BlockingScheduler() #进程可能影响cli运行 - multiprocessing.Process(target=PLANTASK.plantaskdsfsdfsafdsafsd,args=(PLANTASK.BlockingSchedulers,func,targger,args,year,month,week,day_of_week,day,hour,minute,second,iden)).start() - # t=threading.Thread(target=PLANTASK.plantaskdsfsdfsafdsafsd,args=(PLANTASK.BlockingSchedulers,func,targger,args,year,month,week,day_of_week,day,hour,minute,second,iden)) - # t.daemon=True - # t.start() + # multiprocessing.Process(target=PLANTASK.plantaskdsfsdfsafdsafsd,args=(PLANTASK.BlockingSchedulers,func,targger,args,year,month,week,day_of_week,day,hour,minute,second,iden)).start() + t=threading.Thread(target=PLANTASK.plantaskdsfsdfsafdsafsd,args=(PLANTASK.BlockingSchedulers,func,targger,args,year,month,week,day_of_week,day,hour,minute,second,iden)) + t.daemon=True + t.start() # print("添加",data) except: -- Gitee From b483d184c6094c8e16e7447ea83ff5c6d71c0d00 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 21 Jul 2020 18:26:24 +0800 Subject: [PATCH 03/38] kun --- kcweb/common/autoload.py | 6 ++---- kcweb/config/__init__.py | 2 +- kcweb/setup.py | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/kcweb/common/autoload.py b/kcweb/common/autoload.py index 48fc635..cb0bebe 100644 --- a/kcweb/common/autoload.py +++ b/kcweb/common/autoload.py @@ -493,7 +493,6 @@ class create: if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):#安装打包好的插件 zip.unzip_file(self.appname+"/"+self.modular+"/controller/"+plug+".zip",self.appname+"/"+self.modular+"/controller/"+plug+"/") os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip") - if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+"/install.txt"): #安装依赖包 install_requires=[] try: @@ -512,14 +511,13 @@ class create: try: install_requires.insert(0,"install") if 0 != pip.main(install_requires): - shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) + shutil.rmtree(self.appname+"/"+self.modular+"/controller/"+plug) return False,"error" except AttributeError as e: - shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug) + shutil.rmtree(self.appname+"/"+self.modular+"/controller/"+plug) if config.app['app_debug']: print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/") return False,str(e) - # try: # m=importlib.import_module(self.appname+"."+self.modular+"/controller/"+plug+".install") # except: diff --git a/kcweb/config/__init__.py b/kcweb/config/__init__.py index 8c81349..eef962f 100644 --- a/kcweb/config/__init__.py +++ b/kcweb/config/__init__.py @@ -98,7 +98,7 @@ email['recNick']='' #默认收件人昵称 kcweb={} kcweb['name']='kcweb' #项目的名称 -kcweb['version']='4.11.7' #项目版本 +kcweb['version']='4.11.8' #项目版本 kcweb['description']='' #项目的简单描述 kcweb['long_description']='' #项目详细描述 kcweb['license']='MIT' #开源协议 mit开源 diff --git a/kcweb/setup.py b/kcweb/setup.py index 8f2c47e..328b102 100644 --- a/kcweb/setup.py +++ b/kcweb/setup.py @@ -16,7 +16,7 @@ def file_get_content(k): return con confkcw={} confkcw['name']='kcweb' #项目的名称 -confkcw['version']='4.11.7' #项目版本 +confkcw['version']='4.11.8' #项目版本 confkcw['description']='' #项目的简单描述 confkcw['long_description']="" #项目详细描述 confkcw['license']='MIT License' #开源协议 mit开源 -- Gitee From ee4819ad360e867b923106b70adfd50dd97fb40b Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 22 Jul 2020 21:23:49 +0800 Subject: [PATCH 04/38] kun --- app/common/__init__.py | 2 +- app/common/html/login.html | 78 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 app/common/html/login.html diff --git a/app/common/__init__.py b/app/common/__init__.py index 69d04a3..42baad2 100644 --- a/app/common/__init__.py +++ b/app/common/__init__.py @@ -106,7 +106,7 @@ def check_login(): G.userinfo=get_session("userinfo") if not G.userinfo: if 'GET' == request.HEADER.Method(): - return response.tpl('pub/login') + return response.tpl('/intapp/html/login') else: return errorjson(code=-1,msg='登录失效,请重新登录') return check_role() diff --git a/app/common/html/login.html b/app/common/html/login.html new file mode 100644 index 0000000..0909468 --- /dev/null +++ b/app/common/html/login.html @@ -0,0 +1,78 @@ + + + + +kcweb + + + + + + + + + + + + + + + +
+
+
+
+

+

kcweb   

+
+
+ +
+
+ +
+
+ 登录 +
+
+
+
+ +
+ + + -- Gitee From 256220bdaf8bc1fda2ca8d32a311a4889757e632 Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 22 Jul 2020 21:30:00 +0800 Subject: [PATCH 05/38] kun --- app/common/__init__.py | 2 +- app/intapp/controller/index/tpl/setup/index.html | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/common/__init__.py b/app/common/__init__.py index 42baad2..5eb0d73 100644 --- a/app/common/__init__.py +++ b/app/common/__init__.py @@ -106,7 +106,7 @@ def check_login(): G.userinfo=get_session("userinfo") if not G.userinfo: if 'GET' == request.HEADER.Method(): - return response.tpl('/intapp/html/login') + return response.tpl('/common/html/login.html') else: return errorjson(code=-1,msg='登录失效,请重新登录') return check_role() diff --git a/app/intapp/controller/index/tpl/setup/index.html b/app/intapp/controller/index/tpl/setup/index.html index 1ff58d7..63d6a55 100644 --- a/app/intapp/controller/index/tpl/setup/index.html +++ b/app/intapp/controller/index/tpl/setup/index.html @@ -34,6 +34,7 @@
+ 启动项
-- Gitee From ba53ac2194d76fa0bd0dfe2a66273aad075de8ce Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 22 Jul 2020 22:33:18 +0800 Subject: [PATCH 06/38] kun --- app/common/__init__.py | 76 ++++++++++------ app/common/model.py | 20 ++++- app/intapp/controller/index/setup.py | 35 +++++++- .../controller/index/tpl/setup/index.html | 89 ++++++++++++++++--- 4 files changed, 182 insertions(+), 38 deletions(-) diff --git a/app/common/__init__.py b/app/common/__init__.py index 5eb0d73..c1ae18e 100644 --- a/app/common/__init__.py +++ b/app/common/__init__.py @@ -217,38 +217,64 @@ def file_set_content(k,data): return True def insert_Boot_up(cmd): "添加开机启动命令" - if 'Linux' in get_sysinfo()['uname'][0]: - f=open("/usr/bin/startkcweb","a") - f.write("\n"+cmd+"\n") - f.close() - return True - else: - return False + return system_start.insert_Boot_up(cmd) def del_Boot_up(cmd,vague=False): """删除开机启动命令 vague 是否模糊匹配 """ - if 'Linux' in get_sysinfo()['uname'][0]: - if vague: - f = open("/usr/bin/startkcweb") - con='' - while True: - line = f.readline() - if not line: - break - if 'cmd' in line: - line='' - con=con+line + return system_start.del_Boot_up(cmd,vague) +class system_start: + "系统启动项" + def lists(pagenow=1,pagesize=20,where=None): + "启动项列表" + lists=sqlite().connect(model_app_path).where(where).table("start").order("id asc").page(pagenow,pagesize).select() + count=sqlite().connect(model_app_path).where(where).table("start").count() + return lists,count + def insert_Boot_up(cmd,name="系统添加",types="shell",icon="",admin_id=0): + "添加开机启动命令" + if 'Linux' in get_sysinfo()['uname'][0]: + f=open("/usr/bin/startkcweb","a") + f.write("\n"+cmd+"\n") f.close() - file_set_content("/usr/bin/startkcweb",con) + if not sqlite("start").connect(model_app_path).where("cmd",cmd).count(): + return False + sqlite("start").connect(model_app_path).insert({"name":name,"types":types,"value":cmd,"icon":icon,"admin_id":admin_id,"addtime":times()}) + return True else: - content=file_get_content("/usr/bin/startkcweb") - content=content.replace("\n"+cmd+"\n","") - file_set_content("/usr/bin/startkcweb",content) - return True - else: - return False + return False + def del_Boot_up(cmd,vague=False,id=False): + """删除开机启动命令 + + vague 是否模糊匹配 + """ + if id: + where=[("id",">",id),"and",("admin_id",">",0)] + if 'Linux' in get_sysinfo()['uname'][0]: + if vague: + f = open("/usr/bin/startkcweb") + con='' + while True: + line = f.readline() + if not line: + break + if 'cmd' in line: + line='cmd' + con=con+line + f.close() + file_set_content("/usr/bin/startkcweb",con) + if not id: + where=[("value","like","%"+str(cmd)+"%"),"and",("admin_id",">",0)] + else: + content=file_get_content("/usr/bin/startkcweb") + content=content.replace("\n"+cmd+"\n","") + file_set_content("/usr/bin/startkcweb",content) + if not id: + where=[("value","=",cmd),"and",("admin_id",">",0)] + sqlite("start").connect(model_app_path).where(where).delete() + return True + else: + return False g_local_ip='' def get_local_ip(): "获取内网ip" diff --git a/app/common/model.py b/app/common/model.py index 12897f1..aa539b6 100644 --- a/app/common/model.py +++ b/app/common/model.py @@ -123,4 +123,22 @@ except: "icon":'', "role":json_encode(role), "addtime":times() - }) \ No newline at end of file + }) + +class model_app_start(modelsqliteintapp): + "启动项" + table="start" + fields={ + "id":model.dbtype.int(LEN=11,PRI=True,A_L=True), #设置id为自增主键 + "name":model.dbtype.varchar(LEN=128,DEFAULT=''), #名字 + "icon":model.dbtype.varchar(LEN=128,DEFAULT=''), + "types":model.dbtype.varchar(LEN=128,DEFAULT='shell'), #类型 + "value":model.dbtype.varchar(LEN=512,DEFAULT=''), + "admin_id":model.dbtype.int(LEN=11), + "addtime":model.dbtype.int(LEN=11,DEFAULT=0), #添加时间 + } +try: + sqlite('start',model_app_path).find() +except: + model_app_start=model_app_start() + model_app_start.create_table() \ No newline at end of file diff --git a/app/intapp/controller/index/setup.py b/app/intapp/controller/index/setup.py index 9294b0a..3e31284 100644 --- a/app/intapp/controller/index/setup.py +++ b/app/intapp/controller/index/setup.py @@ -1,7 +1,36 @@ from .common import * def index(): return response.tpl() - +def addstart(): + "添加启动项" + data=request.get_json() + if system_start.insert_Boot_up(cmd=data['value'],name=data['name'],types=data['types'],admin_id=G.userinfo['id']): + return successjson() + else: + return errorjson(msg="添加失败,该系统支不支持") +def delstart(): + data=request.get_json() + if system_start.del_Boot_up(cmd=data['value'],id=data['id']): + return successjson() + else: + return errorjson() +def startlist(): + "启动项列表" + pagenow=request.args.get('pagenow') + pagesize=request.args.get('pagesize') + if not pagenow: + pagenow=1 + else: + pagenow=int(pagenow) + if not pagesize: + pagesize=10 + else: + pagesize=int(pagesize) + yz=system_start.lists(pagenow,pagesize) + lists=yz[0] + count=yz[1] + data=return_list(lists,count,pagenow,pagesize) + return successjson(data) def backup(): "备份" dirname=request.args.get("dirname") @@ -56,7 +85,7 @@ def recovery(): return successjson() else: return errorjson(msg="备份文件不存在") - else: + elif os.path.exists("backup"): filelist=get_file("backup") for k in filelist: if k['type']=='file' and 'backup.zip' in k['path']: @@ -64,6 +93,8 @@ def recovery(): dirname=re.sub("/backup.zip","",dirname) zip.unzip_file("backup/"+dirname+"/backup.zip",dirname) return successjson("恢复所有") + else: + return errorjson(msg="备份目录不存在") def download(name=""): "下载备份文件" if os.path.exists("backup"): diff --git a/app/intapp/controller/index/tpl/setup/index.html b/app/intapp/controller/index/tpl/setup/index.html index 63d6a55..f73afe1 100644 --- a/app/intapp/controller/index/tpl/setup/index.html +++ b/app/intapp/controller/index/tpl/setup/index.html @@ -23,23 +23,49 @@
- 启动项 + +
+    + + 添加启动项 + +
+ + + + + + + + + + + + + +
- 恢复所有备份
@@ -54,6 +80,23 @@ + + + + + + + + + + + 取 消 + 添加 + +
@@ -72,7 +115,13 @@ Vues=new Vue({ el: '#app', data:{ winheight:document.documentElement.clientHeight,winwidth:document.documentElement.clientWidth, - activeName: 'pack' + activeName: 'start', + admin:{value:'',name:'',types:''},admindialog:{status:false,title:'添加启动项'}, + data:{ + 'count':0, + 'pagenow':1, + 'lists':[] + }, }, mounted:function(){ self=this @@ -80,8 +129,28 @@ Vues=new Vue({ self.winheight=document.documentElement.clientHeight self.winwidth=document.documentElement.clientWidth } + self.obtain() }, methods: { + obtain:function(){ + self=this + self.get("/intapp/index/setup/startlist",{pagenow:self.data.pagenow},'获取中...').then(function(res){ + self.data=res.data + }) + },addstart:function(){ + self=this + self.post("/intapp/index/setup/addstart",self.admin,"请稍后...").then(function(res){ + self.admindialog.status=false + self.obtain() + }).catch(function(err){ + self.admindialog.status=false + }) + },delstart:function(item){ + self=this + self.post("/intapp/index/setup/delstart",item,"请稍后...").then(function(res){ + self.admindialog.status=false + }) + }, download:function(){ window.location.href="/intapp/index/setup/download/backup"; }, -- Gitee From 26f5fafde21425a22e11336cc2e736bf3bfc75cd Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 22 Jul 2020 22:37:32 +0800 Subject: [PATCH 07/38] kun --- app/common/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/__init__.py b/app/common/__init__.py index c1ae18e..b3cca56 100644 --- a/app/common/__init__.py +++ b/app/common/__init__.py @@ -237,7 +237,7 @@ class system_start: f=open("/usr/bin/startkcweb","a") f.write("\n"+cmd+"\n") f.close() - if not sqlite("start").connect(model_app_path).where("cmd",cmd).count(): + if not sqlite("start").connect(model_app_path).where("value",cmd).count(): return False sqlite("start").connect(model_app_path).insert({"name":name,"types":types,"value":cmd,"icon":icon,"admin_id":admin_id,"addtime":times()}) return True -- Gitee From 567a5bf0dccfeae2b2c58abb03688cdf1ca8f61b Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 22 Jul 2020 22:39:05 +0800 Subject: [PATCH 08/38] kun --- app/common/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/__init__.py b/app/common/__init__.py index b3cca56..d13d5ce 100644 --- a/app/common/__init__.py +++ b/app/common/__init__.py @@ -237,7 +237,7 @@ class system_start: f=open("/usr/bin/startkcweb","a") f.write("\n"+cmd+"\n") f.close() - if not sqlite("start").connect(model_app_path).where("value",cmd).count(): + if sqlite("start").connect(model_app_path).where("value",cmd).count(): return False sqlite("start").connect(model_app_path).insert({"name":name,"types":types,"value":cmd,"icon":icon,"admin_id":admin_id,"addtime":times()}) return True -- Gitee From f47086dabd6e47d51f0bcab86e2c0286850fa70a Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 22 Jul 2020 22:44:01 +0800 Subject: [PATCH 09/38] kun --- app/common/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/__init__.py b/app/common/__init__.py index d13d5ce..50250ad 100644 --- a/app/common/__init__.py +++ b/app/common/__init__.py @@ -249,7 +249,7 @@ class system_start: vague 是否模糊匹配 """ if id: - where=[("id",">",id),"and",("admin_id",">",0)] + where=[("id","=",id),"and",("admin_id",">",0)] if 'Linux' in get_sysinfo()['uname'][0]: if vague: f = open("/usr/bin/startkcweb") -- Gitee From 29be8bf2727a8c442d0095aec89170b78c74afc2 Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 22 Jul 2020 22:45:22 +0800 Subject: [PATCH 10/38] kun --- app/common/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/__init__.py b/app/common/__init__.py index 50250ad..9362bb4 100644 --- a/app/common/__init__.py +++ b/app/common/__init__.py @@ -246,7 +246,7 @@ class system_start: def del_Boot_up(cmd,vague=False,id=False): """删除开机启动命令 - vague 是否模糊匹配 + vague 是否模糊匹配 """ if id: where=[("id","=",id),"and",("admin_id",">",0)] -- Gitee From e8d04c77d4bc33656f748bda7c9885f32a92df64 Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 22 Jul 2020 22:46:52 +0800 Subject: [PATCH 11/38] kun --- app/common/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/common/__init__.py b/app/common/__init__.py index 9362bb4..a6e243e 100644 --- a/app/common/__init__.py +++ b/app/common/__init__.py @@ -249,7 +249,7 @@ class system_start: vague 是否模糊匹配 """ if id: - where=[("id","=",id),"and",("admin_id",">",0)] + where=[("id","eq",id),"and",("admin_id","gt",0)] if 'Linux' in get_sysinfo()['uname'][0]: if vague: f = open("/usr/bin/startkcweb") @@ -264,13 +264,13 @@ class system_start: f.close() file_set_content("/usr/bin/startkcweb",con) if not id: - where=[("value","like","%"+str(cmd)+"%"),"and",("admin_id",">",0)] + where=[("value","like","%"+str(cmd)+"%"),"and",("admin_id","gt",0)] else: content=file_get_content("/usr/bin/startkcweb") content=content.replace("\n"+cmd+"\n","") file_set_content("/usr/bin/startkcweb",content) if not id: - where=[("value","=",cmd),"and",("admin_id",">",0)] + where=[("value","eq",cmd),"and",("admin_id","gt",0)] sqlite("start").connect(model_app_path).where(where).delete() return True else: -- Gitee From f1b3a0882ed7efa3d67fa448e25d59b654ab719e Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 22 Jul 2020 22:49:20 +0800 Subject: [PATCH 12/38] kun --- app/intapp/controller/index/tpl/setup/index.html | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/intapp/controller/index/tpl/setup/index.html b/app/intapp/controller/index/tpl/setup/index.html index f73afe1..7eadcb7 100644 --- a/app/intapp/controller/index/tpl/setup/index.html +++ b/app/intapp/controller/index/tpl/setup/index.html @@ -147,9 +147,17 @@ Vues=new Vue({ }) },delstart:function(item){ self=this - self.post("/intapp/index/setup/delstart",item,"请稍后...").then(function(res){ - self.admindialog.status=false - }) + self=this + self.$confirm(res.msg, '该操作会上传启动项', { + confirmButtonText: '删除', + cancelButtonText: '取消', + type: 'warning' + }).then(function(){ + self.post("/intapp/index/setup/delstart",item,"请稍后...").then(function(res){ + self.obtain() + }) + }).catch(function(){}); + }, download:function(){ window.location.href="/intapp/index/setup/download/backup"; -- Gitee From a09a4b80dde4f3c8ed1714d43c5e9a026709e2b4 Mon Sep 17 00:00:00 2001 From: kunkun Date: Wed, 22 Jul 2020 22:51:41 +0800 Subject: [PATCH 13/38] kun --- app/intapp/controller/index/tpl/setup/index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/intapp/controller/index/tpl/setup/index.html b/app/intapp/controller/index/tpl/setup/index.html index 7eadcb7..1888a27 100644 --- a/app/intapp/controller/index/tpl/setup/index.html +++ b/app/intapp/controller/index/tpl/setup/index.html @@ -49,7 +49,7 @@ - +