Add NPMplus proxy hosts controls
This commit is contained in:
@@ -132,6 +132,48 @@ def fetch_certificates(cfg: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
return data
|
||||
|
||||
|
||||
def list_proxy_hosts(cfg: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
npm_cfg = cfg.get("npmplus", {})
|
||||
base_url = (npm_cfg.get("base_url") or "").rstrip("/")
|
||||
verify_tls = npm_cfg.get("verify_tls", True)
|
||||
if not base_url:
|
||||
raise ValueError("NPMplus base_url not configured")
|
||||
|
||||
token = _get_token(cfg)
|
||||
url = f"{base_url}/nginx/proxy-hosts"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {token}",
|
||||
"User-Agent": "tg-admin-bot",
|
||||
}
|
||||
data = _request_json(url, headers, None, verify_tls)
|
||||
if not isinstance(data, list):
|
||||
raise RuntimeError("Unexpected API response")
|
||||
return data
|
||||
|
||||
|
||||
def set_proxy_host(cfg: dict[str, Any], host_id: int, enabled: bool) -> tuple[bool, str]:
|
||||
npm_cfg = cfg.get("npmplus", {})
|
||||
base_url = (npm_cfg.get("base_url") or "").rstrip("/")
|
||||
verify_tls = npm_cfg.get("verify_tls", True)
|
||||
if not base_url:
|
||||
return False, "NPMplus base_url not configured"
|
||||
|
||||
token = _get_token(cfg)
|
||||
action = "enable" if enabled else "disable"
|
||||
url = f"{base_url}/nginx/proxy-hosts/{host_id}/{action}"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {token}",
|
||||
"User-Agent": "tg-admin-bot",
|
||||
}
|
||||
try:
|
||||
payload = _request_json(url, headers, None, verify_tls)
|
||||
except Exception as e:
|
||||
return False, str(e)
|
||||
if payload is True or (isinstance(payload, dict) and payload.get("success", True)):
|
||||
return True, "OK"
|
||||
return False, "API returned error"
|
||||
|
||||
|
||||
def format_certificates(certs: list[dict[str, Any]]) -> str:
|
||||
if not certs:
|
||||
return "🔒 SSL certificates\n\nℹ️ No certificates found"
|
||||
|
||||
Reference in New Issue
Block a user