Example #1
0
	public function ChangeMode($file, $dirmode, $filemode, $recursive=false)
	{
		if(in_array($file, array(".",".."))) {
			return false;
		}

		if (is_dir($this->GetDir() . $file)) {
			$mode = $dirmode;
		} elseif (is_file($this->GetDir() . $file)) {
			$mode = $filemode;
		} else {
			return false;
		}

		if(isc_chmod($this->GetDir() . $file,$mode)) {
			if($recursive === true && is_dir($this->GetDir() . $file)) {

				$tmp = new FileClass;
				$tmp->SetLoadDir($this->GetDir() . $file);

				while(($f = $tmp->NextDirElement()) !== false) {
					$tmp->ChangeMode($f, $dirmode, $filemode, $recursive);
				}

				$tmp->CloseHandle();
				unset($tmp);

			} else {
				return true;
			}
		}else {
			return false;
		}
	}
Example #2
0
	public function DownloadNewTemplates2()
	{
		if(!isset($_REQUEST['template'])) {
			$GLOBALS['ErrorMessage'] = GetLang('InvalidTemplate');
			return false;
		}

		// Include the File_Archive package
		GetLib('class.zip');

		GetLib('class.file');
		$FileClass = new FileClass();

		$key = '';
		if(isset($_REQUEST['key'])) {
			$key = $_REQUEST['key'];
		}

		$downloadUrls = $this->GenerateTemplateDownloadURLs($_REQUEST['template'], $key);
		$url = $downloadUrls['url'];
		$streamUrl = $downloadUrls['streamUrl'];

		// Get the information about this template from the remote server
		$response = PostToRemoteFileAndGetResponse($url);

		// A remote connection couldn't be established
		if($response === null) {
			$GLOBALS['ErrorMessage'] = GetLang('InvalidTemplate');
			return false;
		}

		$templateXML = @simplexml_load_string($response);
		if(!is_object($templateXML)) {
			$GLOBALS['ErrorMessage'] = GetLang('InvalidTemplate');
			return false;
		}

		if(isset($templateXML->error)) {
			switch(strval($templateXML->error)) {
				case "invalid":
					$GLOBALS['ErrorMessage'] = GetLang('InvalidKey');
					return false;
				case "invalid_domain":
					$GLOBALS['ErrorMessage'] = GetLang('InvalidKeyDomain');
					return false;
				case "invalid_tpl":
					$GLOBALS['ErrorMessage'] = GetLang('InvalidKeyTemplate');
					return false;
				case "invalid_tpl2":
					$GLOBALS['ErrorMessage'] = GetLang('InvalidKeyTemplate2');
					return false;
				default:
					$GLOBALS['ErrorMessage'] = GetLang('InvalidTemplate');
					return false;
			}
		}

		// If safemode is enabled, simply redirect to the stream URL to download the ZIP
		if($this->safeMode) {
			header("Location: ".$streamUrl);
			exit;
		}

		// Template is valid, so download the zip file
		$data = PostToRemoteFileAndGetResponse($streamUrl, '', false);
		if($data === null) {
			$GLOBALS['ErrorMessage'] = GetLang('InvalidTemplate');
			return false;
		}

		$tmp_dir = ISC_BASE_PATH . "/cache/";
		$filename = $this->_GenRandFileName();
		$tmpFile = $tmp_dir . $filename . ".zip";

		// If we can't write to the temporary directory, show a message
		if(!CheckDirWritable($tmp_dir)) {
			$GLOBALS['ErrorMessage'] = GetLang('TempDirWriteError');
			return false;
		}

		// Cannot write the temporary file
		if(!$fp = @fopen($tmpFile, "wb+")) {
			$GLOBALS['ErrorMessage'] = GetLang("TempDirWriteError");
			return false;
		}

		// Write the contents
		if(!@fwrite($fp, $data)) {
			$GLOBALS['ErrorMessage'] = GetLang("TempDirWriteError");
			return false;
		}

		@fclose($fp);

		$templateName = strval($templateXML->name);

		// If this is an update for the template, remove the old one first
		$templatePath = ISC_BASE_PATH."/templates/".basename($_REQUEST['template']);
		if(is_dir($templatePath)) {
			$FileClass->SetDir('');
			$deleted = $FileClass->DeleteDir($templatePath, true);
			// Couldn't remove old template first
			if(!$deleted) {
				$GLOBALS['ErrorMessage'] = sprintf(GetLang("TemplateUnlinkError"), $templateName);
				return false;
			}
		}

		// Extract the new template
		$archive = new PclZip($tmpFile);
		if($archive->extract(PCLZIP_OPT_PATH, ISC_BASE_PATH."/templates") === 0) {
			$GLOBALS['ErrorMessage'] = GetLang('TemplateDirWriteError');
			return false;
		}

		// Remove the temporary file
		@unlink($tmpFile);

		// Set the file permissions on the new template
		$file = new FileClass;
		$file->SetLoadDir(ISC_BASE_PATH."/templates");
		$file->ChangeMode(basename($templatePath), ISC_WRITEABLE_DIR_PERM, ISC_WRITEABLE_FILE_PERM, true);
		$file->CloseHandle();
		return true;
	}