cookie_extractor 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +28 -0
- data/README.md +22 -0
- data/Rakefile +1 -0
- data/bin/cookie_extractor +11 -0
- data/cookie_extractor.gemspec +23 -0
- data/lib/cookie_extractor/firefox_cookie_extractor.rb +43 -0
- data/lib/cookie_extractor/version.rb +3 -0
- data/lib/cookie_extractor.rb +5 -0
- data/spec/cookie_extractor_spec.rb +6 -0
- data/spec/firefox_cookie_extractor_spec.rb +116 -0
- data/spec/spec_helper.rb +2 -0
- metadata +108 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use default@cookie-extractor
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cookie_extractor (0.0.1)
|
5
|
+
sqlite3-ruby
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
rspec (2.8.0)
|
12
|
+
rspec-core (~> 2.8.0)
|
13
|
+
rspec-expectations (~> 2.8.0)
|
14
|
+
rspec-mocks (~> 2.8.0)
|
15
|
+
rspec-core (2.8.0)
|
16
|
+
rspec-expectations (2.8.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.8.0)
|
19
|
+
sqlite3 (1.3.5)
|
20
|
+
sqlite3-ruby (1.3.3)
|
21
|
+
sqlite3 (>= 1.3.3)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
cookie_extractor!
|
28
|
+
rspec
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
cookie_extractor
|
2
|
+
----------------
|
3
|
+
|
4
|
+
Extract cookies from Firefox sqlite cookie store (eventually Chrome also) into a wget-compatible cookies.txt file.
|
5
|
+
|
6
|
+
### Install ###
|
7
|
+
|
8
|
+
gem install cookie_extractor
|
9
|
+
|
10
|
+
### Usage ###
|
11
|
+
|
12
|
+
cookie_extractor /path/to/firefox/cookies.sqlite > cookies.txt
|
13
|
+
|
14
|
+
### License ###
|
15
|
+
|
16
|
+
Copyright (c) 2012 Jeff Dallien
|
17
|
+
|
18
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
19
|
+
|
20
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
21
|
+
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "cookie_extractor"))
|
4
|
+
|
5
|
+
# TODO: detect firefox or chrome input file and/or locate it automatically
|
6
|
+
filename = ARGV.first
|
7
|
+
if filename
|
8
|
+
puts CookieExtractor::FirefoxCookieExtractor.new(filename).extract.join("\n")
|
9
|
+
else
|
10
|
+
puts "Usage: cookie_extractor /path/to/cookies.sqlite"
|
11
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cookie_extractor/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "cookie_extractor"
|
7
|
+
s.version = CookieExtractor::VERSION
|
8
|
+
s.authors = ["Jeff Dallien"]
|
9
|
+
s.email = ["jeff@dallien.net"]
|
10
|
+
s.homepage = "http://github.com/jdallien/cookie_extractor"
|
11
|
+
s.summary = %q{Create cookies.txt from Firefox cookies}
|
12
|
+
s.description = %q{Extract cookies from Firefox sqlite databases into a wget-compatible cookies.txt file.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "cookie_extractor"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
s.add_runtime_dependency "sqlite3-ruby"
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'sqlite3'
|
2
|
+
|
3
|
+
module CookieExtractor
|
4
|
+
class FirefoxCookieExtractor
|
5
|
+
|
6
|
+
def initialize(cookie_file)
|
7
|
+
@cookie_file = cookie_file
|
8
|
+
end
|
9
|
+
|
10
|
+
def extract
|
11
|
+
db = SQLite3::Database.new @cookie_file
|
12
|
+
db.results_as_hash = true
|
13
|
+
@result = []
|
14
|
+
db.execute("SELECT * FROM moz_cookies") do |row|
|
15
|
+
@result << [ row['host'],
|
16
|
+
true_false_word(is_domain_wide(row['host'])),
|
17
|
+
row['path'],
|
18
|
+
true_false_word(row['isSecure']),
|
19
|
+
row['expiry'],
|
20
|
+
row['name'],
|
21
|
+
row['value']
|
22
|
+
].join("\t")
|
23
|
+
end
|
24
|
+
@result
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def is_domain_wide(hostname)
|
30
|
+
hostname[0..0] == "."
|
31
|
+
end
|
32
|
+
|
33
|
+
def true_false_word(value)
|
34
|
+
if value == "1" || value == 1 || value == true
|
35
|
+
"TRUE"
|
36
|
+
elsif value == "0" || value == 0 || value == false
|
37
|
+
"FALSE"
|
38
|
+
else
|
39
|
+
raise "Invalid value passed to true_false_word: #{value.inspect}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe CookieExtractor::FirefoxCookieExtractor do
|
4
|
+
before :each do
|
5
|
+
@fake_cookie_db = double("cookie database", :results_as_hash= => true)
|
6
|
+
SQLite3::Database.should_receive(:new).
|
7
|
+
with('filename').
|
8
|
+
and_return(@fake_cookie_db)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "with a cookie that has a host starting with a dot" do
|
12
|
+
before :each do
|
13
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
14
|
+
{'host' => '.dallien.net',
|
15
|
+
'path' => '/',
|
16
|
+
'isSecure' => '0',
|
17
|
+
'expiry' => '1234567890',
|
18
|
+
'name' => 'NAME',
|
19
|
+
'value' => 'VALUE'})
|
20
|
+
@extractor = CookieExtractor::FirefoxCookieExtractor.new('filename')
|
21
|
+
@result = @extractor.extract
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return one cookie string" do
|
25
|
+
@result.size.should == 1
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should put TRUE in the domain wide field" do
|
29
|
+
cookie_string = @result.first
|
30
|
+
cookie_string.split("\t")[1].should == "TRUE"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should put FALSE in the secure field" do
|
34
|
+
cookie_string = @result.first
|
35
|
+
cookie_string.split("\t")[3].should == "FALSE"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should build the correct cookie string" do
|
39
|
+
cookie_string = @result.first
|
40
|
+
cookie_string.should ==
|
41
|
+
".dallien.net\tTRUE\t/\tFALSE\t1234567890\tNAME\tVALUE"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "with a cookie that has a host not starting with a dot" do
|
46
|
+
before :each do
|
47
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
48
|
+
{ 'host' => 'jeff.dallien.net',
|
49
|
+
'path' => '/path',
|
50
|
+
'isSecure' => '1',
|
51
|
+
'expiry' => '1234567890',
|
52
|
+
'name' => 'NAME',
|
53
|
+
'value' => 'VALUE'})
|
54
|
+
@extractor = CookieExtractor::FirefoxCookieExtractor.new('filename')
|
55
|
+
@result = @extractor.extract
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return one cookie string" do
|
59
|
+
@result.size.should == 1
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should put FALSE in the domain wide field" do
|
63
|
+
cookie_string = @result.first
|
64
|
+
cookie_string.split("\t")[1].should == "FALSE"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should put TRUE in the secure field" do
|
68
|
+
cookie_string = @result.first
|
69
|
+
cookie_string.split("\t")[3].should == "TRUE"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should build the correct cookie string" do
|
73
|
+
cookie_string = @result.first
|
74
|
+
cookie_string.should ==
|
75
|
+
"jeff.dallien.net\tFALSE\t/path\tTRUE\t1234567890\tNAME\tVALUE"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "with a cookie that is not marked as secure" do
|
80
|
+
before :each do
|
81
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
82
|
+
{'host' => '.dallien.net',
|
83
|
+
'path' => '/',
|
84
|
+
'isSecure' => '0',
|
85
|
+
'expiry' => '1234567890',
|
86
|
+
'name' => 'NAME',
|
87
|
+
'value' => 'VALUE'})
|
88
|
+
@extractor = CookieExtractor::FirefoxCookieExtractor.new('filename')
|
89
|
+
@result = @extractor.extract
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should put FALSE in the secure field" do
|
93
|
+
cookie_string = @result.first
|
94
|
+
cookie_string.split("\t")[3].should == "FALSE"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "with a cookie that is marked as secure" do
|
99
|
+
before :each do
|
100
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
101
|
+
{'host' => '.dallien.net',
|
102
|
+
'path' => '/',
|
103
|
+
'isSecure' => '1',
|
104
|
+
'expiry' => '1234567890',
|
105
|
+
'name' => 'NAME',
|
106
|
+
'value' => 'VALUE'})
|
107
|
+
@extractor = CookieExtractor::FirefoxCookieExtractor.new('filename')
|
108
|
+
@result = @extractor.extract
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should put TRUE in the secure field" do
|
112
|
+
cookie_string = @result.first
|
113
|
+
cookie_string.split("\t")[3].should == "TRUE"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cookie_extractor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jeff Dallien
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-20 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: sqlite3-ruby
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Extract cookies from Firefox sqlite databases into a wget-compatible cookies.txt file.
|
50
|
+
email:
|
51
|
+
- jeff@dallien.net
|
52
|
+
executables:
|
53
|
+
- cookie_extractor
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- .rvmrc
|
61
|
+
- Gemfile
|
62
|
+
- Gemfile.lock
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- bin/cookie_extractor
|
66
|
+
- cookie_extractor.gemspec
|
67
|
+
- lib/cookie_extractor.rb
|
68
|
+
- lib/cookie_extractor/firefox_cookie_extractor.rb
|
69
|
+
- lib/cookie_extractor/version.rb
|
70
|
+
- spec/cookie_extractor_spec.rb
|
71
|
+
- spec/firefox_cookie_extractor_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://github.com/jdallien/cookie_extractor
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project: cookie_extractor
|
103
|
+
rubygems_version: 1.4.2
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Create cookies.txt from Firefox cookies
|
107
|
+
test_files: []
|
108
|
+
|