2004-07-31 04:10:33 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
2008-07-16 13:42:54 +00:00
|
|
|
import java.io.ByteArrayInputStream;
|
2004-07-31 04:10:33 +00:00
|
|
|
import java.io.IOException;
|
2004-08-16 20:27:06 +00:00
|
|
|
import java.util.HashSet;
|
2011-11-09 18:36:32 +00:00
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import net.i2p.data.DataHelper;
|
2015-06-06 16:01:39 +00:00
|
|
|
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
|
2004-07-31 04:10:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler to deal with form submissions from the advanced config form and act
|
|
|
|
* upon the values.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ConfigAdvancedHandler extends FormHandler {
|
2009-10-26 21:48:46 +00:00
|
|
|
//private boolean _forceRestart;
|
2004-07-31 04:10:33 +00:00
|
|
|
private boolean _shouldSave;
|
|
|
|
private String _config;
|
2015-05-03 18:49:34 +00:00
|
|
|
private String _ff;
|
2004-07-31 04:10:33 +00:00
|
|
|
|
2009-08-15 16:08:33 +00:00
|
|
|
@Override
|
2004-07-31 04:10:33 +00:00
|
|
|
protected void processForm() {
|
|
|
|
if (_shouldSave) {
|
2015-05-03 18:49:34 +00:00
|
|
|
if ("ff".equals(_action) && _ff != null) {
|
|
|
|
saveFF();
|
|
|
|
} else if (isAdvanced()) {
|
2014-08-03 13:58:51 +00:00
|
|
|
saveChanges();
|
2015-05-03 18:49:34 +00:00
|
|
|
} else {
|
2014-08-03 13:58:51 +00:00
|
|
|
addFormError("Save disabled, edit the router.config file to make changes") ;
|
2015-05-03 18:49:34 +00:00
|
|
|
}
|
2004-07-31 04:10:33 +00:00
|
|
|
} else {
|
|
|
|
// noop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setShouldsave(String moo) { _shouldSave = true; }
|
2009-10-26 21:48:46 +00:00
|
|
|
//public void setRestart(String moo) { _forceRestart = true; }
|
2004-07-31 04:10:33 +00:00
|
|
|
|
2015-05-03 18:49:34 +00:00
|
|
|
/** @since 0.9.20 */
|
|
|
|
public void setFf(String ff) { _ff = ff; }
|
|
|
|
|
2014-08-03 13:58:51 +00:00
|
|
|
public void setNofilter_config(String val) {
|
2004-07-31 04:10:33 +00:00
|
|
|
_config = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The user made changes to the config and wants to save them, so
|
|
|
|
* lets go ahead and do so.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private void saveChanges() {
|
2013-11-21 11:31:50 +00:00
|
|
|
Set<String> unsetKeys = new HashSet<String>(_context.router().getConfigSettings());
|
2004-07-31 04:10:33 +00:00
|
|
|
if (_config != null) {
|
2011-11-09 18:36:32 +00:00
|
|
|
Properties props = new Properties();
|
2004-07-31 04:10:33 +00:00
|
|
|
try {
|
2011-11-09 18:36:32 +00:00
|
|
|
DataHelper.loadProps(props, new ByteArrayInputStream(_config.getBytes()));
|
2004-07-31 04:10:33 +00:00
|
|
|
} catch (IOException ioe) {
|
2011-11-09 18:36:32 +00:00
|
|
|
_log.error("Config error", ioe);
|
|
|
|
addFormError(ioe.toString());
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormError(_t("Error updating the configuration - please see the error logs"));
|
2004-07-31 04:10:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-08-16 20:27:06 +00:00
|
|
|
|
2015-04-24 16:27:03 +00:00
|
|
|
for (String key : props.stringPropertyNames()) {
|
2011-11-09 18:36:32 +00:00
|
|
|
unsetKeys.remove(key);
|
|
|
|
}
|
|
|
|
|
2012-01-18 01:54:34 +00:00
|
|
|
boolean saved = _context.router().saveConfig(props, unsetKeys);
|
2004-07-31 04:10:33 +00:00
|
|
|
if (saved)
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Configuration saved successfully"));
|
2004-07-31 04:10:33 +00:00
|
|
|
else
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormError(_t("Error saving the configuration (applied but not saved) - please see the error logs"));
|
2004-07-31 04:10:33 +00:00
|
|
|
|
2009-10-26 21:48:46 +00:00
|
|
|
//if (_forceRestart) {
|
|
|
|
// addFormNotice("Performing a soft restart");
|
|
|
|
// _context.router().restart();
|
|
|
|
// addFormNotice("Soft restart complete");
|
|
|
|
//}
|
2004-07-31 04:10:33 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-03 18:49:34 +00:00
|
|
|
|
|
|
|
/** @since 0.9.20 */
|
|
|
|
private void saveFF() {
|
|
|
|
boolean saved = _context.router().saveConfig(ConfigAdvancedHelper.PROP_FLOODFILL_PARTICIPANT, _ff);
|
2015-06-06 16:01:39 +00:00
|
|
|
if (_ff.equals("false") || _ff.equals("true")) {
|
|
|
|
FloodfillNetworkDatabaseFacade fndf = (FloodfillNetworkDatabaseFacade) _context.netDb();
|
|
|
|
boolean wasFF = fndf.floodfillEnabled();
|
|
|
|
boolean isFF = _ff.equals("true");
|
|
|
|
fndf.setFloodfillEnabled(isFF);
|
|
|
|
if (wasFF != isFF)
|
|
|
|
_context.router().rebuildRouterInfo();
|
|
|
|
}
|
2015-05-03 18:49:34 +00:00
|
|
|
if (saved)
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Configuration saved successfully"));
|
2015-05-03 18:49:34 +00:00
|
|
|
else
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormError(_t("Error saving the configuration (applied but not saved) - please see the error logs"));
|
2015-05-03 18:49:34 +00:00
|
|
|
}
|
2004-07-31 04:10:33 +00:00
|
|
|
}
|