Initial impl of configuration page

This commit is contained in:
Ziver Koc 2015-08-07 14:46:01 +00:00
parent 78cb41a39c
commit 813d48ca05
5 changed files with 80 additions and 55 deletions

View file

@ -4,14 +4,18 @@
<div class="panel-body"> <div class="panel-body">
<table class="table table-hover"> <table class="table table-hover">
<thead><tr> <thead><tr>
<th data-field="service">Service</th> {{#headers}}<th>Service</th>{{#headers}}
<th data-field="desc">Description</th>
<th data-field="action" class="text-right">Actions</th>
</tr></thead> </tr></thead>
{{! #data}} {{#data}}
<tr {{^.enabled}}class="active"{{/.enabled}}> <tr {{^.enabled}}class="active"{{/.enabled}}>
<td>{{.getName()}}</td> {{#params}}
<td>{{.getValue()}}</td> <td>
{{#.isTypeBoolean()}}
<input type="checkbox" {{#.getValue()}}checked{{/.getValue()}} disabled />
{{/.isTypeBoolean()}}
{{^.isTypeBoolean()}}{{.getValue()}}{{/.isTypeBoolean()}}
</td>
{{/params}}
<td class="text-right"> <td class="text-right">
<button type="button" class="btn btn-primary btn-xs">Edit</button> <button type="button" class="btn btn-primary btn-xs">Edit</button>
{{^.enabled}}<button type="button" class="btn btn-default btn-xs">Disable</button>{{/.enabled}} {{^.enabled}}<button type="button" class="btn btn-default btn-xs">Disable</button>{{/.enabled}}
@ -19,7 +23,7 @@
<button type="button" class="btn btn-danger btn-xs">Remove</button> <button type="button" class="btn btn-danger btn-xs">Remove</button>
</td> </td>
</tr> </tr>
{{! /data}} {{/data}}
</table> </table>
</div> </div>
<div class="panel-footer text-right"> <div class="panel-footer text-right">

View file

@ -61,6 +61,8 @@ public class ConfigPage implements WAPage{
Map<String, String> request) { Map<String, String> request) {
try { try {
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE)); Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
tmpl.set("headers", null);
tmpl.set("data", null);
return tmpl; return tmpl;
} catch (IOException e) { } catch (IOException e) {
log.log(Level.SEVERE, null, e); log.log(Level.SEVERE, null, e);

View file

@ -1,12 +1,24 @@
package wa.server.plugin; package wa.server.plugin;
import java.io.IOException;
import java.sql.SQLException;
import zutil.db.DBConnection;
public interface WAServiceConfig { public interface WAServiceConfig {
/**
* @return the String name of this configuration type
*/
public String getName(); public String getName();
public void read() throws SQLException;
public void save() throws IOException; /**
* Read in current configuration data
*/
public void read() throws Exception;
/**
* Save configured data to disk or database
*/
public void save() throws Exception;
/**
* Configure service with current configuration data
*/
public void configure() throws Exception;
} }

View file

@ -19,18 +19,9 @@ public class ApacheConfig{
private static final String STATIC_PRE_CONF = "wa/server/plugin/apache/apache_default.config"; private static final String STATIC_PRE_CONF = "wa/server/plugin/apache/apache_default.config";
// Configuration data // Configuration data
List<ApacheConfigVirtualHost> vhosts; List<ApacheConfigVirtualHost.VirtualHostData> vhosts;
public ApacheConfig(){
vhosts = new LinkedList<ApacheConfigVirtualHost>();
}
public void read() throws SQLException {
DBConnection db = WAConstants.getDB();
//vhosts = ApacheConfigVirtualHost.load(db, ApacheConfigVirtualHost.class);
}
public void save() throws IOException { public void save() throws IOException {
@ -47,7 +38,7 @@ public class ApacheConfig{
out.println(FileUtil.getContent(new File(STATIC_PRE_CONF))); out.println(FileUtil.getContent(new File(STATIC_PRE_CONF)));
out.println("######################################"); out.println("######################################");
out.println("# vhost.php"); out.println("# vhost.php");
for(ApacheConfigVirtualHost vhost : vhosts){ for(ApacheConfigVirtualHost.VirtualHostData vhost : vhosts){
if(vhost.isSSL()) if(vhost.isSSL())
writeSSLVhost(out, vhost); writeSSLVhost(out, vhost);
else else
@ -57,7 +48,7 @@ public class ApacheConfig{
out.close(); out.close();
} }
private void writeVhost(PrintStream out, ApacheConfigVirtualHost conf) throws IOException{ private void writeVhost(PrintStream out, ApacheConfigVirtualHost.VirtualHostData conf) throws IOException{
out.println("<VirtualHost *:80>"); out.println("<VirtualHost *:80>");
out.println(" ServerName "+conf.getDomain()+":80"); out.println(" ServerName "+conf.getDomain()+":80");
out.println(" DocumentRoot "+conf.getPath()); out.println(" DocumentRoot "+conf.getPath());
@ -65,7 +56,7 @@ public class ApacheConfig{
out.println(""); out.println("");
} }
private void writeSSLVhost(PrintStream out, ApacheConfigVirtualHost conf) throws IOException{ private void writeSSLVhost(PrintStream out, ApacheConfigVirtualHost.VirtualHostData conf) throws IOException{
out.println("<VirtualHost *:80>"); out.println("<VirtualHost *:80>");
out.println(" ServerName "+conf.getDomain()+":80"); out.println(" ServerName "+conf.getDomain()+":80");
out.println(" RewriteEngine On"); out.println(" RewriteEngine On");
@ -83,7 +74,7 @@ public class ApacheConfig{
out.println(""); out.println("");
} }
private void writeTomcatVhost(PrintStream out, ApacheConfigVirtualHost conf) throws IOException{ private void writeTomcatVhost(PrintStream out, ApacheConfigVirtualHost.VirtualHostData conf) throws IOException{
out.println("<VirtualHost *:80>"); out.println("<VirtualHost *:80>");
out.println(" ServerName "+conf.getDomain()+":80"); out.println(" ServerName "+conf.getDomain()+":80");
out.println(" "); out.println(" ");

View file

@ -2,14 +2,44 @@ package wa.server.plugin.apache;
import wa.server.WAConstants; import wa.server.WAConstants;
import wa.server.plugin.WAServiceConfig; import wa.server.plugin.WAServiceConfig;
import zutil.db.DBConnection;
import zutil.db.bean.DBBean; import zutil.db.bean.DBBean;
import zutil.db.bean.DBBean.DBTable;;import java.io.IOException; import zutil.db.bean.DBBean.DBTable;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@DBTable(WAConstants.DB_TABLE_PREFIX+"_apache_vhost")
public class ApacheConfigVirtualHost implements WAServiceConfig{ public class ApacheConfigVirtualHost implements WAServiceConfig{
public static final String CONFIG_NAME = "Apache Virtual Host"; public static final String CONFIG_NAME = "Apache Virtual Host";
private List<VirtualHostData> vhosts = new ArrayList<>();
@Override
public String getName() {
return CONFIG_NAME;
}
@Override
public void read() throws Exception {
DBConnection db = WAConstants.getDB();
vhosts = DBBean.load(db, VirtualHostData.class);
}
@Override
public void save() throws Exception {
}
@Override
public void configure() throws Exception {
}
@DBTable(WAConstants.DB_TABLE_PREFIX + "_apache_vhost")
public static class VirtualHostData extends DBBean{
protected String domain; protected String domain;
protected String path; protected String path;
protected boolean ssl; protected boolean ssl;
@ -34,19 +64,5 @@ public class ApacheConfigVirtualHost implements WAServiceConfig{
public void setSSL(boolean ssl) { public void setSSL(boolean ssl) {
this.ssl = ssl; this.ssl = ssl;
} }
@Override
public String getName() {
return CONFIG_NAME;
}
@Override
public void read() throws SQLException {
}
@Override
public void save() throws IOException {
} }
} }