3217c96dd6
* User may now specify a browser to use * Or he may choose to guess the best, based on mtime of cookie files * Command line application accepts flags for this functionality
47 lines
1.6 KiB
Ruby
Executable file
47 lines
1.6 KiB
Ruby
Executable file
#!/usr/bin/env ruby
|
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "cookie_extractor"))
|
|
|
|
|
|
def usage msg=nil
|
|
puts msg if msg
|
|
puts "Usage: cookie_extractor /path/to/cookies.sqlite Open a DB file"
|
|
puts " cookie_extractor --guess Guess which browser to use and open corresponding file"
|
|
puts " cookie_extractor --browser chrome|chromium|firefox Open DB corresponding to a particular browser"
|
|
exit
|
|
end
|
|
|
|
|
|
begin
|
|
extractor =
|
|
case ARGV.first
|
|
when '--guess', '-g'
|
|
begin
|
|
CookieExtractor::BrowserDetector.guess()
|
|
rescue CookieExtractor::NoCookieFileFoundException
|
|
abort "Error: we couldn't find any supported broswer's cookies"
|
|
end
|
|
when '--browser', '-b'
|
|
browser = ARGV[1]
|
|
usage "Error: Please supply a browser name" unless browser
|
|
begin
|
|
CookieExtractor::BrowserDetector.browser_extractor(browser)
|
|
rescue CookieExtractor::InvalidBrowserNameException
|
|
abort "Error: '#{browser}' is not a valid browser name"
|
|
rescue CookieExtractor::NoCookieFileFoundException
|
|
abort "Error: Could not locate cookie file for browser #{browser}"
|
|
end
|
|
when nil
|
|
usage
|
|
else
|
|
filename = ARGV.first
|
|
abort "Error: #{filename} does not exist" unless File.exists?(filename)
|
|
CookieExtractor::BrowserDetector.new_extractor(filename)
|
|
end
|
|
puts extractor.extract.join("\n")
|
|
rescue SQLite3::NotADatabaseException,
|
|
CookieExtractor::BrowserNotDetectedException
|
|
abort "Error: File '#{filename}' is not a Firefox or Chrome cookie database"
|
|
end
|
|
|
|
|