diff --git a/src/wa/server/page/MainPage.java b/src/wa/server/page/MainPage.java new file mode 100755 index 0000000..bd1689d --- /dev/null +++ b/src/wa/server/page/MainPage.java @@ -0,0 +1,24 @@ +package wa.server.page; + +import wa.server.WAContext; +import zutil.net.http.HttpHeader; +import zutil.parser.Templator; + +import java.io.IOException; +import java.util.Map; + +/** + * Created by Ziver on 2016-07-23. + */ +public class MainPage extends WAPage { + + + public MainPage(){ + super("/"); + } + + @Override + public Templator htmlResponse(WAContext context, HttpHeader client_info, Map session, Map cookie, Map request) throws IOException { + return null; + } +} diff --git a/src/wa/server/page/ServiceStatusPage.java b/src/wa/server/page/ServiceStatusPage.java index 864caf8..2a88acb 100755 --- a/src/wa/server/page/ServiceStatusPage.java +++ b/src/wa/server/page/ServiceStatusPage.java @@ -42,21 +42,25 @@ import java.util.logging.Logger; */ public class ServiceStatusPage extends WAPage { private static final Logger log = LogUtil.getLogger(); + + public static final String PAGE_NAME = "status"; public static final String NAVIGATION_NAME = "Service Status"; private static final String TMPL_FILE = "WebContent/page/ServiceStatusPage.tmpl"; private ArrayList services; - public ServiceStatusPage(WAServiceStatus ss){ - services = new ArrayList<>(); - services.add(ss); - } + public ServiceStatusPage(){ + super(WAServicePage.NAVIGATION_NAME +"/"+ PAGE_NAME); this.services = WAContext.getPluginManager().toArray(WAServiceStatus.class); Navigation nav = WAContext.getRootNav().createSubNav(WAServicePage.NAVIGATION_NAME) - .createSubNav(NAVIGATION_NAME).setWeight(-100); + .createSubNav(getPageName(), NAVIGATION_NAME).setWeight(-100); + } + public ServiceStatusPage(WAServiceStatus ss){ + services = new ArrayList<>(); + services.add(ss); } diff --git a/src/wa/server/page/ConfigPage.java b/src/wa/server/page/WAConfigPage.java similarity index 70% rename from src/wa/server/page/ConfigPage.java rename to src/wa/server/page/WAConfigPage.java index 97b0a42..fec16b8 100755 --- a/src/wa/server/page/ConfigPage.java +++ b/src/wa/server/page/WAConfigPage.java @@ -1,122 +1,139 @@ -/* - * 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.WAConfigEntry; -import wa.server.plugin.WAServiceConfig; -import zutil.io.file.FileUtil; -import zutil.log.LogUtil; -import zutil.net.http.HttpHeader; -import zutil.parser.DataNode; -import zutil.parser.Templator; -import zutil.ui.Configurator; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A dynamic configuration page where a list of the same - * Bean type can be configured - * - * Created by Ziver on 2015-07-27. - */ -public class ConfigPage extends WAPage { - private static final Logger log = LogUtil.getLogger(); - private static final String TMPL_FILE = "WebContent/page/ConfigPage.tmpl"; - - private WAServiceConfig config; - - - public ConfigPage(WAServiceConfig conf) { - this.config = conf; - } - - - @Override - public Templator htmlResponse(WAContext context, - HttpHeader client_info, - Map session, - Map cookie, - Map request) { - try { - List confObjs = config.getConfigData(); - ArrayList> confList = new ArrayList<>(); - for(Object obj : confObjs){ - confList.add(new Configurator(obj)); - } - - // Actions - int index = Integer.parseInt(request.get("id")); - Configurator target = findObj(confList, index); - switch (request.get("action")){ - case "create": - target = new Configurator(config.createConfig()).applyConfiguration(); - case "modify": - target.setValues(request).applyConfiguration(); - break; - case "delete": - config.deleteConfig(index); - break; - case "enable": - target.getObject().setEnabled(true); - break; - case "disable": - target.getObject().setEnabled(false); - break; - } - - // Prepare Output - Templator tmpl = new Templator(FileUtil.find(TMPL_FILE)); - tmpl.set("params", Configurator.getConfiguration( - config.getConfigClass())); - tmpl.set("data", confList); - return tmpl; - } catch (IOException e) { - log.log(Level.SEVERE, null, e); - } - return null; - } - - @Override - public DataNode jsonResponse(WAContext context, - HttpHeader client_info, - Map session, - Map cookie, - Map request) { - return null; - } - - - private static Configurator findObj(List> list, int id){ - for (Configurator conf : list) { - if(conf.getObject().getId() == id) - return conf; - } - return null; - } -} +/* + * 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.WAConfigEntry; +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.Configurator; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * A dynamic configuration page where a list of the same + * Bean type can be configured + * + * Created by Ziver on 2015-07-27. + */ +public abstract class WAConfigPage extends WAPage { + private static final Logger log = LogUtil.getLogger(); + private static final String TEMPLATE = "WebContent/page/ConfigPage.tmpl"; + + + + public WAConfigPage(String serviceName, String name, String niceName) { + super(WAServicePage.NAVIGATION_NAME +"/"+ serviceName +"/"+ name); + WAContext.getRootNav().createSubNav(WAServicePage.NAVIGATION_NAME).createSubNav(serviceName) + .createSubNav(name, niceName); + } + + + @Override + public Templator htmlResponse(WAContext context, + HttpHeader client_info, + Map session, + Map cookie, + Map request) { + try { + List confObjs = getConfigData(); + ArrayList> confList = new ArrayList<>(); + for(Object obj : confObjs){ + confList.add(new Configurator(obj)); + } + + // Actions + int id = Integer.parseInt(request.get("id")); + Configurator target = findObj(confList, id); + switch (request.get("action")){ + case "create": + target = new Configurator(createConfig()).applyConfiguration(); + case "modify": + target.setValues(request).applyConfiguration(); + break; + case "delete": + deleteConfig(id); + break; + case "enable": + target.getObject().setEnabled(true); + break; + case "disable": + target.getObject().setEnabled(false); + break; + } + + // Prepare Output + Templator tmpl = new Templator(FileUtil.find(TEMPLATE)); + tmpl.set("params", Configurator.getConfiguration( + getConfigClass())); + tmpl.set("data", confList); + return tmpl; + } catch (IOException e) { + log.log(Level.SEVERE, null, e); + } + return null; + } + + + + private static Configurator findObj(List> list, int id){ + for (Configurator conf : list) { + if(conf.getObject().getId() == id) + return conf; + } + return null; + } + + + + + public abstract WAConfigEntry createConfig(); + public abstract void deleteConfig(int id); + + /** + * Configure service with current configuration data + */ + public abstract void configure() throws Exception; + + + + /** + * @return a list of configuration objects, the object + * configuration can be changed with the + * {@link zutil.ui.Configurator} class. + */ + public abstract List getConfigData(); + + /** + * @return the class that contains the configuration data + */ + public abstract Class getConfigClass(); +} diff --git a/src/wa/server/page/WAPage.java b/src/wa/server/page/WAPage.java index d52b127..2007f3b 100755 --- a/src/wa/server/page/WAPage.java +++ b/src/wa/server/page/WAPage.java @@ -51,6 +51,10 @@ public abstract class WAPage implements HttpPage{ public WAPage() { + this(null); + } + public WAPage(String pageName) { + this.pageName = pageName; try { tmpl = new Templator(FileUtil.find(TMPL_FILE)); } catch(IOException e){ @@ -104,9 +108,6 @@ public abstract class WAPage implements HttpPage{ } - public void setPageName(String pageName){ - this.pageName = pageName; - } public String getPageName(){ return pageName; } diff --git a/src/wa/server/page/WAServicePage.java b/src/wa/server/page/WAServicePage.java index 3110dfb..4386975 100755 --- a/src/wa/server/page/WAServicePage.java +++ b/src/wa/server/page/WAServicePage.java @@ -25,7 +25,6 @@ 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; @@ -34,9 +33,7 @@ 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; /** @@ -52,11 +49,11 @@ public abstract class WAServicePage extends WAPage { private LogPage logPage; - public WAServicePage(String pageName, String serviceName){ - super.setPageName("service/"+pageName); + public WAServicePage(String name, String niceName){ + super("service/"+name); - Navigation rootNav = WAContext.getRootNav().createSubNav(NAVIGATION_NAME).setWeight(100); - Navigation serviceNav = rootNav.createSubNav(getPageName(), serviceName); + WAContext.getRootNav().createSubNav(NAVIGATION_NAME).setWeight(100) + .createSubNav(getPageName(), niceName); statusPage = new ServiceStatusPage(getStatus()); logPage = new LogPage(getLog()); @@ -97,4 +94,5 @@ public abstract class WAServicePage extends WAPage { * @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/page/WAStatusPage.java b/src/wa/server/page/WAStatusPage.java index 25ecd7f..9210897 100755 --- a/src/wa/server/page/WAStatusPage.java +++ b/src/wa/server/page/WAStatusPage.java @@ -32,11 +32,11 @@ public abstract class WAStatusPage extends WAPage { public static final String NAVIGATION_NAME = "Status"; - public WAStatusPage(String subPageName, String niceName){ - super.setPageName("status/"+subPageName); + public WAStatusPage(String name, String niceName){ + super("status/"+name); WAContext.getRootNav().createSubNav(NAVIGATION_NAME) - .setWeight(0).createSubNav(this.getPageName(), niceName); + .setWeight(-100).createSubNav(this.getPageName(), niceName); } diff --git a/src/wa/server/plugin.json b/src/wa/server/plugin.json index eabeca4..a763ef5 100755 --- a/src/wa/server/plugin.json +++ b/src/wa/server/plugin.json @@ -2,6 +2,7 @@ "version": "1.0", "name": "WA Core", "interfaces": [ + {"wa.server.page.WAPage": "wa.server.page.MainPage"}, {"wa.server.page.WAPage": "wa.server.page.ServiceStatusPage"} ] } \ No newline at end of file diff --git a/src/wa/server/plugin/WAServiceConfig.java b/src/wa/server/plugin/WAServiceConfig.java deleted file mode 100755 index d7d71e3..0000000 --- a/src/wa/server/plugin/WAServiceConfig.java +++ /dev/null @@ -1,43 +0,0 @@ -package wa.server.plugin; - - -import java.util.List; - -public interface WAServiceConfig { - /** - * @return the String name of this configuration type - */ - String getName(); - - /** - * Read in current configuration data - */ - //public void read() throws Exception; - - /** - * Save configured data to disk or database - */ - //public void save() throws Exception; - - WAConfigEntry createConfig(); - void deleteConfig(int id); - - /** - * Configure service with current configuration data - */ - void configure() throws Exception; - - - - /** - * @return a list of configuration objects, the object - * configuration can be changed with the - * {@link zutil.ui.Configurator} class. - */ - List getConfigData(); - - /** - * @return the class that contains the configuration data - */ - Class getConfigClass(); -} diff --git a/src/wa/server/plugin/apache/ApacheConfigVirtualHost.java b/src/wa/server/plugin/apache/ApacheConfigVirtualHost.java index fd8152d..3118edb 100755 --- a/src/wa/server/plugin/apache/ApacheConfigVirtualHost.java +++ b/src/wa/server/plugin/apache/ApacheConfigVirtualHost.java @@ -2,8 +2,8 @@ package wa.server.plugin.apache; import wa.server.WAConstants; import wa.server.WAContext; +import wa.server.page.WAConfigPage; import wa.server.plugin.WAConfigEntry; -import wa.server.plugin.WAServiceConfig; import wa.server.util.ConfigFileUtil; import zutil.db.bean.DBBean; import zutil.db.bean.DBBean.DBTable; @@ -18,8 +18,10 @@ import java.util.ArrayList; import java.util.List; -public class ApacheConfigVirtualHost implements WAServiceConfig{ - private static final String CONFIG_NAME = "Apache Virtual Host"; +public class ApacheConfigVirtualHost extends WAConfigPage { + private static final String CONFIG_NAME = "vhost"; + private static final String NAVIGATION_NAME = "Apache Virtual Host"; + private static final String APACHE_MAIN_CONFIG_FILE = "/apache2/apache2.conf"; private static final String APACHE_SITE_AVAILABLE_PATH = "/apache2/site-available/"; private static final String STATIC_PRE_CONF = "wa/server/plugin/apache/apache_default.config"; @@ -28,14 +30,11 @@ public class ApacheConfigVirtualHost implements WAServiceConfig{ public ApacheConfigVirtualHost() throws SQLException { + super(ApacheService.NAVIGATION_NAME, CONFIG_NAME, NAVIGATION_NAME); vhosts = DBBean.load(WAContext.getDB(), ApacheVirtualHostEntry.class); } - @Override - public String getName() { - return CONFIG_NAME; - } public WAConfigEntry createConfig(){ return new ApacheVirtualHostEntry(); diff --git a/src/wa/server/plugin/apache/ApacheService.java b/src/wa/server/plugin/apache/ApacheService.java index a287238..21b6bfc 100755 --- a/src/wa/server/plugin/apache/ApacheService.java +++ b/src/wa/server/plugin/apache/ApacheService.java @@ -24,20 +24,16 @@ package wa.server.plugin.apache; import wa.server.page.WAServicePage; import wa.server.plugin.*; -import zutil.log.LogUtil; - -import java.sql.SQLException; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Created by Ziver on 2014-12-23. */ public class ApacheService extends WAServicePage { - public static final String SERVICE_NAME = "Apache2"; + protected static final String SERVICE_NAME = "apache"; + protected static final String NAVIGATION_NAME = "Apache2"; public ApacheService() { - super("apache", SERVICE_NAME); + super(SERVICE_NAME, NAVIGATION_NAME); } @@ -56,4 +52,5 @@ public class ApacheService extends WAServicePage { public WAInstaller getInstaller() { return new ApacheInstaller(); } + } diff --git a/src/wa/server/plugin/apache/ApacheStatus.java b/src/wa/server/plugin/apache/ApacheStatus.java index 91e17d2..53a87fb 100755 --- a/src/wa/server/plugin/apache/ApacheStatus.java +++ b/src/wa/server/plugin/apache/ApacheStatus.java @@ -42,7 +42,7 @@ public class ApacheStatus extends WAServiceStatus { @Override public String getName() { - return ApacheService.SERVICE_NAME; + return ApacheService.NAVIGATION_NAME; } @Override diff --git a/src/wa/server/plugin/apache/plugin.json b/src/wa/server/plugin/apache/plugin.json index 7d3009d..13e6a63 100755 --- a/src/wa/server/plugin/apache/plugin.json +++ b/src/wa/server/plugin/apache/plugin.json @@ -2,8 +2,8 @@ "version": "1.0", "name": "Apache Web Server", "interfaces": [ - {"wa.server.page.WAServicePage": "wa.server.plugin.apache.ApacheService"}, + {"wa.server.page.WAPage": "wa.server.plugin.apache.ApacheService"}, {"wa.server.plugin.WAServiceStatus": "wa.server.plugin.apache.ApacheStatus"}, - {"wa.server.page.WAConfigPage": "wa.server.plugin.apache.ApacheConfigVirtualHost"} + {"wa.server.page.WAPage": "wa.server.plugin.apache.ApacheConfigVirtualHost"} ] } \ No newline at end of file diff --git a/src/wa/server/plugin/hwstatus/plugin.json b/src/wa/server/plugin/hwstatus/plugin.json index d5a32a1..8d75c00 100755 --- a/src/wa/server/plugin/hwstatus/plugin.json +++ b/src/wa/server/plugin/hwstatus/plugin.json @@ -2,8 +2,8 @@ "version": "1.0", "name": "HW Status", "interfaces": [ - {"wa.server.plugin.WAPage": "wa.server.plugin.hwstatus.HwStatus"}, - {"wa.server.plugin.WAPage": "wa.server.plugin.hwstatus.HDDStatus"}, - {"wa.server.plugin.WAPage": "wa.server.plugin.hwstatus.NetStatus"} + {"wa.server.page.WAPage": "wa.server.plugin.hwstatus.HwStatus"}, + {"wa.server.page.WAPage": "wa.server.plugin.hwstatus.HDDStatus"}, + {"wa.server.page.WAPage": "wa.server.plugin.hwstatus.NetStatus"} ] } \ No newline at end of file diff --git a/src/wa/server/plugin/nutups/plugin.json b/src/wa/server/plugin/nutups/plugin.json index fc871a8..1febc1f 100755 --- a/src/wa/server/plugin/nutups/plugin.json +++ b/src/wa/server/plugin/nutups/plugin.json @@ -2,6 +2,6 @@ "version": "1.0", "name": "NUT UPS", "interfaces": [ - {"wa.server.plugin.WAPage": "wa.server.plugin.nutups.UPSStatus"} + {"wa.server.page.WAPage": "wa.server.plugin.nutups.UPSStatus"} ] } \ No newline at end of file diff --git a/src/wa/server/plugin/tomcat/plugin.json b/src/wa/server/plugin/tomcat/plugin.json index 97ce091..ede07f1 100755 --- a/src/wa/server/plugin/tomcat/plugin.json +++ b/src/wa/server/plugin/tomcat/plugin.json @@ -2,7 +2,7 @@ "version": "1.0", "name": "Tomcat", "interfaces": { - "wa.server.plugin.WAService": "wa.server.plugin.apache.TomcatService", + "wa.server.page.WAServicePage": "wa.server.plugin.apache.TomcatService", "wa.server.plugin.WAServiceStatus": "wa.server.plugin.tomcat.TomcatStatus" } } \ No newline at end of file