diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF old mode 100644 new mode 100755 diff --git a/src/examples/real_time_status.jsp b/src/examples/real_time_status.jsp old mode 100644 new mode 100755 diff --git a/src/wa/server/WAContext.java b/src/wa/server/WAContext.java index 71729ce..7d42ee0 100755 --- a/src/wa/server/WAContext.java +++ b/src/wa/server/WAContext.java @@ -29,6 +29,7 @@ import zutil.db.handler.SimpleSQLResult; import zutil.io.file.FileUtil; import zutil.log.LogUtil; import zutil.net.http.HttpHeader; +import zutil.plugin.PluginManager; import zutil.ui.Navigation; import java.io.File; @@ -45,6 +46,8 @@ public class WAContext { private static final Logger logger = LogUtil.getLogger(); private static Navigation rootNav; public static DBConnection db; + private static PluginManager pluginManager; + private ArrayList alerts; // Navigation @@ -52,6 +55,7 @@ public class WAContext { private List breadcrumb; + public WAContext(HttpHeader header){ // Navigation navInstance = rootNav.createPagedNavInstance(header); @@ -77,6 +81,7 @@ public class WAContext { protected static void initialize(){ try { + pluginManager = new PluginManager(); rootNav = Navigation.createRootNav(); @@ -119,5 +124,7 @@ public class WAContext { public static Navigation getRootNav(){ return rootNav; } - + public static PluginManager getPluginManager() { + return pluginManager; + } } diff --git a/src/wa/server/WebAdminServer.java b/src/wa/server/WebAdminServer.java index 04e0950..9bcf0ef 100755 --- a/src/wa/server/WebAdminServer.java +++ b/src/wa/server/WebAdminServer.java @@ -1,6 +1,6 @@ package wa.server; -import wa.server.plugin.WAPage; +import wa.server.page.WAPage; import zutil.io.file.FileUtil; import zutil.log.CompactLogFormatter; import zutil.log.LogUtil; @@ -26,10 +26,9 @@ public class WebAdminServer { public WebAdminServer(){ try { WAContext.initialize(); - PluginManager pluginManager = new PluginManager(); HttpServer http = new HttpServer(80); - for (Iterator it = pluginManager.getObjectIterator(WAPage.class); it.hasNext(); ){ + for (Iterator it = WAContext.getPluginManager().getObjectIterator(WAPage.class); it.hasNext(); ){ WAPage page = it.next(); if (page.getPageName() != null) http.setPage(page.getPageName(), page); diff --git a/src/wa/server/page/ConfigPage.java b/src/wa/server/page/ConfigPage.java index 2193bdc..97b0a42 100755 --- a/src/wa/server/page/ConfigPage.java +++ b/src/wa/server/page/ConfigPage.java @@ -24,7 +24,6 @@ package wa.server.page; import wa.server.WAContext; import wa.server.plugin.WAConfigEntry; -import wa.server.plugin.WAPage; import wa.server.plugin.WAServiceConfig; import zutil.io.file.FileUtil; import zutil.log.LogUtil; diff --git a/src/wa/server/page/ServicePage.java b/src/wa/server/page/ServicePage.java deleted file mode 100755 index 6e13581..0000000 --- a/src/wa/server/page/ServicePage.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2015 ezivkoc - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package wa.server.page; - -import wa.server.WAContext; -import wa.server.plugin.WAPage; -import wa.server.plugin.WAService; -import wa.server.plugin.WAServiceConfig; -import zutil.io.file.FileUtil; -import zutil.log.LogUtil; -import zutil.net.http.HttpHeader; -import zutil.parser.Templator; -import zutil.plugin.PluginManager; -import zutil.ui.Navigation; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Created by Ziver on 2015-04-06. - */ -public class ServicePage extends WAPage { - private static final Logger log = LogUtil.getLogger(); - public static final String NAVIGATION_NAME = "Services"; - private static final String TMPL_FILE = "WebContent/page/ServicePage.tmpl"; - - - private ServiceStatusPage rootStatusPage; - private ArrayList services; - private ArrayList statusPages; - private ArrayList logPages; - private ArrayList configPages; - - - public ServicePage(){ - super.setPageName("service"); - PluginManager pluginManager = new PluginManager(); - this.services = pluginManager.toArray(WAService.class); - this.rootStatusPage = new ServiceStatusPage(pluginManager); - this.statusPages = new ArrayList<>(); - this.logPages = new ArrayList<>(); - this.configPages = new ArrayList<>(); - - Navigation nav = WAContext.getRootNav().createSubNav(this.getPageName(), NAVIGATION_NAME); - nav.setResource(this); - nav.setWeight(100); - for(WAService plugin : services) { - statusPages.add(new ServiceStatusPage(plugin.getStatus())); - logPages.add(new LogPage(plugin.getLog())); - - Navigation serviceNav = nav.createSubNav(plugin.getName()); - serviceNav.setResource(plugin); - for(WAServiceConfig conf : plugin.getConfigurations()){ - ConfigPage page = new ConfigPage(conf); - configPages.add(page); - serviceNav.createSubNav(conf.getName()) - .setResource(page); - } - } - } - - - @Override - public Templator htmlResponse(WAContext context, - HttpHeader client_info, - Map session, - Map cookie, - Map request) { - - try { - Object resource = context.getBreadcrumb().get(context.getBreadcrumb().size()-1).getResource(); - int index; - if((index = configPages.indexOf(resource)) >= 0){ - return configPages.get(index).htmlResponse(context, client_info, session, cookie, request); - } - else if ((index = services.indexOf(resource)) >= 0) { - WAService obj = services.get(index); - ServiceStatusPage statusPage = statusPages.get(index); - LogPage logPage = logPages.get(index); - - Templator tmpl = new Templator(FileUtil.find(TMPL_FILE)); - if(statusPage != null) - tmpl.set("service_status", - statusPage.htmlResponse(context, client_info, session, cookie, request)); - if(logPage != null) - tmpl.set("service_logs", - logPage.htmlResponse(context, client_info, session, cookie, request)); - return tmpl; - } - else{ // root page - return rootStatusPage.htmlResponse(context, client_info, session, cookie, request); - } - - }catch (IOException e){ - log.log(Level.SEVERE, null, e); - } - return null; - } - - - -} diff --git a/src/wa/server/page/ServiceStatusPage.java b/src/wa/server/page/ServiceStatusPage.java index 96f852a..864caf8 100755 --- a/src/wa/server/page/ServiceStatusPage.java +++ b/src/wa/server/page/ServiceStatusPage.java @@ -23,14 +23,12 @@ package wa.server.page; import wa.server.WAContext; -import wa.server.plugin.WAPage; import wa.server.plugin.WAServiceStatus; import zutil.io.file.FileUtil; import zutil.log.LogUtil; import zutil.net.http.HttpHeader; import zutil.parser.DataNode; import zutil.parser.Templator; -import zutil.plugin.PluginManager; import zutil.ui.Navigation; import java.io.IOException; @@ -54,12 +52,11 @@ public class ServiceStatusPage extends WAPage { services = new ArrayList<>(); services.add(ss); } - public ServiceStatusPage(PluginManager pluginManager){ - this.services = pluginManager.toArray(WAServiceStatus.class); + public ServiceStatusPage(){ + this.services = WAContext.getPluginManager().toArray(WAServiceStatus.class); - Navigation nav = WAContext.getRootNav().createSubNav(ServicePage.NAVIGATION_NAME) - .createSubNav(NAVIGATION_NAME); - nav.setResource(this); + Navigation nav = WAContext.getRootNav().createSubNav(WAServicePage.NAVIGATION_NAME) + .createSubNav(NAVIGATION_NAME).setWeight(-100); } diff --git a/src/wa/server/plugin/WAPage.java b/src/wa/server/page/WAPage.java similarity index 98% rename from src/wa/server/plugin/WAPage.java rename to src/wa/server/page/WAPage.java index e2799c6..d52b127 100755 --- a/src/wa/server/plugin/WAPage.java +++ b/src/wa/server/page/WAPage.java @@ -20,7 +20,7 @@ * THE SOFTWARE. */ -package wa.server.plugin; +package wa.server.page; import wa.server.WAContext; import zutil.io.file.FileUtil; @@ -31,11 +31,9 @@ import zutil.net.http.HttpPrintStream; import zutil.parser.DataNode; import zutil.parser.Templator; import zutil.parser.json.JSONWriter; -import zutil.plugin.PluginManager; import zutil.ui.Navigation; import java.io.IOException; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.logging.Level; diff --git a/src/wa/server/page/WAServicePage.java b/src/wa/server/page/WAServicePage.java new file mode 100755 index 0000000..3110dfb --- /dev/null +++ b/src/wa/server/page/WAServicePage.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2015 ezivkoc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package wa.server.page; + +import wa.server.WAContext; +import wa.server.plugin.WAInstaller; +import wa.server.plugin.WALog; +import wa.server.plugin.WAServiceConfig; +import wa.server.plugin.WAServiceStatus; +import zutil.io.file.FileUtil; +import zutil.log.LogUtil; +import zutil.net.http.HttpHeader; +import zutil.parser.Templator; +import zutil.ui.Navigation; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Created by Ziver on 2015-04-06. + */ +public abstract class WAServicePage extends WAPage { + private static final Logger log = LogUtil.getLogger(); + public static final String NAVIGATION_NAME = "Services"; + private static final String TMPL_FILE = "WebContent/page/ServicePage.tmpl"; + + + private ServiceStatusPage statusPage; + private LogPage logPage; + + + public WAServicePage(String pageName, String serviceName){ + super.setPageName("service/"+pageName); + + Navigation rootNav = WAContext.getRootNav().createSubNav(NAVIGATION_NAME).setWeight(100); + Navigation serviceNav = rootNav.createSubNav(getPageName(), serviceName); + + statusPage = new ServiceStatusPage(getStatus()); + logPage = new LogPage(getLog()); + } + + + @Override + public Templator htmlResponse(WAContext context, + HttpHeader client_info, + Map session, + Map cookie, + Map request) throws IOException { + + Templator tmpl = new Templator(FileUtil.find(TMPL_FILE)); + if(statusPage != null) + tmpl.set("service_status", + statusPage.htmlResponse(context, client_info, session, cookie, request)); + if(logPage != null) + tmpl.set("service_logs", + logPage.htmlResponse(context, client_info, session, cookie, request)); + return tmpl; + } + + + + + /** + * @return a service status object or null if it is not possible to check status + */ + public abstract WAServiceStatus getStatus(); + + /** + * @return a service log object or null if it is not possible to read logs + */ + public abstract WALog getLog(); + + /** + * @return a installer object that will install the service or null if the installer is not available + */ + public abstract WAInstaller getInstaller(); +} diff --git a/src/wa/server/plugin/WAStatusPage.java b/src/wa/server/page/WAStatusPage.java similarity index 93% rename from src/wa/server/plugin/WAStatusPage.java rename to src/wa/server/page/WAStatusPage.java index b1f2eb6..25ecd7f 100755 --- a/src/wa/server/plugin/WAStatusPage.java +++ b/src/wa/server/page/WAStatusPage.java @@ -23,7 +23,6 @@ package wa.server.page; import wa.server.WAContext; -import wa.server.plugin.WAPage; /** @@ -36,7 +35,7 @@ public abstract class WAStatusPage extends WAPage { public WAStatusPage(String subPageName, String niceName){ super.setPageName("status/"+subPageName); - WAContext.getRootNav().createSubNav("status", NAVIGATION_NAME) + WAContext.getRootNav().createSubNav(NAVIGATION_NAME) .setWeight(0).createSubNav(this.getPageName(), niceName); } diff --git a/src/wa/server/plugin.json b/src/wa/server/plugin.json index fae01fa..eabeca4 100755 --- a/src/wa/server/plugin.json +++ b/src/wa/server/plugin.json @@ -1,5 +1,7 @@ { "version": "1.0", "name": "WA Core", - "interfaces": [ ] + "interfaces": [ + {"wa.server.page.WAPage": "wa.server.page.ServiceStatusPage"} + ] } \ No newline at end of file diff --git a/src/wa/server/plugin/WAInstaller.java b/src/wa/server/plugin/WAInstaller.java old mode 100644 new mode 100755 diff --git a/src/wa/server/plugin/WAService.java b/src/wa/server/plugin/WAService.java deleted file mode 100755 index b764737..0000000 --- a/src/wa/server/plugin/WAService.java +++ /dev/null @@ -1,26 +0,0 @@ -package wa.server.plugin; - -public interface WAService { - - String getName(); - - /** - * @return a service status object or null if it is not possible to check status - */ - WAServiceStatus getStatus(); - - /** - * @return a service log object or null if it is not possible to read logs - */ - WALog getLog(); - - /** - * @return a installer object that will install the service or null if the installer is not available - */ - WAInstaller getInstaller(); - - /** - * @return a array of configuration objects - */ - WAServiceConfig[] getConfigurations(); -} diff --git a/src/wa/server/plugin/WAServiceConfig.java b/src/wa/server/plugin/WAServiceConfig.java index a8df942..d7d71e3 100755 --- a/src/wa/server/plugin/WAServiceConfig.java +++ b/src/wa/server/plugin/WAServiceConfig.java @@ -7,7 +7,7 @@ public interface WAServiceConfig { /** * @return the String name of this configuration type */ - public String getName(); + String getName(); /** * Read in current configuration data @@ -19,13 +19,13 @@ public interface WAServiceConfig { */ //public void save() throws Exception; - public WAConfigEntry createConfig(); - public void deleteConfig(int id); + WAConfigEntry createConfig(); + void deleteConfig(int id); /** * Configure service with current configuration data */ - public void configure() throws Exception; + void configure() throws Exception; @@ -34,10 +34,10 @@ public interface WAServiceConfig { * configuration can be changed with the * {@link zutil.ui.Configurator} class. */ - public List getConfigData(); + List getConfigData(); /** * @return the class that contains the configuration data */ - public Class getConfigClass(); + Class getConfigClass(); } diff --git a/src/wa/server/plugin/WAServiceStatus.java b/src/wa/server/plugin/WAServiceStatus.java old mode 100644 new mode 100755 diff --git a/src/wa/server/plugin/apache/ApacheConfigVirtualHost.java b/src/wa/server/plugin/apache/ApacheConfigVirtualHost.java index 08cdafd..fd8152d 100755 --- a/src/wa/server/plugin/apache/ApacheConfigVirtualHost.java +++ b/src/wa/server/plugin/apache/ApacheConfigVirtualHost.java @@ -31,6 +31,7 @@ public class ApacheConfigVirtualHost implements WAServiceConfig{ vhosts = DBBean.load(WAContext.getDB(), ApacheVirtualHostEntry.class); } + @Override public String getName() { return CONFIG_NAME; diff --git a/src/wa/server/plugin/apache/ApacheInstaller.java b/src/wa/server/plugin/apache/ApacheInstaller.java old mode 100644 new mode 100755 diff --git a/src/wa/server/plugin/apache/ApacheService.java b/src/wa/server/plugin/apache/ApacheService.java index 222efb5..a287238 100755 --- a/src/wa/server/plugin/apache/ApacheService.java +++ b/src/wa/server/plugin/apache/ApacheService.java @@ -22,6 +22,7 @@ package wa.server.plugin.apache; +import wa.server.page.WAServicePage; import wa.server.plugin.*; import zutil.log.LogUtil; @@ -32,24 +33,18 @@ import java.util.logging.Logger; /** * Created by Ziver on 2014-12-23. */ -public class ApacheService implements WAService { - private static Logger logger = LogUtil.getLogger(); +public class ApacheService extends WAServicePage { public static final String SERVICE_NAME = "Apache2"; - private ApacheStatus status; - private ApacheInstaller installer; - private WAServiceConfig[] config; - - @Override - public String getName() { - return SERVICE_NAME; + public ApacheService() { + super("apache", SERVICE_NAME); } + + @Override public WAServiceStatus getStatus() { - if(status == null) - status = new ApacheStatus(); - return status; + return new ApacheStatus(); } @Override @@ -59,21 +54,6 @@ public class ApacheService implements WAService { @Override public WAInstaller getInstaller() { - if(installer == null) - installer = new ApacheInstaller(); - return installer; - } - - @Override - public WAServiceConfig[] getConfigurations() { - if(config == null) - try { - config = new WAServiceConfig[]{ - new ApacheConfigVirtualHost() - }; - } catch (SQLException e) { - logger.log(Level.SEVERE, null, e); - } - return config; + return new ApacheInstaller(); } } diff --git a/src/wa/server/plugin/apache/apache_default.config b/src/wa/server/plugin/apache/apache_default.config old mode 100644 new mode 100755 diff --git a/src/wa/server/plugin/apache/plugin.json b/src/wa/server/plugin/apache/plugin.json index 2ed2100..7d3009d 100755 --- a/src/wa/server/plugin/apache/plugin.json +++ b/src/wa/server/plugin/apache/plugin.json @@ -2,7 +2,8 @@ "version": "1.0", "name": "Apache Web Server", "interfaces": [ - {"wa.server.plugin.WAService": "wa.server.plugin.apache.ApacheService"}, - {"wa.server.plugin.WAServiceStatus": "wa.server.plugin.apache.ApacheStatus"} + {"wa.server.page.WAServicePage": "wa.server.plugin.apache.ApacheService"}, + {"wa.server.plugin.WAServiceStatus": "wa.server.plugin.apache.ApacheStatus"}, + {"wa.server.page.WAConfigPage": "wa.server.plugin.apache.ApacheConfigVirtualHost"} ] } \ No newline at end of file diff --git a/src/wa/server/plugin/hwstatus/HDDStatus.java b/src/wa/server/plugin/hwstatus/HDDStatus.java index 79b1cf5..83f3ba5 100755 --- a/src/wa/server/plugin/hwstatus/HDDStatus.java +++ b/src/wa/server/plugin/hwstatus/HDDStatus.java @@ -44,9 +44,7 @@ import java.util.Map; */ public class HDDStatus extends WAStatusPage { private static final String TEMPLATE = "wa/server/plugin/hwstatus/HddStatus.tmpl"; - private static final String NAVIGATION_NAME = "wa/server/plugin/hwstatus/HddStatus.tmpl"; - private Templator tmpl; private int nextId; private HashMap idMap = new HashMap(); @@ -59,9 +57,7 @@ public class HDDStatus extends WAStatusPage { @Override public Templator htmlResponse(WAContext context, HttpHeader client_info, Map session, Map cookie, Map request) throws IOException { - if (tmpl == null) - tmpl = new Templator(FileUtil.getContent(FileUtil.find(TEMPLATE))); - return tmpl; + return new Templator(FileUtil.getContent(FileUtil.find(TEMPLATE))); } @Override diff --git a/src/wa/server/plugin/hwstatus/HwStatus.java b/src/wa/server/plugin/hwstatus/HwStatus.java index 529a5db..09beb2d 100755 --- a/src/wa/server/plugin/hwstatus/HwStatus.java +++ b/src/wa/server/plugin/hwstatus/HwStatus.java @@ -42,8 +42,6 @@ import java.util.Map; public class HwStatus extends WAStatusPage { private static final String TEMPLATE = "wa/server/plugin/hwstatus/HwStatus.tmpl"; - private Templator tmpl; - public HwStatus() { super("hw", "Hardware Summary"); @@ -53,9 +51,7 @@ public class HwStatus extends WAStatusPage { @Override public Templator htmlResponse(WAContext context, HttpHeader client_info, Map session, Map cookie, Map request) throws IOException { - if (tmpl == null) - tmpl = new Templator(FileUtil.getContent(FileUtil.find(TEMPLATE))); - return tmpl; + return new Templator(FileUtil.getContent(FileUtil.find(TEMPLATE))); } @Override diff --git a/src/wa/server/plugin/hwstatus/NetStatus.java b/src/wa/server/plugin/hwstatus/NetStatus.java index 712ea2c..ec322f7 100755 --- a/src/wa/server/plugin/hwstatus/NetStatus.java +++ b/src/wa/server/plugin/hwstatus/NetStatus.java @@ -42,7 +42,6 @@ import java.util.Map; public class NetStatus extends WAStatusPage { private static final String TEMPLATE = "wa/server/plugin/hwstatus/NetStatus.tmpl"; - private Templator tmpl; private int nextId; private HashMap idMap = new HashMap(); @@ -58,9 +57,7 @@ public class NetStatus extends WAStatusPage { @Override public Templator htmlResponse(WAContext context, HttpHeader client_info, Map session, Map cookie, Map request) throws IOException { - if (tmpl == null) - tmpl = new Templator(FileUtil.getContent(FileUtil.find(TEMPLATE))); - return tmpl; + return new Templator(FileUtil.getContent(FileUtil.find(TEMPLATE))); } @Override