Esempio n. 1
0
def session_load(sid):
    validate_non_empty_string(sid)
    try:
        # Load session.
        session = kweb_session.ksession_get_session(sid, database=sess_database)
    except Exception, e:
        log.error("Session error: '%s'." % ( str(e) ) )
        raise xmlrpclib.Fault(101, "Internal error.")
Esempio n. 2
0
    def session_login(self, login, password):
        # Initialize the database (kctl).
        db_init()

        # Validate parameters.
        login = validate_login(login)
        password = validate_password(password)

        # Load config
        config = CustomConfigParser()
        config.read(ini_conf_path)

        # Check login/pass pair.
        if not config.has_section(login):
            raise xmlrpclib.Fault(201, "Invalid login or password.")
        goodpass = config.get_default(login, "password", "").strip(" ")
        if goodpass == "":
            log.error("Invalid configuration 'password' for login '%s'." % ( login ) )
            raise xmlrpclib.Fault(201, "Invalid login or password.")                
        if goodpass != password: 
            raise xmlrpclib.Fault(201, "Invalid login or password.")

        # Create session.
        session = kweb_session.ksession_get_session(database=sess_database)
        session.data["kpsapi"] = 1
        session.data["start_stamp"] = int(time.time())

        # Load security context.
        security_ctx = config.get_default(login, "security_ctx", "").strip(" ")
        if security_ctx not in valid_security_contexts:
            log.error("Invalid configuration 'security_ctx' for login '%s'." % ( login ) )
            raise xmlrpclib.Fault(106, "Invalid KPS API configuration.")
        session.data["security_ctx"] = security_ctx
        if session.data["security_ctx"] == KAPI_SECURITY_CTX_ORG:
            str_org_id = config.get_default(login, "org_id", "").strip(" ")
            if not str_org_id.isdigit():
                log.error("Invalid configuration 'org_id' for login '%s'." % ( login ) )
                raise xmlrpclib.Fault(106, "Invalid KPS API configuration.")
            org_id = int(str_org_id)
            if org_id == 0:
                org_id = sdb_get_main_org_id()
                if not org_id:
                     raise xmlrpclib.Fault(241, "No main organization yet.")
            session.data["org_id"] = org_id

        # Load keys.
        session.data["main_key_id"] = main_key_id()
        try:
            str_key_id = config.get(login, "key_id").strip(" ")
            if str_key_id == "":
                session.data["key_id"] = session.data["main_key_id"]
            elif str_key_id.isdigit():
                session.data["key_id"] = int(str_key_id)
            else:
                log.error("Invalid configuration 'key_id' for login '%s'." % ( login ) )
                raise xmlrpclib.Fault(106, "Invalid KPS API configuration.")
        except ConfigParser.NoOptionError, e:
            session.data["key_id"] = session.data["main_key_id"]
Esempio n. 3
0
    def session_login(self, login, password):
        # Initialize the database (kctl).
        db_init()

        # Validate parameters.
        login = validate_login(login)
        password = validate_password(password)

        # Check login/pass pair.
        if not self.config.has_section(login):
            raise xmlrpclib.Fault(201, "No password configured.")
        goodpass = self.config.get_default(login, "password", "").strip(" ")
        if goodpass == "":
            log.error("Invalid configuration 'password' for login '%s'." % ( login ) )
            raise xmlrpclib.Fault(201, "No password configured.")                
        if goodpass != password: 
            raise xmlrpclib.Fault(201, "Invalid login or password.")

        db_name = self.config.get('db', 'db_name')
        db_host = self.config.get('db', 'db_host')
        db_port = self.config.get('db', 'db_port')
        db_user = self.config.get('db', 'db_user')
        db_pwd = self.config.get('db', 'db_pwd')

        # Create session.
        session = kweb_session.ksession_get_session(db_name = db_name, db_host = db_host,
                                                    db_port = db_port, db_user = db_user,
                                                    db_pwd = db_pwd)
        session.data["kpsapi"] = 1
        session.data["start_stamp"] = int(time.time())

        # Load security context.
        security_ctx = self.config.get_default(login, "security_ctx", "").strip(" ")
        if security_ctx not in valid_security_contexts:
            log.error("Invalid configuration 'security_ctx' for login '%s'." % ( login ) )
            raise xmlrpclib.Fault(106, "Invalid KPS API configuration.")
        session.data["security_ctx"] = security_ctx
        if session.data["security_ctx"] == KAPI_SECURITY_CTX_ORG:
            str_org_id = self.config.get_default(login, "org_id", "").strip(" ")
            if not str_org_id.isdigit():
                log.error("Invalid configuration 'org_id' for login '%s'." % ( login ) )
                raise xmlrpclib.Fault(106, "Invalid KPS API configuration.")
            org_id = int(str_org_id)
            if org_id == 0:
                org_id = sdb_get_main_org_id()
                if not org_id:
                     raise xmlrpclib.Fault(241, "No main organization yet.")
            session.data["org_id"] = org_id

        # Save session.
        session.save()

        log.info("User '%s' logged... session id: '%s'." % ( login, session.sid ) )
        return session.sid
Esempio n. 4
0
def session_load(sid, config):
    validate_non_empty_string(sid)
    try:
        # Load session.
        session = kweb_session.ksession_get_session(db_name = config.get('db', 'db_name'),
                                                    db_host = config.get('db', 'db_host'),
                                                    db_port = config.get('db', 'db_port'),
                                                    db_user = config.get('db', 'db_user'),
                                                    db_pwd = config.get('db', 'db_pwd'),
                                                    sid = sid)
    except Exception, e:
        log.error("Session error: '%s'." % ( str(e) ) )
        raise xmlrpclib.Fault(101, "Internal error (" + str(e) + ").")