/// <summary> /// Checks user impersonation settings. /// </summary> private bool EnsureImpersonation() { var userIsImpersonated = MembershipContext.CurrentUserIsImpersonated(); // Show impersonate button for global admin only or impersonated user if (CookieHelper.AllowCookies && (MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin) || userIsImpersonated)) { lnkUsers.Visible = true; lnkUsers.OnClientClick = ucUsers.GetSelectionDialogScript(); // Show all users except global administrators and public user, in CMSDesk show only site users ucUsers.WhereCondition = GetImpersonateWhereCondition().ToString(true); // Script for open uniselector modal dialog string impersonateScript = "function userImpersonateShowDialog () {US_SelectionDialog_" + ucUsers.ClientID + "()}"; ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ImpersonateContextMenu", ScriptHelper.GetScript(impersonateScript)); string userName = HTMLHelper.HTMLDecode(ValidationHelper.GetString(ucUsers.Value, String.Empty)); if (userName != String.Empty) { // Get selected user info UserInfo iui = UserInfoProvider.GetUserInfo(userName); if (!iui.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin)) { // Indicates whether user will be able to continue in the administration interface bool keepAdimUI = iui.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName); AuthenticationHelper.ImpersonateUser(iui, null, !keepAdimUI); if (keepAdimUI) { PortalScriptHelper.RegisterAdminRedirectScript(Page); } } } // Set visibility of Cancel impersonation item in menu plcCancelImpersonate.Visible = userIsImpersonated; // Hide impersonate action in menu if user is already impersonated plcImpersonate.Visible = !plcCancelImpersonate.Visible; return(true); } // Hide impersonate action in menu plcImpersonate.Visible = false; plcCancelImpersonate.Visible = false; return(false); }
/// <summary> /// Row data bound - gridChannels. /// </summary> protected void gridChannels_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[0].Text = "<span class=\"control-label\">" + e.Row.Cells[0].Text + "</span>"; e.Row.Cells[1].Text = HTMLHelper.HTMLDecode(e.Row.Cells[1].Text); } if (e.Row.RowType == DataControlRowType.Header) { foreach (TableCell cell in e.Row.Cells) { cell.Text = "<span class=\"control-label\">" + cell.Text + "</span>"; } } }
/// <summary> /// Loads the control content. /// </summary> /// <param name="content">Content to load</param> /// <param name="forceReload">If true, the content is forced to reload</param> public void LoadContent(string content, bool forceReload) { if (StopProcessing) { return; } ApplySettings(); bool contentIsEmpty = String.IsNullOrEmpty(content); content = contentIsEmpty ? DefaultText : content; // Resolve URLs content = HTMLHelper.ResolveUrls(content, null); switch (ViewMode) { case ViewModeEnum.Edit: case ViewModeEnum.EditDisabled: switch (RegionType) { case CMSEditableRegionTypeEnum.HtmlEditor: // HTML editor if ((Editor != null) && (forceReload || !RequestHelper.IsPostBack() || (ViewMode == ViewModeEnum.EditDisabled) || contentIsEmpty)) { Editor.ResolvedValue = content; } break; case CMSEditableRegionTypeEnum.TextArea: case CMSEditableRegionTypeEnum.TextBox: content = (EncodeText) ? HTMLHelper.HTMLDecode(content) : content; // TextBox if ((forceReload || !RequestHelper.IsPostBack() || contentIsEmpty) && (txtValue != null)) { txtValue.Text = content; } break; } break; default: // Check authorization bool isAuthorized = true; if ((PageManager != null) && (CheckPermissions)) { isAuthorized = PageManager.IsAuthorized; } // Only published if ((PortalContext.ViewMode != ViewModeEnum.LiveSite) || !SelectOnlyPublished || ((CurrentPageInfo != null) && CurrentPageInfo.IsPublished)) { if (isAuthorized) { if (ltlContent == null) { ltlContent = (Literal)FindControl("ltlContent"); } if (ltlContent != null) { ltlContent.Text = content; // Resolve inline controls if (ResolveDynamicControls) { ControlsHelper.ResolveDynamicControls(this); } } } } break; } }
/// <summary> /// Gets the macros from the system /// </summary> /// <param name="startIndex">Start index</param> /// <param name="endIndex">End index</param> /// <param name="maxTotalRecords">Maximum number of total records to process</param> /// <param name="totalRecords">Returns the total number of records found</param> private IEnumerable <MacroExpr> GetMacros(int startIndex, int endIndex, int maxTotalRecords, out int totalRecords) { var index = 0; var textToSearch = txtTextToSearch.Text; var searchByText = !String.IsNullOrEmpty(textToSearch); var reportProblems = chkReportProblems.Checked; var skipTestingObjects = SystemContext.DevelopmentMode && chkSkipTestingObjects.Checked; var type = drpType.Text; var result = new List <MacroExpr>(); foreach (var objectType in GetObjectTypes()) { // Skip certain object types switch (objectType) { case ObjectVersionHistoryInfo.OBJECT_TYPE: case VersionHistoryInfo.OBJECT_TYPE: case StagingTaskInfo.OBJECT_TYPE: case IntegrationTaskInfo.OBJECT_TYPE: continue; } // Process all objects of the given type var infos = new ObjectQuery(objectType) .TopN(maxTotalRecords) .BinaryData(false); var typeInfo = infos.TypeInfo; if (skipTestingObjects) { ExcludeTestingObjects(infos); } // Search particular expression or search macros of specific type infos.WhereAnyColumnContains(searchByText ? textToSearch : "{" + type); Action <DataRow> collectMacros = dr => { // Process all expressions MacroProcessor.ProcessMacros(new DataRowContainer(dr), (context, colName) => { // Get original macro text with hash string macroType; string originalExpression = MacroProcessor.RemoveMacroBrackets(context.GetOriginalExpression(), out macroType); string processedExpression = context.Expression; // Decode macro from XML if needed if (MacroProcessor.IsXMLColumn(colName)) { originalExpression = HTMLHelper.HTMLDecode(originalExpression); processedExpression = HTMLHelper.HTMLDecode(processedExpression); } MacroExpr e = null; bool add = false; if (!searchByText || (originalExpression.IndexOf(textToSearch, StringComparison.InvariantCultureIgnoreCase) >= 0)) { // If not tracking errors, count immediately if (!reportProblems) { // Apply paging. (endIndex is -1 when paging is off) if ((endIndex < 0) || ((index >= startIndex) && (index < endIndex))) { e = GetMacroExpr(originalExpression, processedExpression); add = true; } index++; } else { e = GetMacroExpr(originalExpression, processedExpression); // Filter invalid signature / syntax if (!e.SignatureValid || e.Error) { // Apply paging. (endIndex is -1 when paging is off) if ((endIndex < 0) || ((index >= startIndex) && (index < endIndex))) { add = true; } index++; } } } if (add) { // Fill in the object information e.ObjectType = objectType; e.ObjectID = (typeInfo.IDColumn == ObjectTypeInfo.COLUMN_NAME_UNKNOWN) ? 0 : ValidationHelper.GetInteger(dr[typeInfo.IDColumn], 0); e.Field = colName; result.Add(e); } return(context.Expression); }, new List <string> { type }); if ((maxTotalRecords != -1) && (index >= maxTotalRecords)) { // Enough data - cancel enumeration throw new ActionCancelledException(); } }; using (var scope = new CMSConnectionScope()) { scope.CommandTimeout = ConnectionHelper.LongRunningCommandTimeout; infos.ForEachRow(collectMacros); } if (((maxTotalRecords != -1) && (index >= maxTotalRecords)) || !CMSHttpContext.Current.Response.IsClientConnected) { break; } } totalRecords = index; return(result); }
/// <summary> /// Gets the macros from the system /// </summary> /// <param name="startIndex">Start index</param> /// <param name="endIndex">End index</param> /// <param name="maxTotalRecords">Maximum number of total records to process</param> /// <param name="totalRecords">Returns the total number of records found</param> private IEnumerable <MacroExpr> GetMacros(int startIndex, int endIndex, int maxTotalRecords, ref int totalRecords) { var index = 0; IEnumerable <string> objectTypes = null; // Get object types to search var selectedType = ValidationHelper.GetString(selObjectType.Value, ""); if (!String.IsNullOrEmpty(selectedType)) { if (ObjectTypeManager.GetRegisteredTypeInfo(selectedType) != null) { objectTypes = new List <string> { selectedType }; } } if (objectTypes == null) { objectTypes = ObjectTypeManager.ObjectTypesWithMacros; } var result = new List <MacroExpr>(); var search = txtFilter.Text; var invalid = chkInvalid.Checked; var skipTesting = SystemContext.DevelopmentMode && chkSkipTesting.Checked; var type = drpType.Text; foreach (var objectType in objectTypes) { // Skip certain object types switch (objectType) { case ObjectVersionHistoryInfo.OBJECT_TYPE: case VersionHistoryInfo.OBJECT_TYPE: case StagingTaskInfo.OBJECT_TYPE: case IntegrationTaskInfo.OBJECT_TYPE: continue; } // Process all objects of the given type var infos = new ObjectQuery(objectType) .TopN(maxTotalRecords) .BinaryData(false); var typeInfo = infos.TypeInfo; if (skipTesting) { ExcludeTestingObjects(infos); } if (!String.IsNullOrEmpty(search)) { // Search particular expression infos.WhereAnyColumnContains(search); } else { // Search just type infos.WhereAnyColumnContains("{" + type); } Action <DataRow> collectMacros = dr => { var drc = new DataRowContainer(dr); // Process all expressions MacroProcessor.ProcessMacros(drc, (expression, colName) => { var originalExpression = expression; // Decode macro from XML if (MacroProcessor.IsXMLColumn(colName)) { expression = HTMLHelper.HTMLDecode(expression); } MacroExpr e = null; bool add = false; if (String.IsNullOrEmpty(search) || (expression.IndexOfCSafe(search, true) >= 0)) { // If not tracking errors, count immediately if (!invalid) { // Apply paging. Endindex is -1 when paging is off if ((endIndex < 0) || ((index >= startIndex) && (index <= endIndex))) { e = GetMacroExpr(expression); add = true; } index++; } else { e = GetMacroExpr(expression); // Filter invalid signature / syntax var pass = !e.SignatureValid || e.Error; if (pass) { // Apply paging. Endindex is -1 when paging is off if ((endIndex < 0) || ((index >= startIndex) && (index <= endIndex))) { add = true; } index++; } } } if (add) { // Fill in the object information e.ObjectType = objectType; e.ObjectID = (typeInfo.IDColumn == ObjectTypeInfo.COLUMN_NAME_UNKNOWN) ? 0 : ValidationHelper.GetInteger(dr[typeInfo.IDColumn], 0); e.Field = colName; result.Add(e); } return(originalExpression); }, new List <string> { type } ); if ((maxTotalRecords != -1) && (index >= maxTotalRecords)) { // Enough data - cancel enumeration throw new ActionCancelledException(); } }; using (var scope = new CMSConnectionScope()) { scope.Connection.CommandTimeout = ConnectionHelper.LongRunningCommandTimeout; infos.ForEachRow(collectMacros); } if (((maxTotalRecords != -1) && (index >= maxTotalRecords)) || !CMSHttpContext.Current.Response.IsClientConnected) { break; } } totalRecords = index; return(result); }
/// <summary> /// Gets the log message in raw format. /// </summary> private string GetRawLogMessage() { return(HTMLHelper.HTMLDecode(ctlAsyncLog.Log)); }