def load(self, dao, token=None): self.config = dao.get_config("proxy_config", "System") self.proxy_type = dao.get_config("proxy_type", None) self.port = dao.get_config("proxy_port", None) self.server = dao.get_config("proxy_server", None) self.username = dao.get_config("proxy_username", None) password = dao.get_config("proxy_password", None) self.exceptions = dao.get_config("proxy_exceptions", None) self.authenticated = (dao.get_config("proxy_authenticated", "0") == "1") if token is None: token = dao.get_config("device_id", None) if password is not None and token is not None: token = token + "_proxy" self.password = decrypt(password, token) else: # If no server binding or no token available # (possibly after token revocation) reset password self.password = ''
def get_proxy_settings(self, device_config=None): """Fetch proxy settings from database""" dc = (self.get_device_config() if device_config is None else device_config) # Decrypt password with token as the secret token = self.get_first_token() if dc.proxy_password is not None and token is not None: password = decrypt(dc.proxy_password, token) else: # If no server binding or no token available # (possibly after token revocation) reset password password = '' return ProxySettings(config=dc.proxy_config, proxy_type=dc.proxy_type, server=dc.proxy_server, port=dc.proxy_port, authenticated=dc.proxy_authenticated, username=dc.proxy_username, password=password, exceptions=dc.proxy_exceptions)