public void Update(ToscaConfigFilesModel config) { IEnumerable <string> appsettingsList = Directory.GetFiles(AppPath, "appsettings.json"); foreach (var appsetting in appsettingsList) { try { Trace.WriteLine("Updating files in AO service"); string json = File.ReadAllText(appsetting); JObject jsonObj = JObject.Parse(json); Trace.WriteLine("---ServiceDiscovery."); UpdateJSONFields.UpdateServiceDiscovery(jsonObj, config, appsetting); Trace.WriteLine("---Scheme."); UpdateJSONFields.UpdateScheme(jsonObj, appsetting); Trace.WriteLine("---HTTPS Thumbprint."); UpdateJSONFields.UpdateCertificate(jsonObj, config, appsetting); Trace.WriteLine("---DexBaseUrl"); UpdateDexBaseUrl(jsonObj, config, appsetting); string output = JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented); File.WriteAllText(appsetting, output); UpdatedFilesCount++; Updated = true; } catch (Exception) { Trace.WriteLine("Failed to updated file at " + AppPath); } } }
public static void UpdateBaseUrl(JObject jsonObj, ToscaConfigFilesModel config, string appsetting) { try { jsonObj["AdminConsoleSettings"]["BaseUrl"] = config.Hostname; } catch (Exception) { Trace.WriteLine(appsetting + " does not have json field 'AdminConsoleSettings/BaseUrl'"); } }
public static void UpdateCertificate(JObject jsonObj, ToscaConfigFilesModel config, string appsetting) { try { jsonObj["HttpServer"]["Endpoints"]["Https"]["Thumbprint"] = config.GetCertificate.GetCertificateThumbprint(); jsonObj["HttpServer"]["Endpoints"]["Https"]["StoreName"] = config.GetCertificate.GetCertificateStoreName(); jsonObj["HttpServer"]["Endpoints"]["Https"]["StoreLocation"] = config.GetCertificate.GetCertificateStoreLocation(); } catch (Exception) { Trace.WriteLine(appsetting + " file doesn't contain 'HttpServer/Endpoints/Https/(Thumbprint|StoreName|StoreLocation)'"); } }
public static void UpdateTokenCertificate(JObject jsonObj, ToscaConfigFilesModel config) { try { jsonObj["TokenSignCertificate"]["Thumbprint"] = config.GetCertificate.GetCertificateThumbprint(); jsonObj["TokenSignCertificate"]["StoreName"] = config.GetCertificate.GetCertificateStoreName(); jsonObj["TokenSignCertificate"]["StoreLocation"] = config.GetCertificate.GetCertificateStoreLocation(); } catch (Exception) { throw; } }
public static void UpdateServiceDiscovery(JObject jsonObj, ToscaConfigFilesModel config, string appsetting) { try { var value = (string)jsonObj["Discovery"]["ServiceDiscovery"]; string[] sd = value.Split(':'); var endpoint = @"https://" + config.Hostname + ":" + sd[2]; jsonObj["Discovery"]["ServiceDiscovery"] = endpoint; } catch (Exception) { Trace.WriteLine(appsetting + " file doesn't contain 'Discovery/ServiceDiscovery'"); } }
public static void UpdateHost(JObject jsonObj, ToscaConfigFilesModel config, string appsetting) { try { var endpointsArray = jsonObj["Discovery"]["Endpoints"]; foreach (var endpoint in endpointsArray) { endpoint["Host"] = config.Hostname; } } catch (Exception) { Trace.WriteLine(appsetting + " doesn't contain 'Discovery/Endpoints'"); } }
public void Update(ToscaConfigFilesModel config) { Trace.WriteLine("REST API Update:"); XmlDocument doc; var exeConfig = string.Empty; try { exeConfig = AppPath + @"\web.config"; doc = new XmlDocument(); doc.Load(exeConfig); } catch (Exception) { Trace.WriteLine("web.config file not found at" + exeConfig); return; } try { //1. var binding = doc.SelectSingleNode("/configuration/system.serviceModel/services/service/endpoint").Attributes["bindingConfiguration"]; binding.Value = "https"; } catch (Exception) { Trace.WriteLine("Exception changing binding to 'https'"); throw; } using (FileStream fs = File.Open(exeConfig, FileMode.Create, FileAccess.Write)) { try { doc.Save(fs); UpdatedFilesCount++; Updated = true; } catch (Exception) { Trace.WriteLine("Exception saving REST API web.config"); throw; } } }
public static void UpdateCORS(ref XmlDocument xmlObj, ToscaConfigFilesModel config, string webconfig) { try { var corsNode = xmlObj.SelectSingleNode("//add[@name='Content-Security-Policy']"); //var corsValue = xmlObj.SelectSingleNode("/configuration/system.webServer/httpProtocol/customHeaders/add").Attributes["value"]; var newCorsValue = @"default-src " + config.Hostname + @":* 'self' 'unsafe-inline';frame-src " + config.Hostname + @":* 'self' localhost:*; connect-src " + config.Hostname + @":* 'self' localhost:*; script-src 'self' 'unsafe-inline' https://ajax.googleapis.com https://maxcdn.bootstrapcdn.com"; corsNode.Attributes["value"].Value = newCorsValue; xmlObj.Save(webconfig); } catch (Exception) { Trace.WriteLine(webconfig + " XML error while adding value"); } }
public void Update(ToscaConfigFilesModel config) { try { IEnumerable <string> appsettingsList = Directory.GetFiles(AppPath, "appsettings.json"); foreach (var appsetting in appsettingsList) { Trace.WriteLine($"Updating files in {appsetting}"); string json = File.ReadAllText(appsetting); JObject jsonObj = JObject.Parse(json); Trace.WriteLine("---ServiceDiscovery."); UpdateJSONFields.UpdateServiceDiscovery(jsonObj, config, appsetting); string output = JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented); File.WriteAllText(appsetting, output); UpdatedFilesCount++; } } catch (Exception) { Trace.WriteLine("Failed to updated file at " + AppPath); } //update web.config var webconfig = AppPath + @"\web.config"; XmlDocument doc = new XmlDocument(); try { doc.Load(AppPath + @"\web.config"); Trace.WriteLine("---CORS."); UpdateXMLFields.UpdateCORS(ref doc, config, webconfig); using (FileStream fs = File.Open(AppPath + @"\Web.config", FileMode.Create, FileAccess.Write)) { doc.Save(fs); UpdatedFilesCount++; Updated = true; } } catch (Exception) { Trace.WriteLine("Unable to update file at " + AppPath + @"\Web.config"); } }
public void UpdateDexBaseUrl(JObject jsonObj, ToscaConfigFilesModel config, string appsetting) { try { if (string.IsNullOrEmpty(config.DexServerPort)) { jsonObj["AutomationObjectServiceConfig"]["DexBaseUrl"] = @"https://" + config.Hostname; } else { jsonObj["AutomationObjectServiceConfig"]["DexBaseUrl"] = @"https://" + config.Hostname + ":" + config.DexServerPort; } } catch (Exception) { Trace.WriteLine(appsetting + " file doesn't contain 'AutomationObjectServiceConfig/DexBaseUrl'"); } }
private void UpdateDataXml(string appPath, ToscaConfigFilesModel config) { XmlDocument doc; var dataxml = string.Empty; //update web.config try { appPath = appPath.Replace("AuthenticationService", "LandingPage"); dataxml = appPath + @"\resources\data\data.xml"; doc = new XmlDocument(); doc.Load(dataxml); //doc.Load(@"C:\Program Files (x86)\TRICENTIS\Tosca Server\DEXServer\Web.config"); } catch (Exception) { Trace.WriteLine("Web.config file not found at" + AppPath + @"\Web.config"); return; } try { var hostname = doc.SelectSingleNode("/features/feature/url"); var split = hostname.InnerText.Split(":"); hostname.InnerText = "https://" + config.Hostname + ":" + split[2]; } catch (Exception) { Trace.WriteLine("Rdp Server endpoint node '/configuration/system.serviceModel/client/endpoint/address'not found in DEX Server web.config"); return; } using (FileStream fs = File.Open(dataxml, FileMode.Create, FileAccess.Write)) { doc.Save(fs); UpdatedFilesCount++; Updated = true; } }
public void Update(ToscaConfigFilesModel config) { //update web.config var webconfig = AppPath + @"\web.config"; XmlDocument doc = new XmlDocument(); try { doc.Load(AppPath + @"\web.config"); Trace.WriteLine("---CORS."); UpdateXMLFields.UpdateCORS(ref doc, config, webconfig); using (FileStream fs = File.Open(AppPath + @"\Web.config", FileMode.Create, FileAccess.Write)) { doc.Save(fs); UpdatedFilesCount++; Updated = true; } } catch (Exception) { Trace.WriteLine("Unable to update file at " + AppPath + @"\Web.config"); } }
public BaseFileUpdateHandler(IGetInstallationDirectories getToscaServerDirectories, ToscaConfigFilesModel config) { _updateFilesBehaviorList = new List <IUpdateFilesBehavior>(); _getDirectoriesBehavior = getToscaServerDirectories; _config = config; }
public void Update(ToscaConfigFilesModel config) { Trace.WriteLine("RdpServer Update:"); XmlDocument doc; var exeConfig = string.Empty; try { exeConfig = AppPath + @"\ToscaRdpServer.exe.config"; doc = new XmlDocument(); doc.Load(exeConfig); } catch (Exception) { Trace.WriteLine("exe.config file not found at" + exeConfig); return; } try { //1. var binding = doc.SelectSingleNode("/configuration/system.serviceModel/services/service/endpoint").Attributes["bindingConfiguration"]; binding.Value = "RdpSlaveServiceBinding"; //2. var rdpEndpoint = doc.SelectSingleNode("/configuration/system.serviceModel/services/service/host/baseAddresses/add").Attributes["baseAddress"]; var split = rdpEndpoint.Value.Split(":"); var newRdpEndpoint = split[1] = @"https://" + config.Hostname + ":" + split[2]; rdpEndpoint.Value = newRdpEndpoint; var baseAddress = doc.SelectSingleNode("/configuration/system.serviceModel/client/endpoint").Attributes["address"]; split = baseAddress.Value.Split("/"); split[0] = "https:"; split[2] = (string.IsNullOrEmpty(config.DexServerPort)) ? config.Hostname : config.Hostname + ":" + config.DexServerPort; var newBaseAddress = string.Empty; for (var i = 0; i < split.Length; i++) { if (i < split.Length - 1) { newBaseAddress += split[i] + "/"; } else { newBaseAddress += split[i]; } } baseAddress.Value = newBaseAddress; //3. if (doc.SelectSingleNode("/configuration/system.serviceModel/behaviors/serviceBehaviors/behavior/serviceMetadata").Attributes["httpsGetEnabled"] == null) { XmlAttribute httpsAttr = doc.CreateAttribute("httpsGetEnabled"); httpsAttr.Value = "true"; XmlNode httpsGetEnableNode = doc.SelectSingleNode("/configuration/system.serviceModel/behaviors/serviceBehaviors/behavior/serviceMetadata"); httpsGetEnableNode.Attributes.Append(httpsAttr); } //4. doc.SelectSingleNode("/configuration/system.serviceModel/bindings/basicHttpBinding/binding/security").Attributes["mode"].Value = "Transport"; if (doc.SelectSingleNode("//binding[@name='BasicHttpBinding_IRdpMasterService']/security") == null) { XmlElement security = doc.CreateElement("security"); security.SetAttribute("mode", "Transport"); var node = doc.SelectSingleNode("//binding[@name='BasicHttpBinding_IRdpMasterService']"); node.AppendChild(security); } //5. Bind cert to port BackgroundWorker worker_SslCert = new BackgroundWorker(); worker_SslCert.WorkerReportsProgress = false; worker_SslCert.DoWork += DoAsyncSslCertBinding; worker_SslCert.RunWorkerAsync(argument: config.CertThumbprint); } catch (Exception) { Trace.WriteLine("Exception binding rdp certificate"); return; } using (FileStream fs = File.Open(exeConfig, FileMode.Create, FileAccess.Write)) { try { doc.Save(fs); UpdatedFilesCount++; Updated = true; } catch (Exception) { Trace.WriteLine("Exception saving ToscaRdpServer.exe.config"); return; } } }
public void Update(ToscaConfigFilesModel config) { XmlDocument doc; var exeConfig = AppPath + @"\ToscaDistributionAgent.exe.config"; Trace.WriteLine($"Updating config at {exeConfig}"); try { doc = new XmlDocument(); doc.Load(exeConfig); } catch (Exception) { Trace.WriteLine("exe.config file not found at " + exeConfig); return; } try { if (config.Hostname != null) { var address = doc.SelectSingleNode("/configuration/system.serviceModel/client/endpoint").Attributes["address"]; var split = address.Value.Split("/"); split[0] = "https:"; split[2] = (string.IsNullOrEmpty(config.DexServerPort)) ? config.Hostname : config.Hostname + ":" + config.DexServerPort; var newAddress = string.Empty; for (int i = 0; i < split.Length; i++) { if (i < split.Length - 1) { newAddress += split[i] + "/"; } else { newAddress += split[i]; } } address.Value = newAddress; } } catch (Exception) { Trace.WriteLine("Agent address node '/configuration/system.serviceModel/client/endpoint/address'not found in Agent exe.config"); } try { doc.SelectSingleNode("/configuration/system.serviceModel/bindings/basicHttpBinding/binding/security").Attributes["mode"].Value = "Transport"; } catch (Exception) { Trace.WriteLine("Agent address node '/configuration/system.serviceModel/bindings/basicHttpBinding/binding/security' not found in Agent exe.config"); } using (FileStream fs = File.Open(exeConfig, FileMode.Create, FileAccess.Write)) { doc.Save(fs); UpdatedFilesCount++; } Updated = true; }
public void Update(ToscaConfigFilesModel config) { throw new NotImplementedException(); }
//Constructor public ToscaConfigFilesViewModel() { _ToscaConfigFilesModel = new ToscaConfigFilesModel(); }
public void Update(ToscaConfigFilesModel config) { XmlDocument doc; //update web.config try { var webconfig = AppPath + @"\web.config"; doc = new XmlDocument(); doc.Load(webconfig); //doc.Load(@"C:\Program Files (x86)\TRICENTIS\Tosca Server\DEXServer\Web.config"); } catch (Exception) { Trace.WriteLine("Web.config file not found at" + AppPath + @"\Web.config"); return; } try { var rdpEndpoint = doc.SelectSingleNode("/configuration/system.serviceModel/client/endpoint").Attributes["address"]; var split = rdpEndpoint.Value.Split(":"); var newRdpEndpoint = split[1] = @"https://" + config.Hostname + ":" + split[2]; rdpEndpoint.Value = newRdpEndpoint; } catch (Exception) { Trace.WriteLine("Rdp Server endpoint node '/configuration/system.serviceModel/client/endpoint/address'not found in DEX Server web.config"); return; } try { doc.SelectSingleNode("/configuration/system.serviceModel/bindings/basicHttpBinding/binding/security").Attributes["mode"].Value = "Transport"; doc.SelectSingleNode("/configuration/system.serviceModel/bindings/webHttpBinding/binding/security").Attributes["mode"].Value = "Transport"; } catch (Exception) { return; } try { var baseAddresses = doc.SelectNodes("/configuration/system.serviceModel/services/service/host/baseAddresses/add"); foreach (XmlNode baseAddress in baseAddresses) { var split = baseAddress.Attributes["baseAddress"].Value.Split("/"); split[0] = "https:"; split[2] = (string.IsNullOrEmpty(config.DexServerPort)) ? config.Hostname : config.Hostname + ":" + config.DexServerPort; var newBaseAddress = string.Empty; for (var i = 0; i < split.Length; i++) { if (i < split.Length - 1) { newBaseAddress += split[i] + "/"; } else { newBaseAddress += split[i]; } } baseAddress.Attributes["baseAddress"].Value = newBaseAddress; } } catch (Exception) { Trace.WriteLine("Rdp Server endpoint node '/configuration/system.serviceModel/client/endpoint/address'not found in DEX Server web.config"); return; } try { using (FileStream fs = File.Open(AppPath + @"\Web.config", FileMode.Create, FileAccess.Write)) { doc.Save(fs); UpdatedFilesCount++; Updated = true; } } catch (Exception) { Trace.WriteLine($"Exception when writing file at {AppPath}\\web.config"); throw; } }
public void Update(ToscaConfigFilesModel config) { Trace.WriteLine("License Administration not implemented"); }