def check_setting_str(config, cfg_name, item_name, def_val, log=True): # For passwords you must include the word `password` in the item_name and add `helpers.encrypt(ITEM_NAME, ENCRYPTION_VERSION)` in save_config() if bool(item_name.find('password') + 1): encryption_version = sickbeard.ENCRYPTION_VERSION else: encryption_version = 0 try: my_val = helpers.decrypt(config[cfg_name][item_name], encryption_version) except: my_val = def_val try: config[cfg_name][item_name] = helpers.encrypt( my_val, encryption_version) except: config[cfg_name] = {} config[cfg_name][item_name] = helpers.encrypt( my_val, encryption_version) if log: logger.log(item_name + " -> " + my_val, logger.DEBUG) else: logger.log(item_name + " -> ******", logger.DEBUG) return my_val
def check_setting_str(config, cfg_name, item_name, def_val, silent=True, censor_log=False): # For passwords you must include the word `password` in the item_name and add `helpers.encrypt(ITEM_NAME, ENCRYPTION_VERSION)` in save_config() if bool(item_name.find('password') + 1): log = False encryption_version = sickbeard.ENCRYPTION_VERSION else: encryption_version = 0 try: my_val = helpers.decrypt(config[cfg_name][item_name], encryption_version) if str(my_val) == str(None): raise except: my_val = def_val try: config[cfg_name][item_name] = helpers.encrypt(my_val, encryption_version) except: config[cfg_name] = {} config[cfg_name][item_name] = helpers.encrypt(my_val, encryption_version) if censor_log or (cfg_name, item_name) in logger.censoredItems.items(): logger.censoredItems[cfg_name, item_name] = my_val if not silent: logger.log(item_name + " -> " + str(my_val), logger.DEBUG) return my_val
def check_setting_str(config, cfg_name, item_name, def_val, log=True): """ For passwords you must include the word `password` in the item_name and add `helpers.encrypt(ITEM_NAME, ENCRYPTION_VERSION)` in save_config() """ if bool(item_name.find('password') + 1): log = False encryption_version = sickbeard.ENCRYPTION_VERSION else: encryption_version = 0 try: my_val = helpers.decrypt(config[cfg_name][item_name], encryption_version) except: my_val = def_val try: config[cfg_name][item_name] = helpers.encrypt(my_val, encryption_version) except: config[cfg_name] = {} config[cfg_name][item_name] = helpers.encrypt(my_val, encryption_version) if log: logger.log('%s -> %s' % (item_name, my_val), logger.DEBUG) else: logger.log('%s -> ******' % item_name, logger.DEBUG) return my_val
def check_setting_str(config, cfg_name, item_name, def_val, silent=True, censor_log=False): # For passwords you must include the word `password` in the item_name and add `helpers.encrypt(ITEM_NAME, ENCRYPTION_VERSION)` in save_config() if not censor_log: censor_level = sickbeard.common.privacy_levels['stupid'] else: censor_level = sickbeard.common.privacy_levels[censor_log] privacy_level = sickbeard.common.privacy_levels[sickbeard.PRIVACY_LEVEL] if bool(item_name.find('password') + 1): encryption_version = sickbeard.ENCRYPTION_VERSION else: encryption_version = 0 try: my_val = helpers.decrypt(config[cfg_name][item_name], encryption_version) if str(my_val) == str(None): raise except Exception: my_val = def_val try: config[cfg_name][item_name] = helpers.encrypt(my_val, encryption_version) except Exception: config[cfg_name] = {} config[cfg_name][item_name] = helpers.encrypt(my_val, encryption_version) if privacy_level >= censor_level or (cfg_name, item_name) in logger.censored_items.iteritems(): if not item_name.endswith('custom_url'): logger.censored_items[cfg_name, item_name] = my_val if not silent: logger.log(item_name + " -> " + my_val, logger.DEBUG) return my_val
def check_setting_str(config, cfg_name, item_name, def_val, log=True): """ For passwords you must include the word `password` in the item_name and add `helpers.encrypt(ITEM_NAME, ENCRYPTION_VERSION)` in save_config() """ if bool(item_name.find('password') + 1): log = False encryption_version = sickbeard.ENCRYPTION_VERSION else: encryption_version = 0 try: my_val = helpers.decrypt(config[cfg_name][item_name], encryption_version) except (StandardError, Exception): my_val = def_val try: config[cfg_name][item_name] = helpers.encrypt( my_val, encryption_version) except (StandardError, Exception): config[cfg_name] = {} config[cfg_name][item_name] = helpers.encrypt( my_val, encryption_version) if log: logger.log('%s -> %s' % (item_name, my_val), logger.DEBUG) else: logger.log('%s -> ******' % item_name, logger.DEBUG) return (my_val, def_val)['None' == my_val]
def check_setting_str(config, cfg_name, item_name, def_val=six.text_type(''), silent=True, censor_log=False): if not isinstance(def_val, six.string_types): logger.log( "{dom}:{key} default value is not the correct type. Expected {t}, got {dt}".format( dom=cfg_name, key=item_name, t='string', dt=type(def_val)), logger.ERROR) # For passwords you must include the word `password` in the item_name and add `helpers.encrypt(ITEM_NAME, ENCRYPTION_VERSION)` in save_config() encryption_version = (0, sickbeard.ENCRYPTION_VERSION)['password' in item_name] try: if not (check_section(config, cfg_name) and item_name in config[cfg_name]): raise ValueError my_val = helpers.decrypt(config[cfg_name][item_name], encryption_version) if six.text_type(my_val) == six.text_type(None) or not six.text_type(my_val): raise ValueError except (ValueError, IndexError, KeyError): my_val = def_val if cfg_name not in config: config[cfg_name] = {} config[cfg_name][item_name] = helpers.encrypt(my_val, encryption_version) if (censor_log or (cfg_name, item_name) in six.iteritems(logger.censored_items)) and not item_name.endswith('custom_url'): logger.censored_items[cfg_name, item_name] = my_val if not silent: logger.log(item_name + " -> " + my_val, logger.DEBUG) return six.text_type(my_val)
def check_setting_str(config, cfg_name, item_name, def_val=six.text_type(''), silent=True, censor_log=False): """ Checks config setting of string types :param config: config object :type config: ConfigObj() :param cfg_name: section name of config :param item_name: item name of section :param def_val: default value to return in case a value can't be retrieved from config or if couldn't be converted (default: empty six.text_type) :param silent: don't log result to debug log (default: True) :param censor_log: overrides and adds this setting to logger censored items (default: False) :return: decrypted value of `config[cfg_name][item_name]` or `def_val` (see cases of def_val) :rtype: six.text_type """ if not isinstance(def_val, six.string_types): logger.log( "{dom}:{key} default value is not the correct type. Expected {t}, got {dt}".format( dom=cfg_name, key=item_name, t='string', dt=type(def_val)), logger.ERROR) # For passwords you must include the word `password` in the item_name and add `helpers.encrypt(ITEM_NAME, ENCRYPTION_VERSION)` in save_config() encryption_version = (0, sickbeard.ENCRYPTION_VERSION)['password' in item_name] try: if not (check_section(config, cfg_name) and item_name in config[cfg_name]): raise ValueError my_val = helpers.decrypt(config[cfg_name][item_name], encryption_version) if six.text_type(my_val) == six.text_type(None) or not six.text_type(my_val): raise ValueError except (ValueError, IndexError, KeyError): my_val = def_val if cfg_name not in config: config[cfg_name] = {} config[cfg_name][item_name] = helpers.encrypt(my_val, encryption_version) if (censor_log or (cfg_name, item_name) in six.iteritems(logger.censored_items)) and not item_name.endswith('custom_url'): logger.censored_items[cfg_name, item_name] = my_val if not silent: logger.log(item_name + " -> " + my_val, logger.DEBUG) return six.text_type(my_val)
def test_encrypt(self): helpers.unique_key1 = '0x12d48f154876c16164a1646' crypt_test = [ { 'param': ('Test', 0, False), 'result': 'Test' }, { 'param': ('Test', 1, False), 'result': 'ZB1CRg==' }, { 'param': ('ZB1CRg==', 1, True), 'result': 'Test' }, ] for t in crypt_test: self.assertEqual(t['result'], helpers.encrypt(*t['param']))
def save_config(): new_config = ConfigObj() new_config.filename = CONFIG_FILE # For passwords you must include the word `password` in the item_name and add `helpers.encrypt(ITEM_NAME, ENCRYPTION_VERSION)` in save_config() new_config['General'] = {} new_config['General']['config_version'] = CONFIG_VERSION new_config['General']['encryption_version'] = int(ENCRYPTION_VERSION) new_config['General']['log_dir'] = ACTUAL_LOG_DIR if ACTUAL_LOG_DIR else 'Logs' new_config['General']['socket_timeout'] = SOCKET_TIMEOUT new_config['General']['web_port'] = WEB_PORT new_config['General']['web_host'] = WEB_HOST new_config['General']['web_ipv6'] = int(WEB_IPV6) new_config['General']['web_log'] = int(WEB_LOG) new_config['General']['web_root'] = WEB_ROOT new_config['General']['web_username'] = WEB_USERNAME new_config['General']['web_password'] = helpers.encrypt(WEB_PASSWORD, ENCRYPTION_VERSION) new_config['General']['localhost_ip'] = LOCALHOST_IP new_config['General']['cpu_preset'] = CPU_PRESET new_config['General']['anon_redirect'] = ANON_REDIRECT new_config['General']['use_api'] = int(USE_API) new_config['General']['api_key'] = API_KEY new_config['General']['debug'] = int(DEBUG) new_config['General']['handle_reverse_proxy'] = int(HANDLE_REVERSE_PROXY) new_config['General']['update_frequency'] = int(UPDATE_FREQUENCY) new_config['General']['version_notify'] = int(VERSION_NOTIFY) new_config['General']['auto_update'] = int(AUTO_UPDATE) new_config['General']['launch_browser'] = int(LAUNCH_BROWSER) new_config['General']['proxy_setting'] = PROXY_SETTING new_config['General']['use_listview'] = int(USE_LISTVIEW) new_config['General']['extra_scripts'] = '|'.join(EXTRA_SCRIPTS) new_config['General']['git_path'] = GIT_PATH new_config['Plex'] = {} new_config['Plex']['use_plex'] = int(USE_PLEX) new_config['Plex']['plex_notify_onsnatch'] = int(PLEX_NOTIFY_ONSNATCH) new_config['Plex']['plex_notify_ondownload'] = int(PLEX_NOTIFY_ONDOWNLOAD) new_config['Plex']['plex_update_library'] = int(PLEX_UPDATE_LIBRARY) new_config['Plex']['plex_server_host'] = PLEX_SERVER_HOST new_config['Plex']['plex_host'] = PLEX_HOST new_config['Plex']['plex_username'] = PLEX_USERNAME new_config['Plex']['plex_password'] = helpers.encrypt(PLEX_PASSWORD, ENCRYPTION_VERSION) new_config['Boxcar2'] = {} new_config['Boxcar2']['use_boxcar2'] = int(USE_BOXCAR2) new_config['Boxcar2']['boxcar2_notify_onsnatch'] = int(BOXCAR2_NOTIFY_ONSNATCH) new_config['Boxcar2']['boxcar2_notify_ondownload'] = int(BOXCAR2_NOTIFY_ONDOWNLOAD) new_config['Boxcar2']['boxcar2_accesstoken'] = BOXCAR2_ACCESSTOKEN new_config['Trakt'] = {} new_config['Trakt']['use_trakt'] = int(USE_TRAKT) new_config['Trakt']['trakt_username'] = TRAKT_USERNAME new_config['Trakt']['trakt_password'] = helpers.encrypt(TRAKT_PASSWORD, ENCRYPTION_VERSION) new_config['Trakt']['trakt_api'] = TRAKT_API new_config['Trakt']['trakt_remove_watchlist'] = int(TRAKT_REMOVE_WATCHLIST) new_config['Trakt']['trakt_use_watchlist'] = int(TRAKT_USE_WATCHLIST) new_config['Trakt']['trakt_method_add'] = TRAKT_METHOD_ADD new_config['Trakt']['trakt_start_paused'] = int(TRAKT_START_PAUSED) new_config['Trakt']['trakt_use_recommended'] = int(TRAKT_USE_RECOMMENDED) new_config['Trakt']['trakt_sync'] = int(TRAKT_SYNC) new_config['GUI'] = {} new_config['GUI']['gui_name'] = GUI_NAME new_config['GUI']['fuzzy_dating'] = int(FUZZY_DATING) new_config['GUI']['trim_zero'] = int(TRIM_ZERO) new_config['GUI']['date_preset'] = DATE_PRESET new_config['GUI']['time_preset'] = TIME_PRESET_W_SECONDS new_config['GUI']['timezone_display'] = TIMEZONE_DISPLAY new_config['EventGhost'] = {} new_config['EventGhost']['eventghost_plex'] = int(USE_PLEX) new_config['EventGhost']['eventghost_server_host'] = PLEX_SERVER_HOST new_config['EventGhost']['eventghost_host'] = PLEX_HOST new_config['Drives'] = {} new_config['Drives']['use_drives'] = int(USE_DRIVES) new_config['Drives']['use_driveA'] = int(USE_DRIVEA) new_config['Drives']['use_driveB'] = int(USE_DRIVEB) new_config['Drives']['use_driveC'] = int(USE_DRIVEC) new_config['Drives']['driveA_name'] = DRIVEA_NAME new_config['Drives']['driveB_name'] = DRIVEB_NAME new_config['Drives']['driveC_name'] = DRIVEC_NAME new_config['Sickbeard'] = {} new_config['Sickbeard']['use_sickbeard'] = int(USE_SICKBEARD) new_config['Sickbeard']['sickbeard_host'] = SICKBEARD_HOST new_config['Sickbeard']['sickbeard_api'] = SICKBEARD_API new_config['Speedfan'] = {} new_config['Speedfan']['use_speedfan'] = int(USE_SPEEDFAN) new_config['Speedfan']['speedfan_log_location'] = SPEEDFAN_LOG_LOCATION new_config.write()