| |
| |
| |
| |
| |
| |
| |
| |
| |
| from typing import List, Dict, Tuple |
|
|
| import public, panelPush |
|
|
| try: |
| from BTPanel import cache |
| except: |
| from cachelib import SimpleCache |
| cache = SimpleCache() |
|
|
|
|
| class metaclass(type): |
| def __new__(cls, name, *args, **kwargs): |
| push_cls = super().__new__(cls, name, *args, **kwargs) |
| if name == "base_push": |
| return push_cls |
| else: |
| push_cls.all_push_model.append(push_cls) |
| return push_cls |
|
|
|
|
| class base_push(metaclass=metaclass): |
| all_push_model = [] |
|
|
| |
| def get_version_info(self, get=None): |
| raise NotImplementedError |
|
|
| |
| def get_push_cycle(self, data: dict): |
| return data |
|
|
| |
| def get_module_config(self, get: public.dict_obj): |
| raise NotImplementedError |
|
|
| |
| def get_push_config(self, get: public.dict_obj): |
| |
| raise NotImplementedError |
|
|
| |
| def set_push_config(self, get: public.dict_obj): |
| raise NotImplementedError |
|
|
| |
| def del_push_config(self, get: public.dict_obj): |
| |
| raise NotImplementedError |
|
|
| |
| def get_total(self): |
| return True |
|
|
| |
| def get_push_data(self, data, total): |
| |
| |
| |
| |
| raise NotImplementedError |
|
|
| |
| def get_task_template(self) -> Tuple[str, List[Dict]]: |
| |
| raise NotImplementedError |
|
|
| |
| def get_view_msg(self, task_id: str, task_data: dict) -> dict: |
| return task_data |
|
|
|
|
| class WxAccountMsgBase: |
|
|
| @classmethod |
| def new_msg(cls): |
| return cls() |
|
|
| def set_ip_address(self, server_ip, local_ip): |
| pass |
|
|
| def to_send_data(self): |
| return "", {} |
|
|
|
|
| class WxAccountMsg(WxAccountMsgBase): |
| def __init__(self): |
| self.ip_address: str = "" |
| self.thing_type: str = "" |
| self.msg: str = "" |
| self.next_msg: str = "" |
|
|
| def set_ip_address(self, server_ip, local_ip): |
| self.ip_address = "{}({})".format(server_ip, local_ip) |
| if len(self.ip_address) > 32: |
| self.ip_address = self.ip_address[:29] + "..." |
|
|
| def to_send_data(self): |
| res = { |
| "first": {}, |
| "keyword1": { |
| "value": self.ip_address, |
| }, |
| "keyword2": { |
| "value": self.thing_type, |
| }, |
| "keyword3": { |
| "value": self.msg, |
| } |
| } |
|
|
| if self.next_msg != "": |
| res["keyword4"] = {"value": self.next_msg} |
|
|
| return "", res |
|
|
|
|
| class WxAccountLoginMsg(WxAccountMsgBase): |
| tid = "RJNG8dBZ5Tb9EK6j6gOlcAgGs2Fjn5Fb07vZIsYg1P4" |
|
|
| def __init__(self): |
| self.login_name: str = "" |
| self.login_ip: str = "" |
| self.login_type: str = "" |
| self.address: str = "" |
| self._server_name: str = "" |
| self._server_ip = "" |
|
|
| def set_ip_address(self, server_ip, local_ip: str): |
| if local_ip != "127.0.0.1" and local_ip.startswith("192.168"): |
| self._server_ip = local_ip |
| else: |
| self._server_ip = server_ip |
| if self._server_name == "": |
| self._server_name = "服务器IP{}".format(server_ip) |
|
|
| def _get_server_name(self): |
| data = public.GetConfigValue("title") |
| if data == "宝塔Linux面板": |
| self._server_name = "宝塔面板({})".format(".".join(self._server_ip.split(".")[2:])) |
| elif data != "": |
| self._server_name = data |
|
|
| def to_send_data(self): |
| self._get_server_name() |
| if self.address.startswith(">归属地:"): |
| self.address = self.address[5:] |
| if self.address == "": |
| self.address = "未知的归属地" |
|
|
| if not public.is_ipv4(self.login_ip): |
| self.login_ip = "ipv6-can not show" |
| |
| res = { |
| "thing10": { |
| "value": self._server_name, |
| }, |
| "character_string9": { |
| "value": self.login_ip, |
| }, |
| "thing7": { |
| "value": self.login_type, |
| }, |
| "thing11": { |
| "value": self.address, |
| }, |
| "thing2": { |
| "value": self.login_name, |
| } |
| } |
| return self.tid, res |
|
|