def test_ip_range(self, config, ip_range_key): """ Test that a value is an IP range in 1 of 4 formats Args: config (ConfigDict): the section config to test ip_range_key (str): Formats are single, range, cidr, and IP/netmask Returns: bool """ ip = config.get(ip_range_key) return all(ip_util.is_valid_ip(ip) for ip in util.parse_delimited_set(ip))
def get_allowed_ip_networks(config): """ Determine the list of allowed IP Networks from the given configuration, where there may be a 'client_ip' section with a comma-separated list, each item being either A single IP address An IP address range A CIDR-style IP range Args: config (ConfigDict): the section config Returns: [IPNetwork]: The allowed IP Networks from the config """ client_ips = [] for ip_string in util.parse_delimited_set(config.get_str("client_ip", "")): if ip_util.is_valid_ip(ip_string): client_ips.extend(ip_util.get_ip_networks(ip_string)) return client_ips
def validate_http_proxy_config(config): """ Validate an 'http_proxy' configuration, checking that 1) All required values are present (currently only 'api_host' is required) 2) Any IPs provided in 'client_ip' are valid Args: config: A ConfigDict for an http_proxy module Returns: ConfigCheckResult with any config problems """ problems = [] if "api_host" not in config: problems.append(MissingConfigKeyProblem("api_host")) for client_ip in util.parse_delimited_set(config.get_str("client_ip", "")): is_valid = ip_util.is_valid_ip(client_ip) if not is_valid: problems.append(InvalidConfigKeyProblem("client_ip", client_ip)) return ConfigCheckResult(problems)
def __init__(self, secrets, primary_ator, pass_through_attr_names, **kwargs): """Initialize the Radius Server instance. secrets: dictionary mapping from ip address to radius secret (e.g. '{"127.0.0.1": "s3cr3t"}') primary_ator: client module with which to perform primary auth """ super(SimpleRadiusServer, self).__init__() self.requests = {} self.secrets = secrets self.primary_ator = primary_ator pass_through_attr_names = pass_through_attr_names.strip() if pass_through_attr_names: self._pass_through_attr_names = util.parse_delimited_set( pass_through_attr_names) else: self._pass_through_attr_names = [] self.pass_through_all = kwargs.get("pass_through_all", False) self.pw_codec = kwargs.get("pw_codec", "utf-8") self.client_ip_attr = kwargs.get("client_ip_attr", "Calling-Station-Id") self.server_section_name = kwargs.get("server_section_name", "Unknown") self.server_section_ikey = kwargs.get("server_section_ikey", "Unknown")