package documentation

Objects utilities

From __init__.py:

Function add_domain_set Add domain set to objects config.
Function add_host_set Add host set to objects config.
Function delete_domain_set Delete domain set from objects config.
Function delete_host_set Delete host set from objects config.
Function edit_domain_set Edit domain set in objects config.
Function edit_host_set Edit host set in objects config.
Function get_domain_set_ipsets Get ipsets linked to domain set.
Function get_domain_set_total_chars Calculate the total number of characters the given domain set will use in the dnsmasq configuration file. This file supports a maximum of 1024 characters per line.
Function get_info Get the info of the object.
Function get_object Get object from objects config.
Function get_object_ip Get the first IP address from an object.
Function get_object_ips Get all IP addresses from an object.
Function is_domain Check if an object is a domain.
Function is_domain_set Check if an object is a domain set.
Function is_host Check if an object is a host.
Function is_host_set Check if an object is a host set.
Function is_object_id Check if an id is an object id.
Function is_singleton_host_set Check if an object is a host set with a single IP address. The IP must not be an IP range. If allow_cidr is True, the IP can be in CIDR notation.
Function is_used_domain_set Check if domain set is used in firewall config.
Function is_used_host_set Check if host set is used in firewall config.
Function is_used_object firewall config
Function is_vpn_user Check if an object is a VPN user.
Function list_dhcp_static_leases Get all DHCP static leases from dhcp config
Function list_dns_records Get all DNS records from dhcp config
Function list_domain_sets Get all domain sets from objects config
Function list_host_sets Get all host sets from objects config
Function list_objects Get objects from objects, dhcp, and users config
Function list_vpn_users Get all VPN users from users config
Function object_exists Check if the object exists.
Function _has_loop Undocumented
Function _validate_host_set_ipaddr Undocumented
Function _validate_host_set_ipaddr_v4 Undocumented
Function _validate_host_set_ipaddr_v6 Undocumented
def add_domain_set(uci, name: str, family: str, domains: list[str], timeout: int = 660) -> str: (source)

Add domain set to objects config.

Args:
uci: EUci pointer name: name of domain set family: can be ipv4 or ipv6 domains: a list of valid DNS names timeout: the timeout in seconds for the DNS resolution, default is 660 seconds
Returns:
id of domain set config that was added
def add_host_set(uci, name: str, family: str, ipaddrs: list[str]) -> str: (source)

Add host set to objects config.

Args:
uci: EUci pointer name: name of host set family: can be ipv4 or ipv6 ipaddrs: a list of IP addresses
Returns:
id of host set config that was added
def delete_domain_set(uci, id: str) -> str: (source)

Delete domain set from objects config.

Args:
uci: EUci pointer id: id of domain set to delete
Returns:
name of domain set config that was deleted
def delete_host_set(uci, id: str) -> str: (source)

Delete host set from objects config.

Args:
uci: EUci pointer id: id of host set to delete
Returns:
name of host set config that was deleted
def edit_domain_set(uci, id: str, name: str, family: str, domains: list[str], timeout: int = 660) -> str: (source)

Edit domain set in objects config.

Args:
uci: EUci pointer id: id of domain set to edit name: name of domain set family: can be ipv4 or ipv6 domains: a list of valid DNS names timeout: the timeout in seconds for the DNS resolution, default is 660 seconds
Returns:
id of domain set config that was edited
def edit_host_set(uci, id: str, name: str, family: str, ipaddrs: list[str]) -> str: (source)

Edit host set in objects config.

Args:
uci: EUci pointer id: id of host set to edit name: name of host set family: can be ipv4 or ipv6 ipaddrs: a list of IP addresses
Returns:
id of host set config that was edited
def get_domain_set_ipsets(uci, id): (source)

Get ipsets linked to domain set.

Args:
uci: EUci pointer id: id of domain set
Returns:
a dictionary with - firewall: the ipset id linked to domain set from firewall config - dhcp: the ipset id linked to domain set from dhcp config
def get_domain_set_total_chars(name: str, unique_domains: list[str]): (source)

Calculate the total number of characters the given domain set will use in the dnsmasq configuration file. This file supports a maximum of 1024 characters per line.

Example syntax of a domain set in dnsmasq configuration file: nftset=/example1.org/example2.org/example3.org/.../4#inet#fw4#domainSetName

Args:
name: name of domain set domains: a list of valid DNS names
Returns:
the number of characters
def get_info(uci, database_id): (source)

Get the info of the object.

Args:
uci: EUci pointer database_id: id of the object in the form of <database>/
Returns:

a dictionary with the following fields:

  • database: the database of the object
  • id: the id of the object
  • name: the name of the object
  • type: the type of the object
  • family: IP family, like ipv4 or ipv6
def get_object(uci, database_id): (source)

Get object from objects config.

Args:
uci: EUci pointer id: id of the object in the form of <database>/
Returns:
object from config or None if not found
def get_object_ip(uci, database_id): (source)

Get the first IP address from an object.

Args:
uci: EUci pointer id: id of the object in the form of <database>/
Returns:
the first IP address from the object
def get_object_ips(uci, database_id): (source)

Get all IP addresses from an object.

Args:
uci: EUci pointer id: id of the object in the form of <database>/
Returns:
a list of unique IP addresses from the object
def is_domain(uci, database_id): (source)

Check if an object is a domain.

Args:
uci: EUci pointer database_id: id of the object in the form of <database>/
Returns:
True if object is a domain, False otherwise
def is_domain_set(uci, database_id): (source)

Check if an object is a domain set.

Args:
uci: EUci pointer id: id of the object in the form of <database>/
Returns:
True if object is a domain set, False otherwise
def is_host(uci, database_id): (source)

Check if an object is a host.

Args:
uci: EUci pointer database_id: id of the object in the form of <database>/
Returns:
True if object is a host, False otherwise
def is_host_set(uci, database_id): (source)

Check if an object is a host set.

Args:
uci: EUci pointer id: id of the object in the form of <database>/
Returns:
True if object is a host set, False otherwise
def is_object_id(id): (source)

Check if an id is an object id.

Args:
id: id to check
Returns:
True if id is an object id, False otherwise
def is_singleton_host_set(uci, database_id, allow_cidr=False): (source)

Check if an object is a host set with a single IP address. The IP must not be an IP range. If allow_cidr is True, the IP can be in CIDR notation.

Args:
uci: EUci pointer database_id: id of the object in the form of <database>/ allow_cidr: allow CIDR notation
Returns:
True if object is a singleton host set, False otherwise
def is_used_domain_set(uci, id): (source)

Check if domain set is used in firewall config.

Args:
uci: EUci pointer id: id of domain set
Returns:
A tuple with: - True if domain set is used in firewall config, False otherwise - a list of firewall sections where domain set is used
def is_used_host_set(uci, id): (source)

Check if host set is used in firewall config.

Args:
uci: EUci pointer id: id of host set
Returns:
A tuple with: - True if host set is used in firewall config, False otherwise - a list of firewall sections where host set is used
def is_used_object(uci, database_id): (source)

Check if an object is used in:
  • firewall config
  • mwan3 config
  • dpi config
  • existing host set
Args:
uci: EUci pointer id: id of the object in the form of <database>/
Returns:
A tuple with: - True if domain set is used in firewall config, False otherwise - a list of firewall sections where domain set is used

def is_vpn_user(uci, database_id): (source)

Check if an object is a VPN user.

Args:
uci: EUci pointer database_id: id of the object in the form of <database>/
Returns:
True if object is a VPN user, False otherwise
def list_dhcp_static_leases(uci, expand=False, used_info=False): (source)

Get all DHCP static leases from dhcp config

Args:
uci: EUci pointer expand: expand the list with all IP addresses of the object used_info: include used and matches info
Returns:
a list of all DHCP static leases
def list_dns_records(uci, expand=False, used_info=False): (source)

Get all DNS records from dhcp config

Args:
uci: EUci pointer expand: expand the list with all IP addresses of the object used_info: include used and matches info
Returns:
a list of all DNS records
def list_domain_sets(uci, used_info=True) -> list: (source)

Get all domain sets from objects config

Args:
uci: EUci pointer used_info: include used and matches info
Returns:
a list of all domain sets
def list_host_sets(uci, used_info=True) -> list: (source)

Get all host sets from objects config

Args:
uci: EUci pointer used_info: include used and matches info
Returns:
a list of all host sets
def list_objects(uci, include_domain_sets=True, include_host_sets=True, singleton_only=False, expand=False): (source)

Get objects from objects, dhcp, and users config

Args:
uci: EUci pointer include_domain_sets: include domain sets in the list include_host_sets: include host sets in the list expand: expand the list with all IP addresses of the object
Returns:
a list of all objects
def list_vpn_users(uci, expand=False, used_info=False): (source)

Get all VPN users from users config

Args:
uci: EUci pointer expand: expand the list with all IP addresses of the object used_info: include used and matches info
Returns:
a list of all VPN users
def object_exists(uci, database_id): (source)

Check if the object exists.

Args:
database_id: id to check in the form of <database>/
Returns:
True if object exists, False otherwise
def _has_loop(uci, id, ipaddr, depth=0): (source)

Undocumented

def _validate_host_set_ipaddr(uci, id, ipaddr: str, family: str): (source)

Undocumented

def _validate_host_set_ipaddr_v4(ipaddr: str): (source)

Undocumented

def _validate_host_set_ipaddr_v6(ipaddr: str): (source)

Undocumented