private string GetFormConsentMacroRule() { var rule = $@"{{%Rule(""(Contact.AgreedWithConsent(""{FormConsentGenerator.CONSENT_NAME}""))"", "" <rules><r pos =\""0\"" par=\""\"" op=\""and\"" n=\""CMSContactHasAgreedWithConsent\"" > <p n=\""consent\""><t>{FormConsentGenerator.CONSENT_DISPLAY_NAME}</t><v>{FormConsentGenerator.CONSENT_NAME}</v><r>0</r><d>select consent</d><vt>text</vt><tv>0</tv></p> <p n=\""_perfectum\""><t>has</t><v></v><r>0</r><d>select operation</d><vt>text</vt><tv>0</tv></p></r></rules>"")%}}"; return(MacroSecurityProcessor.AddSecurityParameters(rule, MacroIdentityOption.FromUserInfo(UserInfoProvider.AdministratorUser), null)); }
private void GenerateBannerPersonalizationVariantsMacrosAndEnableVariants() { var personalizationVariant1 = ContentPersonalizationVariantInfoProvider.GetContentPersonalizationVariant( "TheCafeOwnerBannerVariant_dd20f145-3779-4748-9bc8-d383eecfbd15"); var personalizationVariant2 = ContentPersonalizationVariantInfoProvider.GetContentPersonalizationVariant( "TheCoffeeGeekBannerVariant_d862b458-e5a5-432f-a3fe-60f495acad9f"); if (personalizationVariant1 == null || personalizationVariant2 == null || personalizationVariant1.VariantEnabled || personalizationVariant2.VariantEnabled || personalizationVariant1.VariantDisplayCondition != "{%// Macro will be added by generator%}" || personalizationVariant2.VariantDisplayCondition != "{%// Macro will be added by generator%}") { return; } var personaInfoByCodeName1 = PersonaInfoProvider.GetPersonaInfoByCodeName(PERSONA_CAFE_OWNER); var personaInfoByCodeName2 = PersonaInfoProvider.GetPersonaInfoByCodeName(PERSONA_COFEE_GEEK); if (personaInfoByCodeName1 == null || personaInfoByCodeName2 == null) { return; } var identityOption = MacroIdentityOption.FromUserInfo(UserInfoProvider.AdministratorUser); personalizationVariant1.VariantDisplayCondition = MacroSecurityProcessor.AddSecurityParameters( string.Format( "{{%Rule(\"(Contact.IsInPersona(\\\"{0}\\\"))\", \"<rules><r pos=\\\"0\\\" par=\\\"\\\" op=\\\"and\\\" n=\\\"ContactIsInPersona\\\" ><p n=\\\"_is\\\"><t>is</t><v></v><r>0</r><d>select operation</d><vt>text</vt><tv>0</tv></p><p n=\\\"personaguid\\\"><t>{1}</t><v>{0}</v><r>1</r><d>select persona</d><vt>text</vt><tv>0</tv></p></r></rules>\")%}}", personaInfoByCodeName1.PersonaGUID, personaInfoByCodeName1.PersonaDisplayName), identityOption, null); personalizationVariant2.VariantDisplayCondition = MacroSecurityProcessor.AddSecurityParameters( string.Format( "{{%Rule(\"(Contact.IsInPersona(\\\"{0}\\\"))\", \"<rules><r pos=\\\"0\\\" par=\\\"\\\" op=\\\"and\\\" n=\\\"ContactIsInPersona\\\" ><p n=\\\"_is\\\"><t>is</t><v></v><r>0</r><d>select operation</d><vt>text</vt><tv>0</tv></p><p n=\\\"personaguid\\\"><t>{1}</t><v>{0}</v><r>1</r><d>select persona</d><vt>text</vt><tv>0</tv></p></r></rules>\")%}}", personaInfoByCodeName2.PersonaGUID, personaInfoByCodeName2.PersonaDisplayName), identityOption, null); personalizationVariant1.VariantEnabled = true; personalizationVariant2.VariantEnabled = true; ContentPersonalizationVariantInfoProvider.SetContentPersonalizationVariant(personalizationVariant1); ContentPersonalizationVariantInfoProvider.SetContentPersonalizationVariant(personalizationVariant2); }
/// <summary> /// Refreshes macro signatures in all object which can contain macros. /// </summary> private static void RefreshMacroSignatures() { // Get object types var objectTypes = new List <string> { TransformationInfo.OBJECT_TYPE, UIElementInfo.OBJECT_TYPE, FormUserControlInfo.OBJECT_TYPE, SettingsKeyInfo.OBJECT_TYPE, AlternativeFormInfo.OBJECT_TYPE, DataClassInfo.OBJECT_TYPE, // Process all data classes just through general object type to avoid duplicities PageTemplateInfo.OBJECT_TYPE, LayoutInfo.OBJECT_TYPE, CssStylesheetInfo.OBJECT_TYPE, WorkflowActionInfo.OBJECT_TYPE, }; var adminIdentityOption = MacroIdentityOption.FromUserInfo(UserInfoProvider.AdministratorUser); foreach (string type in objectTypes) { try { using (var context = new CMSActionContext()) { context.DisableLogging(); context.CreateVersion = false; context.LogIntegration = false; var infos = new InfoObjectCollection(type); foreach (var info in infos) { MacroSecurityProcessor.RefreshSecurityParameters(info, adminIdentityOption, true); } } } catch (Exception ex) { EventLogProvider.LogException(EventLogSource, "REFRESHMACROSIGNATURES", ex, 0, "Type: " + type); } } }
/// <summary> /// Loads data from textboxes and store them to data collection /// </summary> private void LoadData() { data.Clear(); var authenticatedUserIdentityOption = MacroIdentityOption.FromUserInfo(MembershipContext.AuthenticatedUser); foreach (String key in Request.Form.AllKeys) { if ((key != null) && key.StartsWithCSafe(UniqueID + "$tk")) { String value = Request.Form[key.Replace(UniqueID + "$tk", UniqueID + "$tv")]; // Sign the macro value = MacroSecurityProcessor.AddSecurityParameters(value, authenticatedUserIdentityOption, null); String k = Request.Form[key]; if (!IsValidKey(k)) { invalidKey = k; k = INVALIDTOKEN; } data.SetValue(k, value); } } // Add data from new field String newValue = Request.Form[UniqueID + "$utv_newvalue"]; String newKey = Request.Form[UniqueID + "$utk_newkey"]; if (!String.IsNullOrEmpty(newValue) || !String.IsNullOrEmpty(newKey)) { if (!IsValidKey(newKey)) { isNewValid = false; return; } // Sign the macro newValue = MacroSecurityProcessor.AddSecurityParameters(newValue, authenticatedUserIdentityOption, null); data.SetValue(newKey, newValue); } }
private static ContactGroupInfo CreateContactGroup(PersonaInfo persona) { var contactGroupInfo = ContactGroupInfoProvider.GetContactGroupInfo(CoffeeGeekPersonaContactGroupName); if (contactGroupInfo != null) { ContactGroupInfoProvider.DeleteContactGroupInfo(contactGroupInfo); } var groupObj = new ContactGroupInfo(); groupObj.ContactGroupDisplayName = "Is in persona 'Martina, the Coffee Geek'"; groupObj.ContactGroupName = CoffeeGeekPersonaContactGroupName; groupObj.ContactGroupEnabled = true; var str = MacroSecurityProcessor.AddSecurityParameters( string.Format( "{{%Rule(\"(Contact.IsInPersona(\\\"{0}\\\"))\", \"<rules><r pos=\\\"0\\\" par=\\\"\\\" op=\\\"and\\\" n=\\\"ContactIsInPersona\\\" ><p n=\\\"_is\\\"><t>is</t><v></v><r>0</r><d>select operation</d><vt>text</vt><tv>0</tv></p><p n=\\\"personaguid\\\"><t>{1}</t><v>{0}</v><r>1</r><d>select persona</d><vt>text</vt><tv>0</tv></p></r></rules>\") %}}", persona.PersonaGUID, persona.PersonaDisplayName), MacroIdentityOption.FromUserInfo(UserInfoProvider.AdministratorUser), null); groupObj.ContactGroupDynamicCondition = str; ContactGroupInfoProvider.SetContactGroupInfo(groupObj); return(groupObj); }
/// <summary> /// Creates new <see cref="FieldMacroRule"/> object based on inputs. /// </summary> private FieldMacroRule CreateMacroRule() { if (!IsValid()) { return(null); } MacroRuleTree main = null; FieldMacroRule fmr = null; MacroRuleInfo mri = MacroRuleInfoProvider.GetMacroRuleInfo(mSelectedRuleName); if (mri != null) { main = new MacroRuleTree(); MacroRuleTree childern = new MacroRuleTree() { RuleText = mri.MacroRuleText, RuleName = mri.MacroRuleName, RuleCondition = mri.MacroRuleCondition, Parent = main }; main.Children.Add(childern); foreach (string paramName in formProperties.Fields) { // Load value from the form control FormEngineUserControl ctrl = formProperties.FieldControls[paramName]; if (ctrl != null) { // Convert value to EN culture var dataType = ctrl.FieldInfo.DataType; var convertedValue = DataTypeManager.ConvertToSystemType(TypeEnum.Field, dataType, ctrl.Value); string value = ValidationHelper.GetString(convertedValue, "", CultureHelper.EnglishCulture); string displayName = ctrl.ValueDisplayName; if (String.IsNullOrEmpty(displayName)) { displayName = value; } MacroRuleParameter param = new MacroRuleParameter { Value = value, Text = displayName, ValueType = dataType }; childern.Parameters.Add(paramName, param); } } string macroRule = string.Format("Rule(\"{0}\", \"{1}\")", MacroElement.EscapeSpecialChars(main.GetCondition()), MacroElement.EscapeSpecialChars(main.GetXML())); if (!MacroSecurityProcessor.IsSimpleMacro(macroRule)) { // Sign complex macros macroRule = MacroSecurityProcessor.AddMacroSecurityParams(macroRule, MacroIdentityOption.FromUserInfo(MembershipContext.AuthenticatedUser)); } fmr = new FieldMacroRule(); fmr.MacroRule = string.Format("{{%{0}%}}", macroRule); fmr.ErrorMessage = txtErrorMsg.Text; } return(fmr); }
private void RefreshSecurityParams(IEnumerable <string> objectTypes, string oldSalt, string newSalt) { var oldSaltSpecified = !string.IsNullOrEmpty(oldSalt) && !chkRefreshAll.Checked; var newSaltSpecified = !string.IsNullOrEmpty(newSalt) && !chkUseCurrentSalt.Checked; processedObjects.Clear(); using (var context = new CMSActionContext()) { context.LogEvents = false; context.LogSynchronization = false; var processingString = GetString("macros.refreshsecurityparams.processing"); foreach (var objectType in objectTypes) { var niceObjectType = GetNiceObjectTypeName(objectType); AddLog(string.Format(processingString, niceObjectType)); try { var infos = new InfoObjectCollection(objectType) { PageSize = 1000 }; var csi = infos.TypeInfo.ClassStructureInfo; var orderByIndex = FindOrderByIndex(csi); if (orderByIndex != null) { infos.OrderByColumns = orderByIndex.GetOrderBy(); } // Skip object types derived from general data class object type to avoid duplicities if ((infos.TypeInfo.OriginalObjectType == DataClassInfo.OBJECT_TYPE) && (infos.TypeInfo.ObjectType != DataClassInfo.OBJECT_TYPE)) { continue; } foreach (var info in infos) { try { bool refreshed; if (oldSaltSpecified) { refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, oldSalt, newSaltSpecified ? newSalt : ValidationHelper.HashStringSalt, true); } else { var identityOption = MacroIdentityOption.FromUserInfo(MembershipContext.AuthenticatedUser); if (chkRefreshAll.Checked && newSaltSpecified) { // Do not check integrity, but use new salt refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, identityOption, true, newSalt); } else { // Do not check integrity, sign everything with current user refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, identityOption, true); } } if (refreshed) { var objectName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(info.Generalized.ObjectDisplayName)); processedObjects.Add(niceObjectType, objectName); } } catch (Exception ex) { string message = "Signing " + TypeHelper.GetNiceObjectTypeName(info.TypeInfo.ObjectType) + " " + info.Generalized.ObjectDisplayName + " failed: " + ex.Message; using (var exceptionContext = new CMSActionContext()) { exceptionContext.LogEvents = true; EventLogProvider.LogEvent(EventType.ERROR, "Import", "MACROSECURITY", message); } } } } catch (Exception ex) { AddLog(ex.Message); using (var exceptionContext = new CMSActionContext()) { exceptionContext.LogEvents = true; EventLogProvider.LogException(EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "ERROR", ex); } } } } EventLogProvider.LogEvent(EventType.INFORMATION, EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "PROCESSEDOBJECTS", GetProcessedObjectsForEventLog()); }
/// <summary> /// Creates new or updates existing newsletter issue. /// </summary> protected void btnSubmit_Click(object sender, EventArgs e) { if (IsValid()) { IssueInfo issue = IssueInfoProvider.GetIssueInfo(IssueID); if ((issue != null) && Enabled) { if (IsDisplayNameFieldEnabled(issue)) { issue.IssueDisplayName = txtDisplayName.Text.Trim(); } issue.IssueTemplateID = TemplateID; issue.IssueSenderName = txtSenderName.Text.Trim(); issue.IssueSenderEmail = txtSenderEmail.Text.Trim(); issue.IssuePreheader = txtPreheader.Text.Trim(); issue.IssueUseUTM = chkIssueUseUTM.Checked; issue.IssueUTMSource = Normalize(txtIssueUTMSource.Text.Trim()); if (radUTMCampaignNew.Checked) { var normalizedUtmCampaign = Normalize(mUTMCampaignTextBox.Text.Trim()); if (string.IsNullOrEmpty(normalizedUtmCampaign)) { normalizedUtmCampaign = Normalize(Newsletter.NewsletterName); } mUTMCampaignTextBox.Text = issue.IssueUTMCampaign = normalizedUtmCampaign; } else { issue.IssueUTMCampaign = selectorUTMCampaign.Value.ToString().ToLower(CultureInfo.CurrentCulture); } PostProcessVariants(issue); // Remove '#' from macros if included txtSubject.Text = txtSubject.Text.Trim().Replace("#%}", "%}"); // Sign macros if included in the subject issue.IssueSubject = MacroSecurityProcessor.AddSecurityParameters(txtSubject.Text, MacroIdentityOption.FromUserInfo(MembershipContext.AuthenticatedUser), null); // Save issue IssueInfoProvider.SetIssueInfo(issue); // Update IssueID IssueID = issue.IssueID; OnSave(new EmailBuilderEventArgs(NewsletterID, IssueID)); } } }
private string BuildMacroRuleCondition(string macroCondition) => "<condition>\r\n <macro>\r\n <value>" + MacroSecurityProcessor.AddSecurityParameters(macroCondition, MacroIdentityOption.FromUserInfo(UserInfoProvider.AdministratorUser), null) + "</value>\r\n </macro>\r\n</condition>";
/// <summary> /// Creates new or updates existing newsletter issue. /// </summary> protected void btnSubmit_Click(object sender, EventArgs e) { var issue = IssueInfo.Provider.Get(IssueID); if ((issue == null) || !Enabled || !IsValid(issue)) { return; } if (IsDisplayNameFieldEnabled(issue)) { issue.IssueDisplayName = txtDisplayName.Text.Trim(); } issue.IssueTemplateID = TemplateID; issue.IssueSenderName = txtSenderName.Text.Trim(); issue.IssueSenderEmail = txtSenderEmail.Text.Trim(); issue.IssuePreheader = txtPreheader.Text.Trim(); issue.IssueUseUTM = chkIssueUseUTM.Checked; issue.IssueUTMSource = Normalize(txtIssueUTMSource.Text.Trim()); var needsFullRefresh = false; if (chkIssueForAutomation.Visible) { // Check whether the full refresh of the Email builder (including the left tabs) is necessary needsFullRefresh = issue.IssueForAutomation != chkIssueForAutomation.Checked; issue.IssueForAutomation = chkIssueForAutomation.Checked; } if (radUTMCampaignNew.Checked) { var normalizedUtmCampaign = Normalize(mUTMCampaignTextBox.Text.Trim()); if (string.IsNullOrEmpty(normalizedUtmCampaign)) { normalizedUtmCampaign = Normalize(Newsletter.NewsletterName); } mUTMCampaignTextBox.Text = issue.IssueUTMCampaign = normalizedUtmCampaign; } else { issue.IssueUTMCampaign = selectorUTMCampaign.Value.ToString().ToLower(CultureInfo.CurrentCulture); } PostProcessVariants(issue); // Remove '#' from macros if included txtSubject.Text = txtSubject.Text.Trim().Replace("#%}", "%}"); // Sign macros if included in the subject issue.IssueSubject = MacroSecurityProcessor.AddSecurityParameters(txtSubject.Text, MacroIdentityOption.FromUserInfo(MembershipContext.AuthenticatedUser), null); // Save issue IssueInfo.Provider.Set(issue); // Update IssueID IssueID = issue.IssueID; var builderEventArgs = needsFullRefresh ? new EmailBuilderEventArgs() : new EmailBuilderEventArgs(NewsletterID, IssueID, 1); OnSave(builderEventArgs); }
private void ExecuteCreateAction(int templateId) { if (templateId == CREATE_FROM_SCRATCH_ID) { mWorkflow = AutomationHelper.CreateEmptyWorkflow(); } else { var template = AutomationTemplateInfo.Provider.Get(templateId); if (template != null) { mWorkflow = AutomationTemplateManager.CreateAutomationProcessFromTemplate(template, MacroIdentityOption.FromUserInfo(CurrentUser)); } } }