Changeset 1029
- Timestamp:
- 06/15/03 00:44:21 (21 years ago)
- Location:
- pykota/trunk
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/conf/pykota.conf.sample
r1027 r1029 55 55 # Here we define some helpers to know where 56 56 # to plug into an existing LDAP directory 57 #user sou: ou=People,dc=librelogiciel,dc=com57 #userbase: ou=People,dc=librelogiciel,dc=com 58 58 #userrdn: uid 59 #group sou: ou=Groups,dc=librelogiciel,dc=com59 #groupbase: ou=Groups,dc=librelogiciel,dc=com 60 60 #grouprdn: cn 61 #printer sou: ou=Printers,dc=librelogiciel,dc=com61 #printerbase: ou=Printers,ou=PyKota,dc=librelogiciel,dc=com 62 62 #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 67 71 68 72 # Where to log ? -
pykota/trunk/NEWS
r1028 r1029 22 22 PyKota NEWS : 23 23 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 24 30 - 1.08 : 25 31 26 32 - Major bug fix wrt LPRng support for remote jobs. 33 27 34 - Major bug fix wrt increase/decrease account balances. 28 35 … … 30 37 31 38 - Code refactoring. 39 32 40 - A single user/password pair is used to connect 33 41 to the database backend. The storageuser configuration 34 42 field, and its associated passwords storageuserpw, are 35 43 not used anymore. 44 36 45 - You can now set PyKota in debug mode, see sample configuration 37 46 file for details. … … 42 51 43 52 - Very latest LDAP schema. 53 44 54 - Code enhancement wrt easy pluggability of PyKota attributes 45 55 and object classes into an existing LDAP directory. … … 48 58 49 59 - Minor bug corrections 60 50 61 - More work on LDAP : new schema 51 62 -
pykota/trunk/pykota/config.py
r1021 r1029 21 21 # 22 22 # $Log$ 23 # Revision 1.29 2003/06/14 22:44:21 jalet 24 # More work on LDAP storage backend. 25 # 23 26 # Revision 1.28 2003/06/10 16:37:54 jalet 24 27 # Deletion of the second user which is not needed anymore. … … 194 197 return backendinfo 195 198 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 196 211 def getLoggingBackend(self) : 197 212 """Returns the logging backend information.""" -
pykota/trunk/pykota/storages/ldapstorage.py
r1027 r1029 21 21 # 22 22 # $Log$ 23 # Revision 1.7 2003/06/14 22:44:21 jalet 24 # More work on LDAP storage backend. 25 # 23 26 # Revision 1.6 2003/06/13 19:07:57 jalet 24 27 # Two big bugs fixed, time to release something ;-) … … 67 70 """Opens the LDAP connection.""" 68 71 # raise PyKotaStorageError, "Sorry, the LDAP backend for PyKota is not yet implemented !" 72 self.closed = 1 69 73 self.tool = pykotatool 70 74 self.debug = pykotatool.config.getDebug() 71 self. closed = 175 self.info = pykotatool.config.getLDAPInfo() 72 76 try : 73 77 self.database = ldap.initialize(host) … … 103 107 def getMatchingPrinters(self, printerpattern) : 104 108 """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"]) 106 110 if result : 107 111 return [(printerid, printer["pykotaPrinterName"][0]) for (printerid, printer) in result if fnmatch.fnmatchcase(printer["pykotaPrinterName"][0], printerpattern)] … … 109 113 def getPrinterId(self, printername) : 110 114 """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"]) 112 116 if result : 113 117 return result[0][0] … … 115 119 def getPrinterPrices(self, printerid) : 116 120 """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) 118 122 if result : 119 123 return (float(result[0][1]["pykotaPricePerPage"][0]), float(result[0][1]["pykotaPricePerJob"][0])) … … 125 129 def getUserId(self, username) : 126 130 """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"]) 128 132 if result : 129 133 return result[0][0] … … 131 135 def getGroupId(self, groupname) : 132 136 """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"]) 134 138 if result is not None : 135 139 (groupid, dummy) = result[0] … … 146 150 """Returns the list of userids and usernames which uses a given printer.""" 147 151 # 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"]) 153 157 if result : 154 158 return [(pquotauserid, fields["pykotaUserName"][0]) for (pquotauserid, fields) in result] … … 157 161 """Returns the list of groups which uses a given printer.""" 158 162 # 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"]) 164 168 if result : 165 169 return [(pquotagroupid, fields["pykotaGroupName"][0]) for (pquotagroupid, fields) in result] … … 167 171 def getGroupMembersNames(self, groupname) : 168 172 """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"]) 173 177 174 178 def getUserGroupsNames(self, userid) : … … 206 210 if result : 207 211 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"]) 209 213 if result : 210 214 fields = result[0][1] … … 214 218 """Returns the current account balance for a given user id.""" 215 219 # 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"]) 221 225 if result : 222 226 fields = result[0][1] … … 241 245 return (balance, lifetimepaid) 242 246 243 def getUserLimitBy(self, user id) :247 def getUserLimitBy(self, userquotaid) : 244 248 """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] 248 255 249 256 def getGroupLimitBy(self, groupquotaid) : … … 253 260 if result : 254 261 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"]) 256 263 if result : 257 264 return result[0][1]["pykotaLimitBy"][0] … … 350 357 def getPrinterPageCounter(self, printerid) : 351 358 """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"]) 357 364 if result : 358 365 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"]) 360 367 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 } 362 375 363 376 def addUserToGroup(self, userid, groupid) : -
pykota/trunk/pykota/version.py
r1027 r1029 21 21 # 22 22 23 __version__ = "1.0 8_unofficial"23 __version__ = "1.09alpha1_unofficial" 24 24 25 25 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""