Changeset 1029

Show
Ignore:
Timestamp:
06/15/03 00:44:21 (21 years ago)
Author:
jalet
Message:

More work on LDAP storage backend.

Location:
pykota/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/conf/pykota.conf.sample

    r1027 r1029  
    5555# Here we define some helpers to know where  
    5656# to plug into an existing LDAP directory 
    57 #usersou: ou=People,dc=librelogiciel,dc=com 
     57#userbase: ou=People,dc=librelogiciel,dc=com 
    5858#userrdn: uid 
    59 #groupsou: ou=Groups,dc=librelogiciel,dc=com 
     59#groupbase: ou=Groups,dc=librelogiciel,dc=com 
    6060#grouprdn: cn 
    61 #printersou: ou=Printers,dc=librelogiciel,dc=com 
     61#printerbase: ou=Printers,ou=PyKota,dc=librelogiciel,dc=com 
    6262#printerrdn: cn 
    63 #jobsou: ou=Jobs,ou=PyKota,dc=librelogiciel,dc=com 
    64 #userquotasou: ou=UQuotas,ou=PyKota,dc=librelogiciel,dc=com 
    65 #groupquotasou: ou=GQuotas,ou=PyKota,dc=librelogiciel,dc=com 
    66 #lastjobsou: ou=LastJobs,ou=PyKota,dc=librelogiciel,dc=com 
     63#jobbase: ou=Jobs,ou=PyKota,dc=librelogiciel,dc=com 
     64#userquotabase: ou=UQuotas,ou=PyKota,dc=librelogiciel,dc=com 
     65#groupquotabase: ou=GQuotas,ou=PyKota,dc=librelogiciel,dc=com 
     66#lastjobbase: ou=LastJobs,ou=PyKota,dc=librelogiciel,dc=com 
     67#  
     68# Choose what attribute contains the list of group members 
     69# common values are : memberUid, uniqueMember, member 
     70#groupmembers: memberUid 
    6771 
    6872# Where to log ? 
  • pykota/trunk/NEWS

    r1028 r1029  
    2222PyKota NEWS : 
    2323 
     24    - 1.09alpha1 : 
     25     
     26        - More work on LDAP storage backend. Many options 
     27          were added to /etc/pykota.conf to give some 
     28          hints to the LDAP storage backend. 
     29       
    2430    - 1.08 : 
    2531     
    2632        - Major bug fix wrt LPRng support for remote jobs. 
     33         
    2734        - Major bug fix wrt increase/decrease account balances. 
    2835         
     
    3037     
    3138        - Code refactoring. 
     39         
    3240        - A single user/password pair is used to connect 
    3341          to the database backend. The storageuser configuration 
    3442          field, and its associated passwords storageuserpw, are  
    3543          not used anymore. 
     44           
    3645        - You can now set PyKota in debug mode, see sample configuration   
    3746          file for details.  
     
    4251     
    4352        - Very latest LDAP schema. 
     53         
    4454        - Code enhancement wrt easy pluggability of PyKota attributes 
    4555          and object classes into an existing LDAP directory. 
     
    4858     
    4959        - Minor bug corrections 
     60         
    5061        - More work on LDAP : new schema 
    5162         
  • pykota/trunk/pykota/config.py

    r1021 r1029  
    2121# 
    2222# $Log$ 
     23# Revision 1.29  2003/06/14 22:44:21  jalet 
     24# More work on LDAP storage backend. 
     25# 
    2326# Revision 1.28  2003/06/10 16:37:54  jalet 
    2427# Deletion of the second user which is not needed anymore. 
     
    194197        return backendinfo 
    195198         
     199    def getLDAPInfo(self) :     
     200        """Returns some hints for the LDAP backend."""         
     201        ldapinfo = {} 
     202        for option in [ "userbase", "userrdn", \ 
     203                        "groupbase", "grouprdn", "groupmembers", \ 
     204                        "printerbase", "printerrdn", \ 
     205                        "userquotabase", "groupquotabase", \ 
     206                        "jobbase", "lastjobbase", \ 
     207                      ] : 
     208            ldapinfo[option] = self.getGlobalOption(option) 
     209        return ldapinfo 
     210         
    196211    def getLoggingBackend(self) :     
    197212        """Returns the logging backend information.""" 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1027 r1029  
    2121# 
    2222# $Log$ 
     23# Revision 1.7  2003/06/14 22:44:21  jalet 
     24# More work on LDAP storage backend. 
     25# 
    2326# Revision 1.6  2003/06/13 19:07:57  jalet 
    2427# Two big bugs fixed, time to release something ;-) 
     
    6770        """Opens the LDAP connection.""" 
    6871        # raise PyKotaStorageError, "Sorry, the LDAP backend for PyKota is not yet implemented !" 
     72        self.closed = 1 
    6973        self.tool = pykotatool 
    7074        self.debug = pykotatool.config.getDebug() 
    71         self.closed = 1 
     75        self.info = pykotatool.config.getLDAPInfo() 
    7276        try : 
    7377            self.database = ldap.initialize(host)  
     
    103107    def getMatchingPrinters(self, printerpattern) : 
    104108        """Returns the list of all printers as tuples (id, name) for printer names which match a certain pattern.""" 
    105         result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName"]) 
     109        result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName"], base=self.info["printerbase"]) 
    106110        if result : 
    107111            return [(printerid, printer["pykotaPrinterName"][0]) for (printerid, printer) in result if fnmatch.fnmatchcase(printer["pykotaPrinterName"][0], printerpattern)] 
     
    109113    def getPrinterId(self, printername) :         
    110114        """Returns a printerid given a printername.""" 
    111         result = self.doSearch("(&(objectClass=pykotaPrinter)(|(pykotaPrinterName=%s)(cn=%s)))" % (printername, printername), ["pykotaPrinterName"]) 
     115        result = self.doSearch("(&(objectClass=pykotaPrinter)(|(pykotaPrinterName=%s)(%s=%s)))" % (printername, self.info["printerrdn"], printername), ["pykotaPrinterName"], base=self.info["printerbase"]) 
    112116        if result : 
    113117            return result[0][0] 
     
    115119    def getPrinterPrices(self, printerid) :         
    116120        """Returns a printer prices per page and per job given a printerid.""" 
    117         result = self.doSearch("(|(pykotaPrinterName=*)(cn=*))", ["pykotaPricePerPage", "pykotaPricePerJob"], base=printerid, scope=ldap.SCOPE_BASE) 
     121        result = self.doSearch("(|(pykotaPrinterName=*)(%s=*))" % self.info["printerrdn"], ["pykotaPricePerPage", "pykotaPricePerJob"], base=printerid, scope=ldap.SCOPE_BASE) 
    118122        if result : 
    119123            return (float(result[0][1]["pykotaPricePerPage"][0]), float(result[0][1]["pykotaPricePerJob"][0])) 
     
    125129    def getUserId(self, username) : 
    126130        """Returns a userid given a username.""" 
    127         result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(uid=%s)))" % (username, username), ["uid"]) 
     131        result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), [self.info["userrdn"]], base=self.info["userbase"]) 
    128132        if result : 
    129133            return result[0][0] 
     
    131135    def getGroupId(self, groupname) : 
    132136        """Returns a groupid given a grupname.""" 
    133         result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(cn=%s)))" % (groupname, groupname), ["cn"]) 
     137        result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % (groupname, self.info["grouprdn"], groupname), [self.info["grouprdn"]], base=self.info["groupbase"]) 
    134138        if result is not None : 
    135139            (groupid, dummy) = result[0] 
     
    146150        """Returns the list of userids and usernames which uses a given printer.""" 
    147151        # first get the printer's name from the id 
    148         result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName", "cn"], base=printerid, scope=ldap.SCOPE_BASE) 
    149         if result : 
    150             fields = result[0][1] 
    151             printername = (fields.get("pykotaPrinterName") or fields.get("cn"))[0] 
    152             result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s))" % printername, ["pykotaUserName"])  
     152        result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName", self.info["printerrdn"]], base=printerid, scope=ldap.SCOPE_BASE) 
     153        if result : 
     154            fields = result[0][1] 
     155            printername = (fields.get("pykotaPrinterName") or fields.get(self.info["printerrdn"]))[0] 
     156            result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s))" % printername, ["pykotaUserName"], base=self.info["userquotabase"])  
    153157            if result : 
    154158                return [(pquotauserid, fields["pykotaUserName"][0]) for (pquotauserid, fields) in result] 
     
    157161        """Returns the list of groups which uses a given printer.""" 
    158162        # first get the printer's name from the id 
    159         result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName", "cn"], base=printerid, scope=ldap.SCOPE_BASE) 
    160         if result : 
    161             fields = result[0][1] 
    162             printername = (fields.get("pykotaPrinterName") or fields.get("cn"))[0] 
    163             result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s))" % printername, ["pykotaGroupName"])  
     163        result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName", self.info["printerrdn"]], base=printerid, scope=ldap.SCOPE_BASE) 
     164        if result : 
     165            fields = result[0][1] 
     166            printername = (fields.get("pykotaPrinterName") or fields.get(self.info["printerrdn"]))[0] 
     167            result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s))" % printername, ["pykotaGroupName"], base=self.info["groupquotabase"])  
    164168            if result : 
    165169                return [(pquotagroupid, fields["pykotaGroupName"][0]) for (pquotagroupid, fields) in result] 
     
    167171    def getGroupMembersNames(self, groupname) :         
    168172        """Returns the list of user's names which are member of this group.""" 
    169         result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(cn=%s)))" % (groupname, groupname), ["memberUid", "uniqueMember", "member"]) 
    170         if result : 
    171             fields = result[0][1] 
    172             return fields.get("memberUid") or fields.get("uniqueMember") or fields.get("member") 
     173        result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % (groupname, self.info["grouprdn"], groupname), [self.info["groupmembers"]]) 
     174        if result : 
     175            fields = result[0][1] 
     176            return fields.get(self.info["groupmembers"]) 
    173177         
    174178    def getUserGroupsNames(self, userid) :         
     
    206210        if result : 
    207211            username = result[0][1]["pykotaUserName"][0] 
    208             result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(uid=%s)))" % (username, username), ["pykotaBalance", "pykotaLifeTimePaid"]) 
     212            result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaBalance", "pykotaLifeTimePaid"]) 
    209213            if result : 
    210214                fields = result[0][1] 
     
    214218        """Returns the current account balance for a given user id.""" 
    215219        # first get the user's name from the user id 
    216         result = self.doSearch("objectClass=pykotaAccount", ["pykotaUserName", "uid"], base=userid, scope=ldap.SCOPE_BASE) 
    217         if result : 
    218             fields = result[0][1] 
    219             username = (fields.get("pykotaUserName") or fields.get("uid"))[0] 
    220             result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(uid=%s)))" % (username, username), ["pykotaBalance", "pykotaLifeTimePaid"]) 
     220        result = self.doSearch("objectClass=pykotaAccount", ["pykotaUserName", self.info["userrdn"]], base=userid, scope=ldap.SCOPE_BASE) 
     221        if result : 
     222            fields = result[0][1] 
     223            username = (fields.get("pykotaUserName") or fields.get(self.info["userrdn"]))[0] 
     224            result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaBalance", "pykotaLifeTimePaid"]) 
    221225            if result : 
    222226                fields = result[0][1] 
     
    241245            return (balance, lifetimepaid)             
    242246         
    243     def getUserLimitBy(self, userid) :     
     247    def getUserLimitBy(self, userquotaid) :     
    244248        """Returns the way in which user printing is limited.""" 
    245         result = self.doSearch("objectClass=pykotaAccount", ["pykotaLimitBy"], base=userid, scope=ldap.SCOPE_BASE) 
    246         if result : 
    247             return result[0][1]["pykotaLimitBy"][0] 
     249        result = self.doSearch("objectClass=pykotaUserPQuota", ["pykotaUserName"], base=userquotaid, scope=ldap.SCOPE_BASE) 
     250        if result : 
     251            username = result[0][1]["pykotaUserName"][0] 
     252            result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaLimitBy"]) 
     253            if result : 
     254                return result[0][1]["pykotaLimitBy"][0] 
    248255         
    249256    def getGroupLimitBy(self, groupquotaid) :     
     
    253260        if result : 
    254261            groupname = result[0][1]["pykotaGroupName"][0] 
    255             result = self.doSearch("(&(objectClass=pykotaGroup)(pykotaGroupName=%s))" % groupname, ["pykotaLimitBy"]) 
     262            result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % (groupname, self.info["grouprdn"], groupname), ["pykotaLimitBy"]) 
    256263            if result : 
    257264                return result[0][1]["pykotaLimitBy"][0] 
     
    350357    def getPrinterPageCounter(self, printerid) : 
    351358        """Returns the last page counter value for a printer given its id, also returns last username, last jobid and history line id.""" 
    352         result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName", "cn"], base=printerid, scope=ldap.SCOPE_BASE) 
    353         if result : 
    354             fields = result[0][1] 
    355             printername = (fields.get("pykotaPrinterName") or fields.get("cn"))[0] 
    356             result = self.doSearch("(&(objectClass=pykotaLastjob)(|(pykotaPrinterName=%s)(cn=%s)))" % (printername, printername), ["pykotaLastJobIdent"]) 
     359        result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName", self.info["printerrdn"]], base=printerid, scope=ldap.SCOPE_BASE) 
     360        if result : 
     361            fields = result[0][1] 
     362            printername = (fields.get("pykotaPrinterName") or fields.get(self.info["printerrdn"]))[0] 
     363            result = self.doSearch("(&(objectClass=pykotaLastjob)(|(pykotaPrinterName=%s)(%s=%s)))" % (printername, self.info["printerrdn"], printername), ["pykotaLastJobIdent"], base=self.info["lastjobbase"]) 
    357364            if result : 
    358365                lastjobident = result[0][1]["pykotaLastJobIdent"][0] 
    359                 result = self.doSearch("(&(objectClass=pykotaJob)(cn=%s))" % lastjobident, ["pykotaUserName", "pykotaPrinterName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaJobSize", "pykotaAction", "createTimestamp"]) 
     366                result = self.doSearch("(&(objectClass=pykotaJob)(cn=%s))" % lastjobident, ["pykotaUserName", "pykotaPrinterName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaJobSize", "pykotaAction", "createTimestamp"], base=self.info["jobbase"]) 
    360367                if result : 
    361                     pass # TODO 
     368                    fields = result[0][1] 
     369                    return { "id": lastjobident,  
     370                             "jobid" : fields.get("pykotaJobId")[0], 
     371                             "userid" : self.getUserId(fields.get("pykotaUserName")[0]), 
     372                             "username" : fields.get("pykotaUserName")[0],  
     373                             "pagecounter" : int(fields.get("pykotaPrinterPageCounter")[0]), 
     374                           } 
    362375         
    363376    def addUserToGroup(self, userid, groupid) :     
  • pykota/trunk/pykota/version.py

    r1027 r1029  
    2121# 
    2222 
    23 __version__ = "1.08_unofficial" 
     23__version__ = "1.09alpha1_unofficial" 
    2424 
    2525__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""