-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtaccess_checker.rb
More file actions
31 lines (27 loc) · 808 Bytes
/
htaccess_checker.rb
File metadata and controls
31 lines (27 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'digest'
require 'base64'
require_relative 'htaccess'
#Class to check if user is authorized
class HtaccessChecker
def initialize(path, headers)
@path = path
@headers = headers
end
def protected?
file = File.exist?(@path)
end
def can_authorize?
encrypted_string = @headers["Authorization"]
encrypted_string != nil ? true : false
end
def authorized?
htaccess = Htaccess.new(File.readlines(@path))
htaccess.load
file = File.open(htaccess.auth_user_file, 'r')
content = file.read()
encrypted_string = @headers["Authorization"].split("Basic")
decoded_string = Base64.decode64(encrypted_string[1])
sha_encoded_string = Digest::SHA1.base64digest(decoded_string.split(":")[1])
content.include?(sha_encoded_string) ? true : false
end
end