Commit efab041e authored by tarak.li's avatar tarak.li

修正 window 与 linux 远程的区分

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