示例#1
0
	/**
	 * Writes the given e-mail in a log file.
	 * 
	 * @param	Mail	$mail
	 */
	public function sendMail(Mail $mail) {
		if ($this->log === null) {
			$this->log = new File(MAIL_DEBUG_LOGFILE_PATH.'mail.log', 'ab');
		}
		
		$this->log->write($this->printMail($mail));
	}
示例#2
0
 /**
  * Saves meta data for given template.
  * 
  * @param	string		$templateName
  * @param	string		$filename
  * @param	string		$content
  */
 public function saveMetaData($templateName, $filename, $content)
 {
     $file = new File($filename);
     $file->write("<?php exit; /* meta data for template: " . $templateName . " (generated at " . gmdate('r') . ") DO NOT EDIT THIS FILE */ ?>\n");
     $file->write(serialize($content));
     $file->close();
 }
示例#3
0
 /**
  * Loads the compiled language file.
  * Compiles the language file before if necessary.
  */
 public function loadLanguage()
 {
     $filename = TMP_DIR . 'setup/lang/cache/' . $this->languageCode . '_wcf.setup.php';
     if (!file_exists($filename)) {
         $xml = new XML();
         $xml->load(TMP_DIR . 'setup/lang/setup_' . $this->languageCode . '.xml');
         // get language items
         $categoriesToCache = array();
         $items = $xml->xpath()->query('/ns:language/ns:category/ns:item');
         foreach ($items as $item) {
             $categoriesToCache[] = array('name' => $item->getAttribute('name'), 'cdata' => $item->nodeValue);
         }
         // update language files here
         if (count($categoriesToCache) > 0) {
             $file = new File($filename);
             $file->write("<?php\n/**\n* WoltLab Community Framework\n* language: " . $this->languageCode . "\n* encoding: UTF-8\n* category: WCF Setup\n* generated at " . gmdate("r") . "\n* \n* DO NOT EDIT THIS FILE\n*/\n");
             foreach ($categoriesToCache as $name) {
                 $file->write("\$this->items['" . $name['name'] . "'] = '" . str_replace("'", "\\'", $name['cdata']) . "';\n");
                 // compile dynamic language variables
                 if (strpos($name['cdata'], '{') !== false) {
                     $compiledString = LanguageFactory::getInstance()->getScriptingCompiler()->compileString($name['name'], $name['cdata']);
                     $file->write("\$this->dynamicItems['" . $name['name'] . "'] = '" . str_replace("'", "\\'", $compiledString['template']) . "';\n");
                 }
             }
             $file->write("?>");
             $file->close();
         }
     }
     include_once $filename;
     $this->setLocale();
 }
示例#4
0
 /**
  * @see	wcf\system\cache\source\ICacheSource::set()
  */
 public function set(array $cacheResource, $value)
 {
     // write cache
     $targetFile = new File($cacheResource['file']);
     $targetFile->write("<?php exit; /* cache: " . $cacheResource['cache'] . " (generated at " . gmdate('r') . ") DO NOT EDIT THIS FILE */ ?>\n");
     $targetFile->write(serialize($value));
     $targetFile->close();
     // add value
     $this->cache[$cacheResource['cache']] = $value;
     $this->loaded[$cacheResource['file']] = true;
 }
示例#5
0
 /**
  * Writes the given e-mail in a log file.
  * 
  * @param	Mail	$mail
  */
 public function sendMail(Mail $mail)
 {
     if ($this->log === null) {
         $logFilePath = '';
         if (MAIL_DEBUG_LOGFILE_PATH) {
             $logFilePath = FileUtil::addTrailingSlash(MAIL_DEBUG_LOGFILE_PATH);
         } else {
             $logFilePath = WCF_DIR . 'log/';
         }
         $this->log = new File($logFilePath . 'mail.log', 'ab');
     }
     $this->log->write($this->printMail($mail));
 }
示例#6
0
 /**
  * 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)) {
         mkdir($folder, 0777);
     }
     // set source
     $file = new File($path);
     $file->write($source);
     $file->close();
     @$file->chmod(0777);
 }
示例#7
0
	/**
	 * @see	wcf\system\cache\source\ICacheSource::set()
	 */
	public function set($cacheName, $value, $maxLifetime) {
		$file = new File($this->getFilename($cacheName));
		$file->write("<?php exit; /* cache: ".$cacheName." (generated at ".gmdate('r').") DO NOT EDIT THIS FILE */ ?>\n");
		$file->write(serialize($value));
		$file->close();
	}
示例#8
0
 /**
  * Write the languages files.
  *
  * @param 	array		$categoryIDs
  * @param 	array		$packageIDs
  */
 protected function writeLanguageFiles(array $categoryIDs, array $packageIDs)
 {
     // get categories
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("languageCategoryID IN (?)", array($categoryIDs));
     $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_language_category\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     while ($category = $statement->fetchArray()) {
         $categoryName = $category['languageCategory'];
         $categoryID = $category['languageCategoryID'];
         // loop packages
         foreach ($packageIDs as $packageID) {
             $conditions = new PreparedStatementConditionBuilder();
             $conditions->add("languageID = ?", array($this->languageID));
             $conditions->add("languageCategoryID = ?", array($categoryID));
             // get language items
             if ($packageID === 0) {
                 // update after wcf installation
                 $conditions->add("packageID IS NULL");
                 $sql = "SELECT \tlanguageItem, languageItemValue, languageCustomItemValue, languageUseCustomValue\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_language_item\n\t\t\t\t\t\t" . $conditions;
             } else {
                 // update after regular package installation or update or manual import
                 $conditions->add("package_dependency.packageID = ?", array($packageID));
                 $sql = "SELECT\t\tlanguageItem, languageItemValue, languageCustomItemValue, languageUseCustomValue\n\t\t\t\t\t\tFROM\t\twcf" . WCF_N . "_language_item language_item\n\t\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\t\t\t\tON\t\t(package_dependency.dependency = language_item.packageID)\n\t\t\t\t\t\t" . $conditions . "\n\t\t\t\t\t\tORDER BY \tpackage_dependency.priority ASC";
             }
             $statement2 = WCF::getDB()->prepareStatement($sql);
             $statement2->execute($conditions->getParameters());
             $items = array();
             while ($row = $statement2->fetchArray()) {
                 if ($row['languageUseCustomValue'] == 1) {
                     $items[$row['languageItem']] = $row['languageCustomItemValue'];
                 } else {
                     $items[$row['languageItem']] = $row['languageItemValue'];
                 }
             }
             if (count($items) > 0) {
                 $file = new File(WCF_DIR . 'language/' . $packageID . '_' . $this->languageID . '_' . $categoryName . '.php');
                 @$file->chmod(0777);
                 $file->write("<?php\n/**\n* WoltLab Community Framework\n* language: " . $this->languageCode . "\n* encoding: UTF-8\n* category: " . $categoryName . "\n* generated at " . gmdate("r") . "\n* \n* DO NOT EDIT THIS FILE\n*/\n");
                 foreach ($items as $languageItem => $languageItemValue) {
                     $file->write("\$this->items['" . $languageItem . "'] = '" . str_replace("'", "\\'", $languageItemValue) . "';\n");
                     // compile dynamic language variables
                     if ($categoryName != 'wcf.global' && strpos($languageItemValue, '{') !== false) {
                         $output = LanguageFactory::getInstance()->getScriptingCompiler()->compileString($languageItem, $languageItemValue);
                         $file->write("\$this->dynamicItems['" . $languageItem . "'] = '" . str_replace("'", "\\'", $output['template']) . "';\n");
                     }
                 }
                 $file->write("?>");
                 $file->close();
             }
         }
     }
 }
示例#9
0
	/**
	 * Rebuilds the option file.
	 */
	public static function rebuild() {
		$buffer = '';
		
		// file header
		$buffer .= "<?php\n/**\n* generated at ".gmdate('r')."\n*/\n";
		
		// get all options
		$options = Option::getOptions();
		foreach ($options as $optionName => $option) {
			$buffer .= "if (!defined('".$optionName."')) define('".$optionName."', ".(($option->optionType == 'boolean' || $option->optionType == 'integer') ? intval($option->optionValue) : "'".addcslashes($option->optionValue, "'\\")."'").");\n";
		}
		unset($options);
		
		// file footer
		$buffer .= "\n";
		
		// open file
		$file = new File(WCF_DIR.'options.inc.php');
		
		// write buffer
		$file->write($buffer);
		
		// close file
		$file->close();
		@$file->chmod(0777);
	}
示例#10
0
	/**
	 * Writes the config.inc.php for an application.
	 * 
	 * @param	integer		$packageID
	 */
	public static function writeConfigFile($packageID) {
		$package = new Package($packageID);
		$packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$package->packageDir));
		$file = new File($packageDir.PackageInstallationDispatcher::CONFIG_FILE);
		$file->write("<?php\n");
		$prefix = strtoupper(self::getAbbreviation($package->package));
		
		$file->write("// ".$package->package." (packageID ".$package->packageID.")\n");
		$file->write("if (!defined('".$prefix."_DIR')) define('".$prefix."_DIR', dirname(__FILE__).'/');\n");
		$file->write("if (!defined('RELATIVE_".$prefix."_DIR')) define('RELATIVE_".$prefix."_DIR', '');\n");
		$file->write("\n");
		
		// write general information
		$file->write("// general info\n");
		$file->write("if (!defined('RELATIVE_WCF_DIR')) define('RELATIVE_WCF_DIR', RELATIVE_".$prefix."_DIR.'".FileUtil::getRelativePath($packageDir, WCF_DIR)."');\n");
		$file->write("if (!defined('PACKAGE_ID')) define('PACKAGE_ID', ".$packageID.");\n");
		$file->write("if (!defined('PACKAGE_NAME')) define('PACKAGE_NAME', '".str_replace("'", "\'", $package->getName())."');\n");
		$file->write("if (!defined('PACKAGE_VERSION')) define('PACKAGE_VERSION', '".$package->packageVersion."');\n");
		
		// write end
		$file->close();
	}
 /**
  * Tries to download a package from available update servers.
  * 
  * @param	string		$package		package identifier
  * @param	array		$packageUpdateVersions	package update versions
  * @param	boolean		$validateInstallInstructions
  * @return	string		tmp filename of a downloaded package
  */
 protected function downloadPackage($package, $packageUpdateVersions, $validateInstallInstructions = false)
 {
     // get download from cache
     if ($filename = $this->getCachedDownload($package, $packageUpdateVersions[0]['package'])) {
         return $filename;
     }
     // download file
     foreach ($packageUpdateVersions as $packageUpdateVersion) {
         // get auth data
         $authData = $this->getAuthData($packageUpdateVersion);
         if ($packageUpdateVersion['filename']) {
             $request = new HTTPRequest($packageUpdateVersion['filename'], !empty($authData) ? array('auth' => $authData) : array(), array('apiVersion' => PackageUpdate::API_VERSION));
         } else {
             // create request
             $request = new HTTPRequest($this->packageUpdateServers[$packageUpdateVersion['packageUpdateServerID']]->getDownloadURL(), !empty($authData) ? array('auth' => $authData) : array(), array('apiVersion' => PackageUpdate::API_VERSION, 'packageName' => $packageUpdateVersion['package'], 'packageVersion' => $packageUpdateVersion['packageVersion']));
         }
         try {
             $request->execute();
         } catch (HTTPUnauthorizedException $e) {
             throw new PackageUpdateUnauthorizedException($request, $this->packageUpdateServers[$packageUpdateVersion['packageUpdateServerID']], $packageUpdateVersion);
         }
         $response = $request->getReply();
         // check response
         if ($response['statusCode'] != 200) {
             throw new SystemException(WCF::getLanguage()->getDynamicVariable('wcf.acp.package.error.downloadFailed', array('__downloadPackage' => $package)) . ' (' . $response['body'] . ')');
         }
         // write content to tmp file
         $filename = FileUtil::getTemporaryFilename('package_');
         $file = new File($filename);
         $file->write($response['body']);
         $file->close();
         unset($response['body']);
         // test package
         $archive = new PackageArchive($filename);
         $archive->openArchive();
         // check install instructions
         if ($validateInstallInstructions) {
             $installInstructions = $archive->getInstallInstructions();
             if (empty($installInstructions)) {
                 throw new SystemException("Package '" . $archive->getLocalizedPackageInfo('packageName') . "' (" . $archive->getPackageInfo('name') . ") does not contain valid installation instructions.");
             }
         }
         $archive->getTar()->close();
         // cache download in session
         PackageUpdateDispatcher::getInstance()->cacheDownload($package, $packageUpdateVersion['packageVersion'], $filename);
         return $filename;
     }
     return false;
 }
示例#12
0
	/**
	 * @see	wcf\form\IForm::save()
	 */
	public function save() {
		// generate salt
		$salt = PasswordUtil::getRandomSalt();
		
		// write master password file
		$file = new File(WCF_DIR.'acp/masterPassword.inc.php');
		$file->write("<?php
/** MASTER PASSWORD STORAGE
DO NOT EDIT THIS FILE */
define('MASTER_PASSWORD', '".PasswordUtil::getSaltedHash($this->masterPassword, $salt)."');
define('MASTER_PASSWORD_SALT', '".$salt."');
?>");
		$file->close();
		@chmod(WCF_DIR.'acp/masterPassword.inc.php', 0777);
		
		parent::save();
	}
示例#13
0
 /**
  * @see wcf\system\io\IArchive::extract()
  */
 public function extract($offset, $destination)
 {
     if (!is_int($offset)) {
         $offset = $this->getIndexByFilename($offset);
     }
     try {
         $file = $this->readFile($offset);
     } catch (SystemException $e) {
         return false;
     }
     FileUtil::makePath(dirname($destination));
     if ($file['header']['type'] === 'folder') {
         FileUtil::makePath($destination);
         return;
     }
     $targetFile = new File($destination);
     $targetFile->write($file['content'], strlen($file['content']));
     $targetFile->close();
     if (FileUtil::isApacheModule() || !@$targetFile->is_writable()) {
         @$targetFile->chmod(0777);
     } else {
         @$targetFile->chmod(0755);
     }
     if ($file['header']['mtime']) {
         @$targetFile->touch($file['header']['mtime']);
     }
     // check filesize
     if (filesize($destination) != $file['header']['size']) {
         throw new SystemException("Could not unzip file '" . $file['header']['filename'] . "' to '" . $destination . "'. Maybe disk quota exceeded in folder '" . dirname($destination) . "'.");
     }
     return true;
 }
示例#14
0
 /**
  * Uncompresses a gzipped file and returns true if successful.
  * 
  * @param	string		$gzipped
  * @param	string		$destination
  * @return	boolean
  */
 public static function uncompressFile($gzipped, $destination)
 {
     if (!@is_file($gzipped)) {
         return false;
     }
     $sourceFile = new GZipFile($gzipped, 'rb');
     //$filesize = $sourceFile->getFileSize();
     $targetFile = new File($destination);
     while (!$sourceFile->eof()) {
         $targetFile->write($sourceFile->read(512), 512);
     }
     $targetFile->close();
     $sourceFile->close();
     self::makeWritable($destination);
     return true;
 }
示例#15
0
 /** 
  * @see	wcf\system\io\IArchive::extract()
  */
 public function extract($index, $destination)
 {
     if (!$this->read) {
         $this->open();
         $this->readContent();
     }
     $header = $this->getFileInfo($index);
     FileUtil::makePath(dirname($destination));
     if ($header['type'] === 'folder') {
         FileUtil::makePath($destination);
         return;
     }
     // seek to offset
     $this->file->seek($header['offset']);
     $targetFile = new File($destination);
     // read data
     $n = floor($header['size'] / 512);
     for ($i = 0; $i < $n; $i++) {
         $content = $this->file->read(512);
         $targetFile->write($content, 512);
     }
     if ($header['size'] % 512 != 0) {
         $content = $this->file->read(512);
         $targetFile->write($content, $header['size'] % 512);
     }
     $targetFile->close();
     if (FileUtil::isApacheModule() || !@$targetFile->is_writable()) {
         @$targetFile->chmod(0777);
     } else {
         @$targetFile->chmod(0755);
     }
     if ($header['mtime']) {
         @$targetFile->touch($header['mtime']);
     }
     // check filesize
     if (filesize($destination) != $header['size']) {
         throw new SystemException("Could not untar file '" . $header['filename'] . "' to '" . $destination . "'. Maybe disk quota exceeded in folder '" . dirname($destination) . "'.");
     }
     return true;
 }
示例#16
0
 /**
  * Rebuilds cached options
  *
  * @param 	string 		filename
  * @param	integer		$packageID
  */
 public static function rebuildFile($filename, $packageID = PACKAGE_ID)
 {
     $buffer = '';
     // file header
     $buffer .= "<?php\n/**\n* generated at " . gmdate('r') . "\n*/\n";
     // get all options
     $options = Option::getOptions($packageID);
     foreach ($options as $optionName => $option) {
         $buffer .= "if (!defined('" . $optionName . "')) define('" . $optionName . "', " . ($option['optionType'] == 'boolean' || $option['optionType'] == 'integer' ? intval($option['optionValue']) : "'" . addcslashes($option['optionValue'], "'\\") . "'") . ");\n";
     }
     unset($options);
     // file footer
     $buffer .= "?>";
     // open file
     $file = new File($filename);
     // write buffer
     $file->write($buffer);
     unset($buffer);
     // close file
     $file->close();
     @$file->chmod(0777);
 }
示例#17
0
 /**
  * Shows the page for configurating the database connection.
  */
 protected function configureDB()
 {
     $availableDBClasses = self::getAvailableDBClasses();
     $dbHost = 'localhost';
     $dbUser = '******';
     $dbPassword = '';
     $dbName = 'wcf';
     $dbNumber = 1;
     $dbClass = '';
     // set $dbClass to first item in $availableDBClasses
     foreach ($availableDBClasses as $dbClass) {
         $dbClass = $dbClass['class'];
         break;
     }
     if (isset($_POST['send'])) {
         if (isset($_POST['dbHost'])) {
             $dbHost = $_POST['dbHost'];
         }
         if (isset($_POST['dbUser'])) {
             $dbUser = $_POST['dbUser'];
         }
         if (isset($_POST['dbPassword'])) {
             $dbPassword = $_POST['dbPassword'];
         }
         if (isset($_POST['dbName'])) {
             $dbName = $_POST['dbName'];
         }
         // ensure that $dbNumber is zero or a positive integer
         if (isset($_POST['dbNumber'])) {
             $dbNumber = max(0, intval($_POST['dbNumber']));
         }
         if (isset($_POST['dbClass'])) {
             $dbClass = $_POST['dbClass'];
         }
         // get port
         $dbPort = 0;
         if (preg_match('/^(.+?):(\\d+)$/', $dbHost, $match)) {
             $dbHost = $match[1];
             $dbPort = intval($match[2]);
         }
         // test connection
         try {
             // check db class
             $validDB = false;
             foreach ($availableDBClasses as $dbData) {
                 if ($dbData['class'] == $dbClass) {
                     $validDB = true;
                     break;
                 }
             }
             if (!$validDB) {
                 throw new SystemException("Database type '" . $dbClass . "'. is not available on this system.");
             }
             // check connection data
             $db = new $dbClass($dbHost, $dbUser, $dbPassword, $dbName, $dbPort, true);
             $db->connect();
             // check sql version
             if (!empty($availableDBClasses[$dbClass]['minversion'])) {
                 $compareSQLVersion = preg_replace('/^(\\d+\\.\\d+\\.\\d+).*$/', '\\1', $db->getVersion());
                 if (!(version_compare($compareSQLVersion, $availableDBClasses[$dbClass]['minversion']) >= 0)) {
                     throw new SystemException("Insufficient SQL version '" . $compareSQLVersion . "'. Version '" . $availableDBClasses[$dbClass]['minversion'] . "' or greater is needed.");
                 }
             }
             // check innodb support
             if ($dbClass == 'wcf\\system\\database\\MySQLDatabase') {
                 $sql = "SHOW ENGINES";
                 $statement = $db->prepareStatement($sql);
                 $statement->execute();
                 $hasInnoDB = false;
                 while ($row = $statement->fetchArray()) {
                     if ($row['Engine'] == 'InnoDB' && in_array($row['Support'], array('DEFAULT', 'YES'))) {
                         $hasInnoDB = true;
                         break;
                     }
                 }
                 if (!$hasInnoDB) {
                     throw new SystemException("Support for InnoDB is missing.");
                 }
             }
             // check for table conflicts
             $conflictedTables = $this->getConflictedTables($db, $dbNumber);
             // write config.inc
             if (empty($conflictedTables)) {
                 // connection successfully established
                 // write configuration to config.inc.php
                 $file = new File(WCF_DIR . 'config.inc.php');
                 $file->write("<?php\n");
                 $file->write("\$dbHost = '" . str_replace("'", "\\'", $dbHost) . "';\n");
                 $file->write("\$dbPort = " . $dbPort . ";\n");
                 $file->write("\$dbUser = '******'", "\\'", $dbUser) . "';\n");
                 $file->write("\$dbPassword = '******'", "\\'", $dbPassword) . "';\n");
                 $file->write("\$dbName = '" . str_replace("'", "\\'", $dbName) . "';\n");
                 $file->write("\$dbClass = '" . str_replace("'", "\\'", $dbClass) . "';\n");
                 $file->write("if (!defined('WCF_N')) define('WCF_N', {$dbNumber});\n");
                 $file->close();
                 // go to next step
                 $this->gotoNextStep('createDB');
                 exit;
             } else {
                 WCF::getTPL()->assign(array('conflictedTables' => $conflictedTables));
             }
         } catch (SystemException $e) {
             WCF::getTPL()->assign(array('exception' => $e));
         }
     }
     WCF::getTPL()->assign(array('dbHost' => $dbHost, 'dbUser' => $dbUser, 'dbPassword' => $dbPassword, 'dbName' => $dbName, 'dbNumber' => $dbNumber, 'dbClass' => $dbClass, 'availableDBClasses' => $availableDBClasses, 'nextStep' => 'configureDB'));
     WCF::getTPL()->display('stepConfigureDB');
 }
示例#18
0
 /**
  * Shows the page for configurating the database connection.
  */
 protected function configureDB()
 {
     $availableDBClasses = self::getAvailableDBClasses();
     $dbHost = 'localhost';
     $dbUser = '******';
     $dbPassword = '';
     $dbName = 'wcf';
     $dbNumber = '1';
     $dbClass = 'MySQLDatabase';
     if (!function_exists('mysql_connect')) {
         $dbClass = 'MySQLiDatabase';
     }
     $overwriteTables = false;
     if (isset($_POST['send'])) {
         if (isset($_POST['dbHost'])) {
             $dbHost = $_POST['dbHost'];
         }
         if (isset($_POST['dbUser'])) {
             $dbUser = $_POST['dbUser'];
         }
         if (isset($_POST['dbPassword'])) {
             $dbPassword = $_POST['dbPassword'];
         }
         if (isset($_POST['dbName'])) {
             $dbName = $_POST['dbName'];
         }
         if (isset($_POST['overwriteTables'])) {
             $overwriteTables = intval($_POST['overwriteTables']);
         }
         // Should the user not be prompted if converted or default n match an
         // existing installation number? By now the existing installation
         // will be overwritten just so!
         if (isset($_POST['dbNumber'])) {
             $dbNumber = intval($_POST['dbNumber']);
         }
         if (isset($_POST['dbClass'])) {
             $dbClass = $_POST['dbClass'];
         }
         // get port
         $dbPort = 0;
         if (preg_match('/^(.+?):(\\d+)$/', $dbHost, $match)) {
             $dbHost = $match[1];
             $dbPort = intval($match[2]);
         }
         // test connection
         try {
             // check db class
             $validDB = false;
             foreach ($availableDBClasses as $dbData) {
                 if ($dbData['class'] == $dbClass) {
                     $validDB = true;
                     break;
                 }
             }
             if (!$validDB) {
                 throw new SystemException("Database type '" . $dbClass . "'. is not available on this system.");
             }
             // check connection data
             $db = new $dbClass($dbHost, $dbUser, $dbPassword, $dbName, $dbPort);
             $db->connect();
             // check sql version
             if (!empty($availableDBClasses[$dbClass]['minversion'])) {
                 $sqlVersion = $db->getVersion();
                 if ($sqlVersion != 'unknown') {
                     $compareSQLVersion = preg_replace('/^(\\d+\\.\\d+\\.\\d+).*$/', '\\1', $sqlVersion);
                     if (!(version_compare($compareSQLVersion, $availableDBClasses[$dbClass]['minversion']) >= 0)) {
                         throw new SystemException("Insufficient SQL version '" . $compareSQLVersion . "'. Version '" . $availableDBClasses[$dbClass]['minversion'] . "' or greater is needed.");
                     }
                 }
             }
             // check for table conflicts
             $conflictedTables = $this->getConflictedTables($db, $dbNumber);
             if (!empty($conflictedTables) && ($overwriteTables || self::$developerMode)) {
                 // remove tables
                 $db->getEditor()->dropConflictedTables($conflictedTables);
             }
             // write config.inc
             if (empty($conflictedTables) || $overwriteTables || self::$developerMode) {
                 // connection successfully established
                 // write configuration to config.inc.php
                 $file = new File(WCF_DIR . 'config.inc.php');
                 $file->write("<?php\n");
                 $file->write("\$dbHost = '" . StringUtil::replace("'", "\\'", $dbHost) . "';\n");
                 $file->write("\$dbPort = " . $dbPort . ";\n");
                 $file->write("\$dbUser = '******'", "\\'", $dbUser) . "';\n");
                 $file->write("\$dbPassword = '******'", "\\'", $dbPassword) . "';\n");
                 $file->write("\$dbName = '" . StringUtil::replace("'", "\\'", $dbName) . "';\n");
                 $file->write("\$dbClass = '" . StringUtil::replace("'", "\\'", $dbClass) . "';\n");
                 $file->write("if (!defined('WCF_N')) define('WCF_N', {$dbNumber});\n?>");
                 $file->close();
                 // go to next step
                 $this->gotoNextStep('createDB');
                 exit;
             } else {
                 WCF::getTPL()->assign(array('conflictedTables' => $conflictedTables));
             }
         } catch (SystemException $e) {
             WCF::getTPL()->assign(array('exception' => $e));
         }
     }
     WCF::getTPL()->assign(array('dbHost' => $dbHost, 'dbUser' => $dbUser, 'dbPassword' => $dbPassword, 'dbName' => $dbName, 'dbNumber' => $dbNumber, 'dbClass' => $dbClass, 'availableDBClasses' => $availableDBClasses, 'nextStep' => 'configureDB'));
     WCF::getTPL()->display('stepConfigureDB');
 }
	/**
	 * Tries to download a package from available update servers.
	 * 
	 * @param	string		$package		package identifier
	 * @param	array		$packageUpdateVersions	package update versions
	 * @return	string		tmp filename of a downloaded package
	 */
	protected function downloadPackage($package, $packageUpdateVersions) {
		// get download from cache
		if ($filename = $this->getCachedDownload($package, $packageUpdateVersions[0]['package'])) {
			return $filename;
		}
		
		// download file
		$authorizationRequiredException = array();
		$systemExceptions = array();
		foreach ($packageUpdateVersions as $packageUpdateVersion) {
			try {
				// get auth data
				$authData = $this->getAuthData($packageUpdateVersion);
				
				// send request
				// TODO: Use HTTPRequest
				if (!empty($packageUpdateVersion['file'])) {
					$response = PackageUpdateDispatcher::getInstance()->sendRequest($packageUpdateVersion['file'], array(), $authData);
				}
				else {
					$response = PackageUpdateDispatcher::getInstance()->sendRequest($packageUpdateVersion['server'], array('packageName' => $packageUpdateVersion['package'], 'packageVersion' => $packageUpdateVersion['packageVersion']), $authData);
				}
				
				// check response
				// check http code
				if ($response['httpStatusCode'] == 401) {
					throw new PackageUpdateAuthorizationRequiredException($packageUpdateVersion['packageUpdateServerID'], (!empty($packageUpdateVersion['file']) ? $packageUpdateVersion['file'] : $packageUpdateVersion['server']), $response);
				}
				
				if ($response['httpStatusCode'] != 200) {
					throw new SystemException(WCF::getLanguage()->get('wcf.acp.packageUpdate.error.downloadFailed', array('$package' => $package)) . ' ('.$response['httpStatusLine'].')');
				}
				
				// write content to tmp file
				$filename = FileUtil::getTemporaryFilename('package_');
				$file = new File($filename);
				$file->write($response['content']);
				$file->close();
				unset($response['content']);
				
				// test package
				$archive = new PackageArchive($filename);
				$archive->openArchive();
				$archive->getTar()->close();
				
				// cache download in session
				PackageUpdateDispatcher::getInstance()->cacheDownload($package, $packageUpdateVersion['packageVersion'], $filename);
				
				return $filename;
			}
			catch (PackageUpdateAuthorizationRequiredException $e) {
				$authorizationRequiredException[] = $e;
			}
			catch (SystemException $e) {
				$systemExceptions[] = $e;
			}
		}
		
		if (!empty($authorizationRequiredException)) {
			throw array_shift($authorizationRequiredException);
		}
		
		if (!empty($systemExceptions)) {
			throw array_shift($systemExceptions);
		}
		
		return false;
	}
示例#20
0
 /**
  * Scales the style preview image.
  * 
  * @param	string		$filename
  * @return	boolean
  */
 public static function scalePreviewImage($filename)
 {
     $thumbnail = new Thumbnail($filename, self::STYLE_PREVIEW_IMAGE_MAX_WIDTH, self::STYLE_PREVIEW_IMAGE_MAX_HEIGHT);
     if ($source = $thumbnail->makeThumbnail()) {
         $file = new File($filename);
         $file->write($source);
         $file->close();
         return true;
     }
     return false;
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     // write master password file
     $file = new File(WCF_DIR . 'acp/masterPassword.inc.php');
     $file->write("<?php\n/** MASTER PASSWORD STORAGE\nDO NOT EDIT THIS FILE */\ndefine('MASTER_PASSWORD', '" . PasswordUtil::getDoubleSaltedHash($this->masterPassword) . "');\n?>");
     $file->close();
     FileUtil::makeWritable(WCF_DIR . 'acp/masterPassword.inc.php');
     parent::save();
 }
示例#22
0
	/**
	 * Write the languages files.
	 * 
	 * @param	array<integer>		$languageCategoryIDs
	 */
	protected function writeLanguageFiles(array $languageCategoryIDs) {
		$conditions = new PreparedStatementConditionBuilder();
		$conditions->add("languageID = ?", array($this->languageID));
		$conditions->add("languageCategoryID IN (?)", array($languageCategoryIDs));
		
		// get language items
		$sql = "SELECT	languageItem, languageItemValue, languageCustomItemValue,
				languageUseCustomValue, languageCategoryID
			FROM	wcf".WCF_N."_language_item
			".$conditions;
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute($conditions->getParameters());
		$items = array();
		while ($row = $statement->fetchArray()) {
			$languageCategoryID = $row['languageCategoryID'];
			if (!isset($items[$languageCategoryID])) {
				$items[$languageCategoryID] = array();
			}
			
			$items[$languageCategoryID][$row['languageItem']] = ($row['languageUseCustomValue']) ? $row['languageCustomItemValue'] : $row['languageItemValue'];
		}
		
		foreach ($items as $languageCategoryID => $languageItems) {
			$category = LanguageFactory::getInstance()->getCategoryByID($languageCategoryID);
			if ($category === null) {
				continue;
			}
			
			$content = "<?php\n/**\n* WoltLab Community Framework\n* language: ".$this->languageCode."\n* encoding: UTF-8\n* category: ".$category->languageCategory."\n* generated at ".gmdate("r")."\n* \n* DO NOT EDIT THIS FILE\n*/\n";
			foreach ($languageItems as $languageItem => $languageItemValue) {
				$content .= "\$this->items['".$languageItem."'] = '".str_replace("'", "\'", $languageItemValue)."';\n";
				
				// compile dynamic language variables
				if ($category->languageCategory != 'wcf.global' && strpos($languageItemValue, '{') !== false) {
					$output = LanguageFactory::getInstance()->getScriptingCompiler()->compileString($languageItem, $languageItemValue);
					$content .= "\$this->dynamicItems['".$languageItem."'] = '".str_replace("'", "\'", $output['template'])."';\n";
				}
			}
			
			$file = new File(WCF_DIR.'language/'.$this->languageID.'_'.$category->languageCategory.'.php');
			@$file->chmod(0777);
			$file->write($content . '?>');
			$file->close();
		}
	}
示例#23
0
 /**
  * Uncompresses a gzipped file
  *
  * @param 	string 		$gzipped
  * @param 	string 		$destination
  * @return 	boolean 	result
  */
 public static function uncompressFile($gzipped, $destination)
 {
     if (!@is_file($gzipped)) {
         return false;
     }
     $sourceFile = new GZipFile($gzipped, 'rb');
     //$filesize = $sourceFile->getFileSize();
     $targetFile = new File($destination);
     while (!$sourceFile->eof()) {
         $targetFile->write($sourceFile->read(512), 512);
     }
     $targetFile->close();
     $sourceFile->close();
     @$targetFile->chmod(0777);
     /*if ($filesize != filesize($destination)) {
     			@unlink($destination);
     			return false;
     		}*/
     return true;
 }
示例#24
0
 /**
  * Converts the file of this style to a RTL ("right-to-left") version. 
  */
 public static function updateStyleFileRTL()
 {
     // get contents of LTR version
     $contents = file_get_contents(WCF_DIR . 'acp/style/style-ltr.css');
     // convert ltr to rtl
     $contents = StyleUtil::convertCSSToRTL($contents);
     // write file
     $file = new File(WCF_DIR . 'acp/style/style-rtl.css');
     $file->write($contents);
     // close file
     $file->close();
     @chmod(WCF_DIR . 'acp/style/style-rtl.css', 0777);
 }