kcwebps 1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kcwebps-1.3/PKG-INFO +13 -0
- kcwebps-1.3/README.md +23 -0
- kcwebps-1.3/kcwebps/__init__.py +13 -0
- kcwebps-1.3/kcwebps/common/__init__.py +442 -0
- kcwebps-1.3/kcwebps/common/autoload.py +188 -0
- kcwebps-1.3/kcwebps/common/model.py +198 -0
- kcwebps-1.3/kcwebps/config/__init__.py +6 -0
- kcwebps-1.3/kcwebps/config/app.py +51 -0
- kcwebps-1.3/kcwebps/config/database.py +28 -0
- kcwebps-1.3/kcwebps/config/other.py +2 -0
- kcwebps-1.3/kcwebps/config/redis.py +9 -0
- kcwebps-1.3/kcwebps/index/__init__.py +1 -0
- kcwebps-1.3/kcwebps/index/common/__init__.py +2 -0
- kcwebps-1.3/kcwebps/index/common/autoload.py +1 -0
- kcwebps-1.3/kcwebps/index/controller/__init__.py +2 -0
- kcwebps-1.3/kcwebps/index/controller/index/__init__.py +10 -0
- kcwebps-1.3/kcwebps/index/controller/index/admin.py +553 -0
- kcwebps-1.3/kcwebps/index/controller/index/common/__init__.py +2 -0
- kcwebps-1.3/kcwebps/index/controller/index/common/autoload.py +84 -0
- kcwebps-1.3/kcwebps/index/controller/index/common/model.py +93 -0
- kcwebps-1.3/kcwebps/index/controller/index/common/plantask.py +159 -0
- kcwebps-1.3/kcwebps/index/controller/index/index.py +220 -0
- kcwebps-1.3/kcwebps/index/controller/index/menu.py +52 -0
- kcwebps-1.3/kcwebps/index/controller/index/modular.py +103 -0
- kcwebps-1.3/kcwebps/index/controller/index/mysocket.py +205 -0
- kcwebps-1.3/kcwebps/index/controller/index/plan.py +69 -0
- kcwebps-1.3/kcwebps/index/controller/index/plug.py +188 -0
- kcwebps-1.3/kcwebps/index/controller/index/pub.py +104 -0
- kcwebps-1.3/kcwebps/index/controller/index/setup.py +590 -0
- kcwebps-1.3/kcwebps/index/controller/index/task.py +27 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/admin/admin.html +320 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/admin/adminlog.html +247 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/admin/blacklistrole.html +217 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/admin/index.html +93 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/admin/role.html +217 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/index/home.html +275 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/index/index.html +529 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/menu/index.html +212 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/modular/index.html +244 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/plan/index.html +417 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/plug/index.html +247 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/setup/bacrecpage.html +210 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/setup/basepage.html +246 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/setup/index.html +100 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/setup/pythonrun.html +366 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/setup/startpage.html +172 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/socket/index.html +127 -0
- kcwebps-1.3/kcwebps/index/controller/index/tpl/task/index.html +258 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/admin/index.html +252 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/include/static.html +11 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/index/home.html +287 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/index/index.html +343 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/menu/index.html +49 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/modular/index.html +180 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/plan/index.html +49 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/plug/index.html +187 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/setup/bacrecpage.html +172 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/setup/basepage.html +108 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/setup/index.html +58 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/setup/pythonrun.html +289 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/setup/startpage.html +142 -0
- kcwebps-1.3/kcwebps/index/controller/index/tplm/task/index.html +106 -0
- kcwebps-1.3/kcwebps/kcwebps.py +49 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/__init__.py +4 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/common/__init__.py +2 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/common/file/config.conf +1 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/common/file/sqlite/app +0 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/common/file/sqlite/index_index +0 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/common/html/error.html +44 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/common/html/include/static.html +23 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/common/html/login.html +69 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/intapp/__init__.py +1 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/intapp/common/__init__.py +3 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/intapp/common/autoload.py +1 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/intapp/controller/__init__.py +12 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/intapp/controller/index/__init__.py +1 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/intapp/controller/index/common/__init__.py +1 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/intapp/controller/index/common/autoload.py +1 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/intapp/controller/index/index.py +4 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/runtime/cachepath/plan/README.md +1 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/runtime/log/README.md +1 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/runtime/session/temp/README.md +1 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/app/static/README.md +1 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/server.bat +7 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/server.py +13 -0
- kcwebps-1.3/kcwebps/tempfile/kcwebps/server.sh +4 -0
- kcwebps-1.3/kcwebps.egg-info/PKG-INFO +13 -0
- kcwebps-1.3/kcwebps.egg-info/SOURCES.txt +174 -0
- kcwebps-1.3/kcwebps.egg-info/dependency_links.txt +1 -0
- kcwebps-1.3/kcwebps.egg-info/entry_points.txt +3 -0
- kcwebps-1.3/kcwebps.egg-info/requires.txt +7 -0
- kcwebps-1.3/kcwebps.egg-info/top_level.txt +56 -0
- kcwebps-1.3/setup.cfg +4 -0
- kcwebps-1.3/setup.py +58 -0
kcwebps-1.3/PKG-INFO
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 1.2
|
|
2
|
+
Name: kcwebps
|
|
3
|
+
Version: 1.3
|
|
4
|
+
Summary: kcwebps是建立在 kcwebs 框架的基础上研发的一套 linux 服务器容器系统
|
|
5
|
+
Home-page: https://docs.kwebapp.cn/index/index/3
|
|
6
|
+
Author: 百里-坤坤
|
|
7
|
+
Author-email: kcwebs@kwebapp.cn
|
|
8
|
+
Maintainer: 百里
|
|
9
|
+
Maintainer-email: fk1402936534@qq.com
|
|
10
|
+
License: Apache License 2.0
|
|
11
|
+
Description: kcwebps是建立在 kcwebs 框架的基础上研发的一套 linux 服务器容器系统,其目的是为了解决可视化部署和架构的过程,系统本身是一款服务端管理软件,通过 web 可视化方式管理服务器,提升运维效率
|
|
12
|
+
Keywords: kcwebps1.3
|
|
13
|
+
Platform: UNKNOWN
|
kcwebps-1.3/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<h1> <span style="color:#409EFF">linux</span>linux集成运维应用</h1>
|
|
4
|
+
|
|
5
|
+
kcwebps是建立在 kcwebs 框架的基础上研发的一套 linux 服务器容器系统,其目的是为了解决可视化部署和架构的过程,系统本身是一款服务端管理软件,通过 web 可视化方式管理服务器,提升运维效率。如:可视化软件安装,nginx 可视化部署,php在线安装等,这都这是 kcwebps 的一个插件,关于该系统的更多功能可以参考文档,文档也有提供体验账号和密码,该系统后期也在进行不断的升级和维护,kcwebps继程kcwebs,所有kcwebps同样支持模块和插件定制
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
[完整文档](https://docs.kwebapp.cn/index/index/3 "文档")
|
|
9
|
+
|
|
10
|
+
<!-- 您可以通过以下命令进行安装
|
|
11
|
+
````
|
|
12
|
+
pip install kcwebps>=3
|
|
13
|
+
````
|
|
14
|
+
然后通过以下命令运行项目
|
|
15
|
+
````
|
|
16
|
+
kcwebps server
|
|
17
|
+
````
|
|
18
|
+
|
|
19
|
+
如果是linux系统 使用以下命令
|
|
20
|
+
````
|
|
21
|
+
yum install -y wget && wget https://file.kwebapp.cn/sh/install/intapp/kcwebps3.sh && bash kcwebps3.sh
|
|
22
|
+
````
|
|
23
|
+
如果是linux系统 会自动运行 -->
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
__version__ = '1.3'
|
|
3
|
+
kcwebpsinfo={}
|
|
4
|
+
kcwebpsinfo['name']='kcwebps' #项目的名称
|
|
5
|
+
kcwebpsinfo['version']=__version__ #项目版本
|
|
6
|
+
kcwebpsinfo['description']='kcwebps是建立在 kcwebs 框架的基础上研发的一套 linux 服务器容器系统' #项目的简单描述
|
|
7
|
+
kcwebpsinfo['long_description']='kcwebps是建立在 kcwebs 框架的基础上研发的一套 linux 服务器容器系统,其目的是为了解决可视化部署和架构的过程,系统本身是一款服务端管理软件,通过 web 可视化方式管理服务器,提升运维效率' #项目详细描述
|
|
8
|
+
kcwebpsinfo['license']='Apache License 2.0' #开源协议
|
|
9
|
+
kcwebpsinfo['url']='https://docs.kwebapp.cn/index/index/3'
|
|
10
|
+
kcwebpsinfo['author']='百里-坤坤' #名字
|
|
11
|
+
kcwebpsinfo['author_email']='kcwebs@kwebapp.cn' #邮件地址
|
|
12
|
+
kcwebpsinfo['maintainer']='百里' #维护人员的名字
|
|
13
|
+
kcwebpsinfo['maintainer_email']='fk1402936534@qq.com' #维护人员的邮件地址
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from .model import *
|
|
3
|
+
import math,random,socket,chardet
|
|
4
|
+
|
|
5
|
+
kcwebps_path_common=os.path.split(os.path.realpath(__file__))[0]
|
|
6
|
+
response.kcwebps_path_common=kcwebps_path_common
|
|
7
|
+
if get_sysinfo()['uname'][0]=='Linux':
|
|
8
|
+
config.app['appmode']='produc'
|
|
9
|
+
def getSignContent(params):
|
|
10
|
+
"字典排序"
|
|
11
|
+
param={}
|
|
12
|
+
for i in sorted (params) :
|
|
13
|
+
param[i]=params[i]
|
|
14
|
+
i=0
|
|
15
|
+
strs=""
|
|
16
|
+
for k in param:
|
|
17
|
+
if k:
|
|
18
|
+
if isinstance(k,dict):
|
|
19
|
+
k=json_encode(k)
|
|
20
|
+
k=k.replace('"', '')
|
|
21
|
+
k=k.replace("'", '')
|
|
22
|
+
if param[k]:
|
|
23
|
+
if i==0:
|
|
24
|
+
strs+=str(k)+"="+str(param[k])
|
|
25
|
+
else:
|
|
26
|
+
strs+="&"+str(k)+"="+str(param[k])
|
|
27
|
+
i+=1
|
|
28
|
+
return strs
|
|
29
|
+
def getsign(params):
|
|
30
|
+
"获取签名"
|
|
31
|
+
if is_index(params,'sign'):
|
|
32
|
+
del params['sign']
|
|
33
|
+
content=getSignContent(params)
|
|
34
|
+
# print(content)
|
|
35
|
+
return md5(content)
|
|
36
|
+
def exsignpra(self,params):
|
|
37
|
+
"生成签名参数"
|
|
38
|
+
params['time']=times()
|
|
39
|
+
params['rands']=randoms()
|
|
40
|
+
params['sign']=getsign(params)
|
|
41
|
+
return params
|
|
42
|
+
def checksign(params,validity=3600):
|
|
43
|
+
if not is_index(params,'sign') or not is_index(params,'time') or not is_index(params,'rands'):
|
|
44
|
+
return -16,'签名参数错误'
|
|
45
|
+
sign=params['sign']
|
|
46
|
+
del params['sign']
|
|
47
|
+
sjc=times()-int(params['time'])
|
|
48
|
+
if sjc>validity or sjc<-3600:
|
|
49
|
+
return -14,'时间错误,请调整设备时间'
|
|
50
|
+
mysign=getsign(params)
|
|
51
|
+
if sign==mysign:
|
|
52
|
+
return 1,'签名验证成功'
|
|
53
|
+
else:
|
|
54
|
+
if is_index(params,'appkey'):
|
|
55
|
+
params['appkey']='appkey'
|
|
56
|
+
if is_index(params,'paympassword'):
|
|
57
|
+
params['paympassword']='paympassword'
|
|
58
|
+
if is_index(params,'loginpwd'):
|
|
59
|
+
params['loginpwd']='loginpwd'
|
|
60
|
+
content=getSignContent(params)
|
|
61
|
+
return -15,'签名错误,签名内容可参考:md5('+content+')'
|
|
62
|
+
|
|
63
|
+
def serlogin(username,sign,timestamp,random,types="session"):
|
|
64
|
+
"""登录方法
|
|
65
|
+
|
|
66
|
+
username
|
|
67
|
+
|
|
68
|
+
sign
|
|
69
|
+
|
|
70
|
+
timestamp
|
|
71
|
+
|
|
72
|
+
random
|
|
73
|
+
|
|
74
|
+
types 登录类型 session浏览器默认会话登录 否则返回account_token
|
|
75
|
+
"""
|
|
76
|
+
account_token=''
|
|
77
|
+
if (times()-int(timestamp))>3600 or times()-int(timestamp)<-3600:
|
|
78
|
+
return False,3,"时间戳错误",account_token
|
|
79
|
+
inifo=sqlite('admin',model_app_path).where([('username','eq',username),'or',('phone','eq',username)]).find()
|
|
80
|
+
if not inifo:
|
|
81
|
+
return False,2,"用户名错误",account_token
|
|
82
|
+
# if inifo['id']>100:
|
|
83
|
+
# return False,-1,"您不是管理员账号",account_token
|
|
84
|
+
usign=md5(str(inifo['username'])+str(inifo['password'])+str(timestamp)+str(random))
|
|
85
|
+
if usign!=sign:
|
|
86
|
+
return False,2,"密码错误",account_token
|
|
87
|
+
inifo['role']=sqlite("role",model_app_path).where('id',inifo['role']).find()
|
|
88
|
+
if is_index(inifo,'blacklistrole'):
|
|
89
|
+
inifo['blacklistrole']=sqlite("blacklistrole",model_app_path).where('id',inifo['blacklistrole']).find()
|
|
90
|
+
else:
|
|
91
|
+
inifo['blacklistrole']=[]
|
|
92
|
+
sqlite('admin',model_app_path).where('id',inifo['id']).update({'logintime':times()})
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
#根据权限给当前登录用户初始化菜单
|
|
96
|
+
systemrolelist=[ #系统菜单权限
|
|
97
|
+
{'title':'首页','icon':config.domain['kcwebsimg']+'/icon/home.png','url':'/index/index/index/home',"types":"left","pid":0,"admin_id":inifo['id'],"sort":10000},
|
|
98
|
+
{'title':'管理员','icon':config.domain['kcwebsimg']+'/icon/admin.png','url':'/index/index/admin',"types":"left","pid":0,"admin_id":inifo['id'],"sort":10000},
|
|
99
|
+
{'title':'模块管理','icon':config.domain['kcwebsimg']+'/icon/modular.png','url':'/index/index/modular',"types":"left","pid":0,"admin_id":inifo['id'],"sort":10000},
|
|
100
|
+
{'title':'插件管理','icon':config.domain['kcwebsimg']+'/icon/plug.png','url':'/index/index/plug',"types":"left","pid":0,"admin_id":inifo['id'],"sort":10000},
|
|
101
|
+
{'title':'系统配置','icon':config.domain['kcwebsimg']+'/icon/setup.png','url':'/index/index/setup',"types":"left","pid":0,"admin_id":inifo['id'],"sort":10000}
|
|
102
|
+
]
|
|
103
|
+
plugmenu=sqlite('plug',model_app_path).select()
|
|
104
|
+
for k in plugmenu: #插件菜单权限
|
|
105
|
+
if not is_index(k,'menu'):
|
|
106
|
+
k['menu']=1
|
|
107
|
+
if k['menu']==1 and k['name']!='index':
|
|
108
|
+
systemrolelist.append({'title':k['title'],'icon':k['icon'],'url':'/'+k['modular']+'/'+k['name'],"types":"left","pid":0,"admin_id":inifo['id'],"sort":1000})
|
|
109
|
+
if inifo['role']:
|
|
110
|
+
rolelist=[]
|
|
111
|
+
if inifo['role']['id']==1: #开拓者权限
|
|
112
|
+
rolelist=systemrolelist
|
|
113
|
+
else:
|
|
114
|
+
for k in systemrolelist:
|
|
115
|
+
for kk in json_decode(inifo['role']['roleroute']):
|
|
116
|
+
# strs=kk.split("/")
|
|
117
|
+
# print(k['url'],kk)
|
|
118
|
+
# if k['url'] in kk:
|
|
119
|
+
# rolelist.append(k)
|
|
120
|
+
if k['url'] in kk:
|
|
121
|
+
# rolelist.append(k)
|
|
122
|
+
tttt=True
|
|
123
|
+
for ttt in rolelist:
|
|
124
|
+
if ttt['title'] == k['title']:
|
|
125
|
+
tttt=False
|
|
126
|
+
break
|
|
127
|
+
if tttt:
|
|
128
|
+
rolelist.append(k)
|
|
129
|
+
if len(rolelist):
|
|
130
|
+
urlstr="0"
|
|
131
|
+
for k in systemrolelist:
|
|
132
|
+
urlstr+=",'"+k['url']+"'"
|
|
133
|
+
sqlite("menu",model_app_path).where("admin_id="+str(inifo['id'])+" and url in ("+urlstr+")").delete()
|
|
134
|
+
sqlite("menu",model_app_path).insert(rolelist)
|
|
135
|
+
if types=='session': #如果使用sess登录,要分配系统菜单权限
|
|
136
|
+
set_session("userinfo",inifo)
|
|
137
|
+
else:
|
|
138
|
+
account_token=md5(str(username)+str(inifo['password']))
|
|
139
|
+
set_cache(account_token,inifo,86400)
|
|
140
|
+
G.userinfo=inifo
|
|
141
|
+
return True,0,"登录成功",account_token
|
|
142
|
+
def check_role():
|
|
143
|
+
t=request.getroutecomponent()
|
|
144
|
+
ts="/"+t[1]+"/"+t[2]+"/"+t[3]+"/"+t[4]
|
|
145
|
+
if G.userinfo['role']:
|
|
146
|
+
roleroute=json_decode(G.userinfo['role']['roleroute'])
|
|
147
|
+
else:
|
|
148
|
+
roleroute=[]
|
|
149
|
+
if G.userinfo['blacklistrole']:
|
|
150
|
+
blacklistrole=json_decode(G.userinfo['blacklistrole']['roleroute'])
|
|
151
|
+
else:
|
|
152
|
+
blacklistrole=[]
|
|
153
|
+
#判断权限黑名单
|
|
154
|
+
status=True
|
|
155
|
+
for k in blacklistrole:
|
|
156
|
+
if k in ts:
|
|
157
|
+
status=False
|
|
158
|
+
break
|
|
159
|
+
if not status:
|
|
160
|
+
if 'GET' == request.HEADER.Method() and not request.args.get('account_token'):
|
|
161
|
+
return response.tpl("/common/html/error",title="无权访问",content="抱歉...,当前页面被黑名单拦截",imgsrc=config.domain['kcwebsimg']+"/icon/suo.png",status="401 error")
|
|
162
|
+
else:
|
|
163
|
+
return errorjson(msg="该操作被黑名单拦截。\r\n"+ts,status="401")
|
|
164
|
+
if ts != '/index/index/index/index' and ts != '/index/index/index/menu' and G.userinfo['role']['id'] !=1:
|
|
165
|
+
status=False
|
|
166
|
+
for k in roleroute:
|
|
167
|
+
if k in ts:
|
|
168
|
+
status=True
|
|
169
|
+
break
|
|
170
|
+
if not status:
|
|
171
|
+
if 'GET' == request.HEADER.Method() and not request.args.get('account_token'):
|
|
172
|
+
return response.tpl("/common/html/error",title="无权访问",content="抱歉...,您当前没有此页面访问权限,请联系管理员",imgsrc=config.domain['kcwebsimg']+"/icon/suo.png",status="401 error")
|
|
173
|
+
else:
|
|
174
|
+
return errorjson(msg="您没有以下接口访问权限,可联系管理员申请。\r\n"+ts,status="401")
|
|
175
|
+
def check_login():
|
|
176
|
+
"检查是否登录"
|
|
177
|
+
if not config.app['cli']:#终端运行时取消登录验证
|
|
178
|
+
G.setadminlog=""
|
|
179
|
+
account_token=request.args.get('account_token')
|
|
180
|
+
if account_token:
|
|
181
|
+
G.userinfo=get_cache(account_token)
|
|
182
|
+
if not G.userinfo:
|
|
183
|
+
return errorjson(code=5,msg='account_token已失效,请重新获取')
|
|
184
|
+
# elif request.args.get('logintype')=='sign':
|
|
185
|
+
# sign=request.args.get('sign')
|
|
186
|
+
# timestr=request.args.get('time')
|
|
187
|
+
# rands=request.args.get('rands')
|
|
188
|
+
# username=request.args.get('username')
|
|
189
|
+
# inifo=sqlite('admin',model_app_path).where([('username','eq',username),'or',('phone','eq',username)]).find()
|
|
190
|
+
# if not inifo:
|
|
191
|
+
# return errorjson(code=-2,msg='intapp用户名错误')
|
|
192
|
+
# code,msg=checksign(params={
|
|
193
|
+
# 'sign':sign,'time':timestr,'rands':rands,'username':username,'loginpwd':inifo['password']
|
|
194
|
+
# })
|
|
195
|
+
# if code!=1:
|
|
196
|
+
# return errorjson(code=code,msg=msg)
|
|
197
|
+
else:
|
|
198
|
+
G.userinfo=get_session("userinfo")
|
|
199
|
+
if not G.userinfo:
|
|
200
|
+
if 'GET' == request.HEADER.Method():
|
|
201
|
+
return response.tpl('/common/html/login')
|
|
202
|
+
else:
|
|
203
|
+
return errorjson(code=-2,msg='登录失效,请登录后操作')
|
|
204
|
+
return check_role()
|
|
205
|
+
def before_request():
|
|
206
|
+
"""请求拦截,
|
|
207
|
+
|
|
208
|
+
进行登录验证,权限验证
|
|
209
|
+
"""
|
|
210
|
+
if request.HEADER.Method()=='OPTIONS':
|
|
211
|
+
return successjson()
|
|
212
|
+
else:
|
|
213
|
+
return check_login()
|
|
214
|
+
def after_request(body,status,resheader):
|
|
215
|
+
"响应拦截"
|
|
216
|
+
if status=='200 ok':
|
|
217
|
+
if G.userinfo: #记录操作日志
|
|
218
|
+
method=request.HEADER.Method()
|
|
219
|
+
if method!="GET":
|
|
220
|
+
t=request.getroutecomponent()
|
|
221
|
+
modular=t[1]
|
|
222
|
+
plug=t[2]
|
|
223
|
+
controller=t[3]
|
|
224
|
+
function=t[4]
|
|
225
|
+
routeparam=json_encode(list(t[5]))
|
|
226
|
+
t1=request.HEADER.URL().split("?")
|
|
227
|
+
if len(t1)>1:
|
|
228
|
+
getparam="?"+t1[1:][0]
|
|
229
|
+
else:
|
|
230
|
+
getparam=""
|
|
231
|
+
dataparam=request.get_data()
|
|
232
|
+
if dataparam:
|
|
233
|
+
sqlite("admin_log",model_app_path).insert({
|
|
234
|
+
"user_id":G.userinfo['id'],
|
|
235
|
+
"title":G.setadminlog,
|
|
236
|
+
"method":method,
|
|
237
|
+
"modular":modular,
|
|
238
|
+
"plug":plug,
|
|
239
|
+
"controller":controller,
|
|
240
|
+
"function":function,
|
|
241
|
+
"routeparam":routeparam,
|
|
242
|
+
"getparam":getparam,
|
|
243
|
+
"dataparam":dataparam,
|
|
244
|
+
"remote_addr":request.HEADER.Physical_IP(),
|
|
245
|
+
"addtime":times()
|
|
246
|
+
})
|
|
247
|
+
G.setadminlog=""
|
|
248
|
+
G.userinfo=None
|
|
249
|
+
def return_list(lists,count,pagenow,pagesize):
|
|
250
|
+
"""返回分页列表
|
|
251
|
+
|
|
252
|
+
lists 数据库列表数据
|
|
253
|
+
|
|
254
|
+
count 数据库总数量
|
|
255
|
+
|
|
256
|
+
pagenow 页码
|
|
257
|
+
|
|
258
|
+
pagesize 每页数量
|
|
259
|
+
"""
|
|
260
|
+
if count:
|
|
261
|
+
pagecount=math.ceil(int(count)/int(pagesize))
|
|
262
|
+
else:
|
|
263
|
+
pagecount=0
|
|
264
|
+
data={
|
|
265
|
+
'count':int(count),
|
|
266
|
+
'pagenow':int(pagenow),
|
|
267
|
+
'pagesize':int(pagesize),
|
|
268
|
+
'pagecount':pagecount,
|
|
269
|
+
'lists':lists
|
|
270
|
+
}
|
|
271
|
+
return data
|
|
272
|
+
def successjson(data=[],code=0,msg="成功",status='200 ok',cache=False):
|
|
273
|
+
"""成功说在浏览器输出包装过的json
|
|
274
|
+
|
|
275
|
+
参数 data 结果 默认[]
|
|
276
|
+
|
|
277
|
+
参数 code body状态码 默认0
|
|
278
|
+
|
|
279
|
+
参数 msg body状态描述 默认 成功
|
|
280
|
+
|
|
281
|
+
参数 status http状态码 默认 200
|
|
282
|
+
|
|
283
|
+
参数 cache 是否启用浏览器缓存(状态码304缓存)
|
|
284
|
+
|
|
285
|
+
返回 json字符串结果集
|
|
286
|
+
"""
|
|
287
|
+
res={
|
|
288
|
+
"code":code,
|
|
289
|
+
"msg":msg,
|
|
290
|
+
"time":int(time.time()),
|
|
291
|
+
"data":data
|
|
292
|
+
}
|
|
293
|
+
return response.json(res,status,response_cache=cache,header={"Access-Control-Allow-Methods":"POT,POST,GET,DELETE,OPTIONS","Access-Control-Allow-Credentials":"true","Content-Type":"text/json; charset=utf-8","Access-Control-Allow-Origin":"*"})
|
|
294
|
+
def errorjson(data=[],code=1,msg="失败",status='400 error',cache=False):
|
|
295
|
+
"""错误时在浏览器输出包装过的json
|
|
296
|
+
|
|
297
|
+
参数 data 结果 默认[]
|
|
298
|
+
|
|
299
|
+
参数 code body状态码 默认0
|
|
300
|
+
|
|
301
|
+
参数 msg body状态描述 默认 成功
|
|
302
|
+
|
|
303
|
+
参数 status http状态码 默认 200
|
|
304
|
+
|
|
305
|
+
参数 cache 是否启用浏览器缓存(状态码304缓存)
|
|
306
|
+
|
|
307
|
+
返回 json字符串结果集
|
|
308
|
+
"""
|
|
309
|
+
return successjson(data=data,code=code,msg=msg,status=status,cache=cache)
|
|
310
|
+
def randoms(lens=6,types=1):
|
|
311
|
+
"""生成随机字符串
|
|
312
|
+
|
|
313
|
+
lens 长度
|
|
314
|
+
|
|
315
|
+
types 1数字 2字母 3字母加数字
|
|
316
|
+
"""
|
|
317
|
+
strs="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM,!@#$%^&*()_+=-;',./:<>?"
|
|
318
|
+
if types==1:
|
|
319
|
+
strs="0123456789"
|
|
320
|
+
elif types==2:
|
|
321
|
+
strs="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
|
|
322
|
+
elif types==3:
|
|
323
|
+
strs="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
|
|
324
|
+
k=''
|
|
325
|
+
i=0
|
|
326
|
+
while i < lens:
|
|
327
|
+
k+=random.choice(strs)
|
|
328
|
+
i+=1
|
|
329
|
+
return k
|
|
330
|
+
def set_session(name,value,expire=None):
|
|
331
|
+
"设置session"
|
|
332
|
+
return session.set("app"+str(name),value,expire)
|
|
333
|
+
def get_session(name):
|
|
334
|
+
"获取session"
|
|
335
|
+
return session.get("app"+str(name))
|
|
336
|
+
def del_session(name):
|
|
337
|
+
"删除session"
|
|
338
|
+
return session.rm("app"+str(name))
|
|
339
|
+
def file_get_content(filename,encoding=False):
|
|
340
|
+
"""获取文件内容
|
|
341
|
+
|
|
342
|
+
filename 完整文件名
|
|
343
|
+
|
|
344
|
+
encoding 是否返回文件编码 默认否
|
|
345
|
+
"""
|
|
346
|
+
fileData=''
|
|
347
|
+
cur_encoding="utf-8"
|
|
348
|
+
if os.path.isfile(filename):
|
|
349
|
+
with open(filename, 'rb') as f:
|
|
350
|
+
cur_encoding = chardet.detect(f.read())['encoding']
|
|
351
|
+
#用获取的编码读取该文件而不是python3默认的utf-8读取。
|
|
352
|
+
with open(filename,encoding=cur_encoding) as file:
|
|
353
|
+
fileData = file.read()
|
|
354
|
+
if encoding:
|
|
355
|
+
return fileData,cur_encoding
|
|
356
|
+
else:
|
|
357
|
+
return fileData
|
|
358
|
+
def file_set_content(k,data,encoding="utf-8"):
|
|
359
|
+
f=open(k,'w',encoding=encoding)
|
|
360
|
+
f.write(data)
|
|
361
|
+
f.close()
|
|
362
|
+
return True
|
|
363
|
+
class system_start:
|
|
364
|
+
"系统启动项"
|
|
365
|
+
def lists(pagenow=1,pagesize=20,where=None):
|
|
366
|
+
"启动项列表"
|
|
367
|
+
lists=sqlite().connect(model_app_path).where(where).table("start").order("id asc").page(pagenow,pagesize).select()
|
|
368
|
+
count=sqlite().connect(model_app_path).where(where).table("start").count()
|
|
369
|
+
return lists,count
|
|
370
|
+
def count(where=None):
|
|
371
|
+
"启动项数量"
|
|
372
|
+
return sqlite().connect(model_app_path).where(where).table("start").count()
|
|
373
|
+
def insert_Boot_up(cmd,name="系统添加",types="shell",icon="",admin_id=0):
|
|
374
|
+
"添加开机启动命令"
|
|
375
|
+
if types not in ['shell','kcwebps']:
|
|
376
|
+
return False
|
|
377
|
+
if 'Linux' in get_sysinfo()['uname'][0]:
|
|
378
|
+
if sqlite("start").connect(model_app_path).where("value",cmd).count():
|
|
379
|
+
return False
|
|
380
|
+
if types=='shell':
|
|
381
|
+
insert_system_up(cmd=cmd)
|
|
382
|
+
sqlite("start").connect(model_app_path).insert({"name":name,"types":types,"value":cmd,"icon":icon,"admin_id":admin_id,"addtime":times(),"updtime":times()})
|
|
383
|
+
return True
|
|
384
|
+
else:
|
|
385
|
+
return False
|
|
386
|
+
def del_Boot_up(cmd,vague=False,id=False):
|
|
387
|
+
"""删除开机启动命令
|
|
388
|
+
|
|
389
|
+
vague 是否模糊匹配
|
|
390
|
+
"""
|
|
391
|
+
if id:
|
|
392
|
+
where=[("id","eq",id)]
|
|
393
|
+
if 'Linux' in get_sysinfo()['uname'][0]:
|
|
394
|
+
del_system_up(cmd=cmd,vague=vague)
|
|
395
|
+
if vague:
|
|
396
|
+
if not id:
|
|
397
|
+
where=[("value","like","%"+str(cmd)+"%")]
|
|
398
|
+
else:
|
|
399
|
+
if not id:
|
|
400
|
+
where=[("value","eq",cmd)]
|
|
401
|
+
sqlite("start").connect(model_app_path).where(where).delete()
|
|
402
|
+
return True
|
|
403
|
+
else:
|
|
404
|
+
return False
|
|
405
|
+
g_local_ip=''
|
|
406
|
+
def get_local_ip():
|
|
407
|
+
"获取内网ip"
|
|
408
|
+
global g_local_ip
|
|
409
|
+
if g_local_ip:
|
|
410
|
+
return g_local_ip
|
|
411
|
+
try:
|
|
412
|
+
socket_objs = [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]
|
|
413
|
+
ip_from_ip_port = [(s.connect(("8.8.8.8", 53)), s.getsockname()[0], s.close()) for s in socket_objs][0][1]
|
|
414
|
+
ip_from_host_name = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1]
|
|
415
|
+
g_local_ip = [l for l in (ip_from_ip_port, ip_from_host_name) if l][0]
|
|
416
|
+
except (Exception) as e:
|
|
417
|
+
print("get_local_ip found exception : %s" % e)
|
|
418
|
+
return g_local_ip if("" != g_local_ip and None != g_local_ip) else socket.gethostbyname(socket.gethostname())
|
|
419
|
+
|
|
420
|
+
def sysisphone():
|
|
421
|
+
"判断是不是手机端访问"
|
|
422
|
+
HTTP_USER_AGENT=request.HEADER.GET()['HTTP_USER_AGENT']
|
|
423
|
+
if "Android" in HTTP_USER_AGENT or 'iPhone' in HTTP_USER_AGENT:
|
|
424
|
+
return True
|
|
425
|
+
else:
|
|
426
|
+
return False
|
|
427
|
+
|
|
428
|
+
if os.path.isfile("app/common/file/config.conf"):
|
|
429
|
+
kcwebsapidata=json_decode(file_get_content("app/common/file/config.conf"))
|
|
430
|
+
if is_index(kcwebsapidata,'kcwebsapi'):
|
|
431
|
+
if is_index(kcwebsapidata['kcwebsapi'],"host") and kcwebsapidata['kcwebsapi']['host']:
|
|
432
|
+
config.domain['kcwebsapi']=kcwebsapidata['kcwebsapi']['host']
|
|
433
|
+
if is_index(kcwebsapidata['kcwebsapi'],"filehost") and kcwebsapidata['kcwebsapi']['filehost']:
|
|
434
|
+
config.domain['kcwebsfile']=kcwebsapidata['kcwebsapi']['filehost']
|
|
435
|
+
if is_index(kcwebsapidata['system'],'staticurl') and kcwebsapidata['system']['staticurl']:
|
|
436
|
+
config.domain['kcwebsstatic']=kcwebsapidata['system']['staticurl']
|
|
437
|
+
if config.domain['kcwebsstatic'][-1:]=='/':
|
|
438
|
+
config.domain['kcwebsstatic']=config.domain['kcwebsstatic'][:-1]
|
|
439
|
+
|
|
440
|
+
def get_kcwebps_folder():
|
|
441
|
+
'获取kcwebps框架目录'
|
|
442
|
+
return (os.path.split(os.path.realpath(__file__))[0][:-7]).replace('\\','/')
|