moved templates to WeContent folder
This commit is contained in:
parent
1d34162bb5
commit
29def452b6
16 changed files with 11465 additions and 29 deletions
|
|
@ -22,8 +22,7 @@
|
|||
|
||||
package wa.server;
|
||||
|
||||
import wa.server.WAContext;
|
||||
import wa.server.page.ServicesPage;
|
||||
import wa.server.page.ServicePage;
|
||||
import wa.server.page.StatusPage;
|
||||
import wa.server.page.WAPage;
|
||||
import wa.server.page.struct.WANavigation;
|
||||
|
|
@ -38,7 +37,6 @@ import zutil.parser.json.JSONWriter;
|
|||
import zutil.plugin.PluginManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Array;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -57,7 +55,7 @@ public class WAAbstractPage implements HttpPage{
|
|||
try {
|
||||
pages = Arrays.asList(new WAPage[] {
|
||||
new StatusPage(pluginManager),
|
||||
new ServicesPage(pluginManager)
|
||||
new ServicePage(pluginManager)
|
||||
});
|
||||
|
||||
tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||
|
|
|
|||
|
|
@ -8,10 +8,12 @@ import zutil.osal.OSAbstractionLayer.OSType;
|
|||
public class WAConstants {
|
||||
public static final String DB_TABLE_PREFIX = "wa";
|
||||
|
||||
public static String WA_BASE_CONFIG_PATH;
|
||||
public static final String WA_BASE_CONFIG_PATH_LINUX = "/etc/webadmin";
|
||||
public static final String WA_BASE_CONFIG_PATH_WINDOWS = ".";
|
||||
|
||||
|
||||
public static final String WA_ROOT_PATH_LINUX = "/";
|
||||
public static final String WA_ROOT_PATH_WINDOWS = "C:\\webadmin\\";
|
||||
public static final String WA_BASE_CONFIG_PATH = "etc/webadmin/";
|
||||
private static final File configPath;
|
||||
|
||||
public static final String WA_SSL_CERT = "cert/server.crt";
|
||||
public static final String WA_SSL_KEY = "cert/server.key";
|
||||
|
||||
|
|
@ -22,15 +24,18 @@ public class WAConstants {
|
|||
OSAbstractionLayer os = OSAbstractionLayer.getInstance();
|
||||
|
||||
if(os.getOSType() == OSType.Linux){
|
||||
WA_BASE_CONFIG_PATH = WA_BASE_CONFIG_PATH_LINUX;
|
||||
configPath = new File(WA_ROOT_PATH_LINUX + WA_BASE_CONFIG_PATH);
|
||||
}
|
||||
else if(os.getOSType() == OSType.Windows){
|
||||
WA_BASE_CONFIG_PATH = WA_BASE_CONFIG_PATH_WINDOWS;
|
||||
configPath = new File(WA_ROOT_PATH_WINDOWS + WA_BASE_CONFIG_PATH);
|
||||
}
|
||||
else {
|
||||
configPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static File getConfigFile(String name){
|
||||
return new File(WA_BASE_CONFIG_PATH, name);
|
||||
return new File(configPath, name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
package wa.server.page;
|
||||
|
||||
import wa.server.WAAbstractPage;
|
||||
import wa.server.WAContext;
|
||||
import wa.server.page.struct.WANavigation;
|
||||
import wa.server.plugin.WAService;
|
||||
|
|
@ -42,13 +41,13 @@ import java.util.logging.Logger;
|
|||
/**
|
||||
* Created by Ziver on 2015-04-06.
|
||||
*/
|
||||
public class ServicesPage implements WAPage {
|
||||
public class ServicePage implements WAPage {
|
||||
private static final Logger log = LogUtil.getLogger();
|
||||
private static final String TMPL_FILE = "";
|
||||
private static final String TMPL_FILE = "WebContent/page/ServicePage.tmpl";
|
||||
|
||||
private ArrayList<WAService> plugins;
|
||||
|
||||
public ServicesPage(PluginManager pluginManager){
|
||||
public ServicePage(PluginManager pluginManager){
|
||||
this.plugins = pluginManager.toArray(WAService.class);
|
||||
|
||||
WANavigation nav = new WANavigation("Services");
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
<div class="col-md-12"><div class="panel panel-default">
|
||||
<div class="panel-heading">Cpu Status</div>
|
||||
<div class="panel-body">
|
||||
<div><canvas id="cpu-chart" height="300"></canvas></div>
|
||||
</div>
|
||||
</div></div>
|
||||
<div class="col-md-4"><div class="panel panel-default">
|
||||
<div class="panel-heading">Memory</div>
|
||||
<div class="panel-body">
|
||||
<center><canvas id="mem-chart" height="300"></canvas></center>
|
||||
<br>
|
||||
<table class="table">
|
||||
<tr><th></th><th>Used</th><th>Free</th></tr>
|
||||
<tr><th><b>Memory</b></th>
|
||||
<td id="mem-used"></td><td id="mem-free"></td></tr>
|
||||
<tr><th><b>Swap</b></th>
|
||||
<td id="swap-used"></td><td id="swap-free"></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</div></div>
|
||||
<div class="col-md-8"><div class="panel panel-default">
|
||||
<div class="panel-heading">Process List</div>
|
||||
<div class="panel-body">
|
||||
<table id="proc-list" class="table table-hover small" data-sort-name="cpu" data-sort-order="desc">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-field="pid" data-sortable="true"><b>PID</b></th>
|
||||
<th data-field="user" data-sortable="true">User</th>
|
||||
<th data-field="cpu" data-sortable="true">CPU</th>
|
||||
<th data-field="cputime" data-sortable="true">CpuTime</th>
|
||||
<th data-field="mem" data-sortable="true">Memory(MB)</th>
|
||||
<th data-field="cmd" data-sortable="true" style="word-wrap: break-word;">Proc</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
</div></div>
|
||||
|
||||
<script language="javascript" type="text/javascript">
|
||||
|
||||
$(function() {
|
||||
updateCpuChart();
|
||||
updateMemChart();
|
||||
updateProcTable();
|
||||
});
|
||||
|
||||
|
||||
var cpu_chart = null;
|
||||
var cpu_data = {
|
||||
labels : ["","","","","","","","","","",
|
||||
"","","","","","","","","","",
|
||||
"","","","","","","","","","",],
|
||||
datasets: []
|
||||
};
|
||||
|
||||
function updateCpuChart(){
|
||||
$.getJSON("{{nav.url}}&json&cpu", function( data ) {
|
||||
// Setup graph
|
||||
if(cpu_chart == null){
|
||||
// Fill in cpus
|
||||
for(i=0; i<data['cpu'].length; ++i){
|
||||
cpu_data['datasets'].push({
|
||||
strokeColor: "rgba(151,187,205,1)",
|
||||
fillColor: "rgba(151,187,205,0.2)",
|
||||
data: [0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0]
|
||||
});
|
||||
}
|
||||
// Graph
|
||||
var ctx = $("#cpu-chart").get(0).getContext("2d");
|
||||
cpu_chart = new Chart(ctx).Line(cpu_data, {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false, // Fixes stuped behaviour with size
|
||||
datasetFill: true, pointDot: false, showTooltips: false,
|
||||
scaleOverride: true, scaleStartValue: 0, scaleStepWidth: 0.1, scaleSteps: 10, scaleIntegersOnly: false,
|
||||
animation : false,
|
||||
});
|
||||
}
|
||||
|
||||
// Update graph
|
||||
cpu_chart.addData(data['cpu'], "");
|
||||
cpu_chart.removeData();
|
||||
});
|
||||
setTimeout(updateCpuChart, 2000);
|
||||
}
|
||||
|
||||
|
||||
var mem_chart = null;
|
||||
var mem_data = [
|
||||
{
|
||||
value: 0,
|
||||
color:"#46BFBD",
|
||||
highlight: "#5AD3D1",
|
||||
label: "Used"
|
||||
},{
|
||||
value: 1,
|
||||
color: "#EEEEEE",
|
||||
highlight: "#DDDDDD",
|
||||
label: "Free"
|
||||
}
|
||||
];
|
||||
|
||||
function updateMemChart(){
|
||||
$.getJSON("{{nav.url}}&json&memory", function( data ) {
|
||||
if(mem_chart == null){
|
||||
var ctx = $("#mem-chart").get(0).getContext("2d");
|
||||
mem_chart = new Chart(ctx).Doughnut(mem_data, {
|
||||
animateScale: true
|
||||
});
|
||||
}
|
||||
mem_chart.segments[0].value = data.memory.used;
|
||||
mem_chart.segments[1].value = data.memory.free;
|
||||
mem_chart.update();
|
||||
|
||||
$("#mem-used").html(data.memory.used + " MB");
|
||||
$("#mem-free").html(data.memory.free + " MB");
|
||||
$("#swap-used").html(data.swap.used + " MB");
|
||||
$("#swap-free").html(data.swap.free + " MB");
|
||||
});
|
||||
setTimeout(updateMemChart, 5000);
|
||||
}
|
||||
|
||||
|
||||
function updateProcTable(){
|
||||
$.getJSON("{{nav.url}}&json&proc", function( data ) {
|
||||
$('#proc-list').bootstrapTable({
|
||||
data: data['proc']
|
||||
});
|
||||
});
|
||||
setTimeout(updateProcTable, 10000);
|
||||
}
|
||||
</script>
|
||||
100
src/wa/server/page/ServiceStatusPage.java
Normal file
100
src/wa/server/page/ServiceStatusPage.java
Normal file
|
|
@ -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.page.struct.WANavigation;
|
||||
import wa.server.plugin.WAService;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HttpHeaderParser;
|
||||
import zutil.parser.DataNode;
|
||||
import zutil.parser.Templator;
|
||||
import zutil.plugin.PluginManager;
|
||||
|
||||
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 ServiceStatusPage implements WAPage {
|
||||
private static final Logger log = LogUtil.getLogger();
|
||||
private static final String TMPL_FILE = "WebContent/page/ServiceStatusPage.tmpl";
|
||||
|
||||
private ArrayList<WAService> plugins;
|
||||
|
||||
public ServiceStatusPage(PluginManager pluginManager){
|
||||
this.plugins = pluginManager.toArray(WAService.class);
|
||||
|
||||
WANavigation nav = new WANavigation("Services");
|
||||
for(WAService plugin : plugins)
|
||||
nav.addSubNav(new WANavigation(plugin.getName()));
|
||||
WANavigation.addRootNav(nav);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Templator htmlResponse(WAContext context,
|
||||
HttpHeaderParser client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) {
|
||||
|
||||
try {
|
||||
WAService obj = getPlugin(context);
|
||||
|
||||
if (obj != null) {
|
||||
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||
tmpl.set("nav", context.getBreadcrumb().get(1));
|
||||
return tmpl;
|
||||
}
|
||||
}catch (IOException e){
|
||||
log.log(Level.SEVERE, null, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public DataNode jsonResponse(WAContext context,
|
||||
HttpHeaderParser client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request){
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private WAService getPlugin(WAContext context){
|
||||
if(context.getBreadcrumb().size() >= 2){
|
||||
int i = plugins.indexOf(context.getBreadcrumb().get(1).getResource());
|
||||
if(i >= 0)
|
||||
return plugins.get(i);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -72,15 +72,13 @@ public class StatusPage implements WAPage {
|
|||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request){
|
||||
|
||||
if(request.containsKey("i")) {
|
||||
DataNode root = new DataNode(DataNode.DataType.Map);
|
||||
WAStatus obj = getPlugin(context);
|
||||
if(obj != null)
|
||||
// Do JSON request in all status plugins
|
||||
DataNode root = new DataNode(DataNode.DataType.Map);
|
||||
for(WAStatus obj : plugins) {
|
||||
if (obj != null)
|
||||
obj.jsonUpdate(request, root);
|
||||
return root;
|
||||
}
|
||||
return null;
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public interface WAServiceStatus {
|
|||
public enum ServiceStatusType{
|
||||
RUNNING,
|
||||
NOT_RESPONDING,
|
||||
UNAVAILABLE,
|
||||
STOPPED,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class ApacheStatus implements WAServiceStatus {
|
|||
FileUtil.getContent(new File(PID_FILE)));
|
||||
if(Ps.isRunning(pid))
|
||||
return ServiceStatusType.RUNNING;
|
||||
return ServiceStatusType.UNAVAILABLE;
|
||||
return ServiceStatusType.STOPPED;
|
||||
}catch(IOException e){
|
||||
log.log(Level.WARNING, null, e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue