/** * Creates a new FTPUninstaller object. * * @param string $targetDir directory from the deleting files * @param array $files delete files * @param FTP $ftp active ftp connection * @param boolean $deleteEmptyTargetDir delete target dir if empty * @param boolean $deleteEmptyDirectories delete sub-directories if empty */ public function __construct($targetDir, $files, FTP $ftp, $deleteEmptyTargetDir, $deleteEmptyDirectories) { $this->ftp = $ftp; $this->ftpPath = FTPUtil::getRelativeFtpPath($this->ftp, $targetDir); if (!$this->ftpPath) { throw new SystemException(WCF::getLanguage()->get('warnings.couldNotFindFTPPath', array('{$dir}' => $targetDir))); } parent::__construct($this->ftpPath, $files, $deleteEmptyTargetDir, $deleteEmptyDirectories); }
/** * @see Installer::createTargetDir() */ protected function createTargetDir() { if (!FTPUtil::pathExists($this->ftp, $this->ftpPath)) { if (!FTPUtil::makePath($this->ftp, $this->ftpPath, IS_APACHE_MODULE ? 0777 : 0755)) { throw new SystemException("cannot create directory '" . $this->ftpPath . "' at ftp server.", 14005); } } else { if (IS_APACHE_MODULE || !is_writeable($this->targetDir)) { $this->makeWriteable($this->ftpPath); } } // create dummy upload file $this->dummyUploadFile = FileUtil::getTemporaryFilename('ftpDummy_', '.dat'); @touch($this->dummyUploadFile); }
/** * Validates the download file input. * * @throws UserInputException */ protected function validateDownloadFile() { if (FileUtil::isURL($this->downloadFile)) { //download file $parsedUrl = parse_url($this->downloadFile); $prefix = 'importSubscriber'; try { // file transfer via hypertext transfer protocol. if ($parsedUrl['scheme'] == 'http') { $this->downloadFile = FileUtil::downloadFileFromHttp($this->downloadFile, $prefix); } elseif ($parsedUrl['scheme'] == 'ftp') { $this->downloadFile = FTPUtil::downloadFileFromFtp($this->downloadFile, $prefix); } } catch (SystemException $e) { throw new UserInputException('downloadFile', 'notFound'); } } else { // probably local path if (!file_exists($this->downloadFile)) { throw new UserInputException('downloadFile', 'notFound'); } } }
/** * Checks if PHP's safe_mode is enabled, and if so, cares for ftp access. * * @return resource $ftp */ public function checkSafeMode() { if (FileUtil::getSafeMode() == 1 && function_exists('ftp_connect')) { // has this form already been submitted? if (isset($_POST['send']) && !empty($_POST['send'])) { $send = $_POST['send']; } else { $send = false; } $ftpHost = ''; $ftpUser = ''; $ftpPassword = ''; $errorField = ''; $errorType = ''; try { if ($send) { // get ftp hostname, username and password from POST data, if available if (isset($_POST['ftpHost']) && !empty($_POST['ftpHost'])) { $ftpHost = $_POST['ftpHost']; WCF::getSession()->register('ftpHost', $ftpHost); } if (isset($_POST['ftpUser']) && !empty($_POST['ftpUser'])) { $ftpUser = $_POST['ftpUser']; WCF::getSession()->register('ftpUser', $ftpUser); } if (isset($_POST['ftpPassword']) && !empty($_POST['ftpPassword'])) { $ftpPassword = $_POST['ftpPassword']; WCF::getSession()->register('ftpPassword', $ftpPassword); } } // else try to read them from session variables; if still not available, // mark the respective field as being erroneous. if (empty($ftpHost)) { $ftpHost = WCF::getSession()->getVar('ftpHost'); if (empty($ftpHost) && $send == true) { throw new UserInputException('ftpHost'); } } if (empty($ftpUser)) { $ftpUser = WCF::getSession()->getVar('ftpUser'); if (empty($ftpUser) && $send == true) { throw new UserInputException('ftpUser'); } } if (empty($ftpPassword)) { $ftpPassword = WCF::getSession()->getVar('ftpPassword'); } if (!empty($ftpHost) && !empty($ftpUser)) { // open ftp connection. try { $ftp = FTPUtil::initFtpAccess($ftpHost, $ftpUser, $ftpPassword); return $ftp; } catch (SystemException $e) { $errCode = $e->getCode(); switch ($errCode) { case 14000: throw new UserInputException('ftpHost', 'cannotConnect'); case 14002: throw new UserInputException('ftpUser', 'cannotLogin'); } } } } catch (UserInputException $e) { $errorField = $e->getField(); $errorType = $e->getType(); // go back to the prompt and tell the user that something went wrong. FTPUtil::promptFtpAccess($ftpHost, $ftpUser, $ftpPassword, $errorField, $errorType); } // if ftp username and password are not available, prompt the user. if (empty($ftpUser) && empty($ftpPassword)) { FTPUtil::promptFtpAccess(); } } else { return null; } }
/** * Downloads the package archive. * * @return string path to the dowloaded file */ public function downloadArchive() { $parsedUrl = parse_url($this->archive); $prefix = 'package'; // file transfer via hypertext transfer protocol. if ($parsedUrl['scheme'] == 'http') { $this->archive = FileUtil::downloadFileFromHttp($this->archive, $prefix); } elseif ($parsedUrl['scheme'] == 'ftp') { $this->archive = FTPUtil::downloadFileFromFtp($this->archive, $prefix); } // unzip tar $this->archive = self::unzipPackageArchive($this->archive); return $this->archive; }