2008-06-16 12:31:14 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
2008-06-17 13:48:41 +00:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2008-06-16 12:31:14 +00:00
|
|
|
import java.util.Map;
|
2008-06-17 13:48:41 +00:00
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2008-06-16 12:31:14 +00:00
|
|
|
import net.i2p.data.DataFormatException;
|
2008-06-17 13:48:41 +00:00
|
|
|
import net.i2p.router.startup.ClientAppConfig;
|
2008-06-16 12:31:14 +00:00
|
|
|
import net.i2p.util.Log;
|
|
|
|
|
|
|
|
/**
|
2008-06-17 13:48:41 +00:00
|
|
|
* Saves changes to clients.config or webapps.config
|
2008-06-16 12:31:14 +00:00
|
|
|
*/
|
|
|
|
public class ConfigClientsHandler extends FormHandler {
|
|
|
|
private Log _log;
|
|
|
|
private Map _settings;
|
|
|
|
|
2008-06-17 13:48:41 +00:00
|
|
|
public ConfigClientsHandler() {}
|
2008-06-16 12:31:14 +00:00
|
|
|
|
|
|
|
protected void processForm() {
|
2008-06-17 13:48:41 +00:00
|
|
|
if (_action.startsWith("Save Client")) {
|
|
|
|
saveClientChanges();
|
|
|
|
} else if (_action.startsWith("Save WebApp")) {
|
|
|
|
saveWebAppChanges();
|
2008-06-16 12:31:14 +00:00
|
|
|
} else {
|
2008-06-17 13:48:41 +00:00
|
|
|
addFormError("Unsupported " + _action);
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSettings(Map settings) { _settings = new HashMap(settings); }
|
|
|
|
|
2008-06-17 13:48:41 +00:00
|
|
|
private void saveClientChanges() {
|
|
|
|
List clients = ClientAppConfig.getClientApps(_context);
|
|
|
|
for (int cur = 0; cur < clients.size(); cur++) {
|
|
|
|
ClientAppConfig ca = (ClientAppConfig) clients.get(cur);
|
|
|
|
Object val = _settings.get(cur + ".enabled");
|
|
|
|
if (! "webConsole".equals(ca.clientName))
|
|
|
|
ca.disabled = val == null;
|
|
|
|
}
|
|
|
|
ClientAppConfig.writeClientAppConfig(_context, clients);
|
|
|
|
addFormNotice("Client configuration saved successfully - restart required to take effect");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void saveWebAppChanges() {
|
|
|
|
Properties props = RouterConsoleRunner.webAppProperties();
|
|
|
|
Set keys = props.keySet();
|
|
|
|
int cur = 0;
|
|
|
|
for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
|
|
|
|
String name = (String)iter.next();
|
|
|
|
if (! (name.startsWith(RouterConsoleRunner.PREFIX) && name.endsWith(RouterConsoleRunner.ENABLED)))
|
|
|
|
continue;
|
|
|
|
String app = name.substring(RouterConsoleRunner.PREFIX.length(), name.lastIndexOf(RouterConsoleRunner.ENABLED));
|
|
|
|
Object val = _settings.get(app + ".enabled");
|
|
|
|
if (! RouterConsoleRunner.ROUTERCONSOLE.equals(app))
|
|
|
|
props.setProperty(name, "" + (val != null));
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
2008-06-17 13:48:41 +00:00
|
|
|
RouterConsoleRunner.storeWebAppProperties(props);
|
|
|
|
addFormNotice("WebApp configuration saved successfully - restart required to take effect");
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
|
|
|
}
|