Ejemplo n.º 1
0
    def fetchChildList(self):
        """
        (Re)aquire the list of childs for this item (if any).
        """
        lumaConnection = LumaConnectionWrapper(self.serverParent.serverMeta)

        bindSuccess, exceptionObject = lumaConnection.bindSync()

        if not bindSuccess:
            tmp = LDAPErrorItem(str("[" + exceptionObject[0]["desc"] + "]"),
                                self.serverParent, self)
            # We're adding the error as LDAPErrorItem-child, so return True
            return (True, [tmp], exceptionObject)

        # Search for items at the level under this one
        success, resultList, exceptionObject = lumaConnection.searchSync(self.itemData.getDN(), \
                scope=ldap.SCOPE_ONELEVEL, filter=self.filter.encode('utf8'), sizelimit=self.limit)
        lumaConnection.unbind()

        if not success:
            tmp = LDAPErrorItem(str("[" + exceptionObject[0]["desc"] + "]"),
                                self.serverParent, self)
            # We're adding the error as LDAPErrorItem-child, so return True
            return (True, [tmp], exceptionObject)

        self.error = False

        # Default behavior: return all
        return (True,
                [LDAPTreeItem(x, self.serverParent, self)
                 for x in resultList], exceptionObject)
Ejemplo n.º 2
0
    def reloadModel(self):
        """
        Refreshes the LDAP data from server,
        """
        lumaConnection = LumaConnectionWrapper(
            self.smartObject.getServerMeta())
        bindSuccess, exceptionObject = lumaConnection.bindSync()

        if not bindSuccess:
            message = self.str_BIND
            return (False, message, exceptionObject)

        success, resultList, exceptionObject = lumaConnection.searchSync(
            self.smartObject.getDN(), ldap.SCOPE_BASE)
        lumaConnection.unbind()

        if success and (len(resultList) > 0):
            self.smartObject = resultList[0]
            self.smartObject.checkIntegrity()
            self.VALID = self.smartObject.isValid
            self.EDITED = False
            self.modelChangedSignal.emit(True)
            return (True, None, None)
        else:
            message = self.str_REFRESH
            return (False, message, exceptionObject)
Ejemplo n.º 3
0
    def fetchChildList(self):
        """
        (Re)aquire the list of childs for this item (if any).
        """       
        lumaConnection = LumaConnectionWrapper(self.serverParent.serverMeta)

        bindSuccess, exceptionObject = lumaConnection.bindSync()
        
        if not bindSuccess:
            tmp = LDAPErrorItem(str("["+exceptionObject[0]["desc"]+"]"), self.serverParent, self)
            # We're adding the error as LDAPErrorItem-child, so return True
            return (True, [tmp], exceptionObject)
        
        # Search for items at the level under this one
        success, resultList, exceptionObject = lumaConnection.searchSync(self.itemData.getDN(), \
                scope=ldap.SCOPE_ONELEVEL, filter=self.filter.encode('utf8'), sizelimit=self.limit)
        lumaConnection.unbind()
        
        if not success:
            tmp = LDAPErrorItem(str("["+exceptionObject[0]["desc"]+"]"), self.serverParent, self)
            # We're adding the error as LDAPErrorItem-child, so return True
            return (True, [tmp], exceptionObject)
        
        self.error = False
        
        # Default behavior: return all
        return (True, [LDAPTreeItem(x, self.serverParent, self) for x in resultList], exceptionObject)
Ejemplo n.º 4
0
    def fetchChildList(self):
        """
        Gets the list of baseDNs for the server and return them.
        """
                
        connection = LumaConnectionWrapper(self.serverMeta)
        
        # If baseDNs are aleady spesified
        if self.serverMeta.autoBase == False:
            self.logger.debug("autoBase=False")
            tmpList = self.serverMeta.baseDN
            
            #Need to bind in order to fetch the data for the baseDNs
            bindSuccess, exceptionObject = connection.bindSync()
            if not bindSuccess:
                self.logger.debug("Bind failed.")
                tmp = LDAPErrorItem(str("["+exceptionObject[0]["desc"]+"]"), self, self)
                # We're adding the error as LDAPErrorItem-child, so return True
                return (True, [tmp], exceptionObject)
            
        # Else get them from the server
        else:
            self.logger.debug("Using getBaseDNList()")
            #self.isWorking.emit()
            success, tmpList, exceptionObject = connection.getBaseDNListSync()
        
            if not success:
                self.logger.debug("getBaseDNList failed:"+str(exceptionObject))
                tmp = LDAPErrorItem(str("["+exceptionObject[0]["desc"]+"]"), self, self)
                return (True, [tmp], exceptionObject) #See above
            
            #getBaseDNList calles unbind(), so let's rebind
            connection.bindSync()
        
        self.logger.debug("Entering for-loop")

        # Get the info for the baseDNs
        newChildList = []
        for base in tmpList:
            success, resultList, exceptionObject = connection.searchSync(base, \
                    scope=ldap.SCOPE_BASE,filter='(objectclass=*)', sizelimit=1)
            if not success:
                self.logger.debug("Couldn't search item:"+str(exceptionObject))
                tmp = LDAPErrorItem(str(base+" ["+exceptionObject[0]["desc"]+"]"), self, self)
                newChildList.append(tmp)
                continue
            
            if resultList:
                self.logger.debug("Found item")
                tmp = LDAPTreeItem(resultList[0], self, self)    
                newChildList.append(tmp)
            
        self.logger.debug("End populatItem")
        
        return (True, newChildList, exceptionObject)
Ejemplo n.º 5
0
    def initModel(self, create=False):
        if create:
            self.EDITED = True
            self.ISLEAF = False
            self.CREATE = True
            self.VALID = True
        else:
            self.EDITED = False
            isLeave = False
            self.smartObject.checkIntegrity()
            self.VALID = self.smartObject.isValid

            serverMeta = self.smartObject.getServerMeta()

            lumaConnection = LumaConnectionWrapper(serverMeta, self)

            bindSuccess, exceptionObject = lumaConnection.bindSync()

            if not bindSuccess:
                message = self.str_BIND
                return (False, message, exceptionObject)

            success, resultList, exceptionObject = lumaConnection.searchSync(
                self.smartObject.dn,
                ldap.SCOPE_ONELEVEL,
                filter="(objectClass=*)",
                attrList=None,
                attrsonly=1,
                sizelimit=1)
            lumaConnection.unbind()

            # Our search succeeded. No errors
            if success:

                # There are no leaves below
                if len(resultList) == 0:
                    self.ISLEAF = True

                # Leaves are below
                else:
                    self.ISLEAF = False

            # Error during search request
            else:
                self.ISLEAF = False
                message = self.str_CHECK_LEAF
                self.modelChangedSignal.emit(True)
                return (False, message, exceptionObject)

            self.CREATE = False

        self.modelChangedSignal.emit(True)
        return (True, None, None)
Ejemplo n.º 6
0
    def initModel(self, create=False):
        if create:
            self.EDITED = True
            self.ISLEAF = False
            self.CREATE = True
            self.VALID = True
        else:
            self.EDITED = False
            isLeave = False
            self.smartObject.checkIntegrity()
            self.VALID = self.smartObject.isValid

            serverMeta = self.smartObject.getServerMeta()

            lumaConnection = LumaConnectionWrapper(serverMeta, self)

            bindSuccess, exceptionObject = lumaConnection.bindSync()

            if not bindSuccess:
                message = self.str_BIND
                return (False, message, exceptionObject)

            success, resultList, exceptionObject = lumaConnection.searchSync(self.smartObject.dn, ldap.SCOPE_ONELEVEL, filter="(objectClass=*)", attrList=None, attrsonly=1, sizelimit=1)
            lumaConnection.unbind()

            # Our search succeeded. No errors
            if success:

                # There are no leaves below
                if len(resultList) == 0:
                    self.ISLEAF = True

                # Leaves are below
                else:
                    self.ISLEAF = False

            # Error during search request
            else:
                self.ISLEAF = False
                message = self.str_CHECK_LEAF
                self.modelChangedSignal.emit(True)
                return (False, message, exceptionObject)

            self.CREATE = False

        self.modelChangedSignal.emit(True)
        return (True, None, None)
Ejemplo n.º 7
0
    def reloadModel(self):
        """
        Refreshes the LDAP data from server,
        """
        lumaConnection = LumaConnectionWrapper(self.smartObject.getServerMeta())
        bindSuccess, exceptionObject = lumaConnection.bindSync()

        if not bindSuccess:
            message = self.str_BIND
            return (False, message, exceptionObject)

        success, resultList, exceptionObject = lumaConnection.searchSync(self.smartObject.getDN(), ldap.SCOPE_BASE)
        lumaConnection.unbind()

        if success and (len(resultList) > 0):
            self.smartObject = resultList[0]
            self.smartObject.checkIntegrity()
            self.VALID = self.smartObject.isValid
            self.EDITED = False
            self.modelChangedSignal.emit(True)
            return (True, None, None)
        else:
            message = self.str_REFRESH
            return (False, message, exceptionObject)
Ejemplo n.º 8
0
    def fetchChildList(self):
        """
        Gets the list of baseDNs for the server and return them.
        """

        connection = LumaConnectionWrapper(self.serverMeta)

        # If baseDNs are aleady spesified
        if self.serverMeta.autoBase == False:
            self.logger.debug("autoBase=False")
            tmpList = self.serverMeta.baseDN

            #Need to bind in order to fetch the data for the baseDNs
            bindSuccess, exceptionObject = connection.bindSync()
            if not bindSuccess:
                self.logger.debug("Bind failed.")
                tmp = LDAPErrorItem(
                    str("[" + exceptionObject[0]["desc"] + "]"), self, self)
                # We're adding the error as LDAPErrorItem-child, so return True
                return (True, [tmp], exceptionObject)

        # Else get them from the server
        else:
            self.logger.debug("Using getBaseDNList()")
            #self.isWorking.emit()
            success, tmpList, exceptionObject = connection.getBaseDNListSync()

            if not success:
                self.logger.debug("getBaseDNList failed:" +
                                  str(exceptionObject))
                tmp = LDAPErrorItem(
                    str("[" + exceptionObject[0]["desc"] + "]"), self, self)
                return (True, [tmp], exceptionObject)  #See above

            #getBaseDNList calles unbind(), so let's rebind
            connection.bindSync()

        self.logger.debug("Entering for-loop")

        # Get the info for the baseDNs
        newChildList = []
        for base in tmpList:
            success, resultList, exceptionObject = connection.searchSync(base, \
                    scope=ldap.SCOPE_BASE,filter='(objectclass=*)', sizelimit=1)
            if not success:
                self.logger.debug("Couldn't search item:" +
                                  str(exceptionObject))
                tmp = LDAPErrorItem(
                    str(base + " [" + exceptionObject[0]["desc"] + "]"), self,
                    self)
                newChildList.append(tmp)
                continue

            if resultList:
                self.logger.debug("Found item")
                tmp = LDAPTreeItem(resultList[0], self, self)
                newChildList.append(tmp)

        self.logger.debug("End populatItem")

        return (True, newChildList, exceptionObject)
Ejemplo n.º 9
0
    def __exportSelection(self, scope=0):
        """Slot for the context menu.

        Opens the ExportDialog with the selected entries, giving the
        user the option to validate the selection before exporting.

        :param scope: The scope selection.
         0 = SCOPE_BASE -> Item(s),
         1 = SCOPE_ONELEVEL -> Subtree(s);
         2 = SCOPE_SUBTREE -> Subtree(s) with parent
        :type scope: int
        """
        exportObjects = []
        msg = ''

        self.setBusy(True)
        for index in self.selection:
            smartObject = index.internalPointer().smartObject()

            serverName = smartObject.getServerAlias()
            dn = smartObject.getDN()
            serverObject = self.serverList.getServerObject(serverName)
            con = LumaConnectionWrapper(serverObject, self)

            # For both subtree and subtree with parent, we fetch the
            # whole subtree including the parent, with a basic sync
            # search operation. Then, if only the subtree is to be
            # exported, we remove the smartObject(s) selected.
            if scope > 0:
                pass

            # Do a search on the whole subtree
            # 2 = ldap.SCOPE_SUBTREE
            #elif scope == 2:

                success, e = con.bindSync()

                if not success:
                    self.__logger.error(str(e))
                    continue
                success, result, e = con.searchSync(base=dn, scope=2)

                if success:
                    exportObjects.extend(result)
                else:
                    self.__logger.error(str(e))

                # If only the subtree is to be selected, we remove
                # the parent, which happens to be the smartObject(s)
                # initialy selected.
                if scope == 1:
                    exportObjects.remove(smartObject)

            # For scope == 0 we need not do any LDAP search operation
            # because we already got what we need
            else:
                exportObjects.append(smartObject)

        # Initialize the export dialog
        # and give it the items for export
        dialog = ExportDialog(msg)
        dialog.setExportItems(exportObjects)
        self.setBusy(False)
        dialog.exec_()
Ejemplo n.º 10
0
    def __exportSelection(self, scope=0):
        """Slot for the context menu.

        Opens the ExportDialog with the selected entries, giving the
        user the option to validate the selection before exporting.

        :param scope: The scope selection.
         0 = SCOPE_BASE -> Item(s),
         1 = SCOPE_ONELEVEL -> Subtree(s);
         2 = SCOPE_SUBTREE -> Subtree(s) with parent
        :type scope: int
        """
        exportObjects = []
        msg = ''

        self.setBusy(True)
        for index in self.selection:
            smartObject = index.internalPointer().smartObject()

            serverName = smartObject.getServerAlias()
            dn = smartObject.getDN()
            serverObject = self.serverList.getServerObject(serverName)
            con = LumaConnectionWrapper(serverObject, self)

            # For both subtree and subtree with parent, we fetch the
            # whole subtree including the parent, with a basic sync
            # search operation. Then, if only the subtree is to be
            # exported, we remove the smartObject(s) selected.
            if scope > 0:
                pass

                # Do a search on the whole subtree
                # 2 = ldap.SCOPE_SUBTREE
                #elif scope == 2:

                success, e = con.bindSync()

                if not success:
                    self.__logger.error(str(e))
                    continue
                success, result, e = con.searchSync(base=dn, scope=2)

                if success:
                    exportObjects.extend(result)
                else:
                    self.__logger.error(str(e))

                # If only the subtree is to be selected, we remove
                # the parent, which happens to be the smartObject(s)
                # initialy selected.
                if scope == 1:
                    exportObjects.remove(smartObject)

            # For scope == 0 we need not do any LDAP search operation
            # because we already got what we need
            else:
                exportObjects.append(smartObject)

        # Initialize the export dialog
        # and give it the items for export
        dialog = ExportDialog(msg)
        dialog.setExportItems(exportObjects)
        self.setBusy(False)
        dialog.exec_()