Changeset 3413 for pykota/trunk/cgi-bin
- Timestamp:
- 09/27/08 22:02:37 (16 years ago)
- Location:
- pykota/trunk/cgi-bin
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/cgi-bin/dumpykota.cgi
r3411 r3413 11 11 # the Free Software Foundation, either version 3 of the License, or 12 12 # (at your option) any later version. 13 # 13 # 14 14 # This program is distributed in the hope that it will be useful, 15 15 # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 17 # GNU General Public License for more details. 18 # 18 # 19 19 # You should have received a copy of the GNU General Public License 20 20 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 42 42 <script type="text/javascript"> 43 43 <!-- 44 function checkvalues() 44 function checkvalues() 45 45 { 46 46 if ((document.mainform.format.value == "cups") && (document.mainform.datatype.value != "history")) … … 49 49 return false; 50 50 } 51 51 52 52 if (document.mainform.sum.checked && (document.mainform.datatype.value != "payments") && (document.mainform.datatype.value != "history")) 53 53 { … … 55 55 return false; 56 56 } 57 57 58 58 if (document.mainform.sum.checked && (document.mainform.format.value == "cups")) 59 59 { … … 61 61 return false; 62 62 } 63 63 64 64 return true; 65 65 } … … 92 92 %s 93 93 </p>""" 94 94 95 95 footer = """ 96 96 <table> … … 100 100 </td> 101 101 </tr> 102 </table> 102 </table> 103 103 </form> 104 </p> 104 </p> 105 105 <hr width="25%%" /> 106 106 <p> 107 107 <font size="-2"> 108 108 <a href="http://www.pykota.com/">%s</a> 109 © %s %s 109 © %s %s 110 110 <br /> 111 111 <pre> … … 115 115 </p> 116 116 </body> 117 </html>""" 117 </html>""" 118 118 119 119 class PyKotaDumperGUI(DumPyKota) : … … 137 137 content.append(u"<br />") 138 138 content.append(self.htmlSumCheckbox(self.options.sum)) 139 content.append(footer % (_("Dump"), 140 version.__doc__, 141 version.__years__, 142 version.__author__, 139 content.append(footer % (_("Dump"), 140 version.__doc__, 141 version.__years__, 142 version.__author__, 143 143 saxutils.escape(version.__gplblurb__))) 144 144 for c in content : 145 145 sys.stdout.write(c.encode(self.charset, "replace")) 146 146 sys.stdout.flush() 147 148 def htmlListDataTypes(self, selected="") : 147 148 def htmlListDataTypes(self, selected="") : 149 149 """Displays the datatype selection list.""" 150 150 message = '<table><tr><td valign="top">%s :</td><td valign="top"><select name="datatype">' % _("Data Type") … … 156 156 message += '</select></td></tr></table>' 157 157 return message 158 159 def htmlListFormats(self, selected="") : 158 159 def htmlListFormats(self, selected="") : 160 160 """Displays the formats selection list.""" 161 161 message = '<table><tr><td valign="top">%s :</td><td valign="top"><select name="format">' % _("Output Format") … … 167 167 message += '</select></td></tr></table>' 168 168 return message 169 170 def htmlFilterInput(self, value="") : 169 170 def htmlFilterInput(self, value="") : 171 171 """Input the optional dump filter.""" 172 172 return _("Filter") + (' : <input type="text" name="filter" size="40" value="%s" /> <em>e.g. <strong>username=jerome printername=HP2100 start=today-30</strong></em>' % (value or "")) 173 174 def htmlOrderbyInput(self, value="") : 173 174 def htmlOrderbyInput(self, value="") : 175 175 """Input the optional ordering.""" 176 176 return _("Ordering") + (' : <input type="text" name="orderby" size="40" value="%s" /> <em>e.g. <strong>+username,-printername</strong></em>' % (value or "")) 177 178 def htmlSumCheckbox(self, checked="") : 177 178 def htmlSumCheckbox(self, checked="") : 179 179 """Input the optional Sum option.""" 180 180 return _("Summarize") + (' : <input type="checkbox" name="sum" %s /> <em>%s</em>' % ((checked and 'checked="checked"'), _("only for payments or history"))) 181 181 182 182 def guiAction(self) : 183 183 """Main function""" 184 184 try : 185 185 wantreport = self.form.has_key("report") 186 except TypeError : 186 except TypeError : 187 187 pass # WebDAV request probably, seen when trying to open a csv file in OOo 188 else : 188 else : 189 189 if wantreport : 190 190 try : … … 193 193 if self.form.has_key("format") : 194 194 self.options.format = self.form["format"].value 195 if self.form.has_key("filter") : 195 if self.form.has_key("filter") : 196 196 self.arguments = self.form["filter"].value.split() 197 if self.form.has_key("sum") : 197 if self.form.has_key("sum") : 198 198 self.options.sum = self.form["sum"].value 199 if self.form.has_key("orderby") : 199 if self.form.has_key("orderby") : 200 200 self.options.orderby = self.form["orderby"].value 201 # when no authentication is done, or when the remote username 201 # when no authentication is done, or when the remote username 202 202 # is 'root' (even if not run as root of course), then unrestricted 203 203 # dump is allowed. 204 remuser = os.environ.get("REMOTE_USER", "root") 204 remuser = os.environ.get("REMOTE_USER", "root") 205 205 # special hack to accomodate mod_auth_ldap Apache module 206 206 try : 207 207 remuser = remuser.split("=")[1].split(",")[0] 208 except IndexError : 208 except IndexError : 209 209 pass 210 210 if remuser != "root" : … … 214 214 if self.options.data not in ["printers", "pmembers", "groups", "gpquotas"] : 215 215 self.arguments.append("username=%s" % remuser) 216 217 fname = "error" 216 217 fname = "error" 218 218 ctype = "text/plain" 219 219 if self.options.format in ("csv", "ssv") : … … 231 231 ctype = "text/plain" 232 232 fname = "page_log" 233 print "Content-type: %s" % ctype 234 print "Content-disposition: attachment; filename=%s" % fname 233 print "Content-type: %s" % ctype 234 print "Content-disposition: attachment; filename=%s" % fname 235 235 print 236 236 self.main(self.arguments, self.options, restricted=0) 237 237 except : 238 238 print 'Content-type: text/html\n\n<html><head><title>CGI Error</title></head><body><p><font color="red">%s</font></p></body></html>' % self.crashed("CGI Error").replace("\n", "<br />") 239 else : 239 else : 240 240 self.guiDisplay() 241 242 class FakeCommandLineOptions : 241 242 class FakeCommandLineOptions : 243 243 """A class to fake command line options.""" 244 244 output = "-" … … 247 247 sum = None 248 248 orderby = None 249 249 250 250 if __name__ == "__main__" : 251 251 utils.reinitcgilocale() … … 258 258 try : 259 259 admin.storage.close() 260 except (TypeError, NameError, AttributeError) : 260 except (TypeError, NameError, AttributeError) : 261 261 pass 262 262 263 263 sys.exit(0) -
pykota/trunk/cgi-bin/printquota.cgi
r3411 r3413 11 11 # the Free Software Foundation, either version 3 of the License, or 12 12 # (at your option) any later version. 13 # 13 # 14 14 # This program is distributed in the hope that it will be useful, 15 15 # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 17 # GNU General Public License for more details. 18 # 18 # 19 19 # You should have received a copy of the GNU General Public License 20 20 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 68 68 </tr> 69 69 </table>""" 70 70 71 71 footer = """ 72 72 <table> … … 76 76 </td> 77 77 </tr> 78 </table> 78 </table> 79 79 </form> 80 80 </p> … … 83 83 <font size="-2"> 84 84 <a href="http://www.pykota.com/">%s</a> 85 © %s %s 85 © %s %s 86 86 <br /> 87 87 <pre> … … 91 91 </p> 92 92 </body> 93 </html>""" 93 </html>""" 94 94 95 95 class PyKotaReportGUI(PyKotaTool) : … … 104 104 version.__version__, _("PyKota Reports"), \ 105 105 _("Report")) ] 106 content.append(self.body) 107 content.append(footer % (_("Report"), 108 version.__doc__, 109 version.__years__, 110 version.__author__, 106 content.append(self.body) 107 content.append(footer % (_("Report"), 108 version.__doc__, 109 version.__years__, 110 version.__author__, 111 111 saxutils.escape(version.__gplblurb__))) 112 112 for c in content : 113 113 sys.stdout.write(c.encode(self.charset, "replace")) 114 114 sys.stdout.flush() 115 115 116 116 def error(self, message) : 117 117 """Adds an error message to the GUI's body.""" 118 118 if message : 119 119 self.body = '<p><font color="red">%s</font></p>\n%s' % (message, self.body) 120 121 def htmlListPrinters(self, selected=[], mask="*") : 120 121 def htmlListPrinters(self, selected=[], mask="*") : 122 122 """Displays the printers multiple selection list.""" 123 123 printers = self.storage.getMatchingPrinters(mask) … … 131 131 message += '</select></td></tr></table>' 132 132 return message 133 134 def htmlUGNamesInput(self, value="*") : 133 134 def htmlUGNamesInput(self, value="*") : 135 135 """Input field for user/group names wildcard.""" 136 136 return _("User / Group names mask") + (' : <input type="text" name="ugmask" size="20" value="%s" /> <em>e.g. <strong>jo*</strong></em>' % (value or "*")) 137 137 138 138 def htmlGroupsCheckbox(self, isgroup=0) : 139 139 """Groups checkbox.""" 140 140 if isgroup : 141 141 return _("Groups report") + ' : <input type="checkbox" checked="checked" name="isgroup" />' 142 else : 142 else : 143 143 return _("Groups report") + ' : <input type="checkbox" name="isgroup" />' 144 144 145 145 def guiAction(self) : 146 146 """Main function""" 147 147 printers = ugmask = isgroup = None 148 remuser = os.environ.get("REMOTE_USER", "root") 148 remuser = os.environ.get("REMOTE_USER", "root") 149 149 # special hack to accomodate mod_auth_ldap Apache module 150 150 try : 151 151 remuser = remuser.split("=")[1].split(",")[0] 152 except IndexError : 152 except IndexError : 153 153 pass 154 154 self.body = "<p>%s</p>\n" % _("Please click on the above button") … … 159 159 printersfield = [ printersfield ] 160 160 printers = [self.storage.getPrinter(p.value) for p in printersfield] 161 else : 161 else : 162 162 printers = self.storage.getMatchingPrinters("*") 163 163 if remuser == "root" : 164 if self.form.has_key("ugmask") : 164 if self.form.has_key("ugmask") : 165 165 ugmask = self.form["ugmask"].value 166 else : 166 else : 167 167 ugmask = "*" 168 else : 169 if self.form.has_key("isgroup") : 168 else : 169 if self.form.has_key("isgroup") : 170 170 user = self.storage.getUser(remuser) 171 171 if user.Exists : 172 172 ugmask = " ".join([ g.Name for g in self.storage.getUserGroups(user) ]) 173 else : 173 else : 174 174 ugmask = remuser # result will probably be empty, we don't care 175 else : 175 else : 176 176 ugmask = remuser 177 if self.form.has_key("isgroup") : 177 if self.form.has_key("isgroup") : 178 178 isgroup = 1 179 else : 179 else : 180 180 isgroup = 0 181 self.body += self.htmlListPrinters(printers or []) 181 self.body += self.htmlListPrinters(printers or []) 182 182 self.body += "<br />" 183 183 self.body += self.htmlUGNamesInput(ugmask) … … 189 189 self.reportingtool = openReporter(admin, "html", printers, ugmask.split(), isgroup) 190 190 self.body += "%s" % self.reportingtool.generateReport() 191 else : 191 else : 192 192 if remuser != "root" : 193 193 username = remuser 194 elif self.form.has_key("username") : 194 elif self.form.has_key("username") : 195 195 username = self.form["username"].value 196 else : 196 else : 197 197 username = None 198 if username is not None : 198 if username is not None : 199 199 user = self.storage.getUser(username) 200 else : 200 else : 201 201 user = None 202 202 if self.form.has_key("printername") : 203 203 printer = self.storage.getPrinter(self.form["printername"].value) 204 else : 204 else : 205 205 printer = None 206 if self.form.has_key("datelimit") : 206 if self.form.has_key("datelimit") : 207 207 datelimit = self.form["datelimit"].value 208 else : 208 else : 209 209 datelimit = None 210 if self.form.has_key("hostname") : 210 if self.form.has_key("hostname") : 211 211 hostname = self.form["hostname"].value 212 else : 212 else : 213 213 hostname = None 214 if self.form.has_key("billingcode") : 214 if self.form.has_key("billingcode") : 215 215 billingcode = self.form["billingcode"].value 216 else : 216 else : 217 217 billingcode = None 218 self.report = ["<h2>%s</h2>" % _("History")] 218 self.report = ["<h2>%s</h2>" % _("History")] 219 219 history = self.storage.retrieveHistory(user=user, printer=printer, hostname=hostname, billingcode=billingcode, end=datelimit) 220 220 if not history : … … 232 232 for job in history : 233 233 oddeven += 1 234 if job.JobAction == "ALLOW" : 234 if job.JobAction == "ALLOW" : 235 235 if oddeven % 2 : 236 236 oddevenclass = "odd" 237 else : 237 else : 238 238 oddevenclass = "even" 239 239 else : … … 243 243 if job.JobHostName : 244 244 hostname_url = '<a href="%s?%s">%s</a>' % (os.environ.get("SCRIPT_NAME", ""), urllib.urlencode({"history" : 1, "hostname" : job.JobHostName}), job.JobHostName) 245 else : 245 else : 246 246 hostname_url = None 247 247 if job.JobBillingCode : 248 248 billingcode_url = '<a href="%s?%s">%s</a>' % (os.environ.get("SCRIPT_NAME", ""), urllib.urlencode({"history" : 1, "billingcode" : job.JobBillingCode}), job.JobBillingCode) 249 else : 249 else : 250 250 billingcode_url = None 251 251 curdate = DateTime.ISO.ParseDateTime(str(job.JobDate)[:19]) … … 286 286 if printer and printer.Exists : 287 287 dico.update({ "printername" : printer.Name }) 288 if hostname : 288 if hostname : 289 289 dico.update({ "hostname" : hostname }) 290 290 prevurl = "%s?%s" % (os.environ.get("SCRIPT_NAME", ""), urllib.urlencode(dico)) 291 291 self.report.append('<a href="%s">%s</a>' % (prevurl, _("Previous page"))) 292 self.body = "\n".join(self.report) 292 self.body = "\n".join(self.report) 293 293 except : 294 294 self.body += '<p><font color="red">%s</font></p>' % self.crashed("CGI Error").replace("\n", "<br />") 295 295 296 296 if __name__ == "__main__" : 297 297 utils.reinitcgilocale() … … 303 303 try : 304 304 admin.storage.close() 305 except (TypeError, NameError, AttributeError) : 305 except (TypeError, NameError, AttributeError) : 306 306 pass 307 307 308 308 sys.exit(0) -
pykota/trunk/cgi-bin/pykotme.cgi
r3411 r3413 11 11 # the Free Software Foundation, either version 3 of the License, or 12 12 # (at your option) any later version. 13 # 13 # 14 14 # This program is distributed in the hope that it will be useful, 15 15 # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 17 # GNU General Public License for more details. 18 # 18 # 19 19 # You should have received a copy of the GNU General Public License 20 20 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 38 38 39 39 from pkpgpdls import analyzer, pdlparser 40 40 41 41 42 42 header = """Content-type: text/html;charset=%s … … 69 69 </tr> 70 70 </table>""" 71 71 72 72 footer = """ 73 73 <table> … … 77 77 </td> 78 78 </tr> 79 </table> 79 </table> 80 80 </form> 81 81 </p> … … 84 84 <font size="-2"> 85 85 <a href="http://www.pykota.com/">%s</a> 86 © %s %s 86 © %s %s 87 87 <br /> 88 88 <pre> … … 92 92 </p> 93 93 </body> 94 </html>""" 94 </html>""" 95 95 96 96 class PyKotMeGUI(PyKotaTool) : … … 106 106 _("Quote")) ] 107 107 content.append(self.body) 108 content.append(footer % (_("Quote"), 109 version.__doc__, 110 version.__years__, 111 version.__author__, 108 content.append(footer % (_("Quote"), 109 version.__doc__, 110 version.__years__, 111 version.__author__, 112 112 saxutils.escape(version.__gplblurb__))) 113 113 for c in content : 114 114 sys.stdout.write(c.encode(self.charset, "replace")) 115 115 sys.stdout.flush() 116 116 117 117 def error(self, message) : 118 118 """Adds an error message to the GUI's body.""" 119 119 if message : 120 120 self.body = '<p><font color="red">%s</font></p>\n%s' % (message, self.body) 121 122 def htmlListPrinters(self, selected=[], mask="*") : 121 122 def htmlListPrinters(self, selected=[], mask="*") : 123 123 """Displays the printers multiple selection list.""" 124 124 printers = self.storage.getMatchingPrinters(mask) … … 132 132 message += '</select></td></tr></table>' 133 133 return message 134 134 135 135 def guiAction(self) : 136 136 """Main function""" … … 143 143 printersfield = [ printersfield ] 144 144 printers = [self.storage.getPrinter(p.value) for p in printersfield] 145 else : 145 else : 146 146 printers = self.storage.getMatchingPrinters("*") 147 if self.form.has_key("inputfile") : 147 if self.form.has_key("inputfile") : 148 148 inputfile = self.form["inputfile"].value 149 150 if os.environ.get("REMOTE_USER") is not None : 151 self.body += self.htmlListPrinters(printers or []) 149 150 if os.environ.get("REMOTE_USER") is not None : 151 self.body += self.htmlListPrinters(printers or []) 152 152 self.body += "<br />" 153 153 self.body += _("Filename") + " : " … … 158 158 parser = analyzer.PDLAnalyzer(cStringIO.StringIO(inputfile)) 159 159 jobsize = parser.getJobSize() 160 except pdlparser.PDLParserError, msg : 160 except pdlparser.PDLParserError, msg : 161 161 self.body += '<p><font color="red">%s</font></p>' % msg 162 162 jobsize = 0 # unknown file format ? 163 else : 163 else : 164 164 self.body += "<p>%s</p>" % (_("Job size : %i pages") % jobsize) 165 165 166 166 remuser = os.environ.get("REMOTE_USER") 167 167 # special hack to accomodate mod_auth_ldap Apache module 168 168 try : 169 169 remuser = remuser.split("=")[1].split(",")[0] 170 except : 170 except : 171 171 pass 172 if not remuser : 172 if not remuser : 173 173 self.body += "<p>%s</p>" % _("The exact cost of a print job can only be determined for a particular user. Please retry while logged-in.") 174 else : 175 try : 174 else : 175 try : 176 176 user = self.storage.getUser(remuser) 177 177 if user.Exists : 178 178 if user.LimitBy == "noprint" : 179 179 self.body += "<p>%s</p>" % _("Your account settings forbid you to print at this time.") 180 else : 180 else : 181 181 for printer in printers : 182 182 upquota = self.storage.getUserPQuota(user, printer) … … 184 184 if printer.MaxJobSize and (jobsize > printer.MaxJobSize) : 185 185 msg = _("You are not allowed to print so many pages on printer %s at this time.") % printer.Name 186 else : 186 else : 187 187 cost = upquota.computeJobPrice(jobsize) 188 188 msg = _("Cost on printer %s : %.2f") % (printer.Name, cost) 189 189 if printer.PassThrough : 190 190 msg = "%s (%s)" % (msg, _("won't be charged, printer is in passthrough mode")) 191 elif user.LimitBy == "nochange" : 191 elif user.LimitBy == "nochange" : 192 192 msg = "%s (%s)" % (msg, _("won't be charged, your account is immutable")) 193 193 self.body += "<p>%s</p>" % msg 194 194 except : 195 195 self.body += '<p><font color="red">%s</font></p>' % self.crashed("CGI Error").replace("\n", "<br />") 196 196 197 197 if __name__ == "__main__" : 198 198 utils.reinitcgilocale() … … 204 204 try : 205 205 admin.storage.close() 206 except (TypeError, NameError, AttributeError) : 206 except (TypeError, NameError, AttributeError) : 207 207 pass 208 208 209 209 sys.exit(0) -
pykota/trunk/cgi-bin/README
r3275 r3413 24 24 Be sure to restrict access to these CGI scripts as necessary. 25 25 26 If you protect access to printquota.cgi or dumpykota.cgi with 26 If you protect access to printquota.cgi or dumpykota.cgi with 27 27 username+password authentication, the REMOTE_USER CGI environment variable 28 28 is honored, so an user can only see his own datas, but not … … 36 36 authentication, then only the job's size will be displayed 37 37 to you. This is due to the cost of a print job on a particular printer 38 depending on the user because of the overcharging factor's value. 39 So if you want pykotme.cgi to produce complete web quotes, you must 40 ensure that the user logs in from his web browser whenever he uses 38 depending on the user because of the overcharging factor's value. 39 So if you want pykotme.cgi to produce complete web quotes, you must 40 ensure that the user logs in from his web browser whenever he uses 41 41 this CGI script. 42 42 … … 45 45 PyKota's pykotadmin.conf configuration file is necessary though. 46 46 47 The web server doesn't need to be a print server nor a PyKota 48 Storage Backend server, but it must contain a correctly configured 49 PyKota installation. 47 The web server doesn't need to be a print server nor a PyKota 48 Storage Backend server, but it must contain a correctly configured 49 PyKota installation. 50 50 51 51 ====================================================================