Added a Config page. Currently unreachable.
This commit is contained in:
parent
b115a9cb4f
commit
ee19d84434
11 changed files with 157 additions and 27 deletions
20
resources/WebContent/page/ConfigPage.tmpl
Normal file
20
resources/WebContent/page/ConfigPage.tmpl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<div class="col-md-12">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">Service Status</div>
|
||||
<div class="panel-body">
|
||||
<table class="table hdd-detail">
|
||||
<thead><tr>
|
||||
<th data-field="service">Service</th>
|
||||
<th data-field="status">Status</th>
|
||||
<th data-field="action" >Action</th>
|
||||
</tr></thead>
|
||||
<tr>
|
||||
<td>{{.getName()}}</td>
|
||||
<td></td>
|
||||
<td>[EDIT][DISABLE][REMOVE]</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="panel-footer">Panel footer</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -55,18 +55,18 @@
|
|||
<div id="side-bar" class="col-md-2">
|
||||
<ul class="side-menu nav nav-pills nav-stacked">
|
||||
{{#side-nav}}
|
||||
{{^.subNavs.length}}
|
||||
{{^.subNav.length}}
|
||||
<li><a href="{{.url}}">{{.name}}</a></li>
|
||||
{{/.subNavs.length}}
|
||||
{{/.subNav.length}}
|
||||
{{#.subNav.length}}
|
||||
<li class="">
|
||||
<a data-toggle="collapse" data-parent="#side-bar" href="#{{.name}}_collapse">
|
||||
{{.name}} <b class="caret"></b>
|
||||
</a>
|
||||
<ul id="{{.name}}_collapse" class="side-sub-menu collapse nav nav-pills nav-stacked ">
|
||||
{{#.subNavs}}
|
||||
{{#.subNav}}
|
||||
<li><a href="{{.url}}">{{.name}}</a></li>
|
||||
{{/.subNavs}}
|
||||
{{/.subNav}}
|
||||
</ul>
|
||||
</li>
|
||||
{{/.subNav.length}}
|
||||
|
|
|
|||
79
src/wa/server/page/ConfigPage.java
Normal file
79
src/wa/server/page/ConfigPage.java
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* 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.WAServiceConfig;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HttpHeaderParser;
|
||||
import zutil.parser.DataNode;
|
||||
import zutil.parser.Templator;
|
||||
|
||||
import java.io.IOException;
|
||||
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 implements 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,
|
||||
HttpHeaderParser client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) {
|
||||
try {
|
||||
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||
return tmpl;
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, null, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataNode jsonResponse(WAContext context,
|
||||
HttpHeaderParser client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -56,15 +56,16 @@ public class ServicePage implements WAPage {
|
|||
this.rootStatusPage = new ServiceStatusPage(pluginManager);
|
||||
this.statusPages = new ArrayList<>();
|
||||
|
||||
WANavigation nav = WANavigation.getRootNav(NAVIGATION_NAME);
|
||||
WANavigation nav = WANavigation.createRootNav(NAVIGATION_NAME);
|
||||
nav.setResource(this);
|
||||
for(WAService plugin : services) {
|
||||
statusPages.add(new ServiceStatusPage(plugin.getStatus()));
|
||||
|
||||
WANavigation serviceNav = nav.getSubNav(plugin.getName());
|
||||
WANavigation serviceNav = nav.createSubNav(plugin.getName());
|
||||
serviceNav.setResource(plugin);
|
||||
for(WAServiceConfig conf : plugin.getConfigurations()){
|
||||
//serviceNav.getSubNav(conf.getName()).setResource(conf);
|
||||
serviceNav.createSubNav(conf.getName())
|
||||
.setResource(new ConfigPage(conf));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ public class ServiceStatusPage implements WAPage {
|
|||
public ServiceStatusPage(PluginManager pluginManager){
|
||||
this.services = pluginManager.toArray(WAServiceStatus.class);
|
||||
|
||||
WANavigation nav = WANavigation.getRootNav(ServicePage.NAVIGATION_NAME).getSubNav(NAVIGATION_NAME);
|
||||
WANavigation nav = WANavigation.createRootNav(ServicePage.NAVIGATION_NAME)
|
||||
.createSubNav(NAVIGATION_NAME);
|
||||
nav.setResource(this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.WAStatus;
|
||||
|
|
@ -44,10 +43,10 @@ public class StatusPage implements WAPage {
|
|||
public StatusPage(PluginManager pluginManager){
|
||||
this.plugins = pluginManager.toArray(WAStatus.class);
|
||||
|
||||
WANavigation nav = WANavigation.getRootNav(NAVIGATION_NAME);
|
||||
WANavigation nav = WANavigation.createRootNav(NAVIGATION_NAME);
|
||||
nav.setResource(this);
|
||||
for(WAStatus plugin : plugins)
|
||||
nav.getSubNav(plugin.getName()).setResource(plugin);
|
||||
nav.createSubNav(plugin.getName()).setResource(plugin);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -57,18 +57,25 @@ public class WANavigation implements Iterable{
|
|||
public List<WANavigation> getSubNavs() {
|
||||
return subNav;
|
||||
}
|
||||
public WANavigation getSubNav(String name) {
|
||||
private WANavigation getSubNav(String name) {
|
||||
for(WANavigation nav : subNav) {
|
||||
if(nav.equals(name))
|
||||
return nav;
|
||||
}
|
||||
WANavigation nav = new WANavigation(name);
|
||||
this.addSubNav(nav);
|
||||
return nav;
|
||||
return null;
|
||||
}
|
||||
private void addSubNav(WANavigation subNav) {
|
||||
this.subNav.add(subNav);
|
||||
subNav.setParentNav(this );
|
||||
/**
|
||||
* Will create a new subnav if it does not already exist or return the existing one.
|
||||
*/
|
||||
public WANavigation createSubNav(String name) {
|
||||
WANavigation nav = getSubNav(name);
|
||||
if(nav != null)
|
||||
return nav;
|
||||
|
||||
nav = new WANavigation(name);
|
||||
nav.setParentNav(this);
|
||||
subNav.add(nav);
|
||||
return nav;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
|
|
@ -97,8 +104,8 @@ public class WANavigation implements Iterable{
|
|||
public static List<WANavigation> getRootNav(){
|
||||
return rootNav.getSubNavs();
|
||||
}
|
||||
public static WANavigation getRootNav(String name){
|
||||
return rootNav.getSubNav(name);
|
||||
public static WANavigation createRootNav(String name){
|
||||
return rootNav.createSubNav(name);
|
||||
}
|
||||
|
||||
public static List<WANavigation> getNavBreadcrumb(Map<String, String> request) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import java.sql.SQLException;
|
|||
import zutil.db.DBConnection;
|
||||
|
||||
public interface WAServiceConfig {
|
||||
public String getName();
|
||||
public void read() throws SQLException;
|
||||
public void save() throws IOException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import wa.server.util.ConfigFileUtil;
|
|||
import zutil.db.DBConnection;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
||||
public class ApacheConfig implements WAServiceConfig {
|
||||
public class ApacheConfig{
|
||||
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";
|
||||
|
|
@ -26,13 +26,13 @@ public class ApacheConfig implements WAServiceConfig {
|
|||
vhosts = new LinkedList<ApacheConfigVirtualHost>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public void read() throws SQLException {
|
||||
DBConnection db = WAConstants.getDB();
|
||||
vhosts = ApacheConfigVirtualHost.load(db, ApacheConfigVirtualHost.class);
|
||||
//vhosts = ApacheConfigVirtualHost.load(db, ApacheConfigVirtualHost.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public void save() throws IOException {
|
||||
File file = WAConstants.getConfigFile(APACHE_CONF_FILE);
|
||||
// Update main configuration file
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package wa.server.plugin.apache;
|
||||
|
||||
import wa.server.WAConstants;
|
||||
import wa.server.plugin.WAServiceConfig;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.db.bean.DBBean.DBTable;;
|
||||
import zutil.db.bean.DBBean.DBTable;;import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@DBTable(WAConstants.DB_TABLE_PREFIX+"_apache_vhost")
|
||||
public class ApacheConfigVirtualHost extends DBBean{
|
||||
public class ApacheConfigVirtualHost implements WAServiceConfig{
|
||||
public static final String CONFIG_NAME = "Apache Virtual Host";
|
||||
|
||||
protected String domain;
|
||||
protected String path;
|
||||
protected boolean ssl;
|
||||
|
|
@ -30,4 +34,19 @@ public class ApacheConfigVirtualHost extends DBBean{
|
|||
public void setSSL(boolean ssl) {
|
||||
this.ssl = ssl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return CONFIG_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read() throws SQLException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws IOException {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ public class ApacheService implements WAService {
|
|||
|
||||
private ApacheStatus status;
|
||||
private ApacheInstaller installer;
|
||||
private WAServiceConfig[] config = new WAServiceConfig[]{
|
||||
new ApacheConfigVirtualHost()
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
|
@ -61,6 +64,6 @@ public class ApacheService implements WAService {
|
|||
|
||||
@Override
|
||||
public WAServiceConfig[] getConfigurations() {
|
||||
return new WAServiceConfig[0];
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue