Show
Ignore:
Timestamp:
02/06/03 10:19:02 (21 years ago)
Author:
jalet
Message:

More robust behavior (hopefully) when the user or printer is not managed
correctly by the Quota System : e.g. cupsFilter added in ppd file, but
printer and/or user not 'yet?' in storage.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/tool.py

    r712 r713  
    1515# 
    1616# $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# 
    1722# Revision 1.7  2003/02/06 00:00:45  jalet 
    1823# Now includes the printer name in email messages 
     
    9196        now = DateTime.now() 
    9297        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"] : 
    101102                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 :          
    111128                         action = "DENY" 
    112                  else :          
    113                      action = "DENY" 
     129                else :         
     130                    action = "DENY" 
    114131            else :         
    115                 action = "DENY" 
    116         else :         
    117             action = "ALLOW" 
    118         return (action, (hardlimit - pagecounter), datelimit) 
     132                action = "ALLOW" 
     133            return (action, (hardlimit - pagecounter), datelimit) 
    119134     
    120135    def warnQuotaPrinter(self, username) : 
     
    122137        (action, grace, gracedate) = self.checkUserPQuota(username, self.printername) 
    123138        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) 
    128145        elif action == "WARN" :     
    129146            adminmessage = "Print Quota soft limit exceeded for user %s on printer %s" % (username, self.printername)