Class: Okayu::IECookieThief
Class Method Summary
collapse
Methods inherited from CookieThief
cookiestxt_from_array, do_on_tmpfile, send_query
Class Method Details
.cookie_filenames(host) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/cookie_thief.rb', line 83
def cookie_filenames host
cookie_filename = []
if OS == 'Windows'
cookie_filenames = Dir.glob("#{APPDATA_PATH}/Microsoft/Windows/Cookies/Low/*").select{|path| path =~ /#{host_main_str(host)}/}
if cookie_filenames == []
cookie_filename = Dir.glob("#{TMP_INET_FILES_PATH}/*").select{|path| path =~ /#{host_main_str(host)}/}
end
end
cookie_filenames
end
|
.cookie_from_cookie_string(str) ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'lib/cookie_thief.rb', line 73
def cookie_from_cookie_string str
a = str.split(/\n/m)
name = a[0]
value = a[1]
host = "." + a[2].sub(%r{/.*$}, '')
path = "/" + a[2].sub(%r{^.*/}, '')
expiry = ((10**-7) * (a[4].to_i * (2**32) + a[3].to_i) - 11644473600).to_i
"#{host}\tTRUE\t#{path}\tTRUE\t#{expiry}\t#{name}\t#{value}"
end
|
.cookies_from_cookie_file(filename) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/cookie_thief.rb', line 61
def cookies_from_cookie_file filename
cookies = []
File.open filename, 'r' do |f|
cookies = cookies_from_cookies_string(f.read)
end
cookies
end
|
.cookies_from_cookies_string(str) ⇒ Object
69
70
71
|
# File 'lib/cookie_thief.rb', line 69
def cookies_from_cookies_string str
str.split(/^\*\n/m).map{|s|cookie_from_cookie_string(s)}
end
|
.get(args) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/cookie_thief.rb', line 43
def get args
cookies = []
if args[:host]
cookie_filenames(args[:host]).map do |cookie_filename|
cookies = cookies_from_cookie_file(cookie_filename)
end
end
if args[:name]
cookies = select_by_name(cookies, args[:name])
end
cookies.join("\n")
end
|
.host_main_str(host) ⇒ Object
95
96
97
|
# File 'lib/cookie_thief.rb', line 95
def host_main_str host
host_main_str = host.sub(/^\./, '').sub(/\..*$/, '')
end
|
.select_by_name(cookies, name) ⇒ Object
57
58
59
|
# File 'lib/cookie_thief.rb', line 57
def select_by_name cookies, name
cookies.select{|cookie|cookie.split("\t")[5] == name}
end
|