Skip to content

Instantly share code, notes, and snippets.

@markauskas
Forked from mnutt/ffcurl.rb
Created May 11, 2010 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markauskas/397746 to your computer and use it in GitHub Desktop.
Save markauskas/397746 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# ffcurl
#
# This curl that automatically uses your firefox cookies. Use it like you would normally
# use curl. Report bugs to michael@nuttnet. 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