* configclients.jsp: Implement saves for clients and webapps.

This commit is contained in:
zzz
2008-06-17 13:48:41 +00:00
parent 91950a37f5
commit f3d73a6c15
6 changed files with 85 additions and 55 deletions

View File

@ -1,59 +1,63 @@
package net.i2p.router.web;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import net.i2p.data.DataFormatException;
import net.i2p.router.startup.ClientAppConfig;
import net.i2p.util.Log;
/**
*
* Saves changes to clients.config or webapps.config
*/
public class ConfigClientsHandler extends FormHandler {
private Log _log;
private Map _settings;
private boolean _shouldSave;
public ConfigClientsHandler() {
_shouldSave = false;
}
public ConfigClientsHandler() {}
protected void processForm() {
if (_shouldSave) {
saveChanges();
if (_action.startsWith("Save Client")) {
saveClientChanges();
} else if (_action.startsWith("Save WebApp")) {
saveWebAppChanges();
} else {
// noop
addFormError("Unimplemented");
addFormError("Unsupported " + _action);
}
}
public void setShouldsave(String moo) {
if ( (moo != null) && (moo.equals("Save changes")) )
_shouldSave = true;
}
public void setSettings(Map settings) { _settings = new HashMap(settings); }
/**
* The user made changes to the network config and wants to save them, so
* lets go ahead and do so.
*
*/
private void saveChanges() {
_log = _context.logManager().getLog(ConfigClientsHandler.class);
boolean saveRequired = false;
int updated = 0;
int index = 0;
if (updated > 0)
addFormNotice("Updated settings");
if (saveRequired) {
boolean saved = _context.router().saveConfig();
if (saved)
addFormNotice("Exploratory tunnel configuration saved successfully");
else
addFormNotice("Error saving the configuration (applied but not saved) - please see the error logs");
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));
}
RouterConsoleRunner.storeWebAppProperties(props);
addFormNotice("WebApp configuration saved successfully - restart required to take effect");
}
}