Exemplo n.º 1
0
 def do_shell_session(self):
     client_enable = istrue(self.get_ns_tag('client', 'log_me', 'no'))
     # The following line is useless because the site namespace is not
     # yet set up at this point. We get the site 'log_me' tag by
     # overriding the authorize method, hence the UGLY HACK comment.
     site_enable = istrue(self.get_ns_tag('site', 'log_me', 'no'))
     if client_enable or site_enable:
         TTYrplProxyShell.register()
     return Server.do_shell_session(self)
Exemplo n.º 2
0
 def authorize(self, user_site, need_login=True):
     # UGLY HACK
     auth = Server.authorize(self, user_site, need_login=True)
     if auth:
         if istrue(self.get_ns_tag('site', 'log_me', 'no')):
             TTYrplProxyShell.register()
     return auth
Exemplo n.º 3
0
    def authenticate(self, **tokens):
        resp = False
        for token in self.auth_token_order():
            if token in tokens.keys() and tokens[token] is not None:
                if token == 'password':
                    query = """select id from client where uid='%s' and
                            '%s' = password""" % (Q(self.username),
                                    Q(sha.new(tokens['password']).hexdigest()))
                    if self.sql_get(query):
                        resp = True
                        break
                elif token == 'pubkey':
                    pubkeys = self.get_token(token, '').split('\n')
                    pubkeys = [ pk.split()[0] for pk in pubkeys if len(pk) ]
                    for pk in pubkeys:
                        if pk == tokens[token]:
                            resp = True
                            break
                    ClientDB()._unauth_pubkey = tokens[token]

                elif self.get_token(token) == tokens[token]:
                    resp = True
                    break
        pubkey = getattr(ClientDB(), '_unauth_pubkey', None)
        if resp and pubkey and istrue(get_config('sshproxy')['auto_add_key']):
            tokens['pubkey'] = pubkey
            if self.add_pubkey(**tokens):
                Server().message_client("WARNING: Your public key"
                                        " has been added to the keyring\n")
            del ClientDB()._unauth_pubkey
        return resp
Exemplo n.º 4
0
    def authenticate(self, **tokens):
        resp = False
        for token in self.auth_token_order():
            if token in tokens.keys() and tokens[token] is not None:
                if token == 'password':
                    query = """select id from client where uid='%s' and
                            '%s' = password""" % (
                        Q(self.username),
                        Q(sha.new(tokens['password']).hexdigest()))
                    if self.sql_get(query):
                        resp = True
                        break
                elif token == 'pubkey':
                    pubkeys = self.get_token(token, '').split('\n')
                    pubkeys = [pk.split()[0] for pk in pubkeys if len(pk)]
                    for pk in pubkeys:
                        if pk == tokens[token]:
                            resp = True
                            break
                    ClientDB()._unauth_pubkey = tokens[token]

                elif self.get_token(token) == tokens[token]:
                    resp = True
                    break
        pubkey = getattr(ClientDB(), '_unauth_pubkey', None)
        if resp and pubkey and istrue(get_config('sshproxy')['auto_add_key']):
            tokens['pubkey'] = pubkey
            if self.add_pubkey(**tokens):
                Server().message_client("WARNING: Your public key"
                                        " has been added to the keyring\n")
            del ClientDB()._unauth_pubkey
        return resp
Exemplo n.º 5
0
    def report_failure(self, reason, *args, **kwargs):
        """Reporting error
        
        @param reason: reason of failure"""
        from datetime import datetime

        cfg = get_config('email_notifier')

        tpldict = {}
        
        tpldict['reason'] = reason
        if len(args) > 0:
            tpldict['msg'] = args[0]
        else:
            tpldict['msg'] = "No additional message."
        
        
        tpldict['client'] = self.username
        tpldict['site'] = self.g_site
        tpldict['when'] = datetime.now()
        tpldict['conntype'] = self.g_conn_type
        tpldict['sshproxy_id'] = cfg['smtp_sender'] # ?


        server = cfg['smtp_server']
        try:
            port = cfg['smtp_port']
        except ValueError:
            port = 25
            
        login = cfg['smtp_login']
        password = cfg['smtp_password']
        
        admin_email = cfg['admin_email']
        sender = cfg['smtp_sender']

        tls = istrue(cfg["smtp_tls"])
        
        msg = cfg['message_template'] % tpldict

        if admin_email != "" and "@" in admin_email:
            email = Email(server, port, login, password, tls=tls)
            
            email.new(admin_email, sender, "Failure Report", msg)
            
            try:
                email.send_email()
            except smtplib.SMTPException, e:
                log.exception(e)
Exemplo n.º 6
0
    def report_failure(self, reason, *args, **kwargs):
        """Reporting error
        
        @param reason: reason of failure"""
        from datetime import datetime

        cfg = get_config('email_notifier')

        tpldict = {}

        tpldict['reason'] = reason
        if len(args) > 0:
            tpldict['msg'] = args[0]
        else:
            tpldict['msg'] = "No additional message."

        tpldict['client'] = self.username
        tpldict['site'] = self.g_site
        tpldict['when'] = datetime.now()
        tpldict['conntype'] = self.g_conn_type
        tpldict['sshproxy_id'] = cfg['smtp_sender']  # ?

        server = cfg['smtp_server']
        try:
            port = cfg['smtp_port']
        except ValueError:
            port = 25

        login = cfg['smtp_login']
        password = cfg['smtp_password']

        admin_email = cfg['admin_email']
        sender = cfg['smtp_sender']

        tls = istrue(cfg["smtp_tls"])

        msg = cfg['message_template'] % tpldict

        if admin_email != "" and "@" in admin_email:
            email = Email(server, port, login, password, tls=tls)

            email.new(admin_email, sender, "Failure Report", msg)

            try:
                email.send_email()
            except smtplib.SMTPException, e:
                log.exception(e)
Exemplo n.º 7
0
 def update_smtp_tls(value):
     if istrue(value):
         cfg['smtp_tls'] = 'yes'
     else:
         cfg['smtp_tls'] = 'no'
Exemplo n.º 8
0
 def update_smtp_tls(value):
     if istrue(value):
         cfg['smtp_tls'] = 'yes'
     else:
         cfg['smtp_tls'] = 'no'