ptj 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.2"
12
+ gem "rcov", ">= 0"
13
+ gem "rspec", "~> 2.3.0"
14
+ gem "dm-core"
15
+ gem "dm-migrations"
16
+ gem "dm-types"
17
+ gem "dm-transactions"
18
+ gem "dm-aggregates"
19
+ gem "dm-validations"
20
+ gem "dm-serializer"
21
+ gem "dm-timestamps"
22
+ gem "dm-sqlite-adapter"
23
+ gem "dm-postgres-adapter"
24
+ end
@@ -0,0 +1,84 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.6)
5
+ bcrypt-ruby (2.1.4)
6
+ data_objects (0.10.6)
7
+ addressable (~> 2.1)
8
+ diff-lcs (1.1.2)
9
+ dm-aggregates (1.1.0)
10
+ dm-core (~> 1.1.0)
11
+ dm-core (1.1.0)
12
+ addressable (~> 2.2.4)
13
+ dm-do-adapter (1.1.0)
14
+ data_objects (~> 0.10.2)
15
+ dm-core (~> 1.1.0)
16
+ dm-migrations (1.1.0)
17
+ dm-core (~> 1.1.0)
18
+ dm-postgres-adapter (1.1.0)
19
+ dm-do-adapter (~> 1.1.0)
20
+ do_postgres (~> 0.10.2)
21
+ dm-serializer (1.1.0)
22
+ dm-core (~> 1.1.0)
23
+ fastercsv (~> 1.5.4)
24
+ json (~> 1.4.6)
25
+ dm-sqlite-adapter (1.1.0)
26
+ dm-do-adapter (~> 1.1.0)
27
+ do_sqlite3 (~> 0.10.2)
28
+ dm-timestamps (1.1.0)
29
+ dm-core (~> 1.1.0)
30
+ dm-transactions (1.1.0)
31
+ dm-core (~> 1.1.0)
32
+ dm-types (1.1.0)
33
+ bcrypt-ruby (~> 2.1.4)
34
+ dm-core (~> 1.1.0)
35
+ fastercsv (~> 1.5.4)
36
+ json (~> 1.4.6)
37
+ stringex (~> 1.2.0)
38
+ uuidtools (~> 2.1.2)
39
+ dm-validations (1.1.0)
40
+ dm-core (~> 1.1.0)
41
+ do_postgres (0.10.6)
42
+ data_objects (= 0.10.6)
43
+ do_sqlite3 (0.10.6)
44
+ data_objects (= 0.10.6)
45
+ fastercsv (1.5.4)
46
+ git (1.2.5)
47
+ jeweler (1.6.4)
48
+ bundler (~> 1.0)
49
+ git (>= 1.2.5)
50
+ rake
51
+ json (1.4.6)
52
+ rake (0.9.2)
53
+ rcov (0.9.10)
54
+ rspec (2.3.0)
55
+ rspec-core (~> 2.3.0)
56
+ rspec-expectations (~> 2.3.0)
57
+ rspec-mocks (~> 2.3.0)
58
+ rspec-core (2.3.1)
59
+ rspec-expectations (2.3.0)
60
+ diff-lcs (~> 1.1.2)
61
+ rspec-mocks (2.3.0)
62
+ shoulda (2.11.3)
63
+ stringex (1.2.2)
64
+ uuidtools (2.1.2)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ bundler (~> 1.0.0)
71
+ dm-aggregates
72
+ dm-core
73
+ dm-migrations
74
+ dm-postgres-adapter
75
+ dm-serializer
76
+ dm-sqlite-adapter
77
+ dm-timestamps
78
+ dm-transactions
79
+ dm-types
80
+ dm-validations
81
+ jeweler (~> 1.6.2)
82
+ rcov
83
+ rspec (~> 2.3.0)
84
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Josh Grunzweig
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,96 @@
1
+ = PTJ
2
+
3
+ Minimalistic database for the analyzing and storing of passwords.
4
+
5
+ == Using PTJ
6
+
7
+ === Setup
8
+
9
+ First, we want to ensure our configuration file is correct.
10
+
11
+ gem which ptj
12
+ /some/path/gems/ptj-0.1.0/lib/ptj.rb
13
+
14
+ Navigate to the 'etc' directory
15
+
16
+ cd /some/path/gems/ptj-0.1.0/etc/
17
+
18
+ Modify the configuration file to point to the correct database (default is a
19
+ local SQLite database).
20
+
21
+ When this is complete, you can setup a new project as such:
22
+
23
+ require 'ptj'
24
+ PTJ::Model.setup!
25
+ DataMapper.auto_upgrade!
26
+
27
+ === Importing Data
28
+
29
+ There is a provided script which will allow you to import data into the PTJ
30
+ database.
31
+
32
+ Working with our PTJ path above, it can be found in
33
+
34
+ /some/path/gems/ptj-0.1.0/scripts/import.rb
35
+
36
+ Running it, you can see the following options:
37
+
38
+ ruby scripts/import.rb -h
39
+
40
+ Usage: import.rb [opts] -f file|-p password
41
+ -t, --tag TAGS Tags to be used to identify imported passwords (separated by a comma)
42
+ --[no-]strict Enable/Disable Strict Mode
43
+ -f, --file FILENAME File to import.
44
+ -r, --parser NUMBER File parser to use:
45
+ 1 - Password Only
46
+ 2 - Hash:Password
47
+ 3 - Count, Password
48
+ 4 - Something ::: Password ::: Something
49
+ -p, --password PASSWORD Password to import.
50
+ -a, --hash HASH Hash to import (Use in conjunction with -p).
51
+ -h, --help Show this message.
52
+
53
+ If you feel like doing it the hard way, feel free to view the source of this
54
+ script.
55
+
56
+ === Analying Data
57
+
58
+ Again, there is a handy, included, script which can be used to quickly generate
59
+ and 'analysis' of a subset of passwords. It can be found in the 'scripts'
60
+ directory as well.
61
+
62
+ ruby script/analyze.rb -h
63
+
64
+ Usage: analyze.rb [opts]
65
+ -t, --tags TAGS Tags to be used to when querying passwords (separated by a comma)
66
+ --max-size SIZE Maximum size of the resulting passords
67
+ --min-size SIZE Minimum size of the resulting passwords
68
+ --[no-]upper Query based on upper-case letters
69
+ --[no-]lower Query based on lower-case letters
70
+ --[no-]special Query based on special charaters
71
+ --[no-]number Query based on numbers
72
+ -h, --help Show this message
73
+
74
+ == Contributing to ptj
75
+
76
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
77
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
78
+ * Fork the project
79
+ * Start a feature/bugfix branch
80
+ * Commit and push until you are happy with your contribution
81
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
82
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
83
+
84
+ == Copyright
85
+
86
+ Copyright (c) 2011 Josh Grunzweig. See LICENSE.txt for
87
+ further details.
88
+
89
+
90
+ == TODO
91
+
92
+ * Batch imports?
93
+ * specs / unit tests :/
94
+ * benchmark unit tests with various actions
95
+
96
+
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'rake'
4
+
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+
13
+ Dir["tasks/*.rake"].each { |taskfile| load taskfile }
14
+
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "ptj"
19
+ gem.homepage = "http://github.com/jgrunzweig/ptj"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{Password analysis and collection database.}
22
+ gem.description = %Q{An easy way to collect and analyze data about password
23
+ databases.}
24
+ gem.email = "jgrunzweig@gmail.com"
25
+ gem.authors = ["Josh Grunzweig"]
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "ptj #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,23 @@
1
+
2
+ ## The development environment uses sqlite as a database.
3
+ ##
4
+ ## This connection string will cause the sqlite database to be located in
5
+ ## the root directory of the ptj project under 'data/ptj.db'
6
+
7
+ db_conn: "sqlite://$DATADIR$/ptj.db"
8
+
9
+ ## ... Or you can specify a hash of seperated parameters.
10
+ ## The configuration below is loosely based on a production config.yml
11
+ ## which uses postgres as its backend db repository.
12
+
13
+ #db_conn:
14
+ # adapter: 'postgres'
15
+ # database: 'ptj'
16
+ # username: 'ptj'
17
+ # password: 'abc123'
18
+ # host: '172.16.51.145'
19
+
20
+
21
+
22
+
23
+
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'ptj/environment'
3
+ require 'ptj/ext'
4
+ require 'ptj/model'
5
+ require 'ptj/parser'
@@ -0,0 +1,10 @@
1
+ # This is a default setup file you can
2
+ # require as in "require 'ptj/default_setup'"
3
+ # it will automatically use default settings
4
+ # for the configuration and database if they
5
+ # are not specified in the configuration file.
6
+ require 'ptj'
7
+
8
+ PTJ::Env.read_config
9
+ PTJ::Model.setup! unless PTJ::Model.setup?
10
+
@@ -0,0 +1,115 @@
1
+ require 'pathname'
2
+ require 'yaml'
3
+
4
+ module PTJ
5
+ # This module is used in bootstrapping and configuring the
6
+ # PTJ Environment.
7
+ #
8
+ # The "KEY_*" constants in this module specify configuration options
9
+ # that can be used as hash keys via load_config or in the yara formatted
10
+ # configuration file via read_config.
11
+ #
12
+ module Environment
13
+
14
+ LIBROOT = Pathname.new(__FILE__).dirname.dirname.expand_path
15
+ ROOTDIR = LIBROOT.dirname.expand_path
16
+ DATADIR = ROOTDIR.join('data')
17
+
18
+ PTJ_ENV = ((d=ENV['PTJ_ENV']) and not d.empty?)? d : nil
19
+
20
+ CFGDIR = if (d=ENV['PTJ_CFGDIR'])
21
+ Pathname.new(d)
22
+ elsif PTJ_ENV
23
+ ROOTDIR.join('etc', PTJ_ENV)
24
+ else
25
+ ROOTDIR.join('etc')
26
+ end
27
+
28
+ CFGFILE = (d=ENV['PTJ_CFGFILE'])? Pathname.new(d) : CFGDIR.join('config.yml')
29
+
30
+ VERSION = File.read(ROOTDIR.join('VERSION'))
31
+ VERS_MAJOR, VERS_MINOR, VERS_PATCH = VERSION.split('.',3).map{|n| n.to_i}
32
+
33
+ # The 'db_url' configuration option
34
+ KEY_DB_CONN = "db_conn"
35
+
36
+ # The debug configuration option may be set to true or false.
37
+ # If debugging is enabled, certain features in spookt will emit extra
38
+ # debugging information. The default value is false.
39
+ KEY_DEBUG = "debug"
40
+
41
+ CONFIG = {
42
+ KEY_DEBUG => false,
43
+ KEY_DB_CONN => "sqlite::memory:",
44
+ }
45
+
46
+
47
+ # The load config method will load new configuration settings from
48
+ # a hash object. Note, the default configuration settings are overridden
49
+ # by new values specified with this method.
50
+ #
51
+ # Example:
52
+ #
53
+ # # This example enables debugging...
54
+ # Spookt::Environment.load_config "debug" => true
55
+ #
56
+ # Note certain configuration variables are available such as LIBROOT,
57
+ # DATADIR, ROOTDIR, CFGDIR, and can be accessed from config options by enclosing
58
+ # them with the special character '$'. Any constant defined in Spookt::Environment
59
+ # can be accessed this way, actually.
60
+ #
61
+ # Example:
62
+ #
63
+ # # This example sets the samples directory as a subdirectory of
64
+ # # the DATADIR (this is the default, but this does it explicitly)
65
+ # Spookt::Environment.load_config "sample_dir" => "$DATADIR$/samples"
66
+ #
67
+ #
68
+ def self.load_config(hash)
69
+ hash.each do |k,v|
70
+ if v.is_a?(String)
71
+ v = v.gsub(/\$([A-Z][A-Z0-9_]*)\$/) do |v|
72
+ var = $1
73
+ if const_defined?(var)
74
+ const_get(var).to_s
75
+ else
76
+ raise("Invalid variable referenced in configuration: #{v}")
77
+ end
78
+ end
79
+ end
80
+
81
+ CONFIG[k.to_s] = v
82
+ end
83
+ end
84
+
85
+ class ConfigError < StandardError
86
+ end
87
+
88
+ # The load config method will load new configuration settings from
89
+ # a yaml-formatted configuration file. Note, the default configuration
90
+ # settings are overridden by new values specified in the configuration
91
+ # file.
92
+ #
93
+ # The yaml config data is treated as a ruby hash and passed directly to
94
+ # load_config. See load_config for more options.
95
+ #
96
+ def self.read_config(file=CFGFILE)
97
+ begin
98
+ h = YAML.load_file(file)
99
+ rescue
100
+ raise(ConfigError, "Error in file: #{file} -> #{$!}")
101
+ end
102
+ if h.is_a?(Hash)
103
+ load_config(h)
104
+ else
105
+ raise(ConfigError, "invalid ptj config format for file: #{file}")
106
+ end
107
+ end
108
+
109
+ end
110
+
111
+ Env = Environment
112
+
113
+ end
114
+
115
+