-
-
Save jmazzi/629396 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# ffcurl | |
# | |
# This curl that automatically uses your firefox cookies. Use it like you would normally | |
# use curl. Report bugs to [email protected]. Or better yet, fork it from: | |
# | |
# http://gist.github.com/393140 | |
# | |
# Also for webkit/safari: http://gist.github.com/393141 | |
require 'rubygems' | |
require 'fileutils' | |
require 'sqlite3' | |
require 'uri' | |
url = ARGV.select{|a| a =~ /http/ }.first | |
host = URI.split(url)[2] | |
top_level_host = host.split('.').slice(-2, 2).join('.') | |
if File.directory? "#{ENV['HOME']}/Library" | |
cookie_file = Dir["#{ENV['HOME']}/Library/Application\ Support/Firefox/**/cookies.sqlite"].first | |
else | |
cookie_file = Dir["#{ENV['HOME']}/.mozilla/firefox/**/cookies.sqlite"].first | |
end | |
FileUtils.cp(cookie_file, "/tmp/.ffcurl_db") | |
db = SQLite3::Database.new("/tmp/.ffcurl_db") | |
File.open("/tmp/.ffcurl_cookie", "w") do |f| | |
db.execute("SELECT host, 'TRUE', path, case isSecure when 0 then 'FALSE' else 'TRUE' end, expiry, name, value FROM moz_cookies WHERE host LIKE '%#{top_level_host}'") do |row| | |
f.write(row.join("\t") + "\n") | |
end | |
end | |
cmd = "curl " + ARGV.join(' ') + " --cookie /tmp/.ffcurl_cookie" | |
Kernel.exec(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment