feat: add certificate management module and schedule auto-renewal cron
This commit is contained in:
parent
42767fd8bc
commit
f793ddd02f
6 changed files with 214 additions and 198 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from .ssh import SSHClient
|
||||
import re
|
||||
|
||||
class DNSManager:
|
||||
def __init__(self, config):
|
||||
|
|
@ -41,7 +42,8 @@ class DNSManager:
|
|||
self.reload()
|
||||
|
||||
def remove_dns(self, domain):
|
||||
cmd = f"sh -c \"sed -i '\#address=/{domain}/#d' {self.dns_file}\""
|
||||
# Use raw string to avoid escape warnings
|
||||
cmd = rf"sh -c \"sed -i '\#address=/{domain}/#d' {self.dns_file}\""
|
||||
self.exec_lxc(cmd)
|
||||
self.reload()
|
||||
|
||||
|
|
@ -57,46 +59,23 @@ class DNSManager:
|
|||
dns = self.exec_lxc(f"cat {self.dns_file}").stdout
|
||||
return {"hosts": hosts, "dns": dns}
|
||||
|
||||
def get_free_ips(self, start_subnet=70, end_subnet=80):
|
||||
def get_free_ips(self, start_subnet=70, end_subnet=80):
|
||||
"""Finds free IPs in the range 10.32.[70-80].1-254 by checking both static and dynamic leases"""
|
||||
# 1. Get all static IPs from dhcp-hosts.conf and dynamic-hosts.conf
|
||||
static_configs = self.exec_lxc(f"cat /etc/dnsmasq.d/dhcp-hosts.conf {self.hosts_file} 2>/dev/null").stdout
|
||||
used_ips = set(re.findall(r'10\.32\.[0-9]{1,3}\.[0-9]{1,3}', static_configs))
|
||||
|
||||
# 2. Get all active dynamic leases
|
||||
leases = self.exec_lxc("cat /var/lib/misc/dnsmasq.leases 2>/dev/null").stdout
|
||||
used_ips.update(set(re.findall(r'10\.32\.[0-9]{1,3}\.[0-9]{1,3}', leases)))
|
||||
|
||||
"""Finds free IPs in the range 10.32.[70-80].1-254 by checking both static and dynamic leases"""
|
||||
|
||||
# 1. Get all static IPs from dhcp-hosts.conf and dynamic-hosts.conf
|
||||
|
||||
static_configs = self.exec_lxc(f"cat /etc/dnsmasq.d/dhcp-hosts.conf {self.hosts_file} 2>/dev/null").stdout
|
||||
|
||||
import re
|
||||
|
||||
used_ips = set(re.findall(r'10\.32\.[0-9]{1,3}\.[0-9]{1,3}', static_configs))
|
||||
|
||||
|
||||
|
||||
# 2. Get all active dynamic leases
|
||||
|
||||
leases = self.exec_lxc("cat /var/lib/misc/dnsmasq.leases 2>/dev/null").stdout
|
||||
|
||||
used_ips.update(set(re.findall(r'10\.32\.[0-9]{1,3}\.[0-9]{1,3}', leases)))
|
||||
|
||||
|
||||
|
||||
# 3. Find first available in the expanded agent range
|
||||
|
||||
free_ips = []
|
||||
|
||||
for subnet_idx in range(start_subnet, end_subnet + 1):
|
||||
|
||||
for host_idx in range(1, 255):
|
||||
|
||||
candidate = f"10.32.{subnet_idx}.{host_idx}"
|
||||
|
||||
if candidate not in used_ips:
|
||||
|
||||
free_ips.append(candidate)
|
||||
|
||||
if len(free_ips) >= 10: # Return top 10
|
||||
|
||||
return free_ips
|
||||
|
||||
return free_ips
|
||||
|
||||
|
||||
# 3. Find first available in the expanded agent range
|
||||
free_ips = []
|
||||
for subnet_idx in range(start_subnet, end_subnet + 1):
|
||||
for host_idx in range(1, 255):
|
||||
candidate = f"10.32.{subnet_idx}.{host_idx}"
|
||||
if candidate not in used_ips:
|
||||
free_ips.append(candidate)
|
||||
if len(free_ips) >= 10: # Return top 10
|
||||
return free_ips
|
||||
return free_ips
|
||||
Loading…
Add table
Add a link
Reference in a new issue