MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / create_reverse_proxy

Function create_reverse_proxy

tools.py:907–970  ·  view source on GitHub ↗

@param get: @name 调用面板反向代理的模块创建 @author wzz <2024/5/29 下午6:00> @param "data":{"参数名":""} <数据类型> 参数描述 @return dict{"status":True/False,"msg":"提示信息"}

(get)

Source from the content-addressed store, hash-verified

905
906# 2024/5/29 下午5:58 调用面板反向代理的模块创建
907def create_reverse_proxy(get):
908 ''&#x27;
909 @param get:
910 @name 调用面板反向代理的模块创建
911 @author wzz <2024/5/29 下午6:00>
912 @param "data":{"参数名":""} <数据类型> 参数描述
913 @return dict{"status":True/False,"msg":"提示信息"}
914 ''&#x27;
915 from mod.project.proxy.comMod import main as proxyMod
916 pMod = proxyMod()
917
918 panel_port = public.readFile('data/port.pl')
919
920 try:
921 close_reverse_proxy()
922 __http = 'https' if os.path.exists("/www/server/panel/data/ssl.pl") else 'http'
923 if __http != "https":
924 CreateSSL()
925 __http = "https"
926
927 args = public.to_dict_obj({
928 "proxy_pass": "{}://127.0.0.1:{}".format(__http, panel_port),
929 "proxy_type": "http",
930 "domains": get.siteName,
931 "proxy_host": "$http_host",
932 "remark": "宝塔面板的反代[请误操作,修改可能会导致面板无法访问]"
933 })
934 create_result = pMod.create(args)
935 if not create_result['status']:
936 return public.returnResult(False, create_result['msg'])
937
938 # args.site_name = get.siteName
939 # args.auth_path = "/"
940 # args.username = public.GetRandomString(8).lower()
941 # args.password = public.GetRandomString(8).lower()
942 # if os.path.exists("data/http_auth.pwd"):
943 # public.ExecShell("rm -rf /www/server/panel/data/http_auth.pwd")
944 #
945 # public.writeFile("data/http_auth.pwd", args.password)
946 # args.name = public.GetRandomString(5)
947 #
948 # auth_result = pMod.add_dir_auth(args)
949 # if not create_result['status']:
950 # return public.returnResult(False, auth_result['msg'])
951
952 return_data = {
953 # "username": args.username,
954 # "password": args.password,
955 "siteName": get.siteName,
956 "http": __http
957 }
958 return public.returnResult(True, '添加成功', data=return_data)
959 except Exception as e:
960 result = public.M('sites').where("name=?", (get.siteName,)).find()
961 if not isinstance(result, dict):
962 return public.returnResult(False, '添加失败,可能是Nginx配置文件错误,请先检查后再设置!错误详情:{}!'.format(str(e)))
963
964 args = public.to_dict_obj({

Callers 1

bt_cliFunction · 0.70

Calls 11

readFileMethod · 0.80
returnResultMethod · 0.80
close_reverse_proxyFunction · 0.70
CreateSSLFunction · 0.70
existsMethod · 0.45
formatMethod · 0.45
createMethod · 0.45
findMethod · 0.45
whereMethod · 0.45
MMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected