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
efab041e
Commit
efab041e
authored
May 29, 2020
by
tarak.li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修正 window 与 linux 远程的区分
parent
c5034271
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
22 deletions
+52
-22
auto_install.py
server/www/teleport/webroot/app/controller/auto_install.py
+7
-10
plugin.py
server/www/teleport/webroot/app/controller/plugin.py
+38
-6
script.py
server/www/teleport/webroot/app/controller/script.py
+7
-6
No files found.
server/www/teleport/webroot/app/controller/auto_install.py
View file @
efab041e
...
...
@@ -59,7 +59,7 @@ def add_site(site, host):
"webname"
:
webname
,
"ftp"
:
"false"
,
"sql"
:
"true"
,
"address"
:
"localhost"
,
"codeing"
:
"utf8"
}
resp
=
session
.
post
(
url
,
data
=
data
)
print
(
resp
.
tex
t
)
print
(
resp
.
conten
t
)
# 正常添加返回
# {"ftpStatus": false, "databaseUser": "sql121_196_33_88", "databaseStatus": true, "databasePass": "123456", "siteId": 6, "siteStatus": true}
# 异常添加返回
...
...
@@ -79,7 +79,7 @@ def del_site(ip, site):
# data = "id=1&webname=site"
data
=
{
"database"
:
1
,
"path"
:
1
,
"webname"
:
site
,
"id"
:
item
.
get
(
"id"
)}
resp
=
session
.
post
(
url
,
data
)
print
(
resp
.
tex
t
)
print
(
resp
.
conten
t
)
def
install_dbshop
(
site
,
host
):
...
...
@@ -92,7 +92,7 @@ def install_dbshop(site, host):
i
=
0
while
True
:
resp
=
session
.
post
(
url
,
data
=
data
)
print
(
url
,
data
,
resp
.
tex
t
)
print
(
url
,
data
,
resp
.
conten
t
)
if
resp
.
status_code
==
200
:
break
...
...
@@ -110,7 +110,7 @@ def install_dbshop(site, host):
url
=
"http://{}/deployment?action=GetSpeed"
.
format
(
host
)
resp
=
session
.
get
(
url
)
pre
=
resp
.
json
()
.
get
(
"pre"
,
1
)
print
(
"GetSpeed"
,
resp
.
tex
t
)
print
(
"GetSpeed"
,
resp
.
conten
t
)
if
pre
==
0
:
break
time
.
sleep
(
5
)
...
...
@@ -145,7 +145,7 @@ def shop_config(host, site, webname="DBShop电子商务系统"):
i
=
0
while
True
:
resp
=
session
.
post
(
url
,
data
=
data
)
print
(
url
,
data
,
resp
.
tex
t
)
print
(
url
,
data
,
resp
.
conten
t
)
if
resp
.
text
!=
"false"
:
break
...
...
@@ -159,7 +159,7 @@ def shop_config(host, site, webname="DBShop电子商务系统"):
print
(
"数据库配置失败"
)
return
False
print
(
"数据库配置成功"
,
resp
.
tex
t
)
print
(
"数据库配置成功"
,
resp
.
conten
t
)
url
=
"http://{}/install/Install/installFinish/step_3"
.
format
(
host
)
data
=
{
'dbhost'
:
'localhost'
,
'dbname'
:
user
,
'dbuser'
:
user
,
'dbpasswd'
:
'123456'
,
...
...
@@ -187,7 +187,6 @@ def get_domain(ip, id):
url
=
"http://{}/data?action=getData"
.
format
(
ip
)
data
=
{
"table"
:
"domain"
,
"list"
:
True
,
"search"
:
id
}
resp
=
session
.
post
(
url
,
data
)
print
(
"get_domain"
,
[
i
.
get
(
"name"
,
""
)
for
i
in
resp
.
json
()],
resp
.
text
)
return
[
i
.
get
(
"name"
,
""
)
for
i
in
resp
.
json
()]
...
...
@@ -330,7 +329,6 @@ def update_nginx(ip, site):
url
=
"http://{}/files?action=GetFileBody"
.
format
(
ip
)
data
=
{
"path"
:
"/www/server/panel/vhost/nginx/{}.conf"
.
format
(
site
)}
resp
=
session
.
post
(
url
,
data
)
print
(
"nginx"
,
resp
.
text
)
pay_site
=
sub_domain
(
site
)
body
=
nginx_conf
(
site
,
pay_site
,
site
)
...
...
@@ -376,14 +374,13 @@ def add_nginx(ip, id, site):
url
=
"http://{}/files?action=GetFileBody"
.
format
(
ip
)
data
=
{
"path"
:
"/www/server/panel/vhost/nginx/{}.conf"
.
format
(
site
)}
resp
=
session
.
post
(
url
,
data
)
print
(
"nginx"
,
resp
.
text
)
main_domain
=
' '
.
join
(
sites
)
pay_domain
=
' '
.
join
([
sub_domain
(
domain
)
for
domain
in
sites
])
print
(
"domain"
,
main_domain
,
"pay_domain"
,
pay_domain
)
body
=
nginx_conf
(
main_domain
,
pay_domain
,
site
)
print
(
"body"
,
body
)
url
=
"http://{}/files?action=SaveFileBody"
.
format
(
ip
)
# encoding: utf-8
data
=
{
"data"
:
body
,
"path"
:
"/www/server/panel/vhost/nginx/{}.conf"
.
format
(
site
),
"encoding"
:
"utf-8"
}
...
...
server/www/teleport/webroot/app/controller/plugin.py
View file @
efab041e
...
...
@@ -93,15 +93,16 @@ def is_ipv4(address):
def
execute_auto_install_script
(
ip
,
usename
,
password
,
site
,
webname
,
host_id
):
path
=
os
.
path
.
dirname
(
__file__
)
cmd
=
'nohup /usr/bin/python3 {}/script.py --ip {} -u {} -p {} -s {} -w {} &'
.
format
(
path
,
ip
,
usename
,
password
,
path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
cmd
=
'nohup /usr/bin/python3 {}/script.py --ip {} -u {} -p {} -s {} -w {} >> auto.out &'
.
format
(
path
,
ip
,
usename
,
password
,
site
,
webname
)
os
.
system
(
cmd
)
return
cmd
def
execute_add_proxy
(
ip
):
path
=
os
.
path
.
dirname
(
__file__
)
path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)
)
os
.
system
(
'nohup /usr/bin/python3 {}/clash_refresh.py --ip {} &'
.
format
(
path
,
ip
))
...
...
@@ -261,12 +262,18 @@ class UpdateHostHandler(TPBasePluginHandler):
host_id
=
resp
.
get
(
"data"
)
url
=
"http://127.0.0.1:7190/asset/update-account"
if
os_type
==
1
:
args
=
{
"args"
:
json
.
dumps
({
"host_id"
:
host_id
,
"acc_id"
:
-
1
,
"param"
:
{
"host_ip"
:
ip
,
"router_ip"
:
""
,
"router_port"
:
0
,
"protocol"
:
1
,
"port"
:
3389
,
"auth_type"
:
1
,
"username"
:
username
,
"password"
:
password
,
"pri_key"
:
""
,
"username_prompt"
:
""
,
"password_prompt"
:
""
}})
.
encode
()}
else
:
args
=
{
"args"
:
json
.
dumps
({
"host_id"
:
host_id
,
"acc_id"
:
-
1
,
"param"
:
{
"host_ip"
:
ip
,
"router_ip"
:
""
,
"router_port"
:
0
,
"protocol"
:
2
,
"port"
:
22
,
"auth_type"
:
1
,
"username"
:
username
,
"password"
:
password
,
"pri_key"
:
""
,
"username_prompt"
:
""
,
"password_prompt"
:
""
}})
.
encode
()}
# {"code": 0, "message": "", "data": 5}
# 带信息带先插入
...
...
@@ -342,11 +349,18 @@ class UpdateHostHandler(TPBasePluginHandler):
url
=
"http://127.0.0.1:7190/asset/update-account"
if
os_type
==
1
:
args
=
{
"args"
:
json
.
dumps
({
"host_id"
:
host_id
,
"acc_id"
:
acc_id
,
"param"
:
{
"host_ip"
:
ip
,
"router_ip"
:
""
,
"router_port"
:
0
,
"protocol"
:
1
,
"port"
:
3389
,
"auth_type"
:
1
,
"username"
:
username
,
"password"
:
password
,
"pri_key"
:
""
,
"username_prompt"
:
""
,
"password_prompt"
:
""
}})
.
encode
()}
else
:
args
=
{
"args"
:
json
.
dumps
({
"host_id"
:
host_id
,
"acc_id"
:
acc_id
,
"param"
:
{
"host_ip"
:
ip
,
"router_ip"
:
""
,
"router_port"
:
0
,
"protocol"
:
2
,
"port"
:
22
,
"auth_type"
:
1
,
"username"
:
username
,
"password"
:
password
,
"pri_key"
:
""
,
"username_prompt"
:
""
,
"password_prompt"
:
""
}})
.
encode
()}
# {"code": 0, "message": "", "data": 5}
# 带信息带先插入
...
...
@@ -499,11 +513,19 @@ class GetSessionInfoHandler(TPBasePluginHandler):
self
.
finish_json
(
1002
,
"未发现请求主机信息"
)
return
os_type
=
self
.
query
(
"host"
,
"os_type"
,
{
"id"
:
host_id
})
url
=
"http://127.0.0.1:7190/ops/get-session-id"
if
os_type
==
1
:
args
=
{
"args"
:
json
.
dumps
(
{
"mode"
:
2
,
"auth_id"
:
"none"
,
"acc_id"
:
info
,
"host_id"
:
host_id
,
"protocol_type"
:
1
,
"protocol_sub_type"
:
100
,
"rdp_width"
:
0
,
"rdp_height"
:
0
,
"rdp_console"
:
False
})
.
encode
()}
else
:
args
=
{
"args"
:
json
.
dumps
(
{
"mode"
:
2
,
"auth_id"
:
"none"
,
"acc_id"
:
info
,
"host_id"
:
host_id
,
"protocol_type"
:
2
,
"protocol_sub_type"
:
"200"
,
"rdp_width"
:
0
,
"rdp_height"
:
0
,
"rdp_console"
:
False
})
.
encode
()}
# 带信息带先插入
resp
=
await
self
.
request_api
(
url
,
args
)
...
...
@@ -514,10 +536,17 @@ class GetSessionInfoHandler(TPBasePluginHandler):
cfg
=
tp_cfg
()
core_host
=
cfg
.
plugin
.
core_host
# log.i("core_host:{}".format(core_host))
if
os_type
==
1
:
resp
=
{
"teleport_ip"
:
core_host
,
"teleport_port"
:
52089
,
"remote_host_ip"
:
ip
,
"session_id"
:
resp
.
get
(
"data"
,
{})
.
get
(
"session_id"
),
"protocol_type"
:
1
,
"protocol_sub_type"
:
100
,
"session_id"
:
resp
.
get
(
"data"
,
{})
.
get
(
"session_id"
),
"protocol_type"
:
1
,
"protocol_sub_type"
:
100
,
"protocol_flag"
:
resp
.
get
(
"data"
,
{})
.
get
(
"protocol_flag"
),
"rdp_width"
:
0
,
"rdp_height"
:
0
,
"rdp_console"
:
False
}
else
:
resp
=
{
"teleport_ip"
:
core_host
,
"teleport_port"
:
52189
,
"remote_host_ip"
:
ip
,
"session_id"
:
resp
.
get
(
"data"
,
{})
.
get
(
"session_id"
),
"protocol_type"
:
2
,
"protocol_sub_type"
:
200
,
"protocol_flag"
:
resp
.
get
(
"data"
,
{})
.
get
(
"protocol_flag"
)}
resp
=
"""http://localhost:50022/api/run/{}"""
.
format
(
json
.
dumps
(
resp
))
self
.
finish_json
(
0
,
data
=
[
resp
])
...
...
@@ -574,6 +603,7 @@ class BindPayAccountHandler(TPBasePluginHandler):
comp_id
,
biz_id
,
host_assigned
,
host_id
=
\
self
.
param_get
(
props
,
[
'comp_id'
,
'biz_id'
,
'host_assigned'
,
'host_id'
],
0
)
biz_id
=
biz_id
or
1
try
:
host_assigned
=
int
(
host_assigned
)
host_id
=
int
(
host_id
)
...
...
@@ -888,8 +918,10 @@ class ShopBindHandler(TPBasePluginHandler):
items
=
plugin
.
query_one
(
"remote_host"
,
[
'ip'
,
'username'
,
'password'
],
{
"id"
:
host_id
,
})
password
=
des_descrypt
(
items
.
get
(
"password"
,
""
))
.
decode
()
execute_auto_install_script
(
items
.
get
(
"ip"
,
""
),
items
.
get
(
"username"
,
""
),
password
,
domain
,
name
,
cmd
=
execute_auto_install_script
(
items
.
get
(
"ip"
,
""
),
items
.
get
(
"username"
,
""
),
password
,
domain
,
name
,
host_id
)
log
.
i
(
"自动部署商城:{}"
.
format
(
cmd
))
self
.
finish_json
(
0
)
return
...
...
server/www/teleport/webroot/app/controller/script.py
View file @
efab041e
...
...
@@ -47,7 +47,6 @@ def push_file(ip, username, password):
p
.
put
(
'{}/install-bt.sh'
.
format
(
path
),
'/root/install-bt.sh'
)
# 上传文件到远程机
p
.
put
(
'{}/auto_install.py'
.
format
(
path
),
'/root/auto_install.py'
)
# 上传文件到远程机
p
.
put
(
'{}/install-shop.sh'
.
format
(
path
),
'/root/install-shop.sh'
)
# 上传文件到远程机
# cat /root/install-bt.sh
finally
:
nimei
.
close
()
p
.
close
()
...
...
@@ -84,12 +83,14 @@ 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
)
if
"一键配置商城信息失败"
in
result
:
elif
"商城已存在"
in
result
:
update_shop_info
(
site
,
webname
,
host_id
,
status
=
1
,
remark
=
"商城已存在"
,
url
=
site
)
else
:
update_shop_info
(
site
,
webname
,
host_id
,
status
=
3
,
remark
=
"商城部署失败,请重试"
,
url
=
site
)
except
AuthenticationException
as
err
:
update_shop_info
(
site
,
webname
,
host_id
,
status
=
3
,
remark
=
"连接失败,请检查远程信息"
)
except
Exception
as
err
:
update_shop_info
(
site
,
webname
,
host_id
,
status
=
3
,
remark
=
"商城部署异常,请重试"
)
finally
:
# 关闭服务器连接
transport
.
close
()
...
...
@@ -111,6 +112,6 @@ def main():
if
__name__
==
'__main__'
:
# push_file('121.196.33.88', 'root', 'Aa123456')
auto_install_bt
(
'121.196.33.88'
,
'root'
,
'Aa123456'
,
"www.gingboutrade.com"
,
"测试商城
"
)
# auto_install_bt('34.92.159.68', 'root', 'Aa@123321', "34.92.159.68", "
")
# update_shop_info(site="www.test.com", webname="测试商城1", test="")
#
main()
main
()
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