/**
  * Saves the source of this template.
  * 
  * @param	string		$source 
  */
 public function setSource($source)
 {
     $path = $this->getPath();
     // create dir
     $folder = dirname($path);
     if (!file_exists($folder) && !FileUtil::getSafeMode()) {
         mkdir($folder, 0777);
     }
     // set source
     require_once WCF_DIR . 'lib/system/io/File.class.php';
     $file = new File($path);
     $file->write($source);
     $file->close();
     @$file->chmod(0777);
 }
 /**
  * Imports a style.
  * 
  * @param	string		$filename
  * @param	integer		$packageID
  * @param	StyleEditor	$style
  * @return	StyleEditor
  */
 public static function import($filename, $packageID = PACKAGE_ID, $style = null)
 {
     // open file
     require_once WCF_DIR . 'lib/system/io/Tar.class.php';
     $tar = new Tar($filename);
     // get style data
     $data = self::readStyleData($tar);
     // fix safe_mode problem
     $iconsLocation = FileUtil::addTrailingSlash($data['variables']['global.icons.location']);
     $imagesLocation = $data['variables']['global.images.location'];
     if (FileUtil::getSafeMode() && !empty($data['images']) && !file_exists(WCF_DIR . $imagesLocation)) {
         $oldImagesLocation = $imagesLocation;
         $imagesLocation = 'images/' . str_replace('/', '-', preg_replace('!^images/!', '', $imagesLocation));
         foreach ($data['variables'] as $name => $value) {
             $data['variables'][$name] = str_replace($oldImagesLocation, $imagesLocation, $value);
         }
         $data['variables']['global.images.location'] = 'images/';
         if (strpos($data['variables']['page.logo.image'], '../') !== false) {
             $data['variables']['page.logo.image'] = 'images/' . basename($data['variables']['page.logo.image']);
         }
     }
     // create template pack
     $templatePackID = 0;
     if (!empty($data['templates'])) {
         // create template pack
         $originalTemplatePackName = $templatePackName = $data['name'];
         $templatePackFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templatePackName);
         if (empty($templatePackFolderName)) {
             $templatePackFolderName = 'generic' . StringUtil::substring(StringUtil::getRandomID(), 0, 8);
         }
         $originalTemplatePackFolderName = $templatePackFolderName;
         // get unique template pack name
         $i = 1;
         do {
             $sql = "SELECT\tCOUNT(*) AS count\n\t\t\t\t\tFROM\twcf" . WCF_N . "_template_pack\n\t\t\t\t\tWHERE\ttemplatePackName = '" . escapeString($templatePackName) . "'";
             $row = WCF::getDB()->getFirstRow($sql);
             if (!$row['count']) {
                 break;
             }
             $templatePackName = $originalTemplatePackName . '_' . $i;
             $i++;
         } while (true);
         // get unique folder name
         $i = 1;
         do {
             $sql = "SELECT\tCOUNT(*) AS count\n\t\t\t\t\tFROM\twcf" . WCF_N . "_template_pack\n\t\t\t\t\tWHERE\ttemplatePackFolderName = '" . escapeString(FileUtil::addTrailingSlash($templatePackFolderName)) . "'\n\t\t\t\t\t\tAND parentTemplatePackID = 0";
             $row = WCF::getDB()->getFirstRow($sql);
             if (!$row['count']) {
                 break;
             }
             $templatePackFolderName = $originalTemplatePackFolderName . '_' . $i;
             $i++;
         } while (true);
         $sql = "INSERT INTO\twcf" . WCF_N . "_template_pack\n\t\t\t\t\t\t(templatePackName, templatePackFolderName)\n\t\t\t\tVALUES\t\t('" . escapeString($templatePackName) . "', '" . FileUtil::addTrailingSlash(escapeString($templatePackFolderName)) . "')";
         WCF::getDB()->sendQuery($sql);
         $templatePackID = WCF::getDB()->getInsertID("wcf" . WCF_N . "_template_pack", 'templatePackID');
     }
     // save style
     if ($style !== null) {
         $style->update($data['name'], $data['variables'], $templatePackID, $data['description'], $data['version'], $data['date'], ($data['image'] ? 'images/' : '') . $data['image'], $data['copyright'], $data['license'], $data['authorName'], $data['authorURL']);
     } else {
         $style = self::create($data['name'], $data['variables'], $templatePackID, $data['description'], $data['version'], $data['date'], ($data['image'] ? 'images/' : '') . $data['image'], $data['copyright'], $data['license'], $data['authorName'], $data['authorURL'], 0, $packageID);
     }
     // import preview image
     if (!empty($data['image'])) {
         $i = $tar->getIndexByFilename($data['image']);
         if ($i !== false) {
             $tar->extract($i, WCF_DIR . 'images/' . $data['image']);
             @chmod(WCF_DIR . 'images/' . $data['image'], 0777);
         }
     }
     // import images
     if (!empty($data['images'])) {
         // create images folder if necessary
         if (!file_exists(WCF_DIR . $imagesLocation) && !FileUtil::getSafeMode()) {
             @mkdir(WCF_DIR . $data['variables']['global.images.location'], 0777);
             @chmod(WCF_DIR . $data['variables']['global.images.location'], 0777);
         }
         $i = $tar->getIndexByFilename($data['images']);
         if ($i !== false) {
             // extract images tar
             $destination = FileUtil::getTemporaryFilename('images_');
             $tar->extract($i, $destination);
             // open images tar
             $imagesTar = new Tar($destination);
             $contentList = $imagesTar->getContentList();
             foreach ($contentList as $key => $val) {
                 if ($val['type'] == 'file') {
                     $imagesTar->extract($key, WCF_DIR . $imagesLocation . basename($val['filename']));
                     @chmod(WCF_DIR . $imagesLocation . basename($val['filename']), 0666);
                 }
             }
             // delete tmp file
             $imagesTar->close();
             @unlink($destination);
         }
     }
     // import icons
     if (!empty($data['icons']) && $iconsLocation != 'icon/') {
         $i = $tar->getIndexByFilename($data['icons']);
         if ($i !== false) {
             // extract icons tar
             $destination = FileUtil::getTemporaryFilename('icons_');
             $tar->extract($i, $destination);
             // open icons tar and group icons by package
             $iconsTar = new Tar($destination);
             $contentList = $iconsTar->getContentList();
             $packageToIcons = array();
             foreach ($contentList as $key => $val) {
                 if ($val['type'] == 'file') {
                     $folders = explode('/', $val['filename']);
                     $packageName = array_shift($folders);
                     if (!isset($packageToIcons[$packageName])) {
                         $packageToIcons[$packageName] = array();
                     }
                     $packageToIcons[$packageName][] = array('index' => $val['index'], 'filename' => implode('/', $folders));
                 }
             }
             // copy icons
             foreach ($packageToIcons as $package => $icons) {
                 // try to find package
                 $sql = "SELECT\t*\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\t\tWHERE\tpackage = '" . escapeString($package) . "'\n\t\t\t\t\t\t\tAND standalone = 1";
                 $result = WCF::getDB()->sendQuery($sql);
                 while ($row = WCF::getDB()->fetchArray($result)) {
                     // get icon path
                     $iconDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . $iconsLocation;
                     // create icon path
                     if (!file_exists($iconDir)) {
                         @mkdir($iconDir, 0777);
                         @chmod($iconDir, 0777);
                     }
                     // copy icons
                     foreach ($icons as $icon) {
                         $iconsTar->extract($icon['index'], $iconDir . $icon['filename']);
                     }
                 }
             }
             // delete tmp file
             $iconsTar->close();
             @unlink($destination);
         }
     }
     // import templates
     if (!empty($data['templates'])) {
         $i = $tar->getIndexByFilename($data['templates']);
         if ($i !== false) {
             // extract templates tar
             $destination = FileUtil::getTemporaryFilename('templates_');
             $tar->extract($i, $destination);
             // open templates tar and group templates by package
             $templatesTar = new Tar($destination);
             $contentList = $templatesTar->getContentList();
             $packageToTemplates = array();
             foreach ($contentList as $key => $val) {
                 if ($val['type'] == 'file') {
                     $folders = explode('/', $val['filename']);
                     $packageName = array_shift($folders);
                     if (!isset($packageToTemplates[$packageName])) {
                         $packageToTemplates[$packageName] = array();
                     }
                     $packageToTemplates[$packageName][] = array('index' => $val['index'], 'filename' => implode('/', $folders));
                 }
             }
             // copy templates
             foreach ($packageToTemplates as $package => $templates) {
                 // try to find package
                 $sql = "SELECT\t*\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\t\tWHERE\tpackage = '" . escapeString($package) . "'\n\t\t\t\t\t\t\tAND standalone = 1";
                 $result = WCF::getDB()->sendQuery($sql);
                 while ($row = WCF::getDB()->fetchArray($result)) {
                     // get icon path
                     $templatesDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . 'templates/' . $templatePackFolderName);
                     // create template path
                     if (!file_exists($templatesDir)) {
                         @mkdir($templatesDir, 0777);
                         @chmod($templatesDir, 0777);
                     }
                     // copy templates
                     foreach ($templates as $template) {
                         $templatesTar->extract($template['index'], $templatesDir . $template['filename']);
                         $sql = "INSERT INTO\twcf" . WCF_N . "_template\n\t\t\t\t\t\t\t\t\t\t(packageID, templateName, templatePackID)\n\t\t\t\t\t\t\t\tVALUES\t\t(" . $row['packageID'] . ", '" . escapeString(str_replace('.tpl', '', $template['filename'])) . "', " . $templatePackID . ")";
                         WCF::getDB()->sendQuery($sql);
                     }
                 }
             }
             // delete tmp file
             $templatesTar->close();
             @unlink($destination);
         }
     }
     $tar->close();
     return $style;
 }
 /**
  * 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;
     }
 }
Exemplo n.º 4
0
 /**
  * Prompts for ftp access data.
  */
 protected function promptFtp()
 {
     // safe mode is not active or ftp extension is not loaded
     // skip ftp prompting
     if (FileUtil::getSafeMode() != 1 || !extension_loaded('ftp')) {
         return;
     }
     // get username and password
     if (isset($_POST['ftpHost'])) {
         $ftpHost = $_POST['ftpHost'];
     } else {
         $ftpHost = 'localhost';
     }
     if (isset($_POST['ftpUser'])) {
         $ftpUser = $_POST['ftpUser'];
     } else {
         $ftpUser = '';
     }
     if (isset($_POST['ftpPassword'])) {
         $ftpPassword = $_POST['ftpPassword'];
     } else {
         $ftpPassword = '';
     }
     $error = false;
     if (!empty($ftpUser)) {
         try {
             // create new ftp connection
             self::$ftpConnection = new FTP($ftpHost);
             self::$ftpConnection->login($ftpUser, $ftpPassword);
             return;
         } catch (SystemException $e) {
             $error = true;
         }
     }
     WCF::getTPL()->assign('ftpPassword', $ftpPassword);
     WCF::getTPL()->assign('ftpUser', $ftpUser);
     WCF::getTPL()->assign('ftpHost', $ftpHost);
     WCF::getTPL()->assign('error', $error);
     WCF::getTPL()->assign('nextStep', 'unzipFiles');
     WCF::getTPL()->display('stepPromptFtp');
     exit;
 }
 /**
  * @see Action::execute()
  */
 public function execute()
 {
     parent::execute();
     // header
     $buffer = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
     $buffer .= "<systeminfo xmlns=\"http://www.woltlab.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.woltlab.com/XSD/systeminfo.xsd\">\n";
     // system block
     $buffer .= "\t<system>\n";
     // os block
     $buffer .= "\t\t<os>\n";
     // os type
     $buffer .= "\t\t\t<type><![CDATA[" . StringUtil::escapeCDATA(StringUtil::toLowerCase(PHP_OS)) . "]]></type>\n";
     // try to get os version
     $osVersion = @exec('cat /proc/version');
     // Linux
     if (empty($osVersion)) {
         $osVersion = @exec('uname -a');
     }
     // FreeBSD / Darwin
     if (empty($osVersion)) {
         $osVersion = @exec('ver');
     }
     // Windows
     $buffer .= "\t\t\t<version><![CDATA[" . StringUtil::escapeCDATA($osVersion) . "]]></version>\n";
     $buffer .= "\t\t</os>\n";
     // webserver block
     $buffer .= "\t\t<webserver>\n";
     // webserver type
     $webserver = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
     $webserverType = 'other';
     if (stripos($webserver, 'apache') !== false) {
         $webserverType = 'apache';
     } else {
         if (stripos($webserver, 'iis') !== false) {
             $webserverType = 'iis';
         } else {
             if (stripos($webserver, 'lighttpd') !== false) {
                 $webserverType = 'lighttpd';
             } else {
                 if (stripos($webserver, 'zeus') !== false) {
                     $webserverType = 'zeus';
                 }
             }
         }
     }
     $buffer .= "\t\t\t<type><![CDATA[" . $webserverType . "]]></type>\n";
     // webserver version
     $buffer .= "\t\t\t<version><![CDATA[" . StringUtil::escapeCDATA($webserver) . "]]></version>\n";
     // webserver modules
     $modules = '';
     if (function_exists('apache_get_modules')) {
         $modules = @implode(', ', apache_get_modules());
     }
     $buffer .= "\t\t\t<modules><![CDATA[" . StringUtil::escapeCDATA($modules) . "]]></modules>\n";
     $buffer .= "\t\t</webserver>\n";
     // php block
     $buffer .= "\t\t<php>\n";
     // version
     $buffer .= "\t\t\t<version><![CDATA[" . StringUtil::escapeCDATA(PHP_VERSION) . "]]></version>\n";
     // integration
     $buffer .= "\t\t\t<integration><![CDATA[" . StringUtil::escapeCDATA(php_sapi_name()) . "]]></integration>\n";
     // safe-mode?
     $buffer .= "\t\t\t<safemode><![CDATA[" . FileUtil::getSafeMode() . "]]></safemode>\n";
     // suhosin?
     $buffer .= "\t\t\t<suhosin><![CDATA[" . intval(extension_loaded('suhosin')) . "]]></suhosin>\n";
     // php modules
     $buffer .= "\t\t\t<modules><![CDATA[" . StringUtil::escapeCDATA(implode(', ', get_loaded_extensions())) . "]]></modules>\n";
     $buffer .= "\t\t</php>\n";
     // sql block
     $buffer .= "\t\t<sql>\n";
     // type
     $buffer .= "\t\t\t<type><![CDATA[" . StringUtil::escapeCDATA(str_replace('Database', '', WCF::getDB()->getDBType())) . "]]></type>\n";
     // version
     $buffer .= "\t\t\t<version><![CDATA[" . StringUtil::escapeCDATA(WCF::getDB()->getVersion()) . "]]></version>\n";
     $buffer .= "\t\t</sql>\n";
     $buffer .= "\t</system>\n\n";
     // wcf block
     $buffer .= "\t<wcf>\n";
     $buffer .= "\t\t<packages>\n";
     $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_package\n\t\t\tORDER BY\tpackage";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $buffer .= "\t\t\t<package>\n";
         $buffer .= "\t\t\t\t<name><![CDATA[" . StringUtil::escapeCDATA($row['package']) . "]]></name>\n";
         $buffer .= "\t\t\t\t<version><![CDATA[" . StringUtil::escapeCDATA($row['packageVersion']) . "]]></version>\n";
         $buffer .= "\t\t\t</package>\n";
     }
     $buffer .= "\t\t</packages>\n";
     $buffer .= "\t</wcf>\n";
     $buffer .= "</systeminfo>";
     // output
     header('Content-Type: application/xml; charset=' . CHARSET);
     header('Content-Disposition: attachment; filename="systeminfo.xml"');
     header('Content-Length: ' . strlen($buffer));
     print $buffer;
     $this->executed();
     exit;
 }