Class WEBrick::HTTPAuth::Htpasswd
In: lib/webrick/httpauth/htpasswd.rb
Parent: Object

Methods

delete_passwd   each   flush   get_passwd   new   reload   set_passwd  

Included Modules

UserDB

Public Class methods

[Source]

    # File lib/webrick/httpauth/htpasswd.rb, line 19
19:       def initialize(path)
20:         @path = path
21:         @mtime = Time.at(0)
22:         @passwd = Hash.new
23:         @auth_type = BasicAuth
24:         open(@path,"a").close unless File::exist?(@path)
25:         reload
26:       end

Public Instance methods

[Source]

    # File lib/webrick/httpauth/htpasswd.rb, line 72
72:       def delete_passwd(realm, user)
73:         @passwd.delete(user)
74:       end

[Source]

    # File lib/webrick/httpauth/htpasswd.rb, line 76
76:       def each
77:         @passwd.keys.sort.each{|user|
78:           yield([user, @passwd[user]])
79:         }
80:       end

[Source]

    # File lib/webrick/httpauth/htpasswd.rb, line 51
51:       def flush(output=nil)
52:         output ||= @path
53:         tmp = Tempfile.new("htpasswd", File::dirname(output))
54:         begin
55:           each{|item| tmp.puts(item.join(":")) }
56:           tmp.close
57:           File::rename(tmp.path, output)
58:         rescue
59:           tmp.close(true)
60:         end
61:       end

[Source]

    # File lib/webrick/httpauth/htpasswd.rb, line 63
63:       def get_passwd(realm, user, reload_db)
64:         reload() if reload_db
65:         @passwd[user]
66:       end

[Source]

    # File lib/webrick/httpauth/htpasswd.rb, line 28
28:       def reload
29:         mtime = File::mtime(@path)
30:         if mtime > @mtime
31:           @passwd.clear
32:           open(@path){|io|
33:             while line = io.gets
34:               line.chomp!
35:               case line
36:               when %r!\A[^:]+:[a-zA-Z0-9./]{13}\z!
37:                 user, pass = line.split(":")
38:               when /:\$/, /:\{SHA\}/
39:                 raise NotImplementedError,
40:                       'MD5, SHA1 .htpasswd file not supported'
41:               else
42:                 raise StandardError, 'bad .htpasswd file'
43:               end
44:               @passwd[user] = pass
45:             end
46:           }
47:           @mtime = mtime
48:         end
49:       end

[Source]

    # File lib/webrick/httpauth/htpasswd.rb, line 68
68:       def set_passwd(realm, user, pass)
69:         @passwd[user] = make_passwd(realm, user, pass)
70:       end

[Validate]