Class: RouterCrypt::CLI
- Inherits:
-
Object
- Object
- RouterCrypt::CLI
- Defined in:
- lib/cli/cli.rb
Class Method Summary collapse
Class Method Details
.opts_parse ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/cli/cli.rb', line 32 def opts_parse Slop.parse do |o| o.on '-h', '--help' do puts o; exit; end o.bool '-D', '--debug', 'turn on debugging' o.string '-j', '--junipercrypt', 'crypt Juniper' o.string '-s', '--salt', 'salt for crypt' o.string '-d', '--decrypt', 'decrypt' end end |
.run ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cli/cli.rb', line 7 def run opts=opts_parse.to_hash #ARGV[0] or raise ArgumentError, 'no password given' if opts[:junipercrypt] pw=opts[:junipercrypt] if opts[:salt] RouterCrypt::JunOS.crypt(opts[:junipercrypt], opts[:salt]) else RouterCrypt::JunOS.crypt opts[:junipercrypt] end elsif opts [:decrypt] pw=opts[:decrypt].dup case pw when /^\$9\$/ RouterCrypt::JunOS.decrypt pw when /^[\dA-F]+$/ RouterCrypt::IOS.decrypt pw else #presume it's NXOS, no clear way to separate garbage and NXOS PW RouterCrypt::NXOS.decrypt pw end end end |