diff --git a/uptimekumaapi/__init__.py b/uptimekumaapi/__init__.py index c13a6b9..2fde6a1 100644 --- a/uptimekumaapi/__init__.py +++ b/uptimekumaapi/__init__.py @@ -1,4 +1,5 @@ from .auth_method import AuthMethod from .monitor_type import MonitorType from .notification_providers import NotificationType, notification_provider_options +from .proxy_protocol import ProxyProtocol from .api import UptimeKumaApi diff --git a/uptimekumaapi/api.py b/uptimekumaapi/api.py index 1d2902c..8f66fdf 100644 --- a/uptimekumaapi/api.py +++ b/uptimekumaapi/api.py @@ -5,6 +5,7 @@ import socketio from . import AuthMethod from . import MonitorType from . import NotificationType, notification_provider_options +from . import ProxyProtocol class UptimeKumaApi(object): @@ -327,8 +328,40 @@ class UptimeKumaApi(object): def get_proxies(self): return self.get_event_data("proxyList") - def add_proxy(self): - pass + def add_proxy(self, *args, **kwargs): + data = self._build_proxy_data(*args, **kwargs) + return self.sio.call('addProxy', (data, None)) + + def edit_proxy(self, id_: int, *args, **kwargs): + data = self._build_proxy_data(*args, **kwargs) + return self.sio.call('addProxy', (data, id_)) + + def delete_proxy(self, id_: int): + return self.sio.call('deleteProxy', id_) + + def _build_proxy_data( + self, + protocol: ProxyProtocol, + host: str, + port: str, + auth: bool = False, + username: str = None, + password: str = None, + active: bool = True, + default: bool = False, + apply_existing: bool = False, + ): + return { + "protocol": protocol, + "host": host, + "port": port, + "auth": auth, + "username": username, + "password": password, + "active": active, + "default": default, + "applyExisting": apply_existing + } # status page diff --git a/uptimekumaapi/proxy_protocol.py b/uptimekumaapi/proxy_protocol.py new file mode 100644 index 0000000..93ccba4 --- /dev/null +++ b/uptimekumaapi/proxy_protocol.py @@ -0,0 +1,9 @@ +from enum import Enum + + +class ProxyProtocol(str, Enum): + HTTPS = "https" + HTTP = "http" + SOCKS = "socks" + SOCKS5 = "socks5" + SOCKS4 = "socks4"