Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
 def check_user(self, username, password):
     # Check username and password in the dictionary
     if username in self.server.user_dict:
         from glances.password import GlancesPassword
         pwd = GlancesPassword()
         return pwd.check_password(self.server.user_dict[username], password)
     else:
         return False
Ejemplo n.º 3
0
 def check_user(self, username, password):
     # Check username and password in the dictionary
     if username in self.server.user_dict:
         from glances.password import GlancesPassword
         pwd = GlancesPassword()
         return pwd.check_password(self.server.user_dict[username], password)
     else:
         return False
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
    def __get_password(self, description='', confirm=False, clear=False, username='******'):
        """Read a password from the command line.

        - if confirm = True, with confirmation
        - if clear = True, plain (clear password)
        """
        from glances.password import GlancesPassword
        password = GlancesPassword(username=username)
        return password.get_password(description, confirm, clear)
Ejemplo n.º 7
0
    def __get_password(self, description='', confirm=False, clear=False, username='******'):
        """Read a password from the command line.

        - if confirm = True, with confirmation
        - if clear = True, plain (clear password)
        """
        from glances.password import GlancesPassword
        password = GlancesPassword(username=username)
        return password.get_password(description, confirm, clear)