protected void Page_Load(object sender, EventArgs e)
    {
        // Check permissions
        string permissionName = IsBackupMode ? "BackupObjects" : "ExportObjects";

        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.globalpermissions", permissionName, SiteContext.CurrentSiteName))
        {
            RedirectToAccessDenied("cms.globalpermissions", permissionName);
        }

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

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

        if (!RequestHelper.IsCallback())
        {
            try
            {
                // Clean previous export files up
                ExportProvider.DeleteTemporaryFiles();
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }

            SetTitle(GetString(IsBackupMode ? "BackupObject.Title" : "ExportObject.Title"));
            btnOk.ResourceString = IsBackupMode ? "General.backup" : "General.export";
            btnOk.Click         += btnOk_Click;

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

            string errorMessage = ValidateExportObject();
            if (!String.IsNullOrEmpty(errorMessage))
            {
                plcExportDetails.Visible = false;
                btnOk.Enabled            = false;

                ShowError(errorMessage);
            }
            else
            {
                // Check permissions
                CheckObjectPermissions();

                lblIntro.Text = String.Format(GetString(IsBackupMode ? "BackupObject.Intro" : "ExportObject.Intro"), ExportedObjectDisplayName);

                if (!RequestHelper.IsPostBack())
                {
                    lblIntro.Visible = true;
                    txtFileName.Text = GetExportFileName(ExportedObjectInfo, IsBackupMode);
                }
            }
        }
    }
示例#2
0
    private void CheckTrial()
    {
        // Hide message if requested by user
        if (!CheckWarningMessage(SESSION_KEY_TRIAL))
        {
            pnlTrial.Visible = false;
            return;
        }

        string info = null;

        if (LicenseHelper.ApplicationExpires != DateTime.MinValue)
        {
            TimeSpan appExpiration = LicenseHelper.ApplicationExpires.Subtract(DateTime.Now);

            // Application expires
            if (CMSVersion.IsBetaVersion())
            {
                if (appExpiration.Ticks <= 0)
                {
                    info = GetString("Beta.AppExpired");
                }
                else
                {
                    info = string.Format(GetString("Beta.AppExpiresIn"), GetExpirationString(appExpiration.Days));
                }
            }
            else
            {
                if (appExpiration.Ticks <= 0)
                {
                    info = string.Format(GetString("Preview.AppExpired"), CMSVersion.VersionSuffix);
                }
                else
                {
                    info = string.Format(GetString("Preview.AppExpiresIn"), CMSVersion.VersionSuffix, GetExpirationString(appExpiration.Days));
                }
            }
        }
        // Check the license key for trial or free version
        else if (DataHelper.GetNotEmpty(RequestContext.CurrentDomain, string.Empty) != string.Empty)
        {
            LicenseKeyInfo lki = LicenseKeyInfoProvider.GetLicenseKeyInfo(RequestContext.CurrentDomain);
            if ((lki != null) && (lki.Key.Length == LicenseKeyInfo.TRIAL_KEY_LENGTH) && (lki.ExpirationDateReal != LicenseKeyInfo.TIME_UNLIMITED_LICENSE))
            {
                TimeSpan expiration = lki.ExpirationDateReal.Subtract(DateTime.Now.AddDays(-1));
                // Trial version expiration date
                if (expiration.Ticks <= 0)
                {
                    info = GetString("Trial.Expired");
                }
                else
                {
                    info = string.Format(GetString("Trial.ExpiresIn"), GetExpirationString(expiration.Days));
                }
            }
            else if ((lki != null) && (lki.Edition == ProductEditionEnum.Free))
            {
                info = GetString("header.freeedition");
            }
        }

        ltlText.Text     = info;
        pnlTrial.Visible = !string.IsNullOrEmpty(ltlText.Text);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register script for pendingCallbacks repair
        ScriptHelper.FixPendingCallbacks(Page);

        // Handle export settings
        if (!RequestHelper.IsCallback() && !RequestHelper.IsPostBack())
        {
            ExportSettings = GetNewSettings();
        }

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

            bool notTargetPermissions = false;
            bool notTempPermissions   = false;

            ctrlAsyncSelection.OnFinished += CtrlAsyncSelectionOnFinished;
            ctrlAsyncSelection.OnError    += CtrlAsyncSelectionOnError;

            ctlAsyncExport.OnCancel += ctlAsyncExport_OnCancel;

            // Init steps
            if (wzdExport.ActiveStepIndex < 2)
            {
                configExport.Settings = ExportSettings;
                if (!RequestHelper.IsPostBack())
                {
                    configExport.SiteId = SiteId;
                }

                pnlExport.Settings = ExportSettings;

                // Ensure directories and check permissions
                try
                {
                    DirectoryHelper.EnsureDiskPath(ExportSettings.TargetPath + "\\temp.file", ExportSettings.WebsitePath);
                    notTargetPermissions = !DirectoryHelper.CheckPermissions(ExportSettings.TargetPath, true, true, false, false);
                }
                catch (UnauthorizedAccessException)
                {
                    notTargetPermissions = true;
                }
                catch (IOExceptions.IOException ex)
                {
                    pnlWrapper.Visible = false;
                    SetAlertLabel(lblErrorBlank, ex.Message);
                    return;
                }
                try
                {
                    DirectoryHelper.EnsureDiskPath(ExportSettings.TemporaryFilesPath + "\\temp.file", ExportSettings.WebsitePath);
                    notTempPermissions = !DirectoryHelper.CheckPermissions(ExportSettings.TemporaryFilesPath, true, true, false, false);
                }
                catch (UnauthorizedAccessException)
                {
                    notTempPermissions = true;
                }
                catch (IOExceptions.IOException ex)
                {
                    pnlWrapper.Visible = false;
                    SetAlertLabel(lblErrorBlank, ex.Message);
                    return;
                }
            }

            if (notTargetPermissions || notTempPermissions)
            {
                string folder = (notTargetPermissions) ? ExportSettings.TargetPath : ExportSettings.TemporaryFilesPath;
                pnlWrapper.Visible     = false;
                pnlPermissions.Visible = true;
                SetAlertLabel(lblErrorBlank, String.Format(GetString("ExportSite.ErrorPermissions"), folder, WindowsIdentity.GetCurrent().Name));
                lnkPermissions.Target      = "_blank";
                lnkPermissions.Text        = GetString("Install.ErrorPermissions");
                lnkPermissions.NavigateUrl = DocumentationHelper.GetDocumentationTopicUrl(HELP_TOPIC_DISKPERMISSIONS_LINK);
            }
            else
            {
                // Try to delete temporary files from previous export
                if (!RequestHelper.IsPostBack())
                {
                    try
                    {
                        ExportProvider.DeleteTemporaryFiles(ExportSettings, false);
                    }
                    catch (Exception ex)
                    {
                        pnlWrapper.Visible = false;
                        SetAlertLabel(lblErrorBlank, GetString("ImportSite.ErrorDeletionTemporaryFiles") + " " + ex.Message);
                        return;
                    }
                }

                ControlsHelper.EnsureScriptManager(Page).EnablePageMethods = true;

                // Javascript functions
                string script = String.Format(
                    @"
function Finished(sender) {{
    var errorElement = document.getElementById('{2}');

    var errorText = sender.getErrors();
    if (errorText != '') {{ 
        errorElement.innerHTML = errorText;
        document.getElementById('{4}').style.removeProperty('display');
    }}

    var warningElement = document.getElementById('{3}');
    
    var warningText = sender.getWarnings();
    if (warningText != '') {{ 
        warningElement.innerHTML = warningText;
        document.getElementById('{5}').style.removeProperty('display');
    }}    

    var actDiv = document.getElementById('actDiv');
    if (actDiv != null) {{ 
        actDiv.style.display = 'none'; 
    }}

    BTN_Disable('{0}');
    BTN_Enable('{1}');
}}
",
                    CancelButton.ClientID,
                    FinishButton.ClientID,
                    lblError.LabelClientID,
                    lblWarning.LabelClientID,
                    pnlError.ClientID,
                    pnlWarning.ClientID
                    );

                // Register the script to perform get flags for showing buttons retrieval callback
                ScriptHelper.RegisterClientScriptBlock(this, GetType(), "Finished", ScriptHelper.GetScript(script));

                // Add cancel button attribute
                CancelButton.Attributes.Add("onclick", ctlAsyncExport.GetCancelScript(true) + "return false;");

                wzdExport.NextButtonClick     += wzdExport_NextButtonClick;
                wzdExport.PreviousButtonClick += wzdExport_PreviousButtonClick;
                wzdExport.FinishButtonClick   += wzdExport_FinishButtonClick;

                if (!RequestHelper.IsPostBack())
                {
                    configExport.InitControl();
                }
            }
        }
    }
    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;
                }
            }
        }
    }
示例#5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register script for pendingCallbacks repair
        ScriptHelper.FixPendingCallbacks(Page);

        // Handle export settings
        if (!RequestHelper.IsCallback() && !RequestHelper.IsPostBack())
        {
            ExportSettings = GetNewSettings();
        }

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

            bool notTargetPermissions = false;
            bool notTempPermissions   = false;

            ctrlAsync.OnFinished += ctrlAsync_OnFinished;
            ctrlAsync.OnError    += ctrlAsync_OnError;

            // Init steps
            if (wzdExport.ActiveStepIndex < 2)
            {
                configExport.Settings = ExportSettings;
                if (!RequestHelper.IsPostBack())
                {
                    configExport.SiteId = SiteId;
                }

                pnlExport.Settings = ExportSettings;

                // Ensure directories and check permissions
                try
                {
                    DirectoryHelper.EnsureDiskPath(ExportSettings.TargetPath + "\\temp.file", ExportSettings.WebsitePath);
                    notTargetPermissions = !DirectoryHelper.CheckPermissions(ExportSettings.TargetPath, true, true, false, false);
                }
                catch (UnauthorizedAccessException)
                {
                    notTargetPermissions = true;
                }
                catch (IOExceptions.IOException ex)
                {
                    pnlWrapper.Visible = false;
                    SetErrorLabel(ex.Message);
                    return;
                }
                try
                {
                    DirectoryHelper.EnsureDiskPath(ExportSettings.TemporaryFilesPath + "\\temp.file", ExportSettings.WebsitePath);
                    notTempPermissions = !DirectoryHelper.CheckPermissions(ExportSettings.TemporaryFilesPath, true, true, false, false);
                }
                catch (UnauthorizedAccessException)
                {
                    notTempPermissions = true;
                }
                catch (IOExceptions.IOException ex)
                {
                    pnlWrapper.Visible = false;
                    SetErrorLabel(ex.Message);
                    return;
                }
            }

            if (notTargetPermissions || notTempPermissions)
            {
                string folder = (notTargetPermissions) ? ExportSettings.TargetPath : ExportSettings.TemporaryFilesPath;
                pnlWrapper.Visible = false;
                SetErrorLabel(String.Format(GetString("ExportSite.ErrorPermissions"), folder, WindowsIdentity.GetCurrent().Name));
                pnlPermissions.Visible     = true;
                lnkPermissions.Target      = "_blank";
                lnkPermissions.Text        = GetString("Install.ErrorPermissions");
                lnkPermissions.NavigateUrl = UIContextHelper.GetDocumentationTopicUrl(HELP_TOPIC_DISKPERMISSIONS_LINK);
            }
            else
            {
                // Try to delete temporary files from previous export
                if (!RequestHelper.IsPostBack())
                {
                    try
                    {
                        ExportProvider.DeleteTemporaryFiles(ExportSettings, false);
                    }
                    catch (Exception ex)
                    {
                        pnlWrapper.Visible = false;
                        SetErrorLabel(GetString("ImportSite.ErrorDeletionTemporaryFiles") + ex.Message);
                        return;
                    }
                }

                PortalHelper.EnsureScriptManager(Page).EnablePageMethods = true;

                // Javascript functions
                string script =
                    @"var exMessageText = '';
var exErrorText = '';
var exWarningText = '';
var exMachineName = '" + SystemContext.MachineName.ToLowerCSafe() + @"';
var getBusy = false;

function GetExportState(cancel) { 
    if (window.Activity) { 
        window.Activity(); 
    } 
    if (getBusy) return; 
    getBusy = true; 
    setTimeout('getBusy = false;', 2000);
    var argument = cancel + ';' + exMessageText.length + ';' + exErrorText.length + ';' + exWarningText.length + ';' + exMachineName; 
    " + Page.ClientScript.GetCallbackEventReference(this, "argument", "SetExportStateMssg", "argument", false) + @";
}

function SetExportStateMssg(rValue, context) {
    getBusy = false;
    if (rValue!='') {
        var args = context.split(';');
        var values = rValue.split('" + SiteExportSettings.SEPARATOR + @"');
        var messageElement = document.getElementById('" + lblProgress.ClientID + @"');
        var errorElement = document.getElementById('" + lblError.ClientID + @"');
        var warningElement = document.getElementById('" + lblWarning.ClientID + @"');
        var messageText = exMessageText;
        messageText = values[1] + messageText.substring(messageText.length - args[1]);
        if (messageText.length > exMessageText.length) { 
            exMessageText = messageElement.innerHTML = messageText; 
        }
        var errorText = exErrorText;
        errorText = values[2] + errorText.substring(errorText.length - args[2]);
        if (errorText.length > exErrorText.length) { 
            exErrorText = errorElement.innerHTML = errorText;
            document.getElementById('" + pnlError.ClientID + @"').style.removeProperty('display');
        }
        var warningText = exWarningText;
        warningText = values[3] + warningText.substring(warningText.length - args[3]);
        if (warningText.length > exWarningText.length) { 
            exWarningText = warningElement.innerHTML = warningText;
            document.getElementById('" + pnlWarning.ClientID + @"').style.removeProperty('display');
        }
        if ((values=='') || (values[0]=='F')) {
            StopExportStateTimer();
            var actDiv = document.getElementById('actDiv');
            if (actDiv != null) { actDiv.style.display = 'none'; }
            BTN_Enable('" + FinishButton.ClientID + @"');
            try {
                BTN_Disable('" + CancelButton.ClientID + @"');
            }
            catch(err) {
            }
        }
    }
}";

                // Register the script to perform get flags for showing buttons retrieval callback
                ScriptHelper.RegisterClientScriptBlock(this, GetType(), "GetSetExportState", ScriptHelper.GetScript(script));

                // Add cancel button attribute
                CancelButton.Attributes.Add("onclick", "BTN_Disable('" + CancelButton.ClientID + "'); return CancelExport();");

                wzdExport.NextButtonClick     += wzdExport_NextButtonClick;
                wzdExport.PreviousButtonClick += wzdExport_PreviousButtonClick;
                wzdExport.FinishButtonClick   += wzdExport_FinishButtonClick;

                if (!RequestHelper.IsPostBack())
                {
                    configExport.InitControl();
                }
            }
        }
    }