/** * Creates a directory below a users homedir and sets all directories, * which had to be created below with correct Owner/Group * (Copied from cron_tasks.php:rev1189 as we'll need this more often in future) * * @param string The homedir of the user * @param string The dir which should be created * @param int The uid of the user * @param int The gid of the user * @param bool Place standard-index.html into the new folder * @param bool Allow creating a directory out of the customers docroot * * @return bool true if everything went okay, false if something went wrong * * @author Florian Lippert <*****@*****.**> * @author Martin Burchert <*****@*****.**> */ function mkDirWithCorrectOwnership($homeDir, $dirToCreate, $uid, $gid, $placeindex = false, $allow_notwithinhomedir = false, $setgid = false) { $returncode = true; if ($homeDir != '' && $dirToCreate != '') { $homeDir = makeCorrectDir($homeDir); $dirToCreate = makeCorrectDir($dirToCreate); if (substr($dirToCreate, 0, strlen($homeDir)) == $homeDir) { $subdir = substr($dirToCreate, strlen($homeDir) - 1); $within_homedir = true; } else { $subdir = $dirToCreate; $within_homedir = false; } $subdir = makeCorrectDir($subdir); $subdirs = array(); if ($within_homedir || !$allow_notwithinhomedir) { $subdirlen = strlen($subdir); $offset = 0; while ($offset < $subdirlen) { $offset = strpos($subdir, '/', $offset); $subdirelem = substr($subdir, 0, $offset); $offset++; array_push($subdirs, makeCorrectDir($homeDir . $subdirelem)); } } else { array_push($subdirs, $dirToCreate); } $subdirs = array_unique($subdirs); sort($subdirs); foreach ($subdirs as $sdir) { if (!is_dir($sdir)) { $sdir = makeCorrectDir($sdir); safe_exec('mkdir -p ' . escapeshellarg($sdir)); /** * #68 */ if ($placeindex) { $loginname = getLoginNameByUid($uid); if ($loginname !== false) { storeDefaultIndex($loginname, $sdir, null); } } safe_exec('chown -R ' . (int) $uid . ':' . $gid . ' ' . escapeshellarg($sdir)); if ($setgid) { safe_exec('chmod g+s ' . escapeshellarg($sdir)); } } } } else { $returncode = false; } return $returncode; }
/** * remove installation scripts from filesystem and remove tasks and update the database * * @param xml instance of a valid xml object with a parsed APP-META.xml file * @param row current entry from the database for app to handle * @param task numeric code to specify what to do */ private function CleanupData($Xml, $Row, $Task) { chdir($this->RootDir); if ($Task == TASK_INSTALL) { //cleanup installation self::UnlinkRecursive($this->RealPath . $this->DomainPath . '/install_scripts/'); //remove task $this->db->query('DELETE FROM `' . TABLE_APS_TASKS . '` WHERE `Task` = ' . TASK_INSTALL . ' AND `InstanceID` = ' . $this->db->escape($Row['InstanceID'])); } elseif ($Task == TASK_REMOVE) { // check for database if ($this->aps_version == '1.0') { // the good ole way $XmlDb = $Xml->requirements->children('http://apstandard.com/ns/1/db'); } else { // since 1.1 $Xml->registerXPathNamespace('db', 'http://apstandard.com/ns/1/db'); $XmlDb = new DynamicProperties(); $XmlDb->db->id = getXPathValue($Xml, '//db:id'); } if ($XmlDb->db->id) { //drop database permissions $Database = 'web' . $Row['CustomerID'] . 'aps' . $Row['InstanceID']; foreach (array_map('trim', explode(',', $this->Hosts)) as $DatabaseHost) { $this->db_root->query('REVOKE ALL PRIVILEGES ON * . * FROM `' . $this->db->escape($Database) . '`@`' . $this->db->escape($DatabaseHost) . '`'); $this->db_root->query('REVOKE ALL PRIVILEGES ON `' . $this->db->escape($Database) . '` . * FROM `' . $this->db->escape($Database) . '`@`' . $this->db->escape($DatabaseHost) . '`'); $this->db_root->query('DELETE FROM `mysql`.`user` WHERE `User` = "' . $this->db->escape($Database) . '" AND `Host` = "' . $this->db->escape($DatabaseHost) . '"'); } //drop database $this->db_root->query('DROP DATABASE IF EXISTS `' . $this->db->escape($Database) . '`'); $this->db_root->query('FLUSH PRIVILEGES'); /* * remove database from customer-mysql overview, #272 */ $this->db->query('DELETE FROM `' . TABLE_PANEL_DATABASES . '` WHERE `customerid`="' . (int) $Row['CustomerID'] . '" AND `databasename`="' . $this->db->escape($Database) . '" AND `apsdb`="1"'); $result = $this->db->query('UPDATE `' . TABLE_PANEL_CUSTOMERS . '` SET `mysqls_used`=`mysqls_used`-1 WHERE `customerid`="' . (int) $Row['CustomerID'] . '"'); } //remove task & delete package instance + settings $this->db->query('DELETE FROM `' . TABLE_APS_TASKS . '` WHERE `Task` = ' . TASK_REMOVE . ' AND `InstanceID` = ' . $this->db->escape($Row['InstanceID'])); $this->db->query('DELETE FROM `' . TABLE_APS_INSTANCES . '` WHERE `ID` = ' . $this->db->escape($Row['InstanceID'])); $this->db->query('DELETE FROM `' . TABLE_APS_SETTINGS . '` WHERE `InstanceID` = ' . $this->db->escape($Row['InstanceID'])); //remove data, #273 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 . '/'); } } } }
} } else { $cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: mkdir -p ' . escapeshellarg($userhomedir . 'webalizer')); safe_exec('mkdir -p ' . escapeshellarg($userhomedir . 'webalizer')); // in case we changed from the other stats -> remove old // (yes i know, the stats are lost - that's why you should not change all the time!) if (file_exists($userhomedir . 'awstats')) { safe_exec('rm -rf ' . escapeshellarg($userhomedir . 'awstats')); } } // maildir $cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: mkdir -p ' . escapeshellarg($usermaildir)); safe_exec('mkdir -p ' . escapeshellarg($usermaildir)); //check if admin of customer has added template for new customer directories if ((int) $row['data']['store_defaultindex'] == 1) { storeDefaultIndex($row['data']['loginname'], $userhomedir, $cronlog, true); } // strip of last slash of paths to have correct chown results $userhomedir = substr($userhomedir, 0, -1) == '/' ? substr($userhomedir, 0, -1) : $userhomedir; $usermaildir = substr($usermaildir, 0, -1) == '/' ? substr($usermaildir, 0, -1) : $usermaildir; $cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: chown -R ' . (int) $row['data']['uid'] . ':' . (int) $row['data']['gid'] . ' ' . escapeshellarg($userhomedir)); safe_exec('chown -R ' . (int) $row['data']['uid'] . ':' . (int) $row['data']['gid'] . ' ' . escapeshellarg($userhomedir)); // don't allow others to access the directory (webserver will be the group via libnss-mysql) if (Settings::Get('system.mod_fcgid') == 1 || Settings::Get('phpfpm.enabled') == 1) { // fcgid or fpm safe_exec('chmod 0750 ' . escapeshellarg($userhomedir)); } else { // mod_php -> no libnss-mysql -> no webserver-user in group safe_exec('chmod 0755 ' . escapeshellarg($userhomedir)); } $cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: chown -R ' . (int) Settings::Get('system.vmail_uid') . ':' . (int) Settings::Get('system.vmail_gid') . ' ' . escapeshellarg($usermaildir));