paradrop.backend.pdconfd.config package

Submodules

paradrop.backend.pdconfd.config.base module

class ConfigObject[source]

Bases: object

addDependent(dep)[source]
classmethod build(manager, source, name, options, comment)[source]

Build a config object instance from the UCI section.

Arguments: source – file containing this configuration section name – name of the configuration section

If None, a unique name will be generated.

options – dictionary of options loaded from the section comment – comment string or None

commands(allConfigs)[source]

Return a list of commands to execute.

Each one is a Command object.

getTypeAndName()[source]

Return tuple (section type, section name).

lookup(allConfigs, sectionType, sectionName, addDependent=True)[source]

Look up a section by type and name.

If addDependent is True (default), the current object will be added as a dependent of the found section.

Will raise an exception if the section is not found.

nextId = 0
options = []
optionsMatch(other)[source]

Test equality of config sections by comparing option values.

typename = None
undoCommands(allConfigs)[source]

Return a list of commands to execute.

Each one is a Command object.

paradrop.backend.pdconfd.config.command module

class Command(priority, command, parent=None)[source]

Bases: object

PRIO_ADD_IPTABLES = 40
PRIO_CONFIG_IFACE = 20
PRIO_CREATE_IFACE = 10
PRIO_DELETE_IFACE = 50
PRIO_START_DAEMON = 30
execute()[source]
success()[source]

Returns True if the command was successfully executed.

paradrop.backend.pdconfd.config.dhcp module

class ConfigDhcp[source]

Bases: paradrop.backend.pdconfd.config.base.ConfigObject

options = [{'default': None, 'required': True, 'type': <type 'str'>, 'name': 'interface'}, {'default': '12h', 'required': True, 'type': <type 'str'>, 'name': 'leasetime'}, {'default': 150, 'required': True, 'type': <type 'int'>, 'name': 'limit'}, {'default': 100, 'required': True, 'type': <type 'int'>, 'name': 'start'}, {'default': '', 'required': False, 'type': <type 'list'>, 'name': 'dhcp_option'}]
typename = 'dhcp'
class ConfigDnsmasq[source]

Bases: paradrop.backend.pdconfd.config.base.ConfigObject

commands(allConfigs)[source]
options = [{'default': None, 'required': False, 'type': <type 'list'>, 'name': 'interface'}, {'default': False, 'required': False, 'type': <type 'bool'>, 'name': 'noresolv'}, {'default': None, 'required': False, 'type': <type 'list'>, 'name': 'server'}]
typename = 'dnsmasq'
undoCommands(allConfigs)[source]
get_all_dhcp_interfaces(allConfigs)[source]

paradrop.backend.pdconfd.config.firewall module

class ConfigRedirect[source]

Bases: paradrop.backend.pdconfd.config.base.ConfigObject

commands(allConfigs)[source]
options = [{'default': None, 'required': False, 'type': <type 'str'>, 'name': 'src'}, {'default': None, 'required': False, 'type': <type 'str'>, 'name': 'src_ip'}, {'default': None, 'required': False, 'type': <type 'str'>, 'name': 'src_dip'}, {'default': None, 'required': False, 'type': <type 'str'>, 'name': 'src_port'}, {'default': None, 'required': False, 'type': <type 'str'>, 'name': 'src_dport'}, {'default': 'tcpudp', 'required': True, 'type': <type 'str'>, 'name': 'proto'}, {'default': None, 'required': False, 'type': <type 'str'>, 'name': 'dest'}, {'default': None, 'required': False, 'type': <type 'str'>, 'name': 'dest_ip'}, {'default': None, 'required': False, 'type': <type 'str'>, 'name': 'dest_port'}, {'default': 'DNAT', 'required': False, 'type': <type 'str'>, 'name': 'target'}]
typename = 'redirect'
undoCommands(allConfigs)[source]
class ConfigZone[source]

Bases: paradrop.backend.pdconfd.config.base.ConfigObject

commands(allConfigs)[source]
interfaces(allConfigs)[source]

List of interfaces in this zone (generator).

options = [{'default': None, 'required': True, 'type': <type 'str'>, 'name': 'name'}, {'default': None, 'required': False, 'type': <type 'list'>, 'name': 'network'}, {'default': False, 'required': False, 'type': <type 'bool'>, 'name': 'masq'}, {'default': 'DROP', 'required': False, 'type': <type 'str'>, 'name': 'input'}, {'default': 'DROP', 'required': False, 'type': <type 'str'>, 'name': 'forward'}, {'default': 'DROP', 'required': False, 'type': <type 'str'>, 'name': 'output'}]
typename = 'zone'
undoCommands(allConfigs)[source]

paradrop.backend.pdconfd.config.manager module

class ConfigManager(writeDir)[source]

Bases: object

changingSet(files)[source]

Return the sections from the current configuration that may have changed.

This checks which sections from the current configuration came from files in the given file list. These are sections that may be changed or removed when we reload the files.

execute(commands)[source]
findMatchingConfig(config, byName=False)[source]

Check the current config for an identical section.

Returns the matching object or None.

getPreviousCommands()[source]

Get the most recent command list.

loadConfig(search=None, execute=True)[source]

Load configuration files and apply changes to the system.

We process the configuration files in sections. Each section corresponds to an interface, firewall rule, DHCP server instance, etc. Each time we reload configuration files after the initial time, we check for changes against the current configuration. Here is the decision tree for handling differences in the newly loaded configuration vs. the existing configuration:

Section exists in current config (by type and name)?
  • No -> Add section, apply changes, and stop.
  • Yes -> Continue.

Section is identical to the one in the current config (by option values)?

  • No -> Revert current section, mark any affected dependents,

    add new section, apply changes, and stop.

  • Yes -> Continue.

Section has not changed but one of its dependencies has?
  • No -> Stop.

  • Yes -> Revert current section, mark any affected dependents,

    add new section, apply changes, and stop.

readConfig(files)[source]

Load configuration files and return configuration objects.

This method only loads the configuration files without making any changes to the system and returns configuration objects as a generator.

statusString()[source]

Return a JSON string representing status of the system.

The format will be a list of dictionaries. Each dictionary corresponds to a configuration block and contains at the following fields.

type: interface, wifi-device, etc. name: name of the section (may be autogenerated for some configs) comment: comment from the configuration file or None success: True if all setup commands succeeded

unload(execute=True)[source]
waitSystemUp()[source]

Wait for the first load to complete and return system status string.

findConfigFiles(search=None)[source]

Look for and return a list of configuration files.

The behavior depends on whether the search argument is a file, a directory, or None.

If search is None, return a list of files in the system config directory. If search is a file name (not a path), look for it in the working directory first, and the system directory second. If search is a full path to a file, and it exists, then return that file. If search is a directory, return the files in that directory.

sortCommands(commands)[source]

Return commands in order by priority.

The input should be a list of command objects. The output will be just the command part in order according to priority (ascending). For ties, the order from the original list is maintained.

paradrop.backend.pdconfd.config.network module

class ConfigInterface[source]

Bases: paradrop.backend.pdconfd.config.base.ConfigObject

commands(allConfigs)[source]
options = [{'default': None, 'required': True, 'type': <type 'str'>, 'name': 'proto'}, {'default': None, 'required': True, 'type': <type 'str'>, 'name': 'ifname'}, {'default': True, 'required': False, 'type': <type 'bool'>, 'name': 'enabled'}, {'default': None, 'required': False, 'type': <type 'str'>, 'name': 'ipaddr'}, {'default': None, 'required': False, 'type': <type 'str'>, 'name': 'netmask'}]
typename = 'interface'
undoCommands(allConfigs)[source]

paradrop.backend.pdconfd.config.wireless module

class ConfigWifiDevice[source]

Bases: paradrop.backend.pdconfd.config.base.ConfigObject

commands(allConfigs)[source]
options = [{'default': None, 'required': True, 'type': <type 'str'>, 'name': 'type'}, {'default': 1, 'required': True, 'type': <type 'int'>, 'name': 'channel'}]
typename = 'wifi-device'
class ConfigWifiIface[source]

Bases: paradrop.backend.pdconfd.config.base.ConfigObject

commands(allConfigs)[source]
options = [{'default': None, 'required': True, 'type': <type 'str'>, 'name': 'device'}, {'default': 'ap', 'required': True, 'type': <type 'str'>, 'name': 'mode'}, {'default': 'Paradrop', 'required': True, 'type': <type 'str'>, 'name': 'ssid'}, {'default': 'lan', 'required': True, 'type': <type 'str'>, 'name': 'network'}, {'default': None, 'required': False, 'type': <type 'str'>, 'name': 'encryption'}, {'default': None, 'required': False, 'type': <type 'str'>, 'name': 'key'}]
typename = 'wifi-iface'
undoCommands(allConfigs)[source]
isHexString(data)[source]

Test if a string contains only hex digits.

Module contents