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

Method add_server_proxy

class/projectModel/pythonModel.py:3890–3951  ·  view source on GitHub ↗
(self, get)

Source from the content-addressed store, hash-verified

3888
3889 # 添加代理
3890 def add_server_proxy(self, get):
3891 if not hasattr(get, "site_name") or not get.site_name.strip():
3892 return json_response(status=False, msg="参数错误")
3893
3894 project_data = self.get_project_find(get.site_name)
3895 if not project_data:
3896 return json_response(False, "未找到项目")
3897
3898 status = get.get("status/d")
3899 proxy_path = get.get("proxy_path/s", "/")
3900 proxy_port = get.get("proxy_port/d", 0)
3901 if not 0 < proxy_port < 65535:
3902 return json_response(False, "请输入正确的端口范围")
3903 if not proxy_path.startswith("/"):
3904 proxy_path = "/" + proxy_path
3905 if not proxy_path.endswith("/"):
3906 proxy_path = proxy_path + "/"
3907
3908 # 不能包含../ 这样的不安全路由路径
3909 re_safe_uri = re.compile(r"\.\./")
3910 if re_safe_uri.search(proxy_path):
3911 return json_response(False, "请输入安全的路径")
3912
3913 file_path = "{}/nginx/python_{}.conf".format(self._vhost_path, get.site_name)
3914 config_file = public.readFile(file_path)
3915 if not isinstance(config_file, str):
3916 return json_response(False, "未找到配置文件,请先开启外网映射")
3917
3918 proxy_info = project_data["project_config"].setdefault("proxy_info", [])
3919
3920 for p_info in proxy_info:
3921 if p_info["proxy_port"] == proxy_port:
3922 p_info["proxy_path"] = proxy_path
3923 p_info["status"] = status
3924 break
3925 else:
3926 proxy_info.append({
3927 "proxy_path": proxy_path,
3928 "proxy_port": proxy_port,
3929 "status": status
3930 })
3931 default_port = project_data["project_config"].get("port", "")
3932 try:
3933 default_ports = [int(default_port)]
3934 except:
3935 default_ports = []
3936 listens = self._list_listen(self.get_project_run_state(get.site_name)) or default_ports
3937 for idx in range(len(proxy_info) - 1, -1, -1):
3938 p_info = proxy_info[idx]
3939 if not p_info["status"]:
3940 proxy_info.pop(idx)
3941 continue
3942 if p_info["proxy_port"] not in listens:
3943 proxy_info.pop(idx)
3944
3945 pdata = {
3946 "project_config": json.dumps(project_data["project_config"])
3947 }

Callers 1

start_java_projectMethod · 0.45

Calls 15

get_project_findMethod · 0.95
_list_listenMethod · 0.95
get_project_run_stateMethod · 0.95
set_configMethod · 0.95
json_responseFunction · 0.90
readFileMethod · 0.80
getMethod · 0.45
searchMethod · 0.45
formatMethod · 0.45
appendMethod · 0.45
popMethod · 0.45
dumpsMethod · 0.45

Tested by

no test coverage detected