Initial commit
This commit is contained in:
commit
aa4e110832
69 changed files with 17898 additions and 0 deletions
40
src/wa/server/plugin/apache/ApacheConfigVirtualHost.java
Normal file
40
src/wa/server/plugin/apache/ApacheConfigVirtualHost.java
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package wa.server.plugin.apache;
|
||||
|
||||
import wa.server.WAConstants;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.db.bean.DBBean.DBTable;;
|
||||
|
||||
@DBTable(WAConstants.DB_TABLE_PREFIX+"_apache_vhost")
|
||||
public class ApacheConfigVirtualHost extends DBBean{
|
||||
protected String domain;
|
||||
protected String path;
|
||||
protected boolean ssl;
|
||||
protected boolean tomcat;
|
||||
|
||||
|
||||
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
public boolean isSSL() {
|
||||
return ssl;
|
||||
}
|
||||
public void setSSL(boolean ssl) {
|
||||
this.ssl = ssl;
|
||||
}
|
||||
public boolean isTomcatApp() {
|
||||
return tomcat;
|
||||
}
|
||||
public void setTomcatApp(boolean tomcat) {
|
||||
this.tomcat = tomcat;
|
||||
}
|
||||
}
|
||||
104
src/wa/server/plugin/apache/ApacheConfigurator.java
Normal file
104
src/wa/server/plugin/apache/ApacheConfigurator.java
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
package wa.server.plugin.apache;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import wa.server.WAConstants;
|
||||
import wa.server.plugin.WAConfigurator;
|
||||
import wa.server.util.ConfigFileUtil;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
||||
public class ApacheConfigurator implements WAConfigurator {
|
||||
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";
|
||||
|
||||
// Configuration data
|
||||
List<ApacheConfigVirtualHost> vhosts;
|
||||
|
||||
|
||||
public ApacheConfigurator(){
|
||||
vhosts = new LinkedList<ApacheConfigVirtualHost>();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void read(DBConnection db) throws SQLException {
|
||||
vhosts = ApacheConfigVirtualHost.load(db, ApacheConfigVirtualHost.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DBConnection db) throws IOException {
|
||||
File file = WAConstants.getConfigFile(APACHE_CONF_FILE);
|
||||
// Update Man configuration file
|
||||
ConfigFileUtil.writeBetweenBoundary(
|
||||
new File(APACHE_MAIN_CONFIG_FILE),
|
||||
"#",
|
||||
"Include "+file.getAbsolutePath());
|
||||
|
||||
// Write Vhost configuration
|
||||
PrintStream out = new PrintStream(file);
|
||||
|
||||
out.println(FileUtil.getContent(new File(STATIC_PRE_CONF)));
|
||||
out.println("######################################");
|
||||
out.println("# vhost.php");
|
||||
for(ApacheConfigVirtualHost vhost : vhosts){
|
||||
if(vhost.isTomcatApp())
|
||||
writeTomcatVhost(out, vhost);
|
||||
else if(vhost.isSSL())
|
||||
writeSSLVhost(out, vhost);
|
||||
else
|
||||
writeVhost(out, vhost);
|
||||
}
|
||||
|
||||
out.close();
|
||||
}
|
||||
|
||||
private void writeVhost(PrintStream out, ApacheConfigVirtualHost conf) throws IOException{
|
||||
out.println("<VirtualHost *:80>");
|
||||
out.println(" ServerName "+conf.getDomain()+":80");
|
||||
out.println(" DocumentRoot "+conf.getPath());
|
||||
out.println("</VirtualHost>");
|
||||
out.println("");
|
||||
}
|
||||
|
||||
private void writeSSLVhost(PrintStream out, ApacheConfigVirtualHost conf) throws IOException{
|
||||
out.println("<VirtualHost *:80>");
|
||||
out.println(" ServerName "+conf.getDomain()+":80");
|
||||
out.println(" RewriteEngine On");
|
||||
out.println(" RewriteCond %{SERVER_PORT} !^443$");
|
||||
out.println(" RewriteRule ^(.*)$ https://server$1 [L,R]");
|
||||
out.println("</VirtualHost>");
|
||||
out.println("<VirtualHost *:443>");
|
||||
out.println(" ServerName "+conf.getDomain()+":443");
|
||||
out.println(" DocumentRoot "+conf.getPath());
|
||||
out.println("");
|
||||
out.println(" SSLEngine on");
|
||||
out.println(" SSLCertificateFile "+WAConstants.getConfigFile(WAConstants.WA_SSL_CERT));
|
||||
out.println(" SSLCertificateKeyFile "+WAConstants.getConfigFile(WAConstants.WA_SSL_KEY));
|
||||
out.println("</VirtualHost>");
|
||||
out.println("");
|
||||
}
|
||||
|
||||
private void writeTomcatVhost(PrintStream out, ApacheConfigVirtualHost conf) throws IOException{
|
||||
out.println("<VirtualHost *:80>");
|
||||
out.println(" ServerName "+conf.getDomain()+":80");
|
||||
out.println(" ");
|
||||
out.println(" RewriteEngine On");
|
||||
out.println(" RewriteRule ^/$ /"+conf.getPath()+" [R]");
|
||||
out.println(" ProxyPreserveHost on");
|
||||
out.println(" <Proxy *>");
|
||||
out.println(" Order deny,allow");
|
||||
out.println(" Allow from all");
|
||||
out.println(" </Proxy>");
|
||||
out.println(" ProxyPass / ajp://localhost:8009/");
|
||||
out.println(" ProxyPassReverse / http://localhost:8080/");
|
||||
out.println("</VirtualHost>");
|
||||
out.println("");
|
||||
}
|
||||
}
|
||||
43
src/wa/server/plugin/apache/ApacheInstaller.java
Normal file
43
src/wa/server/plugin/apache/ApacheInstaller.java
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2014 Ziver
|
||||
*
|
||||
* 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.plugin.apache;
|
||||
|
||||
import wa.server.plugin.WAInstaller;
|
||||
import wa.server.util.AptGet;
|
||||
import zutil.osal.OSAbstractionLayer;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2014-11-09.
|
||||
*/
|
||||
public class ApacheInstaller implements WAInstaller {
|
||||
|
||||
@Override
|
||||
public void install() {
|
||||
AptGet.install("apache php5 php5-mcrypt php5-gd imagemagick");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uninstall() {
|
||||
AptGet.purge("apache php5 php5-mcrypt php5-gd imagemagick");
|
||||
}
|
||||
}
|
||||
68
src/wa/server/plugin/apache/ApacheService.java
Normal file
68
src/wa/server/plugin/apache/ApacheService.java
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2014 Ziver
|
||||
*
|
||||
* 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.plugin.apache;
|
||||
|
||||
import wa.server.plugin.WAService;
|
||||
import wa.server.util.Ps;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.osal.OSAbstractionLayer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2014-12-23.
|
||||
*/
|
||||
public class ApacheService implements WAService {
|
||||
private static Logger log = LogUtil.getLogger();
|
||||
|
||||
private static OSAbstractionLayer os = OSAbstractionLayer.getInstance();
|
||||
private static final String PID_FILE = "/var/run/apache2.pid";
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
os.runCommand("service apache2 start");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
os.runCommand("service apache2 stop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public WAServiceStatus getStatus() {
|
||||
try {
|
||||
int pid = Integer.parseInt(
|
||||
FileUtil.getContent(new File(PID_FILE)));
|
||||
if(Ps.isRunning(pid))
|
||||
return WAServiceStatus.RUNNING;
|
||||
return WAServiceStatus.UNAVAILABLE;
|
||||
}catch(IOException e){
|
||||
log.log(Level.WARNING, null, e);
|
||||
}
|
||||
return WAServiceStatus.UNKNOWN;
|
||||
}
|
||||
}
|
||||
91
src/wa/server/plugin/apache/apache_default.config
Normal file
91
src/wa/server/plugin/apache/apache_default.config
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
###################################
|
||||
# default.php
|
||||
|
||||
ScriptAlias /cgi-bin/ /home/www/cgi-bin/
|
||||
#NameVirtualHost *:80
|
||||
NameVirtualHost *:443
|
||||
ServerName koc.se
|
||||
ServerAdmin ziver@koc.se
|
||||
|
||||
#<VirtualHost *:80>
|
||||
# Redirect / http://koc.se
|
||||
#</VirtualHost>
|
||||
|
||||
# WebAdmin {
|
||||
<VirtualHost *:80>
|
||||
ServerName admin.koc.se:80
|
||||
RewriteEngine On
|
||||
RewriteCond %{SERVER_PORT} !^443$
|
||||
RewriteRule ^(.*)$ https://admin.koc.se$1 [L,R]
|
||||
</VirtualHost>
|
||||
<VirtualHost *:443>
|
||||
ServerName admin.koc.se:443
|
||||
DocumentRoot ".$config["apache_www_path"]."/admin
|
||||
|
||||
SSLEngine on
|
||||
SSLCertificateFile ".$config["apache_conf_path"]."/cert/server.crt
|
||||
SSLCertificateKeyFile ".$config["apache_conf_path"]."/cert/server.key
|
||||
</VirtualHost>
|
||||
|
||||
<VirtualHost *:80>
|
||||
ServerName server:80
|
||||
RewriteEngine On
|
||||
RewriteCond %{SERVER_PORT} !^443$
|
||||
RewriteRule ^(.*)$ https://server$1 [L,R]
|
||||
</VirtualHost>
|
||||
<VirtualHost *:443>
|
||||
ServerName server:443
|
||||
DocumentRoot ".$config["apache_www_path"]."/admin
|
||||
|
||||
SSLEngine on
|
||||
SSLCertificateFile ".$config["apache_conf_path"]."/cert/server.crt
|
||||
SSLCertificateKeyFile ".$config["apache_conf_path"]."/cert/server.key
|
||||
</VirtualHost>
|
||||
|
||||
<VirtualHost *:80>
|
||||
ServerName localhost:80
|
||||
RewriteEngine On
|
||||
RewriteCond %{SERVER_PORT} !^443$
|
||||
RewriteRule ^(.*)$ https://localhost$1 [L,R]
|
||||
</VirtualHost>
|
||||
<VirtualHost *:443>
|
||||
ServerName localhost:443
|
||||
DocumentRoot ".$config["apache_www_path"]."/admin
|
||||
|
||||
SSLEngine on
|
||||
SSLCertificateFile ".$config["apache_conf_path"]."/cert/server.crt
|
||||
SSLCertificateKeyFile ".$config["apache_conf_path"]."/cert/server.key
|
||||
</VirtualHost>
|
||||
|
||||
<VirtualHost *:80>
|
||||
ServerName 192.168.0.2:80
|
||||
RewriteEngine On
|
||||
RewriteCond %{SERVER_PORT} !^443$
|
||||
RewriteRule ^(.*)$ https://192.168.0.2$1 [L,R]
|
||||
</VirtualHost>
|
||||
<VirtualHost *:443>
|
||||
ServerName 192.168.0.2:443
|
||||
DocumentRoot ".$config["apache_www_path"]."/admin
|
||||
|
||||
SSLEngine on
|
||||
SSLCertificateFile ".$config["apache_conf_path"]."/cert/server.crt
|
||||
SSLCertificateKeyFile ".$config["apache_conf_path"]."/cert/server.key
|
||||
</VirtualHost>
|
||||
#}
|
||||
# Mythweb
|
||||
#<VirtualHost *:80>
|
||||
# ServerName mythtv.koc.se
|
||||
# DirectoryIndex mythweb
|
||||
# DocumentRoot /var/www
|
||||
#
|
||||
# # Include /etc/apache2/sites-available/mythweb.conf
|
||||
#</VirtualHost>
|
||||
# TvHeadend
|
||||
<VirtualHost *:80>
|
||||
ServerName tv.koc.se:80
|
||||
|
||||
ProxyPreserveHost on
|
||||
ProxyPass / http://localhost:9981/
|
||||
ProxyPassReverse / http://localhost:9981/
|
||||
</VirtualHost>
|
||||
|
||||
9
src/wa/server/plugin/apache/plugin.json
Normal file
9
src/wa/server/plugin/apache/plugin.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"version": "1.0",
|
||||
"name": "Apache Web Server",
|
||||
"interfaces": {
|
||||
"wa.server.plugin.WAInstaller": "wa.server.plugin.apache.ApacheInstaller",
|
||||
"wa.server.plugin.WAConfigurator": "wa.server.plugin.apache.ApacheConfigurator",
|
||||
"wa.server.plugin.WAService": "wa.server.plugin.apache.ApacheService"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue