diff --git a/resources/WebContent/css/main.css b/resources/WebContent/css/main.css
index 91887c6..e60f6cb 100644
--- a/resources/WebContent/css/main.css
+++ b/resources/WebContent/css/main.css
@@ -7,6 +7,7 @@ body{
/*margin-bottom: 30px; /* Margin bottom by footer height */
}
table{
+ font-family: sans-serif;
font-size: 100%;
}
diff --git a/resources/WebContent/page/ServiceStatusPage.tmpl b/resources/WebContent/page/ServiceStatusPage.tmpl
index d432bcc..ffc9cfc 100644
--- a/resources/WebContent/page/ServiceStatusPage.tmpl
+++ b/resources/WebContent/page/ServiceStatusPage.tmpl
@@ -1,7 +1,7 @@
Service Status
-
+
diff --git a/resources/WebContent/index.tmpl b/resources/WebContent/page/index.tmpl
similarity index 84%
rename from resources/WebContent/index.tmpl
rename to resources/WebContent/page/index.tmpl
index 2313559..10bc3ab 100644
--- a/resources/WebContent/index.tmpl
+++ b/resources/WebContent/page/index.tmpl
@@ -19,8 +19,8 @@
@@ -30,21 +30,21 @@
{{title}}
{{#top-nav}}
- {{^.sub_navs.length}}
+ {{^.subNav.length}}
- {{.name}}
- {{/.sub_navs.length}}
- {{#.sub_navs.length}}
+ {{/.subNav.length}}
+ {{#.subNav.length}}
-
{{.name}}
- {{/.sub_navs.length}}
+ {{/.subNav.length}}
{{/top-nav}}
@@ -55,21 +55,21 @@
diff --git a/resources/WebContent/index_original.html b/resources/WebContent/page/index_original.html
similarity index 100%
rename from resources/WebContent/index_original.html
rename to resources/WebContent/page/index_original.html
diff --git a/src/wa/server/WAAbstractPage.java b/src/wa/server/WAAbstractPage.java
index 576b758..ea67a42 100644
--- a/src/wa/server/WAAbstractPage.java
+++ b/src/wa/server/WAAbstractPage.java
@@ -46,7 +46,7 @@ import java.util.logging.Logger;
*/
public class WAAbstractPage implements HttpPage{
private static final Logger log = LogUtil.getLogger();
- private static final String TMPL_FILE = "WebContent/index.tmpl";
+ private static final String TMPL_FILE = "WebContent/page/index.tmpl";
private List pages;
private Templator tmpl;
@@ -100,7 +100,7 @@ public class WAAbstractPage implements HttpPage{
tmpl.set("top-nav", context.getNavigation());
tmpl.set("side-nav-show", true);
if(breadcrumb.size() >= 1)
- tmpl.set("side-nav", breadcrumb.get(0).getSubNav());
+ tmpl.set("side-nav", breadcrumb.get(0).getSubNavs());
tmpl.set("breadcrumb", breadcrumb);
tmpl.set("alerts", context.getAlerts());
//tmpl.set("footer", null);
@@ -109,7 +109,8 @@ public class WAAbstractPage implements HttpPage{
if(page != null)
content = page.htmlResponse(context, client_info, session, cookie, request);
if(content != null) {
- content.set("nav", context.getBreadcrumb().get(1));
+ if(!breadcrumb.isEmpty())
+ content.set("nav", breadcrumb.get(breadcrumb.size() - 1));
tmpl.set("content", content.compile());
}
diff --git a/src/wa/server/WAContext.java b/src/wa/server/WAContext.java
index d9a4ce8..48b2242 100644
--- a/src/wa/server/WAContext.java
+++ b/src/wa/server/WAContext.java
@@ -26,7 +26,6 @@ import wa.server.page.struct.WAAlert;
import wa.server.page.struct.WANavigation;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -44,7 +43,7 @@ public class WAContext {
nav = WANavigation.getRootNav();
// Breadcrumb
- breadcrumb = WANavigation.getNavResource(request);
+ breadcrumb = WANavigation.getNavBreadcrumb(request);
}
diff --git a/src/wa/server/page/ServicePage.java b/src/wa/server/page/ServicePage.java
index 3571af3..4d45e70 100644
--- a/src/wa/server/page/ServicePage.java
+++ b/src/wa/server/page/ServicePage.java
@@ -48,21 +48,25 @@ public class ServicePage implements WAPage {
private static final String TMPL_FILE = "WebContent/page/ServicePage.tmpl";
private ArrayList services;
- private ArrayList statuses;
+ private ServiceStatusPage rootStatusPage;
+ private ArrayList statusPages;
public ServicePage(PluginManager pluginManager){
this.services = pluginManager.toArray(WAService.class);
- this.statuses = new ArrayList<>();
+ this.rootStatusPage = new ServiceStatusPage(pluginManager);
+ this.statusPages = new ArrayList<>();
- WANavigation nav = new WANavigation(NAVIGATION_NAME, this);
+ WANavigation nav = WANavigation.getRootNav(NAVIGATION_NAME);
+ nav.setResource(this);
for(WAService plugin : services) {
- statuses.add(new ServiceStatusPage(plugin.getStatus()));
- nav.addSubNav(new WANavigation(plugin.getName(), plugin));
- for(WAServiceConfig conf : plugin.getConfigurations()){
+ statusPages.add(new ServiceStatusPage(plugin.getStatus()));
+ WANavigation serviceNav = nav.getSubNav(plugin.getName());
+ serviceNav.setResource(plugin);
+ for(WAServiceConfig conf : plugin.getConfigurations()){
+ //serviceNav.getSubNav(conf.getName()).setResource(conf);
}
}
- WANavigation.addRootNav(nav);
}
@@ -74,16 +78,20 @@ public class ServicePage implements WAPage {
Map request) {
try {
- int index = services.indexOf(context.getBreadcrumb().get(1).getResource());
- if(index < 0)
- return null;
- WAService obj = services.get(index);
- ServiceStatusPage statusPage = statuses.get(index);
- Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
- tmpl.set("service_status",
- statusPage.htmlResponse(context, client_info, session, cookie, request).compile());
- return tmpl;
+ int index = services.indexOf(context.getBreadcrumb().get(1).getResource());
+ if (index >= 0) {
+ WAService obj = services.get(index);
+ ServiceStatusPage statusPage = statusPages.get(index);
+
+ Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
+ tmpl.set("service_status",
+ statusPage.htmlResponse(context, client_info, session, cookie, request).compile());
+ return tmpl;
+ }
+ else{ // root page
+ return rootStatusPage.htmlResponse(context, client_info, session, cookie, request);
+ }
}catch (IOException e){
log.log(Level.SEVERE, null, e);
diff --git a/src/wa/server/page/ServiceStatusPage.java b/src/wa/server/page/ServiceStatusPage.java
index 522d3ea..9a493db 100644
--- a/src/wa/server/page/ServiceStatusPage.java
+++ b/src/wa/server/page/ServiceStatusPage.java
@@ -32,7 +32,6 @@ import zutil.parser.DataNode;
import zutil.parser.Templator;
import zutil.plugin.PluginManager;
-import javax.xml.crypto.Data;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
@@ -57,8 +56,8 @@ public class ServiceStatusPage implements WAPage {
public ServiceStatusPage(PluginManager pluginManager){
this.services = pluginManager.toArray(WAServiceStatus.class);
- WANavigation.getRootNav(ServicePage.NAVIGATION_NAME).addSubNav(
- new WANavigation(NAVIGATION_NAME, this));
+ WANavigation nav = WANavigation.getRootNav(ServicePage.NAVIGATION_NAME).getSubNav(NAVIGATION_NAME);
+ nav.setResource(this);
}
diff --git a/src/wa/server/page/StatusPage.java b/src/wa/server/page/StatusPage.java
index cf1be9d..66bdd3e 100644
--- a/src/wa/server/page/StatusPage.java
+++ b/src/wa/server/page/StatusPage.java
@@ -44,10 +44,10 @@ public class StatusPage implements WAPage {
public StatusPage(PluginManager pluginManager){
this.plugins = pluginManager.toArray(WAStatus.class);
- WANavigation nav = new WANavigation(NAVIGATION_NAME, this);
+ WANavigation nav = WANavigation.getRootNav(NAVIGATION_NAME);
+ nav.setResource(this);
for(WAStatus plugin : plugins)
- nav.addSubNav(new WANavigation(plugin.getName(), plugin));
- WANavigation.addRootNav(nav);
+ nav.getSubNav(plugin.getName()).setResource(plugin);
}
diff --git a/src/wa/server/page/struct/WANavigation.java b/src/wa/server/page/struct/WANavigation.java
index 3a312c0..b75a75f 100644
--- a/src/wa/server/page/struct/WANavigation.java
+++ b/src/wa/server/page/struct/WANavigation.java
@@ -27,46 +27,49 @@ import java.util.*;
/**
* Created by Ziver on 2015-04-02.
*/
-public class WANavigation {
- private static int nextId;
- private static List root_nav = new ArrayList();
- private static HashMap nav_map = new HashMap();
+public class WANavigation implements Iterable{
+ private static int nextId = 0;
+ private static HashMap navMap = new HashMap();
+ private static WANavigation rootNav = new WANavigation(null);
private int id;
private String url;
private String name;
- private ArrayList sub_navs;
+ private ArrayList subNav;
- private WANavigation parent_nav;
+ private WANavigation parentNav;
private Object resource;
- public WANavigation(String name) {
+ private WANavigation(String name) {
this.id = nextId++;
- this.nav_map.put(this.id, this);
+ this.navMap.put(this.id, this);
this.url = "?i="+this.id;
this.name = name;
- this.sub_navs = new ArrayList<>();
- }
- public WANavigation(String name, Object resource) {
- this(name);
- this.setResource(resource);
+ this.subNav = new ArrayList<>();
}
- public void addSubNav(WANavigation subNav) {
- this.sub_navs.add(subNav);
+ @Override
+ public Iterator iterator() {
+ return subNav.iterator();
+ }
+ public List getSubNavs() {
+ return subNav;
+ }
+ public WANavigation getSubNav(String name) {
+ for(WANavigation nav : subNav) {
+ if(nav.equals(name))
+ return nav;
+ }
+ WANavigation nav = new WANavigation(name);
+ this.addSubNav(nav);
+ return nav;
+ }
+ private void addSubNav(WANavigation subNav) {
+ this.subNav.add(subNav);
subNav.setParentNav(this );
}
- public List getSubNav() {
- return sub_navs;
- }
- public Object getSubNav(String name) {
- int index = sub_navs.indexOf(name);
- if(index >= 0)
- return sub_navs.get(index);
- return null;
- }
public String getName(){
return name;
@@ -79,9 +82,10 @@ public class WANavigation {
}
private void setParentNav(WANavigation nav){
- this.parent_nav = nav;
+ this.parentNav = nav;
}
+ @Override
public boolean equals(Object o){
if(o instanceof String)
return this.name.equals(o);
@@ -90,27 +94,20 @@ public class WANavigation {
}
- public static void addRootNav(WANavigation nav){
- getRootNav().add(nav);
- }
public static List getRootNav(){
- return root_nav;
+ return rootNav.getSubNavs();
}
public static WANavigation getRootNav(String name){
- for(WANavigation nav : root_nav){
- if(nav.getName().equals(name))
- return nav;
- }
- return null;
+ return rootNav.getSubNav(name);
}
- public static List getNavResource(Map request) {
+ public static List getNavBreadcrumb(Map request) {
LinkedList list = new LinkedList();
if(request.containsKey("i")){
- WANavigation current = nav_map.get(Integer.parseInt(request.get("i")));
- while(current != null){
+ WANavigation current = navMap.get(Integer.parseInt(request.get("i")));
+ while(current != null && current != rootNav){
list.addFirst(current);
- current = current.parent_nav;
+ current = current.parentNav;
}
}
return list;
diff --git a/src/wa/server/plugin/apache/ApacheConfig.java b/src/wa/server/plugin/apache/ApacheConfig.java
index a1d1c23..86b35d2 100644
--- a/src/wa/server/plugin/apache/ApacheConfig.java
+++ b/src/wa/server/plugin/apache/ApacheConfig.java
@@ -26,7 +26,6 @@ public class ApacheConfig implements WAServiceConfig {
vhosts = new LinkedList();
}
-
@Override
public void read() throws SQLException {
DBConnection db = WAConstants.getDB();
diff --git a/src/wa/server/plugin/apache/ApacheStatus.java b/src/wa/server/plugin/apache/ApacheStatus.java
index 988c7fe..02faff4 100644
--- a/src/wa/server/plugin/apache/ApacheStatus.java
+++ b/src/wa/server/plugin/apache/ApacheStatus.java
@@ -35,7 +35,7 @@ import java.util.logging.Logger;
public class ApacheStatus extends WAServiceStatus {
private static final Logger log = LogUtil.getLogger();
- private static final String PID_FILE = "/var/run/apache2.pid";
+ private static final String PID_FILE_PATH = "/var/run/apache2.pid";
private static OSAbstractionLayer os = OSAbstractionLayer.getInstance();
@@ -58,11 +58,14 @@ public class ApacheStatus extends WAServiceStatus {
@Override
public ServiceStatusType getStatus() {
try {
- int pid = Integer.parseInt(
- FileUtil.getContent(new File(PID_FILE)));
- if(Ps.isRunning(pid))
- return ServiceStatusType.RUNNING;
- return ServiceStatusType.STOPPED;
+ File pidFile = new File(PID_FILE_PATH);
+ if(pidFile.exists()) {
+ int pid = Integer.parseInt(
+ FileUtil.getContent(pidFile));
+ if (Ps.isRunning(pid))
+ return ServiceStatusType.RUNNING;
+ return ServiceStatusType.STOPPED;
+ }
}catch(IOException e){
log.log(Level.WARNING, null, e);
}
diff --git a/src/wa/server/plugin/apache/plugin.json b/src/wa/server/plugin/apache/plugin.json
index 8829ba4..aec5df8 100644
--- a/src/wa/server/plugin/apache/plugin.json
+++ b/src/wa/server/plugin/apache/plugin.json
@@ -2,6 +2,7 @@
"version": "1.0",
"name": "Apache Web Server",
"interfaces": {
- "wa.server.plugin.WAService": "wa.server.plugin.apache.ApacheService"
+ "wa.server.plugin.WAService": "wa.server.plugin.apache.ApacheService",
+ "wa.server.plugin.WAServiceStatus": "wa.server.plugin.apache.ApacheStatus"
}
}
\ No newline at end of file
diff --git a/src/wa/server/plugin/hwstatus/NetStatus.tmpl b/src/wa/server/plugin/hwstatus/NetStatus.tmpl
index 9bee19b..2ca781e 100644
--- a/src/wa/server/plugin/hwstatus/NetStatus.tmpl
+++ b/src/wa/server/plugin/hwstatus/NetStatus.tmpl
@@ -103,7 +103,9 @@ function updateNet(){
$(element).find(".net-total-tx").html(byteToString(net.total_tx));
$(element).find(".net-dropped").html(net.dropped);
$(element).find(".net-error").html(net.error);
- $(element).find(".net-up").html( (net.up ? "UP" : "DOWN") );
+ $(element).find(".net-up").html( (net.up ?
+ "UP" :
+ "DOWN") );
$(element).find(".net-ip").html(net.ip);
$(element).find(".net-netmask").html(net.netmask);
$(element).find(".net-mac").html(net.mac);