private void InstallPackage(FileInfo file) { // in case file disappeared since retrieved file.Refresh(); if (!file.Exists) { return; } FridayLog.Info(AutoPackages.FeatureName, $"Install auto package (Skip on conflicts): {file.FullName}"); using (new SecurityDisabler()) { var context = new SimpleProcessingContext(); // IItemInstallerEvents type cast is essential var items = (IItemInstallerEvents) new DefaultItemInstallerEvents(new BehaviourOptions(InstallMode.Skip, MergeMode.Undefined)); context.AddAspect(items); // IFileInstallerEvents type cast is essential var files = (IFileInstallerEvents) new DefaultFileInstallerEvents(false); context.AddAspect(files); new Installer().InstallPackage(file.FullName, context); new Installer().InstallSecurity(file.FullName, context); var previewContext = Installer.CreatePreviewContext(); var packageReader = new PackageReader(file.FullName); var view = new MetadataView(previewContext); var metadataSink = new MetadataSink(view); metadataSink.Initialize(previewContext); packageReader.Populate(metadataSink); new Installer().ExecutePostStep(view.PostStep, previewContext); } }
internal void Process(HttpRequestArgs args) { if (Done) { return; } lock (SyncRoot) { if (Done) { return; } Timer.Stop(); FridayLog.Info(SitecoreStarted.FeatureName, $"Sitecore is up and serving requests. Elapsed: \"{Timer.Elapsed}\", First Request: \"{HttpContext.Current.Request.RawUrl}\""); new Thread( () => { try { Event.RaiseEvent(SitecoreStarted.EventName, new EventArgs()); } catch (Exception ex) { FridayLog.Error(SitecoreStarted.FeatureName, $"Failed to process \"{SitecoreStarted.EventName}\" event", ex); } }).Start(); Done = true; } }
private void RemovePage(string signupFilePath) { if (File.Exists(signupFilePath)) { FridayLog.Info(SignUpRules.FeatureName, "Remove /sitecore/signup page"); File.Delete(signupFilePath); } }
internal void Process(PipelineArgs args) { // AutoPackages.Enabled throws exception when misconfigured // this is the main purpose of this processor - not to let // Sitecore start successfully when feature is misconfigured if (!AutoPackages.Enabled) { FridayLog.Info(AutoPackages.FeatureName, "Feature is disabled. Refer to the corresponding configuration file for instructions."); } }
internal void DoWork() { var directory = AutoPackages.Directory; FridayLog.Info(AutoPackages.FeatureName, $"Install auto packages in folder: {directory.FullName}"); Start(directory); FridayLog.Info(AutoPackages.FeatureName, $"All auto packages were installed."); }
public void Process(PipelineArgs args) { if (!AccountResetRules.Enabled) { FridayLog.Info(AccountResetRules.FeatureName, $"Feature is disabled."); return; } ThreadPool.QueueUserWorkItem(DoWork); }
private void RemoveInjectedLink(string loginFilePath, string[] lines) { for (var i = 0; i < lines.Length - 1; ++i) { var line = lines[i]; if (line.Contains(Code)) { lines[i] = line.Replace(Code, ""); FridayLog.Info(SignUpRules.FeatureName, "Remove a link to /sitecore/signup page to /sitecore/login/default.aspx"); File.WriteAllLines(loginFilePath, lines); return; } } }
internal void Process(PipelineArgs args) { try { if (ConfigExtensions.Enabled) { return; } FridayLog.Info(ConfigExtensions.FeatureName, "Feature is disabled. Refer to the corresponding configuration file for instructions."); } catch (Exception ex) { throw new ConfigurationException($"The {ConfigExtensions.FeatureName} extension is configured incorrectly. See inner exception for details.", ex); } }
public void Process(PipelineArgs args) { if (!AccountResetRules.Enabled) { FridayLog.Info(AccountResetRules.FeatureName, "Feature is disabled. Refer to the corresponding configuration file for instructions."); return; } if (!IsAsync) { DoWork(null); return; } ThreadPool.QueueUserWorkItem(DoWork); }
private void DoWork(object args) { foreach (var account in AccountResetRules.Accounts) { var username = account.Name; try { var user = MembershipProvider.GetUser(username, false); if (user == null) { MembershipProvider.CreateUserAccount(username, "", true, new string[0], AccountResetRules.FeatureName); user = MembershipProvider.GetUser(username, false) ?? throw new InvalidOperationException($"Failed to find user after creating, UserName: {username}"); } // first change password and only then it is safe to unlock var password = MembershipProvider.ResetPassword(username, null); if (user.IsLockedOut) { user.UnlockUser(); } var desiredPassword = account.Password; if (!string.IsNullOrEmpty(desiredPassword)) { try { user.ChangePassword(password, desiredPassword); FridayLog.Info(AccountResetRules.FeatureName, $"User account was reset, UserName: {username}, Password: {desiredPassword}, IsLockedOut: false"); } catch (Exception ex) { FridayLog.Error(AccountResetRules.FeatureName, $"User account was reset, but failed to change password to desired one, UserName: {username}, CurrentPassword: {password}, DesiredPassword: {desiredPassword} IsLockedOut: false", ex); } } } catch (Exception ex) { FridayLog.Error(AccountResetRules.FeatureName, $"Failed to reset user account, UserName: {username}", ex); } } }
internal void Process(PipelineArgs args) { try { var domains = SignUpRules.Rules; if (domains.Count == 0) { FridayLog.Info(SignUpRules.FeatureName, "Feature is disabled. Refer to the corresponding configuration file for instructions."); return; } if (string.IsNullOrEmpty(Settings.MailServer)) { FridayLog.Info(SignUpRules.FeatureName, "Feature is disabled (mail server is not configured)."); return; } foreach (var domain in domains) { var name = domain.Domain; var roles = string.Join(", ", domain.Roles); var secret = domain.Secret; var isAdministrator = domain.IsAdministrator; FridayLog.Info( SignUpRules.FeatureName, $"Enable sign up rule, " + $"Domain: \"{name}\", " + $"IsAdministrator: {isAdministrator}, " + $"Roles: \"{roles}\", " + $"Secret: \"{secret}\", " + $"Profile: \"/sitecore/system/Settings/Security/Profiles/User\""); } } catch (Exception ex) { throw new ConfigurationException($"The {SignUpRules.FeatureName} extension is configured incorrectly. See inner exception for details.", ex); } }
private void InjectLink(string loginFilePath, string[] lines) { for (var i = 0; i < lines.Length - 1; ++i) { var line = lines[i]; if (line.Contains("ID=\"forgotPasswordLinkMessage\"")) { var next = lines[i + 1]; if (next.Contains("new-user-account")) { return; } lines[i + 1] = next + Code; FridayLog.Info(SignUpRules.FeatureName, "Inject a link to /sitecore/signup page to /sitecore/login/default.aspx"); File.WriteAllLines(loginFilePath, lines); return; } } }
internal void LogMeasurements(object obj, EventArgs args) { Timer.Stop(); FridayLog.Info(SitecoreStarted.FeatureName, $"Sitecore is up and serving requests. Elapsed: {Timer.Elapsed}"); }
public static void Initialize() { Timer.Start(); FridayLog.Info(SitecoreStarted.FeatureName, $"Sitecore is initializing..."); }
private void InstallPackage(FileInfo file) { // in case file disappeared since retrieved file.Refresh(); if (!file.Exists) { return; } var filenameWithoutExtension = Path.GetFileNameWithoutExtension(file.Name); filenameWithoutExtension = ItemUtil.ProposeValidItemName(filenameWithoutExtension); Assert.IsTrue(!string.IsNullOrWhiteSpace(filenameWithoutExtension), "The package should be renamed to something that item can have name of: " + file.Name); using (new SecurityDisabler()) { var db = Factory.GetDatabase("core"); var historyItem = db.GetItem("/sitecore/system/Packages/Installation history"); if (historyItem.Children.Any(x => string.Equals(x.Name, filenameWithoutExtension, StringComparison.OrdinalIgnoreCase))) { FridayLog.Info(AutoPackages.FeatureName, $"Install auto package skipped (already installed): \"{file.FullName}\""); return; } } // The way how SC creates history item it cumbersome - it has some non-obvious length limitations // so add extra logic to work around it. var historyFile = new FileInfo(file.FullName + ".history.txt"); if (historyFile.Exists) { FridayLog.Info(AutoPackages.FeatureName, $"Install auto package skipped (already installed): \"{file.FullName}\""); return; } File.AppendAllText(historyFile.FullName, DateTime.UtcNow.ToString("o") + "\r\n"); FridayLog.Info(AutoPackages.FeatureName, $"Install auto package (Skip on conflicts): \"{file.FullName}\""); using (new SecurityDisabler()) { var context = new SimpleProcessingContext(); // IItemInstallerEvents type cast is essential var items = (IItemInstallerEvents) new DefaultItemInstallerEvents(new BehaviourOptions(InstallMode.Overwrite, MergeMode.Undefined)); context.AddAspect(items); // IFileInstallerEvents type cast is essential var files = (IFileInstallerEvents) new DefaultFileInstallerEvents(true); context.AddAspect(files); new Installer().InstallPackage(file.FullName, context); new Installer().InstallSecurity(file.FullName, context); var previewContext = Installer.CreatePreviewContext(); var packageReader = new PackageReader(file.FullName); var view = new MetadataView(previewContext); var metadataSink = new MetadataSink(view); metadataSink.Initialize(previewContext); packageReader.Populate(metadataSink); new Installer().ExecutePostStep(view.PostStep, previewContext); } }
private void DoWork(object args) { foreach (var account in AccountResetRules.Accounts) { var username = account.Name; try { var user = MembershipProvider.GetUser(username, false); if (user == null) { MembershipProvider.CreateUserAccount(username, "", true, new string[0], AccountResetRules.FeatureName); var error = "Failed to find user after creating, " + $"UserName: {username}"; user = MembershipProvider.GetUser(username, false) ?? throw new InvalidOperationException(error); } // first change password and only then it is safe to unlock var password = MembershipProvider.ResetPassword(username, null); if (user.IsLockedOut) { user.UnlockUser(); } var desiredPassword = account.Password; if (!string.IsNullOrEmpty(desiredPassword)) { try { Assert.IsTrue(user.ChangePassword(password, desiredPassword), "Membership provider rejected password change request."); } catch (Exception ex) { var error = "User account was reset, but failed to change password to desired one, " + $"UserName: \"{username}\", " + $"CurrentPassword: \"{password}\", " + $"DesiredPassword: \"{desiredPassword}\", " + "IsLockedOut: false"; FridayLog.Error(AccountResetRules.FeatureName, error, ex); continue; } } var message = "User account was reset, " + $"UserName: \"{username}\", " + $"Password: \"{(account.WritePasswordToLog ? desiredPassword ?? password : "******")}\", " + "IsLockedOut: false"; FridayLog.Info(AccountResetRules.FeatureName, message); var recepients = account.EmailPasswordToRecepients; if (recepients.Any()) { Helper.SendMailMessageAsync(user, desiredPassword ?? password, recepients); } } catch (Exception ex) { var error = "Failed to reset user account, " + $"UserName: \"{username}\""; FridayLog.Error(AccountResetRules.FeatureName, error, ex); } } }