(self, get)
| 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 | } |
no test coverage detected