Changeset 03588e76


Ignore:
Timestamp:
Nov 26, 2017 8:54:44 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
404fe4f
Parents:
6a48910
Message:

Console: Safer processing of changes on /configadvanced

Location:
apps/routerconsole
Files:
2 edited

Legend:

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

    r6a48910 r03588e76  
    44import java.io.IOException;
    55import java.util.HashSet;
     6import java.util.Iterator;
     7import java.util.Map;
    68import java.util.Properties;
    79import java.util.Set;
     
    1820    //private boolean _forceRestart;
    1921    private boolean _shouldSave;
    20     private String _config;
     22    private String _oldConfig, _config;
    2123    private String _ff;
    2224   
     
    4547        _config = val;
    4648    }
     49
     50    /** @since 0.9.33 */
     51    public void setNofilter_oldConfig(String val) {
     52        _oldConfig = val;
     53    }
    4754   
    4855    /**
     
    5057     * lets go ahead and do so.
    5158     *
     59     * We saved the previous config in the form, so we do a diff between the two.
     60     * This will reduce the chance of undoing some change that happened in-between.
    5261     */
    5362    private void saveChanges() {
    54         Set<String> unsetKeys = new HashSet<String>(_context.router().getConfigSettings());
    55         if (_config != null) {
     63        if (_oldConfig != null && _config != null) {
     64            Properties oldProps = new Properties();
    5665            Properties props = new Properties();
    5766            try {
     67                DataHelper.loadProps(oldProps, new ByteArrayInputStream(DataHelper.getUTF8(_oldConfig)));
    5868                DataHelper.loadProps(props, new ByteArrayInputStream(DataHelper.getUTF8(_config)));
    5969            } catch (IOException ioe) {
     
    6474            }
    6575
    66             for (String key : props.stringPropertyNames()) {
     76            Set<String> unsetKeys = new HashSet<String>(oldProps.stringPropertyNames());
     77            for (Iterator<Map.Entry<Object, Object>> iter = props.entrySet().iterator(); iter.hasNext(); ) {
     78                Map.Entry<Object, Object> e = iter.next();
     79                String key = (String) e.getKey();
     80                String nnew = (String) e.getValue();
     81                String old = oldProps.getProperty(key);
    6782                unsetKeys.remove(key);
     83                if (nnew.equals(old)) {
     84                    // no change
     85                    iter.remove();
     86                }
    6887            }
     88            // what's remaining in unsetKeys will be deleted
    6989
    7090            boolean saved = _context.router().saveConfig(props, unsetKeys);
  • apps/routerconsole/jsp/configadvanced.jsp

    r6a48910 r03588e76  
    5757
    5858<h3 id="advancedconfig" class="tabletitle"><%=intl._t("Advanced I2P Configuration")%>&nbsp;<a title="Help with additional configuration settings" href="/help#advancedsettings">[Additional Options]</a></h3>
    59 <% if (advancedhelper.isAdvanced()) { %>
     59<%
     60  String advConfig = advancedhelper.getSettings();
     61  if (advancedhelper.isAdvanced()) {
     62%>
    6063 <form action="" method="POST">
    6164 <input type="hidden" name="nonce" value="<%=pageNonce%>" >
    6265 <input type="hidden" name="action" value="blah" >
     66 <input type="hidden" name="nofilter_oldConfig" value="<%=advConfig%>" >
    6367<% }  // isAdvanced %>
    6468<table class="configtable" id="advconf">
     
    7377<% }  // isAdvanced %>
    7478 <tr><td class="tabletextarea">
    75  <textarea id="advancedsettings" rows="32" cols="60" name="nofilter_config" wrap="off" spellcheck="false" <% if (!advancedhelper.isAdvanced()) { %>readonly="readonly"<% } %>><jsp:getProperty name="advancedhelper" property="settings" /></textarea>
     79 <textarea id="advancedsettings" rows="32" cols="60" name="nofilter_config" wrap="off" spellcheck="false" <% if (!advancedhelper.isAdvanced()) { %>readonly="readonly"<% } %>><%=advConfig%></textarea>
    7680 </td></tr>
    7781<% if (advancedhelper.isAdvanced()) { %>
Note: See TracChangeset for help on using the changeset viewer.