private string GetTargetUrl()
 {
     if (IsBackupMode)
     {
         string path = ImportExportHelper.GetObjectBackupFolder(ExportedObjectInfo);
         return(ResolveUrl(path) + "/" + txtFileName.Text);
     }
     return(ImportExportHelper.GetExportPackageUrl(txtFileName.Text, SiteContext.CurrentSiteName));
 }
    private string GetTargetFolder()
    {
        string targetFolder = null;

        if (IsBackupMode)
        {
            string path = ImportExportHelper.GetObjectBackupFolder(ExportedObjectInfo);

            targetFolder = Server.MapPath(path);
        }
        else
        {
            targetFolder = ImportExportHelper.GetSiteUtilsFolder() + "Export";
        }

        return(targetFolder);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        backup = QueryHelper.GetBoolean("backup", false);

        // Check permissions
        if (backup)
        {
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.globalpermissions", "BackupObjects", CMSContext.CurrentSiteName))
            {
                RedirectToCMSDeskAccessDenied("cms.globalpermissions", "BackupObjects");
            }
        }
        else if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.globalpermissions", "ExportObjects", CMSContext.CurrentSiteName))
        {
            RedirectToCMSDeskAccessDenied("cms.globalpermissions", "ExportObjects");
        }

        // Register script for pendingCallbacks repair
        ScriptHelper.FixPendingCallbacks(Page);

        // Async control events binding
        ucAsyncControl.OnFinished += ucAsyncControl_OnFinished;
        ucAsyncControl.OnError    += ucAsyncControl_OnError;

        if (!IsCallback)
        {
            try
            {
                // Delete temporary files
                ExportProvider.DeleteTemporaryFiles();
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }

            if (backup)
            {
                SetTitle("CMSModules/CMS_ImportExport/backupobject.png", GetString("BackupObject.Title"), null, null);
            }
            else
            {
                SetTitle("CMSModules/CMS_ImportExport/exportobject.png", GetString("ExportObject.Title"), null, null);
            }

            // Display BETA warning
            lblBeta.Visible = CMSContext.IsBetaVersion();
            lblBeta.Text    = string.Format(GetString("export.BETAwarning"), CMSContext.GetFriendlySystemVersion(false));

            // Get data from parameters
            objectId   = ValidationHelper.GetInteger(Request.QueryString["objectId"], 0);
            objectType = ValidationHelper.GetString(Request.QueryString["objectType"], "");

            // Get the object
            infoObj = CMSObjectHelper.GetReadOnlyObject(objectType);

            if (infoObj == null)
            {
                plcExportDetails.Visible = false;
                lblIntro.Text            = GetString("ExportObject.ObjectTypeNotFound");
                lblIntro.CssClass        = "ErrorLabel";
                return;
            }

            // Get exported object
            exportObj = infoObj.GetObject(objectId);
            if (exportObj == null)
            {
                plcExportDetails.Visible = false;
                lblIntro.Text            = GetString("ExportObject.ObjectNotFound");
                lblIntro.CssClass        = "ErrorLabel";
                btnOk.Visible            = false;
                return;
            }

            // Store display name
            exportObjectDisplayName = HTMLHelper.HTMLEncode(exportObj.ObjectDisplayName);

            if (backup)
            {
                lblIntro.Text = string.Format(GetString("BackupObject.Intro"), ResHelper.LocalizeString(exportObjectDisplayName));
            }
            else
            {
                lblIntro.Text = string.Format(GetString("ExportObject.Intro"), ResHelper.LocalizeString(exportObjectDisplayName));
            }

            btnOk.Click += btnOk_Click;

            if (!RequestHelper.IsPostBack())
            {
                lblIntro.Visible    = true;
                lblFileName.Visible = true;
                txtFileName.Text    = GetExportFileName(exportObj, backup);
                if (backup)
                {
                    btnOk.Text = GetString("General.backup");
                }
                else
                {
                    btnOk.Text = GetString("General.export");
                }
                btnCancel.Text = GetString("General.Close");
            }

            string path = null;
            if (backup)
            {
                path         = ImportExportHelper.GetObjectBackupFolder(exportObj);
                targetFolder = Server.MapPath(path);

                targetUrl = ResolveUrl(path) + "/" + txtFileName.Text;
            }
            else
            {
                targetFolder = ImportExportHelper.GetSiteUtilsFolder() + "Export";
                path         = ImportExportHelper.GetSiteUtilsFolderRelativePath();
                if (path != null)
                {
                    string externalUrl = null;
                    string fullPath    = path + "Export/" + txtFileName.Text;

                    // Handle external storage URL
                    if (StorageHelper.IsExternalStorage(fullPath))
                    {
                        externalUrl = File.GetFileUrl(fullPath, CMSContext.CurrentSiteName);
                    }

                    // Ensure default target URL if not set
                    if (string.IsNullOrEmpty(externalUrl))
                    {
                        targetUrl = ResolveUrl(path) + "Export/" + txtFileName.Text;
                    }
                    else
                    {
                        targetUrl = externalUrl;
                    }
                }
                else
                {
                    targetUrl = null;
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        var currentSiteName = SiteContext.CurrentSiteName;

        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.globalpermissions", "RestoreObjects", currentSiteName))
        {
            RedirectToAccessDenied("cms.globalpermissions", "RestoreObjects");
        }

        // Register script for pendingCallbacks repair
        ScriptHelper.FixPendingCallbacks(Page);

        // Async control events binding
        ucAsyncControl.OnFinished += ucAsyncControl_OnFinished;
        ucAsyncControl.OnError    += ucAsyncControl_OnError;

        if (!RequestHelper.IsCallback())
        {
            try
            {
                // Delete temporary files
                ExportProvider.DeleteTemporaryFiles();
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }

            SetTitle(GetString("RestoreObject.Title"));

            // Get data from parameters
            siteId     = QueryHelper.GetInteger("siteId", 0);
            objectId   = QueryHelper.GetInteger("objectId", 0);
            objectType = QueryHelper.GetString("objectType", "");

            // Get the object
            infoObj = ModuleManager.GetReadOnlyObject(objectType);
            if (infoObj == null)
            {
                lblIntro.Text     = GetString("ExportObject.ObjectTypeNotFound");
                lblIntro.CssClass = "ErrorLabel";
                return;
            }

            // Get exported object
            exportObj = infoObj.GetObject(objectId);
            if (exportObj == null)
            {
                lblIntro.Text      = GetString("ExportObject.ObjectNotFound");
                lblIntro.CssClass  = "ErrorLabel";
                btnRestore.Visible = false;
                return;
            }

            if (!CheckSpecialSecurityCases(exportObj))
            {
                return;
            }

            if (!CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin))
            {
                if (!exportObj.CheckPermissions(PermissionsEnum.Modify, CurrentSiteName, CurrentUser))
                {
                    RedirectToAccessDenied(exportObj.TypeInfo.ModuleName, PermissionsEnum.Modify.ToString());
                }
            }

            // Store display name
            exportObjectDisplayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(exportObj.ObjectDisplayName));
            codeName = exportObj.ObjectCodeName;

            lblIntro.Text = string.Format(GetString("RestoreObject.Intro"), exportObjectDisplayName);

            targetFolder = ImportExportHelper.GetObjectBackupFolder(exportObj);

            btnRestore.Click += btnRestore_Click;

            if (!RequestHelper.IsPostBack())
            {
                lblIntro.Visible = true;

                // Load the available backups
                if (lstImports.Items.Count == 0)
                {
                    RefreshPackageList();
                }
            }
        }
    }
Пример #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.globalpermissions", "RestoreObjects", CMSContext.CurrentSiteName))
        {
            RedirectToCMSDeskAccessDenied("cms.globalpermissions", "RestoreObjects");
        }

        // Register script for pendingCallbacks repair
        ScriptHelper.FixPendingCallbacks(Page);

        imgDelete.ImageUrl = GetImageUrl("Design/Controls/EditModeButtons/delete.png");

        // Async control events binding
        ucAsyncControl.OnFinished += ucAsyncControl_OnFinished;
        ucAsyncControl.OnError    += ucAsyncControl_OnError;

        if (!IsCallback)
        {
            try
            {
                // Delete temporary files
                ExportProvider.DeleteTemporaryFiles();
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }

            SetTitle("CMSModules/CMS_ImportExport/restoreobject.png", GetString("RestoreObject.Title"), null, null);

            // Get data from parameters
            siteId     = ValidationHelper.GetInteger(Request.QueryString["siteId"], 0);
            objectId   = ValidationHelper.GetInteger(Request.QueryString["objectId"], 0);
            objectType = ValidationHelper.GetString(Request.QueryString["objectType"], "");

            // Get the object
            infoObj = CMSObjectHelper.GetReadOnlyObject(objectType);
            if (infoObj == null)
            {
                lblIntro.Text     = GetString("ExportObject.ObjectTypeNotFound");
                lblIntro.CssClass = "ErrorLabel";
                return;
            }

            // Get exported object
            exportObj = infoObj.GetObject(objectId);
            if (exportObj == null)
            {
                lblIntro.Text     = GetString("ExportObject.ObjectNotFound");
                lblIntro.CssClass = "ErrorLabel";
                btnOk.Visible     = false;
                return;
            }

            // Store display name
            exportObjectDisplayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(exportObj.ObjectDisplayName));
            codeName = exportObj.ObjectCodeName;

            lblIntro.Text = string.Format(GetString("RestoreObject.Intro"), exportObjectDisplayName);

            targetFolder = ImportExportHelper.GetObjectBackupFolder(exportObj);

            btnOk.Click += btnOk_Click;

            if (!RequestHelper.IsPostBack())
            {
                lblIntro.Visible = true;
                btnOk.Text       = GetString("General.Restore");
                btnCancel.Text   = GetString("General.Close");

                // Load the available backups
                if (lstImports.Items.Count == 0)
                {
                    RefreshPackageList();
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        backup = QueryHelper.GetBoolean("backup", false);

        // Check permissions
        if (backup)
        {
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.globalpermissions", "BackupObjects", SiteContext.CurrentSiteName))
            {
                RedirectToAccessDenied("cms.globalpermissions", "BackupObjects");
            }
        }
        else if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.globalpermissions", "ExportObjects", SiteContext.CurrentSiteName))
        {
            RedirectToAccessDenied("cms.globalpermissions", "ExportObjects");
        }

        // Register script for pendingCallbacks repair
        ScriptHelper.FixPendingCallbacks(Page);

        // Async control events binding
        ucAsyncControl.OnFinished += ucAsyncControl_OnFinished;
        ucAsyncControl.OnError    += ucAsyncControl_OnError;

        if (!RequestHelper.IsCallback())
        {
            try
            {
                // Delete temporary files
                ExportProvider.DeleteTemporaryFiles();
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }

            if (backup)
            {
                SetTitle(GetString("BackupObject.Title"));
            }
            else
            {
                SetTitle(GetString("ExportObject.Title"));
            }

            // Display BETA warning
            lblBeta.Visible = CMSVersion.IsBetaVersion();
            lblBeta.Text    = string.Format(GetString("export.BETAwarning"), CMSVersion.GetFriendlySystemVersion(false));

            // Get data from parameters
            objectId   = QueryHelper.GetInteger("objectId", 0);
            objectType = QueryHelper.GetString("objectType", "");

            // Get the object
            infoObj = ModuleManager.GetReadOnlyObject(objectType);

            if (infoObj == null)
            {
                plcExportDetails.Visible = false;
                lblIntro.Text            = GetString("ExportObject.ObjectTypeNotFound");
                lblIntro.CssClass        = "ErrorLabel";
                return;
            }

            // Get exported object
            exportObj = infoObj.GetObject(objectId);
            if (exportObj == null)
            {
                plcExportDetails.Visible = false;
                lblIntro.Text            = GetString("ExportObject.ObjectNotFound");
                lblIntro.CssClass        = "ErrorLabel";
                btnOk.Visible            = false;
                return;
            }

            // Check permissions
            var info = (BaseInfo)exportObj;
            if (!CurrentUser.IsGlobalAdministrator)
            {
                try
                {
                    if (info.Generalized.ObjectSiteID > 0)
                    {
                        CurrentUser.IsAuthorizedPerObject(PermissionsEnum.Read, info,
                                                          SiteInfoProvider.GetSiteName(info.Generalized.ObjectSiteID), true);
                    }
                    else if ((info.TypeInfo.SiteBindingObject != null) && (info.AssignedSites[CurrentSiteName] == null))
                    {
                        // Do not allow to clone objects with site binding which are not assigned to current site
                        RedirectToAccessDenied(info.TypeInfo.ModuleName, PermissionsEnum.Read.ToString());
                    }
                    else
                    {
                        CurrentUser.IsAuthorizedPerObject(PermissionsEnum.Read, info, CurrentSiteName, true);
                    }
                }
                catch (PermissionCheckException ex)
                {
                    RedirectToAccessDenied(ex.ModuleName, ex.PermissionFailed);
                }
            }

            // Store display name
            exportObjectDisplayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(exportObj.ObjectDisplayName));

            lblIntro.Text = string.Format(GetString(backup ? "BackupObject.Intro" : "ExportObject.Intro"), exportObjectDisplayName);

            btnOk.Click += btnOk_Click;

            if (!RequestHelper.IsPostBack())
            {
                lblIntro.Visible    = true;
                lblFileName.Visible = true;
                txtFileName.Text    = GetExportFileName(exportObj, backup);
            }

            btnOk.Text = GetString(backup ? "General.backup" : "General.export");

            string path;
            if (backup)
            {
                path         = ImportExportHelper.GetObjectBackupFolder(exportObj);
                targetFolder = Server.MapPath(path);

                targetUrl = ResolveUrl(path) + "/" + txtFileName.Text;
            }
            else
            {
                targetFolder = ImportExportHelper.GetSiteUtilsFolder() + "Export";
                path         = ImportExportHelper.GetSiteUtilsFolderRelativePath();
                if (path != null)
                {
                    string externalUrl = null;
                    string fullPath    = path + "Export/" + txtFileName.Text;

                    // Handle external storage URL
                    if (StorageHelper.IsExternalStorage(fullPath))
                    {
                        externalUrl = File.GetFileUrl(fullPath, SiteContext.CurrentSiteName);
                    }

                    // Ensure default target URL if not set
                    if (string.IsNullOrEmpty(externalUrl))
                    {
                        targetUrl = ResolveUrl(path) + "Export/" + txtFileName.Text;
                    }
                    else
                    {
                        targetUrl = externalUrl;
                    }
                }
                else
                {
                    targetUrl = null;
                }
            }
        }
    }