Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
M
micro-remote
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tarak.li
micro-remote
Commits
981cc02a
Commit
981cc02a
authored
Jun 01, 2020
by
tarak.li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加宝塔面板截取及信息返回
parent
efab041e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
41 deletions
+55
-41
plugin.py
server/www/teleport/webroot/app/controller/plugin.py
+23
-36
script.py
server/www/teleport/webroot/app/controller/script.py
+32
-5
No files found.
server/www/teleport/webroot/app/controller/plugin.py
View file @
981cc02a
...
...
@@ -796,28 +796,6 @@ class AccountInfoHandler(TPBasePluginHandler):
class
ShopInfoHandler
(
TPBasePluginHandler
):
async
def
get
(
self
):
try
:
host_id
=
self
.
get_argument
(
"host_id"
,
0
)
try
:
host_id
=
int
(
host_id
)
except
:
self
.
finish_json
(
1001
,
"提交参数异常,请检查请求参数"
)
return
if
not
host_id
:
self
.
finish_json
(
1001
,
"缺少必填项"
)
return
items
=
plugin
.
query_one
(
"remote_shop_bind"
,
[
'name'
,
'domain'
,
'url'
,
'status'
],
{
"host_id"
:
host_id
})
if
items
:
self
.
finish_json
(
0
,
data
=
[
items
])
else
:
self
.
finish_json
(
0
,
data
=
[{}])
except
:
info
=
traceback
.
format_exc
()
log
.
e
(
"设备详情,异常信息:{}"
.
format
(
info
))
async
def
post
(
self
):
try
:
props
=
self
.
get_payload
()
...
...
@@ -833,8 +811,9 @@ class ShopInfoHandler(TPBasePluginHandler):
self
.
finish_json
(
1001
,
"缺少必填项"
)
return
items
=
plugin
.
query_one
(
"remote_shop_bind"
,
[
'name'
,
'domain'
,
'url'
,
'status'
,
'remark'
],
{
"host_id"
:
host_id
})
items
=
plugin
.
query_one
(
"remote_shop_bind"
,
[
'name'
,
'domain'
,
'url'
,
'status'
,
'remark'
,
'username'
,
'password'
,
'sub_domain'
,
'ssl_remark'
,
'ssl_status'
],
{
"host_id"
:
host_id
})
if
items
:
self
.
finish_json
(
0
,
data
=
[
items
])
else
:
...
...
@@ -845,6 +824,7 @@ class ShopInfoHandler(TPBasePluginHandler):
async
def
put
(
self
):
try
:
#
props
=
self
.
get_payload
()
domain
=
props
.
get
(
"domain"
)
or
""
name
=
props
.
get
(
"name"
)
or
""
...
...
@@ -864,6 +844,7 @@ class ShopInfoHandler(TPBasePluginHandler):
if
not
host_id
and
not
domain
and
not
name
:
self
.
finish_json
(
1001
,
"缺少必填项"
)
return
if
host_id
:
plugin
.
update
(
"tp_remote_shop_bind"
,
{
"url"
:
url
,
"status"
:
status
,
"username"
:
username
,
"password"
:
password
,
...
...
@@ -885,7 +866,7 @@ class ShopBindHandler(TPBasePluginHandler):
host_id
=
props
.
get
(
"host_id"
)
or
0
name
=
props
.
get
(
"name"
)
or
""
domain
=
props
.
get
(
"domain"
)
or
""
sub_domain
=
props
.
get
(
"sub_domain"
)
or
""
try
:
host_id
=
int
(
host_id
)
except
:
...
...
@@ -907,20 +888,21 @@ class ShopBindHandler(TPBasePluginHandler):
try
:
resp
=
requests
.
get
(
"http://{}"
.
format
(
domain
))
code
=
resp
.
status_code
if
code
==
200
and
'用户中心'
in
resp
.
content
and
'登录'
in
resp
.
content
:
self
.
finish_json
(
1003
,
"已存在绑定商城,不可重复绑定"
)
return
except
:
code
=
0
if
code
==
200
:
self
.
finish_json
(
1003
,
"已存在绑定商城,不可重复绑定"
)
return
plugin
.
update
(
"tp_remote_shop_bind"
,
{
"name"
:
name
,
"domain"
:
domain
},
{
"host_id"
:
host_id
})
plugin
.
update
(
"tp_remote_shop_bind"
,
{
"name"
:
name
,
"domain"
:
domain
,
"status"
:
1
,
"sub_domain"
:
sub_domain
},
{
"host_id"
:
host_id
})
items
=
plugin
.
query_one
(
"remote_host"
,
[
'ip'
,
'username'
,
'password'
],
{
"id"
:
host_id
,
})
password
=
des_descrypt
(
items
.
get
(
"password"
,
""
))
.
decode
()
cmd
=
execute_auto_install_script
(
items
.
get
(
"ip"
,
""
),
items
.
get
(
"username"
,
""
),
password
,
domain
,
name
,
host_id
)
name
,
host_id
)
log
.
i
(
"自动部署商城:{}"
.
format
(
cmd
))
self
.
finish_json
(
0
)
return
...
...
@@ -934,7 +916,7 @@ class ShopBindHandler(TPBasePluginHandler):
self
.
finish_json
(
1003
,
"仅支持Linux主机进行绑定"
)
return
args
=
{
"host_id"
:
host_id
,
"name"
:
name
,
"domain"
:
domain
,
"status"
:
0
}
args
=
{
"host_id"
:
host_id
,
"name"
:
name
,
"domain"
:
domain
,
"status"
:
0
,
"sub_domain"
:
sub_domain
}
err
,
info
=
plugin
.
add_shop_bind
(
self
,
args
)
if
err
==
TPE_OK
:
self
.
finish_json
(
0
,
"成功"
)
...
...
@@ -946,7 +928,6 @@ class ShopBindHandler(TPBasePluginHandler):
log
.
i
(
"自动部署商城:{}"
.
format
(
cmd
))
else
:
self
.
finish_json
(
1002
,
"绑定商城信息失败"
)
except
:
info
=
traceback
.
format_exc
()
log
.
e
(
"设备详情,异常信息:{}"
.
format
(
info
))
...
...
@@ -986,6 +967,7 @@ class ShopBindHandler(TPBasePluginHandler):
code
=
0
if
code
==
200
:
plugin
.
update
(
"tp_remote_shop_bind"
,
{
"status"
:
1
},
{
"host_id"
:
host_id
})
self
.
finish_json
(
1021
,
"运行中商城,不可变更"
)
return
...
...
@@ -1093,7 +1075,10 @@ class HostMonitorHandler(TPBasePluginHandler):
class
BatDownloadHandler
(
TPBasePluginHandler
):
async
def
get
(
self
):
try
:
self
.
finish_json
(
0
,
"成功"
,
data
=
[{
"url"
:
"http://121.196.33.88:5566/download/bat"
}])
# manager_host
cfg
=
tp_cfg
()
manager_host
=
cfg
.
plugin
.
manager_host
self
.
finish_json
(
0
,
"成功"
,
data
=
[{
"url"
:
"{}/download/bat"
.
format
(
manager_host
)}])
except
:
info
=
traceback
.
format_exc
()
log
.
e
(
"设备详情,异常信息:{}"
.
format
(
info
))
...
...
@@ -1102,7 +1087,9 @@ class BatDownloadHandler(TPBasePluginHandler):
class
ExeDownloadHandler
(
TPBasePluginHandler
):
async
def
get
(
self
):
try
:
self
.
finish_json
(
0
,
"成功"
,
data
=
[{
"url"
:
"http://121.196.33.88:5566/download/exe"
}])
cfg
=
tp_cfg
()
manager_host
=
cfg
.
plugin
.
manager_host
self
.
finish_json
(
0
,
"成功"
,
data
=
[{
"url"
:
"{}/download/exe"
.
format
(
manager_host
)}])
except
:
info
=
traceback
.
format_exc
()
log
.
e
(
"设备详情,异常信息:{}"
.
format
(
info
))
server/www/teleport/webroot/app/controller/script.py
View file @
981cc02a
...
...
@@ -10,6 +10,17 @@ import requests
executor
=
ThreadPoolExecutor
(
max_workers
=
100
)
def
between
(
source
,
begin_str
,
end_str
,
start
=
''
):
start_index
=
source
.
find
(
start
)
start_index
=
start_index
+
len
(
start
)
if
start_index
else
0
b
=
source
.
find
(
begin_str
,
start_index
)
if
end_str
:
e
=
source
.
find
(
end_str
,
b
+
len
(
begin_str
))
else
:
e
=
len
(
source
)
return
source
[
b
+
len
(
begin_str
):
e
]
def
update_shop_info
(
site
,
webname
,
host_id
=
0
,
status
=
2
,
**
kwargs
):
# url = "http://127.0.0.1:7190/plugin/shop_info"
data
=
{
"domain"
:
site
,
"name"
:
webname
,
"host_id"
:
host_id
,
"status"
:
status
}
...
...
@@ -38,6 +49,17 @@ def install_bt(ssh):
return
result
.
decode
()
def
get_bt_info
(
ssh
):
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
"/etc/init.d/bt default"
)
res
,
err
=
stdout
.
read
(),
stderr
.
read
()
result
=
res
if
res
else
err
result
=
result
.
decode
()
url
=
between
(
result
,
"Bt-Panel-URL: "
,
"username"
)
.
replace
(
"username"
,
""
)
.
strip
()
username
=
between
(
result
,
"username: "
,
"password"
)
.
replace
(
"password"
,
""
)
.
strip
()
password
=
between
(
result
,
"password: "
,
"Warning"
)[:
8
]
return
url
,
username
,
password
def
push_file
(
ip
,
username
,
password
):
nimei
=
paramiko
.
Transport
((
ip
,
22
))
nimei
.
connect
(
username
=
username
,
password
=
password
)
...
...
@@ -66,7 +88,8 @@ def auto_install_bt(ip, username, password, site, webname, host_id=0):
webname
=
webname
or
"DBShop电子商务系统"
update_shop_info
(
site
,
webname
,
remark
=
"开始下载宝塔"
)
result
=
install_bt
(
ssh
)
update_shop_info
(
site
,
webname
,
remark
=
"宝塔初始化完成"
)
url
,
username
,
password
=
get_bt_info
(
ssh
)
update_shop_info
(
site
,
webname
,
remark
=
"宝塔初始化完成"
,
url
=
url
,
username
=
username
,
password
=
password
)
print
(
result
)
i
=
0
while
i
<
2
:
...
...
@@ -77,16 +100,20 @@ def auto_install_bt(ip, username, password, site, webname, host_id=0):
if
"商城已存在"
in
result
:
print
(
"商城已存在"
)
update_shop_info
(
site
,
webname
,
host_id
,
status
=
1
,
remark
=
"商城已存在"
,
url
=
site
)
update_shop_info
(
site
,
webname
,
host_id
,
status
=
1
,
remark
=
"商城已存在"
,
url
=
url
,
username
=
username
,
password
=
password
)
break
if
"配置商城成功"
in
result
:
print
(
"更新商城信息"
)
update_shop_info
(
site
,
webname
,
host_id
,
status
=
1
,
remark
=
"商城部署成功"
,
url
=
site
)
update_shop_info
(
site
,
webname
,
host_id
,
status
=
1
,
remark
=
"商城部署成功"
,
url
=
url
,
username
=
username
,
password
=
password
)
elif
"商城已存在"
in
result
:
update_shop_info
(
site
,
webname
,
host_id
,
status
=
1
,
remark
=
"商城已存在"
,
url
=
site
)
update_shop_info
(
site
,
webname
,
host_id
,
status
=
1
,
remark
=
"商城已存在"
,
url
=
url
,
username
=
username
,
password
=
password
)
else
:
update_shop_info
(
site
,
webname
,
host_id
,
status
=
3
,
remark
=
"商城部署失败,请重试"
,
url
=
site
)
update_shop_info
(
site
,
webname
,
host_id
,
status
=
3
,
remark
=
"商城部署失败,请重试"
,
url
=
url
,
username
=
username
,
password
=
password
)
except
AuthenticationException
as
err
:
update_shop_info
(
site
,
webname
,
host_id
,
status
=
3
,
remark
=
"连接失败,请检查远程信息"
)
except
Exception
as
err
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment