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