5 class WserverPlugin < Plugin
6 def help(plugin, topic="")
7 "wserver <uri> => try and determine what webserver <uri> is using"
10 unless(m.params && m.params =~ /^\S+$/)
11 m.reply "incorrect usage: " + help(m.plugins)
16 hostname = m.params.dup
17 hostname = "http://#{hostname}" unless hostname =~ /:\/\//
19 if(redirect_count > 3)
20 m.reply "cowardly refusing to follow more than 3 redirects"
25 uri = URI.parse(hostname)
26 rescue URI::InvalidURIError => err
27 m.reply "#{m.params} is not a valid URI"
32 m.reply "incorrect usage: " + help(m.plugin)
36 http = @bot.httputil.get_proxy(uri)
41 server = resp['Server']
42 if(server && server.length > 0)
43 m.reply "#{uri.host} is running #{server}"
45 m.reply "couldn't tell what #{uri.host} is running"
48 if(resp.code == "302" || resp.code == "301")
49 newloc = resp['location']
50 newuri = URI.parse(newloc)
51 # detect and ignore incorrect redirects (to relative paths etc)
52 if (newuri.host != nil)
53 if(uri.host != newuri.host)
54 m.reply "#{uri.host} redirects to #{newuri.scheme}://#{newuri.host}"
55 raise resp['location']
60 rescue TimeoutError => err
61 m.reply "timed out connecting to #{uri.host}:#{uri.port} :("
63 rescue RuntimeError => err
65 hostname = err.message
67 rescue StandardError => err
69 m.reply "couldn't connect to #{uri.host}:#{uri.port} :("
74 plugin = WserverPlugin.new
75 plugin.register("wserver")