95 | | def doSearch(self, key, fields, base="", scope=ldap.SCOPE_SUBTREE) : |
| 101 | def genUUID(self) : |
| 102 | """Generates an unique identifier. |
| 103 | |
| 104 | TODO : this one is not unique accross several print servers, but should be sufficient for testing. |
| 105 | """ |
| 106 | return md5.md5("%s" % time.time()).hexdigest() |
| 107 | |
| 108 | def doSearch(self, key, fields=None, base="", scope=ldap.SCOPE_SUBTREE) : |
100 | | self.tool.logger.log_message("QUERY : BaseDN : %s, Scope : %s, Filter : %s, Attributes : %s" % ((base or self.basedn), scope, key, fields), "debug") |
| 113 | self.tool.logger.log_message("QUERY : BaseDN : %s, Scope : %s, Filter : %s, Attributes : %s" % (base, scope, key, fields), "debug") |
| 119 | |
| 120 | def doAdd(self, dn, fields) : |
| 121 | """Adds an entry in the LDAP directory.""" |
| 122 | try : |
| 123 | if self.debug : |
| 124 | self.tool.logger.log_message("QUERY : ADD(%s, %s)" % (dn, str(fields)), "debug") |
| 125 | self.database.add_s(dn, modlist.addModlist(fields)) |
| 126 | except ldap.LDAPError : |
| 127 | raise PyKotaStorageError, _("Problem adding LDAP entry (%s, %s)") % (dn, str(fields)) |
| 128 | else : |
| 129 | return dn |
| 130 | |
| 131 | def doModify(self, dn, fields) : |
| 132 | """Modifies an entry in the LDAP directory.""" |
| 133 | try : |
| 134 | oldentry = self.doSearch("objectClass=*", base=dn, scope=ldap.SCOPE_BASE) |
| 135 | if self.debug : |
| 136 | self.tool.logger.log_message("QUERY : Modify(%s, %s ==> %s)" % (dn, oldentry[0][1], fields), "debug") |
| 137 | self.database.modify_s(dn, modlist.modifyModlist(oldentry[0][1], fields, ignore_oldexistent=1)) |
| 138 | except ldap.LDAPError : |
| 139 | raise PyKotaStorageError, _("Problem modifying LDAP entry (%s, %s)") % (dn, fields) |
| 140 | else : |
| 141 | return dn |
184 | | raise PyKotaStorageError, "Not implemented !" |
| 226 | fields = { self.info["printerrdn"] : printername, |
| 227 | "objectClass" : ["pykotaObject", "pykotaPrinter"], |
| 228 | "pykotaPrinterName" : printername, |
| 229 | "pykotaPricePerPage" : "0.0", |
| 230 | "pykotaPricePerJob" : "0.0", |
| 231 | } |
| 232 | dn = "%s=%s,%s" % (self.info["printerrdn"], printername, self.info["printerbase"]) |
| 233 | return self.doAdd(dn, fields) |
188 | | raise PyKotaStorageError, "Not implemented !" |
| 237 | fields = { self.info["userrdn"] : username, |
| 238 | "objectClass" : ["pykotaObject", "pykotaAccount", "pykotaAccountBalance"], |
| 239 | "pykotaUserName" : username, |
| 240 | "pykotaLimitBy" : "quota", |
| 241 | "pykotaBalance" : "0.0", |
| 242 | "pykotaLifeTimePaid" : "0.0", |
| 243 | } |
| 244 | dn = "%s=%s,%s" % (self.info["userrdn"], username, self.info["userbase"]) |
| 245 | return self.doAdd(dn, fields) |
192 | | raise PyKotaStorageError, "Not implemented !" |
| 249 | fields = { self.info["grouprdn"] : groupname, |
| 250 | "objectClass" : ["pykotaObject", "pykotaGroup"], |
| 251 | "pykotaGroupName" : groupname, |
| 252 | "pykotaLimitBy" : "quota", |
| 253 | } |
| 254 | dn = "%s=%s,%s" % (self.info["grouprdn"], groupname, self.info["groupbase"]) |
| 255 | return self.doAdd(dn, fields) |
196 | | raise PyKotaStorageError, "Not implemented !" |
| 259 | uuid = self.genUUID() |
| 260 | fields = { "objectClass" : ["pykotaObject", "pykotaUserPQuota"], |
| 261 | "cn" : uuid, |
| 262 | "pykotaUserName" : username, |
| 263 | "pykotaPrinterName" : self.getPrinterName(printerid), |
| 264 | "pykotaPageCounter" : "0", |
| 265 | "pykotaLifePageCounter" : "0", |
| 266 | "pykotaSoftLimit" : "0", |
| 267 | "pykotaHardLimit" : "0", |
| 268 | "pykotaDateLimit" : "None", |
| 269 | } |
| 270 | dn = "cn=%s,%s" % (uuid, self.info["userquotabase"]) |
| 271 | return self.doAdd(dn, fields) |
200 | | raise PyKotaStorageError, "Not implemented !" |
| 275 | uuid = self.genUUID() |
| 276 | fields = { "objectClass" : ["pykotaObject", "pykotaGroupPQuota"], |
| 277 | "cn" : uuid, |
| 278 | "pykotaGroupName" : groupname, |
| 279 | "pykotaPrinterName" : self.getPrinterName(printerid), |
| 280 | "pykotaSoftLimit" : "0", |
| 281 | "pykotaHardLimit" : "0", |
| 282 | "pykotaDateLimit" : "None", |
| 283 | } |
| 284 | dn = "cn=%s,%s" % (uuid, self.info["groupquotabase"]) |
| 285 | return self.doAdd(dn, fields) |
280 | | raise PyKotaStorageError, "Not implemented !" |
281 | | |
282 | | def setGroupPQuota(self, groupid, printerid, softlimit, hardlimit) : |
| 365 | fields = { |
| 366 | "pykotaSoftLimit" : str(softlimit), |
| 367 | "pykotaHardLimit" : str(hardlimit), |
| 368 | } |
| 369 | return self.doModify(userquotaid, fields) |
| 370 | |
| 371 | def setGroupPQuota(self, groupquotaid, printerid, softlimit, hardlimit) : |