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"] : |
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 : |
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) |