/** * Prompts for installation directory. * * @return string package dir */ protected function promptPackageDir() { $packageDir = $errorField = $errorType = ''; if (isset($_POST['send'])) { if (isset($_POST['packageDir'])) { $packageDir = StringUtil::trim($_POST['packageDir']); } // error handling try { $dir = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator($packageDir)); // package can not be installed into the wcf directory if (FileUtil::unifyDirSeperator(WCF_DIR) == $dir) { throw new UserInputException('packageDir', 'wcfDirLocked'); } // this package is a standalone package and needs its own package directory $relativePackageDir = FileUtil::getRelativePath(WCF_DIR, $dir); $sql = "SELECT \tCOUNT(*) AS count\n\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\tWHERE\tpackageDir = '" . escapeString($relativePackageDir) . "'"; $alreadyInstalled = WCF::getDB()->getFirstRow($sql); if ($alreadyInstalled['count'] > 0) { throw new UserInputException('packageDir', 'alreadyInstalled'); } // check writing property if (@file_exists($dir) && !@is_writable($dir)) { throw new UserInputException('packageDir', 'notWritable'); } return $relativePackageDir; } catch (UserInputException $e) { $errorField = $e->getField(); $errorType = $e->getType(); } } else { // make default dir //$packageNameParts = explode('.', $this->installation->getPackage()->getPackage()); //$packageDir = FileUtil::getRealPath(WCF_DIR.'../'.$packageNameParts[count($packageNameParts) - 1]); $packageDir = FileUtil::getRealPath(WCF_DIR . '../'); } // domain $domainName = ''; if (!empty($_SERVER['SERVER_NAME'])) { $domainName = 'http://' . $_SERVER['SERVER_NAME']; } // port if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) { $domainName .= ':' . $_SERVER['SERVER_PORT']; } // wcf url $wcfUrl = ''; if (!empty($_SERVER['REQUEST_URI'])) { $wcfUrl = FileUtil::removeTrailingSlash(FileUtil::getRealPath(FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash(dirname($_SERVER['REQUEST_URI']))) . '/' . RELATIVE_WCF_DIR)); } WCF::getTPL()->assign(array('packageDir' => $packageDir, 'errorField' => $errorField, 'errorType' => $errorType, 'domainName' => $domainName, 'wcfUrl' => $wcfUrl, 'wcfDir' => FileUtil::unifyDirSeperator(WCF_DIR))); WCF::getTPL()->display('packageInstallationPromptPackageDir'); exit; }
/** * Writes a dummy file in the selected ftp directory. * Returns the file of the dummy file or null on failure. * * @param FTP $ftp * @return string $filename */ protected static function writeDummyFile(FTP $ftp) { $dummyUploadFile = FileUtil::getTemporaryFilename('ftpDummy_', '.dat'); @touch($dummyUploadFile); $destFile = FileUtil::removeLeadingSlash(strrchr($dummyUploadFile, '/')); if (@(!$ftp->put($destFile, $dummyUploadFile, FTP_ASCII))) { @unlink($dummyUploadFile); return null; } @unlink($dummyUploadFile); return $destFile; }
/** * Searches the wcf dir. */ protected function searchWcfDir() { $foundDirectory = ''; if (self::$wcfDir) { $wcfDir = self::$wcfDir; } else { if ($foundDirectory = FileUtil::scanFolder(INSTALL_SCRIPT_DIR, "WCF.class.php", true)) { $foundDirectory = $wcfDir = FileUtil::unifyDirSeperator(dirname(dirname(dirname($foundDirectory))) . '/'); } else { $wcfDir = FileUtil::unifyDirSeperator(INSTALL_SCRIPT_DIR) . 'wcf/'; } } // domain $domainName = ''; if (!empty($_SERVER['SERVER_NAME'])) { $domainName = 'http://' . $_SERVER['SERVER_NAME']; } // port if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) { $domainName .= ':' . $_SERVER['SERVER_PORT']; } // script url $installScriptUrl = ''; if (!empty($_SERVER['REQUEST_URI'])) { $installScriptUrl = FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash(FileUtil::unifyDirSeperator(dirname($_SERVER['REQUEST_URI'])))); } WCF::getTPL()->assign(array('nextStep' => 'unzipFiles', 'foundDirectory' => $foundDirectory, 'wcfDir' => $wcfDir, 'domainName' => $domainName, 'installScriptUrl' => $installScriptUrl, 'installScriptDir' => FileUtil::unifyDirSeperator(INSTALL_SCRIPT_DIR))); WCF::getTPL()->display('stepSearchWcfDir'); }
/** * Starts the extracting of the files. */ protected function install() { $this->checkTargetDir(); $this->createTargetDir(); // open source archive $tar = new Tar($this->source); // distinct directories and files $directories = array(); $files = array(); foreach ($tar->getContentList() as $index => $file) { if (empty($this->folder) || StringUtil::indexOf($file['filename'], $this->folder) === 0) { if (!empty($this->folder)) { $file['filename'] = StringUtil::replace($this->folder, '', $file['filename']); } // remove leading slash $file['filename'] = FileUtil::removeLeadingSlash($file['filename']); if ($file['type'] == 'folder') { // remove trailing slash $directories[] = FileUtil::removeTrailingSlash($file['filename']); } else { $files[$index] = $file['filename']; } } } $this->checkFiles($files); // now create the directories $errors = array(); foreach ($directories as $dir) { try { $this->createDir($dir); } catch (SystemException $e) { $errors[] = array('file' => $dir, 'code' => $e->getCode(), 'message' => $e->getMessage()); } } // now untar all files foreach ($files as $index => $file) { try { $this->createFile($file, $index, $tar); } catch (SystemException $e) { $errors[] = array('file' => $file, 'code' => $e->getCode(), 'message' => $e->getMessage()); } } if (count($errors) > 0) { throw new SystemException('error(s) during the installation of the files.', 11111, $errors); } $this->logFiles($files); // close tar $tar->close(); }