Commit b4c13ad8 authored by BH's avatar BH

添加入参解析方法

parent 3071123f
...@@ -313,7 +313,7 @@ class AppConfig(BaseAppConfig): ...@@ -313,7 +313,7 @@ class AppConfig(BaseAppConfig):
self.set_default('database::mysql-password', 'password', 'mysql-password=password') self.set_default('database::mysql-password', 'password', 'mysql-password=password')
self.set_default('plugin::core_host', '127.0.0.1', 'core_host=127.0.0.1') self.set_default('plugin::core_host', '127.0.0.1', 'core_host=127.0.0.1')
self.set_default('plugin::consul', '127.0.0.1', 'consul=http://172.30.10.128:6010') self.set_default('plugin::consul', '127.0.0.1', 'consul=http://172.30.20.128:6010')
self.set_default('plugin::release_ip', '127.0.0.1', 'release_ip=127.0.0.1') self.set_default('plugin::release_ip', '127.0.0.1', 'release_ip=127.0.0.1')
self.set_default('plugin::server', '127.0.0.1', 'server=127.0.0.1') self.set_default('plugin::server', '127.0.0.1', 'server=127.0.0.1')
self.set_default('plugin::manager_host', 'http://121.196.33.88:5566', 'manager_host=http://121.196.33.88:5566') self.set_default('plugin::manager_host', 'http://121.196.33.88:5566', 'manager_host=http://121.196.33.88:5566')
......
...@@ -308,6 +308,7 @@ controllers = [ ...@@ -308,6 +308,7 @@ controllers = [
# websocket for real-time information # websocket for real-time information
(r'/plugin/exe_download_url', plugin.ExeDownloadHandler), (r'/plugin/exe_download_url', plugin.ExeDownloadHandler),
# ws-client call 'http://ip:7190/ws/action/' # ws-client call 'http://ip:7190/ws/action/'
(r'/ws/(.*)', ws.WebSocketHandler), (r'/ws/(.*)', ws.WebSocketHandler),
(r'/.*', index.CatchAllHandler), (r'/.*', index.CatchAllHandler),
] ]
......
...@@ -52,7 +52,12 @@ def login(path, username, password, host): ...@@ -52,7 +52,12 @@ def login(path, username, password, host):
def add_site(site, host): def add_site(site, host):
# 添加站點 """
添加站点
:param site: 站点名称
:param host: 站点地址
:return:
"""
url = "http://{}/site?action=AddSite".format(host) url = "http://{}/site?action=AddSite".format(host)
user = 'sql{}'.format(site.replace(".", "_")) user = 'sql{}'.format(site.replace(".", "_"))
webname = json.dumps({"domain": site, "domainlist": [], "count": 1}) webname = json.dumps({"domain": site, "domainlist": [], "count": 1})
...@@ -70,6 +75,12 @@ def add_site(site, host): ...@@ -70,6 +75,12 @@ def add_site(site, host):
def del_site(ip, site): def del_site(ip, site):
"""
删除站点
:param ip:
:param site:
:return:
"""
url = "http://{}/data?action=getData".format(ip) url = "http://{}/data?action=getData".format(ip)
data = {"tojs": "site.get_list", "table": "sites", "limit": 15, "p": 1, "search": "", "order": "id desc", data = {"tojs": "site.get_list", "table": "sites", "limit": 15, "p": 1, "search": "", "order": "id desc",
"type": -1} "type": -1}
...@@ -85,28 +96,32 @@ def del_site(ip, site): ...@@ -85,28 +96,32 @@ def del_site(ip, site):
def install_dbshop(site, host): def install_dbshop(site, host):
"""
安装 dbshop 商城
:param site:
:param host:
:return:
"""
url = "http://{}/deployment?action=GetList".format(host) url = "http://{}/deployment?action=GetList".format(host)
data = {"type": 0} data = {"type": 0}
session.post(url, data) session.post(url, data)
# 一键部署接口
url = "http://{}/deployment?action=SetupPackage".format(host) url = "http://{}/deployment?action=SetupPackage".format(host)
data = {"dname": "DBShop", "site_name": site, "php_version": "56"} data = {"dname": "DBShop", "site_name": site, "php_version": "56"}
i = 0 i = 0
while True: for i in range(3):
resp = session.post(url, data=data) resp = session.post(url, data=data)
if resp.status_code == 200: if resp.status_code == 200:
break break
i += 1
if i > 3:
break
time.sleep(10) time.sleep(10)
# {"status": true, "msg": {"db_config": "", "run_path": "/", "php_versions": "54,55,56,70,71,72,73", "admin_username": "", "success_url": "/install", "chmod": [], "remove_file": [], "php_ext": ["fileinfo"], "admin_password": ""}} # {"status": true, "msg": {"db_config": "", "run_path": "/", "php_versions": "54,55,56,70,71,72,73", "admin_username": "", "success_url": "/install", "chmod": [], "remove_file": [], "php_ext": ["fileinfo"], "admin_password": ""}}
# http://121.196.33.88:8888/deployment?action=GetSpeed # http://121.196.33.88:8888/deployment?action=GetSpeed
# {"pre": 0, "total": 0, "speed": 0, "name": "\u5b89\u88c5\u5fc5\u8981\u7684PHP\u6269\u5c55", "used": 0} # {"pre": 0, "total": 0, "speed": 0, "name": "\u5b89\u88c5\u5fc5\u8981\u7684PHP\u6269\u5c55", "used": 0}
pre = 1 pre = 1
while pre != 0: # 初次调用,下载文件包
for i in range(20):
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)
...@@ -119,6 +134,11 @@ def install_dbshop(site, host): ...@@ -119,6 +134,11 @@ def install_dbshop(site, host):
def mysql_root_pwd(ip): def mysql_root_pwd(ip):
"""
mysql root 密码获取
:param ip:
:return:
"""
url = "http://{}/data?action=getKey".format(ip) url = "http://{}/data?action=getKey".format(ip)
data = {"table": "config", "key": "mysql_root", "id": "1"} data = {"table": "config", "key": "mysql_root", "id": "1"}
resp = session.post(url, data) resp = session.post(url, data)
...@@ -128,7 +148,13 @@ def mysql_root_pwd(ip): ...@@ -128,7 +148,13 @@ def mysql_root_pwd(ip):
def shop_config(host, site, webname="DBShop电子商务系统"): def shop_config(host, site, webname="DBShop电子商务系统"):
pwd = mysql_root_pwd(host) """
商城初始化相关接口
:param host:
:param site:
:param webname:
:return:
"""
host = host.replace(":8888", "") host = host.replace(":8888", "")
# 等待时间让网页进行加载 # 等待时间让网页进行加载
time.sleep(10) time.sleep(10)
...@@ -144,16 +170,11 @@ def shop_config(host, site, webname="DBShop电子商务系统"): ...@@ -144,16 +170,11 @@ def shop_config(host, site, webname="DBShop电子商务系统"):
resp = session.post(url, data) resp = session.post(url, data)
i = 0 i = 0
while True: for i in range(5):
resp = session.post(url, data=data) resp = session.post(url, data=data)
print("check db", url, data, resp.content) print("check db", url, data, resp.content)
if resp.text != "false": if resp.text != "false":
break break
i += 1
if i > 5:
break
time.sleep(10) time.sleep(10)
if resp.text == "false": if resp.text == "false":
...@@ -175,6 +196,11 @@ def shop_config(host, site, webname="DBShop电子商务系统"): ...@@ -175,6 +196,11 @@ def shop_config(host, site, webname="DBShop电子商务系统"):
def check_shop(site): def check_shop(site):
"""
确认商城安装情况
:param site:
:return:
"""
url = "http://{}".format(site) url = "http://{}".format(site)
try: try:
resp = requests.get(url) resp = requests.get(url)
...@@ -195,6 +221,11 @@ def get_domain(ip, id): ...@@ -195,6 +221,11 @@ def get_domain(ip, id):
def check_all_domain(ip): def check_all_domain(ip):
"""
检查宝塔下所有的站点
:param ip:
:return:
"""
url = "http://{}/data?action=getData".format(ip) url = "http://{}/data?action=getData".format(ip)
# tojs=site.get_list&table=sites&limit=15&p=1&search=&order=id desc&type=-1 # tojs=site.get_list&table=sites&limit=15&p=1&search=&order=id desc&type=-1
data = {"tojs": "site.get_list", "table": "sites", "limit": 15, "p": 1, "search": "", "order": "id desc", data = {"tojs": "site.get_list", "table": "sites", "limit": 15, "p": 1, "search": "", "order": "id desc",
...@@ -219,6 +250,11 @@ def check_all_domain(ip): ...@@ -219,6 +250,11 @@ def check_all_domain(ip):
def sub_domain(site): def sub_domain(site):
"""
子域名处理
:param site:
:return:
"""
if site.count('.') == 1: if site.count('.') == 1:
pay_site = 'pay.' + site pay_site = 'pay.' + site
else: else:
...@@ -377,6 +413,14 @@ def install_shop(ip, site, webname): ...@@ -377,6 +413,14 @@ def install_shop(ip, site, webname):
def add_site_domain(id, ip, site, webname): def add_site_domain(id, ip, site, webname):
"""
将域名添加至站点
:param id:
:param ip:
:param site:
:param webname:
:return:
"""
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)
...@@ -389,6 +433,13 @@ def add_site_domain(id, ip, site, webname): ...@@ -389,6 +433,13 @@ def add_site_domain(id, ip, site, webname):
def add_nginx(ip, id, site): def add_nginx(ip, id, site):
"""
修改 nginx 配置
:param ip:
:param id:
:param site:
:return:
"""
sites = get_domain(ip, id) sites = get_domain(ip, id)
url = "http://{}/files?action=GetFileBody".format(ip) url = "http://{}/files?action=GetFileBody".format(ip)
...@@ -410,7 +461,12 @@ def add_nginx(ip, id, site): ...@@ -410,7 +461,12 @@ def add_nginx(ip, id, site):
def check_ssl(ip, sub_domain): def check_ssl(ip, sub_domain):
# 获取已部署证书 """
获取已部署证书
:param ip:
:param sub_domain:
:return:
"""
url = "http://{}/ssl?action=GetCertList".format(ip) url = "http://{}/ssl?action=GetCertList".format(ip)
resp = session.post(url) resp = session.post(url)
...@@ -421,7 +477,13 @@ def check_ssl(ip, sub_domain): ...@@ -421,7 +477,13 @@ def check_ssl(ip, sub_domain):
def set_old_ssl(ip, site, cert_name): def set_old_ssl(ip, site, cert_name):
# 部署已存在证书 """
已存在域名证书,直接使用
:param ip:
:param site:
:param cert_name:
:return:
"""
url = "http://{}/ssl?action=SetCertToSite".format(ip) url = "http://{}/ssl?action=SetCertToSite".format(ip)
data = {"certName": cert_name, "siteName": site} data = {"certName": cert_name, "siteName": site}
resp = session.post(url, data) resp = session.post(url, data)
...@@ -449,7 +511,14 @@ def start_https(ip, site): ...@@ -449,7 +511,14 @@ def start_https(ip, site):
def set_ssl(ip, site, id, sub_domain): def set_ssl(ip, site, id, sub_domain):
# 已部署证书的不再部署 """
部署 https 证书
:param ip:
:param site:
:param id:
:param sub_domain:
:return:
"""
if ssl_status(ip, site): if ssl_status(ip, site):
return return
...@@ -496,14 +565,9 @@ def run(ip, path, user, pwd, site, webname, sub_domain=""): ...@@ -496,14 +565,9 @@ def run(ip, path, user, pwd, site, webname, sub_domain=""):
print(login(path, user, pwd, ip)) print(login(path, user, pwd, ip))
print("完成宝塔登录配置") print("完成宝塔登录配置")
# if check_shop(site):
# print("商城已存在")
# return
shop_id, name = check_all_domain(ip) shop_id, name = check_all_domain(ip)
if shop_id: if shop_id:
print("商城已存在", shop_id, "name", name) print("商城已存在", shop_id, "name", name)
add_site_domain(shop_id, ip, ip.replace(":8888", ""), name)
add_site_domain(shop_id, ip, site, name) add_site_domain(shop_id, ip, site, name)
if sub_domain: if sub_domain:
add_site_domain(shop_id, ip, sub_domain, name) add_site_domain(shop_id, ip, sub_domain, name)
...@@ -545,7 +609,3 @@ def main(): ...@@ -545,7 +609,3 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()
# run("34.92.159.68:8888", path='9f57b254', pwd='950bc7da', site='pay.xamsmsm.com', user='ppvtidah',
# webname='测试', sub_domain="pay.xamsmsm.com")
# print(login(path, user, pwd, ip))
# set_ssl(ip, "34.92.159.68", 5, "pay.xamsmsm.com")
This diff is collapsed.
...@@ -97,18 +97,15 @@ def auto_install_bt(ip, username, password, site, webname, sub="", host_id=0): ...@@ -97,18 +97,15 @@ def auto_install_bt(ip, username, password, site, webname, sub="", host_id=0):
update_shop_info(site, webname, remark="宝塔初始化完成", url=url, username=username, password=password) update_shop_info(site, webname, remark="宝塔初始化完成", url=url, username=username, password=password)
print("install_bt", result) print("install_bt", result)
i = 0 i = 0
while i < 2: for i in range(2):
print('*************************************************************************************')
result = install_shop(ssh, site, ip, webname, sub) result = install_shop(ssh, site, ip, webname, sub)
print("install_shop", result)
i += 1
if "商城已存在" in result: if "商城已存在" in result:
print("商城已存在") print("商城已存在")
update_shop_info(site, webname, host_id, status=1, remark="商城已存在", url=url, username=username, update_shop_info(site, webname, host_id, status=1, remark="商城已存在", url=url, username=username,
password=password) password=password)
break break
ssl_remark, ssl_status = "", 0
if "配置商城成功" in result or "商城已存在" in result: if "配置商城成功" in result or "商城已存在" in result:
print("更新商城信息") print("更新商城信息")
if "申请HTTPS证书成功" in result or "HTTPS证书已存在" in result: if "申请HTTPS证书成功" in result or "HTTPS证书已存在" in result:
...@@ -118,9 +115,6 @@ def auto_install_bt(ip, username, password, site, webname, sub="", host_id=0): ...@@ -118,9 +115,6 @@ def auto_install_bt(ip, username, password, site, webname, sub="", host_id=0):
ssl_remark = between(result, "new ssl response:[", "]\n") ssl_remark = between(result, "new ssl response:[", "]\n")
ssl_remark = json.loads(ssl_remark)['msg'][0] ssl_remark = json.loads(ssl_remark)['msg'][0]
ssl_status = 2 ssl_status = 2
else:
ssl_remark = ""
ssl_status = 0
update_shop_info(site, webname, host_id, status=1, remark="商城部署成功", url=url, username=username, update_shop_info(site, webname, host_id, status=1, remark="商城部署成功", url=url, username=username,
password=password, ssl_remark=ssl_remark, ssl_status=ssl_status) password=password, ssl_remark=ssl_remark, ssl_status=ssl_status)
......
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