示例#1
0
    def deleteQuery(self,ibs_query,src,action,**args):
        self.users=args["users"]
        self.user_ids=self.users.keys()
        self.old_values=[]

        for user_id in self.user_ids:
            loaded_user = self.users[user_id]
            old_value = self.AUDIT_LOG_NOVALUE
            
            if loaded_user.userHasAttr("email_address"):
                ibs_query += self.deleteEmailAddressAttrQuery(user_id)
                
                old_value = loaded_user.getUserAttrs()["email_address"]
                
                if defs.USER_AUDIT_LOG:
                    ibs_query += user_main.getUserAuditLogManager().userAuditLogQuery(args["admin_obj"].getAdminID(),
                                                                              True,
                                                                              loaded_user.getUserID(),
                                                                              "email_address",
                                                                              old_value,
                                                                              self.AUDIT_LOG_NOVALUE)

            self.old_values.append(old_value)
            
        return ibs_query
示例#2
0
    def deleteQuery(self,ibs_query,src,action,**args):
        users=args["users"]

        for user_id in users:
            loaded_user=users[user_id]
            if not loaded_user.userHasAttr("persistent_lan_mac"):
                continue
                
            ibs_query += self.__deletePlanUserAttrsQuery(user_id)
            self.deleted_users.append((user_id,
                                       loaded_user.getUserAttrs()["persistent_lan_mac"],
                                       loaded_user.getUserAttrs()["persistent_lan_ip"],
                                       loaded_user.getUserAttrs()["persistent_lan_ras_id"]))

            if defs.USER_AUDIT_LOG:
                ibs_query += user_main.getUserAuditLogManager().userAuditLogQuery(args["admin_obj"].getAdminID(),
                                                                              True,
                                                                              loaded_user.getUserID(),
                                                                              "persistent_lan_mac",
                                                                              loaded_user.getUserAttrs()["persistent_lan_mac"],
                                                                              self.AUDIT_LOG_NOVALUE)

                ibs_query += user_main.getUserAuditLogManager().userAuditLogQuery(args["admin_obj"].getAdminID(),
                                                                              True,
                                                                              loaded_user.getUserID(),
                                                                              "persistent_lan_ip",
                                                                              loaded_user.getUserAttrs()["persistent_lan_ip"],
                                                                              self.AUDIT_LOG_NOVALUE)
            
                ibs_query += user_main.getUserAuditLogManager().userAuditLogQuery(args["admin_obj"].getAdminID(),
                                                                              True,
                                                                              loaded_user.getUserID(),
                                                                              "persistent_lan_ras_ip",
                                                                              ras_main.getLoader().getRasByID(int(loaded_user.getUserAttrs()["persistent_lan_ras_id"])).getRasIP(),
                                                                              self.AUDIT_LOG_NOVALUE)

        return ibs_query
示例#3
0
文件: group.py 项目: sankopay/IBSng
    def updateQuery(self, ibs_query, src, action, **args):
        group_obj = group_main.getLoader().getGroupByName(self.group_name)
        for user_id in args["users"]:
            ibs_query += ibs_db.createUpdateQuery(
                "users", {"group_id": group_obj.getGroupID()},
                "user_id=%s" % user_id)
            if defs.USER_AUDIT_LOG:
                ibs_query += user_main.getUserAuditLogManager(
                ).userAuditLogQuery(
                    args["admin_obj"].getAdminID(), True, user_id, "group",
                    args["users"]
                    [user_id].getBasicUser().getGroupObj().getGroupName(),
                    self.group_name)

        return ibs_query
示例#4
0
    def deleteQuery(self, ibs_query, src, action, **args):
        users = args["users"]

        for user_id in users:
            loaded_user = users[user_id]
            if loaded_user.userHasAttr("voip_username"):
                ibs_query += self.deleteVoIPUserAttrsQuery(user_id)

                if defs.USER_AUDIT_LOG:
                    ibs_query += user_main.getUserAuditLogManager(
                    ).userAuditLogQuery(
                        args["admin_obj"].getAdminID(), True,
                        loaded_user.getUserID(), "voip_username",
                        loaded_user.getUserAttrs()["voip_username"],
                        self.AUDIT_LOG_NOVALUE)

        return ibs_query
示例#5
0
    def genQueryAuditLogQuery(self, ibs_query, attr_name, old_value, new_value,
                              is_user, obj, admin_obj):
        """
            add query to ibs_query, that insert rows of changing attr_name of objs to audit_log
            attr_updaters can overide this, to add query themselves
            obj is list of loaded_users or a single group_obj
        """
        old_value, new_value = self.genQueryAuditLogPrepareValues(
            attr_name, old_value, new_value)

        if is_user:
            obj_id = obj.getUserID()
        else:
            obj_id = obj.getGroupID()

        ibs_query += user_main.getUserAuditLogManager().userAuditLogQuery(
            admin_obj.getAdminID(), is_user, obj_id, attr_name, old_value,
            new_value)
示例#6
0
    def changeQuery(self, ibs_query, src, action, **args):
        admin_obj = args["admin_obj"]
        users = args["users"]
        user_ids = users.keys()
        user_ids.sort()

        self.__parseVoIPAttrs()
        self.__changeCheckInput(users, admin_obj)

        null_queries = IBSQuery()
        real_queries = IBSQuery()

        i = 0
        for user_id in user_ids:
            loaded_user = users[user_id]
            if loaded_user.userHasAttr("voip_username"):
                null_queries += self.updateVoIPUserAttrsToNullQuery(user_id)
                real_queries += self.updateVoIPUserAttrsQuery(
                    user_id, self.usernames[i],
                    self.passwords[i].getPassword())
                old_value = loaded_user.getUserAttrs()["voip_username"]
            else:
                real_queries += self.insertVoIPUserAttrsQuery(
                    user_id, self.usernames[i],
                    self.passwords[i].getPassword())

                old_value = self.AUDIT_LOG_NOVALUE

            if defs.USER_AUDIT_LOG:
                ibs_query += user_main.getUserAuditLogManager(
                ).userAuditLogQuery(args["admin_obj"].getAdminID(), True,
                                    loaded_user.getUserID(), "voip_username",
                                    old_value, self.usernames[i])

            i += 1

        ibs_query += null_queries
        ibs_query += real_queries

        if self.voip_save:
            user_main.getAddUserSaveActions().newAddUser(
                ibs_query, user_ids, self.usernames, self.passwords,
                admin_obj.getAdminID(), "VoIP", "")
        return ibs_query
示例#7
0
    def deleteQuery(self,ibs_query,src,action,**args):
        users=args["users"]

        for user_id in users:
            loaded_user=users[user_id]
            if not loaded_user.userHasAttr("caller_id"):
                continue
                
            ibs_query += self.__deleteUserCallerIDsQuery(user_id)

            if defs.USER_AUDIT_LOG:
                ibs_query += user_main.getUserAuditLogManager().userAuditLogQuery(args["admin_obj"].getAdminID(),
                                                                              True,
                                                                              loaded_user.getUserID(),
                                                                              "caller_id",
                                                                              loaded_user.getUserAttrs()["caller_id"],
                                                                              self.AUDIT_LOG_NOVALUE)

        return ibs_query
示例#8
0
    def changeQuery(self,ibs_query,src,action,**args):

        self.changeCheckInput(src, action, args)

        self.users=args["users"]
        self.user_ids = self.users.keys()
        self.user_ids.sort()

        self.old_values=[]

        admin_obj=args["admin_obj"]

        i=0
        for user_id in self.user_ids:
            loaded_user=self.users[user_id]
        
            if loaded_user.userHasAttr("email_address"):
                ibs_query += self.updateEmailAddressAttrQuery(user_id,
                                                              self.email_address[i])
                old_value = loaded_user.getUserAttrs()["email_address"]

            else:
                ibs_query +=self.insertEmailAddressAttrQuery(user_id,
                                                              self.email_address[i])
                old_value = self.AUDIT_LOG_NOVALUE

            self.old_values.append(old_value)

            if defs.USER_AUDIT_LOG:
                ibs_query += user_main.getUserAuditLogManager().userAuditLogQuery(admin_obj.getAdminID(),
                                                                              True,
                                                                              loaded_user.getUserID(),
                                                                              "email_address",
                                                                              old_value,
                                                                              self.email_address[i])




            i+=1

        return ibs_query        
示例#9
0
    def __delUserQuery(self, ibs_query, user_ids, del_connections,
                       del_audit_logs):

        user_id_conds = self.__delUserCreateCondition(user_ids)

        ibs_query += self.__delUserAttrsQuery(user_id_conds)
        ibs_query += self.__delUserNormalAttrsQuery(user_id_conds)
        ibs_query += self.__delUserPLanAttrsQuery(user_id_conds)
        ibs_query += self.__delUserCallerIDAttrsQuery(user_id_conds)
        ibs_query += self.__delUserVoIPAttrsQuery(user_id_conds)
        ibs_query += self.__delUserMessagesQuery(user_id_conds)
        ibs_query += self.__delUserWebAnalyzerLogsQuery(user_id_conds)
        ibs_query += self.__delUserBwSnapshotsQuery(user_id_conds)

        if del_connections:
            ibs_query += user_main.getConnectionLogManager(
            ).deleteConnectionLogsForUsersQuery(user_ids)

        if del_audit_logs:
            ibs_query += user_main.getUserAuditLogManager(
            ).deleteAuditLogsForUsersQuery(user_ids)

        ibs_query += self.__delUserFromUsersTableQuery(user_id_conds)
示例#10
0
    def changeQuery(self,ibs_query,src,action,**args):
        admin_obj=args["admin_obj"]
        users=args["users"]
        
        self.__changeCheckInput(users)
        
        i = 0

        for user_id in users:
            loaded_user=users[user_id]

            if loaded_user.hasAttr("caller_id"):
                ibs_query += self.__deleteUserCallerIDsQuery(user_id)
                old_caller_id = ",".join(loaded_user.getUserAttrs()["caller_id"])

            else:
                old_caller_id = self.AUDIT_LOG_NOVALUE

            if i == len(users)-1: #last user?
                updated_caller_ids = self.caller_ids[i:]
            else:
                updated_caller_ids = (self.caller_ids[i],)

            ibs_query += self.__insertCallerIDsQuery(user_id, updated_caller_ids)

            if defs.USER_AUDIT_LOG:
                ibs_query += user_main.getUserAuditLogManager().userAuditLogQuery(args["admin_obj"].getAdminID(),
                                                                              True,
                                                                              loaded_user.getUserID(),
                                                                              "caller_id",
                                                                              old_caller_id,
                                                                              ",".join(updated_caller_ids))

            i+=1

        return ibs_query
示例#11
0
    def changeQuery(self,ibs_query,src,action,**args):
        admin_obj=args["admin_obj"]
        users=args["users"]
        
        self.__changeCheckInput(users,admin_obj)
        
        i=0
        for user_id in users:
            loaded_user=users[user_id]
            ras_id=ras_main.getLoader().getRasByIP(self.ras_ip[i]).getRasID()

            if loaded_user.hasAttr("persistent_lan_mac"):
                ibs_query+=self.__updatePlanUserAttrsQuery(user_id,
                                                           self.mac[i],
                                                           self.ip[i],
                                                           ras_id
                                                           )
                self.updated_users.append(( (ras_id,user_id,self.mac[i],self.ip[i]),

                                           (user_id,
                                            loaded_user.getUserAttrs()["persistent_lan_mac"],
                                            loaded_user.getUserAttrs()["persistent_lan_ip"],
                                            loaded_user.getUserAttrs()["persistent_lan_ras_id"]
                                            ) ))
                
                old_mac = loaded_user.getUserAttrs()["persistent_lan_mac"]
                old_ip = loaded_user.getUserAttrs()["persistent_lan_ip"]
                old_ras_id = int(loaded_user.getUserAttrs()["persistent_lan_ras_id"])

            else:
                ibs_query+=self.__insertPlanUserAttrsQuery(user_id,
                                                           self.mac[i],
                                                           self.ip[i],
                                                           ras_id
                                                           )
                self.inserted_users.append((ras_id,user_id,self.mac[i],self.ip[i]))
                
                old_mac = self.AUDIT_LOG_NOVALUE
                old_ip = self.AUDIT_LOG_NOVALUE
                old_ras_id = self.AUDIT_LOG_NOVALUE

            if defs.USER_AUDIT_LOG:
                ibs_query += user_main.getUserAuditLogManager().userAuditLogQuery(args["admin_obj"].getAdminID(),
                                                                              True,
                                                                              loaded_user.getUserID(),
                                                                              "persistent_lan_mac",
                                                                              old_mac,
                                                                              self.mac[i])

                ibs_query += user_main.getUserAuditLogManager().userAuditLogQuery(args["admin_obj"].getAdminID(),
                                                                              True,
                                                                              loaded_user.getUserID(),
                                                                              "persistent_lan_ip",
                                                                              old_ip,
                                                                              self.ip[i])

                if old_ras_id == self.AUDIT_LOG_NOVALUE:
                    ras_ip = old_ras_id
                else:
                    ras_ip = ras_main.getLoader().getRasByID(old_ras_id).getRasIP()
                ibs_query += user_main.getUserAuditLogManager().userAuditLogQuery(args["admin_obj"].getAdminID(),
                                                                              True,
                                                                              loaded_user.getUserID(),
                                                                              "persistent_lan_ip",
                                                                              ras_ip,
                                                                              self.ras_ip[i])



            i+=1

        return ibs_query
示例#12
0
class AttrUpdater:
    AUDIT_LOG_NOVALUE = user_main.getUserAuditLogManager().AUDIT_LOG_NOVALUE

    def __init__(self, name):
        """
            name(str): attribute handler name, this should be unique between attribute handlers, and should be same
            as the name relevant attribute handler return
        """
        self.name = name
        self.query_funcs = {}
        self.query_attrs = {}

        self.__generate_query_audit_log = defs.USER_AUDIT_LOG

    def changeInit(self, *args):
        """
            should be overide by child classes
            called with attributes as arguments changeInit(self,attr1,attr2,...).. when we want to change
            arguments
        """
        pass

    def deleteInit(self):
        """
            should be overide by child classes
            called when we want to delete attributes
        """
        pass

    def getName(self):
        return self.name

    def checkInput(self, src, action, arg_dic):
        """
            this method must check attr updater properties, and check their validity
            "action" is one of "change","delete" that show what action is getting done
            arg_dic are extra arguments, that maybe necessary for checkings.
            arg_dic contents differs on diffrent actions
            IMPORTANT WARNING: early checkings should be done in class initializer
                               this method will be called after we load users and initialize all plugins
        """
        pass

    def postUpdate(self, src, action):
        """
            this method is called AFTER update/delete is commited to database successfully and broadcast change
            is called
        """
        pass

    def getQuery(self, ibs_query, src, action, **args):
        """
            return query for insert/update/delete our attributes
            preferrably this method should return an IBSQuery instance
            this is important when query can be large
            this method maybe overidded to customize the behaviour
    
            src(string): "group" or "user"
            action(string):"change" or "delete"
            args(dic): extra arguments, for group src, group_obj and for user src "users" objs are passed with requester admin_obj s
            users list and admin_obj would be there always
        """
        self.checkInput(src, action, args)
        if self.query_funcs.has_key(src + "_" + action):
            return self.__callQueryFunc(ibs_query, src, action, args)
        else:
            return ""

    def __callQueryFunc(self, ibs_query, src, action, args):
        args["attr_updater_attrs"] = self.query_attrs[src + "_" + action]
        return apply(self.query_funcs[src + "_" + action],
                     [ibs_query, src, action], args)

    def registerQuery(self, src, action, query_function, attrs):
        """
            register query_function for action

            query_function must accept **args and use this dictionary for it's arguments
            string query_function(IBSQuery ibs_query,string src,string action,dic **args)

            attrs(dic or list): update actions: this dictionary is passed to query_function as "attr_updater_attrs" in dict arguments (**args)
                                delete actions: the list is a list of attrs that should be deleted
                
        """
        self.query_funcs[src + "_" + action] = query_function
        self.query_attrs[src + "_" + action] = attrs

    ######################################################
    def useGenerateQuery(self, attrs, audit_log=True):
        """
            set all query_functions to self.generateQuery
            audit_log(bool): log this to user_audit_log ?
        """

        self.__generate_query_audit_log = audit_log & defs.USER_AUDIT_LOG

        self.registerQuery("user", "change", self.generateQuery, attrs)
        self.registerQuery("user", "delete", self.generateQuery, attrs)
        self.registerQuery("group", "change", self.generateQuery, attrs)
        self.registerQuery("group", "delete", self.generateQuery, attrs)

    def genQueryAuditLogPrepareOldValue(self, attr_name, old_value):
        """
            should parse and return the old value of attr_name
            the upper method, take care of _DELETED_ values
        """
        return old_value

    def genQueryAuditLogPrepareNewValue(self, attr_name, new_value):
        """
            should parse and return the old value of attr_name
            the upper method, take care of _DELETED_ values
        """
        return new_value

    def genQueryAuditLogPrepareValues(self, attr_name, old_value, new_value):
        """
            parse and prepare the old n new values, for logging into audit_log
            only called when audit_log flag is true when using useGenerateQuery
            attr_updaters can overide this, to provide human readable values
            NOTE: both old_value and new_value may be self.AUDIT_LOG_NOVALUE, in such case, it should be
                  returned unchanged
        """
        if old_value != self.AUDIT_LOG_NOVALUE:
            old_value = self.genQueryAuditLogPrepareOldValue(
                attr_name, old_value)

        if new_value != self.AUDIT_LOG_NOVALUE:
            new_value = self.genQueryAuditLogPrepareOldValue(
                attr_name, new_value)

        return old_value, new_value

    def genQueryAuditLogQuery(self, ibs_query, attr_name, old_value, new_value,
                              is_user, obj, admin_obj):
        """
            add query to ibs_query, that insert rows of changing attr_name of objs to audit_log
            attr_updaters can overide this, to add query themselves
            obj is list of loaded_users or a single group_obj
        """
        old_value, new_value = self.genQueryAuditLogPrepareValues(
            attr_name, old_value, new_value)

        if is_user:
            obj_id = obj.getUserID()
        else:
            obj_id = obj.getGroupID()

        ibs_query += user_main.getUserAuditLogManager().userAuditLogQuery(
            admin_obj.getAdminID(), is_user, obj_id, attr_name, old_value,
            new_value)

    def generateQuery(self, ibs_query, src, action, **args):
        """
            this method is a generic query generator for common attribute handlings
            this can be registered via registerQuery or useGenerateQuery, and do the delete/update/insert automatically
            or call by another proxy function
        """
        if action == "delete":
            if src == "user":
                return self._deleteUserAttr(ibs_query,
                                            args["attr_updater_attrs"],
                                            args["users"], args["admin_obj"])
            elif src == "group":
                return self._deleteGroupAttr(ibs_query,
                                             args["attr_updater_attrs"],
                                             args["group_obj"],
                                             args["admin_obj"])
        elif action == "change":
            if src == "user":
                return self._changeUserAttr(ibs_query,
                                            args["attr_updater_attrs"],
                                            args["users"], args["admin_obj"])
            elif src == "group":
                return self._changeGroupAttr(ibs_query,
                                             args["attr_updater_attrs"],
                                             args["group_obj"],
                                             args["admin_obj"])

    def _changeGroupAttr(self, ibs_query, attrs, group_obj, admin_obj):
        for attr_name in attrs:
            if group_obj.hasAttr(attr_name):
                ibs_query += group_main.getActionManager(
                ).updateGroupAttrQuery(group_obj.getGroupID(), attr_name,
                                       attrs[attr_name])
                old_value = group_obj.getAttr(attr_name)
            else:
                ibs_query += group_main.getActionManager(
                ).insertGroupAttrQuery(group_obj.getGroupID(), attr_name,
                                       attrs[attr_name])
                old_value = self.AUDIT_LOG_NOVALUE

            if self.__generate_query_audit_log:
                self.genQueryAuditLogQuery(ibs_query, attr_name, old_value,
                                           attrs[attr_name], False, group_obj,
                                           admin_obj)

        return ibs_query

    def _deleteGroupAttr(self, ibs_query, attrs, group_obj, admin_obj):
        for attr_name in attrs:
            if group_obj.hasAttr(attr_name):
                ibs_query += group_main.getActionManager(
                ).deleteGroupAttrQuery(group_obj.getGroupID(), attr_name)

                if self.__generate_query_audit_log:
                    old_value = group_obj.getAttr(attr_name)
                    self.genQueryAuditLogQuery(ibs_query, attr_name, old_value,
                                               self.AUDIT_LOG_NOVALUE, False,
                                               group_obj, admin_obj)

        return ibs_query

    def _changeUserAttr(self, ibs_query, attrs, users, admin_obj):
        for user_id in users:
            user = users[user_id]
            for attr_name in attrs:
                if user.userHasAttr(attr_name):
                    ibs_query += user_main.getActionManager(
                    ).updateUserAttrQuery(user.getUserID(), attr_name,
                                          attrs[attr_name])

                else:
                    ibs_query += user_main.getActionManager(
                    ).insertUserAttrQuery(user.getUserID(), attr_name,
                                          attrs[attr_name])

                if self.__generate_query_audit_log:
                    if user.hasAttr(attr_name):
                        old_value = user.getUserAttrs()[attr_name]
                    else:
                        old_value = self.AUDIT_LOG_NOVALUE

                    self.genQueryAuditLogQuery(ibs_query, attr_name, old_value,
                                               attrs[attr_name], True, user,
                                               admin_obj)

        return ibs_query

    def _deleteUserAttr(self, ibs_query, attrs, users, admin_obj):
        for user_id in users:
            user = users[user_id]
            for attr_name in attrs:
                if user.userHasAttr(attr_name):
                    ibs_query += user_main.getActionManager(
                    ).deleteUserAttrQuery(user.getUserID(), attr_name)
                    old_value = user.getUserAttrs()[attr_name]

                    if self.__generate_query_audit_log:
                        self.genQueryAuditLogQuery(ibs_query, attr_name,
                                                   old_value,
                                                   self.AUDIT_LOG_NOVALUE,
                                                   True, user, admin_obj)

        return ibs_query