Changeset 713
- Timestamp:
- 02/06/03 10:19:02 (22 years ago)
- Location:
- pykota/trunk
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/conf/pykota.conf.sample
r707 r713 60 60 # 61 61 # Default policy for inexistant users (e.g. root) 62 # either a cceptor deny63 policy: a ccept62 # either allow or deny 63 policy: allow 64 64 -
pykota/trunk/pykota/config.py
r708 r713 15 15 # 16 16 # $Log$ 17 # Revision 1.4 2003/02/06 09:19:02 jalet 18 # More robust behavior (hopefully) when the user or printer is not managed 19 # correctly by the Quota System : e.g. cupsFilter added in ppd file, but 20 # printer and/or user not 'yet?' in storage. 21 # 17 22 # Revision 1.3 2003/02/05 23:26:22 jalet 18 23 # Incorrect handling of grace delay … … 77 82 raise PyKotaConfigError, "Option %s not found in section %s of %s" % (option, printer, self.filename) 78 83 79 validpolicies = [ " accept", "deny" ]80 if self.config.get(printer, "policy"). lower() not in validpolicies :84 validpolicies = [ "ALLOW", "DENY" ] 85 if self.config.get(printer, "policy").upper() not in validpolicies : 81 86 raise PyKotaConfigError, "Option policy in section %s only supports values in %s" % (printer, str(validrequesters)) 82 87 … … 119 124 def getPrinterPolicy(self, printer) : 120 125 """Returns the default policy for the current printer.""" 121 return self.config.get(printer, "policy"). lower()126 return self.config.get(printer, "policy").upper() 122 127 123 128 def getSMTPServer(self) : -
pykota/trunk/pykota/storages/sql.py
r708 r713 15 15 # 16 16 # $Log$ 17 # Revision 1.6 2003/02/06 09:19:02 jalet 18 # More robust behavior (hopefully) when the user or printer is not managed 19 # correctly by the Quota System : e.g. cupsFilter added in ppd file, but 20 # printer and/or user not 'yet?' in storage. 21 # 17 22 # Revision 1.5 2003/02/05 23:26:22 jalet 18 23 # Incorrect handling of grace delay … … 60 65 61 66 def addUserPQuota(self, username, printername) : 62 printerid = self.getPrinterId(printername)67 (userid, printerid) = self.getUPIds(username, printername) 63 68 if printerid is None : 64 69 self.doQuery("INSERT INTO printers (printername) VALUES (%s);" % self.doQuote(printername)) 65 printerid = self.getPrinterId(printername)66 userid = self.getUserId(username)67 70 if userid is None : 68 71 self.doQuery("INSERT INTO users (username) VALUES (%s);" % self.doQuote(username)) 69 userid = self.getUserId(username)70 if ( printerid is not None) and (userid is not None) :72 (userid, printerid) = self.getUPIds(username, printername) 73 if (userid is not None) and (printerid is not None) : 71 74 return self.doQuery("INSERT INTO userpquota (userid, printerid) VALUES (%s, %s);" % (self.doQuote(userid), self.doQuote(printerid))) 72 75 76 def getUPIds(self, username, printername) : 77 return (self.getUserId(username), self.getPrinterId(printername)) 78 73 79 def getUserPQuota(self, username, printername) : 74 result = self.doQuery("SELECT pagecounter, softlimit, hardlimit, datelimit FROM userpquota WHERE userid=%s AND printerid=%s;" % (self.doQuote(self.getUserId(username)), self.doQuote(self.getPrinterId(printername)))) 75 try : 76 return self.doParseResult(result)[0] 77 except TypeError : # Not found 78 return 80 (userid, printerid) = self.getUPIds(username, printername) 81 if (userid is not None) and (printerid is not None) : 82 result = self.doQuery("SELECT pagecounter, softlimit, hardlimit, datelimit FROM userpquota WHERE userid=%s AND printerid=%s;" % (self.doQuote(userid), self.doQuote(printerid))) 83 try : 84 return self.doParseResult(result)[0] 85 except TypeError : # Not found 86 pass 79 87 80 88 def setUserPQuota(self, username, printername, softlimit, hardlimit) : 81 self.doQuery("UPDATE userpquota SET softlimit=%s, hardlimit=%s, datelimit=NULL WHERE userid=%s AND printerid=%s;" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(self.getUserId(username)), self.doQuote(self.getPrinterId(printername)))) 89 (userid, printerid) = self.getUPIds(username, printername) 90 if (userid is not None) and (printerid is not None) : 91 self.doQuery("UPDATE userpquota SET softlimit=%s, hardlimit=%s, datelimit=NULL WHERE userid=%s AND printerid=%s;" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(userid), self.doQuote(printerid))) 82 92 83 93 def updateUserPQuota(self, username, printername, pagecount) : 84 self.doQuery("UPDATE userpquota SET pagecounter=pagecounter+(%s) WHERE userid=%s AND printerid=%s;" % (self.doQuote(pagecount), self.doQuote(self.getUserId(username)), self.doQuote(self.getPrinterId(printername)))) 94 (userid, printerid) = self.getUPIds(username, printername) 95 if (userid is not None) and (printerid is not None) : 96 self.doQuery("UPDATE userpquota SET pagecounter=pagecounter+(%s) WHERE userid=%s AND printerid=%s;" % (self.doQuote(pagecount), self.doQuote(userid), self.doQuote(printerid))) 85 97 86 98 def buyUserPQuota(self, username, printername, pagebought) : -
pykota/trunk/pykota/tool.py
r712 r713 15 15 # 16 16 # $Log$ 17 # Revision 1.8 2003/02/06 09:19:02 jalet 18 # More robust behavior (hopefully) when the user or printer is not managed 19 # correctly by the Quota System : e.g. cupsFilter added in ppd file, but 20 # printer and/or user not 'yet?' in storage. 21 # 17 22 # Revision 1.7 2003/02/06 00:00:45 jalet 18 23 # Now includes the printer name in email messages … … 91 96 now = DateTime.now() 92 97 quota = self.storage.getUserPQuota(username, printername) 93 pagecounter = quota["pagecounter"] 94 softlimit = quota["softlimit"] 95 hardlimit = quota["hardlimit"] 96 datelimit = quota["datelimit"] 97 if datelimit is not None : 98 datelimit = DateTime.ISO.ParseDateTime(datelimit) 99 if softlimit is not None : 100 if pagecounter < softlimit : 98 if quota is None : 99 # Unknown user or printer or combination 100 policy = self.config.getPrinterPolicy(printername) 101 if policy in [None, "ALLOW"] : 101 102 action = "ALLOW" 102 elif hardlimit is not None : 103 gracedelay = self.config.getGraceDelay() 104 if softlimit <= pagecounter < hardlimit : 105 if datelimit is None : 106 datelimit = now + gracedelay 107 self.storage.doQuery("UPDATE userpquota SET datelimit=%s::DATETIME WHERE userid=%s AND printerid=%s;" % (self.doQuote("%04i-%02i-%02i %02i:%02i:%02i" % (datelimit.year, datelimit.month, datelimit.day, datelimit.hour, datelimit.minute, datelimit.second)), self.doQuote(self.getUserId(username)), self.doQuote(self.getPrinterId(printername)))) 108 if (now + gracedelay) < datelimit : 109 action = "WARN" 110 else : 103 else : 104 action = "DENY" 105 self.logger.log_message("Unable to match user %s on printer %s, applying default policy (%s)" % (username, printername, action), "warn") 106 return (action, None, None) 107 else : 108 pagecounter = quota["pagecounter"] 109 softlimit = quota["softlimit"] 110 hardlimit = quota["hardlimit"] 111 datelimit = quota["datelimit"] 112 if datelimit is not None : 113 datelimit = DateTime.ISO.ParseDateTime(datelimit) 114 if softlimit is not None : 115 if pagecounter < softlimit : 116 action = "ALLOW" 117 elif hardlimit is not None : 118 gracedelay = self.config.getGraceDelay() 119 if softlimit <= pagecounter < hardlimit : 120 if datelimit is None : 121 datelimit = now + gracedelay 122 self.storage.doQuery("UPDATE userpquota SET datelimit=%s::DATETIME WHERE userid=%s AND printerid=%s;" % (self.doQuote("%04i-%02i-%02i %02i:%02i:%02i" % (datelimit.year, datelimit.month, datelimit.day, datelimit.hour, datelimit.minute, datelimit.second)), self.doQuote(self.getUserId(username)), self.doQuote(self.getPrinterId(printername)))) 123 if (now + gracedelay) < datelimit : 124 action = "WARN" 125 else : 126 action = "DENY" 127 else : 111 128 action = "DENY" 112 else :113 129 else : 130 action = "DENY" 114 131 else : 115 action = "DENY" 116 else : 117 action = "ALLOW" 118 return (action, (hardlimit - pagecounter), datelimit) 132 action = "ALLOW" 133 return (action, (hardlimit - pagecounter), datelimit) 119 134 120 135 def warnQuotaPrinter(self, username) : … … 122 137 (action, grace, gracedate) = self.checkUserPQuota(username, self.printername) 123 138 if action == "DENY" : 124 adminmessage = "Print Quota exceeded for user %s on printer %s" % (username, self.printername) 125 self.logger.log_message(adminmessage) 126 self.sendMessageToUser(username, "Print Quota Exceeded", "You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s." % self.printername) 127 self.sendMessageToAdmin("Print Quota", adminmessage) 139 if (grace is not None) and (gracedate is not None) : 140 # only when both user and printer are known 141 adminmessage = "Print Quota exceeded for user %s on printer %s" % (username, self.printername) 142 self.logger.log_message(adminmessage) 143 self.sendMessageToUser(username, "Print Quota Exceeded", "You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s." % self.printername) 144 self.sendMessageToAdmin("Print Quota", adminmessage) 128 145 elif action == "WARN" : 129 146 adminmessage = "Print Quota soft limit exceeded for user %s on printer %s" % (username, self.printername)