General utilities
From __init__.py:
| Exception | |
Undocumented |
| Function | check |
Check if the given password matches the given shadow password hash. |
| Function | generic |
Generate a generic error for the APIs. |
| Function | get |
Return all sections with the given option value |
| Function | get |
Return all sections of the given utype from the given config |
| Function | get |
Retrieve all device IPs |
| Function | get |
Retrieve all devices associated to the given zone |
| Function | get |
Retrieve all devices associated to the lan zone, except for VPN ones |
| Function | get |
Retrieve all devices associated to the wan zone |
| Function | get |
List all WAN interfaces with their IP addresses Exclude bond management IPs. |
| Function | get |
Retrieve all devices associated to firewall zones, along with the logical interfaces bound to them |
| Function | get |
Retrieve the physical device name given the MAC address |
| Function | get |
Return a valid UCI id based on the given string. All auto-generated NethSecurity ids: |
| Function | get |
Retrieve the logical UCI interface name given the device name |
| Function | get |
Retrieve the logical UCI interface name given the MAC address |
| Function | get |
Retrieve the network device that carries the IP traffic of the given logical interface. Alias interfaces are resolved to the device of their parent interface, aliases of aliases are not supported. |
| Function | get |
Return the public addresses associated to a private IP address. |
| Function | get |
Return a random valid UCI id. |
| Function | get |
Retrieve all unused/unassigned devices. |
| Function | get |
Retrieve the user object id (UCI section) given the username |
| Function | sanitize |
Replace illegal chars with _ char. UCI identifiers and config file names may contain only the characters a-z, 0-9 and _ |
| Function | set |
Drop-in replacement for uci.set that skips the write when the stored value already matches, so UCI records no change |
| Function | shadow |
Generates a shadow password hash using SHA-512 algorithm. |
| Function | validate |
Ensure the given MAC address is lowercase and colon-separated (e.g. '00:1a:2b:3c:4d:5e'). |
| Function | validate |
Ensure the given name is safe to use as a UCI section identifier, i.e. it would not be altered by sanitize(). |
| Function | validate |
Ensure the given user/group name is safe to store and to use as a filesystem/certificate component. Allows dotted and email-style logins (e.g. 'first.last', 'user@example.com') coming from local or LDAP databases. |
| Function | validation |
Generate a validation error for the APIs. |
| Function | validation |
Generate a validation error for the APIs from an array. |
| Constant | _VALID |
Undocumented |
| Constant | _VALID |
Undocumented |
Check if the given password matches the given shadow password hash.
- Arguments:
- password (str) - the password to be checked.
- shadow (str) - the shadow password hash to be checked.
- Returns:
- True if the password matches the hash, False otherwise
Generate a generic error for the APIs.
- Arguments:
- message -- An error message
- Returns:
- A validation error object
Return all sections with the given option value
- Arguments:
- uci -- EUci pointer
- config -- Configuration database name
- option -- Option name
- value -- Option value
- deep - If true, return a dict of all matched keys, otherwise return a list of section names
- Returns:
- A dictionary or a list of all matched sections
Return all sections of the given utype from the given config
- Arguments:
- uci -- EUci pointer
- config -- Configuration database name
- utype -- Section type
- Returns:
- A dictionary of all matched sections, None in case of error
Retrieve all devices associated to the given zone
- Arguments:
- uci -- EUci pointer
- zone -- Firewall zone name
- Returns:
- A list of device names
Retrieve all devices associated to the lan zone, except for VPN ones
- Arguments:
- uci -- EUci pointer
- Returns:
- A list of device names
Retrieve all devices associated to the wan zone
- Arguments:
- uci -- EUci pointer
- exclude_aliases -- If true, exclude devices starting with @
- Returns:
- A list of device names
List all WAN interfaces with their IP addresses Exclude bond management IPs.
- Arguments:
- uci -- EUci pointer
- Returns:
- A list of dictionaries with device and IP address
Retrieve all devices associated to firewall zones, along with the logical interfaces bound to them
- Arguments:
- uci -- EUci pointer
- Returns:
- A dictionary with device names as keys and lists of interface names as values, interfaces named like the device itself are not listed
Retrieve the physical device name given the MAC address
- Aarguments:
- hwaddr -- MAC address string
- Returns:
- The device name as a string if the network interface has been found, None otherwise.
Return a valid UCI id based on the given string. All auto-generated NethSecurity ids:
- have a maximum length of 100 characters
- start with ns_ prefix
- are sanitized accordingly to UCI conventions
- Arguments:
- name -- the name of the section
- length -- maximum id length, default is 100. Maximum length for firewall zones is 15.
- Returns:
- a valid UCI identifier as string
Retrieve the logical UCI interface name given the device name
- Arguments:
- uci -- EUci pointer
- device -- Device name
- Returns:
- The device name as a string if the interface has been found, None otherwise
Retrieve the logical UCI interface name given the MAC address
- Arguments:
- uci -- EUci pointer
- hwaddr -- MAC address string
- Returns:
- The device name as a string if the interface has been found, None otherwise
Retrieve the network device that carries the IP traffic of the given logical interface. Alias interfaces are resolved to the device of their parent interface, aliases of aliases are not supported.
- Arguments:
- uci -- EUci pointer
- interface -- Logical interface name
- Returns:
- The device name as a string, None if it can't be resolved
Return the public addresses associated to a private IP address.
- Arguments:
- ip_address -- the private IP address of a network interface. If not specified, the default network interface is used.
- Returns:
- a list of public addresses. Usually, the list contains only one element.
Return a random valid UCI id.
- Random ids:
- have a length of 11 characters
- are sanitized accordingly to UCI conventions (see 'sanitize' function)
- start with ns_ prefix
- Arguments:
- name -- the name of the section
- Returns:
- a valid UCI identifier as string
Retrieve the user object id (UCI section) given the username
- Arguments:
- uci -- EUci pointer
- username -- Username
- Returns:
- The user object id (UCI section) if the user has been found, None otherwise
Replace illegal chars with _ char. UCI identifiers and config file names may contain only the characters a-z, 0-9 and _
- Arguments:
- name -- the name of the section
- Returns:
- a string with valid chachars for UCI
str, section: str, option: str, value: str | list[ str] | tuple[ str, ...]):
(source)
¶
Drop-in replacement for uci.set that skips the write when the stored value already matches, so UCI records no change
- Arguments:
- uci -- EUci pointer
- config -- Configuration database name
- section -- Section name
- option -- Option name
- value -- Value to set, either a scalar or a list
- Returns:
- Whatever uci.set returns
Generates a shadow password hash using SHA-512 algorithm.
- Arguments:
- password (str) - the password to be hashed.
- Returns:
- the shadow password hash as strin
Ensure the given MAC address is lowercase and colon-separated (e.g. '00:1a:2b:3c:4d:5e').
- Arguments:
- mac -- the MAC address to validate
- parameter -- the parameter name to report in the ValidationError (default: 'mac')
- Raises:
- ValidationError if the MAC address is not valid
Ensure the given name is safe to use as a UCI section identifier, i.e. it would not be altered by sanitize().
- Arguments:
- name -- the name to validate
- parameter -- the parameter name to report in the ValidationError (default: 'name')
- Raises:
- ValidationError if the name is empty or would be altered by sanitize()
Ensure the given user/group name is safe to store and to use as a filesystem/certificate component. Allows dotted and email-style logins (e.g. 'first.last', 'user@example.com') coming from local or LDAP databases.
- Arguments:
- name -- the name to validate
- parameter -- the parameter name to report in the ValidationError (default: 'name')
- Raises:
- ValidationError if the name is empty or contains disallowed characters
Generate a validation error for the APIs.
- Arguments:
- parameter -- The name of the parameter
- message -- The validation error reason, default is empty
- value -- The parmeter original value that caused the error
- Returns:
- A validation error object