1 | # $Id$ |
---|
2 | |
---|
3 | PyKota - Print Quota for CUPS |
---|
4 | |
---|
5 | (c) 2003 Jerome Alet <alet@librelogiciel.com> |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2 of the License, or |
---|
9 | (at your option) any later version. |
---|
10 | |
---|
11 | This program is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with this program; if not, write to the Free Software |
---|
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
19 | |
---|
20 | ==================================================================== |
---|
21 | |
---|
22 | READ SPECIAL LICENSING AND REDISTRBUTION TERMS IN THE FILE 'LICENSE' |
---|
23 | |
---|
24 | ==================================================================== |
---|
25 | |
---|
26 | PyKota is a complete Print Quota system for the Common Unix Printing |
---|
27 | System (aka CUPS), which works by directly querying the printers |
---|
28 | for the number of pages they have printed. |
---|
29 | |
---|
30 | Actual working features : |
---|
31 | |
---|
32 | - Per printer user and group quotas. |
---|
33 | |
---|
34 | - Automated email warning of users above quota to the |
---|
35 | user himself and to the print quota administrator. |
---|
36 | |
---|
37 | - CUPS filter for quota accounting : pykota |
---|
38 | |
---|
39 | - Command line print quota editor : edpykota |
---|
40 | |
---|
41 | - Command line print quota report generator : repykota |
---|
42 | |
---|
43 | - Command line print quota automated warning sender : warnpykota |
---|
44 | |
---|
45 | - Command line tools mimic the disk quota utilities for |
---|
46 | easier mastering. |
---|
47 | |
---|
48 | - Centralized storage of quotas : you can manage quotas for |
---|
49 | different printers on different print servers and store them all |
---|
50 | on the same quota storage server. |
---|
51 | |
---|
52 | - SNMP querying of any networked SNMP-enabled printer. |
---|
53 | |
---|
54 | - Netatalk querying of any networked AppleTalk-enabled printer. |
---|
55 | |
---|
56 | - External command querying of any printer : you can use |
---|
57 | you own querying command, e.g. to query a printer via |
---|
58 | the serial port, sending it a special PJL job and |
---|
59 | reading the result. See the example scripts in the |
---|
60 | "untested" directory and try to adapt them to your |
---|
61 | configuration. |
---|
62 | |
---|
63 | - Special scripts included for a seamless integration of |
---|
64 | PyKota on Debian machines. |
---|
65 | |
---|
66 | - Complete job history is saved. This will allow more |
---|
67 | complex reports in the future. |
---|
68 | |
---|
69 | - Price per page and price per job can be defined for |
---|
70 | every printer. A job's price is the sum of the |
---|
71 | price per job for this printer plus the number of |
---|
72 | pages multiplied by the price per page for this |
---|
73 | printer. |
---|
74 | |
---|
75 | - User's account balance and lifetime paid money are now |
---|
76 | stored in the Quota Storage, and account balance can be |
---|
77 | used to limit the user printing instead of a print quota. |
---|
78 | Actually you can limit either by account balance OR by |
---|
79 | print quota, but maybe both should be checked at the |
---|
80 | same time. Tell me what you prefer. |
---|
81 | |
---|
82 | All the command line tools accept the -h | --help command line option |
---|
83 | which prints all the available options and show usage examples. |
---|
84 | |
---|
85 | Planned features are described in the TODO file. |
---|
86 | |
---|
87 | Actually only the lazy quota method is implemented. What do I call |
---|
88 | lazy method ? |
---|
89 | |
---|
90 | The lazy method consists in querying the printer (actually via SNMP |
---|
91 | or Netatalk) for its total pages counter, just before the beginning |
---|
92 | of a job, and use this to modify the *preceding* user's quota. So |
---|
93 | you're always late of one print job, but this is generally ok, |
---|
94 | especially because a check is also done to see if the current user |
---|
95 | is allowed or not to print. |
---|
96 | |
---|
97 | Problem may theorically arise in batches of successive print jobs by |
---|
98 | different users when there's no sleep time between two jobs : the |
---|
99 | used pages may theorically be attributed to an incorrect user in the |
---|
100 | case that the printer is asked for its page counter at the beginning |
---|
101 | of a new job and before the end of the previous job. This depends on |
---|
102 | the printer speed and time between jobs, but so far I've not seen |
---|
103 | any problem with moderately used printers. This also depends on CUPS |
---|
104 | internal behavior : if CUPS doesn't begin to send a job to a printer |
---|
105 | before the previous one is completely printed, then there's no |
---|
106 | problem. |
---|
107 | |
---|
108 | Other querying methods which won't suffer from this possible |
---|
109 | problem, but probably from other ones ;-) will be implemented in the |
---|
110 | future. |
---|
111 | |
---|
112 | PyKota is known to work fine with HP Laserjet 2100 and 2200, and |
---|
113 | Apple LaserWriter 16/600 PS. |
---|
114 | |
---|
115 | It should also work fine with any printer capable of outputing |
---|
116 | its lifetime printed pages counter via either SNMP or AppleTalk. |
---|
117 | |
---|
118 | If your printers don't support SNMP or AppleTalk, then making them |
---|
119 | work with PyKota is up to you. Some sample scripts which can query |
---|
120 | non-SNMP printers for their lifetime page counter are included in |
---|
121 | the ./untested directory. You'll have to test and adapt them though, |
---|
122 | and define them as external requesters in the PyKota configuration |
---|
123 | file. See the sample configuration file to learn how to do that. |
---|
124 | |
---|
125 | ============================================================ |
---|
126 | |
---|
127 | INSTALLATION: |
---|
128 | ============= |
---|
129 | |
---|
130 | WARNING : |
---|
131 | ========= |
---|
132 | |
---|
133 | If you run a PyKota version lower than 1.03, you definitely have to |
---|
134 | upgrade you Quota Storage Database. Please read the documentation |
---|
135 | included in the initscripts subdirectory first ! |
---|
136 | |
---|
137 | Prerequisite : |
---|
138 | -------------- |
---|
139 | |
---|
140 | You need to have the following tools installed on the CUPS Server : |
---|
141 | |
---|
142 | - CUPS |
---|
143 | - Python v2.1 or above |
---|
144 | - eGenix' mxDateTime Python extension |
---|
145 | - PostgreSQL's PygreSQL Python extension and the PostgreSQL client |
---|
146 | libraries. |
---|
147 | - SNMP tools (specifically the snmpget command) if you plan to |
---|
148 | request your printer's lifetime page counter via SNMP. |
---|
149 | - Netatalk (specifically the pap command) if you plan to |
---|
150 | request your printer's lifetime page counter via AppleTalk. |
---|
151 | |
---|
152 | You need to have the following tools installed on the Quota Storage |
---|
153 | Server : |
---|
154 | |
---|
155 | - PostgreSQL |
---|
156 | |
---|
157 | PygreSQL and the PostgreSQL client libraries's versions on the CUPS |
---|
158 | Server must match the PostgreSQL version used on the Quota Storage |
---|
159 | Server. |
---|
160 | |
---|
161 | This list of prerequisite software may change in the future, when |
---|
162 | PyKota will support more functionnalities you will be given |
---|
163 | alternatives. |
---|
164 | |
---|
165 | Of course the CUPS Server and the Quota Storage Server can be the |
---|
166 | very same machine if you've got a tiny network, or you can have |
---|
167 | multiple CUPS Servers all storing their quotas on the same Quota |
---|
168 | Storage Server if you've got a bigger network. |
---|
169 | |
---|
170 | Then : |
---|
171 | ------ |
---|
172 | |
---|
173 | Download the latest PyKota version from the CVS tree on : |
---|
174 | |
---|
175 | http://savannah.nongnu.org/projects/pykota |
---|
176 | |
---|
177 | Just type : |
---|
178 | |
---|
179 | python setup.py install |
---|
180 | |
---|
181 | You may need to be logged in with sufficient privileges (e.g. root) |
---|
182 | |
---|
183 | The installation script will now automatically check if some software |
---|
184 | is missing and ask you if you still want to proceed with the |
---|
185 | installation or abort it completely. |
---|
186 | |
---|
187 | Go to the initscripts subdirectory of PyKota's sources, and choose |
---|
188 | the appropriate storage backend for your configuration. Read |
---|
189 | the associated README file and execute the initialization script |
---|
190 | to create an empty PyKota Storage. Upgrade scripts may be |
---|
191 | provided as well. |
---|
192 | |
---|
193 | Copy the conf/pykota.conf.sample sample configuration file to |
---|
194 | /etc/pykota.conf, and adapt this file to your own needs and |
---|
195 | configuration. The installation script tries to do this for |
---|
196 | you if needed and you agreed to this action. |
---|
197 | |
---|
198 | Modify the PPD files for each printer on which you want to manage |
---|
199 | print quotas, for example /etc/cups/ppd/lp.ppd : |
---|
200 | |
---|
201 | --- Add the line below exactly as-is somewhere near the top --- |
---|
202 | *cupsFilter: "application/vnd.cups-postscript 0 /usr/bin/pykota" |
---|
203 | --- Add the line above exactly as-is somewhere near the top --- |
---|
204 | |
---|
205 | Modify the path to the pykota executable if needed, unfortunately |
---|
206 | you have to supply the correct absolute path here due to CUPS |
---|
207 | internals, or put the pykota executable into /usr/lib/cups/filter |
---|
208 | instead of into /usr/bin. |
---|
209 | |
---|
210 | Do this for each ppd file present in this directory if you want |
---|
211 | to enable quota on every printer. |
---|
212 | |
---|
213 | WARNING : In the case you've got a non-postscript printer, chances |
---|
214 | are that the *cupsFilter is already filled-in and points |
---|
215 | to cupsomatic or such a print filter. In this case please |
---|
216 | check if you can switch your printer to PostScript mode |
---|
217 | or if there's a way to make it accept PostScript jobs. |
---|
218 | If yes then ensure that your workstations uses a PostScript |
---|
219 | printer driver, and replace the *cupsFilter line with the |
---|
220 | one pointing to the pykota filter. This should work, but |
---|
221 | is currently untested. |
---|
222 | If your printer really needs the original *cupsFilter line |
---|
223 | then you may not be able to use PyKota easily for now. |
---|
224 | |
---|
225 | Add printers and users to the quota system and set their quota values : |
---|
226 | |
---|
227 | $ edpykota --add -P printer -S softlimit -H hardlimit user1 ... userN |
---|
228 | |
---|
229 | launching edpykota without any argument or with the --help |
---|
230 | command line option will show you all the possibilities. |
---|
231 | |
---|
232 | Restart CUPS, for example under Debian GNU/Linux systems : |
---|
233 | |
---|
234 | $ /etc/init.d/cupsys restart |
---|
235 | |
---|
236 | Your users now should be able to print but not exceed their |
---|
237 | printing quota. |
---|
238 | |
---|
239 | To see printer command usage, you can use : |
---|
240 | |
---|
241 | $ repykota --printer lp |
---|
242 | |
---|
243 | or : |
---|
244 | |
---|
245 | $ repykota |
---|
246 | |
---|
247 | which will print quota usage for all users on all printers, |
---|
248 | along with totals. |
---|
249 | |
---|
250 | SECURITY : You should ensure that only the print quota administrator |
---|
251 | can run the warnpykota command, but this is actually not |
---|
252 | enforced in the program. Any user able to launch warnpykota |
---|
253 | could flood over-quota users' email boxes. |
---|
254 | |
---|
255 | You should ensure that only the print quota administrator |
---|
256 | can run the edpykota command, but this is actually not |
---|
257 | enforced in the program. Otherwise, any user could modify |
---|
258 | his/her or other people's print quota. |
---|
259 | |
---|
260 | launching : chmod 750 /usr/bin/warnpykota /usr/bin/edpykota |
---|
261 | should make you reasonably safe. |
---|
262 | |
---|
263 | ============================================================ |
---|
264 | |
---|
265 | Please e-mail bugs to: alet@librelogiciel.com (Jerome Alet) |
---|