Skip to content

Instantly share code, notes, and snippets.

@mnutt
Created May 7, 2010 06:30
Show Gist options
  • Save mnutt/393140 to your computer and use it in GitHub Desktop.
Save mnutt/393140 to your computer and use it in GitHub Desktop.

Revisions

  1. mnutt revised this gist May 16, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ffcurl.rb
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # 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:
    # use curl. Report bugs to michael@nuttnet.net. Or better yet, fork it from:
    #
    # http://gist.github.com/393140
    #
  2. Brian Turnbull revised this gist May 7, 2010. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion ffcurl.rb
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,11 @@
    host = URI.split(url)[2]
    top_level_host = host.split('.').slice(-2, 2).join('.')

    cookie_file = Dir["#{ENV['HOME']}/Library/Application\ Support/Firefox/**/cookies.sqlite"].first
    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")

  3. mnutt revised this gist May 7, 2010. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ffcurl.rb
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,8 @@
    # 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'
  4. @invalid-email-address Anonymous revised this gist May 7, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ffcurl.rb
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    # 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:
    #
    # [ gist link to come ]
    # http://gist.github.com/393140

    require 'rubygems'
    require 'fileutils'
  5. @invalid-email-address Anonymous created this gist May 7, 2010.
    32 changes: 32 additions & 0 deletions ffcurl.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/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:
    #
    # [ gist link to come ]

    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('.')

    cookie_file = Dir["#{ENV['HOME']}/Library/Application\ Support/Firefox/**/cookies.sqlite"].first

    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)