* Move some core plugins to use the new httputil
* fix wserver's redirection handling for relative (i.e. broken) redirects
* fix tube plugin's html parsing
+Wed Jul 20 23:30:01 BST 2005 Tom Gilbert <tom@linuxbrit.co.uk>
+
+ * Move some core plugins to use the new httputil
+ * fix wserver's redirection handling for relative (i.e. broken) redirects
+ * fix tube plugin's html parsing
+
Wed Jul 20 01:18:06 BST 2005 Tom Gilbert <tom@linuxbrit.co.uk>
* Add new httputil object to the bot object, to be used by plugins etc
Wed Jul 20 01:18:06 BST 2005 Tom Gilbert <tom@linuxbrit.co.uk>
* Add new httputil object to the bot object, to be used by plugins etc
- proxy_host = nil
- proxy_port = nil
-
- if(ENV['http_proxy'])
- if(ENV['http_proxy'] =~ /^http:\/\/(.+):(\d+)$/)
- proxy_host = $1
- proxy_port = $2
- end
- end
-
langs = ["en", "fr", "de", "it", "pt", "es", "nl"]
query = "/babelfish/tr"
langs = ["en", "fr", "de", "it", "pt", "es", "nl"]
query = "/babelfish/tr"
- http = Net::HTTP.new("babelfish.altavista.com", 80, proxy_host, proxy_port)
+ http = @bot.httputil.get_proxy(URI.parse("http://babelfish.altavista.com"))
http.start {|http|
resp = http.post(query, data, {"content-type",
http.start {|http|
resp = http.post(query, data, {"content-type",
def search_freshmeat(m, search, max=4)
max = 8 if max > 8
begin
def search_freshmeat(m, search, max=4)
max = 8 if max > 8
begin
- xml = Utils.http_get("http://freshmeat.net/search-xml/?orderby=locate_projectname_full_DESC&q=#{URI.escape(search)}")
+ xml = @bot.httputil.get(URI.parse("http://freshmeat.net/search-xml/?orderby=locate_projectname_full_DESC&q=#{URI.escape(search)}"))
rescue URI::InvalidURIError, URI::BadURIError => e
m.reply "illegal search string #{search}"
return
rescue URI::InvalidURIError, URI::BadURIError => e
m.reply "illegal search string #{search}"
return
def freshmeat(m, max=4)
max = 8 if max > 8
def freshmeat(m, max=4)
max = 8 if max > 8
- xml = Utils.http_get("http://images.feedstermedia.com/feedcache/ostg/freshmeat/fm-releases-global.xml")
+ xml = @bot.httputil.get(URI.parse("http://images.feedstermedia.com/feedcache/ostg/freshmeat/fm-releases-global.xml"))
unless xml
m.reply "freshmeat news parse failed"
return
unless xml
m.reply "freshmeat news parse failed"
return
- http = Net::HTTP.new("www.google.com", 80, proxy_host, proxy_port)
+ http = @bot.httputil.get_proxy(URI.parse("http://www.google.com"))
def search_slashdot(m, search, max=4)
begin
def search_slashdot(m, search, max=4)
begin
- xml = Utils.http_get("http://slashdot.org/search.pl?content_type=rss&query=#{URI.escape(search)}")
+ xml = @bot.httputil.get(URI.parse("http://slashdot.org/search.pl?content_type=rss&query=#{URI.escape(search)}"))
rescue URI::InvalidURIError, URI::BadURIError => e
m.reply "illegal search string #{search}"
return
rescue URI::InvalidURIError, URI::BadURIError => e
m.reply "illegal search string #{search}"
return
end
def slashdot(m, max=4)
end
def slashdot(m, max=4)
- xml = Utils.http_get("http://slashdot.org/slashdot.xml")
+ xml = @bot.httputil.get(URI.parse("http://slashdot.org/slashdot.xml"))
unless xml
m.reply "slashdot news parse failed"
return
unless xml
m.reply "slashdot news parse failed"
return
return unless m.kind_of?(PrivMessage)
return if m.address?
# TODO support multiple urls in one line
return unless m.kind_of?(PrivMessage)
return if m.address?
# TODO support multiple urls in one line
- if m.message =~ /(f|ht)tp:\/\//
- if m.message =~ /((f|ht)tp:\/\/.*?)(?:\s+|$)/
+ if m.message =~ /(f|ht)tps?:\/\//
+ if m.message =~ /((f|ht)tps?:\/\/.*?)(?:\s+|$)/
url = Url.new(m.target, m.sourcenick, Time.new, $1)
list = @registry[m.target]
debug "#{list.length} urls so far"
url = Url.new(m.target, m.sourcenick, Time.new, $1)
list = @registry[m.target]
debug "#{list.length} urls so far"
- 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
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"
begin
if(redirect_count > 3)
m.reply "cowardly refusing to follow more than 3 redirects"
m.reply "incorrect usage: " + help(m.plugin)
return
end
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|
http.open_timeout = 5
http.start {|http|
- resp = http.head(path)
- result = host
server = resp['Server']
if(server && server.length > 0)
server = resp['Server']
if(server && server.length > 0)
- m.reply "#{host} is running #{server}"
+ m.reply "#{uri.host} is running #{server}"
- 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")
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
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
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} :("
SENDQ_BURST = 4
NICK = rbot
USER = rbot
SENDQ_BURST = 4
NICK = rbot
USER = rbot
PORT = 6667
LANGUAGE = english
KEYWORD_LISTEN = false
PORT = 6667
LANGUAGE = english
KEYWORD_LISTEN = false