Changeset fa6a4ca1 for apps


Ignore:
Timestamp:
Dec 23, 2018 12:19:32 PM (19 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
af49a90
Parents:
e122393
Message:

Console: Convert NetDbHelper? to a FormHandler?,
change SybilRenderer? forms to POST,
only collect RIs on required Sybil tabs

Location:
apps/routerconsole
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/helpers/NetDbHelper.java

    re122393 rfa6a4ca1  
    77import net.i2p.data.DataHelper;
    88import net.i2p.util.SystemVersion;
    9 import net.i2p.router.web.HelperBase;
    10 
    11 public class NetDbHelper extends HelperBase {
     9import net.i2p.router.web.FormHandler;
     10
     11/**
     12 *  /netdb
     13 *  A FormHandler since 0.9.38.
     14 *  Most output is generated in NetDbRenderer and SybilRender.
     15 */
     16public class NetDbHelper extends FormHandler {
    1217    private String _routerPrefix;
    1318    private String _version;
     
    2126    private boolean _graphical;
    2227    private SigType _type;
     28    private String _newNonce;
     29    private boolean _postOK;
    2330
    2431    private static final int DEFAULT_LIMIT = SystemVersion.isARM() ? 250 : 500;
     
    195202        _graphical = true;
    196203    }
     204   
     205    /**
     206     *  Override to save it
     207     *  @since 0.9.38
     208     */
     209    @Override
     210    public String getNewNonce() {
     211        _newNonce = super.getNewNonce();
     212        return _newNonce;
     213    }
     214
     215    /**
     216     *  Now we're a FormHandler
     217     *  @since 0.9.38
     218     */
     219    protected void processForm() {
     220        _postOK = "Run new analysis".equals(_action) ||
     221                  "Review analysis".equals(_action);
     222    }
    197223
    198224    /**
     
    206232                _family != null || _caps != null || _ip != null || _sybil != null ||
    207233                _port != 0 || _type != null || _mtu != null || _ipv6 != null ||
    208                 _ssucaps != null || _transport != null || _cost != 0)
     234                _ssucaps != null || _transport != null || _cost != 0) {
    209235                renderer.renderRouterInfoHTML(_out, _limit, _page,
    210236                                              _routerPrefix, _version, _country,
    211237                                              _family, _caps, _ip, _sybil, _port, _type,
    212238                                              _mtu, _ipv6, _ssucaps, _transport, _cost);
    213             else if (_lease)
     239            } else if (_lease) {
    214240                renderer.renderLeaseSetHTML(_out, _debug);
    215             else if (_full == 3)
    216                 (new SybilRenderer(_context)).getNetDbSummary(_out, _mode, _date);
    217             else if (_full == 4)
     241            } else if (_full == 3) {
     242                if (_mode == 12 && !_postOK)
     243                    _mode = 0;
     244                else if (_mode == 13 && !_postOK)
     245                    _mode = 14;
     246                (new SybilRenderer(_context)).getNetDbSummary(_out, _newNonce, _mode, _date);
     247            } else if (_full == 4) {
    218248                renderLookupForm();
    219             else
     249            } else {
    220250                renderer.renderStatusHTML(_out, _limit, _page, _full);
     251            }
    221252        } catch (IOException ioe) {
    222253            ioe.printStackTrace();
     
    293324    private void renderLookupForm() throws IOException {
    294325        _out.write("<form action=\"/netdb\" method=\"POST\">\n" +
     326                   "<input type=\"hidden\" name=\"nonce\" value=\"" + _newNonce + "\" >\n" +
    295327                   "<table id=\"netdblookup\"><tr><th colspan=\"3\">Network Database Search</th></tr>\n" +
    296328                   "<tr><td colspan=\"3\" class=\"subheading\"><b>Enter one search field <i>only</i>:</b></td></tr>\n" +
  • apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java

    re122393 rfa6a4ca1  
    7979     *  @param date only for mode = 12
    8080     */
    81     public String getNetDbSummary(Writer out, int mode, long date) throws IOException {
    82         renderRouterInfoHTML(out, mode, date);
     81    public String getNetDbSummary(Writer out, String nonce, int mode, long date) throws IOException {
     82        renderRouterInfoHTML(out, nonce, mode, date);
    8383        return "";
    8484    }
     
    126126     *  @param date only for mode = 12
    127127     */
    128     private void renderRouterInfoHTML(Writer out, int mode, long date) throws IOException {
     128    private void renderRouterInfoHTML(Writer out, String nonce, int mode, long date) throws IOException {
    129129        Hash us = _context.routerHash();
    130130        Analysis analysis = Analysis.getInstance(_context);
    131         List<RouterInfo> ris = analysis.getFloodfills(us);
    132         if (ris.isEmpty()) {
    133             out.write("<h3 class=\"sybils\">No known floodfills</h3>");
    134             return;
     131        List<RouterInfo> ris = null;
     132        if (mode != 0 && mode != 12 && mode != 13 && mode != 14) {
     133            ris = analysis.getFloodfills(us);
     134            if (ris.isEmpty()) {
     135                out.write("<h3 class=\"sybils\">No known floodfills</h3>");
     136                return;
     137            }
    135138        }
    136139
    137140        StringBuilder buf = new StringBuilder(4*1024);
    138141        buf.append("<p id=\"sybilinfo\"><b>This is an experimental network database tool for debugging and analysis. Do not panic even if you see warnings below. " +
    139                    "Possible \"threats\" are summarized at the bottom, however these are unlikely to be real threats. " +
     142                   "Possible \"threats\" are summarized, however these are unlikely to be real threats. " +
    140143                   "If you see anything you would like to discuss with the devs, contact us on IRC #i2p-dev.</b></p>" +
    141144                   "<div id=\"sybilnav\"><ul><li><a href=\"netdb?f=3\">Review stored analysis</a>" +
    142                    "</li><li><a href=\"netdb?f=3&amp;m=13\">Run new analysis</a>" +
     145                   "</li><li><a href=\"netdb?f=3&amp;m=14\">Run new analysis</a>" +
    143146                   "</li><li><a href=\"netdb?f=3&amp;m=1\">Floodfill Summary</a>" +
    144147                   "</li><li><a href=\"netdb?f=3&amp;m=2\">Same Family</a>" +
     
    155158        writeBuf(out, buf);
    156159
    157         double avgMinDist = analysis.getAvgMinDist(ris);
     160        double avgMinDist = 0;
     161        if (mode == 1 || mode == 8 || mode == 9 || mode == 10 || mode == 11) {
     162            avgMinDist = analysis.getAvgMinDist(ris);
     163        }
    158164        Map<Hash, Points> points = new HashMap<Hash, Points>(64);
    159165
    160166        if (mode == 0) {
    161             renderOverview(out, buf, analysis);
     167            renderOverview(out, buf, nonce, analysis);
    162168        } else if (mode == 1) {
    163169            renderFFSummary(out, buf, ris, avgMinDist);
     
    183189            renderDestSummary(out, buf, analysis, avgMinDist, ris, points);
    184190        } else if (mode == 12) {
     191            // load stored analysis
    185192            PersistSybil ps = analysis.getPersister();
    186193            try {
     
    196203            }
    197204        } else if (mode == 13) {
     205            // run analysis and store it
    198206            long now = _context.clock().now();
    199207            points = analysis.backgroundAnalysis();
     
    207215            }
    208216            renderThreatsHTML(out, buf, now, points);
     217        } else if (mode == 14) {
     218            // show form
     219            renderRunForm(out, buf, nonce);
    209220        } else {
    210221            out.write("Unknown mode " + mode);
     
    216227     *  @since 0.9.38
    217228     */
    218     private void renderOverview(Writer out, StringBuilder buf, Analysis analysis) throws IOException {
     229    private void renderOverview(Writer out, StringBuilder buf, String nonce, Analysis analysis) throws IOException {
    219230        PersistSybil ps = analysis.getPersister();
    220231        List<Long> dates = ps.load();
     
    222233            out.write("No stored analysis");
    223234        } else {
    224             buf.append("<form action=\"netdb\" method=\"GET\">\n" +
     235            buf.append("<form action=\"netdb\" method=\"POST\">\n" +
    225236                       "<input type=\"hidden\" name=\"f\" value=\"3\">\n" +
    226237                       "<input type=\"hidden\" name=\"m\" value=\"12\">\n" +
     238                       "<input type=\"hidden\" name=\"nonce\" value=\"" + nonce + "\" >\n" +
    227239                       "Select stored analysis: " +
    228240                       "<select name=\"date\">\n");
     
    242254                       "</form>\n");
    243255        }       
    244         buf.append("<br><a href=\"netdb?f=3&amp;m=13\">Run new analysis</a>");
     256        writeBuf(out, buf);
     257    }
     258
     259
     260    /**
     261     *  @since 0.9.38
     262     */
     263    private void renderRunForm(Writer out, StringBuilder buf, String nonce) throws IOException {
     264        buf.append("<form action=\"netdb\" method=\"POST\">\n" +
     265                   "<input type=\"hidden\" name=\"f\" value=\"3\">\n" +
     266                   "<input type=\"hidden\" name=\"m\" value=\"13\">\n" +
     267                   "<input type=\"hidden\" name=\"nonce\" value=\"" + nonce + "\" >\n" +
     268                   "<input type=\"submit\" name=\"action\" class=\"go\" value=\"Run new analysis\" />" +
     269                   "</form>\n");
    245270        writeBuf(out, buf);
    246271    }
  • apps/routerconsole/jsp/netdb.jsp

    re122393 rfa6a4ca1  
    1313<h1><%=intl._t("I2P Network Database")%></h1>
    1414<div class="main" id="netdb">
    15  <jsp:useBean class="net.i2p.router.web.helpers.NetDbHelper" id="netdbHelper" scope="request" />
    16  <jsp:setProperty name="netdbHelper" property="contextId" value="<%=i2pcontextId%>" />
     15 <jsp:useBean class="net.i2p.router.web.helpers.NetDbHelper" id="formhandler" scope="request" />
    1716<%
    18     netdbHelper.storeWriter(out);
     17    formhandler.storeWriter(out);
    1918    if (allowIFrame)
    20         netdbHelper.allowGraphical();
     19        formhandler.allowGraphical();
    2120%>
    22  <jsp:setProperty name="netdbHelper" property="full" value="<%=request.getParameter(\"f\")%>" />
    23  <jsp:setProperty name="netdbHelper" property="router" value="<%=request.getParameter(\"r\")%>" />
    24  <jsp:setProperty name="netdbHelper" property="lease" value="<%=request.getParameter(\"l\")%>" />
    25  <jsp:setProperty name="netdbHelper" property="version" value="<%=request.getParameter(\"v\")%>" />
    26  <jsp:setProperty name="netdbHelper" property="country" value="<%=request.getParameter(\"c\")%>" />
    27  <jsp:setProperty name="netdbHelper" property="family" value="<%=request.getParameter(\"fam\")%>" />
    28  <jsp:setProperty name="netdbHelper" property="caps" value="<%=request.getParameter(\"caps\")%>" />
    29  <jsp:setProperty name="netdbHelper" property="ip" value="<%=request.getParameter(\"ip\")%>" />
    30  <jsp:setProperty name="netdbHelper" property="sybil" value="<%=request.getParameter(\"sybil\")%>" />
    31  <jsp:setProperty name="netdbHelper" property="sybil2" value="<%=request.getParameter(\"sybil2\")%>" />
    32  <jsp:setProperty name="netdbHelper" property="port" value="<%=request.getParameter(\"port\")%>" />
    33  <jsp:setProperty name="netdbHelper" property="type" value="<%=request.getParameter(\"type\")%>" />
    34  <jsp:setProperty name="netdbHelper" property="ipv6" value="<%=request.getParameter(\"ipv6\")%>" />
    35  <jsp:setProperty name="netdbHelper" property="cost" value="<%=request.getParameter(\"cost\")%>" />
    36  <jsp:setProperty name="netdbHelper" property="mtu" value="<%=request.getParameter(\"mtu\")%>" />
    37  <jsp:setProperty name="netdbHelper" property="ssucaps" value="<%=request.getParameter(\"ssucaps\")%>" />
    38  <jsp:setProperty name="netdbHelper" property="transport" value="<%=request.getParameter(\"tr\")%>" />
    39  <jsp:setProperty name="netdbHelper" property="limit" value="<%=request.getParameter(\"ps\")%>" />
    40  <jsp:setProperty name="netdbHelper" property="page" value="<%=request.getParameter(\"pg\")%>" />
    41  <jsp:setProperty name="netdbHelper" property="mode" value="<%=request.getParameter(\"m\")%>" />
    42  <jsp:setProperty name="netdbHelper" property="date" value="<%=request.getParameter(\"date\")%>" />
    43  <jsp:getProperty name="netdbHelper" property="netDbSummary" />
     21 <jsp:setProperty name="formhandler" property="full" value="<%=request.getParameter(\"f\")%>" />
     22 <jsp:setProperty name="formhandler" property="router" value="<%=request.getParameter(\"r\")%>" />
     23 <jsp:setProperty name="formhandler" property="lease" value="<%=request.getParameter(\"l\")%>" />
     24 <jsp:setProperty name="formhandler" property="version" value="<%=request.getParameter(\"v\")%>" />
     25 <jsp:setProperty name="formhandler" property="country" value="<%=request.getParameter(\"c\")%>" />
     26 <jsp:setProperty name="formhandler" property="family" value="<%=request.getParameter(\"fam\")%>" />
     27 <jsp:setProperty name="formhandler" property="caps" value="<%=request.getParameter(\"caps\")%>" />
     28 <jsp:setProperty name="formhandler" property="ip" value="<%=request.getParameter(\"ip\")%>" />
     29 <jsp:setProperty name="formhandler" property="sybil" value="<%=request.getParameter(\"sybil\")%>" />
     30 <jsp:setProperty name="formhandler" property="sybil2" value="<%=request.getParameter(\"sybil2\")%>" />
     31 <jsp:setProperty name="formhandler" property="port" value="<%=request.getParameter(\"port\")%>" />
     32 <jsp:setProperty name="formhandler" property="type" value="<%=request.getParameter(\"type\")%>" />
     33 <jsp:setProperty name="formhandler" property="ipv6" value="<%=request.getParameter(\"ipv6\")%>" />
     34 <jsp:setProperty name="formhandler" property="cost" value="<%=request.getParameter(\"cost\")%>" />
     35 <jsp:setProperty name="formhandler" property="mtu" value="<%=request.getParameter(\"mtu\")%>" />
     36 <jsp:setProperty name="formhandler" property="ssucaps" value="<%=request.getParameter(\"ssucaps\")%>" />
     37 <jsp:setProperty name="formhandler" property="transport" value="<%=request.getParameter(\"tr\")%>" />
     38 <jsp:setProperty name="formhandler" property="limit" value="<%=request.getParameter(\"ps\")%>" />
     39 <jsp:setProperty name="formhandler" property="page" value="<%=request.getParameter(\"pg\")%>" />
     40 <jsp:setProperty name="formhandler" property="mode" value="<%=request.getParameter(\"m\")%>" />
     41 <jsp:setProperty name="formhandler" property="date" value="<%=request.getParameter(\"date\")%>" />
     42<%@include file="formhandler.jsi" %>
     43 <jsp:getProperty name="formhandler" property="netDbSummary" />
    4444</div></body></html>
Note: See TracChangeset for help on using the changeset viewer.