def validate(cls, config): """ Validates the given configuration dictionary. Args: config (dict): The dictionary to validate. Its keys and values are subclass-specific. Raises: KeyError: If a required configuration option is missing. The error message is the missing key. ValueError: If a configuration option's value is not valid. The error message is in the following format: key: value requirement Returns: dict: The dict given as the config argument with missing optional parameters added with default values. """ defaults = {'port': 22, 'policy': 'Warning'} config = api.check_config(config, cls.parameters(), defaults) if not config['host']: raise ValueError('host: {} Must be non-empty'.format( str(config['host']))) if not config['command_list']: raise ValueError('command_list: {} Must be non-empty'.format( str(config['host']))) if config['policy'] not in ['AutoAdd', 'Reject', 'Warning']: raise ValueError('policy: {} Must be one of "AutoAdd", "Reject", ' 'or "Warning"'.format(str(config['policy']))) if config['port'] < 1 or config['port'] > 65535: raise ValueError('port: {} Must be in the range [1, 65535]'.format( str(config['port']))) return config
def validate(cls, config): """ Check if the given configuration is valid. Args: config (dict): Configuration dictionary, see parameters method. Raises: KeyError: If a required key is missing. The error message will be the missing key. ValueError: If an argument to an option is invalid. The error message will be as follows: key: value reason Returns: dict: The given configuration dict with arguments converted to their required formats with missing optional arguments added with default arguments. """ config = api.check_config(config, cls.parameters(), {}) freq = config['frequency'] if freq <= 0: raise ValueError('frequency: {} Must be positive.'.format(freq)) reps = config['repetitions'] if reps < 0: raise ValueError('repetitions: {} Must not be negative.'.format( str(reps))) return config
def validate(cls, config): """ Validates the given configuration dictionary. Checks that string arguments have the correct type, but doesn't check if they are well-formed e-mail addresses, hostnames, etc. Args: config (dict): The dictionary to validate. Its keys and values are subclass-specific. Its values should be assumed to be str type and converted appropriately. Raises: KeyError: If a required configuration option is missing. The error message is the missing key. ValueError: If a configuration option's value is not valid. The error message is in the following format: key: value requirement Returns: dict: The dict given as the config argument with missing optional parameters updated with default values. """ defaults = { 'messages': [], 'subjects': [], 'encrypt': False, 'port': 25 } config = api.check_config(config, cls.parameters(), defaults) if not config['destinations']: raise ValueError('destinations: {} Must be non-empty'.format( str(config['destinations']))) if not config['mail_server']: raise ValueError('mail_server: {} Must be non-empty'.format( str(config['mail_server']))) return config
def validate(cls, config): """ Validates the given configuration dictionary. Args: config (dict): The dictionary to validate. See parameter() for required format. Raises: KeyError: If a required configuration option is missing. The error message is the missing key. ValueError: If a configuration option's value is not valid. The error message is in the following format: key: value requirement Returns: dict: The dict given as the config argument with missing optional parameters added with default values. """ defaults = { 'port': 445, 'user': '', 'password': '', 'upload': False, 'files': [], 'write_dir': '' } config = api.check_config(config, cls.parameters(), defaults) if config['port'] < 0 or config['port'] > 65535: raise ValueError('port: {} Must be in the range [0, 65535]'.format( str(config['port']))) return config
def validate(cls, config): """ Validates the given configuration dictionary. Makes sure that config['site'] and config['file'] are strings, but does not actually check if they are valid site/filenames. Args: config (dict): The dictionary to validate. See parameters() for required format. Raises: KeyError: If a required configuration option is missing. The error message is the missing key. ValueError: If a configuration option's value is not valid. The error message is in the following format: key: value requirement Returns: dict: The dict given as the config argument, updated with default values for missing optional keys. """ defaults = {'user': '******', 'password': ''} config = api.check_config(config, cls.parameters(), defaults) if not config['site']: raise ValueError('site: {} Must be non-empty'.format( config['site'])) if not config['file']: raise ValueError('file: {} Must be non-empty'.format( config['file'])) return config
def validate(cls, config): config = api.check_config(config, cls.parameters(), {}) # It doesn't make sense to use this task if there are fewer than two tasks. if len(config['tasks']) < 2: raise ValueError( 'tasks: {} Must contain at least two tasks.'.format( config['tasks'])) return config
def validate(cls, config): """ Validate the task configuration. Raises: KeyError: If a required key is missing. ValueError: If a key's value is not valid. """ defaults = {'attachments': [], 'dynamic': False} config = api.check_config(config, cls.parameters(), defaults) return config
def validate(cls, config): defaults = {'days': 0, 'hours': 0, 'minutes': 0, 'seconds': 0} parameters = cls.parameters() optional = parameters['optional'] config = api.check_config(config, parameters, defaults) for key in optional: value = config[key] if value < 0: raise ValueError('{}: {} Must not be negative'.format(key, value)) return config
def validate(cls, config): """ Test for the config component. Arguments: config (dict): The dictionary to validate. Raises: AssertionError: If config is not a dict. KeyError: If a required configuration option is missing. The error message is the missing key. ValueError: if a configuration option's value is not valid. The error message is in the following format: key: value requirement """ defaults = {'somedict': {'yay': 3}, 'somelist': [3.14159]} return api.check_config(config, cls.parameters(), defaults)
def validate(cls, config): """ Validates the given configuration dictionary. Makes sure that config['text_source'] is a string, but does not actually check if it is a valid filename. Also makes sure the each filetype in config['file_types'] is valid Args: config (dict): The dictionary to validate. See parameters() for required format. Raises: ValueError: If a configuration option's value is not valid. The error message is in the following format: key: value requirement Returns: dict: The dict given as the config argument with missing optional parameters added with default values. """ defaults = { 'text_source': 'aliceinwonderland.txt', 'file_types': ['docx'], 'new_doc': True, 'cleanup': False } config = api.check_config(config, cls.parameters(), defaults) if not config['text_source']: # In case someone supplied an empty string for whatever reason. config['text_source'] = 'aliceinwonderland.txt' if not config['file_types']: raise ValueError('file_types: {} Must be non-empty'.format( str(config['file_types']))) for filetype in config['file_types']: if filetype not in { 'docx', 'docm', 'doc', 'dotx', 'dotm', 'dot', 'rtf', 'txt', 'xml' }: raise ValueError('file_types: {} Contains invalid filetype '. format(config['file_types']) + filetype) return config
def validate(cls, config): """ Validate the task configuration. Raises: KeyError: If a required key is missing ValueError: If a key's value does not make sense. Returns: dict: The given configuration with missing optional keys filled in with default values. """ defaults = {'unread': True, 'open_links': 0, 'open_attachments': 0, 'delete_handled': False, 'display_messages': False, 'nuke_outlook': False, 'nuke_folders': [], 'regexes': {}} config = api.check_config(config, cls.parameters(), defaults) open_links = config['open_links'] open_attachments = config['open_attachments'] # 101 because the upper bound is exclusive. if open_links not in range(101): raise ValueError('open_links: {} Must be between 0 and 100.'.format(str(open_links))) if open_attachments not in range(101): raise ValueError('open_attachments: {} Must be between 0 and 100.'.format(str(open_attachments))) regexes = config['regexes'] for regex in regexes: try: # Test that this is a valid regex - regex correctness can't be tested and is up to the user. re.compile(regex) except Exception: raise ValueError('regexes: {} Is not a valid regular expression.'.format(str(regex))) return config
def validate(cls, config): """ Validates the given configuration dictionary. Makes sure that config['commands'] is a list of strings, but does not actually check if the commands are valid. Args: config (dict): The dictionary to validate. See parameters() for required format. Raises: KeyError: If a required configuration option is missing. The error message is the missing key. ValueError: If a configuration option's value is not valid. The error message is in the following format: key: value requirement Returns: dict: The dict given as the config argument """ config = api.check_config(config, cls.parameters(), {'script': False}) if not config['commands']: raise ValueError('commands: {} Cannot be empty'.format( str(config['commands']))) return config
def validate(cls, config, extra_defaults={}): """ All the standard functionality of validate, plus the addition of extra_defaults so subclasses can use the same code. """ defaults = {'sequential': False, 'delay': 0} defaults.update(extra_defaults) config = api.check_config(config, cls.parameters(), defaults) site_list = config['sites'] if not site_list: raise ValueError('sites: {} Must be non-empty.'.format(str(config['sites']))) # Intended to match http:// and https:// at the beginning of a URL. url_pattern = re.compile('^(http|https)://') for site in site_list: if not url_pattern.match(site): raise ValueError('Incorrect URL pattern: {} - must start with http:// or https://'.format(site)) if config['delay'] < 0: raise ValueError('delay: {} Must not be negative.'.format(str(config['delay']))) return config
def validate(cls, config): """ Validates the given configuration dictionary. Args: config (dict): The dictionary to validate. Its keys and values are subclass-specific. Raises: KeyError: If a required configuration option is missing. The error message is the missing key. ValueError: If a configuration option's value is not valid. The error message is in the following format: key: value requirement Returns: dict: The dict given as the config argument with missing optional parameters added with default values. """ defaults = {'seconds': 0.0, 'date': str(datetime.datetime.today().date())} config = api.check_config(config, cls.parameters(), defaults) time = config['time'] try: datetime.datetime.strptime(time, '%H%M').time() except Exception: raise ValueError('time: {} Must be in HHMM format'.format(time)) seconds = config['seconds'] try: assert 0 <= seconds and seconds < 60 except AssertionError: raise ValueError('seconds: {} Must be a number between 0 and 60 non-inclusive'.format(str(seconds))) date = config['date'] try: datetime.datetime.strptime(date, '%Y-%m-%d').date() except Exception: raise ValueError('date: {} Must be in YYYY-MM-DD format'.format(date)) return config
def validate(cls, config): return api.check_config(config, cls.parameters(), {'port': 23})
os.remove("./temp") else: return "error: no auth" else: return "incorrect file echoarea" @route("/f/blacklist.txt") def file_blacklist(): write_to_log("f/blacklist.txt") response.set_header("content-type", "text/plain; charset=utf-8") return open("fblacklist.txt", "r").read() @route("/f/list.txt") def felist(): write_to_log("f/list.tx") response.set_header("content-type", "text/plain; charset=utf-8") ret = "" for fecho in api.fechoareas: flen = len(open("fecho/%s" % fecho[0], "r").read().split("\n")) - 1 ret = ret + fecho[0] + ":" + str(flen) + ":" + fecho[1] + "\n" return ret api.check_config() api.load_config() api.init() if api.web_interface: from api.web import * run(host="0.0.0.0", port=3000)#, quiet=True)
else: return "incorrect file echoarea" @route("/f/blacklist.txt") def file_blacklist(): write_to_log("f/blacklist.txt") response.set_header("content-type", "text/plain; charset=utf-8") return open("fblacklist.txt", "r").read() @route("/f/list.txt") def felist(): write_to_log("f/list.tx") response.set_header("content-type", "text/plain; charset=utf-8") ret = "" for fecho in api.fechoareas: flen = len(open("fecho/%s" % fecho[0], "r").read().split("\n")) - 1 ret = ret + fecho[0] + ":" + str(flen) + ":" + fecho[1] + "\n" return ret api.check_config() api.load_config() api.init() if api.web_interface: from api.web import * run(host="0.0.0.0", port=3000) #, quiet=True)