diff --git a/WebsitePanel.Installer/Sources/Setup.WIXInstaller/Product.wxs b/WebsitePanel.Installer/Sources/Setup.WIXInstaller/Product.wxs index 26442c52..82eef886 100644 --- a/WebsitePanel.Installer/Sources/Setup.WIXInstaller/Product.wxs +++ b/WebsitePanel.Installer/Sources/Setup.WIXInstaller/Product.wxs @@ -215,7 +215,7 @@ DB_CONN_CORRECT="0" DB_CONN_CORRECT="1" - + @@ -563,17 +563,14 @@ - - - - + @@ -595,6 +592,7 @@ WSP_ROOT + @@ -614,6 +612,7 @@ + diff --git a/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Common/Log.cs b/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Common/Log.cs index 3c74bfda..6f9bb1c1 100644 --- a/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Common/Log.cs +++ b/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Common/Log.cs @@ -57,7 +57,7 @@ namespace WebsitePanel.Setup /// /// Error message. /// Exception. - internal static void WriteError(string message, Exception ex) + public static void WriteError(string message, Exception ex) { try { @@ -74,7 +74,7 @@ namespace WebsitePanel.Setup /// /// Error message. /// Exception. - internal static void WriteError(string message) + public static void WriteError(string message) { WriteError(message, null); } @@ -83,7 +83,7 @@ namespace WebsitePanel.Setup /// Write to log /// /// - internal static void Write(string message) + public static void Write(string message) { try { @@ -98,7 +98,7 @@ namespace WebsitePanel.Setup /// Write line to log /// /// - internal static void WriteLine(string message) + public static void WriteLine(string message) { try { @@ -112,7 +112,7 @@ namespace WebsitePanel.Setup /// Write info message to log /// /// - internal static void WriteInfo(string message) + public static void WriteInfo(string message) { try { @@ -126,7 +126,7 @@ namespace WebsitePanel.Setup /// Write start message to log /// /// - internal static void WriteStart(string message) + public static void WriteStart(string message) { try { @@ -141,7 +141,7 @@ namespace WebsitePanel.Setup /// Write end message to log /// /// - internal static void WriteEnd(string message) + public static void WriteEnd(string message) { try { diff --git a/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Wizard/ConfigurationCheckPage.cs b/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Wizard/ConfigurationCheckPage.cs index 20344e42..c80bfd5a 100644 --- a/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Wizard/ConfigurationCheckPage.cs +++ b/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Wizard/ConfigurationCheckPage.cs @@ -601,16 +601,29 @@ namespace WebsitePanel.Setup private static bool IsAspNetRoleServiceInstalled() { - RegistryKey regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\InetStp\\Components"); - if (regkey == null) - return false; - - int value = (int)regkey.GetValue("ASPNET", 0); - - if (value != 1) - value = (int)regkey.GetValue("ASPNET45", 0); - - return value == 1; + return GetIsWebFeaturesInstalled(); } + private static bool GetIsWebFeaturesInstalled() + { // See WebsitePanel.Installer\Sources\WebsitePanel.WIXInstaller\Common\Tool.cs + bool Result = false; + var LMKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); + Result |= CheckAspNetRegValue(LMKey); + LMKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); + Result |= CheckAspNetRegValue(LMKey); + return Result; + } + private static bool CheckAspNetRegValue(RegistryKey BaseKey) + { + var WebComponentsKey = "SOFTWARE\\Microsoft\\InetStp\\Components"; + var AspNet = "ASPNET"; + var AspNet45 = "ASPNET45"; + RegistryKey Key = BaseKey.OpenSubKey(WebComponentsKey); + if (Key == null) + return false; + var Value = int.Parse(Key.GetValue(AspNet, 0).ToString()); + if (Value != 1) + Value = int.Parse(Key.GetValue(AspNet45, 0).ToString()); + return Value == 1; + } } } diff --git a/WebsitePanel.Installer/Sources/WebsitePanel.WIXInstaller/Common/Tool.cs b/WebsitePanel.Installer/Sources/WebsitePanel.WIXInstaller/Common/Tool.cs index 0c8159b1..4b2b20c7 100644 --- a/WebsitePanel.Installer/Sources/WebsitePanel.WIXInstaller/Common/Tool.cs +++ b/WebsitePanel.Installer/Sources/WebsitePanel.WIXInstaller/Common/Tool.cs @@ -1,14 +1,16 @@ -using Microsoft.Deployment.WindowsInstaller; -using System; -using System.Collections.Generic; +using System; +using System.Diagnostics; +using System.IO; using System.Linq; -using System.Text; +using Microsoft.Deployment.WindowsInstaller; +using Microsoft.Win32; using WebsitePanel.Setup; namespace WebsitePanel.WIXInstaller.Common { internal static class Tool { + public const int MINIMUM_WEBSERVER_MAJOR_VERSION = 6; public static SetupVariables GetSetupVars(Session Ctx) { return new SetupVariables @@ -17,20 +19,159 @@ namespace WebsitePanel.WIXInstaller.Common IISVersion = Global.IISVersion }; } - - public static void FillServerVariables(SetupVariables Vars) + public static Version GetWebServerVersion() { - + var WebServerKey = "SOFTWARE\\Microsoft\\InetStp"; + RegistryKey Key = Registry.LocalMachine.OpenSubKey(WebServerKey); + if (Key == null) + return new Version(0,0); + var Major = int.Parse(Key.GetValue("MajorVersion", 0).ToString()); + var Minor = int.Parse(Key.GetValue("MinorVersion", 0).ToString()); + return new Version(Major, Minor); } - - public static void FillEServerVariables(SetupVariables Vars) + public static bool GetIsWebRoleInstalled() { - + var WebServer = GetWebServerVersion(); + return WebServer.Major >= Tool.MINIMUM_WEBSERVER_MAJOR_VERSION; } - - public static void FillPortalVariables(SetupVariables Vars) + public static bool GetIsWebFeaturesInstalled() { - + bool Result = false; + var LMKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); + Result |= CheckAspNetRegValue(LMKey); + LMKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); + Result |= CheckAspNetRegValue(LMKey); + return Result; + } + public static bool CheckAspNetRegValue(RegistryKey BaseKey) + { + var WebComponentsKey = "SOFTWARE\\Microsoft\\InetStp\\Components"; + var AspNet = "ASPNET"; + var AspNet45 = "ASPNET45"; + RegistryKey Key = BaseKey.OpenSubKey(WebComponentsKey); + if (Key == null) + return false; + var Value = int.Parse(Key.GetValue(AspNet, 0).ToString()); + if (Value != 1) + Value = int.Parse(Key.GetValue(AspNet45, 0).ToString()); + return Value == 1; + } + public static bool InstallWebRole(out string Msg) + { + Msg = string.Empty; + var OSV = Global.OSVersion; + switch (OSV) + { + case OS.WindowsVersion.WindowsServer2008: + { + var Features = new[] + { + "Web-Server" + }; + Msg = InstallWebViaServerManagerCmd(Features); + } + break; + case OS.WindowsVersion.WindowsServer2008R2: + case OS.WindowsVersion.WindowsServer2012: + case OS.WindowsVersion.WindowsServer2012R2: + case OS.WindowsVersion.Windows7: + case OS.WindowsVersion.Windows8: + { + var Features = new[] + { + "IIS-WebServer", + "IIS-WebServerRole", + "IIS-CommonHttpFeatures", + "IIS-DefaultDocument", + "IIS-ISAPIExtensions", + "IIS-ISAPIFilter", + "IIS-ManagementConsole", + "IIS-NetFxExtensibility", + "IIS-RequestFiltering", + "IIS-Security", + "IIS-StaticContent" + }; + Msg = InstallWebViaDism(Features); + } + break; + default: + return false; + } + return true; + } + public static bool InstallWebFeatures(out string Msg) + { + Msg = string.Empty; + var OSV = Global.OSVersion; + switch (OSV) + { + case OS.WindowsVersion.WindowsServer2008: + { + var Features = new[] + { + "Web-Asp-Net" + }; + Msg += InstallWebViaServerManagerCmd(Features); + Msg += PrepareAspNet(); + } + break; + case OS.WindowsVersion.WindowsServer2008R2: + case OS.WindowsVersion.WindowsServer2012: + case OS.WindowsVersion.WindowsServer2012R2: + case OS.WindowsVersion.Windows7: + case OS.WindowsVersion.Windows8: + { + var Features = new[] + { + "IIS-ApplicationDevelopment", + "IIS-ASPNET", + "IIS-ASPNET45" + }; + Msg = InstallWebViaDism(Features); + } + break; + default: + return false; + } + return true; + } + public static string PrepareAspNet() + { + var Cmd = string.Format(@"Microsoft.NET\Framework{0}\v4.0.30319\aspnet_regiis.exe", Environment.Is64BitOperatingSystem ? "64" : "" ); + return RunTool(Path.Combine(OS.GetWindowsDirectory(), Cmd), "-i -enable"); + } + private static string InstallWebViaDism(params string[] Features) + { + var Params = string.Format("/NoRestart /Online /Enable-Feature {0}", + string.Join(" ", Features.Select( + Feature => string.Format("/FeatureName:{0} /All", Feature) + ))); + return RunTool(Path.Combine(OS.GetWindowsDirectory(), @"SysNative\dism.exe"), Params); + } + private static string InstallWebViaServerManagerCmd(params string[] Features) + { + var Params = string.Format("-install {0}", + string.Join(" ", Features) + ); + return RunTool(Path.Combine(OS.GetWindowsDirectory(), @"SysNative\servermanagercmd.exe"), Params); + } + private static string RunTool(string Name, string Params) + { + var ToolProcessInfo = new ProcessStartInfo + { + FileName = Name, + Arguments = Params, + UseShellExecute = false, + RedirectStandardOutput = true, + CreateNoWindow = true, + WindowStyle = ProcessWindowStyle.Hidden + }; + using (var ToolProcess = Process.Start(ToolProcessInfo)) + { + var Result = ToolProcess.StandardOutput.ReadToEnd(); + ToolProcess.WaitForExit(); + return Result; + } } } } diff --git a/WebsitePanel.Installer/Sources/WebsitePanel.WIXInstaller/CustomAction.cs b/WebsitePanel.Installer/Sources/WebsitePanel.WIXInstaller/CustomAction.cs index d9c553dc..2f652068 100644 --- a/WebsitePanel.Installer/Sources/WebsitePanel.WIXInstaller/CustomAction.cs +++ b/WebsitePanel.Installer/Sources/WebsitePanel.WIXInstaller/CustomAction.cs @@ -53,6 +53,45 @@ namespace WebsitePanel.WIXInstaller public const string CustomDataDelimiter = "-=del=-"; #region CustomActions + [CustomAction] + public static ActionResult InstallWebFeatures(Session session) + { + var Msg = string.Empty; + var Ctx = session; + Ctx.AttachToSetupLog(); + var Result = ActionResult.Success; + try + { + Log.WriteStart("InstallWebFeatures"); + if(Tool.GetIsWebRoleInstalled()) + { + if (!Tool.GetIsWebFeaturesInstalled()) + { + Log.WriteInfo("InstallWebFeatures: ASP.NET."); + Tool.InstallWebFeatures(out Msg); + } + } + else + { + var Tmp = string.Empty; + Log.WriteInfo("InstallWebFeatures: IIS and ASP.NET."); + Tool.InstallWebRole(out Tmp); + Msg += Tmp; + Tool.InstallWebFeatures(out Tmp); + Msg += Tmp; + } + Log.WriteInfo("InstallWebFeatures: done."); + } + catch(Exception ex) + { + Log.WriteError(string.Format("InstallWebFeatures: fail - {0}.", ex.ToString())); + Result = ActionResult.Failure; + } + if(!string.IsNullOrWhiteSpace(Msg)) + Log.WriteInfo(string.Format("InstallWebFeatures Tool Log: {0}.", Msg)); + Log.WriteEnd("InstallWebFeatures"); + return Result; + } // Install. [CustomAction] public static ActionResult OnServerInstall(Session session)