1 | # $Id$ |
---|
2 | |
---|
3 | PyKota - Print Quota for CUPS and LPRng |
---|
4 | |
---|
5 | (c) 2003-2004 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 | NOTE FOR LPRNG USERS : |
---|
23 | |
---|
24 | FROM MAY 21ST 2004 ON, AND UNTIL THIS NOTE IS REMOVED |
---|
25 | FROM THIS FILE, PYKOTA CAN'T BE USED ANYMORE WITH LPRNG. |
---|
26 | |
---|
27 | SUPPORT FOR LPRNG SHOULD BE RE-ADDED SOON WHEN A HUGE REWRITE |
---|
28 | OF SOME PARTS OF PYKOTA WILL HAVE TAKEN PLACE |
---|
29 | |
---|
30 | ==================================================================== |
---|
31 | |
---|
32 | READ SPECIAL LICENSING AND REDISTRIBUTION TERMS IN THE FILE 'LICENSE' |
---|
33 | |
---|
34 | ==================================================================== |
---|
35 | |
---|
36 | PyKota features : |
---|
37 | ----------------- |
---|
38 | |
---|
39 | Operating systems : |
---|
40 | |
---|
41 | - Any Unix-like system as print server. |
---|
42 | |
---|
43 | - Any operating system as client. |
---|
44 | |
---|
45 | Printing systems : |
---|
46 | |
---|
47 | - Supports both CUPS and LPRng as the printing system. |
---|
48 | |
---|
49 | NB : LPRng support is currently being rewritten, so |
---|
50 | LPRng is actually not supported in latest CVS versions. |
---|
51 | |
---|
52 | Databases : |
---|
53 | |
---|
54 | - Supports PostgreSQL as the Quota Storage backend. |
---|
55 | Complete database creation script in SQL is included. |
---|
56 | |
---|
57 | - Supports OpenLDAP as the Quota Storage backend. |
---|
58 | Complete LDAP schema and sample empty tree are included. |
---|
59 | Plugging PyKota into your existing LDAP infrastructure |
---|
60 | is really easy thanks to PyKota's great configurability. |
---|
61 | |
---|
62 | Printers : |
---|
63 | |
---|
64 | - Hardware or Software accounting methods are completely |
---|
65 | configurable. |
---|
66 | |
---|
67 | - Supports any printer which can report its internal |
---|
68 | page counter. Can ask printers for their internal |
---|
69 | page counter via SNMP, Netatalk, PJL, PS, or any |
---|
70 | other way. |
---|
71 | This is completely configurable. |
---|
72 | |
---|
73 | - Supports PostScript, PDF and PCL5 printers natively |
---|
74 | for software accounting methods. More formats to come. |
---|
75 | |
---|
76 | Quota systems : |
---|
77 | |
---|
78 | - Supports printers and printers groups quotas. |
---|
79 | |
---|
80 | - Supports users and users groups quotas. |
---|
81 | |
---|
82 | - Supports page quotas. |
---|
83 | Page quotas can be set differently on a per printer |
---|
84 | and per user/group basis. |
---|
85 | |
---|
86 | - Supports account balance quotas in any currency. |
---|
87 | Account balance quotas can be set on a per user |
---|
88 | basis. The account balance is shared amongst |
---|
89 | all printers. The history of payments (positive |
---|
90 | or negative credits to an user account) is kept. |
---|
91 | |
---|
92 | - Page quota and account balance can be set/reset |
---|
93 | independantly. |
---|
94 | |
---|
95 | - Limiting factor, page quota or account balance, |
---|
96 | can be set on a per user or per group basis. |
---|
97 | |
---|
98 | - Price per page and per job can be set differently |
---|
99 | on any printer. |
---|
100 | |
---|
101 | - Low level of page quota or account balance are |
---|
102 | configurable. |
---|
103 | |
---|
104 | - Both soft and hard limit with configurable grace delay |
---|
105 | can be set for page quota. |
---|
106 | |
---|
107 | - Possibility to disable quota enforcement for any user |
---|
108 | or group, while still keeping page accounting. |
---|
109 | |
---|
110 | Administration : |
---|
111 | |
---|
112 | - Powerful administration tools can be used to |
---|
113 | automate setting or resetting of quotas or |
---|
114 | account balances at specific intervals. |
---|
115 | |
---|
116 | - Administration tools can modify several users, |
---|
117 | groups, or printers at once. |
---|
118 | |
---|
119 | - Account balances can be set, incremented, or |
---|
120 | decremented. |
---|
121 | |
---|
122 | - Both printers and users can be automatically added on |
---|
123 | first print in a completely configurable way. |
---|
124 | |
---|
125 | - Quota report generator available either from the |
---|
126 | command line or in any web browser. |
---|
127 | The web-based quota report generator can be |
---|
128 | user/password protected. |
---|
129 | |
---|
130 | - Print quote generator can tell users how much |
---|
131 | a print job will cost them in advance. |
---|
132 | |
---|
133 | - Policy with regard to unregistered users can |
---|
134 | be configured for each printer to either deny |
---|
135 | printing, allow printing, or delegate the |
---|
136 | decision to any external tool. |
---|
137 | |
---|
138 | - Warning and error messages can be automatically |
---|
139 | sent via email to the administrator, the user, |
---|
140 | both, or none. |
---|
141 | |
---|
142 | - Warning and error messages' content is completely |
---|
143 | configurable. |
---|
144 | |
---|
145 | - Configuration can be changed without needing to |
---|
146 | restart the printing system. |
---|
147 | |
---|
148 | - Complete print job history is kept. This can be |
---|
149 | disabled if needed. |
---|
150 | |
---|
151 | - Automated low quota or balance remainder can be |
---|
152 | scheduled regularly or launched manually. |
---|
153 | |
---|
154 | User Interface : |
---|
155 | |
---|
156 | - All the command line tools accept the -h | --help |
---|
157 | command line option which prints all the available |
---|
158 | options and show usage examples. |
---|
159 | |
---|
160 | - Completely internationalized. Actually supports the |
---|
161 | English, French, Spanish, Portuguese, Brasilian, Swedish |
---|
162 | and Italian languages. More to come. |
---|
163 | |
---|
164 | ==================================================================== |
---|
165 | |
---|
166 | Planned features are described in the TODO file. |
---|
167 | |
---|
168 | Actually two (or an infinity of) page accounting methods are |
---|
169 | implemented : |
---|
170 | |
---|
171 | - The 'hardware' method consists in querying the printer (via SNMP |
---|
172 | or Netatalk or any other method of your choice) for its total pages |
---|
173 | counter. |
---|
174 | |
---|
175 | With CUPS, this is done both at the beginning and at the end of a |
---|
176 | print job. The counters difference is then immediately used to |
---|
177 | decrease the user's account balance or increase his quota usage. |
---|
178 | |
---|
179 | With LPRng, this is done just before the beginning of a job, and used |
---|
180 | this to modify the *preceding* user's quota. So you're always late |
---|
181 | of one print job, but this is generally ok. |
---|
182 | |
---|
183 | - The 'software' method consists in delegating the computation of the |
---|
184 | job's size in number of pages to any external command of your choice. |
---|
185 | The command can read the job's data from its standard input and MUST |
---|
186 | output the job's size on its standard output. Changes to the user |
---|
187 | account are reported immediately, both with CUPS and LPRng. |
---|
188 | |
---|
189 | PyKota is known to work fine with HP Laserjet 2100 and 2200, and |
---|
190 | Apple LaserWriter 16/600 PS, both with CUPS and LPRng, under |
---|
191 | Debian GNU/Linux (Sarge and Sid) operating systems. It should work |
---|
192 | fine with most network printers. |
---|
193 | |
---|
194 | ============================================================ |
---|
195 | |
---|
196 | INSTALLATION: |
---|
197 | ============= |
---|
198 | |
---|
199 | NB : |
---|
200 | ==== |
---|
201 | |
---|
202 | You may learn more about PyKota, if it fits your own organization, |
---|
203 | its internal working, and some potential performance drawbacks and |
---|
204 | how to avoid them, in a WiKi administered by Ryan Suarez at : |
---|
205 | |
---|
206 | http://webcrossing.macosxlabs.org/webx?14@30.QAu3a5k0c4z.7@.26bf4661 |
---|
207 | |
---|
208 | Prerequisite : |
---|
209 | -------------- |
---|
210 | |
---|
211 | You need to have the following tools installed on the CUPS Server : |
---|
212 | |
---|
213 | - CUPS or LPRng |
---|
214 | - Python v2.1 or above |
---|
215 | - eGenix' mxDateTime Python extension |
---|
216 | - SNMP tools (specifically the snmpget command) if you plan to |
---|
217 | request your printer's lifetime page counter via SNMP. |
---|
218 | - Netatalk (specifically the pap command) if you plan to |
---|
219 | request your printer's lifetime page counter via AppleTalk. |
---|
220 | - PostgreSQL's PygreSQL Python extension and the PostgreSQL client |
---|
221 | libraries if you plan to use PostgreSQL as the Quota Storage |
---|
222 | backend. |
---|
223 | or |
---|
224 | - python-ldap Python module and the OpenLDAP client libraries |
---|
225 | if you plan to use OpenLDAP as the Quota Storage backend. |
---|
226 | |
---|
227 | On Intel i386 architecture, and for performance reasons if you |
---|
228 | print in PCL format, it is strongly suggested that you install |
---|
229 | the Python accelerator Psyco, available at : |
---|
230 | |
---|
231 | http://psyco.sourceforge.net |
---|
232 | |
---|
233 | Under Debian : |
---|
234 | |
---|
235 | $ apt-get install python-psyco |
---|
236 | |
---|
237 | Other architectures may be supported as well in the future, check |
---|
238 | on Psyco's website. |
---|
239 | |
---|
240 | Installing Psyco is not mandatory, but it woud speedup PCL parsing |
---|
241 | by almost 3 times. PostScript and PDF parsing can also benefit, |
---|
242 | but in an almost unnoticeable manner since this part of the code |
---|
243 | is already optimal. For PCL this is a completely different matter, |
---|
244 | and if you install Psyco you will never regret it ! |
---|
245 | |
---|
246 | You may also benefit from having the following tools installed to |
---|
247 | deal with some printers : |
---|
248 | |
---|
249 | - npadmin |
---|
250 | - netcat |
---|
251 | - ghostscript |
---|
252 | |
---|
253 | You need to have the following tools installed on the Quota Storage |
---|
254 | Server : |
---|
255 | |
---|
256 | - PostgreSQL |
---|
257 | |
---|
258 | or |
---|
259 | |
---|
260 | - OpenLDAP |
---|
261 | |
---|
262 | NB : |
---|
263 | |
---|
264 | PygreSQL must be linked with the PostgreSQL client libraries on |
---|
265 | the Print Server. The PostgreSQL client libraries' version must |
---|
266 | match the PostgreSQL version used on the Quota Storage Server. |
---|
267 | BEWARE : under Debian Sarge, as of March 15th 2004, there's a |
---|
268 | problem with python2.2-pygresql and python-2.3-pygresql, so please |
---|
269 | install python2.1-pygresql and use Python 2.1 to install and run |
---|
270 | PyKota. This is not a bug in PyKota, and this should be fixed |
---|
271 | by Debian in a few days I hope. |
---|
272 | |
---|
273 | or |
---|
274 | |
---|
275 | python-ldap must be linked with the OpenLDAP client libraries on the |
---|
276 | Print Server. The OpenLDAP client libraries' version must match the |
---|
277 | OpenLDAP version used on the Quota Storage Server. |
---|
278 | |
---|
279 | This list of prerequisite software may change in the future, when |
---|
280 | PyKota will support more functionnalities you will be given |
---|
281 | alternatives. |
---|
282 | |
---|
283 | Of course the Print Server and the Quota Storage Server can be the |
---|
284 | very same machine if you've got a tiny network, or you can have |
---|
285 | multiple Print Servers all storing their quotas on the same Quota |
---|
286 | Storage Server if you've got a bigger network. |
---|
287 | |
---|
288 | Then : |
---|
289 | ------ |
---|
290 | |
---|
291 | Download the latest PyKota version from the CVS tree on : |
---|
292 | |
---|
293 | http://savannah.nongnu.org/projects/pykota |
---|
294 | |
---|
295 | Just type : |
---|
296 | |
---|
297 | python setup.py install |
---|
298 | |
---|
299 | You may need to be logged in with sufficient privileges (e.g. root) |
---|
300 | |
---|
301 | The installation script will now automatically check if some software |
---|
302 | is missing and ask you if you still want to proceed with the |
---|
303 | installation or abort it completely. |
---|
304 | |
---|
305 | Go to the initscripts subdirectory of PyKota's sources, and choose |
---|
306 | the appropriate storage backend for your configuration. Read |
---|
307 | the associated README file and execute the initialization script |
---|
308 | to create an empty PyKota Storage. Upgrade scripts may be |
---|
309 | provided as well. |
---|
310 | |
---|
311 | Copy the conf/pykota.conf.sample and conf/pykotadmin.conf.sample |
---|
312 | sample configuration files to /etc/pykota/pykota.conf and |
---|
313 | /etc/pykota/pykotadmin.conf. The installation script tries to do |
---|
314 | this for you if needed and you agreed to this action. You need to |
---|
315 | adapt these files to your own needs. Especially you have to create |
---|
316 | sections named after your own printers, and change the |
---|
317 | administrator's email address which by default is root@localhost. |
---|
318 | Read and try to understand these two very well commented files, |
---|
319 | so that you'll encounter less problems later. |
---|
320 | |
---|
321 | Also be sure to double check that commands that query printers |
---|
322 | for their internal page counter work from the command line |
---|
323 | before using them in PyKota's configuration. |
---|
324 | |
---|
325 | The rest of the installation depends on your printing system : |
---|
326 | |
---|
327 | - CUPS Printing System : |
---|
328 | |
---|
329 | Once and for all : |
---|
330 | |
---|
331 | Create a symbolic link to the cupspykota backend |
---|
332 | in CUPS's backend directory : |
---|
333 | |
---|
334 | $ cd /usr/lib/cups/backend |
---|
335 | $ ln -s /usr/share/pykota/cupspykota cupspykota |
---|
336 | |
---|
337 | Restart CUPS so that the new backend can be detected. |
---|
338 | |
---|
339 | $ /etc/init.d/cupsys restart |
---|
340 | |
---|
341 | For new printers : |
---|
342 | |
---|
343 | Go to CUPS management interface (http://localhost:631) |
---|
344 | and choose the appropriate PyKota managed device depending |
---|
345 | on the type of printer you use. For example, if your |
---|
346 | printer is waiting on : |
---|
347 | |
---|
348 | socket://myprinter.example.com:9100 |
---|
349 | |
---|
350 | Then choose : |
---|
351 | |
---|
352 | cupspykota:socket://myprinter.example.com:9100 |
---|
353 | |
---|
354 | Configure your printer as usual. |
---|
355 | |
---|
356 | Now double check /etc/pykota/pykota.conf |
---|
357 | This file should contain a section named after the |
---|
358 | printer you've just added, unless you have set |
---|
359 | all options globally. |
---|
360 | The new pkhint command can help you with correct settings |
---|
361 | for your printers, but don't rely on it because it is still |
---|
362 | incomplete. |
---|
363 | |
---|
364 | That's all. |
---|
365 | |
---|
366 | For existing printers : |
---|
367 | |
---|
368 | If you had already installed a version of PyKota earlier |
---|
369 | than 1.16alpha7, then remove the *cupsFilter lines in your |
---|
370 | PPD files for each printer already managed printers. Each |
---|
371 | line to remove is of the form : |
---|
372 | |
---|
373 | *cupsFilter: "application/vnd.cups-postscript 0 /usr/share/pykota/pykota" |
---|
374 | |
---|
375 | This means that each time the pstops filter will be executed, it will |
---|
376 | pass the job's data through the pykota filter which is present in |
---|
377 | /usr/share/pykota |
---|
378 | |
---|
379 | Don't touch anything else, especially any other *cupsFilter line. |
---|
380 | Then save each of these files. |
---|
381 | |
---|
382 | Then, the easiest is to directly modify the DeviceURI lines |
---|
383 | in /etc/cups/printers.conf, you just have to put |
---|
384 | 'cupspykota:' in front of what is already on these lines. |
---|
385 | For example, replace : |
---|
386 | |
---|
387 | DeviceURI socket://myprinter.example.com:9100 |
---|
388 | |
---|
389 | with : |
---|
390 | |
---|
391 | DeviceURI cupspykota:socket://myprinter.example.com:9100 |
---|
392 | |
---|
393 | or : |
---|
394 | |
---|
395 | DeviceURI cupspykota://socket://myprinter.example.com:9100 |
---|
396 | |
---|
397 | Save the file and restart CUPS. |
---|
398 | |
---|
399 | - LPRng Printing System : |
---|
400 | |
---|
401 | For now LPRng support in PyKota is deactivated. Please be patient. |
---|
402 | |
---|
403 | Now you can begin to populate the PyKota's database with printers, |
---|
404 | users and groups : |
---|
405 | |
---|
406 | Add printers and users to the quota system and set their quota values : |
---|
407 | |
---|
408 | Starting from version 1.18alpha2, the preferred command to manage |
---|
409 | printers is named pkprinters |
---|
410 | |
---|
411 | $ pkprinters --help |
---|
412 | |
---|
413 | will tell you how to create, manage or delete printers and |
---|
414 | printers groups. |
---|
415 | |
---|
416 | $ pkprinters --add --charge 0.05 hp2100 |
---|
417 | |
---|
418 | would add the printer named hp2100 with a price per page |
---|
419 | of 0.05 unit. |
---|
420 | |
---|
421 | Now set quotas for users on this printer : |
---|
422 | |
---|
423 | $ edpykota --add -P hp2100 -S 40 -H 50 user1 ... userN |
---|
424 | |
---|
425 | launching edpykota without any argument or with the --help |
---|
426 | command line option will show you all the possibilities. |
---|
427 | |
---|
428 | by default, each user is limited by "quota", this means that on |
---|
429 | each printer he can have a different soft and hard limit. |
---|
430 | You may want to limit the user by his account balance value, |
---|
431 | in which case, the print quota is shared between all printers |
---|
432 | instead of being different. To do this, use the following : |
---|
433 | |
---|
434 | $ edpykota --add -P hp2100 --limitby balance --balance 10 user1 ... userN |
---|
435 | |
---|
436 | This will put 10 $ (or Euros, PyKota doesn't care) on each user's account |
---|
437 | balance, and tell PyKota to limit them by their account balance value. |
---|
438 | Whenever they print on any printer, their account balance value is |
---|
439 | decreased by an amount which depends on the particular price per page |
---|
440 | and per job that you may have defined on the printer with edpykota's |
---|
441 | --charge command line option. |
---|
442 | Soft and Hard limits are not used if "--limitby balance" is used, |
---|
443 | but you can define a "poorman"'s threshold in /etc/pykota/pykota.conf |
---|
444 | to obtain a similar result (warning message when quota is low). |
---|
445 | |
---|
446 | Restart CUPS or LPRng, for example under Debian GNU/Linux systems : |
---|
447 | |
---|
448 | $ /etc/init.d/cupsys restart |
---|
449 | |
---|
450 | or : |
---|
451 | |
---|
452 | $ /etc/init.d/lprng restart |
---|
453 | |
---|
454 | Your users now should be able to print but not exceed their |
---|
455 | printing quota. |
---|
456 | |
---|
457 | To see printer quota usage, you can use : |
---|
458 | |
---|
459 | $ repykota --printer lp |
---|
460 | |
---|
461 | or : |
---|
462 | |
---|
463 | $ repykota |
---|
464 | |
---|
465 | which will print quota usage for all users on all printers, |
---|
466 | along with totals, if you are the root user. If you are |
---|
467 | a regular user, only your own quota report will be produced. |
---|
468 | |
---|
469 | Quota reports are also available remotely by using the CGI script |
---|
470 | printquota.cgi provided in the cgi-bin/ subdirectory. You can |
---|
471 | also use the CSS stylesheet present in the stylesheets/ subdirectory |
---|
472 | and put it at your web server's DocumentRoot, to benefit from a nicer |
---|
473 | look, especially quota violations will appear in different colors. |
---|
474 | |
---|
475 | For different security concerns, please give a look at the SECURITY |
---|
476 | file which is part of this software. |
---|
477 | |
---|
478 | ============================================================ |
---|
479 | |
---|
480 | Mailing list : |
---|
481 | -------------- |
---|
482 | |
---|
483 | A mailing list is dedicated to Pykota, you can subscribe to it |
---|
484 | or consult its archives at : |
---|
485 | |
---|
486 | http://cgi.librelogiciel.com/mailman/listinfo/pykota |
---|
487 | |
---|
488 | IRC : |
---|
489 | ----- |
---|
490 | |
---|
491 | You can also chat with us : |
---|
492 | |
---|
493 | /server irc.freenode.net |
---|
494 | /join #pykota |
---|
495 | |
---|
496 | ============================================================ |
---|
497 | |
---|
498 | Please e-mail bugs to the mailing list at : pykota@librelogiciel.com |
---|
499 | or to the main author at : alet@librelogiciel.com (Jerome Alet) |
---|