source: apps/routerconsole/jsp/viewstat.jsp @ 35c9e99

Last change on this file since 35c9e99 was 35c9e99, checked in by zzz <zzz@…>, 11 years ago
  • Throw 403 instead of 404 from flags.jsp and viewstat.jsp so we don't render error.jsp
  • Property mode set to 100644
File size: 3.2 KB
Line 
1<%
2/*
3 * USE CAUTION WHEN EDITING
4 * Trailing whitespace OR NEWLINE on the last line will cause
5 * IllegalStateExceptions !!!
6 */
7
8boolean rendered = false;
9String templateFile = request.getParameter("template");
10if (templateFile != null) {
11  java.io.OutputStream cout = response.getOutputStream();
12  response.setContentType("image/png");
13  rendered = net.i2p.router.web.StatSummarizer.instance().renderPng(cout, templateFile);
14}
15net.i2p.stat.Rate rate = null;
16String stat = request.getParameter("stat");
17String period = request.getParameter("period");
18boolean fakeBw = (stat != null && ("bw.combined".equals(stat)));
19net.i2p.stat.RateStat rs = net.i2p.I2PAppContext.getGlobalContext().statManager().getRate(stat);
20if ( !rendered && ((rs != null) || fakeBw) ) {
21  long per = -1;
22  try {
23    if (fakeBw)
24      per = 60*1000;
25    else
26      per = Long.parseLong(period);
27    if (!fakeBw)
28      rate = rs.getRate(per);
29    if ( (rate != null) || (fakeBw) ) {
30      java.io.OutputStream cout = response.getOutputStream();
31      String format = request.getParameter("format");
32      if ("xml".equals(format)) {
33        if (!fakeBw) {
34          response.setContentType("text/xml");
35          rendered = net.i2p.router.web.StatSummarizer.instance().getXML(rate, cout);
36        }
37      } else {
38        response.setContentType("image/png");
39        int width = -1;
40        int height = -1;
41        int periodCount = -1;
42        String str = request.getParameter("width");
43        if (str != null) try { width = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
44        str = request.getParameter("height");
45        if (str != null) try { height = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
46        str = request.getParameter("periodCount");
47        if (str != null) try { periodCount = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
48        boolean hideLegend = Boolean.valueOf(""+request.getParameter("hideLegend")).booleanValue();
49        boolean hideGrid = Boolean.valueOf(""+request.getParameter("hideGrid")).booleanValue();
50        boolean hideTitle = Boolean.valueOf(""+request.getParameter("hideTitle")).booleanValue();
51        boolean showEvents = Boolean.valueOf(""+request.getParameter("showEvents")).booleanValue();
52        boolean showCredit = true;
53        if (request.getParameter("showCredit") != null)
54          showCredit = Boolean.valueOf(""+request.getParameter("showCredit")).booleanValue();
55        if (fakeBw)
56            rendered = net.i2p.router.web.StatSummarizer.instance().renderRatePng(cout, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount, showCredit);
57        else
58            rendered = net.i2p.router.web.StatSummarizer.instance().renderPng(rate, cout, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount, showCredit);
59      }
60      if (rendered)
61        cout.close();
62      //System.out.println("Rendered period " + per + " for the stat " + stat + "? " + rendered);
63    }
64  } catch (NumberFormatException nfe) {}
65}
66/*
67 *  Send a 403 instead of a 404, because the server sends error.jsp
68 *  for 404 errors, complete with the summary bar, which would be
69 *  a huge load for a page full of graphs if there's a problem
70 */
71if (!rendered) {
72  response.sendError(403, "That stat is not available");
73}
74%>
Note: See TracBrowser for help on using the repository browser.