From 7227e86264ce29150c51a289fea143af53108d4e Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Thu, 18 Dec 2008 07:34:05 -0500
Subject: [PATCH] Replace website symlink in /var/www when target directory has been changed.
---
server/plugins-available/apache2_plugin.inc.php | 79 +++++++++++++++++++++++++++++++++------
1 files changed, 66 insertions(+), 13 deletions(-)
diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php
index 7f2cfa4..da6d877 100644
--- a/server/plugins-available/apache2_plugin.inc.php
+++ b/server/plugins-available/apache2_plugin.inc.php
@@ -36,6 +36,19 @@
// private variables
var $action = '';
+ //* This function is called during ispconfig installation to determine
+ // if a symlink shall be created for this plugin.
+ function onInstall() {
+ global $conf;
+
+ if($conf['services']['web'] == true) {
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+
/*
This function is called when the plugin is loaded
@@ -289,6 +302,10 @@
$tmp_symlink = str_replace("[website_domain]",$data["new"]["domain"],$tmp_symlink);
// Remove trailing slash
if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
+ //* Remove symlink if target folder has been changed.
+ if($data["old"]["document_root"] != '' && $data["old"]["document_root"] != $data["new"]["document_root"] && is_link($tmp_symlink)) {
+ unlink($tmp_symlink);
+ }
// create the symlinks, if not exist
if(!is_link($tmp_symlink)) {
exec("ln -s ".escapeshellcmd($data["new"]["document_root"])."/ ".escapeshellcmd($tmp_symlink));
@@ -300,14 +317,34 @@
if($this->action == 'insert' && $data["new"]["type"] == 'vhost') {
// Copy the error pages
- if($data["new"]["errordocs"]){
- $error_page_path = escapeshellcmd($data["new"]["document_root"])."/web/error/";
- exec("cp /usr/local/ispconfig/server/conf/error/".substr(escapeshellcmd($conf["language"]),0,2)."/* ".$error_page_path);
- exec("chmod -R +r ".$error_page_path);
- }
-
+ if($data["new"]["errordocs"]){
+ $error_page_path = escapeshellcmd($data["new"]["document_root"])."/web/error/";
+ if (file_exists("/usr/local/ispconfig/server/conf-custom/error/".substr(escapeshellcmd($conf["language"]),0,2))){
+ exec("cp /usr/local/ispconfig/server/conf-custom/error/".substr(escapeshellcmd($conf["language"]),0,2)."/* ".$error_page_path);
+ }
+ else {
+ if (file_exists("/usr/local/ispconfig/server/conf-custom/error/fileNotFound.html")){
+ exec("cp /usr/local/ispconfig/server/conf-custom/error/*.html ".$error_page_path);
+ }
+ else {
+ exec("cp /usr/local/ispconfig/server/conf/error/".substr(escapeshellcmd($conf["language"]),0,2)."/* ".$error_page_path);
+ }
+ }
+ exec("chmod -R +r ".$error_page_path);
+ }
+
// copy the standard index page
- exec("cp /usr/local/ispconfig/server/conf/index/standard_index.html_".substr(escapeshellcmd($conf["language"]),0,2)." ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
+ if (file_exists("/usr/local/ispconfig/server/conf-custom/index/standard_index.html_".substr(escapeshellcmd($conf["language"]),0,2))){
+ exec("cp /usr/local/ispconfig/server/conf-custom/index/standard_index.html_".substr(escapeshellcmd($conf["language"]),0,2)." ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
+ }
+ else {
+ if (file_exists("/usr/local/ispconfig/server/conf-custom/index/standard_index.html")){
+ exec("cp /usr/local/ispconfig/server/conf-custom/index/standard_index.html ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
+ }
+ else {
+ exec("cp /usr/local/ispconfig/server/conf/index/standard_index.html_".substr(escapeshellcmd($conf["language"]),0,2)." ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
+ }
+ }
exec("chmod +r ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
}
@@ -342,6 +379,9 @@
// Chown and chmod the directories
exec("chown -R $username:$groupname ".escapeshellcmd($data["new"]["document_root"]));
+
+ // make temp direcory writable for the apache user and the website user
+ exec("chmod 777 ".escapeshellcmd($data["new"]["document_root"]."/tmp"));
// Create the vhost config file
@@ -384,14 +424,27 @@
// get alias domains (co-domains and subdomains)
$aliases = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE parent_domain_id = ".$data["new"]["domain_id"]." AND active = 'y'");
- if($data["new"]["is_subdomainwww"]){
- $server_alias .= 'www.'.$data["new"]["domain"].' ';
- } else {
- $server_alias = '';
- }
+ switch($data["new"]["subdomain"]) {
+ case 'www':
+ $server_alias .= 'www.'.$data["new"]["domain"].' ';
+ break;
+ case '*':
+ $server_alias .= '*.'.$data["new"]["domain"].' ';
+ break;
+ }
if(is_array($aliases)) {
foreach($aliases as $alias) {
- $server_alias .= $alias["domain"].' ';
+ switch($alias["subdomain"]) {
+ case 'www':
+ $server_alias .= 'www.'.$alias["domain"].' '.$alias["domain"].' ';
+ break;
+ case '*':
+ $server_alias .= '*.'.$alias["domain"].' '.$alias["domain"].' ';
+ break;
+ default:
+ $server_alias .= $alias["domain"].' ';
+ break;
+ }
$app->log("Add server alias: $alias[domain]",LOGLEVEL_DEBUG);
// Rewriting
if($alias["redirect_type"] != '') {
--
Gitblit v1.9.1