/** * @see \wcf\form\IForm::validate() */ public function validate() { parent::validate(); // check if file is uploaded or linked if (!empty($this->file['tmp_name'])) { $this->backup = $this->file['tmp_name']; } else { if ($this->fileLink != '') { //check if file is external url if (FileUtil::isURL($this->fileLink)) { try { //download file $this->backup = FileUtil::downloadFileFromHttp($this->fileLink, 'cms_backup'); } catch (SystemException $e) { //download failed throw new UserInputException('fileLink', 'downloadFailed'); } } else { //file not found if (!file_exists($this->fileLink)) { throw new UserInputException('fileLink', 'notFound'); } else { $this->backup = $this->fileLink; } } } else { throw new UserInputException('file', 'empty'); } } }
/** * @see \cms\system\content\type\IContentType::validate() */ public function validate($data) { if (!isset($data['video'])) { throw new UserInputException('data[video]'); } if (!FileUtil::isURL($data['video'])) { throw new UserInputException('data[video]', 'notValid'); } }
/** * Creates a new ActiveStyle object. * * @param Style $object */ public function __construct(Style $object) { parent::__construct($object); // calculate page logo path if (!empty($this->object->data['variables']['page.logo.image']) && !FileUtil::isURL($this->object->data['variables']['page.logo.image']) && StringUtil::substring($this->object->data['variables']['page.logo.image'], 0, 1) !== '/') { $this->object->data['variables']['page.logo.image'] = RELATIVE_WCF_DIR . $this->object->data['variables']['page.logo.image']; } // load icon cache $cacheName = 'icon-' . PACKAGE_ID . '-' . $this->styleID; CacheHandler::getInstance()->addResource($cacheName, WCF_DIR . 'cache/cache.' . $cacheName . '.php', 'wcf\\system\\cache\\builder\\IconCacheBuilder'); $this->iconCache = CacheHandler::getInstance()->get($cacheName); }
/** * Returns current package archive. * * @return wcf\system\package\PackageArchive */ public function getArchive() { if ($this->archive === null) { $this->archive = new PackageArchive($this->queue->archive, $this->getPackage()); if (FileUtil::isURL($this->archive->getArchive())) { // get return value and update entry in // package_installation_queue with this value $archive = $this->archive->downloadArchive(); $queueEditor = new PackageInstallationQueueEditor($this->queue); $queueEditor->update(array( 'archive' => $archive )); } $this->archive->openArchive(); } return $this->archive; }
/** * Installs the specified package. * * @param string $file */ private function install($file) { // PackageStartInstallForm::validateDownloadPackage() if (FileUtil::isURL($file)) { // download package $archive = new PackageArchive($file, null); try { if (VERBOSITY >= 1) { Log::info("Downloading '" . $file . "'"); } $file = $archive->downloadArchive(); } catch (SystemException $e) { $this->error('notFound', array('file' => $file)); } } else { // probably local path if (!file_exists($file)) { $this->error('notFound', array('file' => $file)); } $archive = new PackageArchive($file, null); } // PackageStartInstallForm::validateArchive() // try to open the archive try { // TODO: Exceptions thrown within openArchive() are discarded, resulting in // the meaningless message 'not a valid package' $archive->openArchive(); } catch (SystemException $e) { $this->error('noValidPackage'); } $errors = PackageInstallationDispatcher::validatePHPRequirements($archive->getPhpRequirements()); if (!empty($errors)) { // TODO: Nice output $this->error('phpRequirements', array('errors' => $errors)); } // try to find existing package $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\tWHERE\tpackage = ?"; $statement = CLIWCF::getDB()->prepareStatement($sql); $statement->execute(array($archive->getPackageInfo('name'))); $row = $statement->fetchArray(); $package = null; if ($row !== false) { $package = new Package(null, $row); } // check update or install support if ($package !== null) { CLIWCF::getSession()->checkPermissions(array('admin.system.package.canUpdatePackage')); $archive->setPackage($package); if (!$archive->isValidUpdate()) { $this->error('noValidUpdate'); } } else { CLIWCF::getSession()->checkPermissions(array('admin.system.package.canInstallPackage')); if (!$archive->isValidInstall()) { $this->error('noValidInstall'); } else { if ($archive->getPackageInfo('isApplication')) { // applications cannot be installed via CLI $this->error('cli.installIsApplication'); } else { if ($archive->isAlreadyInstalled()) { $this->error('uniqueAlreadyInstalled'); } else { if ($archive->getPackageInfo('isApplication') && $this->archive->hasUniqueAbbreviation()) { $this->error('noUniqueAbbrevation'); } } } } } // PackageStartInstallForm::save() $processNo = PackageInstallationQueue::getNewProcessNo(); // insert queue $queue = PackageInstallationQueueEditor::create(array('processNo' => $processNo, 'userID' => CLIWCF::getUser()->userID, 'package' => $archive->getPackageInfo('name'), 'packageName' => $archive->getLocalizedPackageInfo('packageName'), 'packageID' => $package !== null ? $package->packageID : null, 'archive' => $file, 'action' => $package !== null ? 'update' : 'install')); // PackageInstallationDispatcher::openQueue() $parentQueueID = 0; $conditions = new PreparedStatementConditionBuilder(); $conditions->add("userID = ?", array(CLIWCF::getUser()->userID)); $conditions->add("parentQueueID = ?", array($parentQueueID)); if ($processNo != 0) { $conditions->add("processNo = ?", array($processNo)); } $conditions->add("done = ?", array(0)); $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_package_installation_queue\n\t\t\t" . $conditions . "\n\t\t\tORDER BY\tqueueID ASC"; $statement = CLIWCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); $packageInstallation = $statement->fetchArray(); if (!isset($packageInstallation['queueID'])) { $this->error('internalOpenQueue'); return; } else { $queueID = $packageInstallation['queueID']; } // PackageInstallationConfirmPage::readParameters() $queue = new PackageInstallationQueue($queueID); if (!$queue->queueID || $queue->done) { $this->error('internalReadParameters'); return; } // PackageInstallationConfirmPage::readData() $missingPackages = 0; $packageInstallationDispatcher = new PackageInstallationDispatcher($queue); // get requirements $requirements = $packageInstallationDispatcher->getArchive()->getRequirements(); $openRequirements = $packageInstallationDispatcher->getArchive()->getOpenRequirements(); foreach ($requirements as &$requirement) { if (isset($openRequirements[$requirement['name']])) { $requirement['status'] = 'missing'; $requirement['action'] = $openRequirements[$requirement['name']]['action']; if (!isset($requirement['file'])) { if ($requirement['action'] === 'update') { $requirement['status'] = 'missingVersion'; $requirement['existingVersion'] = $openRequirements[$requirement['name']]['existingVersion']; } $missingPackages++; } else { $requirement['status'] = 'delivered'; $packageArchive = new PackageArchive($packageInstallationDispatcher->getArchive()->extractTar($requirement['file'])); $packageArchive->openArchive(); // make sure that the delivered package is correct if ($requirement['name'] != $packageArchive->getPackageInfo('name')) { $requirement['status'] = 'invalidDeliveredPackage'; $requirement['deliveredPackage'] = $packageArchive->getPackageInfo('name'); $missingPackages++; } else { if (isset($requirement['minversion'])) { // make sure that the delivered version is sufficient if (Package::compareVersion($requirement['minversion'], $packageArchive->getPackageInfo('version')) > 0) { $requirement['deliveredVersion'] = $packageArchive->getPackageInfo('version'); $requirement['status'] = 'missingVersion'; $missingPackages++; } } } } } else { $requirement['status'] = 'installed'; } } unset($requirement); // PackageInstallationConfirmPage::assignVariables/show() $excludingPackages = $packageInstallationDispatcher->getArchive()->getConflictedExcludingPackages(); $excludedPackages = $packageInstallationDispatcher->getArchive()->getConflictedExcludedPackages(); if (!($missingPackages == 0 && count($excludingPackages) == 0 && count($excludedPackages) == 0)) { $this->error('missingPackagesOrExclude', array('requirements' => $requirements, 'excludingPackages' => $excludingPackages, 'excludedPackages' => $excludedPackages)); return; } // AbstractDialogAction::readParameters() $step = 'prepare'; $queueID = $queue->queueID; $node = ''; // initialize progressbar $progressbar = new ProgressBar(new ConsoleProgressBar(array('width' => CLIWCF::getTerminal()->getWidth(), 'elements' => array(ConsoleProgressBar::ELEMENT_PERCENT, ConsoleProgressBar::ELEMENT_BAR, ConsoleProgressBar::ELEMENT_TEXT), 'textWidth' => min(floor(CLIWCF::getTerminal()->getWidth() / 2), 50)))); // InstallPackageAction::readParameters() $finished = false; while (!$finished) { $queue = new PackageInstallationQueue($queueID); if (!$queue->queueID) { // todo: what to output? echo "InstallPackageAction::readParameters()"; return; } $installation = new PackageInstallationDispatcher($queue); switch ($step) { case 'prepare': // InstallPackageAction::stepPrepare() // update package information $installation->updatePackage(); // clean-up previously created nodes $installation->nodeBuilder->purgeNodes(); // create node tree $installation->nodeBuilder->buildNodes(); $node = $installation->nodeBuilder->getNextNode(); $queueID = $installation->nodeBuilder->getQueueByNode($installation->queue->processNo, $node); $step = 'install'; $progress = 0; $currentAction = $installation->nodeBuilder->getPackageNameByQueue($queueID); break; case 'install': // InstallPackageAction::stepInstall() $step_ = $installation->install($node); $queueID = $installation->nodeBuilder->getQueueByNode($installation->queue->processNo, $step_->getNode()); if ($step_->hasDocument()) { $innerTemplate = $step_->getTemplate(); $progress = $installation->nodeBuilder->calculateProgress($node); $node = $step_->getNode(); $currentAction = $installation->nodeBuilder->getPackageNameByQueue($queueID); } else { if ($step_->getNode() == '') { // perform final actions $installation->completeSetup(); // InstallPackageAction::finalize() CacheHandler::getInstance()->flushAll(); // /InstallPackageAction::finalize() // show success $progress = 100; $currentAction = CLIWCF::getLanguage()->get('wcf.acp.package.installation.step.install.success'); $finished = true; continue; } else { // continue with next node $progress = $installation->nodeBuilder->calculateProgress($node); $node = $step_->getNode(); $currentAction = $installation->nodeBuilder->getPackageNameByQueue($queueID); } } break; } $progressbar->update($progress, $currentAction); } $progressbar->getAdapter()->finish(); }
/** * Validates the download package input. */ protected function validateDownloadPackage() { if (FileUtil::isURL($this->downloadPackage)) { // download package $this->archive = new PackageArchive($this->downloadPackage, $this->package); try { $this->downloadPackage = $this->archive->downloadArchive(); //$this->archive->downloadArchive(); } catch (SystemException $e) { throw new UserInputException('downloadPackage', 'notFound'); } } else { // probably local path if (!file_exists($this->downloadPackage)) { throw new UserInputException('downloadPackage', 'notFound'); } $this->archive = new PackageArchive($this->downloadPackage, $this->package); } $this->validateArchive('downloadPackage'); }
/** * Creates the Body (Message, Attachments) for the Mail * Returns the created Body to the function which invoke this class * * @return string mail body */ public function getBody() { $counter = 1; $this->body = ''; if (count($this->getAttachments())) { // add message $this->body .= '--' . $this->getBoundary() . self::$crlf; $this->body .= 'Content-Type: ' . $this->getContentType() . '; charset="UTF-8"' . self::$crlf; $this->body .= 'Content-Transfer-Encoding: 8bit' . self::$crlf; //$this->body .= self::$crlf.self::$crlf; $this->body .= self::$crlf; // wrap lines after 70 characters $this->body .= wordwrap($this->getMessage(), 70); $this->body .= self::$crlf . self::$crlf; $this->body .= '--' . $this->getBoundary() . self::$crlf; // add attachments foreach ($this->getAttachments() as $attachment) { $fileName = $attachment['name']; $path = $attachment['path']; // download file if (FileUtil::isURL($path)) { $tmpPath = FileUtil::getTemporaryFilename('mailAttachment_'); if (!@copy($path, $tmpPath)) { continue; } $path = $tmpPath; } // get file contents $data = @file_get_contents($path); $data = chunk_split(base64_encode($data), 70, self::$crlf); $this->body .= 'Content-Type: application/octetstream; name="' . $fileName . '"' . self::$crlf; $this->body .= 'Content-Transfer-Encoding: base64' . self::$crlf; $this->body .= 'Content-Disposition: attachment; filename="' . $fileName . '"' . self::$crlf . self::$crlf; $this->body .= $data . self::$crlf . self::$crlf; if ($counter < count($this->getAttachments())) { $this->body .= '--' . $this->getBoundary() . self::$crlf; } $counter++; } $this->body .= self::$crlf . '--' . $this->getBoundary() . '--'; } else { //$this->body .= self::$crlf; $this->body .= $this->getMessage(); } return $this->body; }
/** * Validates the download package input. */ protected function validateDownloadPackage() { $this->activeTabMenuItem = 'upload'; if (FileUtil::isURL($this->downloadPackage)) { // download package $this->archive = new PackageArchive($this->downloadPackage, $this->package); try { $this->downloadPackage = $this->archive->downloadArchive(); } catch (SystemException $e) { throw new UserInputException('downloadPackage', 'downloadFailed'); } } else { // probably local path if (!file_exists($this->downloadPackage)) { throw new UserInputException('downloadPackage', 'downloadFailed'); } } if (!PackageValidationManager::getInstance()->validate($this->downloadPackage, false)) { $exception = PackageValidationManager::getInstance()->getException(); if ($exception instanceof PackageValidationException) { switch ($exception->getCode()) { case PackageValidationException::INVALID_PACKAGE_NAME: case PackageValidationException::MISSING_PACKAGE_XML: throw new UserInputException('downloadPackage', 'noValidPackage'); break; } } } $this->package = PackageValidationManager::getInstance()->getPackageValidationArchive()->getPackage(); }
private static function parseAdditionalStyles(&$variables) { self::$variables = $variables; // fix images location if (!empty(self::$variables['global.images.location']) && !FileUtil::isURL(self::$variables['global.images.location']) && substr(self::$variables['global.images.location'], 0, 1) != '/') { self::$variables['global.images.location'] = '../' . self::$variables['global.images.location']; } // fix images location if (!empty(self::$variables['global.icons.location']) && !FileUtil::isURL(self::$variables['global.icons.location']) && substr(self::$variables['global.icons.location'], 0, 1) != '/') { self::$variables['global.icons.location'] = '../' . self::$variables['global.icons.location']; } // parse additional styles if (!empty($variables['user.additional.style.input1.use'])) { $variables['user.additional.style.input1.use'] = preg_replace_callback('/\\$([a-z0-9_\\-\\.]+)\\$/', array('self', 'parseAdditionalStylesCallback'), $variables['user.additional.style.input1.use']); } if (!empty($variables['user.additional.style.input2.use'])) { $variables['user.additional.style.input2.use'] = preg_replace_callback('/\\$([a-z0-9_\\-\\.]+)\\$/', array('self', 'parseAdditionalStylesCallback'), $variables['user.additional.style.input2.use']); } }
/** * Returns current package archive. * * @return \wcf\system\package\PackageArchive */ public function getArchive() { if ($this->archive === null) { $package = $this->getPackage(); // check if we're doing an iterative update of the same package if ($this->previousPackageData !== null && $this->getPackage()->package == $this->previousPackageData['package']) { if (Package::compareVersion($this->getPackage()->packageVersion, $this->previousPackageData['packageVersion'], '<')) { // fake package to simulate the package version required by current archive $this->getPackage()->setPackageVersion($this->previousPackageData['packageVersion']); } } $this->archive = new PackageArchive($this->queue->archive, $this->getPackage()); if (FileUtil::isURL($this->archive->getArchive())) { // get return value and update entry in // package_installation_queue with this value $archive = $this->archive->downloadArchive(); $queueEditor = new PackageInstallationQueueEditor($this->queue); $queueEditor->update(array('archive' => $archive)); } $this->archive->openArchive(); } return $this->archive; }
/** * Unzips compressed package archives and returns the temporary file name. * * @param string $archive filename * @return string */ public static function unzipPackageArchive($archive) { if (!FileUtil::isURL($archive)) { $tar = new Tar($archive); $tar->close(); if ($tar->isZipped()) { $tmpName = FileUtil::getTemporaryFilename('package_'); if (FileUtil::uncompressFile($archive, $tmpName)) { return $tmpName; } } } return $archive; }
/** * Exports smilies. */ public function exportSmilies($offset, $limit) { $sql = "SELECT\t\t*\n\t\t\tFROM\t\t" . $this->databasePrefix . "smilies\n\t\t\tORDER BY\tsmilieid"; $statement = $this->database->prepareStatement($sql, $limit, $offset); $statement->execute(); while ($row = $statement->fetchArray()) { // replace imagefolder $row['smiliepath'] = str_replace('{imagefolder}', 'images', $row['smiliepath']); // insert source path if (!FileUtil::isURL($row['smiliepath'])) { $row['smiliepath'] = $this->fileSystemPath . $row['smiliepath']; } ImportHandler::getInstance()->getImporter('com.woltlab.wcf.smiley')->import($row['smilieid'], array('smileyTitle' => $row['smilietitle'], 'smileyCode' => $row['smiliecode'], 'showOrder' => $row['smilieorder']), array('fileLocation' => $row['smiliepath'])); } }
/** * Exports user avatars. */ public function exportUserAvatars($offset, $limit) { $sql = "(\n\t\t\t\tSELECT\t\tid_member, 'attachment' AS type, filename AS avatarName, (id_attach || '_' || file_hash) AS filename\n\t\t\t\tFROM\t\t" . $this->databasePrefix . "attachments\n\t\t\t\tWHERE\t\tid_member <> ?\n\t\t\t)\n\t\t\tUNION\n\t\t\t(\n\t\t\t\tSELECT\t\tid_member, 'user' AS type, avatar AS avatarName, avatar AS filename\n\t\t\t\tFROM\t\t" . $this->databasePrefix . "members\n\t\t\t\tWHERE\t\tavatar <> ?\n\t\t\t)"; $statement = $this->database->prepareStatement($sql, $limit, $offset); $statement->execute(array('', 0)); while ($row = $statement->fetchArray()) { switch ($row['type']) { case 'attachment': $fileLocation = $this->readOption('attachmentUploadDir') . '/' . $row['filename']; break; case 'user': if (FileUtil::isURL($row['filename'])) { return; } $fileLocation = $this->readOption('avatar_directory') . '/' . $row['filename']; break; } ImportHandler::getInstance()->getImporter('com.woltlab.wcf.user.avatar')->import(0, array('avatarName' => basename($row['avatarName']), 'avatarExtension' => pathinfo($row['avatarName'], PATHINFO_EXTENSION), 'userID' => $row['id_member']), array('fileLocation' => $fileLocation)); } }