Changeset 2474
- Timestamp:
- 09/24/05 00:18:43 (19 years ago)
- Location:
- pykota/trunk
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r2463 r2474 36 36 import fnmatch 37 37 import pwd 38 import socket 39 import smtplib 38 40 39 41 from pykota.tool import PyKotaTool, PyKotaToolError, crashed … … 188 190 189 191 self.Action = "ALLOW" # job allowed by default 192 self.Reason = None 190 193 self.JobId = sys.argv[1].strip() 191 194 # use CUPS' user when printing test pages from CUPS' web interface … … 292 295 if action : 293 296 self.Action = action 297 self.Reason = _("You are not allowed to print at this time.") 294 298 if username : 295 299 self.UserName = username … … 517 521 os.environ["PYKOTAJOBSIZE"] = str(self.JobSize) 518 522 os.environ["PYKOTAJOBPRICE"] = str(self.JobPrice) 523 self.logdebug("Environment updated.") 524 525 def exportReason(self) : 526 """Exports the job's action status and optional reason.""" 527 self.logdebug("Exporting job's action status...") 528 os.environ["PYKOTAACTION"] = str(self.Action) 529 if self.Reason : 530 os.environ["PYKOTAREASON"] = str(self.Reason) 519 531 self.logdebug("Environment updated.") 520 532 … … 768 780 self.printInfo("%s : %s." % (msg, _("Printing is denied by configuration")), "warn") 769 781 self.Action = "DENY" 782 self.Reason = _("Duplicate print jobs are not allowed on printer %s.") % self.PrinterName 770 783 else : 771 784 self.logdebug("Launching subprocess [%s] to see if dupes should be allowed or not." % denyduplicates) … … 775 788 if self.Action == "DENY" : 776 789 self.printInfo("%s : %s." % (msg, _("Subprocess denied printing of a dupe")), "warn") 790 self.Reason = _("Duplicate print jobs are not allowed on printer %s at this time.") % self.PrinterName 777 791 else : 778 792 self.printInfo("%s : %s." % (msg, _("Subprocess allowed printing of a dupe")), "warn") … … 781 795 self.logdebug("Checking if the job is a dupe done.") 782 796 797 def tellUser(self) : 798 """Sends a message to an user.""" 799 self.logdebug("Sending some feedback to user %s..." % self.UserName) 800 if not self.Reason : 801 self.logdebug("No feedback to send to user %s." % self.UserName) 802 else : 803 (mailto, arguments) = self.config.getMailTo(self.PrinterName) 804 if mailto == "EXTERNAL" : 805 # TODO : clean this again 806 self.externalMailTo(arguments, self.Action, self.User, self.Printer, self.Reason) 807 else : 808 # TODO : clean this again 809 admin = self.config.getAdmin(self.PrinterName) 810 adminmail = self.config.getAdminMail(self.PrinterName) 811 usermail = self.User.Email or self.User.Name 812 if "@" not in usermail : 813 usermail = "%s@%s" % (usermail, self.maildomain or self.smtpserver) 814 destination = [] 815 if mailto in ("BOTH", "ADMIN") : 816 destination.append(adminmail) 817 if mailto in ("BOTH", "USER") : 818 destination.append(usermail) 819 820 fullmessage = self.Reason + (_("\n\nYour system administrator :\n\n\t%s - <%s>\n") % (admin, adminmail)) 821 try : 822 server = smtplib.SMTP(self.smtpserver) 823 except socket.error, msg : 824 self.printInfo(_("Impossible to connect to SMTP server : %s") % msg, "error") 825 else : 826 try : 827 server.sendmail(adminmail, destination, \ 828 "From: %s\nTo: %s\nCc: %s\nSubject: %s\n\n%s" \ 829 % (adminmail, usermail, adminmail, _("Print Quota"), fullmessage)) 830 except smtplib.SMTPException, answer : 831 for (k, v) in answer.recipients.items() : 832 self.printInfo(_("Impossible to send mail to %s, error %s : %s") % (k, v[0], v[1]), "error") 833 server.quit() 834 self.logdebug("Feedback sent to user %s." % self.UserName) 835 783 836 def mainWork(self) : 784 837 """Main work is done here.""" … … 827 880 self.printInfo(_("Precomputed job size (%s pages) too large for printer %s.") % (self.softwareJobSize, self.PrinterName), "warn") 828 881 self.Action = "DENY" 882 # here we don't put the precomputed job size in the message 883 # because in case of error the user could complain :-) 884 self.Reason = _("You are not allowed to print so many pages on printer %s at this time.") % self.PrinterName 829 885 830 886 if self.Action != "DENY" : … … 832 888 self.printInfo(_("User %s is not allowed to print at this time.") % self.UserName, "warn") 833 889 self.Action = "DENY" 890 self.Reason = _("Your account settings forbid you to print at this time.") 834 891 835 892 if self.Action != "DENY" : … … 859 916 self.logdebug("Checking user %s print quota entry on printer %s" \ 860 917 % (self.UserName, self.PrinterName)) 861 self.Action = self.warnUserPQuota(self.UserPQuota) 918 self.Action = self.checkUserPQuota(self.UserPQuota) 919 if self.Action.startswith("POLICY_") : 920 self.Action = self.Action[7:] 921 if self.Action == "DENY" : 922 self.printInfo(_("Print Quota exceeded for user %s on printer %s") % (self.UserName, self.PrinterName)) 923 self.Reason = self.config.getHardWarn(self.PrinterName) 924 elif self.Action == "WARN" : 925 self.printInfo(_("Print Quota low for user %s on printer %s") % (self.UserName, self.PrinterName)) 926 if self.User.LimitBy and (self.User.LimitBy.lower() == "balance") : 927 self.Reason = self.config.getPoorWarn() 928 else : 929 self.Reason = self.config.getSoftWarn(self.PrinterName) 862 930 863 931 # exports some new environment variables 864 os.environ["PYKOTAACTION"] = str(self.Action) 932 self.exportReason() 933 934 # now tell the user if he needs to know something 935 self.tellUser() 865 936 866 937 # launches the pre hook -
pykota/trunk/conf/pykota.conf.sample
r2445 r2474 758 758 # PYKOTAOVERCHARGE : user's overcharging factor. 759 759 # PYKOTAJOBBILLING : Job's billing code if present (CUPS only) 760 # PYKOTAREASON : if the job was denied or a warning needs to be issued, contains 761 # the message to send to the user. 760 762 # 761 763 -
pykota/trunk/NEWS
r2467 r2474 22 22 PyKota NEWS : 23 23 24 - 1.23beta : 25 26 - Now the mailto directive is honored in all cases where the job is 27 denied or a warning has to be issued, and the correct reason 28 can be sent back to the user. 29 30 - The PYKOTAREASON environment variable, if defined, contains the 31 textual reason why the job was denied or a warning has to be 32 issued. 33 24 34 - 1.23alpha31 : 25 35 -
pykota/trunk/pykota/version.py
r2465 r2474 22 22 # 23 23 24 __version__ = "1.23 alpha31_unofficial"24 __version__ = "1.23beta_unofficial" 25 25 26 26 __doc__ = "PyKota : a complete Printing Quota Solution for CUPS and LPRng."