Skip to content

Commit 4fa7eb0

Browse files
committed
Fixed a bug when a alias domain or subdomain of a website gets deleted.
1 parent 036579b commit 4fa7eb0

File tree

1 file changed

+65
-51
lines changed

1 file changed

+65
-51
lines changed

server/plugins-available/apache2_plugin.inc.php

Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ function update($event_name,$data) {
574574
$cgi_tpl->newTemplate("php-cgi-starter.master");
575575

576576
// This works, because php "rewrites" a symlink to the physical path
577-
$cgi_tpl->setVar('open_basedir', $data["new"]["document_root"]);
577+
$cgi_tpl->setVar('open_basedir', $data["new"]["document_root"]);
578578
// This will NOT work!
579579
//$cgi_tpl->setVar('open_basedir', "/var/www/" . $data["new"]["domain"]);
580580
$cgi_tpl->setVar('php_cgi_bin',$cgi_config["cgi_bin"]);
@@ -634,73 +634,87 @@ function delete($event_name,$data) {
634634
$app->uses("getconf");
635635
$web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
636636

637-
// Deleting the vhost file, symlink and the data directory
638-
$vhost_symlink = escapeshellcmd($web_config["vhost_conf_enabled_dir"].'/'.$data["old"]["domain"].'.vhost');
639-
unlink($vhost_symlink);
640-
$app->log("Removing symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
641637

642-
$vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["old"]["domain"].'.vhost');
643-
unlink($vhost_file);
644-
$app->log("Removing vhost file: $vhost_file",LOGLEVEL_DEBUG);
638+
if($data["old"]["type"] != "vhost" && $data["old"]["parent_domain_id"] > 0) {
639+
//* This is a alias domain or subdomain, so we have to update the website instead
640+
$parent_domain_id = intval($data["old"]["parent_domain_id"]);
641+
$tmp = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$parent_domain_id." AND active = 'y'");
642+
$data["new"] = $tmp;
643+
$data["old"] = $tmp;
644+
$this->action = 'update';
645+
// just run the update function
646+
$this->update($event_name,$data);
647+
648+
} else {
649+
//* This is a website
650+
// Deleting the vhost file, symlink and the data directory
651+
$vhost_symlink = escapeshellcmd($web_config["vhost_conf_enabled_dir"].'/'.$data["old"]["domain"].'.vhost');
652+
unlink($vhost_symlink);
653+
$app->log("Removing symlink: $vhost_symlink => $vhost_file",LOGLEVEL_DEBUG);
654+
655+
$vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["old"]["domain"].'.vhost');
656+
unlink($vhost_file);
657+
$app->log("Removing vhost file: $vhost_file",LOGLEVEL_DEBUG);
645658

646-
$docroot = escapeshellcmd($data["old"]["document_root"]);
647-
if($docroot != '' && !stristr($docroot,'..')) exec("rm -rf $docroot");
659+
$docroot = escapeshellcmd($data["old"]["document_root"]);
660+
if($docroot != '' && !stristr($docroot,'..')) exec("rm -rf $docroot");
648661

649662

650-
//remove the php fastgi starter script if available
651-
if ($data["old"]["php"] == "fast-cgi")
652-
{
653-
$fastcgi_starter_path = str_replace("[system_user]",$data["old"]["system_user"],$web_config["fastcgi_starter_path"]);
654-
if (is_dir($fastcgi_starter_path))
663+
//remove the php fastgi starter script if available
664+
if ($data["old"]["php"] == "fast-cgi")
655665
{
666+
$fastcgi_starter_path = str_replace("[system_user]",$data["old"]["system_user"],$web_config["fastcgi_starter_path"]);
667+
if (is_dir($fastcgi_starter_path))
668+
{
656669
exec("rm -rf $fastcgi_starter_path");
670+
}
657671
}
658-
}
659672

660-
//remove the php cgi starter script if available
661-
if ($data["old"]["php"] == "cgi")
662-
{
663-
// TODO: fetch the date from the server-settings
664-
$web_config["cgi_starter_path"] = "/var/www/php-cgi-scripts/[system_user]/";
665-
666-
$cgi_starter_path = str_replace("[system_user]",$data["old"]["system_user"],$web_config["cgi_starter_path"]);
667-
if (is_dir($cgi_starter_path))
673+
//remove the php cgi starter script if available
674+
if ($data["old"]["php"] == "cgi")
668675
{
676+
// TODO: fetch the date from the server-settings
677+
$web_config["cgi_starter_path"] = "/var/www/php-cgi-scripts/[system_user]/";
678+
679+
$cgi_starter_path = str_replace("[system_user]",$data["old"]["system_user"],$web_config["cgi_starter_path"]);
680+
if (is_dir($cgi_starter_path))
681+
{
669682
exec("rm -rf $cgi_starter_path");
683+
}
670684
}
671-
}
672685

673-
$app->log("Removing website: $docroot",LOGLEVEL_DEBUG);
686+
$app->log("Removing website: $docroot",LOGLEVEL_DEBUG);
674687

675-
// Delete the symlinks for the sites
676-
$client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".intval($data["old"]["sys_groupid"]));
677-
$client_id = intval($client["client_id"]);
678-
unset($client);
679-
$tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
680-
if(is_array($tmp_symlinks_array)) {
681-
foreach($tmp_symlinks_array as $tmp_symlink) {
682-
$tmp_symlink = str_replace("[client_id]",$client_id,$tmp_symlink);
683-
$tmp_symlink = str_replace("[website_domain]",$data["old"]["domain"],$tmp_symlink);
684-
// Remove trailing slash
685-
if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
686-
// create the symlinks, if not exist
687-
if(is_link($tmp_symlink)) {
688-
unlink($tmp_symlink);
689-
$app->log("Removing symlink: ".$tmp_symlink,LOGLEVEL_DEBUG);
688+
// Delete the symlinks for the sites
689+
$client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".intval($data["old"]["sys_groupid"]));
690+
$client_id = intval($client["client_id"]);
691+
unset($client);
692+
$tmp_symlinks_array = explode(':',$web_config["website_symlinks"]);
693+
if(is_array($tmp_symlinks_array)) {
694+
foreach($tmp_symlinks_array as $tmp_symlink) {
695+
$tmp_symlink = str_replace("[client_id]",$client_id,$tmp_symlink);
696+
$tmp_symlink = str_replace("[website_domain]",$data["old"]["domain"],$tmp_symlink);
697+
// Remove trailing slash
698+
if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1);
699+
// create the symlinks, if not exist
700+
if(is_link($tmp_symlink)) {
701+
unlink($tmp_symlink);
702+
$app->log("Removing symlink: ".$tmp_symlink,LOGLEVEL_DEBUG);
703+
}
690704
}
691705
}
692-
}
693-
// end removing symlinks
706+
// end removing symlinks
694707

695-
// Delete the log file directory
696-
$vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data["old"]["domain"]);
697-
if($data["old"]["domain"] != '' && !stristr($vhost_logfile_dir,'..')) exec("rm -rf $vhost_logfile_dir");
698-
$app->log("Removing website logfile directory: $vhost_logfile_dir",LOGLEVEL_DEBUG);
708+
// Delete the log file directory
709+
$vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data["old"]["domain"]);
710+
if($data["old"]["domain"] != '' && !stristr($vhost_logfile_dir,'..')) exec("rm -rf $vhost_logfile_dir");
711+
$app->log("Removing website logfile directory: $vhost_logfile_dir",LOGLEVEL_DEBUG);
699712

700-
//delete the web user
701-
$command = 'userdel';
702-
$command .= ' '.$data["old"]["system_user"];
703-
exec($command);
713+
//delete the web user
714+
$command = 'userdel';
715+
$command .= ' '.$data["old"]["system_user"];
716+
exec($command);
717+
}
704718
}
705719

706720
//* This function is called when a IP on the server is inserted, updated or deleted

0 commit comments

Comments
 (0)