Generate session logic moved to correct place.

This commit is contained in:
feodor_fitsner 2012-09-13 19:23:21 -07:00
parent a3e5be7fe3
commit f42298e7fe
5 changed files with 52 additions and 47 deletions

View file

@ -31,6 +31,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.IO; using System.IO;
using System.Xml; using System.Xml;
using WebsitePanel.Setup.Common;
namespace WebsitePanel.Setup.Actions namespace WebsitePanel.Setup.Actions
{ {
@ -114,6 +115,55 @@ namespace WebsitePanel.Setup.Actions
} }
} }
public class GenerateSessionValidationKeyAction : Action, IInstallAction
{
public const string LogStartInstallMessage = "Generating session validation key...";
void IInstallAction.Run(SetupVariables vars)
{
try
{
Begin(LogStartInstallMessage);
Log.WriteStart(LogStartInstallMessage);
string path = Path.Combine(vars.InstallationFolder, "web.config");
if (!File.Exists(path))
{
Log.WriteInfo(string.Format("File {0} not found", path));
return;
}
Log.WriteStart("Updating configuration file (session validation key)");
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlElement sessionKey = doc.SelectSingleNode("configuration/appSettings/add[@key='SessionValidationKey']") as XmlElement;
if (sessionKey == null)
{
Log.WriteInfo("SessionValidationKey setting not found");
return;
}
sessionKey.SetAttribute("value", StringUtils.GenerateRandomString(16));
doc.Save(path);
Log.WriteEnd("Generated session validation key");
InstallLog.AppendLine("- Generated session validation key");
}
catch (Exception ex)
{
if (Utils.IsThreadAbortException(ex))
return;
//
Log.WriteError("Site settigs error", ex);
//
throw;
}
}
}
public class CreateDesktopShortcutsAction : Action, IInstallAction public class CreateDesktopShortcutsAction : Action, IInstallAction
{ {
public const string LogStartInstallMessage = "Creating shortcut..."; public const string LogStartInstallMessage = "Creating shortcut...";
@ -253,6 +303,7 @@ namespace WebsitePanel.Setup.Actions
new CreateWebSiteAction(), new CreateWebSiteAction(),
new SwitchAppPoolAspNetVersion(), new SwitchAppPoolAspNetVersion(),
new UpdateEnterpriseServerUrlAction(), new UpdateEnterpriseServerUrlAction(),
new GenerateSessionValidationKeyAction(),
new SaveComponentConfigSettingsAction(), new SaveComponentConfigSettingsAction(),
new CreateDesktopShortcutsAction() new CreateDesktopShortcutsAction()
}; };

View file

@ -88,8 +88,7 @@ namespace WebsitePanel.Setup
SwitchServer2AspNet40, SwitchServer2AspNet40,
SwitchEntServer2AspNet40, SwitchEntServer2AspNet40,
SwitchWebPortal2AspNet40, SwitchWebPortal2AspNet40,
ConfigureSecureSessionModuleInWebConfig, ConfigureSecureSessionModuleInWebConfig
UpdatePortalSessionValidationKey
} }
public class InstallAction public class InstallAction

View file

@ -217,10 +217,6 @@ namespace WebsitePanel.Setup
action.Description = "Updating site settings..."; action.Description = "Updating site settings...";
page3.Actions.Add(action); page3.Actions.Add(action);
action = new InstallAction(ActionTypes.UpdatePortalSessionValidationKey);
action.Description = "Generate session validation key...";
page3.Actions.Add(action);
action = new InstallAction(ActionTypes.UpdateConfig); action = new InstallAction(ActionTypes.UpdateConfig);
action.Description = "Updating system configuration..."; action.Description = "Updating system configuration...";
page3.Actions.Add(action); page3.Actions.Add(action);

View file

@ -260,9 +260,6 @@ namespace WebsitePanel.Setup
break; break;
case ActionTypes.ConfigureSecureSessionModuleInWebConfig: case ActionTypes.ConfigureSecureSessionModuleInWebConfig:
ConfigureSecureSessionModuleInWebConfig(); ConfigureSecureSessionModuleInWebConfig();
break;
case ActionTypes.UpdatePortalSessionValidationKey:
UpdatePortalSessionValidationKey();
break; break;
} }
} }
@ -2657,44 +2654,6 @@ namespace WebsitePanel.Setup
} }
} }
private void UpdatePortalSessionValidationKey()
{
try
{
string installFolder = Wizard.SetupVariables.InstallationFolder;
string path = Path.Combine(installFolder, "web.config");
if (!File.Exists(path))
{
Log.WriteInfo(string.Format("File {0} not found", path));
return;
}
Log.WriteStart("Updating configuration file (session validation key)");
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlElement sessionKey = doc.SelectSingleNode("configuration/appSettings/add[@key='SessionValidationKey']") as XmlElement;
if (sessionKey == null)
{
Log.WriteInfo("SessionValidationKey setting not found");
return;
}
sessionKey.SetAttribute("value", StringUtils.GenerateRandomString(16));
doc.Save(path);
Log.WriteEnd("Updated configuration file");
InstallLog.AppendLine("- Updated session validation key in the configuration file");
}
catch (Exception ex)
{
if (Utils.IsThreadAbortException(ex))
return;
Log.WriteError("Configuration file update error", ex);
throw;
}
}
private void SetServiceSettings() private void SetServiceSettings()
{ {
try try