1 class WserverPlugin < Plugin
2 def help(plugin, topic="")
3 "wserver <uri> => try and determine what webserver <uri> is using"
8 hostname = params[:host].dup
9 hostname = "http://#{hostname}" unless hostname =~ /:\/\//
11 if(redirect_count > 3)
12 m.reply "cowardly refusing to follow more than 3 redirects"
17 uri = URI.parse(hostname)
18 rescue URI::InvalidURIError => err
19 m.reply "#{hostname} is not a valid URI"
24 m.reply "incorrect usage: " + help(m.plugin)
29 resp = @bot.httputil.head(uri)
30 server = resp['Server']
31 if(server && server.length > 0)
32 m.reply "#{uri.host} is running #{server}"
34 m.reply "couldn't tell what #{uri.host} is running"
37 if(resp.code == "302" || resp.code == "301")
38 newloc = resp['location']
39 newuri = URI.parse(newloc)
40 # detect and ignore incorrect redirects (to relative paths etc)
41 if (newuri.host != nil)
42 if(uri.host != newuri.host)
43 m.reply "#{uri.host} redirects to #{newuri.scheme}://#{newuri.host}"
44 raise resp['location']
48 rescue TimeoutError => err
49 m.reply "timed out connecting to #{uri.host}:#{uri.port} :("
51 rescue RuntimeError => err
53 hostname = err.message
55 rescue StandardError => err
57 m.reply "couldn't connect to #{uri.host}:#{uri.port} :("
62 plugin = WserverPlugin.new
63 plugin.map 'wserver :host'