Пример #1
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 
    }
Пример #2
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);
							}
							else
Пример #3
0
$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)) {
            $message = new CAdminMessage(GetMessage("CLO_STORAGE_SEARCH_LIST_ERROR"), $e);
Пример #4
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);
                         }
                     }
                 }
             }
         }
     }
 }
Пример #5
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;
	}
Пример #6
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;
 }
Пример #7
0
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) {
            continue;
Пример #8
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);
							}
						}
					}
				}
			}
		}
	}
Пример #9
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);
                         }
                     }
                 }
             }
         }
     }
 }
Пример #10
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;
 }
Пример #11
0
     break;
 case "deactivate":
     $ob = new CCloudStorageBucket(intval($ID));
     if ($ob->ACTIVE === "Y") {
         $ob->Update(array("ACTIVE" => "N"));
     }
     break;
 case "activate":
     $ob = new CCloudStorageBucket(intval($ID));
     if ($ob->ACTIVE === "N") {
         $ob->Update(array("ACTIVE" => "Y"));
     }
     break;
 case "download":
     $ob = new CCloudStorageBucket(intval($ID));
     if ($ob->Init() && $ob->ACTIVE === "Y") {
         if (isset($_SESSION["last_file_id"])) {
             $last_file_id = intval($_SESSION["last_file_id"]);
         } else {
             $last_file_id = 0;
         }
         if (isset($_SESSION["last_file_pos"])) {
             $last_file_pos = doubleval($_SESSION["last_file_pos"]);
         } else {
             $last_file_pos = 0;
         }
         $rsNextFile = $DB->Query("\n\t\t\t\t\tSELECT MIN(ID) ID, COUNT(1) CNT, SUM(FILE_SIZE) FILE_SIZE\n\t\t\t\t\tFROM b_file\n\t\t\t\t\tWHERE ID > " . intval($last_file_id) . "\n\t\t\t\t\tAND HANDLER_ID = '" . $DB->ForSQL($ob->ID) . "'\n\t\t\t\t");
         $lAdmin->BeginPrologContent();
         if (is_array($ar = $rsNextFile->Fetch()) && intval($ar["ID"]) > 0) {
             $bNextFile = true;
             $bFileMoved = false;