Beispiel #1
0
 /**
  *
  * @param string $bucket_name
  * @param string $prefix
  * @param string $access_key
  * @param string $secret_key
  * @param string $session_token
  * @param string $check_word
  * @param string $file_name
  */
 function __construct($bucket_name, $prefix, $access_key, $secret_key, $session_token, $check_word, $file_name)
 {
     parent::__construct(0);
     $this->arBucket = array("ACTIVE" => "Y", "SORT" => 0, "READ_ONLY" => "N", "SERVICE_ID" => "amazon_s3", "BUCKET" => $bucket_name, "LOCATION" => "", "CNAME" => "", "FILE_COUNT" => 0, "FILE_SIZE" => 0, "LAST_FILE_ID" => 0, "PREFIX" => $prefix, "SETTINGS" => array("ACCESS_KEY" => $access_key, "SECRET_KEY" => $secret_key, "SESSION_TOKEN" => $session_token), "FILE_RULES" => 'a:1:{i:0;a:3:{s:6:"MODULE";s:0:"";s:9:"EXTENSION";s:0:"";s:4:"SIZE";s:0:"";}}', "FILE_RULES_COMPILED" => array(array("MODULE_MASK" => "", "EXTENTION_MASK" => "", "SIZE_ARRAY" => array())));
     $this->file_name = $file_name;
     $this->check_word = $check_word;
 }
</option>
				<option value="all"><?php 
echo GetMessage("IBLOCK_CML2_FILTER_ALL");
?>
</option>
				<option value="none"><?php 
echo GetMessage("IBLOCK_CML2_FILTER_NONE");
?>
</option>
			</select>
		</td>
	</tr>
	<?php 
$bHaveClouds = false;
if (CModule::IncludeModule("clouds")) {
    $rsData = CCloudStorageBucket::GetList(array("SORT" => "DESC", "ID" => "ASC"));
    if ($rsData->Fetch()) {
        $bHaveClouds = true;
    }
}
if ($bHaveClouds) {
    ?>
	<tr>
		<td><label for="CK_DOWNLOAD_CLOUD_FILES"><?php 
    echo GetMessage("IBLOCK_CML2_DOWNLOAD_CLOUD_FILES");
    ?>
:</label></td>
		<td>
			<input name="DOWNLOAD_CLOUD_FILES" type="hidden" value="N">
			<input name="DOWNLOAD_CLOUD_FILES" id="CK_DOWNLOAD_CLOUD_FILES" type="checkbox" value="Y" checked="checked">
		</td>
Beispiel #3
0
 /**
  * @return void
  */
 private static function _init()
 {
     global $DB, $CACHE_MANAGER;
     if (isset(self::$arBuckets)) {
         return;
     }
     $cache_id = "cloud_buckets_v2";
     if (CACHED_b_clouds_file_bucket !== false && $CACHE_MANAGER->Read(CACHED_b_clouds_file_bucket, $cache_id, "b_clouds_file_bucket")) {
         self::$arBuckets = $CACHE_MANAGER->Get($cache_id);
     } else {
         self::$arBuckets = array();
         $rs = $DB->Query("\n\t\t\t\tSELECT *\n\t\t\t\tFROM b_clouds_file_bucket\n\t\t\t\tORDER BY SORT DESC, ID ASC\n\t\t\t");
         while (is_array($ar = $rs->Fetch())) {
             if ($ar["FILE_RULES"] != "") {
                 $arRules = unserialize($ar["FILE_RULES"]);
             } else {
                 $arRules = array();
             }
             $ar["FILE_RULES_COMPILED"] = self::CompileRules($arRules);
             if ($ar["SETTINGS"] != "") {
                 $arSettings = unserialize($ar["SETTINGS"]);
             } else {
                 $arSettings = array();
             }
             if (is_array($arSettings)) {
                 $ar["SETTINGS"] = $arSettings;
             } else {
                 $ar["SETTINGS"] = array();
             }
             self::$arBuckets[intval($ar['ID'])] = $ar;
         }
         if (CACHED_b_clouds_file_bucket !== false) {
             $CACHE_MANAGER->Set($cache_id, self::$arBuckets);
         }
     }
 }
Beispiel #4
0
    function GetItems($Params)
    {
        global $APPLICATION, $USER;
        static $checkChildren, $genTmb;
        if (!isset($checkChildren, $genTmb)) {
            $checkChildren = COption::GetOptionString("fileman", "file_dialog_check_children", "Y") == 'Y';
            $genTmb = COption::GetOptionString("fileman", "file_dialog_gen_thumb", "Y") == 'Y';
        }
        if (strlen($Params["site"]) > 2) {
            if (!$USER->CanDoOperation('clouds_browse')) {
                return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_ACCESS_DENIED'), 'access_denied');
            }
            if ($Params['operation'] !== 'O') {
                return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 04]', 'path_corrupt');
            }
            if (!CModule::IncludeModule('clouds')) {
                return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 01]', 'path_corrupt');
            }
            $obBucket = null;
            foreach (CCloudStorageBucket::GetAllBuckets() as $arBucket) {
                if ($arBucket["ACTIVE"] == "Y" && $arBucket["BUCKET"] === $Params["site"]) {
                    $obBucket = new CCloudStorageBucket($arBucket["ID"]);
                }
            }
            if (!$obBucket) {
                return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 02]', 'path_corrupt');
            }
            if (!$obBucket->Init()) {
                return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 03]', 'path_corrupt');
            }
            $path = preg_replace("#[\\\\\\/]+#", "/", "/" . $APPLICATION->UnJSEscape($Params['path']));
            $path_js = $path == "" ? "/" : addslashes(htmlspecialcharsex($path));
            $path_js = str_replace("//", "/", $path_js);
            $arFiles = $obBucket->ListFiles($path);
            if (!is_array($arFiles)) {
                return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 05]', 'path_corrupt');
            }
            ?>
arFDDirs['<?php 
            echo $path_js;
            ?>
'] = [];
arFDFiles['<?php 
            echo $path_js;
            ?>
'] = [];
<?php 
            foreach ($arFiles["dir"] as $ind => $dir) {
                ?>
arFDDirs['<?php 
                echo $path_js;
                ?>
'][<?php 
                echo $ind;
                ?>
] =
{
	name : '<?php 
                echo CUtil::JSEscape($dir);
                ?>
',
	path : '<?php 
                echo CUtil::JSEscape(preg_replace("#[\\\\\\/]+#", "/", $path . "/" . $dir));
                ?>
',
	empty: false,
	permission : {del : false, ren : false},
	date : '',
	timestamp : '',
	size : 0
};
<?php 
            }
            if ($Params['getFiles']) {
                foreach ($arFiles['file'] as $ind => $file) {
                    ?>
arFDFiles['<?php 
                    echo $path_js;
                    ?>
'][<?php 
                    echo $ind;
                    ?>
] =
{
	name : '<?php 
                    echo CUtil::JSEscape($file);
                    ?>
',
	path : '<?php 
                    echo CUtil::JSEscape($obBucket->GetFileSRC($path . "/" . $file));
                    ?>
',
	permission : {del : false, ren : false},
	date : '',
	timestamp : '',
	size : '<?php 
                    echo $arFiles["file_size"][$ind];
                    ?>
'
};
<?php 
                }
            }
            ?>
arFDPermission['<?php 
            echo $path_js;
            ?>
'] = {
	new_folder : false,
	upload : false
};
<?php 
            return;
        }
        $io = CBXVirtualIo::GetInstance();
        $site = $Params['site'];
        $path = $io->CombinePath("/", $APPLICATION->UnJSEscape($Params['path']));
        $path_js = $path == "" ? "/" : addslashes(htmlspecialcharsex($path));
        $path_js = str_replace("//", "/", $path_js);
        $bCheckEmpty = $Params['bCheckEmpty'];
        $rootPath = CSite::GetSiteDocRoot($site);
        if (!$io->FileExists($rootPath . $path) && !$io->DirectoryExists($rootPath . $path) && $Params['bThrowException'] === true) {
            return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT'), 'path_corrupt');
        } elseif (!$USER->CanDoFileOperation('fm_view_listing', array($site, $path))) {
            return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_ACCESS_DENIED'), 'access_denied');
        }
        $arDirs = array();
        $arFiles = array();
        GetDirList(array($site, $path), $arDirs, $arFiles, array(), array("name" => "asc"), "DF", false, true);
        ?>
arFDDirs['<?php 
        echo $path_js;
        ?>
'] = [];
arFDFiles['<?php 
        echo $path_js;
        ?>
'] = [];
<?php 
        $ind = -1;
        foreach ($arDirs as $Dir) {
            $name = addslashes(htmlspecialcharsex($Dir["NAME"]));
            $path_i = addslashes(htmlspecialcharsex($path)) . "/" . $name;
            $path_i = str_replace("//", "/", $path_i);
            $arPath_i = array($site, $path_i);
            if (!$USER->CanDoFileOperation('fm_view_listing', $arPath_i)) {
                continue;
            }
            $ind++;
            $empty = true;
            if ($bCheckEmpty) {
                $dirTmp = $io->GetDirectory($rootPath . $path . '/' . $name);
                $arDirTmpChildren = $dirTmp->GetChildren();
                foreach ($arDirTmpChildren as $child) {
                    if (!$child->IsDirectory()) {
                        continue;
                    }
                    $empty = false;
                    break;
                }
            }
            $perm_del = $USER->CanDoFileOperation('fm_delete_folder', $arPath_i) ? 'true' : 'false';
            $perm_ren = $USER->CanDoFileOperation('fm_rename_folder', $arPath_i) ? 'true' : 'false';
            ?>
arFDDirs['<?php 
            echo $path_js;
            ?>
'][<?php 
            echo $ind;
            ?>
] =
{
	name : '<?php 
            echo $name;
            ?>
',
	path : '<?php 
            echo $path_i;
            ?>
',
	empty: <?php 
            echo $empty ? 'true' : 'false';
            ?>
,
	permission : {del : <?php 
            echo $perm_del;
            ?>
, ren : <?php 
            echo $perm_ren;
            ?>
},
	date : '<?php 
            echo $Dir["DATE"];
            ?>
',
	timestamp : '<?php 
            echo $Dir["TIMESTAMP"];
            ?>
',
	size : 0
};
<?php 
        }
        if ($Params['getFiles']) {
            $ind = -1;
            foreach ($arFiles as $File) {
                $name = addslashes(htmlspecialcharsex($File["NAME"]));
                $path_i = addslashes(htmlspecialcharsex($File["ABS_PATH"]));
                $path_i = str_replace("//", "/", $path_i);
                $arPath_i = array($site, $path_i);
                if (!$USER->CanDoFileOperation('fm_view_file', $arPath_i)) {
                    continue;
                }
                $ind++;
                $perm_del = $USER->CanDoFileOperation('fm_delete_file', $arPath_i) ? 'true' : 'false';
                $perm_ren = $USER->CanDoFileOperation('fm_rename_file', $arPath_i) ? 'true' : 'false';
                $imageAddProps = '';
                if ($genTmb) {
                    $ext = strtolower(GetFileExtension($name));
                    if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png', 'jpe', 'bmp'))) {
                        $tmbPath = BX_PERSONAL_ROOT . "/tmp/fd_tmb" . $path_i;
                        $destinationFile = $rootPath . $tmbPath;
                        if (!file_exists($destinationFile)) {
                            $sourceFile = $File['PATH'];
                            if (CFile::ResizeImageFile($sourceFile, $destinationFile, array('width' => 140, 'height' => 110))) {
                                $imageAddProps = ",\n" . 'tmb_src : \'' . CUtil::JSEscape($tmbPath) . '\'';
                            }
                        } else {
                            $imageAddProps = ",\n" . 'tmb_src : \'' . CUtil::JSEscape($tmbPath) . '\'';
                        }
                    }
                }
                ?>
arFDFiles['<?php 
                echo $path_js;
                ?>
'][<?php 
                echo $ind;
                ?>
] =
{
	name : '<?php 
                echo $name;
                ?>
',
	path : '<?php 
                echo $path_i;
                ?>
',
	permission : {del : <?php 
                echo $perm_del;
                ?>
, ren : <?php 
                echo $perm_ren;
                ?>
},
	date : '<?php 
                echo $File["DATE"];
                ?>
',
	timestamp : '<?php 
                echo $File["TIMESTAMP"];
                ?>
',
	size : '<?php 
                echo $File["SIZE"];
                ?>
'<?php 
                echo $imageAddProps;
                ?>
};
<?php 
            }
        }
        $arPath = array($site, $path);
        ?>
arFDPermission['<?php 
        echo $path_js;
        ?>
'] = {
	new_folder : <?php 
        echo $USER->CanDoFileOperation('fm_create_new_folder', $arPath) ? 'true' : 'false';
        ?>
,
	upload : <?php 
        echo $USER->CanDoFileOperation('fm_upload_file', $arPath) ? 'true' : 'false';
        ?>
};
<?php 
    }
Beispiel #5
0
 public static function OnBeforeProlog()
 {
     if (defined("BX_CHECK_SHORT_URI") && BX_CHECK_SHORT_URI) {
         $upload_dir = "/" . trim(COption::GetOptionString("main", "upload_dir", "upload"), "/") . "/";
         $request_uri = urldecode($_SERVER["REQUEST_URI"]);
         $request_uri = CCloudUtil::URLEncode($request_uri, LANG_CHARSET);
         foreach (CCloudStorageBucket::GetAllBuckets() as $arBucket) {
             if ($arBucket["ACTIVE"] == "Y") {
                 $obBucket = new CCloudStorageBucket($arBucket["ID"]);
                 if ($obBucket->Init()) {
                     $match = array();
                     if ($obBucket->FileExists($request_uri)) {
                         if (COption::GetOptionString("clouds", "log_404_errors") === "Y") {
                             CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
                         }
                         LocalRedirect($obBucket->GetFileSRC($request_uri), true);
                     } elseif (strpos($request_uri, $upload_dir) === 0) {
                         $check_url = substr($request_uri, strlen($upload_dir) - 1);
                         if ($obBucket->FileExists($check_url)) {
                             if (COption::GetOptionString("clouds", "log_404_errors") === "Y") {
                                 CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
                             }
                             LocalRedirect($obBucket->GetFileSRC($check_url), true);
                         }
                     } elseif (COption::GetOptionString("clouds", "delayed_resize") === "Y" && preg_match("#^(/" . $obBucket->PREFIX . "|)(/resize_cache/.*\$)#", $request_uri, $match)) {
                         session_write_close();
                         $to_file = $obBucket->GetFileSRC(urldecode($match[2]));
                         if (CCloudStorage::ResizeImageFileCheck($obBucket, $to_file)) {
                             LocalRedirect($to_file, true);
                         }
                     }
                 }
             }
         }
     }
 }
}
$message = null;
$sTableID = "tbl_clouds_file_search";
$lAdmin = new CAdminList($sTableID);
$lAdmin->InitFilter(array("bucket", "path"));
$path = isset($_GET["path"]) ? $_GET["path"] : $path;
$path = preg_replace("#[\\\\\\/]+#", "/", "/" . $path . "/");
$n = preg_replace("/[^a-zA-Z0-9_:\\[\\]]/", "", $_GET["n"]);
if (intval($bucket) <= 0 && count($arBuckets) == 1) {
    $bucket = $bucket_id;
}
//TODO when there is only one cloud storage there is no need for filter or at least we can preset it
$arHeaders = array(array("id" => "FILE_NAME", "content" => GetMessage("CLO_STORAGE_SEARCH_NAME"), "default" => true), array("id" => "FILE_SIZE", "content" => GetMessage("CLO_STORAGE_SEARCH_SIZE"), "align" => "right", "default" => true));
$lAdmin->AddHeaders($arHeaders);
$arData = array();
$obBucket = new CCloudStorageBucket($bucket);
if ($obBucket->Init() && $_GET["file"] !== "y") {
    $arFiles = $obBucket->ListFiles($path);
    if ($path != "/") {
        $arData[] = array("ID" => "D..", "TYPE" => "dir", "NAME" => "..", "SIZE" => "");
    }
    if (is_array($arFiles)) {
        foreach ($arFiles["dir"] as $i => $dir) {
            $arData[] = array("ID" => "D" . $dir, "TYPE" => "dir", "NAME" => $dir, "SIZE" => '');
        }
        foreach ($arFiles["file"] as $i => $file) {
            $arData[] = array("ID" => "F" . $file, "TYPE" => "file", "NAME" => $file, "SIZE" => $arFiles["file_size"][$i]);
        }
    } else {
        $e = $APPLICATION->GetException();
        if (is_object($e)) {
Beispiel #7
0
 function GetBucketFileList($BUCKET_ID, $path)
 {
     static $CACHE;
     if ($CACHE[$BUCKET_ID]) {
         $obBucket = $CACHE[$BUCKET_ID];
     } else {
         $CACHE[$BUCKET_ID] = $obBucket = new CCloudStorageBucket($BUCKET_ID);
     }
     if ($obBucket->Init()) {
         return $obBucket->ListFiles($path);
     }
     return false;
 }
Beispiel #8
0
 /**
  * @return CCloudStorageBucket
  * @throws WebDavTmpFileErrorException
  */
 private function getBucket()
 {
     if (!CModule::IncludeModule("clouds")) {
         throw new WebDavTmpFileErrorException('Could not init bucket');
     }
     $bucket = new CCloudStorageBucket($this->bucketId);
     if (!$bucket->init()) {
         throw new WebDavTmpFileErrorException('Could not init bucket');
     }
     return $bucket;
 }
Beispiel #9
0
 /**
  * @return \CCloudStorageBucket|null
  * @throws \Bitrix\Main\LoaderException
  */
 private function getBucket()
 {
     if (!$this->bucketId) {
         $this->errorCollection->addOne(new Error('Could not get bucket. BucketId is empty.', static::ERROR_BUCKET_ID_EMPTY));
         return null;
     }
     if (!Loader::includeModule('clouds')) {
         $this->errorCollection->addOne(new Error('Could not include module "clouds".', static::ERROR_INCLUDE_CLOUDS));
         return null;
     }
     $bucket = new \CCloudStorageBucket($this->bucketId);
     if (!$bucket->init()) {
         $this->errorCollection->addOne(new Error('Could not init bucket.', static::ERROR_INIT_BUCKET));
         return null;
     }
     return $bucket;
 }
Beispiel #10
0
	public static function GetBucketFileList($BUCKET_ID, $path)
	{
		static $CACHE;

		if ($CACHE[$BUCKET_ID])
			$obBucket = $CACHE[$BUCKET_ID];
		else
			$CACHE[$BUCKET_ID] = $obBucket = new CCloudStorageBucket($BUCKET_ID);

		if ($obBucket->Init())
			return $obBucket->ListFiles($path);
		return false;
	}
Beispiel #11
0
<?php

define("ADMIN_MODULE_NAME", "clouds");
/*.require_module 'standard';.*/
/*.require_module 'pcre';.*/
/*.require_module 'bitrix_main_include_prolog_admin_before';.*/
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php";
if (!$USER->CanDoOperation("clouds_browse")) {
    $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
}
/*.require_module 'bitrix_clouds_include';.*/
if (!CModule::IncludeModule('clouds')) {
    $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
}
IncludeModuleLangFile(__FILE__);
$obBucket = new CCloudStorageBucket(intval($_GET["bucket"]));
if (!$obBucket->Init()) {
    $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
}
$PHPchunkSize = 1024 * 1024;
// 1M later TODO return_bytes(ini_get('post_max_size'))
$CLOchunkSize = $obBucket->GetService()->GetMinUploadPartSize();
$message = null;
$path = (string) $_GET["path"];
$sTableID = "tbl_clouds_file_list";
$lAdmin = new CAdminList($sTableID);
$arID = $lAdmin->GroupAction();
$action = isset($_REQUEST["action"]) && is_string($_REQUEST["action"]) ? "{$_REQUEST['action']}" : "";
if ($USER->CanDoOperation("clouds_upload") && is_array($arID)) {
    foreach ($arID as $ID) {
        if (strlen($ID) <= 0) {
Beispiel #12
0
	function OnBeforeProlog()
	{
		if(defined("BX_CHECK_SHORT_URI") && BX_CHECK_SHORT_URI)
		{
			$upload_dir = "/".trim(COption::GetOptionString("main", "upload_dir", "upload"), "/")."/";
			$request_uri = urldecode($_SERVER["REQUEST_URI"]);
			$request_uri = CCloudUtil::URLEncode($request_uri, LANG_CHARSET);
			foreach(CCloudStorageBucket::GetAllBuckets() as $arBucket)
			{
				if($arBucket["ACTIVE"] == "Y")
				{
					$obBucket = new CCloudStorageBucket($arBucket["ID"]);
					if($obBucket->Init())
					{
						$match = array();
						if(
							COption::GetOptionString("clouds", "delayed_resize") === "Y"
							&& preg_match("#^(/".$obBucket->PREFIX."|)(/resize_cache/.*\$)#", $request_uri, $match)
						)
						{
							session_write_close();
							$to_file = $obBucket->GetFileSRC(urldecode($match[2]));
							if (CCloudStorage::ResizeImageFileCheck($obBucket, $to_file))
							{
								$cache_time = 3600*24*30; // 30 days
								header("Cache-Control: max-age=".$cache_time);
								header("Expires: ".gmdate("D, d M Y H:i:s", time()+$cache_time)." GMT");
								header_remove("Pragma");
								LocalRedirect($to_file, true, "301 Moved Permanently");
							}
						}
						elseif($obBucket->FileExists($request_uri))
						{
							if(COption::GetOptionString("clouds", "log_404_errors") === "Y")
								CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
							LocalRedirect($obBucket->GetFileSRC($request_uri), true);
						}
						elseif(strpos($request_uri, $upload_dir) === 0)
						{
							$check_url = substr($request_uri, strlen($upload_dir)-1);
							if($obBucket->FileExists($check_url))
							{
								if(COption::GetOptionString("clouds", "log_404_errors") === "Y")
									CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
								LocalRedirect($obBucket->GetFileSRC($check_url), true);
							}
						}
					}
				}
			}
		}
	}
Beispiel #13
0
 function OnBeforeProlog()
 {
     if (defined("BX_CHECK_SHORT_URI") && BX_CHECK_SHORT_URI) {
         $upload_dir = "/" . trim(COption::GetOptionString("main", "upload_dir", "upload"), "/") . "/";
         $request_uri = urldecode($_SERVER["REQUEST_URI"]);
         $request_uri = CCloudUtil::URLEncode($request_uri, LANG_CHARSET);
         foreach (CCloudStorageBucket::GetAllBuckets() as $arBucket) {
             if ($arBucket["ACTIVE"] == "Y") {
                 $obBucket = new CCloudStorageBucket($arBucket["ID"]);
                 if ($obBucket->Init()) {
                     if ($obBucket->FileExists($request_uri)) {
                         if (COption::GetOptionString("clouds", "log_404_errors") === "Y") {
                             CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
                         }
                         LocalRedirect($obBucket->GetFileSRC($request_uri), true);
                     } elseif (strpos($request_uri, $upload_dir) === 0) {
                         $check_url = substr($request_uri, strlen($upload_dir) - 1);
                         if ($obBucket->FileExists($check_url)) {
                             if (COption::GetOptionString("clouds", "log_404_errors") === "Y") {
                                 CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
                             }
                             LocalRedirect($obBucket->GetFileSRC($check_url), true);
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #14
0
 /**
  * @return bool
  */
 public function Finish($obBucket = null)
 {
     if ($this->isStarted()) {
         $ar = $this->GetArray();
         if ($obBucket == null) {
             $obBucket = new CCloudStorageBucket(intval($ar["BUCKET_ID"]));
         }
         if (!$obBucket->Init()) {
             return false;
         }
         $arUploadInfo = unserialize($ar["NEXT_STEP"]);
         $bSuccess = $obBucket->GetService()->CompleteMultipartUpload($obBucket->GetBucketArray(), $arUploadInfo);
         if ($bSuccess) {
             $this->Delete();
         }
         $this->DeleteOld();
         return $bSuccess;
     }
     return false;
 }
 protected function migrateVersion()
 {
     if (!$this->runWorkWithBizproc) {
         return;
     }
     if ($this->isStepFinished(__METHOD__)) {
         return;
     }
     $uploadDir = COption::getOptionString("main", "upload_dir", "upload");
     $isCloud = CModule::IncludeModule("clouds");
     $useGZipCompressionOption = \Bitrix\Main\Config\Option::get("bizproc", "use_gzip_compression", "");
     $isBitrix24 = IsModuleInstalled('bitrix24');
     $bucket = null;
     if ($isBitrix24 && $isCloud) {
         $bucket = new CCloudStorageBucket(1);
         $bucket->init();
     }
     if ($useGZipCompressionOption === "Y") {
         $this->useGZipCompression = true;
     } elseif ($useGZipCompressionOption === "N") {
         $this->useGZipCompression = false;
     } else {
         $this->useGZipCompression = function_exists("gzcompress") && ($GLOBALS["DB"]->type != "ORACLE" || !defined('BX_UTF'));
     }
     $sqlHelper = $this->connection->getSqlHelper();
     $lastId = $this->getStorageId();
     $versionQuery = $this->connection->query("\n\t\t\tSELECT\n\t\t\t\tobj.*,\n\t\t\t\th.ID VERSION_ID,\n\t\t\t\th.NAME VERSION_NAME,\n\t\t\t\th.DOCUMENT VERSION_DOC,\n\t\t\t\th.USER_ID VERSION_USER_ID,\n\t\t\t\th.MODIFIED VERSION_MODIFIED\n\t\t\tFROM b_disk_object obj\n\t\t\t\tINNER JOIN b_bp_history h ON h.DOCUMENT_ID = obj.WEBDAV_ELEMENT_ID AND h.MODULE_ID = 'webdav'\n\n\t\t\tWHERE obj.TYPE = 3 AND h.ID > {$lastId} ORDER BY h.ID\n\t\t");
     while ($version = $versionQuery->fetch()) {
         $this->abortIfNeeded();
         if (strlen($version['VERSION_DOC']) > 0) {
             if ($this->useGZipCompression) {
                 $version['VERSION_DOC'] = gzuncompress($version['VERSION_DOC']);
             }
             $version['VERSION_DOC'] = unserialize($version['VERSION_DOC']);
             if (!is_array($version['VERSION_DOC'])) {
                 $version['VERSION_DOC'] = array();
             }
         } else {
             $version['VERSION_DOC'] = array();
         }
         if (empty($version['VERSION_DOC']) || empty($version['VERSION_DOC']['PROPERTIES']['WEBDAV_VERSION']['VALUE']) || empty($version['VERSION_DOC']['PROPERTIES']['FILE']['VALUE'])) {
             $this->storeStorageId($version['VERSION_ID']);
             continue;
         }
         $version['VERSION_NAME'] = $sqlHelper->forSql($version['VERSION_NAME']);
         $version['VERSION_MODIFIED'] = $sqlHelper->getCharToDateFunction($version['VERSION_MODIFIED']->format("Y-m-d H:i:s"));
         $version['UPDATE_TIME'] = $sqlHelper->getCharToDateFunction($version['UPDATE_TIME']->format("Y-m-d H:i:s"));
         $fullPath = $version['VERSION_DOC']['PROPERTIES']['FILE']['VALUE'];
         $handlerId = '';
         $filename = bx_basename($fullPath);
         if (substr($fullPath, 0, 4) == "http") {
             if (!$isCloud) {
                 $this->storeStorageId($version['VERSION_ID']);
                 continue;
             }
             if (!$isBitrix24) {
                 $bucket = CCloudStorage::findBucketByFile($fullPath);
                 if (!$bucket) {
                     $this->storeStorageId($version['VERSION_ID']);
                     continue;
                 }
             }
             $handlerId = $bucket->ID;
             $subDir = trim(substr(getDirPath($fullPath), strlen($bucket->getFileSRC('/'))), '/');
             $contentType = \Bitrix\Disk\TypeFile::getMimeTypeByFilename($filename);
         } else {
             $subDir = trim(substr(getDirPath($fullPath), strlen('/' . $uploadDir)), '/');
             $contentType = CFile::getContentType($_SERVER["DOCUMENT_ROOT"] . $fullPath);
             $contentType = \Bitrix\Disk\TypeFile::normalizeMimeType($contentType, $filename);
         }
         $webdavSize = $version['VERSION_DOC']['PROPERTIES']['WEBDAV_SIZE']['VALUE'];
         if (empty($webdavSize)) {
             $webdavSize = 0;
         }
         $fileId = CFile::doInsert(array('HEIGHT' => 0, 'WIDTH' => 0, 'FILE_SIZE' => $webdavSize, 'CONTENT_TYPE' => $contentType, 'SUBDIR' => $subDir, 'FILE_NAME' => $filename, 'MODULE_ID' => Driver::INTERNAL_MODULE_ID, 'ORIGINAL_NAME' => $filename, 'DESCRIPTION' => '', 'HANDLER_ID' => $handlerId, 'EXTERNAL_ID' => md5(mt_rand())));
         if (!$fileId) {
             $this->storeStorageId($version['VERSION_ID']);
             continue;
         }
         $this->connection->queryExecute("\n\t\t\t\tINSERT INTO b_disk_version (OBJECT_ID, FILE_ID, " . $this->sqlHelper->quote('SIZE') . ", NAME, CREATE_TIME, CREATED_BY, MISC_DATA, OBJECT_CREATE_TIME, OBJECT_CREATED_BY, OBJECT_UPDATE_TIME, OBJECT_UPDATED_BY, GLOBAL_CONTENT_VERSION, BP_VERSION_ID)\n\t\t\t\tVALUES ({$version['ID']}, {$fileId}, {$webdavSize}, '{$version['VERSION_NAME']}', {$version['VERSION_MODIFIED']},  {$version['VERSION_USER_ID']}, null, {$version['VERSION_MODIFIED']}, {$version['CREATED_BY']}, {$version['UPDATE_TIME']}, {$version['UPDATED_BY']}, {$version['VERSION_DOC']['PROPERTIES']['WEBDAV_VERSION']['VALUE']}, {$version['VERSION_ID']})\n\t\t\t");
         $this->storeStorageId($version['VERSION_ID']);
     }
     $this->abortIfNeeded();
     $this->storeStorageId(0);
     $this->setStepFinished(__METHOD__);
 }
Beispiel #16
0
 $res = null;
 while ($obUpload->hasRetries()) {
     if ($res = $obUpload->Next($part, $obBucket)) {
         break;
     } elseif (++$fails >= 10) {
         RaiseErrorAndDie('Internal Error: could not init upload for ' . $fails . ' times');
     }
 }
 if ($res) {
     $pos = $obUpload->getPos();
     if ($pos >= $file_size) {
         if ($obUpload->Finish($obBucket)) {
             $NS['pos'] += $file_size;
             $pos = 0;
             if ($NS['BUCKET_ID'] != -1) {
                 $oBucket = new CCloudStorageBucket($NS['BUCKET_ID']);
                 $oBucket->IncFileCounter($file_size);
             }
             if (file_exists($arc_name = CTar::getNextName($NS['arc_name']))) {
                 unset($NS['obBucket']);
                 $NS['arc_name'] = $arc_name;
             } else {
                 CBitrixCloudBackup::clearOptions();
                 $name = CTar::getFirstName($NS['arc_name']);
                 while (file_exists($name)) {
                     $size = filesize($name);
                     if (unlink($name) && IntOption("disk_space") > 0) {
                         CDiskQuota::updateDiskQuota("file", $size, "del");
                     }
                     $name = CTar::getNextName($name);
                 }
Beispiel #17
0
		if ($APPLICATION->GetFileAccessPermission(array($site, $path."/".$ID))< "W")
			continue;
		switch ($_REQUEST['action'])
		{
			case "delete":
				if (preg_match('#^([0-9]+)_(.+)$#', $ID, $regs))
				{
					$BUCKET_ID = $regs[1];
					$item = $regs[2];

					if ($BUCKET_ID)
					{
						if (CModule::IncludeModule('clouds'))
						{
							$obBucket = new CCloudStorageBucket($BUCKET_ID);
							if ($obBucket->Init())
							{
								$name = $path.'/'.$item;
								while($obBucket->FileExists($name))
								{
									$file_size = $obBucket->GetFileSize($name);
									if ($obBucket->DeleteFile($name))
										$obBucket->DecFileCounter($file_size);
									$name = CTar::getNextName($name);
								}

								$e = $APPLICATION->GetException();
								if(is_object($e))
									$lAdmin->AddGroupError($e->GetString(), $ID);
							}
        }
        if ($res > 0) {
            if (isset($_REQUEST["apply"])) {
                LocalRedirect("/bitrix/admin/clouds_storage_edit.php?ID=" . $res . "&lang=" . LANGUAGE_ID . "&" . $tabControl->ActiveTabParam());
            } else {
                LocalRedirect("/bitrix/admin/clouds_storage_list.php?lang=" . LANGUAGE_ID);
            }
        } else {
            $e = $APPLICATION->GetException();
            if (is_object($e)) {
                $message = new CAdminMessage(GetMessage("CLO_STORAGE_EDIT_SAVE_ERROR"), $e);
            }
            $bVarsFromForm = true;
        }
    } elseif (isset($_REQUEST["delete"]) && $ID > 1) {
        $ob = new CCloudStorageBucket($ID);
        if ($ob->Delete()) {
            LocalRedirect("/bitrix/admin/clouds_storage_list.php?lang=" . LANGUAGE_ID);
        } else {
            $bVarsFromForm = true;
        }
    }
}
if ($bVarsFromForm) {
    $arRes = array("ACTIVE" => (string) $_REQUEST["ACTIVE"], "SORT" => "500", "READ_ONLY" => (string) $_REQUEST["READ_ONLY"], "SERVICE_ID" => (string) $_REQUEST["SERVICE_ID"], "BUCKET" => (string) $_REQUEST["BUCKET"], "LOCATION" => (string) $_REQUEST["LOCATION"], "CNAME" => (string) $_REQUEST["CNAME"], "SETTINGS" => "");
    if (isset($_REQUEST["SETTINGS"]) && is_array($_REQUEST["SETTINGS"])) {
        $arRes["SETTINGS"] = $_REQUEST["SETTINGS"];
    }
} else {
    $arRes = null;
    if ($ID > 0) {