[2019] | 1 | #! /usr/bin/python |
---|
| 2 | # -*- coding: ISO-8859-15 -*- |
---|
| 3 | |
---|
| 4 | # PyKota Print Quota Reports generator |
---|
| 5 | # |
---|
| 6 | # PyKota - Print Quotas for CUPS and LPRng |
---|
| 7 | # |
---|
| 8 | # (c) 2003-2004 Jerome Alet <alet@librelogiciel.com> |
---|
| 9 | # This program is free software; you can redistribute it and/or modify |
---|
| 10 | # it under the terms of the GNU General Public License as published by |
---|
| 11 | # the Free Software Foundation; either version 2 of the License, or |
---|
| 12 | # (at your option) any later version. |
---|
| 13 | # |
---|
| 14 | # This program is distributed in the hope that it will be useful, |
---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | # GNU General Public License for more details. |
---|
| 18 | # |
---|
| 19 | # You should have received a copy of the GNU General Public License |
---|
| 20 | # along with this program; if not, write to the Free Software |
---|
| 21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
| 22 | # |
---|
| 23 | # $Id$ |
---|
| 24 | # |
---|
| 25 | # $Log$ |
---|
| 26 | # Revision 1.1 2005/01/08 19:13:11 jalet |
---|
| 27 | # dumpykota.cgi was added to allow the use of dumpykota through the web. |
---|
| 28 | # This makes real time interfacing with the third party software phpPrintAnalyzer |
---|
| 29 | # a breeze ! |
---|
| 30 | # |
---|
| 31 | # |
---|
| 32 | |
---|
| 33 | import sys |
---|
| 34 | import os |
---|
| 35 | import cgi |
---|
| 36 | import urllib |
---|
| 37 | |
---|
| 38 | from pykota import version |
---|
| 39 | from pykota.tool import PyKotaToolError |
---|
| 40 | from pykota.dumper import DumPyKota |
---|
| 41 | from pykota.cgifuncs import getLanguagePreference, getCharsetPreference |
---|
| 42 | |
---|
| 43 | header = """Content-type: text/html |
---|
| 44 | |
---|
| 45 | <?xml version="1.0" encoding="%s"?> |
---|
| 46 | <html> |
---|
| 47 | <head> |
---|
| 48 | <title>%s</title> |
---|
| 49 | <link rel="stylesheet" type="text/css" href="/pykota.css" /> |
---|
| 50 | </head> |
---|
| 51 | <body> |
---|
| 52 | <form action="dumpykota.cgi" method="GET"> |
---|
| 53 | <table> |
---|
| 54 | <tr> |
---|
| 55 | <td> |
---|
| 56 | <p> |
---|
| 57 | <a href="http://www.librelogiciel.com/software/"><img src="http://www.librelogiciel.com/software/PyKota/pykota.png" alt="PyKota's Logo" /></a> |
---|
| 58 | <br /> |
---|
| 59 | <a href="http://www.librelogiciel.com/software/">PyKota v%s</a> |
---|
| 60 | </p> |
---|
| 61 | </td> |
---|
| 62 | <td colspan="2"> |
---|
| 63 | <h1>%s</h1> |
---|
| 64 | </td> |
---|
| 65 | </tr> |
---|
| 66 | <tr> |
---|
| 67 | <td colspan="3" align="center"> |
---|
| 68 | <input type="submit" name="report" value="%s" /> |
---|
| 69 | </td> |
---|
| 70 | </tr> |
---|
| 71 | </table> |
---|
| 72 | <p> |
---|
| 73 | %s |
---|
| 74 | </p>""" |
---|
| 75 | |
---|
| 76 | footer = """ |
---|
| 77 | <table> |
---|
| 78 | <tr> |
---|
| 79 | <td colspan="3" align="center"> |
---|
| 80 | <input type="submit" name="report" value="%s" /> |
---|
| 81 | </td> |
---|
| 82 | </tr> |
---|
| 83 | </table> |
---|
| 84 | </form> |
---|
| 85 | </body> |
---|
| 86 | </html>""" |
---|
| 87 | |
---|
| 88 | class PyKotaDumperGUI(DumPyKota) : |
---|
| 89 | """PyKota Dumper GUI""" |
---|
| 90 | def guiDisplay(self) : |
---|
| 91 | """Displays the dumper interface.""" |
---|
| 92 | global header, footer |
---|
| 93 | print header % (self.getCharset(), _("PyKota Data Dumper"), version.__version__, _("PyKota Data Dumper"), _("Dump"), _("Please click on the above button")) |
---|
| 94 | print self.htmlListDataTypes(self.options.get("datatype", "")) |
---|
| 95 | print "<br />" |
---|
| 96 | print self.htmlListFormats(self.options.get("format", "")) |
---|
| 97 | print "<br />" |
---|
| 98 | print self.htmlFilterInput(" ".join(self.arguments)) |
---|
| 99 | print footer % _("Dump") |
---|
| 100 | |
---|
| 101 | def htmlListDataTypes(self, selected="") : |
---|
| 102 | """Displays the datatype selection list.""" |
---|
| 103 | message = '<table><tr><td valign="top">%s :</td><td valign="top"><select name="datatype">' % _("Data Type") |
---|
| 104 | for dt in self.validdatatypes.items() : |
---|
| 105 | if dt[0] == selected : |
---|
| 106 | message += '<option value="%s" selected="selected">%s (%s)</option>' % (dt[0], dt[0], dt[1]) |
---|
| 107 | else : |
---|
| 108 | message += '<option value="%s">%s (%s)</option>' % (dt[0], dt[0], dt[1]) |
---|
| 109 | message += '</select></td></tr></table>' |
---|
| 110 | return message |
---|
| 111 | |
---|
| 112 | def htmlListFormats(self, selected="") : |
---|
| 113 | """Displays the formats selection list.""" |
---|
| 114 | message = '<table><tr><td valign="top">%s :</td><td valign="top"><select name="format">' % _("Output Format") |
---|
| 115 | for fmt in self.validformats.items() : |
---|
| 116 | if fmt[0] == selected : |
---|
| 117 | message += '<option value="%s" selected="selected">%s (%s)</option>' % (fmt[0], fmt[0], fmt[1]) |
---|
| 118 | else : |
---|
| 119 | message += '<option value="%s">%s (%s)</option>' % (fmt[0], fmt[0], fmt[1]) |
---|
| 120 | message += '</select></td></tr></table>' |
---|
| 121 | return message |
---|
| 122 | |
---|
| 123 | def htmlFilterInput(self, value="") : |
---|
| 124 | """Input the optional dump filter.""" |
---|
| 125 | return _("Filter") + (' : <input type="text" name="filter" size="40" value="%s" /> <em>e.g. <strong>username=jerome printername=HP2100</strong></em>' % (value or "")) |
---|
| 126 | |
---|
| 127 | def guiAction(self) : |
---|
| 128 | """Main function""" |
---|
| 129 | try : |
---|
| 130 | wantreport = self.form.has_key("report") |
---|
| 131 | except TypeError : |
---|
| 132 | pass # WebDAV request probably, seen when trying to open a csv file in OOo |
---|
| 133 | else : |
---|
| 134 | if wantreport : |
---|
| 135 | if self.form.has_key("datatype") : |
---|
| 136 | self.options["data"] = self.form["datatype"].value |
---|
| 137 | if self.form.has_key("format") : |
---|
| 138 | self.options["format"] = self.form["format"].value |
---|
| 139 | if self.form.has_key("filter") : |
---|
| 140 | self.arguments = self.form["filter"].value.split() |
---|
| 141 | |
---|
| 142 | if self.options["format"] in ("csv", "ssv") : |
---|
| 143 | #ctype = "application/vnd.sun.xml.calc" |
---|
| 144 | ctype = "text/comma-separated-values" |
---|
| 145 | fname = "dump.csv" |
---|
| 146 | elif self.options["format"] == "tsv" : |
---|
| 147 | #ctype = "application/vnd.sun.xml.calc" |
---|
| 148 | ctype = "text/tab-separated-values" |
---|
| 149 | fname = "dump.tsv" |
---|
| 150 | elif self.options["format"] == "xml" : |
---|
| 151 | ctype = "text/xml" |
---|
| 152 | fname = "dump.xml" |
---|
| 153 | elif self.options["format"] == "cups" : |
---|
| 154 | ctype = "text/plain" |
---|
| 155 | fname = "page_log" |
---|
| 156 | print "Content-type: %s" % ctype |
---|
| 157 | print "Content-disposition: inline; attachment=%s" % fname |
---|
| 158 | print |
---|
| 159 | try : |
---|
| 160 | self.main(self.arguments, self.options) |
---|
| 161 | except PyKotaToolError, msg : |
---|
| 162 | print msg |
---|
| 163 | else : |
---|
| 164 | self.guiDisplay() |
---|
| 165 | |
---|
| 166 | if __name__ == "__main__" : |
---|
| 167 | os.environ["LC_ALL"] = getLanguagePreference() |
---|
| 168 | admin = PyKotaDumperGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference()) |
---|
| 169 | admin.form = cgi.FieldStorage() |
---|
| 170 | admin.options = { "output" : "-", |
---|
| 171 | "data" : "history", |
---|
| 172 | "format" : "cups", |
---|
| 173 | } |
---|
| 174 | admin.arguments = [] |
---|
| 175 | admin.guiAction() |
---|
| 176 | try : |
---|
| 177 | admin.storage.close() |
---|
| 178 | except (TypeError, NameError, AttributeError) : |
---|
| 179 | pass |
---|
| 180 | |
---|
| 181 | sys.exit(0) |
---|