Index: /pykota/trunk/setup.py
===================================================================
--- /pykota/trunk/setup.py (revision 1952)
+++ /pykota/trunk/setup.py (revision 2019)
@@ -24,4 +24,9 @@
 #
 # $Log$
+# Revision 1.61  2005/01/08 19:13:11  jalet
+# dumpykota.cgi was added to allow the use of dumpykota through the web.
+# This makes real time interfacing with the third party software phpPrintAnalyzer
+# a breeze !
+#
 # Revision 1.60  2004/11/21 21:50:02  jalet
 # Introduced the new pkmail command as a simple email gateway
@@ -290,5 +295,5 @@
 data_files.append((os.sep.join([directory, "conf"]), ["conf/README", "conf/pykota.conf.sample", "conf/pykotadmin.conf.sample"]))
 
-data_files.append((os.sep.join([directory, "cgi-bin"]), ["cgi-bin/README", "cgi-bin/printquota.cgi"]))
+data_files.append((os.sep.join([directory, "cgi-bin"]), ["cgi-bin/README", "cgi-bin/printquota.cgi", "cgi-bin/dumpykota.cgi"]))
 
 data_files.append((os.sep.join([directory, "logos"]), glob.glob(os.sep.join(["logos", "*.jpeg"])) + glob.glob(os.sep.join(["logos", "*.png"])) + glob.glob(os.sep.join(["logos", "*.xcf"]))))
Index: /pykota/trunk/cgi-bin/README
===================================================================
--- /pykota/trunk/cgi-bin/README (revision 1266)
+++ /pykota/trunk/cgi-bin/README (revision 2019)
@@ -24,4 +24,5 @@
 
 Be sure to restrict access to these CGI scripts as necessary.
+
 If you protect access to printquota.cgi with user+password
 authentication, the REMOTE_USER CGI environment variable
@@ -29,4 +30,20 @@
 not other users' quota.
 
+To make dumpykota.cgi work, you have to ensure that your web server 
+runs it as a PyKota administrator. This means that dumpykota.cgi 
+when run must be able to read the pykotadmin.conf file. There are 
+several ways to do so, one of them is to put the user your web 
+server normally runs as into the pykota group (which must be allowed 
+to read pykotadmin.conf), then restart your web server :
+            
+            $ adduser www-data pykota
+            $ /etc/init.d/apache restart
+            
+This is probably not the safest way though, so you may want to            
+restrict access further with an username and password, or use
+Apache's suExec mechanism to directly run this particular 
+script as the pykota system user. Please refer to your web
+server's documentation for details.
+        
 The web server doesn't need to be a print server nor a PyKota 
 Storage Backend server, but it must contain a correctly configured 
Index: /pykota/trunk/cgi-bin/dumpykota.cgi
===================================================================
--- /pykota/trunk/cgi-bin/dumpykota.cgi (revision 2019)
+++ /pykota/trunk/cgi-bin/dumpykota.cgi (revision 2019)
@@ -0,0 +1,181 @@
+#! /usr/bin/python
+# -*- coding: ISO-8859-15 -*-
+
+# PyKota Print Quota Reports generator
+#
+# PyKota - Print Quotas for CUPS and LPRng
+#
+# (c) 2003-2004 Jerome Alet <alet@librelogiciel.com>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+#
+# $Log$
+# Revision 1.1  2005/01/08 19:13:11  jalet
+# dumpykota.cgi was added to allow the use of dumpykota through the web.
+# This makes real time interfacing with the third party software phpPrintAnalyzer
+# a breeze !
+#
+#
+
+import sys
+import os
+import cgi
+import urllib
+
+from pykota import version
+from pykota.tool import PyKotaToolError
+from pykota.dumper import DumPyKota
+from pykota.cgifuncs import getLanguagePreference, getCharsetPreference
+
+header = """Content-type: text/html
+
+<?xml version="1.0" encoding="%s"?>
+<html>
+  <head>
+    <title>%s</title>
+    <link rel="stylesheet" type="text/css" href="/pykota.css" />
+  </head>
+  <body>
+    <form action="dumpykota.cgi" method="GET">
+      <table>
+        <tr>
+          <td>
+            <p>
+              <a href="http://www.librelogiciel.com/software/"><img src="http://www.librelogiciel.com/software/PyKota/pykota.png" alt="PyKota's Logo" /></a>
+              <br />
+              <a href="http://www.librelogiciel.com/software/">PyKota v%s</a>
+            </p>
+          </td>
+          <td colspan="2">
+            <h1>%s</h1>
+          </td>
+        </tr>
+        <tr>
+          <td colspan="3" align="center">
+            <input type="submit" name="report" value="%s" />
+          </td>
+        </tr>
+      </table>
+      <p>
+        %s
+      </p>"""
+    
+footer = """
+      <table>
+        <tr>
+          <td colspan="3" align="center">
+            <input type="submit" name="report" value="%s" />
+          </td>
+        </tr>
+      </table>  
+    </form>
+  </body>
+</html>"""  
+
+class PyKotaDumperGUI(DumPyKota) :
+    """PyKota Dumper GUI"""
+    def guiDisplay(self) :
+        """Displays the dumper interface."""
+        global header, footer
+        print header % (self.getCharset(), _("PyKota Data Dumper"), version.__version__, _("PyKota Data Dumper"), _("Dump"), _("Please click on the above button"))
+        print self.htmlListDataTypes(self.options.get("datatype", "")) 
+        print "<br />"
+        print self.htmlListFormats(self.options.get("format", ""))
+        print "<br />"
+        print self.htmlFilterInput(" ".join(self.arguments))
+        print footer % _("Dump")
+        
+    def htmlListDataTypes(self, selected="") :    
+        """Displays the datatype selection list."""
+        message = '<table><tr><td valign="top">%s :</td><td valign="top"><select name="datatype">' % _("Data Type")
+        for dt in self.validdatatypes.items() :
+            if dt[0] == selected :
+                message += '<option value="%s" selected="selected">%s (%s)</option>' % (dt[0], dt[0], dt[1])
+            else :
+                message += '<option value="%s">%s (%s)</option>' % (dt[0], dt[0], dt[1])
+        message += '</select></td></tr></table>'
+        return message
+        
+    def htmlListFormats(self, selected="") :    
+        """Displays the formats selection list."""
+        message = '<table><tr><td valign="top">%s :</td><td valign="top"><select name="format">' % _("Output Format")
+        for fmt in self.validformats.items() :
+            if fmt[0] == selected :
+                message += '<option value="%s" selected="selected">%s (%s)</option>' % (fmt[0], fmt[0], fmt[1])
+            else :
+                message += '<option value="%s">%s (%s)</option>' % (fmt[0], fmt[0], fmt[1])
+        message += '</select></td></tr></table>'
+        return message
+        
+    def htmlFilterInput(self, value="") :    
+        """Input the optional dump filter."""
+        return _("Filter") + (' : <input type="text" name="filter" size="40" value="%s" /> <em>e.g. <strong>username=jerome printername=HP2100</strong></em>' % (value or ""))
+        
+    def guiAction(self) :
+        """Main function"""
+        try :
+            wantreport = self.form.has_key("report")
+        except TypeError :    
+            pass # WebDAV request probably, seen when trying to open a csv file in OOo
+        else :    
+            if wantreport :
+                if self.form.has_key("datatype") :
+                    self.options["data"] = self.form["datatype"].value
+                if self.form.has_key("format") :
+                    self.options["format"] = self.form["format"].value
+                if self.form.has_key("filter") :    
+                    self.arguments = self.form["filter"].value.split()
+                    
+                if self.options["format"] in ("csv", "ssv") :
+                    #ctype = "application/vnd.sun.xml.calc"
+                    ctype = "text/comma-separated-values"
+                    fname = "dump.csv"
+                elif self.options["format"] == "tsv" :
+                    #ctype = "application/vnd.sun.xml.calc"
+                    ctype = "text/tab-separated-values"
+                    fname = "dump.tsv"
+                elif self.options["format"] == "xml" :
+                    ctype = "text/xml"
+                    fname = "dump.xml"
+                elif self.options["format"] == "cups" :
+                    ctype = "text/plain"
+                    fname = "page_log"
+                print "Content-type: %s" % ctype    
+                print "Content-disposition: inline; attachment=%s" % fname 
+                print
+                try :
+                    self.main(self.arguments, self.options)
+                except PyKotaToolError, msg :    
+                    print msg
+            else :        
+                self.guiDisplay()
+            
+if __name__ == "__main__" :
+    os.environ["LC_ALL"] = getLanguagePreference()
+    admin = PyKotaDumperGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference())
+    admin.form = cgi.FieldStorage()
+    admin.options = { "output" : "-",
+                "data" : "history",
+                "format" : "cups",
+              }
+    admin.arguments = []
+    admin.guiAction()
+    try :
+        admin.storage.close()
+    except (TypeError, NameError, AttributeError) :    
+        pass
+        
+    sys.exit(0)
