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)
19 if(ENV['http_proxy'] =~ /^http:\/\/(.+):(\d+)$/)
22 unless(m.params =~ /\.db\.com/ || m.params =~ /\.deuba\.com/)
30 hostname = m.params.dup
32 if(redirect_count > 3)
33 m.reply "cowardly refusing to follow more than 3 redirects"
38 uri = URI.parse(hostname)
39 rescue URI::InvalidURIError => err
40 m.reply "#{m.params} is not a valid URI"
45 m.reply "incorrect usage: " + help(m.plugin)
48 if(uri.scheme == "https")
49 m.reply "#{uri.scheme} not supported"
53 host = uri.host ? uri.host : hostname
54 port = uri.port ? uri.port : 80
56 if(uri.scheme == "http")
57 path = uri.path if uri.path
60 http = Net::HTTP.new(host, port, proxy_host, proxy_port)
64 resp = http.head(path)
66 server = resp['Server']
67 if(server && server.length > 0)
68 m.reply "#{host} is running #{server}"
70 m.reply "couldn't tell what #{host} is running"
73 if(resp.code == "302" || resp.code == "301")
74 if(host != URI.parse(resp['location']).host)
75 m.reply "#{host} redirects to #{resp['location']}"
76 raise resp['location']
80 rescue TimeoutError => err
81 m.reply "timed out connecting to #{host}:#{port} :("
83 rescue RuntimeError => err
85 hostname = err.message
87 rescue StandardError => err
88 m.reply "couldn't connect to #{host}:#{port} :("
93 plugin = WserverPlugin.new
94 plugin.register("wserver")