* 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");
}
}

View File

@ -26,7 +26,6 @@ public class ConfigClientsHelper {
public ConfigClientsHelper() {}
public String getForm1() {
StringBuffer buf = new StringBuffer(1024);
buf.append("<table border=\"1\">\n");
@ -35,7 +34,7 @@ public class ConfigClientsHelper {
List clients = ClientAppConfig.getClientApps(_context);
for (int cur = 0; cur < clients.size(); cur++) {
ClientAppConfig ca = (ClientAppConfig) clients.get(cur);
renderForm(buf, cur, ca.clientName, false, !ca.disabled, "webConsole".equals(ca.clientName), ca.className + " " + ca.args);
renderForm(buf, ""+cur, ca.clientName, false, !ca.disabled, "webConsole".equals(ca.clientName), ca.className + " " + ca.args);
}
buf.append("</table>\n");
@ -48,21 +47,19 @@ public class ConfigClientsHelper {
buf.append("<tr><td>WebApp</td><td>Enabled?</td><td>Description</td></tr>\n");
Properties props = RouterConsoleRunner.webAppProperties();
Set keys = new TreeSet(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)) {
String app = name.substring(8, name.lastIndexOf(RouterConsoleRunner.ENABLED));
String app = name.substring(RouterConsoleRunner.PREFIX.length(), name.lastIndexOf(RouterConsoleRunner.ENABLED));
String val = props.getProperty(name);
renderForm(buf, cur, app, !"addressbook".equals(app), "true".equals(val), RouterConsoleRunner.ROUTERCONSOLE.equals(app), app + ".war");
cur++;
renderForm(buf, app, app, !"addressbook".equals(app), "true".equals(val), RouterConsoleRunner.ROUTERCONSOLE.equals(app), app + ".war");
}
}
buf.append("</table>\n");
return buf.toString();
}
private void renderForm(StringBuffer buf, int index, String name, boolean urlify, boolean enabled, boolean ro, String desc) {
private void renderForm(StringBuffer buf, String index, String name, boolean urlify, boolean enabled, boolean ro, String desc) {
buf.append("<tr><td>");
if (urlify && enabled) {
String link = "/";
@ -72,7 +69,7 @@ public class ConfigClientsHelper {
} else {
buf.append(name);
}
buf.append("</td><td align=\"center\"><input type=\"checkbox\" name=\"enable\" value=\"").append(index).append(".enabled\" ");
buf.append("</td><td align=\"center\"><input type=\"checkbox\" name=\"").append(index).append(".enabled\" value=\"true\" ");
if (enabled) {
buf.append("checked=\"true\" ");
if (ro)