Class HTAuth::Digest
In: lib/htauth/digest.rb
lib/htauth/digest.rb
Parent: Object

Methods

Constants

MAX_PASSWD_LENGTH = 255
MAX_PASSWD_LENGTH = 255

Attributes

digest_file  [RW] 
digest_file  [RW] 

Public Class methods

[Source]

    # File lib/htauth/digest.rb, line 16
16:     def initialize
17:       @digest_file = nil
18:     end

[Source]

    # File lib/htauth/digest.rb, line 16
16:     def initialize
17:       @digest_file = nil
18:     end

Public Instance methods

[Source]

    # File lib/htauth/digest.rb, line 34
34:     def option_parser
35:       if not @option_parser then
36:         @option_parser = OptionParser.new do |op|
37:           op.banner = "Usage: #{op.program_name} [options] passwordfile realm username"
38:           op.on("-c", "--create", "Create a new digest password file; this overwrites an existing file.") do |c|
39:             options.file_mode = DigestFile::CREATE
40:           end
41: 
42:           op.on("-D", "--delete", "Delete the specified user.") do |d|
43:             options.delete_entry = d
44:           end
45: 
46:           op.on("-h", "--help", "Display this help.") do |h|
47:             options.show_help = h
48:           end
49: 
50:           op.on("-v", "--version", "Show version info.") do |v|
51:             options.show_version = v
52:           end
53:         end
54:       end
55:       @option_parser
56:     end

[Source]

    # File lib/htauth/digest.rb, line 34
34:     def option_parser
35:       if not @option_parser then
36:         @option_parser = OptionParser.new do |op|
37:           op.banner = "Usage: #{op.program_name} [options] passwordfile realm username"
38:           op.on("-c", "--create", "Create a new digest password file; this overwrites an existing file.") do |c|
39:             options.file_mode = DigestFile::CREATE
40:           end
41: 
42:           op.on("-D", "--delete", "Delete the specified user.") do |d|
43:             options.delete_entry = d
44:           end
45: 
46:           op.on("-h", "--help", "Display this help.") do |h|
47:             options.show_help = h
48:           end
49: 
50:           op.on("-v", "--version", "Show version info.") do |v|
51:             options.show_version = v
52:           end
53:         end
54:       end
55:       @option_parser
56:     end

[Source]

    # File lib/htauth/digest.rb, line 20
20:     def options
21:       if @options.nil? then
22:         @options                = ::OpenStruct.new
23:         @options.show_version   = false
24:         @options.show_help      = false
25:         @options.file_mode      = DigestFile::ALTER
26:         @options.passwdfile     = nil
27:         @options.realm          = nil
28:         @options.username       = nil
29:         @options.delete_entry   = false
30:       end
31:       @options
32:     end

[Source]

    # File lib/htauth/digest.rb, line 20
20:     def options
21:       if @options.nil? then
22:         @options                = ::OpenStruct.new
23:         @options.show_version   = false
24:         @options.show_help      = false
25:         @options.file_mode      = DigestFile::ALTER
26:         @options.passwdfile     = nil
27:         @options.realm          = nil
28:         @options.username       = nil
29:         @options.delete_entry   = false
30:       end
31:       @options
32:     end

[Source]

    # File lib/htauth/digest.rb, line 68
68:     def parse_options(argv)
69:       begin
70:         option_parser.parse!(argv)
71:         show_version if options.show_version
72:         show_help if options.show_help or argv.size < 3
73: 
74:         options.passwdfile = argv.shift
75:         options.realm      = argv.shift
76:         options.username   = argv.shift
77:       rescue ::OptionParser::ParseError => pe
78:         $stderr.puts "ERROR: #{option_parser.program_name} - #{pe}"
79:         $stderr.puts "Try `#{option_parser.program_name} --help` for more information"
80:         exit 1
81:       end
82:     end

[Source]

    # File lib/htauth/digest.rb, line 68
68:     def parse_options(argv)
69:       begin
70:         option_parser.parse!(argv)
71:         show_version if options.show_version
72:         show_help if options.show_help or argv.size < 3
73: 
74:         options.passwdfile = argv.shift
75:         options.realm      = argv.shift
76:         options.username   = argv.shift
77:       rescue ::OptionParser::ParseError => pe
78:         $stderr.puts "ERROR: #{option_parser.program_name} - #{pe}"
79:         $stderr.puts "Try `#{option_parser.program_name} --help` for more information"
80:         exit 1
81:       end
82:     end

[Source]

     # File lib/htauth/digest.rb, line 84
 84:     def run(argv, env = ENV)
 85:       begin
 86:         parse_options(argv)
 87:         digest_file = DigestFile.new(options.passwdfile, options.file_mode)
 88: 
 89:         if options.delete_entry then
 90:           digest_file.delete(options.username, options.realm)
 91:         else
 92:           # initialize here so that if $stdin is overwritten it gets picked up
 93:           hl = ::HighLine.new
 94: 
 95:           action = digest_file.has_entry?(options.username, options.realm) ? "Changing" : "Adding"
 96: 
 97:           $stdout.puts "#{action} password for #{options.username} in realm #{options.realm}."
 98: 
 99:           pw_in       = hl.ask("        New password: ") { |q| q.echo = '*' } 
100:           raise PasswordError, "password '#{pw_in}' too long" if pw_in.length >= MAX_PASSWD_LENGTH
101: 
102:           pw_validate = hl.ask("Re-type new password: ") { |q| q.echo = '*' }
103:           raise PasswordError, "They don't match, sorry." unless pw_in == pw_validate
104: 
105:           digest_file.add_or_update(options.username, options.realm, pw_in)
106:         end
107: 
108:         digest_file.save!
109: 
110:       rescue HTAuth::FileAccessError => fae
111:         msg = "Could not open password file #{options.passwdfile} "
112:         $stderr.puts "#{msg}: #{fae.message}"
113:         $stderr.puts fae.backtrace.join("\n")
114:         exit 1
115:       rescue HTAuth::PasswordError => pe
116:         $stderr.puts "#{pe.message}"
117:         exit 1
118:       rescue HTAuth::DigestFileError => fe
119:         $stderr.puts "#{fe.message}"
120:         exit 1
121:       rescue SignalException => se
122:         $stderr.puts
123:         $stderr.puts "Interrupted"
124:         exit 1
125:       end
126:       exit 0
127:     end

[Source]

     # File lib/htauth/digest.rb, line 84
 84:     def run(argv, env = ENV)
 85:       begin
 86:         parse_options(argv)
 87:         digest_file = DigestFile.new(options.passwdfile, options.file_mode)
 88: 
 89:         if options.delete_entry then
 90:           digest_file.delete(options.username, options.realm)
 91:         else
 92:           # initialize here so that if $stdin is overwritten it gets picked up
 93:           hl = ::HighLine.new
 94: 
 95:           action = digest_file.has_entry?(options.username, options.realm) ? "Changing" : "Adding"
 96: 
 97:           $stdout.puts "#{action} password for #{options.username} in realm #{options.realm}."
 98: 
 99:           pw_in       = hl.ask("        New password: ") { |q| q.echo = '*' } 
100:           raise PasswordError, "password '#{pw_in}' too long" if pw_in.length >= MAX_PASSWD_LENGTH
101: 
102:           pw_validate = hl.ask("Re-type new password: ") { |q| q.echo = '*' }
103:           raise PasswordError, "They don't match, sorry." unless pw_in == pw_validate
104: 
105:           digest_file.add_or_update(options.username, options.realm, pw_in)
106:         end
107: 
108:         digest_file.save!
109: 
110:       rescue HTAuth::FileAccessError => fae
111:         msg = "Could not open password file #{options.passwdfile} "
112:         $stderr.puts "#{msg}: #{fae.message}"
113:         $stderr.puts fae.backtrace.join("\n")
114:         exit 1
115:       rescue HTAuth::PasswordError => pe
116:         $stderr.puts "#{pe.message}"
117:         exit 1
118:       rescue HTAuth::DigestFileError => fe
119:         $stderr.puts "#{fe.message}"
120:         exit 1
121:       rescue SignalException => se
122:         $stderr.puts
123:         $stderr.puts "Interrupted"
124:         exit 1
125:       end
126:       exit 0
127:     end

[Source]

    # File lib/htauth/digest.rb, line 58
58:     def show_help
59:       $stdout.puts option_parser
60:       exit 1
61:     end

[Source]

    # File lib/htauth/digest.rb, line 58
58:     def show_help
59:       $stdout.puts option_parser
60:       exit 1
61:     end

[Source]

    # File lib/htauth/digest.rb, line 63
63:     def show_version
64:       $stdout.puts "#{option_parser.program_name}: version #{HTAuth::VERSION}"
65:       exit 1
66:     end

[Source]

    # File lib/htauth/digest.rb, line 63
63:     def show_version
64:       $stdout.puts "#{option_parser.program_name}: version #{HTAuth::VERSION}"
65:       exit 1
66:     end

[Validate]