* 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)

View File

@ -18,7 +18,6 @@
<jsp:useBean class="net.i2p.router.web.ConfigClientsHandler" id="formhandler" scope="request" />
<jsp:setProperty name="formhandler" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
<jsp:setProperty name="formhandler" property="shouldsave" value="<%=request.getParameter("shouldsave")%>" />
<jsp:setProperty name="formhandler" property="action" value="<%=request.getParameter("action")%>" />
<jsp:setProperty name="formhandler" property="nonce" value="<%=request.getParameter("nonce")%>" />
<jsp:setProperty name="formhandler" property="settings" value="<%=request.getParameterMap()%>" />
@ -30,7 +29,6 @@
if (prev != null) System.setProperty("net.i2p.router.web.ConfigClientsHandler.noncePrev", prev);
System.setProperty("net.i2p.router.web.ConfigClientsHandler.nonce", new java.util.Random().nextLong()+""); %>
<input type="hidden" name="nonce" value="<%=System.getProperty("net.i2p.router.web.ConfigClientsHandler.nonce")%>" />
<input type="hidden" name="action" value="blah" />
<h3>Client Configuration</h3>
<p>
The Java clients listed below are started by the router and run in the same JVM.
@ -39,7 +37,7 @@
</p><p>
<input type="submit" name="action" value="Save Client Configuration" />
</p><p>
<i>All changes require restart to take effect. For other changes edit the clients.config file.</i>
<i>All changes require restart to take effect. To change other client options, edit the clients.config file.</i>
</p>
<hr />
<h3>WebApp Configuration</h3>
@ -50,11 +48,15 @@
front-ends to another client or application which must be separately enabled (e.g. susidns, i2ptunnel),
or have no web interface at all (e.g. addressbook).
</p><p>
A web app may also be disabled by removing the .war file from the webapps directory;
however the .war file and web app will reappear when you update your router to a newer version,
so disabling the web app here is the preferred method.
</p><p>
<jsp:getProperty name="clientshelper" property="form2" />
</p><p>
<input type="submit" name="action" value="Save WebApp Configuration" />
</p><p>
<i>All changes require restart to take effect. For other changes edit the webapps.config file.</i>
<i>All changes require restart to take effect. To change other webapp options, edit the webapps.config file.</i>
</p>
</form>
</div>

View File

@ -1,3 +1,9 @@
2008-06-17 zzz
* Comm System: Add new STATUS_HOSED for use when UDP bind fails
* Summary bar: Display helpful errror message when UDP bind fails
* UDP: Don't bid when UDP bind fails
* configclients.jsp: Implement saves for clients and webapps.
2008-06-16 zzz
* UDP: Prevent 100% CPU when UDP bind fails;
change bind fail message from ERROR to CRIT
@ -12,7 +18,6 @@
* configclients.jsp: New. For both clients and webapps.
Saves are not yet implemented.
2008-06-10 zzz
* Floodfill: Add new FloodfillMonitorJob, which tracks active
floodfills, and automatically enables/disables floodfill on

View File

@ -17,7 +17,7 @@ import net.i2p.CoreVersion;
public class RouterVersion {
public final static String ID = "$Revision: 1.548 $ $Date: 2008-06-07 23:00:00 $";
public final static String VERSION = "0.6.2";
public final static long BUILD = 3;
public final static long BUILD = 4;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);

View File

@ -2,6 +2,7 @@ package net.i2p.router.startup;
import java.io.IOException;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@ -22,6 +23,7 @@ public class ClientAppConfig {
private static final String PROP_CLIENT_CONFIG_FILENAME = "router.clientConfigFile";
private static final String DEFAULT_CLIENT_CONFIG_FILENAME = "clients.config";
private static final String PREFIX = "clientApp.";
// let's keep this really simple
public String className;
@ -63,14 +65,14 @@ public class ClientAppConfig {
List rv = new ArrayList(5);
int i = 0;
while (true) {
String className = clientApps.getProperty("clientApp."+i+".main");
String className = clientApps.getProperty(PREFIX + i + ".main");
if (className == null)
break;
String clientName = clientApps.getProperty("clientApp."+i+".name");
String args = clientApps.getProperty("clientApp."+i+".args");
String delayStr = clientApps.getProperty("clientApp." + i + ".delay");
String onBoot = clientApps.getProperty("clientApp." + i + ".onBoot");
String disabled = clientApps.getProperty("clientApp." + i + ".startOnLoad");
String clientName = clientApps.getProperty(PREFIX + i + ".name");
String args = clientApps.getProperty(PREFIX + i + ".args");
String delayStr = clientApps.getProperty(PREFIX + i + ".delay");
String onBoot = clientApps.getProperty(PREFIX + i + ".onBoot");
String disabled = clientApps.getProperty(PREFIX + i + ".startOnLoad");
i++;
boolean dis = disabled != null && "false".equals(disabled);
@ -87,5 +89,25 @@ public class ClientAppConfig {
return rv;
}
public static void writeClientAppConfig(RouterContext ctx, List apps) {
String clientConfigFile = ctx.getProperty(PROP_CLIENT_CONFIG_FILENAME, DEFAULT_CLIENT_CONFIG_FILENAME);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(clientConfigFile);
StringBuffer buf = new StringBuffer(2048);
for(int i = 0; i < apps.size(); i++) {
ClientAppConfig app = (ClientAppConfig) apps.get(i);
buf.append(PREFIX).append(i).append(".main=").append(app.className).append("\n");
buf.append(PREFIX).append(i).append(".name=").append(app.clientName).append("\n");
buf.append(PREFIX).append(i).append(".args=").append(app.args).append("\n");
buf.append(PREFIX).append(i).append(".delay=").append(app.delay / 1000).append("\n");
buf.append(PREFIX).append(i).append(".startOnLoad=").append(!app.disabled).append("\n");
}
fos.write(buf.toString().getBytes());
} catch (IOException ioe) {
} finally {
if (fos != null) try { fos.close(); } catch (IOException ioe) {}
}
}
}