/**
  * @see CacheBuilder::getData()
  */
 public function getData($cacheResource)
 {
     $data = array();
     $sql = "SELECT\t*\n\t\t\tFROM\tpb" . PB_N . "_setup_resource";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $data[$row['sourceID']][] = FileUtil::unifyDirSeperator($row['directory']);
     }
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * @see	SCM::checkout()
  */
 public static function checkout($url, $directory, array $loginDetails = array(), array $options = array())
 {
     if (empty($directory)) {
         throw new SubversionException('Subversion checkout: target directory missing.');
     }
     // append directory
     $directory = FileUtil::unifyDirSeperator($directory);
     $options['directory'] = $directory;
     return self::executeCommand('checkout', $url, $loginDetails, $options);
 }
 /**
  * Creates a new source.
  *
  * @param 	string		$name			The name of the source
  * @param	string		$sourceDirectory	Source directory used for files
  * @param	string		$buildDirectory		Build directory contains all archives
  * @param	string		$scm			Defines used SCM, may be 'git', 'none' and 'subversion'
  * @param	string		$url			URL for accessing subversion
  * @param	string		$username		Username neccessary if subversion repository is protected
  * @param	string		$password		Password neccessary if subversion repository is protected
  * @param	boolean		$trustServerCert	Automaticly trust server certificate
  * @param	boolean		$enableCheckout		Enables checkout ability
  * @param	integer		$position		Position used to order sources
  * @return 	SourceEditor
  */
 public static function create($name, $sourceDirectory, $buildDirectory, $scm, $url, $username, $password, $trustServerCert, $enableCheckout, $position)
 {
     // handle dir seperators
     $sourceDirectory = FileUtil::unifyDirSeperator($sourceDirectory);
     $buildDirectory = FileUtil::unifyDirSeperator($buildDirectory);
     // validate SCM
     $scm = self::validateSCM($scm);
     // save data
     $sourceID = self::insert($name, array('sourceDirectory' => $sourceDirectory, 'buildDirectory' => $buildDirectory, 'scm' => $scm, 'url' => $url, 'username' => $username, 'password' => $password, 'trustServerCert' => $trustServerCert, 'enableCheckout' => $enableCheckout));
     // get source
     $source = new SourceEditor($sourceID, null);
     // set position
     $source->setPosition($position);
     // create permissions
     $source->createPermissions();
     return $source;
 }
 /**
  * @see	Page::readData()
  */
 public function readData()
 {
     // read cache
     WCF::getCache()->addResource('packages-' . $this->source->sourceID, PB_DIR . 'cache/cache.packages-' . $this->source->sourceID . '.php', PB_DIR . 'lib/system/cache/CacheBuilderPackages.class.php');
     try {
         $packages = WCF::getCache()->get('packages-' . $this->source->sourceID, 'packages');
     } catch (SystemException $e) {
         // fallback if no cache available
         $packages = array();
     }
     // handle packages
     foreach ($packages as $package) {
         $this->directories[$package['packageName']] = $package['packageName'];
         $this->packages[$package['directory']] = array('packageName' => $package['packageName'], 'version' => $package['version']);
     }
     // remove duplicates and sort directories
     asort($this->directories);
     // set build directory
     $this->buildDirectory = $this->source->buildDirectory;
     if (WCF::getUser()->getPermission('admin.source.canEditSources')) {
         $this->buildDirectory = StringUtil::replace(FileUtil::unifyDirSeperator(PB_DIR), '', $this->buildDirectory);
     }
     // get source configuration
     $sourceData = WCF::getSession()->getVar('source' . $this->source->sourceID);
     if ($sourceData !== null) {
         $sourceData = unserialize($sourceData);
         $this->currentDirectory = $sourceData['directory'];
         $this->currentPackageName = $sourceData['packageName'];
     } else {
         $sql = "SELECT\tdirectory, packageName\n\t\t\t\tFROM\tpb" . PB_N . "_user_preference\n\t\t\t\tWHERE \tuserID = " . WCF::getUser()->userID . "\n\t\t\t\t\tAND sourceID = " . $this->source->sourceID;
         $row = WCF::getDB()->getFirstRow($sql);
         $this->currentDirectory = $row['directory'];
         $this->currentPackageName = $row['packageName'];
         WCF::getSession()->register('source' . $this->source->sourceID, serialize(array('directory' => $row['directory'], 'packageName' => $row['packageName'])));
     }
     // set current filename
     $currentFilename = WCF::getSession()->getVar('filename' . $this->source->sourceID);
     if ($currentFilename !== null) {
         $this->currentFilename = $currentFilename;
     }
     // read current builds
     $this->sourceFileList = new SourceFileList();
     $this->sourceFileList->sqlConditions = 'source_file.sourceID = ' . $this->source->sourceID;
     $this->sourceFileList->sqlLimit = 0;
     $this->sourceFileList->readObjects();
 }
Ejemplo n.º 5
0
 /**
  * @see	SCM::getHeadRevision()
  */
 public static function getHeadRevision($url, array $loginDetails = array(), array $options = array())
 {
     try {
         self::validateGitPath();
         // not very nice or fast method to find out, but it should work
         self::checkout($url, GIT_TEMPORARY_DIRECTORY, $loginDetails, $options);
         $dir = explode('/', $url);
         $dir = str_replace('.git', '', $dir[count($dir) - 1]);
         $headdir = explode(" ", file_get_contents(FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(GIT_TEMPORARY_DIRECTORY)) . $dir . '/.git/HEAD'));
         $return = file_get_contents(FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(GIT_TEMPORARY_DIRECTORY)) . $dir . '/.git/' . trim($headdir[1]));
         $dir = DirectoryUtil::getInstance(FileUtil::addTrailingSlash(GIT_TEMPORARY_DIRECTORY) . $dir);
         $dir->removeComplete();
         return $return;
     } catch (GitException $e) {
         throw $e;
     } catch (SystemException $e) {
     }
 }
 /**
  * @see Form::readFormParameters()
  */
 public function readFormParameters()
 {
     parent::readFormParameters();
     if (isset($_POST['name'])) {
         $this->name = StringUtil::trim($_POST['name']);
     }
     if (isset($_POST['sourceDirectory'])) {
         $this->sourceDirectory = StringUtil::trim($_POST['sourceDirectory']);
     }
     $this->sourceDirectory = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator($this->sourceDirectory));
     if (isset($_POST['buildDirectory'])) {
         $this->buildDirectory = StringUtil::trim($_POST['buildDirectory']);
     }
     $this->buildDirectory = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator($this->buildDirectory));
     if (isset($_POST['position'])) {
         $this->position = intval($_POST['position']);
     }
     if (isset($_POST['scm'])) {
         $this->scm = StringUtil::trim($_POST['scm']);
     }
     if (isset($_POST['useSubversion'])) {
         $this->useSubversion = intval($_POST['useSubversion']);
     }
     if (isset($_POST['url'])) {
         $this->url = StringUtil::trim($_POST['url']);
     }
     if (isset($_POST['username'])) {
         $this->username = StringUtil::trim($_POST['username']);
     }
     if (isset($_POST['password'])) {
         $this->password = StringUtil::trim($_POST['password']);
     }
     if (isset($_POST['trustServerCert'])) {
         $this->trustServerCert = intval($_POST['trustServerCert']);
     }
     if (isset($_POST['enableCheckout'])) {
         $this->enableCheckout = intval($_POST['enableCheckout']);
     }
 }
Ejemplo n.º 7
0
 /**
  * Returns a random directory
  *
  * @param	string	$directory	Directory to include
  * @return	Random 	directory
  */
 public static function getRandomDirectory($directory)
 {
     $directory = PB_DIR . $directory . '/' . StringUtil::getRandomID() . '/';
     $directory = FileUtil::unifyDirSeperator($directory);
     return $directory;
 }
 /**
  * Uninstalls the files of this package.
  */
 public function uninstall()
 {
     // get absolute package dir
     $packageDir = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(realpath(WCF_DIR . $this->installation->getPackage()->getDir())));
     // create file list
     $files = array();
     // get files from log
     $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_package_installation_file_log\n\t\t\tWHERE \tpackageID = " . $this->installation->getPackageID();
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $files[] = $row['filename'];
     }
     if (count($files) > 0) {
         // delete files
         $this->installation->deleteFiles($packageDir, $files);
         // delete log entries
         parent::uninstall();
     }
 }
Ejemplo n.º 9
0
 /**
  * Returns the request uri of the active request.
  * 
  * @return	string
  */
 public static function getRequestURI()
 {
     $REQUEST_URI = '';
     /*if (!empty($_SERVER['REQUEST_URI'])) {
     			$REQUEST_URI = $_SERVER['REQUEST_URI'];
     		}
     		else {*/
     if (!empty($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], '.php') !== false) {
         $REQUEST_URI = $_SERVER['ORIG_PATH_INFO'];
     } else {
         if (!empty($_SERVER['ORIG_SCRIPT_NAME'])) {
             $REQUEST_URI = $_SERVER['ORIG_SCRIPT_NAME'];
         } else {
             if (!empty($_SERVER['SCRIPT_NAME'])) {
                 $REQUEST_URI = $_SERVER['SCRIPT_NAME'];
             } else {
                 if (!empty($_SERVER['PHP_SELF'])) {
                     $REQUEST_URI = $_SERVER['PHP_SELF'];
                 } else {
                     if (!empty($_SERVER['PATH_INFO'])) {
                         $REQUEST_URI = $_SERVER['PATH_INFO'];
                     }
                 }
             }
         }
     }
     if (!empty($_SERVER['QUERY_STRING'])) {
         $REQUEST_URI .= '?' . $_SERVER['QUERY_STRING'];
     }
     //}
     //if (!strstr($REQUEST_URI, '.')) $REQUEST_URI = 'index.php';
     return substr(FileUtil::unifyDirSeperator($REQUEST_URI), 0, 255);
 }
Ejemplo n.º 10
0
 /**
  * Adds a file to the tar archive.
  * 
  * @param	string		$filename
  * @param	string		$addDir
  * @param	string		$removeDir
  * @return	boolean		result
  */
 protected function addFile($filename, $addDir, $removeDir)
 {
     $filename = FileUtil::unifyDirSeperator($filename);
     $storedFilename = $filename;
     if (!empty($removeDir)) {
         $storedFilename = StringUtil::replaceIgnoreCase($removeDir, '', $filename);
     }
     if (!empty($addDir)) {
         $storedFilename = $addDir . $storedFilename;
     }
     if (is_file($filename)) {
         // open file
         $file = new File($filename, 'rb');
         // write header
         if (!$this->writeFileHeader($filename, $storedFilename)) {
             return false;
         }
         // write file content
         while (($buffer = $file->read(512)) != '') {
             $this->file->write(pack('a512', $buffer));
         }
         // close file
         $file->close();
     } else {
         // only directory header
         if (!$this->writeFileHeader($filename, $storedFilename)) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 11
0
 /**
  * Redirects the user agent.
  *
  * @param	string		$location
  * @param 	boolean		$prependDir
  * @param	boolean		$sendStatusCode
  */
 public static function redirect($location, $prependDir = true, $sendStatusCode = false)
 {
     if ($prependDir) {
         // @see http://www.woltlab.com/bugtracker/index.php?page=Bug&bugID=2909
         $location = self::getHost() . FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(dirname(WCF::getSession()->requestURI))) . $location;
     }
     //if ($sendStatusCode) @header('HTTP/1.0 301 Moved Permanently');
     if ($sendStatusCode) {
         @header('HTTP/1.1 307 Temporary Redirect');
     }
     header('Location: ' . $location);
 }
Ejemplo n.º 12
0
 /**
  * Scans the given dir for installed files.
  * 
  * @param 	string		$dir
  */
 protected function getInstalledFiles($dir)
 {
     if ($files = glob($dir . '*')) {
         foreach ($files as $file) {
             if (is_dir($file)) {
                 $this->getInstalledFiles(FileUtil::addTrailingSlash($file));
             } else {
                 self::$installedFiles[] = FileUtil::unifyDirSeperator($file);
             }
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * Searches a relative path emanating from an absolute installation path.
  * 
  * @param 	FTP 		$ftp
  * @param 	string 		$installPath
  * @return 	string		$relativeFtpPath
  */
 public static function getRelativeFtpPath(FTP $ftp, $installPath)
 {
     // write a zero byte test file to the presumptive root of the ftp server.
     $installPath = FileUtil::unifyDirSeperator($installPath);
     $destFile = self::writeDummyFile($ftp);
     $pathPrefix = '';
     if (!$destFile) {
         // loop through folders to find a writable directory
         $pathSegments = explode('/', FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($installPath)));
         foreach ($pathSegments as $path) {
             if (@$ftp->chdir($path)) {
                 $pathPrefix .= $path . '/';
                 if ($destFile = self::writeDummyFile($ftp)) {
                     for ($i = 0; $i < substr_count($pathPrefix, '/'); $i++) {
                         $ftp->cdup();
                     }
                     break;
                 }
             } else {
                 if (!empty($pathPrefix)) {
                     return null;
                 }
             }
         }
     }
     // search given installation path for that file.
     $pathSegments = explode('/', FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($installPath)));
     while (count($pathSegments) != 0) {
         if (preg_match('/^WIN/i', PHP_OS)) {
             $currentDir = FileUtil::addTrailingSlash(implode($pathSegments, '/'));
         } else {
             $currentDir = '/' . FileUtil::addTrailingSlash(implode($pathSegments, '/'));
         }
         if (@file_exists($currentDir . $destFile)) {
             $basePath = $currentDir;
             break;
         } else {
             array_pop($pathSegments);
         }
     }
     if ($pathPrefix . $destFile) {
         $ftp->delete($pathPrefix . $destFile);
     }
     // return the rest of the path which must be the relative path.
     $relativeFtpPath = FileUtil::addTrailingSlash($pathPrefix . str_replace($currentDir, '', $installPath));
     return $relativeFtpPath;
 }
 /**
  * Clones a directory.
  * 
  * @param	string		$buildDirectory
  * @param	string		$path
  */
 protected function cloneDirectory($buildDirectory, $path)
 {
     $path = FileUtil::addTrailingSlash($path);
     // ensure source directory exists
     if (!is_dir($this->resourceDirectory . $path)) {
         throw new SystemException("Required path '" . $path . "' within resource directory is not available.");
     }
     // create path
     if (!is_dir($buildDirectory . $path)) {
         FileUtil::makePath($buildDirectory . $path);
     }
     // copy files recursively
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->resourceDirectory . $path));
     while ($it->valid()) {
         if (!$it->isDot()) {
             // ignore .svn directories
             $tmp = explode('/', FileUtil::unifyDirSeperator($it->getSubPath()));
             if (in_array('.svn', $tmp)) {
                 $it->next();
                 continue;
             }
             $subPath = FileUtil::addTrailingSlash($it->getSubPath());
             if (!is_dir($buildDirectory . $path . $subPath)) {
                 FileUtil::makePath($buildDirectory . $path . $subPath);
             }
             copy($it->key(), $buildDirectory . $path . $it->getSubPathName());
         }
         $it->next();
     }
 }
 /**
  * returns an instance of DirectoryUtil
  *
  * @param 	string		$directory 	directorypath
  * @param	boolean		$recursive	should the directory be walked through recursive
  * @return 	object				DirectoryUtil object
  */
 public static function getInstance($directory, $recursive = true)
 {
     $directory = realpath(FileUtil::unifyDirSeperator($directory));
     if ($directory === false) {
         throw new SystemException('Invalid directory');
     }
     if (!isset(self::$instances[$recursive][$directory])) {
         self::$instances[$recursive][$directory] = new DirectoryUtil($directory, $recursive);
     }
     return self::$instances[$recursive][$directory];
 }