def _getAPI(self, **kwargs): if 'username' not in kwargs: self.data = self._failureResponse('Missing parameter: username') return else: username = kwargs['username'] if 'password' not in kwargs: self.data = self._failureResponse('Missing parameter: password') return else: password = kwargs['password'] if any([mylar.CONFIG.HTTP_USERNAME is None, mylar.CONFIG.HTTP_PASSWORD is None]): self.data = self._failureResponse('Unable to use this command - username & password MUST be enabled.') return ht_user = mylar.CONFIG.HTTP_USERNAME edc = encrypted.Encryptor(mylar.CONFIG.HTTP_PASSWORD) ed_chk = edc.decrypt_it() if mylar.CONFIG.ENCRYPT_PASSWORDS is True: if username == ht_user and all([ed_chk['status'] is True, ed_chk['password'] == password]): self.data = self._successResponse( {'apikey': mylar.CONFIG.API_KEY} ) else: self.data = self._failureResponse('Incorrect username or password.') else: if username == ht_user and password == mylar.CONFIG.HTTP_PASSWORD: self.data = self._successResponse( {'apikey': mylar.CONFIG.API_KEY} ) else: self.data = self._failureResponse('Incorrect username or password.')
def check_credentials(username, password): """Verifies credentials for username and password. Returns None on success or a string describing the error on failure""" # Adapt to your needs forms_user = cherrypy.request.config['auth.forms_username'] forms_pass = cherrypy.request.config['auth.forms_password'] edc = encrypted.Encryptor(forms_pass) ed_chk = edc.decrypt_it() if mylar.CONFIG.ENCRYPT_PASSWORDS is True: if username == forms_user and all([ed_chk['status'] is True, ed_chk['password'] == password]): return None else: return u"Incorrect username or password." else: if username == forms_user and password == forms_pass: return None else: return u"Incorrect username or password."
def cleaned_config(self): shutil.copy(self.configpath, self.cleanpath) tmpconfig = configparser.SafeConfigParser() tmpconfig.readfp(codecs.open(self.cleanpath, 'r', 'utf8')) for v in self.cleaned_list: try: tmpkey = tmpconfig.get(v[0], v[1]) if all([tmpkey is not None, tmpkey != 'None']): if tmpkey[:5] == '^~$z$': tk = encrypted.Encryptor(tmpkey) tk_stat = tk.decrypt_it() if tk_stat['status'] is True: tmpkey = tk_stat['password'] if tmpkey not in self.keylist: self.keylist.append(tmpkey) tmpconfig.set(v[0], v[1], 'xXX[REMOVED]XXx') except configparser.NoSectionError as e: pass for h in self.hostname_list: hkey = tmpconfig.get(h[0], h[1]) if all([hkey is not None, hkey != 'None']): if hkey[:5] == '^~$z$': hk = encrypted.Encryptor(hkey) hk_stat = tk.decrypt_it() if tk_stat['status'] is True and 'username' not in h[1]: hkey = hk_stat['password'] if hkey not in self.keylist: self.keylist.append(hkey) tmpconfig.set(h[0], h[1], 'xXX[REMOVED]XXx') extra_newznabs = list(zip(*[iter(tmpconfig.get('Newznab', 'extra_newznabs').split(', '))]*6)) extra_torznabs = list(zip(*[iter(tmpconfig.get('Torznab', 'extra_torznabs').split(', '))]*5)) cleaned_newznabs = [] cleaned_torznabs = [] for ens in extra_newznabs: n_host = None n_uid = None n_api = None if ens[1] is not None: n_host = 'xXX[REMOVED]XXx' if ens[3] is not None: nzkey = ens[3] if nzkey[:5] == '^~$z$': nz = encrypted.Encryptor(nzkey) nz_stat = nz.decrypt_it() if nz_stat['status'] is True: nzkey = nz_stat['password'] if nzkey not in self.keylist: self.keylist.append(nzkey) n_api = 'xXX[REMOVED]XXx' if ens[4] is not None: n_uid = 'xXX[REMOVED]XXx' newnewzline = (ens[0], n_host, ens[2], n_api, n_uid, ens[5]) cleaned_newznabs.append(newnewzline) for ets in extra_torznabs: n_host = None n_uid = None n_api = None if ets[1] is not None: n_host = 'xXX[REMOVED]XXx' if ets[2] is not None: tzkey = ets[2] if tzkey[:5] == '^~$z$': tz = encrypted.Encryptor(tzkey) tz_stat = tz.decrypt_it() if tz_stat['status'] is True: tzkey = tz_stat['password'] if tzkey not in self.keylist: self.keylist.append(tzkey) n_api = 'xXX[REMOVED]XXx' if ets[4] is not None: n_uid = 'xXX[REMOVED]XXx' newtorline = (ets[0], n_host, n_api, ets[3], ets[4]) cleaned_torznabs.append(newtorline) tmpconfig.set('Newznab', 'extra_newznabs', ', '.join(self.write_extras(cleaned_newznabs))) tmpconfig.set('Torznab', 'extra_torznabs', ', '.join(self.write_extras(cleaned_torznabs))) try: with codecs.open(self.cleanpath, encoding='utf8', mode='w+') as tmp_configfile: tmpconfig.write(tmp_configfile) logger.fdebug('Configuration cleaned of keys/passwords and written to temporary location.') except IOError as e: logger.warn("Error writing configuration file: %s" % e)