public static I CreateInstance <S, I, C>(InstanceContext <C> context) where I : class where S : class, I { HostRecord hostRecord = GetHostRecord <S, I>(); return(DuplexChannelFactory <I, C> .CreateChannel(context, Binding, hostRecord.Address)); }
public static I CreateInstance <S, I>() where I : class where S : class, I { HostRecord hostRecord = GetHostRecord <S, I>(); ChannelFactory <I> factory = new ChannelFactory <I>(Binding, hostRecord.Address); return(factory.CreateChannel()); }
public async Task <HostRecord> CreateHostRecordAsync(string HostName, string Ipv4Address, string HostMac = null) { // https://10.10.10.10/wapi/v2.9/record:host //Validations (4) // This area perform validations to the information provided to the function. // Check#1 - Validate input to ensure that thereis a hostname and an Ipv4Address if (String.IsNullOrEmpty(HostName) || string.IsNullOrEmpty(Ipv4Address)) { return(default(HostRecord)); } // Check#2 - Ensure that the host is not already in the DNS registry var hostAlreadyExists = await GetHostRecordAsync(HostName); if (hostAlreadyExists != null) { return(hostAlreadyExists); //record for that hostname already exists, return the existing record } // Check#3 - Validate the ipV4 address sent is a valid IP address if ((NetworkUtilities.ParseSingleIPv4Address(Ipv4Address).Value.ToString()) != Ipv4Address) { throw new ArgumentException($"The value of {Ipv4Address} is invalid. Check your values and try again."); } // Check#4 - Validate the ipV4 address is in one of the managed Ip Subnets in the InfoBlox API if (!IsIpv4AddressInSubnetsRange(Ipv4Address)) { throw new ArgumentException($"The value of {Ipv4Address} is not within the range of the subnets managed by the InfoBlox Grid. Check your values and try again."); } //If everything is good so far... let's go ahead and make us a HostRecord! //Add spices to the recipe //Single line model construct. Pick your poison by uncommenting the chosen method. ;-) //HostRecord newHost = new HostRecord() { Name = HostName, Ipv4Addresses = new Ipv4Address[] { new Ipv4Address() { Value = Ipv4Address } } }; //Multi-line model construct. Pick your poison by uncommenting the chosen method. ;-) HostRecordPost newHost = new HostRecordPost(); newHost.Name = HostName; newHost.Ipv4Addresses = new Ipv4AddressPost[] { new Ipv4AddressPost() { Value = Ipv4Address } }; //return newHost.ToJson(); string apifunction = "record:host"; string apipath = $"{helperConfig.ApiRoute}/{helperConfig.ApiVersion}/{apifunction}"; string requestcontent = newHost.ToJson(); string content = await IBXCallApi(HttpMethod : HttpMethod.Post, ApiFunction : apifunction, ApiPath : apipath, RequestContent : requestcontent); HostRecord createdHostRecord = await GetHostRecordAsync(HostName); return(createdHostRecord); }
public async Task <HostRecord> UpdateHostRecordAsync(string HostName, HostRecordPost changedRecord) { // https://10.10.10.10/wapi/v2.9/record:host //Validations (4) // This area perform validations to the information provided to the function. // Check#1 - Validate input to ensure that thereis a hostname and Host object to update if (String.IsNullOrEmpty(HostName) || (changedRecord is null)) { return(default(HostRecord)); } // Check#2 - Ensure that the host is already in the DNS registry var hostAlreadyExists = await GetHostRecordAsync(HostName); if (hostAlreadyExists is null) { throw new ArgumentException($"The hostname {HostName} is does not exist in the server or is invalid. Check your values and try again."); } // Check#3 - Validate the ipV4 address sent is a valid IP address string ipv4AddressToValidate = changedRecord.Ipv4Addresses[0].Value; if ((NetworkUtilities.ParseSingleIPv4Address(ipv4AddressToValidate).Value.ToString()) != ipv4AddressToValidate) { throw new ArgumentException($"The value of {ipv4AddressToValidate} is invalid. Check your values and try again."); } // Check#4 - Validate the ipV4 address is in one of the managed Ip Subnets in the InfoBlox API if (!IsIpv4AddressInSubnetsRange(ipv4AddressToValidate)) { throw new ArgumentException($"The value of {ipv4AddressToValidate} is not within the range of the subnets managed by the InfoBlox Grid. Check your values and try again."); } //If everything is good so far... let's go ahead and prepare the info for the HostRecord! string apifunction = "record:host"; string refhost = hostAlreadyExists.BaseRef; string apipath = $"{helperConfig.ApiRoute}/{helperConfig.ApiVersion}/{apifunction}/{refhost}"; string requestcontent = changedRecord.ToJson(); string content = await IBXCallApi(HttpMethod : HttpMethod.Put, ApiFunction : apifunction, ApiPath : apipath, RequestContent : requestcontent); HostRecord createdHostRecord = await GetHostRecordAsync(changedRecord.Name); return(createdHostRecord); }
/// <summary> /// 1. If requested host was not declared in configuration just forward peer system response to lClient (Config.SslStrippingConfigByHost) /// 2. If requested Url was detected to be redirected replace scheme, host and randomFileName by the redirection location /// 3. If requested host was flaged to use HTTPS because of HSTS, replace the http:// scheme by https /// </summary> /// <param name="requestObj"></param> /// <returns></returns> public PluginInstruction OnPostClientHeadersRequest(RequestObj requestObj) { var instruction = new PluginInstruction(); instruction.Instruction = Instruction.DoNothing; if (requestObj == null) { throw new ProxyWarningException("The request object is invalid"); } string requestedUrl = $"{requestObj.ProxyProtocol.ToString().ToLower()}://{requestObj.ClientRequestObj.Host}{requestObj.ClientRequestObj.RequestLine.Path}"; // 1. If requested Url was HTML SSL stripped // -> replace "http" by "https" if (this.cacheSslStrip.NeedsRequestBeMapped(requestedUrl) == true) { HostRecord tmpHost = this.cacheSslStrip.GetElement(requestObj.ClientRequestObj.GetRequestedUrl()); requestObj.ProxyProtocol = tmpHost.ProxyProtocol; requestObj.ClientRequestObj.Host = tmpHost.Host; requestObj.ClientRequestObj.RequestLine.Path = tmpHost.Path; Logging.Instance.LogMessage(requestObj.Id, requestObj.ProxyProtocol, Loglevel.Info, "SslStrip.OnPostClientHeadersRequest(): SslStripped from {0} {1} to {2}://{3}{4}", requestObj.ClientRequestObj.RequestLine.MethodString, requestedUrl, tmpHost.ProxyProtocol.ToString().ToLower(), tmpHost.Host, tmpHost.Path); } // 2. If requested Url was detected to be redirected // -> replace "scheme://host/randomFileName" by the redirection location if (this.cacheRedirect.NeedsRequestBeMapped(requestedUrl)) { HostRecord tmpHost = this.cacheRedirect.GetElement(requestObj.ClientRequestObj.GetRequestedUrl()); requestObj.ProxyProtocol = tmpHost.ProxyProtocol; requestObj.ClientRequestObj.Host = tmpHost.Host; requestObj.ClientRequestObj.RequestLine.Path = tmpHost.Path; Logging.Instance.LogMessage(requestObj.Id, requestObj.ProxyProtocol, Loglevel.Info, "SslStrip.OnPostClientHeadersRequest(): HTTP redirect(301/302) from {0} {1} to {2}://{3}{4}", requestObj.ClientRequestObj.RequestLine.MethodString, requestedUrl, tmpHost.ProxyProtocol.ToString().ToLower(), tmpHost.Host, tmpHost.Path); } // 3. If requested host was flaged to use HTTPS because of HSTS // -> replace scheme "http://" by "https://" if (this.cacheHsts.GetElement(requestObj.ClientRequestObj.Host) != null) { Logging.Instance.LogMessage(requestObj.Id, requestObj.ProxyProtocol, Loglevel.Info, "SslStrip.OnPostClientHeadersRequest(): HSTS header set for \"{0}\"", requestObj.ClientRequestObj.Host); requestObj.ProxyProtocol = ProxyProtocol.Https; } return(instruction); }
private HostRecord GetHostRecord <TSERVICE, TINTERFACE> () where TINTERFACE : class where TSERVICE : TINTERFACE { HostRecord hostRecord; if (m_hosts.ContainsKey(typeof(TSERVICE))) { hostRecord = m_hosts[typeof(TSERVICE)]; } else { var host = new ServiceHost(typeof(TSERVICE), BaseAddress); string address = BaseAddress.ToString() + Guid.NewGuid().ToString(); hostRecord = new HostRecord(host, address); m_hosts.Add(typeof(TSERVICE), hostRecord); host.AddServiceEndpoint(typeof(TINTERFACE), Binding, address); host.Open(); }; return(hostRecord); }
public async Task <HostRecord> GetHostRecordAsync(string HostName) { //https://10.10.10.10/wapi/v2.9/record:host?name~=host.url.path if (String.IsNullOrEmpty(HostName)) { return(default(HostRecord)); } string apifunction = "record:host"; string apicommand = $"name~={HostName}"; string apipath = $"{helperConfig.ApiRoute}/{helperConfig.ApiVersion}/{apifunction}"; string content = await IBXCallApi(HttpMethod : HttpMethod.Get, ApiFunction : apifunction, ApiPath : apipath, ApiCommand : apicommand); var returnedHost = HostRecords.FromJson(content); HostRecord host = (from record in returnedHost select record).FirstOrDefault(); return(host); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="keyLocation"></param> /// <param name="valueLocation"></param> public void AddElement(string id, string keyLocation, string valueLocation) { // Key value checks if (!Uri.IsWellFormedUriString(keyLocation, UriKind.Absolute)) { throw new Exception("Key Uri is not well formed"); } var tmpUriKey = new Uri(keyLocation); if (tmpUriKey == null || !Regex.Match(tmpUriKey.Scheme, @"^https?$").Success) { throw new Exception("Key Uri is not well formed"); } // Value URI checks if (!Uri.IsWellFormedUriString(valueLocation, UriKind.Absolute)) { throw new Exception("Value Uri is not well formed"); } var tmpUriValue = new Uri(valueLocation); if (tmpUriValue == null || !Regex.Match(tmpUriValue.Scheme, @"^https?$").Success) { throw new Exception("Value Uri is not well formed"); } if (this.NeedsRequestBeMapped(keyLocation)) { throw new Exception("Key was already added to the cache"); } Logging.Instance.LogMessage(id, ProxyProtocol.Undefined, Loglevel.Debug, "CacheSslStrip.Cache.AddElement(): {0} => {1}", keyLocation, valueLocation); var tmpHost = new HostRecord("GET", ProxyProtocol.Https, tmpUriValue.Host, tmpUriValue.PathAndQuery); this.SslStripCache.Add(keyLocation, tmpHost); }
public async Task <HostRecord> GetHostRecordByIPAddressAsync(string Ipv4Address) { //https://10.10.10.10/wapi/v2.9/ipv4address?status=USED&ip_address=10.10.10.10 HostRecord createdHostRecord = new HostRecord(); if (!String.IsNullOrEmpty(Ipv4Address)) { // Check#2 - Validate the ipV4 address sent is a valid IP address if ((NetworkUtilities.ParseSingleIPv4Address(Ipv4Address).Value.ToString()) != Ipv4Address) { throw new ArgumentException($"The value of {Ipv4Address} is invalid. Check your values and try again."); } // Check#3 - Validate the ipV4 address is in one of the managed Ip Subnets in the InfoBlox API if (!IsIpv4AddressInSubnetsRange(Ipv4Address)) { throw new ArgumentException($"The value of {Ipv4Address} is not within the range of the subnets managed by the InfoBlox Grid. Check your values and try again."); } string apifunction = "ipv4address"; string apicommand = $"status=USED&ip_address={Ipv4Address}"; string apipath = $"{helperConfig.ApiRoute}/{helperConfig.ApiVersion}/{apifunction}"; string content = await IBXCallApi(HttpMethod : HttpMethod.Get, ApiFunction : apifunction, ApiPath : apipath, ApiCommand : apicommand); var returnedSearchResults = IPSearchResults.FromJson(content); if (returnedSearchResults.Count > 0) { string hostname = (from item in returnedSearchResults select item.Names[0]).FirstOrDefault(); createdHostRecord = await GetHostRecordAsync(hostname); } } return(createdHostRecord); }
static HostRecord GetHostRecord <S, I>() where I : class where S : class, I { HostRecord hostRecord; if (m_Hosts.ContainsKey(typeof(S))) { hostRecord = m_Hosts[typeof(S)]; } else { ServiceHost <S> host; if (m_Singletons.ContainsKey(typeof(S))) { S singleton = m_Singletons[typeof(S)] as S; Debug.Assert(singleton != null); host = new ServiceHost <S>(singleton, BaseAddress); } else { host = new ServiceHost <S>(BaseAddress); } string address = BaseAddress.ToString() + Guid.NewGuid().ToString(); hostRecord = new HostRecord(host, address); m_Hosts.Add(typeof(S), hostRecord); host.AddServiceEndpoint(typeof(I), Binding, address); if (m_Throttles.ContainsKey(typeof(S))) { host.SetThrottle(m_Throttles[typeof(S)]); } host.Open(); } return(hostRecord); }
static void Main(string[] args) { Console.WriteLine("Welcome InfoBlox Helper Test Console"); Console.WriteLine(Helper.GetVersion()); var _nets = RetrieveNetworks().Result; Console.WriteLine(JsonConvert.SerializeObject(_nets)); Console.ReadKey(); var _subnet = ibxHelper.GetNetworkAsync("10.128.0.0/24").Result; Console.WriteLine(JsonConvert.SerializeObject(_subnet)); Console.ReadKey(); //RetrieveIP().Wait(); var _ip = RetrieveIP().Result; Console.WriteLine(_ip); Console.ReadKey(); Console.Write("Please enter a name for the host to be created: -> "); Console.WriteLine(); string _hostname = $"{Console.ReadLine()}.url.goes.here"; //Write a Record. HostRecord _newRecord = AddNewRecord(_hostname).Result; Console.WriteLine(JsonConvert.SerializeObject(_newRecord)); Console.ReadKey(); //Read a host record. HostRecord _retrieveRecord = GetHostRecord(_hostname).Result; Console.WriteLine(JsonConvert.SerializeObject(_retrieveRecord)); Console.ReadKey(); //Search a host record by IP address. string _ipv4ToSearch = _retrieveRecord.Ipv4Addresses[0].Value; HostRecord _retrieveIpRecord = GetHostByIP(_ipv4ToSearch).Result; Console.WriteLine(JsonConvert.SerializeObject(_retrieveRecord)); Console.ReadKey(); //Update the host record with a new IP address. string _ipv4ToUpdate = ibxHelper.GetIPAsync(1).Result.IPAddresses[0]; HostRecordPost _recordToChange = new HostRecordPost() { Name = _retrieveIpRecord.Name, Ipv4Addresses = new Ipv4AddressPost[] { new Ipv4AddressPost() { Value = _ipv4ToUpdate } } }; HostRecord _updatedRecord = ibxHelper.UpdateHostRecordAsync(_retrieveIpRecord.Name, _recordToChange).Result; Console.WriteLine(JsonConvert.SerializeObject(_updatedRecord)); Console.ReadKey(); //Delete the host record bool _isRecordDeleted = ibxHelper.DeleteHostRecordAsync(_recordToChange).Result; Console.WriteLine(JsonConvert.SerializeObject(_isRecordDeleted)); Console.ReadKey(); //Delete a record that has already been removed (deleted). _isRecordDeleted = ibxHelper.DeleteHostRecordAsync(_recordToChange).Result; Console.WriteLine(JsonConvert.SerializeObject(_isRecordDeleted)); Console.ReadKey(); Console.WriteLine("InfoBlox Helper Test Completed. Press any key to end."); Console.ReadKey(); }