use of net.i2p.router.startup.ClientAppConfig in project i2p.i2p by i2p.
the class ConfigClientsHelper method getForm1.
/**
* clients
*/
public String getForm1() {
StringBuilder buf = new StringBuilder(1024);
buf.append("<table id=\"clientconfig\">\n" + "<tr><th align=\"right\">").append(_t("Client")).append("</th><th>").append(_t("Run at Startup?")).append("</th><th>").append(_t("Control")).append("</th><th align=\"left\">").append(_t("Class and arguments")).append("</th></tr>\n");
boolean allowEdit = isClientChangeEnabled();
List<ClientAppConfig> clients = ClientAppConfig.getClientApps(_context);
List<CAC> cacs = new ArrayList<CAC>(clients.size());
for (int cur = 0; cur < clients.size(); cur++) {
ClientAppConfig ca = clients.get(cur);
String xname = ca.clientName;
if (xname.length() > 0)
xname = _t(xname);
cacs.add(new CAC(cur, ca, xname));
}
Collections.sort(cacs, new CACComparator());
for (CAC cac : cacs) {
ClientAppConfig ca = cac.config;
int cur = cac.index;
boolean isConsole = ca.className.equals("net.i2p.router.web.RouterConsoleRunner");
boolean showStart;
boolean showStop;
if (isConsole) {
showStart = false;
showStop = false;
} else {
ClientApp clientApp = _context.routerAppManager().getClientApp(ca.className, LoadClientAppsJob.parseArgs(ca.args));
showStart = clientApp == null;
showStop = clientApp != null && clientApp.getState() == ClientAppState.RUNNING;
}
renderForm(buf, "" + cur, ca.clientName, // urlify, enabled
false, !ca.disabled, // "webConsole".equals(ca.clientName) || "Web console".equals(ca.clientName),
false, RouterConsoleRunner.class.getName().equals(ca.className), // description
DataHelper.escapeHTML(ca.className + ((ca.args != null) ? " " + ca.args : "")), // edit
allowEdit && ("" + cur).equals(_edit), // Don't allow edit if it's running, or else we would lose the "handle" to the ClientApp to stop it.
allowEdit && !showStop, false, // show stop button
showStop, // show delete button, show start button
allowEdit && !isConsole, showStart);
}
if (allowEdit && "new".equals(_edit))
renderForm(buf, "" + clients.size(), "", false, false, false, false, "", true, false, false, false, false, false);
buf.append("</table>\n");
return buf.toString();
}
use of net.i2p.router.startup.ClientAppConfig in project i2p.i2p by i2p.
the class ConfigServiceHandler method browseOnStartup.
private void browseOnStartup(boolean shouldLaunchBrowser) {
List<ClientAppConfig> clients = ClientAppConfig.getClientApps(_context);
boolean found = false;
for (int cur = 0; cur < clients.size(); cur++) {
ClientAppConfig ca = clients.get(cur);
if (UrlLauncher.class.getName().equals(ca.className)) {
ca.disabled = !shouldLaunchBrowser;
found = true;
break;
}
}
// releases <= 0.6.5 deleted the entry completely
if (shouldLaunchBrowser && !found) {
String url = _context.portMapper().getConsoleURL();
ClientAppConfig ca = new ClientAppConfig(UrlLauncher.class.getName(), "consoleBrowser", url, 5, false);
clients.add(ca);
}
ClientAppConfig.writeClientAppConfig(_context, clients);
}
use of net.i2p.router.startup.ClientAppConfig in project i2p.i2p by i2p.
the class ConfigClientsHandler method saveClientChanges.
private void saveClientChanges() {
List<ClientAppConfig> clients = ClientAppConfig.getClientApps(_context);
for (int cur = 0; cur < clients.size(); cur++) {
ClientAppConfig ca = clients.get(cur);
Object val = _settings.get(cur + ".enabled");
if (!(RouterConsoleRunner.class.getName().equals(ca.className)))
ca.disabled = val == null;
// edit of an existing entry
if (_context.getBooleanProperty(ConfigClientsHelper.PROP_ENABLE_CLIENT_CHANGE) || isAdvanced()) {
String desc = getJettyString("nofilter_desc" + cur);
if (desc != null) {
int spc = desc.indexOf(' ');
String clss = desc;
String args = null;
if (spc >= 0) {
clss = desc.substring(0, spc);
args = desc.substring(spc + 1);
}
ca.className = clss;
ca.args = args;
ca.clientName = getJettyString("nofilter_name" + cur);
}
}
}
// new client
if (_context.getBooleanProperty(ConfigClientsHelper.PROP_ENABLE_CLIENT_CHANGE) || isAdvanced()) {
int newClient = clients.size();
String newDesc = getJettyString("nofilter_desc" + newClient);
if (newDesc != null && newDesc.trim().length() > 0) {
// new entry
int spc = newDesc.indexOf(' ');
String clss = newDesc;
String args = null;
if (spc >= 0) {
clss = newDesc.substring(0, spc);
args = newDesc.substring(spc + 1);
}
String name = getJettyString("nofilter_name" + newClient);
if (name == null || name.trim().length() <= 0)
name = "new client";
ClientAppConfig ca = new ClientAppConfig(clss, name, args, 2 * 60 * 1000, // true for disabled
_settings.get(newClient + ".enabled") == null);
clients.add(ca);
addFormNotice(_t("New client added") + ": " + name + " (" + clss + ").");
}
}
ClientAppConfig.writeClientAppConfig(_context, clients);
addFormNotice(_t("Client configuration saved successfully"));
// addFormNotice(_t("Restart required to take effect"));
}
use of net.i2p.router.startup.ClientAppConfig in project i2p.i2p by i2p.
the class ConfigClientsHandler method deleteClient.
private void deleteClient(int i) {
List<ClientAppConfig> clients = ClientAppConfig.getClientApps(_context);
if (i < 0 || i >= clients.size()) {
addFormError(_t("Bad client index."));
return;
}
ClientAppConfig ca = clients.remove(i);
ClientAppConfig.writeClientAppConfig(_context, clients);
addFormNotice(_t("Client {0} deleted", ca.clientName));
}
use of net.i2p.router.startup.ClientAppConfig in project i2p.i2p by i2p.
the class PluginStarter method stopPlugin.
/**
* @return true on success
* @throws Exception just about anything, caller would be wise to catch Throwable
*/
public static boolean stopPlugin(RouterContext ctx, String appName) throws Exception {
Log log = ctx.logManager().getLog(PluginStarter.class);
File pluginDir = new File(ctx.getConfigDir(), PLUGIN_DIR + '/' + appName);
if ((!pluginDir.exists()) || (!pluginDir.isDirectory())) {
log.error("Cannot stop nonexistent plugin: " + appName);
return false;
}
// stop things in clients.config
File clientConfig = new File(pluginDir, "clients.config");
if (clientConfig.exists()) {
Properties props = new Properties();
DataHelper.loadProps(props, clientConfig);
List<ClientAppConfig> clients = ClientAppConfig.getClientApps(clientConfig);
runClientApps(ctx, pluginDir, clients, "stop");
}
/*
File consoleDir = new File(pluginDir, "console");
Properties props = RouterConsoleRunner.webAppProperties(consoleDir.getAbsolutePath());
File webappDir = new File(consoleDir, "webapps");
String fileNames[] = webappDir.list(RouterConsoleRunner.WarFilenameFilter.instance());
if (fileNames != null) {
for (int i = 0; i < fileNames.length; i++) {
String warName = fileNames[i].substring(0, fileNames[i].lastIndexOf(".war"));
if (Arrays.asList(STANDARD_WEBAPPS).contains(warName)) {
continue;
}
WebAppStarter.stopWebApp(server, warName);
}
}
*/
if (pluginWars.containsKey(appName)) {
Iterator<String> wars = pluginWars.get(appName).iterator();
while (wars.hasNext()) {
String warName = wars.next();
WebAppStarter.stopWebApp(ctx, warName);
}
pluginWars.get(appName).clear();
}
// }
// remove summary bar link
Properties props = pluginProperties(ctx, appName);
String name = stripHTML(props, "consoleLinkName_" + Messages.getLanguage(ctx));
if (name == null)
name = stripHTML(props, "consoleLinkName");
if (name != null && name.length() > 0)
NavHelper.unregisterApp(name);
if (log.shouldLog(Log.WARN))
log.warn("Stopping plugin: " + appName);
return true;
}
Aggregations