Initial work
This commit is contained in:
@@ -48,7 +48,7 @@ class Browser
|
||||
|
||||
@hydra = Typhoeus::Hydra.new(
|
||||
max_concurrency: @max_threads,
|
||||
timeout: @request_timeout
|
||||
#connecttimeout: @request_timeout
|
||||
)
|
||||
|
||||
# TODO : add an option for the cache dir instead of using a constant
|
||||
@@ -56,8 +56,7 @@ class Browser
|
||||
|
||||
@cache.clean
|
||||
|
||||
# might be in CacheFileStore
|
||||
setup_cache_handlers
|
||||
#Typhoeus::Config.cache = @cache
|
||||
end
|
||||
|
||||
private_class_method :new
|
||||
@@ -146,24 +145,6 @@ class Browser
|
||||
end
|
||||
end
|
||||
|
||||
def setup_cache_handlers
|
||||
@hydra.cache_setter do |request|
|
||||
@cache.write_entry(
|
||||
Browser.generate_cache_key_from_request(request),
|
||||
request.response,
|
||||
request.cache_timeout
|
||||
)
|
||||
end
|
||||
|
||||
@hydra.cache_getter do |request|
|
||||
@cache.read_entry(
|
||||
Browser.generate_cache_key_from_request(request)
|
||||
) rescue nil
|
||||
end
|
||||
end
|
||||
|
||||
private :setup_cache_handlers
|
||||
|
||||
def get(url, params = {})
|
||||
run_request(
|
||||
forge_request(url, params.merge(method: :get))
|
||||
@@ -177,10 +158,10 @@ class Browser
|
||||
end
|
||||
|
||||
def get_and_follow_location(url, params = {})
|
||||
params[:max_redirects] ||= 2
|
||||
params[:maxredirs] ||= 2
|
||||
|
||||
run_request(
|
||||
forge_request(url, params.merge(method: :get, follow_location: true))
|
||||
forge_request(url, params.merge(method: :get, followlocation: true))
|
||||
)
|
||||
end
|
||||
|
||||
@@ -208,12 +189,13 @@ class Browser
|
||||
end
|
||||
end
|
||||
|
||||
unless params.has_key?(:disable_ssl_host_verification)
|
||||
params = params.merge(:disable_ssl_host_verification => true)
|
||||
# TODO : check if it's the default value into ethon. If so, removed the lines from here
|
||||
unless params.has_key?(:ssl_verifyhost)
|
||||
params = params.merge(ssl_verifyhost: 0)
|
||||
end
|
||||
|
||||
unless params.has_key?(:disable_ssl_peer_verification)
|
||||
params = params.merge(:disable_ssl_peer_verification => true)
|
||||
unless params.has_key?(:ssl_verifypeer)
|
||||
params = params.merge(ssl_verifypeer: false)
|
||||
end
|
||||
|
||||
if !params.has_key?(:headers)
|
||||
@@ -223,9 +205,9 @@ class Browser
|
||||
end
|
||||
|
||||
# Used to enable the cache system if :cache_timeout > 0
|
||||
unless params.has_key?(:cache_timeout)
|
||||
params = params.merge(:cache_timeout => @cache_timeout)
|
||||
end
|
||||
#unless params.has_key?(:cache_ttl)
|
||||
# params = params.merge(cache_ttl: @cache_timeout)
|
||||
#end
|
||||
|
||||
params
|
||||
end
|
||||
@@ -247,17 +229,4 @@ class Browser
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# The Typhoeus::Request.cache_key only hash the url :/
|
||||
# this one will include the params
|
||||
# TODO : include also the method (:get, :post, :any)
|
||||
def self.generate_cache_key_from_request(request)
|
||||
cache_key = request.cache_key
|
||||
|
||||
if request.params
|
||||
cache_key = Digest::SHA1.hexdigest("#{cache_key}-#{request.params.hash}")
|
||||
end
|
||||
|
||||
cache_key
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,7 +51,7 @@ class CacheFileStore
|
||||
end
|
||||
end
|
||||
|
||||
def read_entry(key)
|
||||
def get(key)
|
||||
entry_file_path = get_entry_file_path(key)
|
||||
|
||||
if File.exists?(entry_file_path)
|
||||
@@ -59,7 +59,7 @@ class CacheFileStore
|
||||
end
|
||||
end
|
||||
|
||||
def write_entry(key, data_to_store, cache_timeout)
|
||||
def set(key, data_to_store, cache_timeout)
|
||||
if cache_timeout > 0
|
||||
File.open(get_entry_file_path(key), 'w') do |f|
|
||||
f.write(@serializer.dump(data_to_store))
|
||||
|
||||
@@ -33,7 +33,6 @@ begin
|
||||
require 'rbconfig'
|
||||
require 'pp'
|
||||
# Third party libs
|
||||
gem 'typhoeus', '=0.4.2'
|
||||
require 'typhoeus'
|
||||
require 'json'
|
||||
require 'nokogiri'
|
||||
|
||||
@@ -60,7 +60,7 @@ module WpUsernames
|
||||
end
|
||||
|
||||
def get_nickname_from_url(url)
|
||||
resp = Browser.instance.get(url, { follow_location: true, max_redirects: 2 })
|
||||
resp = Browser.instance.get_and_follow_location(url)
|
||||
nickname = nil
|
||||
if resp.code == 200
|
||||
nickname = extract_nickname_from_body(resp.body)
|
||||
|
||||
@@ -55,7 +55,7 @@ class WpEnumerator
|
||||
targets.each do |target|
|
||||
url = target.get_full_url
|
||||
|
||||
request = enum_browser.forge_request(url, { cache_timeout: 0, follow_location: true })
|
||||
request = enum_browser.forge_request(url, { cache_ttl: 0, followlocation: true })
|
||||
request_count += 1
|
||||
|
||||
request.on_complete do |response|
|
||||
|
||||
@@ -74,7 +74,7 @@ class WpTheme < WpItem
|
||||
|
||||
# Discover the wordpress theme name by parsing the css link rel
|
||||
def self.find_from_css_link(target_uri)
|
||||
response = Browser.instance.get(target_uri.to_s, { follow_location: true, max_redirects: 2 })
|
||||
response = Browser.instance.get_and_follow_location(target_uri.to_s)
|
||||
|
||||
# https + domain is optional because of relative links
|
||||
matches = %r{(?:https?://[^"']+)?/([^/]+)/themes/([^"']+)/style.css}i.match(response.body)
|
||||
|
||||
@@ -63,7 +63,7 @@ class CheckerPlugin < Plugin
|
||||
number_of_urls = urls.size
|
||||
|
||||
urls.each do |url|
|
||||
request = browser.forge_request(url, { cache_timeout: 0, follow_location: true })
|
||||
request = browser.forge_request(url, { cache_ttl: 0, followlocation: true })
|
||||
request_count += 1
|
||||
|
||||
request.on_complete do |response|
|
||||
|
||||
Reference in New Issue
Block a user