diff options
Diffstat (limited to 'rbot/plugins/wserver.rb')
-rw-r--r-- | rbot/plugins/wserver.rb | 51 |
1 files changed, 16 insertions, 35 deletions
diff --git a/rbot/plugins/wserver.rb b/rbot/plugins/wserver.rb index eb4effaf..e1fe10bd 100644 --- a/rbot/plugins/wserver.rb +++ b/rbot/plugins/wserver.rb @@ -12,22 +12,9 @@ class WserverPlugin < Plugin return end - proxy_host = nil - proxy_port = nil - - if(ENV['http_proxy']) - if(ENV['http_proxy'] =~ /^http:\/\/(.+):(\d+)$/) - hh = $1 - pp = $2 - unless(m.params =~ /\.db\.com/ || m.params =~ /\.deuba\.com/) - proxy_host = hh - proxy_port = pp - end - end - end - redirect_count = 0 hostname = m.params.dup + hostname = "http://#{hostname}" unless hostname =~ /:\/\// begin if(redirect_count > 3) m.reply "cowardly refusing to follow more than 3 redirects" @@ -45,47 +32,41 @@ class WserverPlugin < Plugin m.reply "incorrect usage: " + help(m.plugin) return end - if(uri.scheme == "https") - m.reply "#{uri.scheme} not supported" - return - end - host = uri.host ? uri.host : hostname - port = uri.port ? uri.port : 80 - path = '/' - if(uri.scheme == "http") - path = uri.path if uri.path - end - - http = Net::HTTP.new(host, port, proxy_host, proxy_port) + http = @bot.httputil.get_proxy(uri) http.open_timeout = 5 http.start {|http| - resp = http.head(path) - result = host + resp = http.head('/') server = resp['Server'] if(server && server.length > 0) - m.reply "#{host} is running #{server}" + m.reply "#{uri.host} is running #{server}" else - m.reply "couldn't tell what #{host} is running" + m.reply "couldn't tell what #{uri.host} is running" end if(resp.code == "302" || resp.code == "301") - if(host != URI.parse(resp['location']).host) - m.reply "#{host} redirects to #{resp['location']}" - raise resp['location'] + 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 #{host}:#{port} :(" + m.reply "timed out connecting to #{uri.host}:#{uri.port} :(" return rescue RuntimeError => err redirect_count += 1 hostname = err.message retry rescue StandardError => err - m.reply "couldn't connect to #{host}:#{port} :(" + puts err + m.reply "couldn't connect to #{uri.host}:#{uri.port} :(" return end end |