Backend implementation of config objects
This commit is contained in:
parent
224372f0ad
commit
2d1a7d647c
13 changed files with 215 additions and 131 deletions
48
src/wa/server/plugin/apache/ApacheConfigVirtualHost.java
Normal file → Executable file
48
src/wa/server/plugin/apache/ApacheConfigVirtualHost.java
Normal file → Executable file
|
|
@ -1,6 +1,7 @@
|
|||
package wa.server.plugin.apache;
|
||||
|
||||
import wa.server.WAConstants;
|
||||
import wa.server.plugin.WAConfigEntry;
|
||||
import wa.server.plugin.WAServiceConfig;
|
||||
import wa.server.util.ConfigFileUtil;
|
||||
import zutil.db.DBConnection;
|
||||
|
|
@ -16,30 +17,30 @@ import java.util.List;
|
|||
|
||||
public class ApacheConfigVirtualHost implements WAServiceConfig{
|
||||
private static final String CONFIG_NAME = "Apache Virtual Host";
|
||||
private static final String APACHE_MAIN_CONFIG_FILE = "apache2/apache2.conf";
|
||||
private static final String APACHE_MAIN_CONFIG_FILE = "/apache2/apache2.conf";
|
||||
private static final String APACHE_SITE_AVAILABLE_PATH = "/apache2/site-available/";
|
||||
private static final String STATIC_PRE_CONF = "wa/server/plugin/apache/apache_default.config";
|
||||
|
||||
private List<ApacheVirtualHostData> vhosts = new ArrayList<>();
|
||||
private List<ApacheVirtualHostEntry> vhosts = new ArrayList<>();
|
||||
|
||||
|
||||
public ApacheConfigVirtualHost() throws Exception {
|
||||
DBConnection db = WAConstants.getDB();
|
||||
vhosts = DBBean.load(db, ApacheVirtualHostEntry.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return CONFIG_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read() throws Exception {
|
||||
DBConnection db = WAConstants.getDB();
|
||||
vhosts = DBBean.load(db, ApacheVirtualHostData.class);
|
||||
}
|
||||
public WAConfigEntry createConfig(){
|
||||
return new ApacheVirtualHostEntry();
|
||||
}
|
||||
public void deleteConfig(int id){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws Exception {
|
||||
DBConnection db = WAConstants.getDB();
|
||||
for(ApacheVirtualHostData vhost : vhosts){
|
||||
vhost.save(db);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
|
@ -51,23 +52,23 @@ public class ApacheConfigVirtualHost implements WAServiceConfig{
|
|||
new FileInputStream(STATIC_PRE_CONF)));
|
||||
|
||||
// Write Vhost configuration
|
||||
for(ApacheVirtualHostData vhost : vhosts){
|
||||
for(ApacheVirtualHostEntry vhost : vhosts){
|
||||
vhost.configure();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> getConfigData() {
|
||||
public List<? extends WAConfigEntry> getConfigData() {
|
||||
return vhosts;
|
||||
}
|
||||
@Override
|
||||
public Class<?> getConfigClass() {
|
||||
return ApacheVirtualHostData.class;
|
||||
public Class<? extends WAConfigEntry> getConfigClass() {
|
||||
return ApacheVirtualHostEntry.class;
|
||||
}
|
||||
|
||||
|
||||
@DBTable(WAConstants.DB_TABLE_PREFIX + "_apache_vhost")
|
||||
public static class ApacheVirtualHostData extends DBBean{
|
||||
public static class ApacheVirtualHostEntry extends WAConfigEntry {
|
||||
@Configurable("Domain")
|
||||
protected String domain;
|
||||
protected transient String domain_old;
|
||||
|
|
@ -101,10 +102,11 @@ public class ApacheConfigVirtualHost implements WAServiceConfig{
|
|||
|
||||
public final void configure() throws IOException {
|
||||
if(domain != domain_old){ // Configuration file has changed name
|
||||
WAConstants.getConfigFile("apache2/enabled/"+ domain_old).delete();
|
||||
WAConstants.getConfigFile(APACHE_SITE_AVAILABLE_PATH+ domain_old).delete();
|
||||
domain_old = domain;
|
||||
}
|
||||
PrintStream out = new PrintStream(
|
||||
WAConstants.getConfigFile("apache2/enabled/"+ domain));
|
||||
WAConstants.getConfigFile(APACHE_SITE_AVAILABLE_PATH+ domain));
|
||||
|
||||
writeConfiguration(out);
|
||||
out.close();
|
||||
|
|
@ -129,8 +131,8 @@ public class ApacheConfigVirtualHost implements WAServiceConfig{
|
|||
}
|
||||
else {
|
||||
out.println("<VirtualHost *:80>");
|
||||
out.println(" ServerName " + domain + ":80");
|
||||
out.println(" DocumentRoot " + path);
|
||||
out.println(" ServerName "+ domain +":80");
|
||||
out.println(" DocumentRoot "+ path);
|
||||
out.println("</VirtualHost>");
|
||||
out.println("");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue