def __init__(self, config=None, args=None, timeout=7, return_to_browser=False): # Store the arg/config self.args = args self.config = config # Default client mode self._client_mode = 'glances' # Return to browser or exit self.return_to_browser = return_to_browser # Build the URI if args.password != "": self.uri = 'http://{}:{}@{}:{}'.format(args.username, args.password, args.client, args.port) elif args.password_from_config and self.config.get_value('passwords', args.client): plain = self.config.get_value('passwords', str(args.client)) worker = GlancesPassword() self.uri = 'http://{}:{}@{}:{}'.format('glances', worker.sha256_hash(plain), args.client, args.port) else: self.uri = 'http://{}:{}'.format(args.client, args.port) logger.debug("Try to connect to {}".format(self.uri)) # Try to connect to the URI transport = GlancesClientTransport() # Configure the server timeout transport.set_timeout(timeout) try: self.client = ServerProxy(self.uri, transport=transport) except Exception as e: self.log_and_exit("Client couldn't create socket {}: {}".format(self.uri, e))
def check_auth(self, username, password): """Check if a username/password combination is valid.""" if username == self.args.username: from glances.password import GlancesPassword pwd = GlancesPassword() return pwd.check_password(self.args.password, pwd.sha256_hash(password)) else: return False