public override void Install( IDictionary stateSaver) { // enable the line below to debug this installer; disable otherwise //MessageBox.Show("Attach the .NET debugger to the 'MSI Debug' msiexec.exe process now for debug. Click OK when ready...", "MSI Debug"); // if the installer is running in repair mode, it will try to re-install Myrtille... which is fine // problem is, it won't uninstall it first... which is not fine because some components can't be installed twice! // thus, prior to any install, try to uninstall first Context.LogMessage("Myrtille.Web is being installed, cleaning first"); try { Uninstall(null); } catch (Exception exc) { Context.LogMessage(string.Format("Failed to clean Myrtille.Web ({0})", exc)); } Context.LogMessage("Installing Myrtille.Web"); base.Install(stateSaver); try { // register Myrtille.Web to local IIS if (!IISHelper.IsIISApplicationPoolExists("MyrtilleAppPool")) { IISHelper.CreateIISApplicationPool("MyrtilleAppPool", "v4.0"); } if (!IISHelper.IsIISApplicationExists("/Myrtille")) { IISHelper.CreateIISApplication("/Myrtille", Path.GetFullPath(Context.Parameters["targetdir"]), "MyrtilleAppPool"); } // load config var config = new XmlDocument(); var configPath = Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "Web.config"); config.Load(configPath); var navigator = config.CreateNavigator(); // services port int servicesPort = 8080; if (!string.IsNullOrEmpty(Context.Parameters["SERVICESPORT"])) { int.TryParse(Context.Parameters["SERVICESPORT"], out servicesPort); } if (servicesPort != 8080) { // client endpoints var client = XmlTools.GetNode(navigator, "/configuration/system.serviceModel/client"); if (client != null) { client.InnerXml = client.InnerXml.Replace("8080", servicesPort.ToString()); } } // ssl certificate if (!string.IsNullOrEmpty(Context.Parameters["SSLCERT"])) { // create a self signed certificate var cert = CertificateHelper.CreateSelfSignedCertificate(Environment.MachineName, "Myrtille self-signed certificate"); // bind it to the default website IISHelper.BindCertificate(cert); } // pdf printer var appSettings = XmlTools.GetNode(navigator, "/configuration/appSettings"); if (appSettings != null) { XmlTools.WriteConfigKey(appSettings, "AllowPrintDownload", (!string.IsNullOrEmpty(Context.Parameters["PDFPRINTER"])).ToString().ToLower()); } // save config config.Save(configPath); // add write permission to the targetdir "log" folder for MyrtilleAppPool, so that Myrtille.Web can save logs into it PermissionsHelper.AddDirectorySecurity( Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "log"), "IIS AppPool\\MyrtilleAppPool", FileSystemRights.Write, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); Context.LogMessage("Installed Myrtille.Web"); } catch (Exception exc) { Context.LogMessage(string.Format("Failed to install Myrtille.Web ({0})", exc)); throw; } }
public override void Install( IDictionary stateSaver) { // enable the line below to debug this installer; disable otherwise //MessageBox.Show("Attach the .NET debugger to the 'MSI Debug' msiexec.exe process now for debug. Click OK when ready...", "MSI Debug"); // if the installer is running in repair mode, it will try to re-install Myrtille... which is fine // problem is, it won't uninstall it first... which is not fine because some components can't be installed twice! // thus, prior to any install, try to uninstall first Context.LogMessage("Myrtille.Web is being installed, cleaning first"); try { Uninstall(null); } catch (Exception exc) { Context.LogMessage(string.Format("Failed to clean Myrtille.Web ({0})", exc)); } Context.LogMessage("Installing Myrtille.Web"); base.Install(stateSaver); try { // register Myrtille.Web to local IIS if (!IISHelper.IsIISApplicationPoolExists("MyrtilleAppPool")) { IISHelper.CreateIISApplicationPool("MyrtilleAppPool", "v4.0"); } if (!IISHelper.IsIISApplicationExists("/Myrtille")) { IISHelper.CreateIISApplication("/Myrtille", Path.GetFullPath(Context.Parameters["targetdir"]), "MyrtilleAppPool"); } // load config var config = new XmlDocument(); var configPath = Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "Web.config"); config.Load(configPath); var navigator = config.CreateNavigator(); // services port int servicesPort = 8080; if (!string.IsNullOrEmpty(Context.Parameters["SERVICESPORT"])) { int.TryParse(Context.Parameters["SERVICESPORT"], out servicesPort); } if (servicesPort != 8080) { // client endpoints var client = XmlTools.GetNode(navigator, "/configuration/system.serviceModel/client"); if (client != null) { client.InnerXml = client.InnerXml.Replace("8080", servicesPort.ToString()); } } // admin services port int adminServicesPort = 8008; if (!string.IsNullOrEmpty(Context.Parameters["ADMINSERVICESPORT"])) { int.TryParse(Context.Parameters["ADMINSERVICESPORT"], out adminServicesPort); } if (adminServicesPort != 8008) { // application settings var settings = XmlTools.GetNode(navigator, "/configuration/applicationSettings/Myrtille.Web.Properties.Settings"); if (settings != null) { settings.InnerXml = settings.InnerXml.Replace("8008", adminServicesPort.ToString()); } } // ssl certificate if (!string.IsNullOrEmpty(Context.Parameters["SSLCERT"])) { // create a self signed certificate var cert = CertificateHelper.CreateSelfSignedCertificate(Environment.MachineName, "Myrtille self-signed certificate"); // bind it to the default website IISHelper.BindCertificate(cert); } // pdf printer var appSettings = XmlTools.GetNode(navigator, "/configuration/appSettings"); if (appSettings != null) { XmlTools.WriteConfigKey(appSettings, "AllowPrintDownload", (!string.IsNullOrEmpty(Context.Parameters["PDFPRINTER"])).ToString().ToLower()); } // connection api if (!string.IsNullOrEmpty(Context.Parameters["CONNECTIONAPI"])) { var systemWeb = XmlTools.GetNode(navigator, "/configuration/system.web"); if (systemWeb != null) { XmlNode sessionStateUseUri = null; XmlNode sessionStateUseCookies = null; foreach (XmlNode node in systemWeb.ChildNodes) { // session state // the connection api is likely to be used with iframes // as for multiple connections/tabs, Myrtille must be configured in cookieless mode if (node is XmlComment && node.Value.StartsWith("<sessionState") && node.Value.Contains("cookieless=\"UseUri\"")) { sessionStateUseUri = node; } else if (node.Name == "sessionState" && node.OuterXml.Contains("cookieless=\"UseCookies\"")) { sessionStateUseCookies = node; } } // uncomment cookieless="UseUri" if (sessionStateUseUri != null) { var nodeReader = XmlReader.Create(new StringReader(sessionStateUseUri.Value)); var uncommentedNode = config.ReadNode(nodeReader); systemWeb.ReplaceChild(uncommentedNode, sessionStateUseUri); } // comment cookieless="UseCookies" if (sessionStateUseCookies != null) { var commentContent = sessionStateUseCookies.OuterXml; var commentedNode = config.CreateComment(commentContent); systemWeb.ReplaceChild(commentedNode, sessionStateUseCookies); } } } // save config config.Save(configPath); // add write permission to the targetdir "log" folder for MyrtilleAppPool, so that Myrtille.Web can save logs into it PermissionsHelper.AddDirectorySecurity( Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "log"), "IIS AppPool\\MyrtilleAppPool", FileSystemRights.Write, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); Context.LogMessage("Installed Myrtille.Web"); } catch (Exception exc) { Context.LogMessage(string.Format("Failed to install Myrtille.Web ({0})", exc)); throw; } }
public override void Install( IDictionary stateSaver) { // enable the line below to debug this installer; disable otherwise //MessageBox.Show("Attach the .NET debugger to the 'MSI Debug' msiexec.exe process now for debug. Click OK when ready...", "MSI Debug"); // if the installer is running in repair mode, it will try to re-install Myrtille... which is fine // problem is, it won't uninstall it first... which is not fine because some components can't be installed twice! // thus, prior to any install, try to uninstall first Trace.TraceInformation("Myrtille.Web is being installed, cleaning first"); try { Uninstall(null); } catch (Exception exc) { Trace.TraceInformation("Failed to clean Myrtille.Web ({0})", exc); } base.Install(stateSaver); Trace.TraceInformation("Installing Myrtille.Web"); try { Process process = null; // register Myrtille.Web to local IIS if (!IISHelper.IsIISApplicationPoolExists("MyrtilleAppPool")) { IISHelper.CreateIISApplicationPool("MyrtilleAppPool", "v4.0"); } if (!IISHelper.IsIISApplicationExists("/Myrtille")) { IISHelper.CreateIISApplication("/Myrtille", Path.GetFullPath(Context.Parameters["targetdir"]), "MyrtilleAppPool"); } // add write permission to the targetdir "log" folder for MyrtilleAppPool, so that Myrtille.Web can save logs into it PermissionsHelper.AddDirectorySecurity( Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "log"), "IIS AppPool\\MyrtilleAppPool", FileSystemRights.Write, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); // create a default rdp user (myrtille) on the local server AccountHelper.CreateLocalUser( "Myrtille", "Myrtille User", "/Passw1rd/", true, true); // add myrtille to the windows users group AccountHelper.AddLocalUserToGroup( "Myrtille", AccountHelper.GetUsersGroupName()); // add myrtille to the remote desktop users group AccountHelper.AddLocalUserToGroup( "Myrtille", AccountHelper.GetRemoteDesktopUsersGroupName()); // import the rdp registry keys required by myrtille on the local server process = new Process(); #if !DEBUG process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; #endif process.StartInfo.FileName = "regedit.exe"; process.StartInfo.Arguments = "/s \"" + Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "RDPSetup.reg") + "\""; process.Start(); Trace.TraceInformation("Installed Myrtille.Web"); } catch (Exception exc) { Context.LogMessage(exc.InnerException != null ? exc.InnerException.Message: exc.Message); Trace.TraceError("Failed to install Myrtille.Web ({0})", exc); throw; } }
public override void Install( IDictionary stateSaver) { // enable the line below to debug this installer; disable otherwise //MessageBox.Show("Attach the .NET debugger to the 'MSI Debug' msiexec.exe process now for debug. Click OK when ready...", "MSI Debug"); // if the installer is running in repair mode, it will try to re-install Myrtille... which is fine // problem is, it won't uninstall it first... which is not fine because some components can't be installed twice! // thus, prior to any install, try to uninstall first Trace.TraceInformation("Myrtille.Web is being installed, cleaning first"); try { Uninstall(null); } catch (Exception exc) { Trace.TraceInformation("Failed to clean Myrtille.Web ({0})", exc); } base.Install(stateSaver); Trace.TraceInformation("Installing Myrtille.Web"); try { // register Myrtille.Web to local IIS if (!IISHelper.IsIISApplicationPoolExists("MyrtilleAppPool")) { IISHelper.CreateIISApplicationPool("MyrtilleAppPool", "v4.0"); } if (!IISHelper.IsIISApplicationExists("/Myrtille")) { IISHelper.CreateIISApplication("/Myrtille", Path.GetFullPath(Context.Parameters["targetdir"]), "MyrtilleAppPool"); } // create a self signed certificate var cert = CertificateHelper.CreateSelfSignedCertificate(Environment.MachineName, "Myrtille self-signed certificate"); // bind it to the default website IISHelper.BindCertificate(cert); // add write permission to the targetdir "log" folder for MyrtilleAppPool, so that Myrtille.Web can save logs into it PermissionsHelper.AddDirectorySecurity( Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "log"), "IIS AppPool\\MyrtilleAppPool", FileSystemRights.Write, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); Trace.TraceInformation("Installed Myrtille.Web"); } catch (Exception exc) { Context.LogMessage(exc.InnerException != null ? exc.InnerException.Message: exc.Message); Trace.TraceError("Failed to install Myrtille.Web ({0})", exc); throw; } }
public override void Install( IDictionary stateSaver) { // enable the line below to debug this installer; disable otherwise //MessageBox.Show("Attach the .NET debugger to the 'MSI Debug' msiexec.exe process now for debug. Click OK when ready...", "MSI Debug"); // if the installer is running in repair mode, it will try to re-install Myrtille... which is fine // problem is, it won't uninstall it first... which is not fine because some components can't be installed twice! // thus, prior to any install, try to uninstall first Context.LogMessage("Myrtille.Web is being installed, cleaning first"); try { Uninstall(null); } catch (Exception exc) { Context.LogMessage(string.Format("Failed to clean Myrtille.Web ({0})", exc)); } Context.LogMessage("Installing Myrtille.Web"); base.Install(stateSaver); try { var process = new Process(); bool debug = true; #if !DEBUG debug = false; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; #endif // the install.ps1 (powershell) script enable the myrtille prerequisites (IIS, .NET, websocket, WCF/HTTP activation, etc.), // create a self-signed certificate (if requested), an application pool and a web application for myrtille, etc. // it can be adapted and run manually outside of this installer, if needed // its output is logged under <install path>\log\install.log process.StartInfo.FileName = string.Format(@"{0}\WindowsPowerShell\v1.0\powershell.exe", Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess ? Environment.SystemDirectory.ToLower().Replace("system32", "sysnative") : Environment.SystemDirectory); process.StartInfo.Arguments = "-ExecutionPolicy Bypass" + " -Command \"& '" + Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "Myrtille.Web.Install.ps1") + "'" + " -InstallPath '" + Path.GetFullPath(Context.Parameters["targetdir"]) + "'" + " -SslCert " + (!string.IsNullOrEmpty(Context.Parameters["SSLCERT"]) ? "1" : "0") + " -DebugMode " + (debug ? "1" : "0") + " | Tee-Object -FilePath '" + Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "log", "Myrtille.Web.Install.log") + "'" + "\""; process.Start(); process.WaitForExit(); if (process.ExitCode != 0) { throw new Exception(string.Format("An error occured while running {0}. See {1} for more information.", Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "Myrtille.Web.Install.ps1"), Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "log", "Myrtille.Web.Install.log"))); } // load config var config = new XmlDocument(); var configPath = Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "Web.config"); config.Load(configPath); var navigator = config.CreateNavigator(); // services port int servicesPort = 8080; if (!string.IsNullOrEmpty(Context.Parameters["SERVICESPORT"])) { int.TryParse(Context.Parameters["SERVICESPORT"], out servicesPort); } if (servicesPort != 8080) { // client endpoints var client = XmlTools.GetNode(navigator, "/configuration/system.serviceModel/client"); if (client != null) { client.InnerXml = client.InnerXml.Replace("8080", servicesPort.ToString()); } } // admin services port int adminServicesPort = 8008; if (!string.IsNullOrEmpty(Context.Parameters["ADMINSERVICESPORT"])) { int.TryParse(Context.Parameters["ADMINSERVICESPORT"], out adminServicesPort); } if (adminServicesPort != 8008) { // application settings var settings = XmlTools.GetNode(navigator, "/configuration/applicationSettings/Myrtille.Web.Properties.Settings"); if (settings != null) { settings.InnerXml = settings.InnerXml.Replace("8008", adminServicesPort.ToString()); } } // pdf printer var appSettings = XmlTools.GetNode(navigator, "/configuration/appSettings"); if (appSettings != null) { XmlTools.WriteConfigKey(appSettings, "AllowPrintDownload", (!string.IsNullOrEmpty(Context.Parameters["PDFPRINTER"])).ToString().ToLower()); } // http session state // the default mode into web.config is cookieless="UseUri" // if this should change, reverse the code below if (string.IsNullOrEmpty(Context.Parameters["SESSIONURL"])) { var systemWeb = XmlTools.GetNode(navigator, "/configuration/system.web"); if (systemWeb != null) { XmlNode sessionStateUseUri = null; XmlNode sessionStateUseCookies = null; foreach (XmlNode node in systemWeb.ChildNodes) { // http session id passed into url // allows multiple connections/tabs or iframes if (node is XmlElement && node.Name == "sessionState" && node.OuterXml.Contains("cookieless=\"UseUri\"")) { sessionStateUseUri = node; } // http session id stored into a cookie // same connection for all tabs because a cookie is set for a domain else if (node is XmlComment && node.Value.StartsWith("<sessionState") && node.Value.Contains("cookieless=\"UseCookies\"")) { sessionStateUseCookies = node; } } // comment cookieless="UseUri" if (sessionStateUseUri != null) { XmlTools.CommentNode(config, systemWeb, sessionStateUseUri); } // uncomment cookieless="UseCookies" if (sessionStateUseCookies != null) { XmlTools.UncommentNode(config, systemWeb, sessionStateUseCookies); } } } // save config config.Save(configPath); // add write permission to the targetdir "log" folder for MyrtilleAppPool, so that Myrtille.Web can save logs into it PermissionsHelper.AddDirectorySecurity( Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "log"), "IIS AppPool\\MyrtilleAppPool", FileSystemRights.Write, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); Context.LogMessage("Installed Myrtille.Web"); } catch (Exception exc) { Context.LogMessage(string.Format("Failed to install Myrtille.Web ({0})", exc)); throw; } }
public override void Install( IDictionary stateSaver) { // enable the line below to debug this installer; disable otherwise //MessageBox.Show("Attach the .NET debugger to the 'MSI Debug' msiexec.exe process now for debug. Click OK when ready...", "MSI Debug"); // if the installer is running in repair mode, it will try to re-install Myrtille... which is fine // problem is, it won't uninstall it first... which is not fine because some components can't be installed twice! // thus, prior to any install, try to uninstall first Trace.TraceInformation("Myrtille.Web is being installed, cleaning first"); try { Uninstall(null); } catch (Exception exc) { Trace.TraceInformation("Failed to clean Myrtille.Web ({0})", exc); } base.Install(stateSaver); Trace.TraceInformation("Installing Myrtille.Web"); try { // register Myrtille.Web to local IIS if (!IISHelper.IsIISApplicationPoolExists("MyrtilleAppPool")) { IISHelper.CreateIISApplicationPool("MyrtilleAppPool", "v4.0"); } if (!IISHelper.IsIISApplicationExists("/Myrtille")) { IISHelper.CreateIISApplication("/Myrtille", Path.GetFullPath(Context.Parameters["targetdir"]), "MyrtilleAppPool"); } // create a self signed certificate var cert = CertificateHelper.CreateSelfSignedCertificate(Environment.MachineName, "Myrtille self-signed certificate"); // bind it to the default website IISHelper.BindCertificate(cert); // export it to the targetdir "ssl" folder, for secure websocket communication var certBytes = cert.Export(X509ContentType.Pfx, ""); File.WriteAllBytes(Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "ssl", "PKCS12Cert.pfx"), certBytes); // add write permission to the targetdir "log" folder for MyrtilleAppPool, so that Myrtille.Web can save logs into it PermissionsHelper.AddDirectorySecurity( Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "log"), "IIS AppPool\\MyrtilleAppPool", FileSystemRights.Write, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); // websockets ports int wsPort; if (!int.TryParse(Context.Parameters["WSPort"], out wsPort)) { wsPort = 8181; } int wssPort; if (!int.TryParse(Context.Parameters["WSSPort"], out wssPort)) { wssPort = 8431; } // load config var config = new XmlDocument(); var configPath = Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "Web.config"); config.Load(configPath); // update settings var navigator = config.CreateNavigator(); var node = XmlTools.GetNode(navigator, "/configuration/appSettings"); if (node != null) { XmlTools.WriteConfigKey(node, "WebSocketServerPort", wsPort.ToString()); XmlTools.WriteConfigKey(node, "WebSocketServerPortSecured", wssPort.ToString()); } // save config config.Save(configPath); // open ports FirewallHelper.OpenFirewallPort(wsPort, "Myrtille Websockets"); FirewallHelper.OpenFirewallPort(wssPort, "Myrtille Websockets Secured"); Trace.TraceInformation("Installed Myrtille.Web"); } catch (Exception exc) { Context.LogMessage(exc.InnerException != null ? exc.InnerException.Message: exc.Message); Trace.TraceError("Failed to install Myrtille.Web ({0})", exc); throw; } }