diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/rbot/ircbot.rb | 5 | ||||
-rw-r--r-- | lib/rbot/ircsocket.rb | 28 |
3 files changed, 32 insertions, 5 deletions
@@ -1,3 +1,7 @@ +2006-11-01 Giuseppe Bilotta <giuseppe.bilotta@gmail.com> + + * SSL support: patch from Robin H. Johnson <robbat2@gentoo.org> + 2006-10-28 Giuseppe Bilotta <giuseppe.bilotta@gmail.com> * A-Z game: try to guess the word the bot is thinking of: every miss diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 4be0c444..bbb7c16c 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -154,6 +154,9 @@ class IrcBot :default => 6667, :type => :integer, :requires_restart => true, :desc => "What port should the bot connect to?", :validate => Proc.new {|v| v > 0}, :wizard => true) + BotConfig.register BotConfigBooleanValue.new('server.ssl', + :default => false, :requires_restart => true, :wizard => true, + :desc => "Use SSL to connect to this server?") BotConfig.register BotConfigStringValue.new('server.password', :default => false, :requires_restart => true, :desc => "Password for connecting to this server (if required)", @@ -368,7 +371,7 @@ class IrcBot @plugins.add_botmodule_dir(Config::datadir + "/plugins") @plugins.scan - @socket = IrcSocket.new(@config['server.name'], @config['server.port'], @config['server.bindhost'], @config['server.sendq_delay'], @config['server.sendq_burst']) + @socket = IrcSocket.new(@config['server.name'], @config['server.port'], @config['server.bindhost'], @config['server.sendq_delay'], @config['server.sendq_burst'], :ssl => @config['server.ssl']) @client = IrcClient.new myself.nick = @config['irc.nick'] diff --git a/lib/rbot/ircsocket.rb b/lib/rbot/ircsocket.rb index 9d92ef11..6b49cf00 100644 --- a/lib/rbot/ircsocket.rb +++ b/lib/rbot/ircsocket.rb @@ -260,7 +260,7 @@ module Irc # port:: IRCd port # host:: optional local host to bind to (ruby 1.7+ required) # create a new IrcSocket - def initialize(server, port, host, sendq_delay=2, sendq_burst=4) + def initialize(server, port, host, sendq_delay=2, sendq_burst=4, opts={}) @timer = Timer::Timer.new @timer.add(0.2) do spool @@ -272,6 +272,12 @@ module Irc @spooler = false @lines_sent = 0 @lines_received = 0 + if opts.kind_of?(Hash) and opts.key?(:ssl) + @ssl = opts[:ssl] + else + @ssl = false + end + if sendq_delay @sendq_delay = sendq_delay.to_f else @@ -311,6 +317,15 @@ module Irc else @sock=TCPSocket.new(@server, @port) end + if(@ssl) + require 'openssl' + ssl_context = OpenSSL::SSL::SSLContext.new() + ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE + @rawsock = @sock + @sock = OpenSSL::SSL::SSLSocket.new(@sock, ssl_context) + @sock.sync_close = true + @sock.connect + end @qthread = false @qmutex = Mutex.new @sendq = MessageQueue.new @@ -437,8 +452,13 @@ module Irc # shutdown the connection to the server def shutdown(how=2) - @sock.shutdown(how) unless @sock.nil? - @sock = nil + if(@ssl) + @rawsock.shutdown(how) unless @rawsock.nil? + @rawsock = nil + else + @sock.shutdown(how) unless @sock.nil? + @sock = nil + end @burst = 0 end @@ -452,7 +472,7 @@ module Irc if @sock.nil? error "SEND attempted on closed socket" else - @sock.send(message + "\n",0) + @sock.puts(message + "\n",0) @last_send = Time.new @flood_send += message.irc_send_penalty if penalty @lines_sent += 1 |