Changeset 2393

Show
Ignore:
Timestamp:
07/28/05 17:58:30 (19 years ago)
Author:
jerome
Message:

Added the overwrite_jobticket directive.
Severity : How Powerful !!! :-)

Location:
pykota/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r2389 r2393  
    227227                (bcode, clienthost) = self.getJobInfosFromPageLog(cupsdconf, printer.Name, user.Name, self.jobid) 
    228228            self.logdebug("Client Hostname : %s" % (clienthost or "Unknown"))     
     229             
     230            bcode = self.overwrittenBillingCode or bcode 
    229231            self.logdebug("Billing Code : %s" % (bcode or "None"))     
    230232             
     
    299301                billingcode = None 
    300302             
     303            # Should we cancel the job in any case (because job ticket 
     304            # was overwritten) ? 
     305            if self.mustDeny : 
     306                action = "DENY" 
     307                 
    301308            # exports some new environment variables 
    302309            os.environ["PYKOTAACTION"] = action 
  • pykota/trunk/NEWS

    r2390 r2393  
    2222PyKota NEWS : 
    2323        
     24    - 1.23alpha20 : 
     25     
     26        - Added the overwrite_jobticket directive. See pykota.conf.sample 
     27          for how to use it. 
     28           
    2429    - 1.23alpha19 : 
    2530     
  • pykota/trunk/pykota/tool.py

    r2347 r2393  
    665665        self.username = self.username or pwd.getpwuid(os.geteuid())[0] # use CUPS' user when printing test page from CUPS web interface, otherwise username is empty 
    666666         
     667        (newusername, newbillingcode, newaction) = self.overwriteJobTicket() 
     668        if newusername : 
     669            self.printInfo(_("Job ticket overwritten : new username = [%s]") % newusername) 
     670            self.username = newusername 
     671        if newbillingcode : 
     672            self.printInfo(_("Job ticket overwritten : new billing code = [%s]") % newbillingcode) 
     673            self.overwrittenBillingCode = newbillingcode 
     674        else :     
     675            self.overwrittenBillingCode = None 
     676        if newaction :     
     677            self.printInfo(_("Job ticket overwritten : job will be denied (but a bit later).")) 
     678            self.mustDeny = 1 
     679        else :     
     680            self.mustDeny = 0 
     681         
    667682        # do we want to strip out the Samba/Winbind domain name ? 
    668683        separator = self.config.getWinbindSeparator() 
     
    696711        self.logdebug("Capturing SIGTERM events.") 
    697712        signal.signal(signal.SIGTERM, self.sigterm_handler) 
     713         
     714    def overwriteJobTicket(self) :     
     715        """Should we overwrite the job's ticket (username and billingcode) ?""" 
     716        jobticketcommand = self.config.getOverwriteJobTicket(self.printername) 
     717        if jobticketcommand is not None : 
     718            username = billingcode = action = None 
     719            self.logdebug("Launching subprocess [%s] to overwrite the job's ticket." % jobticketcommand) 
     720            inputfile = os.popen(jobticketcommand, "r") 
     721            for line in inputfile.xreadlines() : 
     722                line = line.strip() 
     723                if line == "DENY" : 
     724                    self.logdebug("Seen DENY command.") 
     725                    action = "DENY" 
     726                elif line.startswith("USERNAME=") :     
     727                    username = line.split("=", 1)[1].strip() 
     728                    self.logdebug("Seen new username [%s]" % username) 
     729                    action = None 
     730                elif line.startswith("BILLINGCODE=") :     
     731                    billingcode = line.split("=", 1)[1].strip() 
     732                    self.logdebug("Seen new billing code [%s]" % billingcode) 
     733                    action = None 
     734            inputfile.close()     
     735            return (username, billingcode, action) 
     736        else : 
     737            return (None, None, None) 
    698738         
    699739    def sendBackChannelData(self, message, level="info") :     
  • pykota/trunk/pykota/version.py

    r2389 r2393  
    2222# 
    2323 
    24 __version__ = "1.23alpha19_unofficial" 
     24__version__ = "1.23alpha20_unofficial" 
    2525 
    2626__doc__ = "PyKota : a complete Printing Quota Solution for CUPS and LPRng." 
  • pykota/trunk/TODO

    r2376 r2393  
    3333        - Add the listing of the member printers in pkprinters if the printer 
    3434          is a printer group. 
    35            
    36         - Add a new external hook to allow the overwriting of the job's ticket         
    37           (mainly username and billing code) at startup time : 
    38            
    39             1 - hook is launched and can do whatever it wants, like asking 
    40                 the user for username+password or billing code 
    41                  
    42             2 - hook prints any (or all) of :     
    43              
    44                 USER:some_username 
    45                 BILLING:some_billingcode 
    46                 DENY 
    47                  
    48                 if hook doesn't print anything, job processed as usual. 
    49                 if DENY, job is rejected. 
    50                  
    51             3 - if billing code or username is invalid, and if PyKota 
    52                 is configured to loop in this case, hook is launched 
    53                 again, otherwise job is rejected. 
    54                  
    55             4 - if billing code and/or username is valid, the job's 
    56                 billing code and/or username are overwritten with 
    57                 these values, and PyKota processes the job as usual. 
    5835           
    5936        - Allow several levels of administrative priviledges by allowing