| 10 | |
| 11 | |
| 12 | class RealServerProxy: |
| 13 | panel_path = "/www/server/panel" |
| 14 | default_headers = ( |
| 15 | "Host", "X-Real-IP", "X-Forwarded-For", "REMOTE-HOST", "X-Host", "X-Scheme", "Upgrade", "Connection" |
| 16 | ) |
| 17 | |
| 18 | def __init__(self, project_data: dict): |
| 19 | self.config_prefix: str = "java_" |
| 20 | |
| 21 | site_name = project_data["name"] |
| 22 | self.project_id = project_data["id"] |
| 23 | self.project_config = project_data["project_config"] |
| 24 | |
| 25 | self._config: Optional[List[dict]] = None |
| 26 | self._ng_file: str = "{}/vhost/nginx/{}{}.conf".format(self.panel_path, self.config_prefix, site_name) |
| 27 | self._ap_file: str = "{}/vhost/apache/{}{}.conf".format(self.panel_path, self.config_prefix, site_name) |
| 28 | self.site_name = site_name |
| 29 | self.ws_type = public.get_webserver() |
| 30 | |
| 31 | @staticmethod |
| 32 | def new_id() -> str: |
| 33 | from uuid import uuid4 |
| 34 | return uuid4().hex[::3] |
| 35 | |
| 36 | @property |
| 37 | def config(self) -> List[dict]: |
| 38 | if self._config is None: |
| 39 | if "proxy_info" in self.project_config: |
| 40 | self._config = self.project_config["proxy_info"] |
| 41 | else: |
| 42 | self._config = [] |
| 43 | |
| 44 | return self._config |
| 45 | |
| 46 | def save_config(self): |
| 47 | if self._config is not None: |
| 48 | self.project_config["proxy_info"] = self._config |
| 49 | public.M("sites").where("id=?", (self.project_id,)).update( |
| 50 | {"project_config": json.dumps(self.project_config)} |
| 51 | ) |
| 52 | |
| 53 | # 检查代理是否存在 |
| 54 | def _check_even(self, proxy_conf: dict, is_modify) -> Optional[str]: |
| 55 | if is_modify is True: |
| 56 | for i in self.config: |
| 57 | if i["proxy_dir"] == proxy_conf["proxy_dir"] and i["proxy_id"] != proxy_conf["proxy_id"]: |
| 58 | return '指定反向代理名称或代理文件夹已存在' |
| 59 | if i["proxy_port"] == proxy_conf["proxy_port"] and i["proxy_id"] != proxy_conf["proxy_id"]: |
| 60 | return '指定反向代理端口已存在对应的代理' |
| 61 | else: |
| 62 | for i in self.config: |
| 63 | if i["proxy_port"] == proxy_conf["proxy_port"]: |
| 64 | return '指定反向代理端口已存在对应的代理' |
| 65 | |
| 66 | def check_args(self, get, is_modify=False) -> Union[str, dict]: |
| 67 | err_msg = check_server_config() |
| 68 | if isinstance(err_msg, str): |
| 69 | return 'WEB服务器配置配置文件错误ERROR:<br><font style="color:red;">' + \ |
no outgoing calls
no test coverage detected