package documentation

General utilities

From __init__.py:

Exception ValidationError Undocumented
Function check_password Check if the given password matches the given shadow password hash.
Function generic_error Generate a generic error for the APIs.
Function get_all_by_option Return all sections with the given option value
Function get_all_by_type Return all sections of the given utype from the given config
Function get_all_device_ips Retrieve all device IPs
Function get_all_devices_by_zone Retrieve all devices associated to the given zone
Function get_all_lan_devices Retrieve all devices associated to the lan zone, except for VPN ones
Function get_all_wan_devices Retrieve all devices associated to the wan zone
Function get_all_wan_ips List all WAN interfaces with their IP addresses Exclude bond management IPs.
Function get_device_name Retrieve the physical device name given the MAC address
Function get_id Return a valid UCI id based on the given string. All auto-generated NethSecurity ids:
Function get_interface_from_device Retrieve the logical UCI interface name given the device name
Function get_interface_from_mac Retrieve the logical UCI interface name given the MAC address
Function get_random_id Return a random valid UCI id.
Function get_unassigned_devices Retrieve all unused/unassigned devices.
Function get_user_by_username 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 shadow_password Generates a shadow password hash using SHA-512 algorithm.
Function validation_error Generate a validation error for the APIs.
Function validation_errors Generate a validation error for the APIs from an array.
def check_password(password, shadow): (source)

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
def generic_error(error): (source)

Generate a generic error for the APIs.

Arguments:
  • message -- An error message
Returns:
  • A validation error object
def get_all_by_option(uci, config, option, value, deep=True): (source)

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
def get_all_by_type(uci, config, utype): (source)

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
def get_all_device_ips(): (source)

Retrieve all device IPs

def get_all_devices_by_zone(uci, zone, exclude_aliases=False): (source)

Retrieve all devices associated to the given zone

Arguments:
  • uci -- EUci pointer
  • zone -- Firewall zone name
Returns:
  • A list of device names
def get_all_lan_devices(uci): (source)

Retrieve all devices associated to the lan zone, except for VPN ones

Arguments:
  • uci -- EUci pointer
Returns:
  • A list of device names
def get_all_wan_devices(uci, exclude_aliases=False): (source)

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
def get_all_wan_ips(uci): (source)

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
def get_device_name(hwaddr): (source)

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.
def get_id(name, length=100): (source)

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
def get_interface_from_device(uci, device): (source)

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
def get_interface_from_mac(uci, hwaddr): (source)

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
def get_random_id(): (source)

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
def get_unassigned_devices(uci): (source)

Retrieve all unused/unassigned devices.

Arguments:
  • uci -- EUci pointer
Returns:
  • A list of devices
def get_user_by_username(uci, username): (source)

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
def sanitize(name): (source)

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
def shadow_password(password): (source)

Generates a shadow password hash using SHA-512 algorithm.

Arguments:
  • password (str) - the password to be hashed.
Returns:
  • the shadow password hash as strin
def validation_error(parameter, message='', value=''): (source)

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
def validation_errors(errors): (source)

Generate a validation error for the APIs from an array.

Arguments:
  • errors -- An array of array errors
Each array element is an array composed by 3 parameters:
  • the name of the parameter
  • the validation error reason
  • the parameter original value that caused the error
Returns:
  • A validation error object