From 29d713ee0c8c25fcf74c4292ff13fe1fa4d0d827 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Wed, 19 Jul 2017 14:17:39 +0200 Subject: [PATCH 1/4] Fixed issue #6 - Domains without an AAA record / that are not reacable fail further lookup tries. --- lib/autodiscover/pox_request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/autodiscover/pox_request.rb b/lib/autodiscover/pox_request.rb index fc661b3..9ab02f4 100644 --- a/lib/autodiscover/pox_request.rb +++ b/lib/autodiscover/pox_request.rb @@ -19,7 +19,7 @@ def autodiscover begin response = client.http.post(url, request_body, {'Content-Type' => 'text/xml; charset=utf-8'}) return PoxResponse.new(response.body) if good_response?(response) - rescue Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError + rescue SocketError, Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError next rescue OpenSSL::SSL::SSLError options[:ignore_ssl_errors] ? next : raise From ee9b53dfa797ce6d4f970b82beea7fbdd2df56bb Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Nov 2017 11:52:04 +0100 Subject: [PATCH 2/4] Fixed bug: SocketError in redirected_http_url fails (to) hard. --- lib/autodiscover/pox_request.rb | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/autodiscover/pox_request.rb b/lib/autodiscover/pox_request.rb index 9ab02f4..7437d1c 100644 --- a/lib/autodiscover/pox_request.rb +++ b/lib/autodiscover/pox_request.rb @@ -16,21 +16,13 @@ def initialize(client, **options) # @return [Autodiscover::PoxResponse, nil] def autodiscover available_urls.each do |url| - begin - response = client.http.post(url, request_body, {'Content-Type' => 'text/xml; charset=utf-8'}) - return PoxResponse.new(response.body) if good_response?(response) - rescue SocketError, Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError - next - rescue OpenSSL::SSL::SSLError - options[:ignore_ssl_errors] ? next : raise - end + response = client.http.post(url, request_body, {'Content-Type' => 'text/xml; charset=utf-8'}) + return PoxResponse.new(response.body) if good_response?(response) end end - private - def good_response?(response) response.status == 200 end @@ -39,10 +31,14 @@ def available_urls(&block) return to_enum(__method__) unless block_given? formatted_https_urls.each {|url| logger.debug "Yielding HTTPS Url #{url}" - yield url + handle_allowed_errors do + yield url + end } - logger.debug "Yielding HTTP Redirected Url #{redirected_http_url}" - yield redirected_http_url + handle_allowed_errors do + logger.debug "Yielding HTTP Redirected Url #{redirected_http_url}" + yield redirected_http_url + end end def formatted_https_urls @@ -71,5 +67,11 @@ def request_body end.to_xml end + def handle_allowed_errors + yield + rescue SocketError, Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError + rescue OpenSSL::SSL::SSLError + raise if !options[:ignore_ssl_errors] + end end end From 441779cf327cd64b4eecd3b8bded5bedd6276516 Mon Sep 17 00:00:00 2001 From: Thiago Rodrigues de Paula Date: Thu, 13 Sep 2018 14:22:05 +0200 Subject: [PATCH 3/4] Add Exchange2017 and fix typo --- lib/autodiscover/server_version_parser.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/autodiscover/server_version_parser.rb b/lib/autodiscover/server_version_parser.rb index cc8fde2..a79e627 100644 --- a/lib/autodiscover/server_version_parser.rb +++ b/lib/autodiscover/server_version_parser.rb @@ -16,7 +16,8 @@ class ServerVersionParser }, 15 => { 0 => "Exchange2013", - 1 => "Exchange2013_SP1", + 1 => "Exchange2016", + 20 => "Exchange2017" } } @@ -38,7 +39,7 @@ def build def exchange_version v = VERSIONS[major][minor] - v.nil? ? VERIONS[8][0] : v + v.nil? ? VERSIONS[8][0] : v end end From 4fceaad38414fda746b615ee76a784c85983ff48 Mon Sep 17 00:00:00 2001 From: Felippe Cardozo Date: Tue, 10 May 2022 16:06:43 +0200 Subject: [PATCH 4/4] update lib --- lib/autodiscover/pox_request.rb | 1 + lib/autodiscover/pox_response.rb | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/autodiscover/pox_request.rb b/lib/autodiscover/pox_request.rb index 7437d1c..f53593e 100644 --- a/lib/autodiscover/pox_request.rb +++ b/lib/autodiscover/pox_request.rb @@ -70,6 +70,7 @@ def request_body def handle_allowed_errors yield rescue SocketError, Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError + rescue Errno::EADDRNOTAVAIL rescue OpenSSL::SSL::SSLError raise if !options[:ignore_ssl_errors] end diff --git a/lib/autodiscover/pox_response.rb b/lib/autodiscover/pox_response.rb index 7d0dfbf..5b1d296 100644 --- a/lib/autodiscover/pox_response.rb +++ b/lib/autodiscover/pox_response.rb @@ -17,16 +17,21 @@ def ews_url end def exch_proto - @exch_proto ||= (response["Account"]["Protocol"].select{|p| p["Type"] == "EXCH"}.first || {}) + @exch_proto ||= protocols.find { |p| p["Type"] == "EXCH" } || {} end def expr_proto - @expr_proto ||= (response["Account"]["Protocol"].select{|p| p["Type"] == "EXPR"}.first || {}) + @expr_proto ||= protocols.find { |p| p["Type"] == "EXPR" } || {} end def web_proto - @web_proto ||= (response["Account"]["Protocol"].select{|p| p["Type"] == "WEB"}.first || {}) + @web_proto ||= protocols.find { |p| p["Type"] == "WEB" } || {} end + private + + def protocols + response["Account"]["Protocol"] || [] + end end end