oplop 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/bin/oplop +36 -19
  2. data/lib/oplop.rb +9 -7
  3. data/lib/oplop/cli.rb +20 -17
  4. data/lib/oplop/version.rb +1 -1
  5. metadata +52 -88
data/bin/oplop CHANGED
@@ -1,48 +1,65 @@
1
1
  #!/usr/bin/env ruby
2
2
  oplop_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  $LOAD_PATH.unshift(oplop_dir) unless $LOAD_PATH.include?(oplop_dir)
4
+
4
5
  require 'oplop'
5
6
  require 'oplop/cli'
6
7
  require 'highline/import'
8
+ require 'optparse'
7
9
 
10
+ # -- options
11
+ options = {}
12
+ optparse = OptionParser.new do |opts|
13
+ opts.banner = Oplop::Cli.banner
8
14
 
9
- if ARGV.first =~ /\-help|\?/ or ARGV.empty?
10
- puts Oplop::Cli.help
11
- exit 0
12
- end
15
+ options[:verbose] = false
16
+ opts.on( '-v', '--verbose', 'Output the password to STDOUT' ) do
17
+ options[:verbose] = true
18
+ end
13
19
 
14
- new_or_label = ARGV.shift
15
- mode = :query
20
+ options[:new] = false
21
+ opts.on( '-n', '--new', 'New mode (2 prompt for master)') do
22
+ options[:new] = true
23
+ end
24
+
25
+ opts.on( '-h', '--help', 'Display this screen' ) do
26
+ puts opts
27
+ puts "\n"
28
+ puts Oplop::Cli.help
29
+ exit
30
+ end
16
31
 
17
- label = if new_or_label =~ /\-new/
18
- mode = :new
19
- ARGV.shift || ""
20
- else
21
- new_or_label
22
- end
32
+ end.parse!
33
+
34
+ # -- program
35
+ label = ARGV.shift
23
36
 
24
37
  if label.empty?
25
38
  puts "!! You need to pass in a label!"
26
39
  exit 2
27
40
  end
28
41
 
29
-
30
- case mode
31
- when :query
32
- master = ask("Enter your master password: ") { |q| q.echo = "*" }
33
- when :new
42
+ if options[:new]
34
43
  master = ask("Enter your master password: ") { |q| q.echo = "*" }
35
44
  master_confirm = ask("Enter your master password (again): ") { |q| q.echo = "*" }
36
45
  if (master != master_confirm)
37
46
  puts "!! Your master and confirm don't match!"
38
47
  exit 2
39
48
  end
49
+ else
50
+ master = ask("Enter your master password: ") { |q| q.echo = "*" }
40
51
  end
41
52
 
42
53
  password = Oplop.password(:label => label, :master => master)
43
54
 
44
- puts "\n Password for #{label}:\t#{password}\n\n"
55
+ if options[:verbose]
56
+ puts "\n Password for #{label}:\t#{password}\n\n"
57
+ end
45
58
 
46
59
  if Oplop::Cli.copy_to_clipboard(password)
47
- print "This has been copied to your clipboard.\n"
60
+ print "Your #{label} password has been copied to your clipboard. \n"
61
+ else
62
+ print "!! Could not copy to clipboard, try installing xclip. "
63
+ print "Run with --verbose flag to see password on STDOUT." unless options[:verbose]
64
+ print "\n"
48
65
  end
data/lib/oplop.rb CHANGED
@@ -10,31 +10,33 @@ module Oplop
10
10
  #
11
11
  def self.password(args={})
12
12
  unless (args.keys.include?(:master) && args.keys.include?(:label))
13
- raise ArgumentError.new "Master and label are required arguments."
13
+ raise ArgumentError.new 'Master and label are required arguments.'
14
14
  end
15
15
 
16
- master_label = "%s%s" % [ args.delete(:master), args.delete(:label) ]
16
+ master_label = '%s%s' % [ args.delete(:master), args.delete(:label) ]
17
17
 
18
- raise ArgumentError.new "Unknown keys #{args.keys.join(",")}." if args.keys.any?
18
+ raise ArgumentError.new "Unknown keys #{args.keys.join(',')}." if args.keys.any?
19
19
 
20
- password = urlsafe_b64encode(master_label)
20
+
21
+ password = urlsafe_b64encode(Digest::MD5.digest(master_label))
21
22
 
22
23
  if password.respond_to?(:encode)
23
24
  password = password.encode('UTF-8')
24
25
  end
25
26
 
26
27
  if m = password.match(/\d+/)
27
- password = "%s%s" % [ m[0], password ] if (m.begin(0) >= LENGTH)
28
+ password = '%s%s' % [ m[0], password ] if (m.begin(0) >= LENGTH)
28
29
  else
29
- password = "1%s" % password
30
+ password = '1%s' % password
30
31
  end
31
32
 
32
33
  password[0,LENGTH]
33
34
  end
34
35
 
35
36
  # See http://www.ietf.org/rfc/rfc4648.txt
37
+ # Ruby 1.8.x does not have this as part of the Base64 lib
36
38
  def self.urlsafe_b64encode(string)
37
- Base64.encode64(Digest::MD5.digest(string)).tr('+/', '-_').gsub("\n",'')
39
+ Base64.encode64(string).tr('+/', '-_')
38
40
  end
39
41
 
40
42
  end
data/lib/oplop/cli.rb CHANGED
@@ -1,32 +1,35 @@
1
1
  module Oplop
2
2
  module Cli
3
-
3
+
4
+ def self.banner
5
+ "Usage: oplop [OPTIONS] [label]"
6
+ end
7
+
4
8
  def self.help
5
9
  help = <<-HELP
6
- Usage: oplap [OPTION] [label]
7
-
8
- Simple cli program to generate oplap passwords.
10
+ This is a simple cli program to generate oplop passwords.
9
11
 
10
- You will be prompted for your master password. If you are
11
- on a Mac (or have pbcopy installed), or if you have xclip
12
- installed, the password will be copied to your clipboard.
12
+ You will be prompted for your master password.
13
13
 
14
- Options:
14
+ The default behavior is to copy the password to your clipboard, and
15
+ not display it. This works if you are on a Mac (and/or have pbcopy
16
+ installed), or if you have xclip (installed for Linux).
15
17
 
16
- --help : This help message
17
- --new : Runs in new mode, double prompts for
18
- master password.
19
-
20
- Examples:
18
+ If you do not have pbcopy or xclip, you will have to run the program
19
+ in verbose mode (--verbose).
21
20
 
22
- Get my github password:
21
+ Here are some examples:
23
22
 
24
- oplap github
23
+ Copy my github password to clipboard:
24
+ oplop github
25
25
 
26
- Generate a new password for amazon:
26
+ Print my gmail password to STDOUT.
27
+ oplop --verbose gmail
27
28
 
28
- oplap --new amazon
29
+ Copy a new password for amazon (prompts for master twice):
30
+ oplop --new amazon
29
31
 
32
+ Feedback, patches and bugs: https://github.com/bkaney/oplop
30
33
  HELP
31
34
  end
32
35
 
data/lib/oplop/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Oplop
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,95 +1,69 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: oplop
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease: !!null
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Brian Kaney
14
- autorequire:
9
+ autorequire: !!null
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-05-12 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-05-14 00:00:00.000000000 -04:00
13
+ default_executable: !!null
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: highline
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &85745850 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
19
+ requirements:
27
20
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 13
30
- segments:
31
- - 1
32
- - 6
33
- - 1
21
+ - !ruby/object:Gem::Version
34
22
  version: 1.6.1
35
23
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: ruby-debug19
39
24
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *85745850
26
+ - !ruby/object:Gem::Dependency
27
+ name: ruby-debug19
28
+ requirement: &85789370 !ruby/object:Gem::Requirement
41
29
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
49
34
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: rspec
53
35
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *85789370
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &85789090 !ruby/object:Gem::Requirement
55
40
  none: false
56
- requirements:
41
+ requirements:
57
42
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 23
60
- segments:
61
- - 2
62
- - 6
63
- - 0
43
+ - !ruby/object:Gem::Version
64
44
  version: 2.6.0
65
45
  type: :development
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: yajl-ruby
69
46
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *85789090
48
+ - !ruby/object:Gem::Dependency
49
+ name: yajl-ruby
50
+ requirement: &85788830 !ruby/object:Gem::Requirement
71
51
  none: false
72
- requirements:
52
+ requirements:
73
53
  - - ~>
74
- - !ruby/object:Gem::Version
75
- hash: 59
76
- segments:
77
- - 0
78
- - 8
79
- - 2
54
+ - !ruby/object:Gem::Version
80
55
  version: 0.8.2
81
56
  type: :development
82
- version_requirements: *id004
57
+ prerelease: false
58
+ version_requirements: *85788830
83
59
  description: Provides a ruby library and command line tool for Oplop
84
- email:
60
+ email:
85
61
  - brian@vermonster.com
86
- executables:
62
+ executables:
87
63
  - oplop
88
64
  extensions: []
89
-
90
65
  extra_rdoc_files: []
91
-
92
- files:
66
+ files:
93
67
  - .gitignore
94
68
  - Gemfile
95
69
  - README.md
@@ -105,36 +79,26 @@ files:
105
79
  has_rdoc: true
106
80
  homepage: http://github.com/bkaney/oplop
107
81
  licenses: []
108
-
109
- post_install_message:
82
+ post_install_message: !!null
110
83
  rdoc_options: []
111
-
112
- require_paths:
84
+ require_paths:
113
85
  - lib
114
- required_ruby_version: !ruby/object:Gem::Requirement
86
+ required_ruby_version: !ruby/object:Gem::Requirement
115
87
  none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: 3
120
- segments:
121
- - 0
122
- version: "0"
123
- required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
93
  none: false
125
- requirements:
126
- - - ">="
127
- - !ruby/object:Gem::Version
128
- hash: 3
129
- segments:
130
- - 0
131
- version: "0"
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
132
98
  requirements: []
133
-
134
99
  rubyforge_project: oplop
135
- rubygems_version: 1.3.7
136
- signing_key:
100
+ rubygems_version: 1.5.0
101
+ signing_key: !!null
137
102
  specification_version: 3
138
103
  summary: Oplop for Ruby
139
104
  test_files: []
140
-