Changeset 3413 for pykota/trunk/cgi-bin/dumpykota.cgi
- Timestamp:
- 09/27/08 22:02:37 (16 years ago)
- Files:
-
- 1 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)