5 class WserverPlugin < Plugin
6 def help(plugin, topic="")
7 "wserver <uri> => try and determine what webserver <uri> is using"
10 def wserver(m, params)
12 hostname = params[:host].dup
13 hostname = "http://#{hostname}" unless hostname =~ /:\/\//
15 if(redirect_count > 3)
16 m.reply "cowardly refusing to follow more than 3 redirects"
21 uri = URI.parse(hostname)
22 rescue URI::InvalidURIError => err
23 m.reply "#{hostname} is not a valid URI"
28 m.reply "incorrect usage: " + help(m.plugin)
32 http = @bot.httputil.get_proxy(uri)
37 server = resp['Server']
38 if(server && server.length > 0)
39 m.reply "#{uri.host} is running #{server}"
41 m.reply "couldn't tell what #{uri.host} is running"
44 if(resp.code == "302" || resp.code == "301")
45 newloc = resp['location']
46 newuri = URI.parse(newloc)
47 # detect and ignore incorrect redirects (to relative paths etc)
48 if (newuri.host != nil)
49 if(uri.host != newuri.host)
50 m.reply "#{uri.host} redirects to #{newuri.scheme}://#{newuri.host}"
51 raise resp['location']
56 rescue TimeoutError => err
57 m.reply "timed out connecting to #{uri.host}:#{uri.port} :("
59 rescue RuntimeError => err
61 hostname = err.message
63 rescue StandardError => err
65 m.reply "couldn't connect to #{uri.host}:#{uri.port} :("
70 plugin = WserverPlugin.new
71 plugin.map 'wserver :host'