Big changes

This commit is contained in:
Ziver Koc 2016-07-23 01:00:10 +02:00
parent f2b4cfdec7
commit c6d2981b12
15 changed files with 203 additions and 205 deletions

View file

@ -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<String, Object> session, Map<String, String> cookie, Map<String, String> request) throws IOException {
return null;
}
}

View file

@ -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<WAServiceStatus> 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);
}

View file

@ -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<String, Object> session,
Map<String, String> cookie,
Map<String, String> request) {
try {
List<?> confObjs = config.getConfigData();
ArrayList<Configurator<WAConfigEntry>> confList = new ArrayList<>();
for(Object obj : confObjs){
confList.add(new Configurator(obj));
}
// Actions
int index = Integer.parseInt(request.get("id"));
Configurator<WAConfigEntry> 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<String, Object> session,
Map<String, String> cookie,
Map<String, String> request) {
return null;
}
private static Configurator<WAConfigEntry> findObj(List<Configurator<WAConfigEntry>> list, int id){
for (Configurator<WAConfigEntry> 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<String, Object> session,
Map<String, String> cookie,
Map<String, String> request) {
try {
List<?> confObjs = getConfigData();
ArrayList<Configurator<WAConfigEntry>> confList = new ArrayList<>();
for(Object obj : confObjs){
confList.add(new Configurator(obj));
}
// Actions
int id = Integer.parseInt(request.get("id"));
Configurator<WAConfigEntry> 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<WAConfigEntry> findObj(List<Configurator<WAConfigEntry>> list, int id){
for (Configurator<WAConfigEntry> 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<? extends WAConfigEntry> getConfigData();
/**
* @return the class that contains the configuration data
*/
public abstract Class<? extends WAConfigEntry> getConfigClass();
}

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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);
}

View file

@ -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"}
]
}

View file

@ -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<? extends WAConfigEntry> getConfigData();
/**
* @return the class that contains the configuration data
*/
Class<? extends WAConfigEntry> getConfigClass();
}

View file

@ -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();

View file

@ -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();
}
}

View file

@ -42,7 +42,7 @@ public class ApacheStatus extends WAServiceStatus {
@Override
public String getName() {
return ApacheService.SERVICE_NAME;
return ApacheService.NAVIGATION_NAME;
}
@Override

View file

@ -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"}
]
}

View file

@ -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"}
]
}

View file

@ -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"}
]
}

View file

@ -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"
}
}