From ec56d8a5c3dd91da1f9ec1d9daf0fca8d1669810 Mon Sep 17 00:00:00 2001 From: Matthias H Date: Thu, 17 Jul 2014 23:54:19 +0200 Subject: [agent] add options for ssl and proxy --- lib/rbot/core/utils/agent.rb | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'lib/rbot') diff --git a/lib/rbot/core/utils/agent.rb b/lib/rbot/core/utils/agent.rb index fc73c288..8949a5c8 100644 --- a/lib/rbot/core/utils/agent.rb +++ b/lib/rbot/core/utils/agent.rb @@ -6,12 +6,18 @@ # # Author:: Matthias Hecker # -# Central repository for Mechanize agent instances, creates -# pre-configured agents, allows for persistent caching, -# cookie and page serialization. +# Central factory for Mechanize agent instances, creates +# pre-configured agents. The main goal of this is to have +# central proxy and user agent configuration for mechanize. +# +# plugins can just call @bot.agent.create to return +# a new unique mechanize agent. require 'mechanize' +require 'digest/md5' +require 'uri' + module ::Irc module Utils @@ -19,6 +25,24 @@ class AgentFactory Bot::Config.register Bot::Config::IntegerValue.new('agent.max_redir', :default => 5, :desc => "Maximum number of redirections to be used when getting a document") + Bot::Config.register Bot::Config::BooleanValue.new('agent.ssl_verify', + :default => true, + :desc => "Whether or not you want to validate SSL certificates") + Bot::Config.register Bot::Config::BooleanValue.new('agent.proxy_use', + :default => true, + :desc => "Use HTTP proxy or not") + Bot::Config.register Bot::Config::StringValue.new('agent.proxy_host', + :default => '127.0.0.1', + :desc => "HTTP proxy hostname") + Bot::Config.register Bot::Config::IntegerValue.new('agent.proxy_port', + :default => 8118, + :desc => "HTTP proxy port") + Bot::Config.register Bot::Config::StringValue.new('agent.proxy_username', + :default => nil, + :desc => "HTTP proxy username") + Bot::Config.register Bot::Config::StringValue.new('agent.proxy_password', + :default => nil, + :desc => "HTTP proxy password") def initialize(bot) @bot = bot @@ -28,10 +52,20 @@ class AgentFactory end # Returns a new, unique instance of Mechanize. - def get_instance + def create(noproxy=false) agent = Mechanize.new agent.redirection_limit = @bot.config['agent.max_redir'] - + if not @bot.config['agent.ssl_verify'] + agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE + end + if @bot.config['agent.proxy_use'] and not noproxy + agent.set_proxy( + @bot.config['agent.proxy_host'], + @bot.config['agent.proxy_port'], + @bot.config['agent.proxy_username'], + @bot.config['agent.proxy_password'] + ) + end agent end end -- cgit v1.2.3 From 2fb24ad9834f0544ac0eef0b589a71fa7add63cf Mon Sep 17 00:00:00 2001 From: Matthias H Date: Fri, 18 Jul 2014 15:37:26 +0200 Subject: add a first basic colorformat string function --- lib/rbot/core/utils/extends.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/rbot') diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb index f3662395..11ebfc61 100644 --- a/lib/rbot/core/utils/extends.rb +++ b/lib/rbot/core/utils/extends.rb @@ -370,8 +370,17 @@ class ::String "#{pre}#{self}#{post}" end end -end + # Format a string using IRC colors + # + def colorformat + txt = self.dup + + txt.gsub!(/\*([^\*]+)\*/, Bold + '\\1' + NormalText) + + return txt + end +end # Extensions to the Regexp class, with some common and/or complex regular # expressions. -- cgit v1.2.3