Some small changes to method names

This commit is contained in:
Ziver Koc 2015-07-15 12:58:30 +00:00
parent 4ece2b0cd2
commit 1053713d15
13 changed files with 61 additions and 167 deletions

View file

@ -6,6 +6,9 @@ body{
margin-top: 40px; /* to offset top-bar */
/*margin-bottom: 30px; /* Margin bottom by footer height */
}
table{
font-size: 100%;
}
#top-bar{
height: 41px;

View file

@ -1,133 +1,5 @@
<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">
{{service_status}}
$(function() {
updateCpuChart();
updateMemChart();
updateProcTable();
});
{{service_logs}}
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>

View file

@ -2,12 +2,15 @@ package wa.server;
import java.io.File;
import zutil.db.DBConnection;
import zutil.osal.OSAbstractionLayer;
import zutil.osal.OSAbstractionLayer.OSType;
public class WAConstants {
public static final String DB_FILE_NAME = "webadmin.db";
public static final String DB_TABLE_PREFIX = "wa";
public static DBConnection db;
public static final String WA_ROOT_PATH_LINUX = "/";
public static final String WA_ROOT_PATH_WINDOWS = "C:\\webadmin\\";
@ -22,7 +25,7 @@ public class WAConstants {
static{
OSAbstractionLayer os = OSAbstractionLayer.getInstance();
if(os.getOSType() == OSType.Linux){
configPath = new File(WA_ROOT_PATH_LINUX + WA_BASE_CONFIG_PATH);
}
@ -32,10 +35,23 @@ public class WAConstants {
else {
configPath = null;
}
if(configPath != null){
try {
db = new DBConnection(DBConnection.DBMS.SQLite, configPath.getAbsolutePath() + DB_FILE_NAME);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
public static File getConfigFile(String name){
return new File(configPath, name);
}
public static DBConnection getDB(){
return db;
}
}

View file

@ -24,9 +24,8 @@ package wa.server.page;
import wa.server.WAContext;
import wa.server.page.struct.WANavigation;
import wa.server.plugin.WAConfiguration;
import wa.server.plugin.WAServiceConfig;
import wa.server.plugin.WAService;
import wa.server.plugin.WAServiceStatus;
import zutil.io.file.FileUtil;
import zutil.log.LogUtil;
import zutil.net.http.HttpHeaderParser;
@ -59,7 +58,7 @@ public class ServicePage implements WAPage {
for(WAService plugin : services) {
statuses.add(new ServiceStatusPage(plugin.getStatus()));
nav.addSubNav(new WANavigation(plugin.getName(), plugin));
for(WAConfiguration conf : plugin.getConfigurations()){
for(WAServiceConfig conf : plugin.getConfigurations()){
}
}

View file

@ -1,11 +0,0 @@
package wa.server.plugin;
import java.io.IOException;
import java.sql.SQLException;
import zutil.db.DBConnection;
public interface WAConfiguration {
public void read(DBConnection db) throws SQLException;
public void save(DBConnection db) throws IOException;
}

View file

@ -26,6 +26,7 @@ package wa.server.plugin;
* Created by Ziver on 2014-11-09.
*/
public interface WAInstaller {
public boolean isInstalled();
public void install();
public void uninstall();
}

View file

@ -17,5 +17,5 @@ public interface WAService {
/**
* @return a array of configuration objects
*/
public WAConfiguration[] getConfigurations();
public WAServiceConfig[] getConfigurations();
}

View file

@ -0,0 +1,11 @@
package wa.server.plugin;
import java.io.IOException;
import java.sql.SQLException;
import zutil.db.DBConnection;
public interface WAServiceConfig {
public void read() throws SQLException;
public void save() throws IOException;
}

View file

@ -8,12 +8,12 @@ import java.util.LinkedList;
import java.util.List;
import wa.server.WAConstants;
import wa.server.plugin.WAConfiguration;
import wa.server.plugin.WAServiceConfig;
import wa.server.util.ConfigFileUtil;
import zutil.db.DBConnection;
import zutil.io.file.FileUtil;
public class ApacheConfiguration implements WAConfiguration {
public class ApacheConfig implements WAServiceConfig {
private static final String APACHE_CONF_FILE = "wa_apache_vhost.conf";
private static final String APACHE_MAIN_CONFIG_FILE = "/etc/apache2/apache2.conf";
private static final String STATIC_PRE_CONF = "wa/server/plugin/apache/apache_default.config";
@ -22,20 +22,21 @@ public class ApacheConfiguration implements WAConfiguration {
List<ApacheConfigVirtualHost> vhosts;
public ApacheConfiguration(){
public ApacheConfig(){
vhosts = new LinkedList<ApacheConfigVirtualHost>();
}
@Override
public void read(DBConnection db) throws SQLException {
public void read() throws SQLException {
DBConnection db = WAConstants.getDB();
vhosts = ApacheConfigVirtualHost.load(db, ApacheConfigVirtualHost.class);
}
@Override
public void save(DBConnection db) throws IOException {
public void save() throws IOException {
File file = WAConstants.getConfigFile(APACHE_CONF_FILE);
// Update Man configuration file
// Update main configuration file
ConfigFileUtil.writeBetweenBoundary(
new File(APACHE_MAIN_CONFIG_FILE),
"#",
@ -48,9 +49,7 @@ public class ApacheConfiguration implements WAConfiguration {
out.println("######################################");
out.println("# vhost.php");
for(ApacheConfigVirtualHost vhost : vhosts){
if(vhost.isTomcatApp())
writeTomcatVhost(out, vhost);
else if(vhost.isSSL())
if(vhost.isSSL())
writeSSLVhost(out, vhost);
else
writeVhost(out, vhost);

View file

@ -9,7 +9,6 @@ public class ApacheConfigVirtualHost extends DBBean{
protected String domain;
protected String path;
protected boolean ssl;
protected boolean tomcat;
@ -31,10 +30,4 @@ public class ApacheConfigVirtualHost extends DBBean{
public void setSSL(boolean ssl) {
this.ssl = ssl;
}
public boolean isTomcatApp() {
return tomcat;
}
public void setTomcatApp(boolean tomcat) {
this.tomcat = tomcat;
}
}

View file

@ -31,6 +31,17 @@ import zutil.osal.app.linux.AptGet;
public class ApacheInstaller implements WAInstaller {
private static final String PACKAGES = "apache php5 php5-mcrypt php5-gd imagemagick";
@Override
public boolean isInstalled() {
String[] tmp = PACKAGES.split(" ");
for(String pkgName : tmp){
AptGet.Package pkg = AptGet.getPackage(PACKAGES);
if( pkg == null || pkg.getCurrentState() != AptGet.Package.PackageState.Installed)
return false;
}
return true;
}
@Override
public void install() {
AptGet.install(PACKAGES);

View file

@ -22,7 +22,7 @@
package wa.server.plugin.apache;
import wa.server.plugin.WAConfiguration;
import wa.server.plugin.WAServiceConfig;
import wa.server.plugin.WAInstaller;
import wa.server.plugin.WAService;
import wa.server.plugin.WAServiceStatus;
@ -60,7 +60,7 @@ public class ApacheService implements WAService {
}
@Override
public WAConfiguration[] getConfigurations() {
return new WAConfiguration[0];
public WAServiceConfig[] getConfigurations() {
return new WAServiceConfig[0];
}
}

View file

@ -9,7 +9,7 @@
<div class="panel-body">
<center><canvas id="mem-chart" height="300"></canvas></center>
<br>
<table class="table">
<table class="table table-hover">
<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>