2023-04-13 19:58:58 +01:00
|
|
|
from typing import Any
|
2020-01-20 23:02:04 +00:00
|
|
|
|
2020-01-17 19:40:29 +00:00
|
|
|
import netaddr
|
|
|
|
|
|
|
|
from core import utils
|
2020-06-18 22:15:45 +01:00
|
|
|
from core.config import Configuration
|
2020-01-17 21:47:55 +00:00
|
|
|
from core.configservice.base import ConfigService, ConfigServiceMode
|
2020-01-17 19:40:29 +00:00
|
|
|
|
|
|
|
GROUP_NAME = "Utility"
|
|
|
|
|
|
|
|
|
2020-01-23 00:54:45 +00:00
|
|
|
class DefaultRouteService(ConfigService):
|
2020-06-18 22:15:45 +01:00
|
|
|
name: str = "DefaultRoute"
|
|
|
|
group: str = GROUP_NAME
|
2023-04-13 19:58:58 +01:00
|
|
|
directories: list[str] = []
|
|
|
|
files: list[str] = ["defaultroute.sh"]
|
|
|
|
executables: list[str] = ["ip"]
|
|
|
|
dependencies: list[str] = []
|
|
|
|
startup: list[str] = ["bash defaultroute.sh"]
|
|
|
|
validate: list[str] = []
|
|
|
|
shutdown: list[str] = []
|
2020-06-18 22:15:45 +01:00
|
|
|
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
|
2023-04-13 19:58:58 +01:00
|
|
|
default_configs: list[Configuration] = []
|
|
|
|
modes: dict[str, dict[str, str]] = {}
|
2020-01-17 19:40:29 +00:00
|
|
|
|
2023-04-13 19:58:58 +01:00
|
|
|
def data(self) -> dict[str, Any]:
|
2020-04-02 23:12:07 +01:00
|
|
|
# only add default routes for linked routing nodes
|
|
|
|
routes = []
|
2020-06-16 17:30:16 +01:00
|
|
|
ifaces = self.node.get_ifaces()
|
|
|
|
if ifaces:
|
|
|
|
iface = ifaces[0]
|
2020-06-19 18:54:58 +01:00
|
|
|
for ip in iface.ips():
|
2020-06-19 16:50:36 +01:00
|
|
|
net = ip.cidr
|
2020-05-02 03:15:53 +01:00
|
|
|
if net.size > 1:
|
|
|
|
router = net[1]
|
|
|
|
routes.append(str(router))
|
2020-04-02 23:12:07 +01:00
|
|
|
return dict(routes=routes)
|
2020-01-17 19:40:29 +00:00
|
|
|
|
|
|
|
|
2020-01-23 00:54:45 +00:00
|
|
|
class DefaultMulticastRouteService(ConfigService):
|
2020-06-18 22:15:45 +01:00
|
|
|
name: str = "DefaultMulticastRoute"
|
|
|
|
group: str = GROUP_NAME
|
2023-04-13 19:58:58 +01:00
|
|
|
directories: list[str] = []
|
|
|
|
files: list[str] = ["defaultmroute.sh"]
|
|
|
|
executables: list[str] = []
|
|
|
|
dependencies: list[str] = []
|
|
|
|
startup: list[str] = ["bash defaultmroute.sh"]
|
|
|
|
validate: list[str] = []
|
|
|
|
shutdown: list[str] = []
|
2020-06-18 22:15:45 +01:00
|
|
|
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
|
2023-04-13 19:58:58 +01:00
|
|
|
default_configs: list[Configuration] = []
|
|
|
|
modes: dict[str, dict[str, str]] = {}
|
2020-01-23 00:54:45 +00:00
|
|
|
|
2023-04-13 19:58:58 +01:00
|
|
|
def data(self) -> dict[str, Any]:
|
2020-01-23 00:54:45 +00:00
|
|
|
ifname = None
|
2020-06-16 17:30:16 +01:00
|
|
|
for iface in self.node.get_ifaces(control=False):
|
|
|
|
ifname = iface.name
|
2020-01-23 00:54:45 +00:00
|
|
|
break
|
|
|
|
return dict(ifname=ifname)
|
|
|
|
|
|
|
|
|
|
|
|
class StaticRouteService(ConfigService):
|
2020-06-18 22:15:45 +01:00
|
|
|
name: str = "StaticRoute"
|
|
|
|
group: str = GROUP_NAME
|
2023-04-13 19:58:58 +01:00
|
|
|
directories: list[str] = []
|
|
|
|
files: list[str] = ["staticroute.sh"]
|
|
|
|
executables: list[str] = []
|
|
|
|
dependencies: list[str] = []
|
|
|
|
startup: list[str] = ["bash staticroute.sh"]
|
|
|
|
validate: list[str] = []
|
|
|
|
shutdown: list[str] = []
|
2020-06-18 22:15:45 +01:00
|
|
|
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
|
2023-04-13 19:58:58 +01:00
|
|
|
default_configs: list[Configuration] = []
|
|
|
|
modes: dict[str, dict[str, str]] = {}
|
2020-01-23 00:54:45 +00:00
|
|
|
|
2023-04-13 19:58:58 +01:00
|
|
|
def data(self) -> dict[str, Any]:
|
2020-01-23 00:54:45 +00:00
|
|
|
routes = []
|
2020-06-16 17:30:16 +01:00
|
|
|
for iface in self.node.get_ifaces(control=False):
|
2020-06-19 18:54:58 +01:00
|
|
|
for ip in iface.ips():
|
2020-06-19 16:50:36 +01:00
|
|
|
address = str(ip.ip)
|
|
|
|
if netaddr.valid_ipv6(address):
|
2020-01-23 00:54:45 +00:00
|
|
|
dst = "3ffe:4::/64"
|
|
|
|
else:
|
|
|
|
dst = "10.9.8.0/24"
|
2020-06-19 16:50:36 +01:00
|
|
|
if ip[-2] != ip[1]:
|
|
|
|
routes.append((dst, ip[1]))
|
2020-01-23 00:54:45 +00:00
|
|
|
return dict(routes=routes)
|
|
|
|
|
|
|
|
|
2020-01-17 19:40:29 +00:00
|
|
|
class IpForwardService(ConfigService):
|
2020-06-18 22:15:45 +01:00
|
|
|
name: str = "IPForward"
|
|
|
|
group: str = GROUP_NAME
|
2023-04-13 19:58:58 +01:00
|
|
|
directories: list[str] = []
|
|
|
|
files: list[str] = ["ipforward.sh"]
|
|
|
|
executables: list[str] = ["sysctl"]
|
|
|
|
dependencies: list[str] = []
|
|
|
|
startup: list[str] = ["bash ipforward.sh"]
|
|
|
|
validate: list[str] = []
|
|
|
|
shutdown: list[str] = []
|
2020-06-18 22:15:45 +01:00
|
|
|
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
|
2023-04-13 19:58:58 +01:00
|
|
|
default_configs: list[Configuration] = []
|
|
|
|
modes: dict[str, dict[str, str]] = {}
|
2020-01-17 19:40:29 +00:00
|
|
|
|
2023-04-13 19:58:58 +01:00
|
|
|
def data(self) -> dict[str, Any]:
|
2020-01-17 19:40:29 +00:00
|
|
|
devnames = []
|
2020-06-16 17:30:16 +01:00
|
|
|
for iface in self.node.get_ifaces():
|
|
|
|
devname = utils.sysctl_devname(iface.name)
|
2020-01-17 19:40:29 +00:00
|
|
|
devnames.append(devname)
|
2020-01-20 23:02:04 +00:00
|
|
|
return dict(devnames=devnames)
|
2020-01-23 00:54:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SshService(ConfigService):
|
2020-06-18 22:15:45 +01:00
|
|
|
name: str = "SSH"
|
|
|
|
group: str = GROUP_NAME
|
2023-04-13 19:58:58 +01:00
|
|
|
directories: list[str] = ["/etc/ssh", "/var/run/sshd"]
|
|
|
|
files: list[str] = ["startsshd.sh", "/etc/ssh/sshd_config"]
|
|
|
|
executables: list[str] = ["sshd"]
|
|
|
|
dependencies: list[str] = []
|
|
|
|
startup: list[str] = ["bash startsshd.sh"]
|
|
|
|
validate: list[str] = []
|
|
|
|
shutdown: list[str] = ["killall sshd"]
|
2020-06-18 22:15:45 +01:00
|
|
|
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
|
2023-04-13 19:58:58 +01:00
|
|
|
default_configs: list[Configuration] = []
|
|
|
|
modes: dict[str, dict[str, str]] = {}
|
2020-01-23 00:54:45 +00:00
|
|
|
|
2023-04-13 19:58:58 +01:00
|
|
|
def data(self) -> dict[str, Any]:
|
2020-01-23 00:54:45 +00:00
|
|
|
return dict(
|
|
|
|
sshcfgdir=self.directories[0],
|
|
|
|
sshstatedir=self.directories[1],
|
|
|
|
sshlibdir="/usr/lib/openssh",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class DhcpService(ConfigService):
|
2020-06-18 22:15:45 +01:00
|
|
|
name: str = "DHCP"
|
|
|
|
group: str = GROUP_NAME
|
2023-04-13 19:58:58 +01:00
|
|
|
directories: list[str] = ["/etc/dhcp", "/var/lib/dhcp"]
|
|
|
|
files: list[str] = ["/etc/dhcp/dhcpd.conf"]
|
|
|
|
executables: list[str] = ["dhcpd"]
|
|
|
|
dependencies: list[str] = []
|
|
|
|
startup: list[str] = ["touch /var/lib/dhcp/dhcpd.leases", "dhcpd"]
|
|
|
|
validate: list[str] = ["pidof dhcpd"]
|
|
|
|
shutdown: list[str] = ["killall dhcpd"]
|
2020-06-18 22:15:45 +01:00
|
|
|
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
|
2023-04-13 19:58:58 +01:00
|
|
|
default_configs: list[Configuration] = []
|
|
|
|
modes: dict[str, dict[str, str]] = {}
|
2020-01-23 00:54:45 +00:00
|
|
|
|
2023-04-13 19:58:58 +01:00
|
|
|
def data(self) -> dict[str, Any]:
|
2020-01-23 00:54:45 +00:00
|
|
|
subnets = []
|
2020-06-16 17:30:16 +01:00
|
|
|
for iface in self.node.get_ifaces(control=False):
|
2020-06-19 16:50:36 +01:00
|
|
|
for ip4 in iface.ip4s:
|
2021-04-23 07:02:42 +01:00
|
|
|
if ip4.size == 1:
|
|
|
|
continue
|
2020-06-19 16:50:36 +01:00
|
|
|
# divide the address space in half
|
|
|
|
index = (ip4.size - 2) / 2
|
|
|
|
rangelow = ip4[index]
|
|
|
|
rangehigh = ip4[-2]
|
2021-04-23 22:00:05 +01:00
|
|
|
subnets.append((ip4.cidr.ip, ip4.netmask, rangelow, rangehigh, ip4.ip))
|
2020-01-23 00:54:45 +00:00
|
|
|
return dict(subnets=subnets)
|
|
|
|
|
|
|
|
|
|
|
|
class DhcpClientService(ConfigService):
|
2020-06-18 22:15:45 +01:00
|
|
|
name: str = "DHCPClient"
|
|
|
|
group: str = GROUP_NAME
|
2023-04-13 19:58:58 +01:00
|
|
|
directories: list[str] = []
|
|
|
|
files: list[str] = ["startdhcpclient.sh"]
|
|
|
|
executables: list[str] = ["dhclient"]
|
|
|
|
dependencies: list[str] = []
|
|
|
|
startup: list[str] = ["bash startdhcpclient.sh"]
|
|
|
|
validate: list[str] = ["pidof dhclient"]
|
|
|
|
shutdown: list[str] = ["killall dhclient"]
|
2020-06-18 22:15:45 +01:00
|
|
|
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
|
2023-04-13 19:58:58 +01:00
|
|
|
default_configs: list[Configuration] = []
|
|
|
|
modes: dict[str, dict[str, str]] = {}
|
2020-01-23 00:54:45 +00:00
|
|
|
|
2023-04-13 19:58:58 +01:00
|
|
|
def data(self) -> dict[str, Any]:
|
2020-01-23 00:54:45 +00:00
|
|
|
ifnames = []
|
2020-06-16 17:30:16 +01:00
|
|
|
for iface in self.node.get_ifaces(control=False):
|
|
|
|
ifnames.append(iface.name)
|
2020-01-23 00:54:45 +00:00
|
|
|
return dict(ifnames=ifnames)
|
|
|
|
|
|
|
|
|
|
|
|
class FtpService(ConfigService):
|
2020-06-18 22:15:45 +01:00
|
|
|
name: str = "FTP"
|
|
|
|
group: str = GROUP_NAME
|
2023-04-13 19:58:58 +01:00
|
|
|
directories: list[str] = ["/var/run/vsftpd/empty", "/var/ftp"]
|
|
|
|
files: list[str] = ["vsftpd.conf"]
|
|
|
|
executables: list[str] = ["vsftpd"]
|
|
|
|
dependencies: list[str] = []
|
|
|
|
startup: list[str] = ["vsftpd ./vsftpd.conf"]
|
|
|
|
validate: list[str] = ["pidof vsftpd"]
|
|
|
|
shutdown: list[str] = ["killall vsftpd"]
|
2020-06-18 22:15:45 +01:00
|
|
|
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
|
2023-04-13 19:58:58 +01:00
|
|
|
default_configs: list[Configuration] = []
|
|
|
|
modes: dict[str, dict[str, str]] = {}
|
2020-01-23 00:54:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PcapService(ConfigService):
|
2020-06-18 22:15:45 +01:00
|
|
|
name: str = "pcap"
|
|
|
|
group: str = GROUP_NAME
|
2023-04-13 19:58:58 +01:00
|
|
|
directories: list[str] = []
|
|
|
|
files: list[str] = ["pcap.sh"]
|
|
|
|
executables: list[str] = ["tcpdump"]
|
|
|
|
dependencies: list[str] = []
|
|
|
|
startup: list[str] = ["bash pcap.sh start"]
|
|
|
|
validate: list[str] = ["pidof tcpdump"]
|
|
|
|
shutdown: list[str] = ["bash pcap.sh stop"]
|
2020-06-18 22:15:45 +01:00
|
|
|
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
|
2023-04-13 19:58:58 +01:00
|
|
|
default_configs: list[Configuration] = []
|
|
|
|
modes: dict[str, dict[str, str]] = {}
|
2020-01-23 00:54:45 +00:00
|
|
|
|
2023-04-13 19:58:58 +01:00
|
|
|
def data(self) -> dict[str, Any]:
|
2020-01-23 00:54:45 +00:00
|
|
|
ifnames = []
|
2020-06-16 17:30:16 +01:00
|
|
|
for iface in self.node.get_ifaces(control=False):
|
|
|
|
ifnames.append(iface.name)
|
2023-03-19 22:17:41 +00:00
|
|
|
return dict(ifnames=ifnames)
|
2020-01-23 00:54:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RadvdService(ConfigService):
|
2020-06-18 22:15:45 +01:00
|
|
|
name: str = "radvd"
|
|
|
|
group: str = GROUP_NAME
|
2023-04-13 19:58:58 +01:00
|
|
|
directories: list[str] = ["/etc/radvd", "/var/run/radvd"]
|
|
|
|
files: list[str] = ["/etc/radvd/radvd.conf"]
|
|
|
|
executables: list[str] = ["radvd"]
|
|
|
|
dependencies: list[str] = []
|
|
|
|
startup: list[str] = [
|
2020-06-18 22:15:45 +01:00
|
|
|
"radvd -C /etc/radvd/radvd.conf -m logfile -l /var/log/radvd.log"
|
|
|
|
]
|
2023-04-13 19:58:58 +01:00
|
|
|
validate: list[str] = ["pidof radvd"]
|
|
|
|
shutdown: list[str] = ["pkill radvd"]
|
2020-06-18 22:15:45 +01:00
|
|
|
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
|
2023-04-13 19:58:58 +01:00
|
|
|
default_configs: list[Configuration] = []
|
|
|
|
modes: dict[str, dict[str, str]] = {}
|
2020-01-23 00:54:45 +00:00
|
|
|
|
2023-04-13 19:58:58 +01:00
|
|
|
def data(self) -> dict[str, Any]:
|
2020-06-16 17:30:16 +01:00
|
|
|
ifaces = []
|
|
|
|
for iface in self.node.get_ifaces(control=False):
|
2020-01-23 00:54:45 +00:00
|
|
|
prefixes = []
|
2020-06-19 16:50:36 +01:00
|
|
|
for ip6 in iface.ip6s:
|
|
|
|
prefixes.append(str(ip6))
|
2020-01-23 00:54:45 +00:00
|
|
|
if not prefixes:
|
|
|
|
continue
|
2020-06-16 17:30:16 +01:00
|
|
|
ifaces.append((iface.name, prefixes))
|
|
|
|
return dict(ifaces=ifaces)
|
2020-01-23 00:54:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AtdService(ConfigService):
|
2020-06-18 22:15:45 +01:00
|
|
|
name: str = "atd"
|
|
|
|
group: str = GROUP_NAME
|
2023-04-13 19:58:58 +01:00
|
|
|
directories: list[str] = ["/var/spool/cron/atjobs", "/var/spool/cron/atspool"]
|
|
|
|
files: list[str] = ["startatd.sh"]
|
|
|
|
executables: list[str] = ["atd"]
|
|
|
|
dependencies: list[str] = []
|
|
|
|
startup: list[str] = ["bash startatd.sh"]
|
|
|
|
validate: list[str] = ["pidof atd"]
|
|
|
|
shutdown: list[str] = ["pkill atd"]
|
2020-06-18 22:15:45 +01:00
|
|
|
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
|
2023-04-13 19:58:58 +01:00
|
|
|
default_configs: list[Configuration] = []
|
|
|
|
modes: dict[str, dict[str, str]] = {}
|
2020-01-23 00:54:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HttpService(ConfigService):
|
2020-06-18 22:15:45 +01:00
|
|
|
name: str = "HTTP"
|
|
|
|
group: str = GROUP_NAME
|
2023-04-13 19:58:58 +01:00
|
|
|
directories: list[str] = [
|
2020-01-23 00:54:45 +00:00
|
|
|
"/etc/apache2",
|
|
|
|
"/var/run/apache2",
|
|
|
|
"/var/log/apache2",
|
|
|
|
"/run/lock",
|
|
|
|
"/var/lock/apache2",
|
|
|
|
"/var/www",
|
|
|
|
]
|
2023-04-13 19:58:58 +01:00
|
|
|
files: list[str] = [
|
2020-06-18 22:15:45 +01:00
|
|
|
"/etc/apache2/apache2.conf",
|
|
|
|
"/etc/apache2/envvars",
|
|
|
|
"/var/www/index.html",
|
|
|
|
]
|
2023-04-13 19:58:58 +01:00
|
|
|
executables: list[str] = ["apache2ctl"]
|
|
|
|
dependencies: list[str] = []
|
|
|
|
startup: list[str] = ["chown www-data /var/lock/apache2", "apache2ctl start"]
|
|
|
|
validate: list[str] = ["pidof apache2"]
|
|
|
|
shutdown: list[str] = ["apache2ctl stop"]
|
2020-06-18 22:15:45 +01:00
|
|
|
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
|
2023-04-13 19:58:58 +01:00
|
|
|
default_configs: list[Configuration] = []
|
|
|
|
modes: dict[str, dict[str, str]] = {}
|
2020-01-23 00:54:45 +00:00
|
|
|
|
2023-04-13 19:58:58 +01:00
|
|
|
def data(self) -> dict[str, Any]:
|
2020-06-16 17:30:16 +01:00
|
|
|
ifaces = []
|
|
|
|
for iface in self.node.get_ifaces(control=False):
|
|
|
|
ifaces.append(iface)
|
|
|
|
return dict(ifaces=ifaces)
|