Changeset 1152
- Timestamp:
- 10/08/03 23:41:38 (21 years ago)
- Location:
- pykota/trunk
- Files:
-
- 10 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pykota
r1144 r1152 24 24 # 25 25 # $Log$ 26 # Revision 1.42 2003/10/08 21:41:38 jalet 27 # External policies for printers works ! 28 # We can now auto-add users on first print, and do other useful things if needed. 29 # 26 30 # Revision 1.41 2003/10/07 09:07:27 jalet 27 31 # Character encoding added to please latest version of Python … … 252 256 return -1 253 257 258 def format_commandline(prt, usr, cmdline) : 259 """Passes printer and user names on the command line.""" 260 printer = prt.Name 261 user = usr.Name 262 # we don't want the external command's standard 263 # output to break the print job's data, but we 264 # want to keep its standard error 265 return "%s >/dev/null" % (cmdline % locals()) 266 254 267 def main(thefilter) : 255 268 """Do it, and do it right !""" … … 268 281 thefilter.logger.log_message(_("Printer %s not registered in the PyKota system") % thefilter.printername, "warn") 269 282 else : 270 user = thefilter.storage.getUser(thefilter.username) 271 if not user.Exists : 272 # The user is unknown from the Quota Storage perspective 273 # Depending on the default policy for this printer, we 274 # either let the job pass through or reject it, but we 275 # log a message in any case. 276 policy = thefilter.config.getPrinterPolicy(thefilter.printername) 277 if policy == "ALLOW" : 278 action = "POLICY_ALLOW" 283 for compteur in range(2) : 284 user = thefilter.storage.getUser(thefilter.username) 285 if user.Exists : 286 break 279 287 else : 280 action = "POLICY_DENY" 281 thefilter.logger.log_message(_("User %s not registered in the PyKota system, applying default policy (%s) for printer %s") % (thefilter.username, action, thefilter.printername), "warn") 282 if action == "POLICY_DENY" : 283 return thefilter.removeJob() 284 else : 288 # The user is unknown from the Quota Storage perspective 289 # Depending on the default policy for this printer, we 290 # either let the job pass through or reject it, but we 291 # log a message in any case. 292 (policy, args) = thefilter.config.getPrinterPolicy(thefilter.printername) 293 if policy == "ALLOW" : 294 action = "POLICY_ALLOW" 295 elif policy == "EXTERNAL" : 296 commandline = format_commandline(printer, user, args) 297 thefilter.logger.log_message(_("User %s not registered in the PyKota system, applying external policy (%s) for printer %s") % (thefilter.username, commandline, thefilter.printername), "info") 298 if os.system(commandline) : 299 thefilter.logger.log_message(_("External policy %s for printer %s produced an error. Job rejected. Please check PyKota's configuration files.") % (commandline, thefilter.printername), "error") 300 return thefilter.removeJob() 301 else : 302 # here we try a second time, because the goal 303 # of the external action was to add the user 304 # in the database. 305 continue 306 else : 307 action = "POLICY_DENY" 308 thefilter.logger.log_message(_("User %s not registered in the PyKota system, applying default policy (%s) for printer %s") % (thefilter.username, action, thefilter.printername), "warn") 309 if action == "POLICY_DENY" : 310 return thefilter.removeJob() 311 # when we get there, the printer policy allows the job to pass 312 break 313 314 # if user exists, do accounting 315 if user.Exists : 285 316 # Now does the accounting and act depending on the result 286 317 action = thefilter.accounter.doAccounting(printer, user) 287 318 288 319 # if not allowed to print then die, else proceed. 289 320 if action == "DENY" : 290 321 # No, just die cleanly 291 322 return thefilter.removeJob() 323 elif policy == "EXTERNAL" : 324 thefilter.logger.log_message(_("External policy %s for printer %s couldn't add user %s. Job rejected.") % (commandline, thefilter.printername, thefilter.username), "error") 325 return thefilter.removeJob() 292 326 293 327 # pass the job untouched to the underlying layer -
pykota/trunk/conf/pykota.conf.sample
r1149 r1152 300 300 301 301 # Default policy for inexistant users (e.g. root) 302 # either allow or deny 302 # either allow or deny or external(some command here) 303 303 # This value can be set either globally or per printer or both. 304 304 # If both are defined, the printer option has priority. … … 309 309 # charged to the next person who prints on the same printer. 310 310 # There's no policy wrt inexistant groups, they are ignored. 311 # 312 # external policy can be used to launch any external command of your choice, 313 # for example to automatically add the user to the quota storage 314 # if he is unknown. Example : 315 # 316 # policy: external(/usr/bin/edpykota --add --printer %(printer)s --softlimit 50 --hardlimit 60 %(user)s) 317 # 318 # NB : '%(user)s' and '%(printer)s' will be automatically replaced 319 # by the user and printer names. 320 # 321 # Of course you can launch any command of your choice with this, e.g. : 322 # 323 # policy: external(/usr/local/bin/myadminscript.sh %(user)s) 324 # 311 325 policy: deny 312 326 -
pykota/trunk/NEWS
r1149 r1152 22 22 PyKota NEWS : 23 23 24 - 1.15alpha9 : 25 26 - External policy can be used to auto-add unknown users 27 and any other interesting things you may want to do. 28 WARNING : You can't auto-add printers for now. 29 They have to be created manually before. 30 Look at sample configuration file for examples. 31 24 32 - 1.15alpha8 : 25 33 -
pykota/trunk/po/en/pykota.po
r1116 r1152 21 21 # 22 22 # $Log$ 23 # Revision 1.35 2003/10/08 21:41:38 jalet 24 # External policies for printers works ! 25 # We can now auto-add users on first print, and do other useful things if needed. 26 # 23 27 # Revision 1.34 2003/08/18 16:20:59 jalet 24 28 # Improvement of the printing system detection code. … … 427 431 msgstr "" 428 432 433 msgid "Invalid policy %s for printer %s" 434 msgstr "" 435 436 msgid "User %s not registered in the PyKota system, applying external policy (%s) for printer %s" 437 msgstr "" 438 439 msgid "External policy %s for printer %s produced an error. Job rejected. Please check PyKota's configuration files." 440 msgstr "" 441 442 msgid "External policy %s for printer %s couldn't add user %s. Job rejected." 443 msgstr "" 444 -
pykota/trunk/po/fr/pykota.po
r1116 r1152 21 21 # 22 22 # $Log$ 23 # Revision 1.34 2003/10/08 21:41:38 jalet 24 # External policies for printers works ! 25 # We can now auto-add users on first print, and do other useful things if needed. 26 # 23 27 # Revision 1.33 2003/08/18 16:20:59 jalet 24 28 # Improvement of the printing system detection code. … … 437 441 msgstr "Syst� d'impression inconnu, args=%s" 438 442 443 msgid "Invalid policy %s for printer %s" 444 msgstr "Option policy %s invalide pour l'imprimante %s" 445 446 msgid "User %s not registered in the PyKota system, applying external policy (%s) for printer %s" 447 msgstr "Utilisateur %s non enregistr�ans le syst� PyKota, action externe (%s) appliqu�sur l'imprimante %s" 448 449 msgid "External policy %s for printer %s produced an error. Job rejected. Please check PyKota's configuration files." 450 msgstr "L'action externe %s sur l'imprimante %s a produit une erreur. Job rejet�Merci de v�fier les fichiers de configuration de PyKota." 451 452 msgid "External policy %s for printer %s couldn't add user %s. Job rejected." 453 msgstr "L'action externe %s sur l'imprimante %s n'a pas pu ajouter l'utilisateur %s. Job rejet� 454 -
pykota/trunk/po/pykota.pot
r1116 r1152 21 21 # 22 22 # $Log$ 23 # Revision 1.35 2003/10/08 21:41:38 jalet 24 # External policies for printers works ! 25 # We can now auto-add users on first print, and do other useful things if needed. 26 # 23 27 # Revision 1.34 2003/08/18 16:20:59 jalet 24 28 # Improvement of the printing system detection code. … … 427 431 msgstr "" 428 432 433 msgid "Invalid policy %s for printer %s" 434 msgstr "" 435 436 msgid "User %s not registered in the PyKota system, applying external policy (%s) for printer %s" 437 msgstr "" 438 439 msgid "External policy %s for printer %s produced an error. Job rejected. Please check PyKota's configuration files." 440 msgstr "" 441 442 msgid "External policy %s for printer %s couldn't add user %s. Job rejected." 443 msgstr "" 444 -
pykota/trunk/pykota/config.py
r1148 r1152 22 22 # 23 23 # $Log$ 24 # Revision 1.39 2003/10/08 21:41:38 jalet 25 # External policies for printers works ! 26 # We can now auto-add users on first print, and do other useful things if needed. 27 # 24 28 # Revision 1.38 2003/10/07 22:06:05 jalet 25 29 # Preliminary code to disable job history … … 320 324 def getPrinterPolicy(self, printer) : 321 325 """Returns the default policy for the current printer.""" 322 validpolicies = [ "ALLOW", "DENY" ] 323 try : 324 policy = self.getPrinterOption(printer, "policy").upper() 325 except PyKotaConfigError : 326 policy = "DENY" 327 if policy not in validpolicies : 328 raise PyKotaConfigError, _("Option policy in section %s only supports values in %s") % (printer, str(validpolicies)) 329 return policy 326 validpolicies = [ "ALLOW", "DENY", "EXTERNAL" ] 327 try : 328 fullpolicy = self.getPrinterOption(printer, "policy") 329 except PyKotaConfigError : 330 return ("DENY", None) 331 else : 332 try : 333 policy = [x.strip() for x in fullpolicy.split('(', 1)] 334 except ValueError : 335 raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printer) 336 if len(policy) == 1 : 337 policy.append("") 338 (policy, args) = policy 339 if args.endswith(')') : 340 args = args[:-1] 341 policy = policy.upper() 342 if (policy == "EXTERNAL") and not args : 343 raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printer) 344 if policy not in validpolicies : 345 raise PyKotaConfigError, _("Option policy in section %s only supports values in %s") % (printer, str(validpolicies)) 346 return (policy, args) 330 347 331 348 def getSMTPServer(self) : -
pykota/trunk/pykota/tool.py
r1144 r1152 22 22 # 23 23 # $Log$ 24 # Revision 1.53 2003/10/08 21:41:38 jalet 25 # External policies for printers works ! 26 # We can now auto-add users on first print, and do other useful things if needed. 27 # 24 28 # Revision 1.52 2003/10/07 09:07:28 jalet 25 29 # Character encoding added to please latest version of Python … … 435 439 436 440 # then we check the user's own quota 437 policy = self.config.getPrinterPolicy(printer.Name) 441 # if we get there we are sure that policy is not EXTERNAL 442 (policy, dummy) = self.config.getPrinterPolicy(printer.Name) 438 443 if user.LimitBy and (user.LimitBy.lower() == "balance") : 439 444 if user.AccountBalance is None : -
pykota/trunk/pykota/version.py
r1149 r1152 22 22 # 23 23 24 __version__ = "1.15alpha 8_unofficial"24 __version__ = "1.15alpha9_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""