From 57124d040dd554c183095cad8045f820f9f0c32c Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Thu, 24 Jun 2010 08:11:43 +0000 Subject: [PATCH] - don't delete everything if the path is the domains document-root (protect basedir, awstats|webalizer-dir and place default index), fixes #273 refs #273 --- customer_extras.php | 2 +- lib/classes/aps/class.ApsInstaller.php | 13 ++++++++++++- lib/classes/aps/class.ApsParser.php | 15 ++++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/customer_extras.php b/customer_extras.php index 548fc5fd..e1b21d5d 100644 --- a/customer_extras.php +++ b/customer_extras.php @@ -342,7 +342,7 @@ elseif($page == 'htaccess') else { $pathSelect = makePathfield($userinfo['documentroot'], $userinfo['guid'], $userinfo['guid'], $settings['panel']['pathedit']); - $options_indexes = makeyesno('options_indexes', '1', '0', '1'); + $options_indexes = makeyesno('options_indexes', '1', '0', '0'); eval("echo \"" . getTemplate("extras/htaccess_add") . "\";"); } } diff --git a/lib/classes/aps/class.ApsInstaller.php b/lib/classes/aps/class.ApsInstaller.php index 4c16d335..8b398a8c 100644 --- a/lib/classes/aps/class.ApsInstaller.php +++ b/lib/classes/aps/class.ApsInstaller.php @@ -264,7 +264,18 @@ class ApsInstaller extends ApsParser $this->db->query('DELETE FROM `' . TABLE_APS_SETTINGS . '` WHERE `InstanceID` = ' . $this->db->escape($Row['InstanceID'])); //remove data, #273 - self::UnlinkRecursive($this->RealPath . $this->DomainPath . '/'); + if($this->DomainPath != '' && $this->DomainPath != '/') { + self::UnlinkRecursive($this->RealPath . $this->DomainPath . '/'); + } else { + // save awstats/webalizer folder if it's the docroot + self::UnlinkRecursive($this->RealPath . $this->DomainPath . '/', true); + // place standard-index file + $loginname = getLoginNameByUid($Row['CustomerID']); + if($loginname !== false) + { + storeDefaultIndex($loginname, $this->RealPath . $this->DomainPath . '/'); + } + } } } diff --git a/lib/classes/aps/class.ApsParser.php b/lib/classes/aps/class.ApsParser.php index 9e3f2397..2413b793 100644 --- a/lib/classes/aps/class.ApsParser.php +++ b/lib/classes/aps/class.ApsParser.php @@ -400,9 +400,9 @@ class ApsParser * unlink files recursively * * @param dir directory to delete recursive + * @param boolean whether the base-directory should be kept or not */ - - protected function UnlinkRecursive($Dir) + protected function UnlinkRecursive($Dir, $save_base = false) { if(!$DirHandle = @opendir($Dir))return; @@ -411,6 +411,12 @@ class ApsParser if($Object == '.' || $Object == '..')continue; + if($save_base + && (strtoupper($Object) == 'AWSTATS' || strtoupper($Object) == 'WEBALIZER') + ) { + continue; + } + if(!@unlink($Dir . '/' . $Object)) { self::UnlinkRecursive($Dir . '/' . $Object); @@ -418,7 +424,10 @@ class ApsParser } closedir($DirHandle); - @rmdir($Dir); + if(!$save_base) + { + @rmdir($Dir); + } } /**