Module: AdsenseCrawlerForPrivate
- Defined in:
- lib/adsense_crawler_for_private.rb,
lib/adsense_crawler_for_private/engine.rb,
lib/adsense_crawler_for_private/version.rb,
app/helpers/adsense_crawler_for_private/application_helper.rb,
app/controllers/adsense_crawler_for_private/application_controller.rb,
app/controllers/adsense_crawler_for_private/adsense_crawler_login_controller.rb
Defined Under Namespace
Modules: ApplicationHelper
Classes: AdsenseCrawlerLoginController, ApplicationController, Engine, Logger
Constant Summary
collapse
- VERSION =
"1.2.1"
Class Method Summary
collapse
Class Method Details
.cookie_hash(crawler_name, crawler_password, request_or_ip) ⇒ Object
46
47
48
49
50
|
# File 'lib/adsense_crawler_for_private.rb', line 46
def self.cookie_hash(crawler_name, crawler_password, request_or_ip)
{:value => AdsenseCrawlerForPrivate.cookie_str(crawler_name, crawler_password, 2.days.from_now, request_or_ip),
:expires => 2.days.from_now,
:domain => AdsenseCrawlerForPrivate.cookie_domain}
end
|
.cookie_str(crawler_name, crawler_password, expire_time, request_or_ip) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/adsense_crawler_for_private.rb', line 52
def self.cookie_str(crawler_name, crawler_password, expire_time, request_or_ip)
ip_str = request_or_ip.respond_to?(:remote_ip) ? request_or_ip.remote_ip : request_or_ip.to_s
return [crawler_name, Digest::SHA1.hexdigest(crawler_password),
expire_time.httpdate, ip_str].to_json
end
|
.ip_check(request) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/adsense_crawler_for_private.rb', line 59
def self.ip_check(request)
unless AdsenseCrawlerForPrivate.ip_ranges.nil?
ip_check = ::IPAddr.new(request.remote_ip)
AdsenseCrawlerForPrivate.ip_ranges.each do |ip_accepted|
return true if ip_accepted.include?(ip_check)
end
return false
end
return true
end
|
.logger ⇒ Object
70
71
72
|
# File 'lib/adsense_crawler_for_private.rb', line 70
def self.logger
Logger
end
|
.login_check(cookies, request) ⇒ Object
Checks crawler cookie, returns true if logged in
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/adsense_crawler_for_private.rb', line 11
def self.login_check(cookies, request)
cookie = cookies.signed[AdsenseCrawlerForPrivate.cookie_name]
login_ok = false
if !cookie.blank?
self.logger.info "login_check: cookie found #{cookie}"
begin
name, password, expiry_time, remote_ip = JSON.parse(cookie)
expiry_time = Time.parse(expiry_time)
if (name == AdsenseCrawlerForPrivate.crawler_name and
password == Digest::SHA1.hexdigest(AdsenseCrawlerForPrivate.crawler_password) and
expiry_time > Time.now and
self.ip_check(request))
login_ok = true
self.logger.warn "login_check was ok for #{name}, org_ip #{remote_ip}, current_ip #{request.remote_ip}"
end
rescue JSON::ParserError => e
self.logger.warn "login_check problem parsing cookie json: #{e.inspect}"
ensure
unless login_ok
info_str = "login_check wasn't ok, even though cookie was found."
info_str += "warning: ip was not accepted" unless self.ip_check(request)
self.logger.warn info_str
cookies.delete(AdsenseCrawlerForPrivate.cookie_name)
end
end
end
return login_ok
end
|