X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fwserver.rb;h=a888ad0c3e9d29a9cd9230366bb3ff600a6d1600;hb=de9ddb8a7eb436c0cb8db81289373dc169f484ba;hp=fb4738c173a13bcd6e662227478e5c6c97071d34;hpb=676dd61e6b0bea5f506d064039a685944aefd6fb;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/wserver.rb b/data/rbot/plugins/wserver.rb index fb4738c1..a888ad0c 100644 --- a/data/rbot/plugins/wserver.rb +++ b/data/rbot/plugins/wserver.rb @@ -1,7 +1,3 @@ -require 'net/http' -require 'uri' -Net::HTTP.version_1_2 - class WserverPlugin < Plugin def help(plugin, topic="") "wserver => try and determine what webserver is using" @@ -29,30 +25,26 @@ class WserverPlugin < Plugin return end - http = @bot.httputil.get_proxy(uri) - http.open_timeout = 5 - http.start {|http| - resp = http.head('/') - server = resp['Server'] - if(server && server.length > 0) - m.reply "#{uri.host} is running #{server}" - else - m.reply "couldn't tell what #{uri.host} is running" - end - - if(resp.code == "302" || resp.code == "301") - newloc = resp['location'] - newuri = URI.parse(newloc) - # detect and ignore incorrect redirects (to relative paths etc) - if (newuri.host != nil) - if(uri.host != newuri.host) - m.reply "#{uri.host} redirects to #{newuri.scheme}://#{newuri.host}" - raise resp['location'] - end + resp = @bot.httputil.head(uri) + server = resp['Server'] + if(server && server.length > 0) + m.reply "#{uri.host} is running #{server}" + else + m.reply "couldn't tell what #{uri.host} is running" + end + + if(resp.code == "302" || resp.code == "301") + newloc = resp['location'] + newuri = URI.parse(newloc) + # detect and ignore incorrect redirects (to relative paths etc) + if (newuri.host != nil) + if(uri.host != newuri.host) + m.reply "#{uri.host} redirects to #{newuri.scheme}://#{newuri.host}" + raise resp['location'] end end - } + end rescue TimeoutError => err m.reply "timed out connecting to #{uri.host}:#{uri.port} :(" return @@ -61,7 +53,7 @@ class WserverPlugin < Plugin hostname = err.message retry rescue StandardError => err - puts err + error err.inspect m.reply "couldn't connect to #{uri.host}:#{uri.port} :(" return end