Commit 88928a50 authored by tarak.li's avatar tarak.li

20200527 提测

parent 2d39fb27
......@@ -120,6 +120,7 @@ def install_dbshop(site, host):
break
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
# {"pre": 0, "total": 0, "speed": 0, "name": "\u5b89\u88c5\u5fc5\u8981\u7684PHP\u6269\u5c55", "used": 0}
......@@ -194,8 +195,10 @@ def check_shop(site):
url = "http://{}".format(site)
try:
resp = requests.get(url)
resp.encoding = "utf-8"
code = resp.status_code
return code == 200 and len(resp.text) > 2000
print("check_shop", resp.content)
return code == 200 and '用户中心' in resp.content and '登录' in resp.content
except:
code = 0
return False
......@@ -311,6 +314,32 @@ server {
return True
def install_shop(ip, site, webname):
del_site(ip, site)
add_site(site, ip)
print("添加站点成功")
install_dbshop(site, ip)
print("一键部署商城")
if shop_config(ip, site=site, webname=webname):
print("配置商城成功")
update_nginx(ip, site)
else:
print("一键配置商城信息失败")
def add_site_domain(id, ip, site, webname):
url = "http://{}/data?action=getData".format(ip)
data = {"table": "domain", "list": True, "search": id}
resp = session.post(url, data)
# domain=121.196.33.88&webname=www.gingboutrade.com&id=13
url = "http://{}/site?action=AddDomain".format(ip)
data = {"domain": site, "webname": webname, "id": id}
session.post(url, data)
print(resp.text)
return
def main():
parser = argparse.ArgumentParser()
# parser.add_argument("action", choices=['start', 'stop', 'restart'])
......@@ -329,19 +358,12 @@ def main():
path = args.path or ''
print(login(path, args.user, args.pwd, ip))
print("完成宝塔登录配置")
if check_shop(args.site):
print("商城已存在")
return
del_site(ip, args.site)
add_site(args.site, ip)
print("添加站点成功")
install_dbshop(args.site, ip)
print("一键部署商城")
if shop_config(ip, site=args.site):
print("配置商城成功")
update_nginx(ip, args.site)
else:
print("一键配置商城信息失败")
install_shop(ip, args.site, args.webname)
if __name__ == '__main__':
......
......@@ -31,8 +31,13 @@ def refre(path):
print(resp.status_code, resp.text)
def min_proxy():
def min_proxy(new_proxy):
_count = proxy_count()
for proxy in new_proxy:
name = proxy.get("name", "")
if name not in _count.keys():
_count[name] = 0
print(_count)
min_key = min(_count, key=lambda x: _count[x])
return min_key
......@@ -48,6 +53,8 @@ def read_conf():
def read_local_ip():
local_proxy = {}
dir_path = "/root/.config/clash/ip"
if not os.path.exists(dir_path):
return local_proxy
for root, dirs, files in os.walk(dir_path, topdown=False):
print(root, dirs, files)
for file in files:
......@@ -58,14 +65,42 @@ def read_local_ip():
return local_proxy
def update_local_proxy(conf, local):
proxy = conf.get("Proxy", [])
proxys = [item.get("name", "") for item in proxy]
print("proxys", proxys)
print(local)
_local = []
for k, v in local.items():
if k not in proxys and len(v.split(":")) == 2:
# {'cipher': 'aes-256-gcm', 'name': 'judy', 'password': '17ATvm1k', 'type': 'ss', 'port': '45678', 'server': '43.248.124.17'}
_p = {'cipher': 'aes-256-gcm', 'name': k, 'password': '17ATvm1k', 'type': 'ss', 'port': v.split(":")[1],
'server': v.split(":")[0]}
_local.append(_p)
proxy.extend(_local)
return proxy
def add_proxy(ip):
conf = read_conf()
proxy_name = min_proxy()
_local = read_local_ip()
new_proxy = update_local_proxy(conf, _local)
# proxys = proxy_count()
# 添加本地proxy,并获取使用最少的一个
proxy_name = min_proxy(new_proxy)
rule = conf.get("Rule", [])
new_rule = "IP-CIDR,{}/32,{}".format(ip, proxy_name)
new_rule = [new_rule]
new_rule.extend(rule)
if not [r for r in rule if ip in r]:
new_rule = "IP-CIDR,{}/32,{}".format(ip, proxy_name)
new_rule = [new_rule]
new_rule.extend(rule)
else:
new_rule = rule
conf["Rule"] = new_rule
conf["Proxy"] = new_proxy
path = "/root/.config/clash/config.yaml"
with open(path, 'w') as dumpfile:
......@@ -87,4 +122,5 @@ def main():
if __name__ == '__main__':
main()
# add_proxy("127.0.0.1")
# print(read_local_ip())
......@@ -18,12 +18,4 @@ if [ ! -f "/usr/bin/pip" ];then
else
echo "pip已安装"
fi
# /etc/init.d/bt default
# shell 脚本获取账户密码
var=$(/etc/init.d/bt default)
host=$(echo ${var#*8888/} | cut -c 1-8)
username=$(echo ${var#*username: } | cut -c 1-8)
password=$(echo ${var#*password: } | cut -c 1-8)
#/usr/bin/python /root/auto_install.py -u $username -p $password -s $1 --path $host --ip $2 -w $3 > /tmp/load.log 2>&1
/usr/bin/python /root/auto_install.py -u $username -p $password -s $1 --path $host --ip $2 -w $3
......@@ -25,5 +25,6 @@ host=$(echo ${var#*8888/} | cut -c 1-8)
username=$(echo ${var#*username: } | cut -c 1-8)
password=$(echo ${var#*password: } | cut -c 1-8)
#/usr/bin/python /root/auto_install.py -u $username -p $password -s $1 --path $host --ip $2 -w $3 > /tmp/load.log 2>&1
echo -u $username -p $password -s $1 --path $host --ip $2 -w $3
/usr/bin/python /root/auto_install.py -u $username -p $password -s $1 --path $host --ip $2 -w $3
......@@ -94,13 +94,15 @@ def is_ipv4(address):
def execute_auto_install_script(ip, usename, password, site, webname, host_id):
path = os.path.dirname(__file__)
os.system('nohup python3 {}/script.py --ip {} -u {} -p {} -s {} -w {} &'.format(path, ip, usename, password, site,
webname))
cmd = 'nohup /usr/bin/python3 {}/script.py --ip {} -u {} -p {} -s {} -w {} &'.format(path, ip, usename, password,
site, webname)
os.system(cmd)
return cmd
def execute_add_proxy(ip):
path = os.path.dirname(__file__)
os.system('nohup python3 {}/clash_refresh.py --ip {} &'.format(path, ip))
os.system('nohup /usr/bin/python3 {}/clash_refresh.py --ip {} &'.format(path, ip))
class TPBasePluginHandler(TPBaseHandler):
......@@ -376,7 +378,7 @@ class GetHostListHandler(TPBasePluginHandler):
async def post(self):
props = self.get_payload()
os_type, status, page_index, page_size = self.param_get(props, ['os_type', 'status', 'page_index', 'page_size'],
os_type, status, page_index, page_size = self.param_get(props, ['os_type', 'status', 'pageIndex', 'pageSize'],
0)
ip, name = self.param_get(props, ['ip', 'name', ], '')
......@@ -907,8 +909,9 @@ class ShopBindHandler(TPBasePluginHandler):
# finish 调用商城自动部署
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,
host_id)
cmd = execute_auto_install_script(items.get("ip", ""), items.get("username", ""), password, domain,
name, host_id)
log.i("自动部署商城:{}".format(cmd))
else:
self.finish_json(1002, "绑定商城信息失败")
......
......@@ -73,16 +73,18 @@ def auto_install_bt(ip, username, password, site, webname, host_id=0):
while i < 2:
print('*************************************************************************************')
result = install_shop(ssh, site, ip, webname)
print(result)
i += 1
if "配置商城成功" in result:
print("更新商城信息")
update_shop_info(site, webname, host_id, status=1, remark="商城部署成功", url=site)
break
if "商城已存在" in result:
print("商城已存在")
update_shop_info(site, webname, host_id, status=1, remark="商城已存在", url=site)
break
if "配置商城成功" in result:
print("更新商城信息")
update_shop_info(site, webname, host_id, status=1, remark="商城部署成功", url=site)
except AuthenticationException as err:
update_shop_info(site, webname, host_id, status=3, remark="连接失败,请检查远程信息")
finally:
......@@ -106,7 +108,6 @@ def main():
if __name__ == '__main__':
# push_file('121.196.33.88', 'root', 'Aa123456')
auto_install_bt('121.196.33.88', 'root', 'Aa123456', "121.196.33.88", "测试商城")
# auto_install_bt('121.196.33.88', 'root', 'Aa123456', "www.gingboutrade.com", "测试商城")
# 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