OK, well what I do is this:

Comment out the last three lines of the printcap entry. You don't need to
worry about pagecounting or accounting in /etc/printcap.

Get rid of the '--start' and '--stop' arguments to your python script.
Your script will instead need to determine this based on whether it is
passed 'filestart' or 'fileend'.

In your ifhp.conf file, you need to specify your accounting script like
this (there should already be a sample one commented out:

## accounting script
accounting=/usr/local/quotaimp/quotaimp.py

Also, you need to adjust the following lines in ifhp.conf to have
appropriate settings for your environment. These lines affect how
pagecounting will be done. 'pagecount_poll_start' specifies how many times
to check the page counter when a job starts. In my case, I have it check
once (ie. just get the number). Then it continues polling the pagecounter
at 15 second intervals ('pagecount_interval') until it gets 2
('pagecount_poll_end') consecutive values that match. Again, adjust these
values based on testing with your printers (ie. the speed of your printers
and the amount of delay you want/need between jobs).

##pagecount_poll=5
pagecount_poll_end=2
pagecount_poll_start=1
pagecount_interval=15
pagecount_timeout=0

Assuming you are using the latest version of ifhp, all the other default
settings should be fine.

When the print job starts, it will first query the printer for the
pagecount and then it will call your filter with the 'filestart' line as
arguments. Here you can check a users' 'quota'. If the print job is
permitted, you exit normally and the print job will begin printing.
Otherwise, you exit with an error (ie. return/exit 1) and the print job
will be aborted.

Once the job is complete and the pagecounter value is matched twice, ifhp
will again run your script, but this time with the 'fileend' line. You
need to parse this line and get the pagecount (it's the first '-b'
argument). Then you can do your billing.

This isn't foolproof, it can sometimes get fooled by paper jams, etc but
at least the user is never over-billed. In my situation that's the main
concern - a few lost pages every now and then is not a big deal with the
volume of printing that I deal with.


If you need any more help, let me know. I use this technique with a
accounting filter written in C, and a daemon backend which uses MySQL
(also written in C). Users have account balances, printing exemptions,
etc. which much be checked before a print job is allowed and then updated
after a print job completes.

Good luck!
Jamie



>
> Hi. Thank you for your reply.
>
> I already use ifhp but I didn't know it could help me with quota. (I read
> whole LPRng-Reference
> and some chapters of LPRng-Cookbook)
>
> So if you can tell me more about your solution, I would be very grateful !
>
> Here is my whole printcap entry if it could help:
> The last 2 commented ifhp lines are just tests I've done, but I didn't
> really understood what it is suppose to do... Maybe the answer is in
> :ifhp=pagecount
>
> lp:
>   :sd=/var/spool/lpd/%P
>   :force_localhost
>   :lp=10.23.1.58%9100
> #  :lp=/dev/null
>   :ifhp=model=hp2200
> #  :ifhp=pagecount=|/home/paul/p.py
> #  :ifhp=pagecounter,status,dev=10.23.1.58%9100
>   :filter=/usr/libexec/filters/ifhp
>   :af=|/tmp/p.py
>   :as=|/usr/local/quotaimp/quotaimp.py --start
>   :ae=|/usr/local/quotaimp/quotaimp.py --stop
>
> Thank you for your help !
>
> Paul
>
>
>
>
>
>
>
>>From: "Jamie Jennings" <[EMAIL PROTECTED]>
>>Reply-To: [EMAIL PROTECTED]
>>To: [EMAIL PROTECTED]
>>Subject: Re: LPRng: I'm lost with accounting...
>>Date: Fri, 16 Jan 2004 07:48:04 -0330 (NST)
>>
>>Hi. I don't have a solution to you exact question, however I do printer
>>accounting (like you want) using ifhp. Ifhp will call a accounting
>>script/program and pass the appropriate filestart/fileend line(s) at the
>>start and end of job.
>>
>>You might want to give it a try. It'll save you your problems with
>>grep'ing.
>>
>>Let me know if you need any more info.
>>
>>
>> >
>> > Hi list,
>> >
>> > I am trying to write a python script to manage quota by user with
>> lprng.
>> >
>> > So I add it to my printcap:
>> >
>> >   :af=/tmp/acct
>> >   :as=|/usr/local/quotaimp/quotaimp.py --start
>> >   :ae=|/usr/local/quotaimp/quotaimp.py --stop
>> >
>> > The --stop option execute some quite simple commands:
>> > it looks at the -n(login) -P(printer) -A(info) options passed through
>>the
>> > command line by LPRng and I check in my accounting file for lines
>>matching
>> > these options with:
>> >
>> > cat /tmp/acct | grep (login) | grep (printer) | grep (info)
>> >
>> > Then most of the time, I obtain 2 lines: one beginning with
>> 'filestart'
>> > and
>> > the other one beginning with 'fileend'.
>> > After, I check the -p(pagecounter) option and get how many pages had
>>been
>> > printed.
>> >
>> > Unfortunately, while my tests, I noticed that sometimes, I don't
>> obtain
>> > only
>> > 2 lines.
>> > For example:
>> >
>> > # cat /tmp/acct | grep paul | grep lp | grep [EMAIL PROTECTED]
>> > filestart '-q26339' '-p0' '-t2004-01-15-09:23:01.728'
>> '[EMAIL PROTECTED]'
>> > '-npaul' '-Plp'
>> > fileend '-b0' '-T0' '-q26339' '-p0' '-t2004-01-15-09:23:01.730'
>> > '[EMAIL PROTECTED]' '-npaul' '-Plp'
>> > filestart '-q30340' '-p471' '-t2004-01-15-18:12:46.904'
>>'[EMAIL PROTECTED]'
>> > '-npaul' '-Plp'
>> > fileend '-b4' '-T26' '-q30340' '-p475' '-t2004-01-15-18:13:11.942'
>> > '[EMAIL PROTECTED]' '-npaul' '-Plp'
>> >
>> > I was first surprised because I used to think the '-A' option was
>>unique.
>> > So is it normal to get 4 lines with this kind of command ?
>> >
>> > And do you know how could I do to don't have this kind of problem ?
>> > I know there is a perl script coming with the LPRng distribution but I
>> > don't
>> > understand it and I even don't know if it does what I want.
>> >
>> > Any help would be appreciated.
>> >
>> > Thanks and sorry for my bad english.
>> >
>> > Paul
>
> _________________________________________________________________
> Hotmail : un compte GRATUIT qui vous suit partout et tout le temps !
> http://g.msn.fr/FR1000/9493
>
>
> -----------------------------------------------------------------------------
> YOU MUST BE A LIST MEMBER IN ORDER TO POST TO THE LPRNG MAILING LIST
> The address you post from MUST be your subscription address
>
> If you need help, send email to [EMAIL PROTECTED] (or lprng-requests
> or lprng-digest-requests) with the word 'help' in the body.  For the
> impatient,
> to subscribe to a list with name LIST,  send mail to [EMAIL PROTECTED]
> with:                           | example:
> subscribe LIST <mailaddr>       |  subscribe lprng-digest [EMAIL PROTECTED]
> unsubscribe LIST <mailaddr>     |  unsubscribe lprng [EMAIL PROTECTED]
>
> If you have major problems,  send email to [EMAIL PROTECTED] with the
> word
> LPRNGLIST in the SUBJECT line.
> -----------------------------------------------------------------------------
>


-----------------------------------------------------------------------------
YOU MUST BE A LIST MEMBER IN ORDER TO POST TO THE LPRNG MAILING LIST
The address you post from MUST be your subscription address

If you need help, send email to [EMAIL PROTECTED] (or lprng-requests
or lprng-digest-requests) with the word 'help' in the body.  For the impatient,
to subscribe to a list with name LIST,  send mail to [EMAIL PROTECTED]
with:                           | example:
subscribe LIST <mailaddr>       |  subscribe lprng-digest [EMAIL PROTECTED]
unsubscribe LIST <mailaddr>     |  unsubscribe lprng [EMAIL PROTECTED]

If you have major problems,  send email to [EMAIL PROTECTED] with the word
LPRNGLIST in the SUBJECT line.
-----------------------------------------------------------------------------

Reply via email to