Beispiel #1
0
	/**
	 * Assigns a list of applications to a group and computes cookie domain and path.
	 */
	public function rebuild() {
		if (empty($this->objects)) {
			$this->readObjects();
		}
		
		$sql = "UPDATE	wcf".WCF_N."_application
			SET	cookieDomain = ?,
				cookiePath = ?
			WHERE	packageID = ?";
		$statement = WCF::getDB()->prepareStatement($sql);
		
		// calculate cookie path
		$domains = array();
		foreach ($this->objects as $application) {
			if (!isset($domains[$application->domainName])) {
				$domains[$application->domainName] = array();
			}
			
			$domains[$application->domainName][$application->packageID] = explode('/', FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($application->domainPath)));
		}
		
		WCF::getDB()->beginTransaction();
		foreach ($domains as $domainName => $data) {
			$path = null;
			foreach ($data as $domainPath) {
				if ($path === null) {
					$path = $domainPath;
				}
				else {
					foreach ($path as $i => $part) {
						if (!isset($domainPath[$i]) || $domainPath[$i] != $part) {
							// remove all following elements including current one
							foreach ($path as $j => $innerPart) {
								if ($j >= $i) {
									unset($path[$j]);
								}
							}
							
							// skip to next domain
							continue 2;
						}
					}
				}
			}
			
			$path = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash(implode('/', $path)));
			
			foreach (array_keys($data) as $packageID) {
				$statement->execute(array(
					$domainName,
					$path,
					$packageID
				));
			}
		}
		WCF::getDB()->commitTransaction();
	}
 /**
  * Assigns a list of applications to a group and computes cookie domain and path.
  */
 public function rebuild()
 {
     if (empty($this->objects)) {
         $this->readObjects();
     }
     $sql = "UPDATE\twcf" . WCF_N . "_application\n\t\t\tSET\tcookieDomain = ?,\n\t\t\t\tcookiePath = ?\n\t\t\tWHERE\tpackageID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     // calculate cookie path
     $domains = array();
     $regex = new Regex(':[0-9]+');
     foreach ($this->objects as $application) {
         $domainName = $application->domainName;
         if (StringUtil::endsWith($regex->replace($domainName, ''), $application->cookieDomain)) {
             $domainName = $application->cookieDomain;
         }
         if (!isset($domains[$domainName])) {
             $domains[$domainName] = array();
         }
         $domains[$domainName][$application->packageID] = explode('/', FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($application->domainPath)));
     }
     WCF::getDB()->beginTransaction();
     foreach ($domains as $domainName => $data) {
         $path = null;
         foreach ($data as $domainPath) {
             if ($path === null) {
                 $path = $domainPath;
             } else {
                 foreach ($path as $i => $part) {
                     if (!isset($domainPath[$i]) || $domainPath[$i] != $part) {
                         // remove all following elements including current one
                         foreach ($path as $j => $innerPart) {
                             if ($j >= $i) {
                                 unset($path[$j]);
                             }
                         }
                         // skip to next domain
                         continue 2;
                     }
                 }
             }
         }
         $path = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash(implode('/', $path)));
         foreach (array_keys($data) as $packageID) {
             $statement->execute(array($domainName, $path, $packageID));
         }
     }
     WCF::getDB()->commitTransaction();
     // rebuild templates
     LanguageFactory::getInstance()->deleteLanguageCache();
     // reset application cache
     ApplicationCacheBuilder::getInstance()->reset();
 }
Beispiel #3
0
 /**
  * Returns available location path.
  * 
  * @param	string		$location
  * @return	string
  */
 protected static function getFileLocation($location)
 {
     $location = FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($location));
     $location = WCF_DIR . $location;
     $index = null;
     do {
         $directory = $location . ($index === null ? '' : $index);
         if (!is_dir($directory)) {
             @mkdir($directory, 0777, true);
             FileUtil::makeWritable($directory);
             return FileUtil::addTrailingSlash($directory);
         }
         $index = $index === null ? 2 : $index + 1;
     } while (true);
 }
Beispiel #4
0
 /**
  * Returns the URI of the current page.
  * 
  * @return	string
  */
 public static function getRequestURI()
 {
     if (URL_LEGACY_MODE) {
         // resolve path and query components
         $scriptName = $_SERVER['SCRIPT_NAME'];
         $pathInfo = RouteHandler::getPathInfo();
         if (empty($pathInfo)) {
             // bug fix if URL omits script name and path
             $scriptName = substr($scriptName, 0, strrpos($scriptName, '/'));
         }
         $path = str_replace('/index.php', '', str_replace($scriptName, '', $_SERVER['REQUEST_URI']));
         if (!StringUtil::isUTF8($path)) {
             $path = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $path);
         }
         $path = FileUtil::removeLeadingSlash($path);
         $baseHref = self::getTPL()->get('baseHref');
         if (!empty($path) && mb_strpos($path, '?') !== 0) {
             $baseHref .= 'index.php/';
         }
         return $baseHref . $path;
     } else {
         $url = preg_replace('~^(https?://[^/]+)(?:/.*)?$~', '$1', self::getTPL()->get('baseHref'));
         $url .= $_SERVER['REQUEST_URI'];
         return $url;
     }
 }
Beispiel #5
0
 /**
  * Starts the extracting of the files.
  */
 protected function install()
 {
     $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) || mb_strpos($file['filename'], $this->folder) === 0) {
             if (!empty($this->folder)) {
                 $file['filename'] = str_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[] = $e->getMessage();
         }
     }
     // now untar all files
     foreach ($files as $index => $file) {
         try {
             $this->createFile($file, $index, $tar);
         } catch (SystemException $e) {
             $errors[] = $e->getMessage();
         }
     }
     if (!empty($errors)) {
         throw new SystemException('error(s) during the installation of the files.', 0, implode("<br />", $errors));
     }
     $this->logFiles($files);
     // close tar
     $tar->close();
 }
Beispiel #6
0
 /**
  * Searches the wcf dir.
  */
 protected function searchWcfDir()
 {
     if (self::$wcfDir) {
         $wcfDir = self::$wcfDir;
     } else {
         $wcfDir = FileUtil::unifyDirSeparator(INSTALL_SCRIPT_DIR) . 'wcf/';
     }
     $invalidDirectory = false;
     if (@is_file($wcfDir . 'lib/system/WCF.class.php')) {
         $invalidDirectory = true;
     }
     // 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::unifyDirSeparator(dirname($_SERVER['REQUEST_URI']))));
     }
     WCF::getTPL()->assign(array('nextStep' => 'unzipFiles', 'invalidDirectory' => $invalidDirectory, 'wcfDir' => $wcfDir, 'domainName' => $domainName, 'installScriptUrl' => $installScriptUrl, 'installScriptDir' => FileUtil::unifyDirSeparator(INSTALL_SCRIPT_DIR)));
     WCF::getTPL()->display('stepSearchWcfDir');
 }
Beispiel #7
0
 /**
  * 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))) . '/');
             if (dirname(dirname($wcfDir)) . '/' == TMP_DIR) {
                 $foundDirectory = false;
                 $wcfDir = FileUtil::unifyDirSeperator(INSTALL_SCRIPT_DIR) . 'wcf/';
             }
         } 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');
 }
	/**
	 * @see	wcf\form\IForm::validate()
	 */
	public function validate() {
		parent::validate();
		
		if (empty($this->domainName)) {
			throw new UserInputException('domainName');
		}
		else {
			$regex = new Regex('^https?\://');
			$this->domainName = FileUtil::removeTrailingSlash($regex->replace($this->domainName, ''));
			$this->cookieDomain = FileUtil::removeTrailingSlash($regex->replace($this->cookieDomain, ''));
			
			// domain may not contain path components
			$regex = new Regex('[/#\?&]');
			if ($regex->match($this->domainName)) {
				throw new UserInputException('domainName', 'containsPath');
			}
			else if ($regex->match($this->cookieDomain)) {
				throw new UserInputException('cookieDomain', 'containsPath');
			}
			
			// check if cookie domain shares the same domain (may exclude subdomains)
			if (!StringUtil::endsWith($this->domainName, $this->cookieDomain)) {
				throw new UserInputException('cookieDomain', 'notValid');
			}
		}
		
		if (empty($this->domainPath)) {
			$this->cookiePath = '';
		}
		else {
			// strip first and last slash
			$this->domainPath = FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($this->domainPath));
			$this->cookiePath = FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($this->cookiePath));
			
			if (!empty($this->cookiePath) && ($this->domainPath != $this->cookiePath)) {
				// check if cookie path is contained within domain path
				if (!StringUtil::startsWith($this->domainPath, $this->cookiePath)) {
					throw new UserInputException('cookiePath', 'notValid');
				}
			}
		}
		
		// add slashes
		$this->domainPath = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash($this->domainPath));
		$this->cookiePath = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash($this->cookiePath));
	}
Beispiel #9
0
	/**
	 * Returns the URI of the current page.
	 *
	 * @return	string
	 */
	public static function getRequestURI() {
		// resolve path and query components
		$scriptName = $_SERVER['SCRIPT_NAME'];
		if (empty($_SERVER['PATH_INFO'])) {
			// bug fix if URL omits script name and path
			$scriptName = substr($scriptName, 0, strrpos($scriptName, '/'));
		}
		
		$path = str_replace('/index.php', '', str_replace($scriptName, '', $_SERVER['REQUEST_URI']));
		if (!StringUtil::isASCII($path) && !StringUtil::isUTF8($path)) {
			$path = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $path);
		}
		$path = FileUtil::removeLeadingSlash($path);
		$baseHref = self::getTPL()->get('baseHref');
		
		if (!empty($path) && StringUtil::indexOf($path, '?') !== 0) {
			$baseHref .= 'index.php/';
		}
		
		return $baseHref . $path;
	}
Beispiel #10
0
 /**
  * @see	\wcf\page\IForm::readFormParameters()
  */
 public function readFormParameters()
 {
     parent::readFormParameters();
     I18nHandler::getInstance()->readValues();
     if (I18nHandler::getInstance()->isPlainValue('smileyTitle')) {
         $this->smileyTitle = I18nHandler::getInstance()->getValue('smileyTitle');
     }
     if (isset($_POST['showOrder'])) {
         $this->showOrder = intval($_POST['showOrder']);
     }
     if (isset($_POST['categoryID'])) {
         $this->categoryID = intval($_POST['categoryID']);
     }
     if (isset($_POST['smileyCode'])) {
         $this->smileyCode = StringUtil::trim($_POST['smileyCode']);
     }
     if (isset($_POST['aliases'])) {
         $this->aliases = StringUtil::unifyNewlines(StringUtil::trim($_POST['aliases']));
     }
     if (isset($_POST['smileyPath'])) {
         $this->smileyPath = FileUtil::removeLeadingSlash(StringUtil::trim($_POST['smileyPath']));
     }
     if (isset($_POST['uploadedFilename'])) {
         $this->uploadedFilename = StringUtil::trim($_POST['uploadedFilename']);
     }
     if (isset($_FILES['fileUpload'])) {
         $this->fileUpload = $_FILES['fileUpload'];
     }
 }