basic test support for rewrite conditions
This commit is contained in:
parent
023925caab
commit
e6d92383e7
@ -14,8 +14,8 @@ module Apache
|
||||
|
||||
alias :allow_from_all! :allow_from_all
|
||||
|
||||
def allow_from(where)
|
||||
allow "from_#{where}".to_sym
|
||||
def allow_from(*where)
|
||||
self << "Allow from #{quoteize(*where) * " "}"
|
||||
end
|
||||
|
||||
def order(*args)
|
||||
@ -39,7 +39,7 @@ module Apache
|
||||
|
||||
alias :order! :order
|
||||
|
||||
def basic_authentication(zone, users_file, requires)
|
||||
def basic_authentication(zone, users_file, requires = {})
|
||||
exist? users_file
|
||||
auth_type :basic
|
||||
auth_name zone
|
||||
@ -51,7 +51,7 @@ module Apache
|
||||
|
||||
alias :basic_authentication! :basic_authentication
|
||||
|
||||
def ldap_authentication(zone, url, requires)
|
||||
def ldap_authentication(zone, url, requires = {})
|
||||
auth_type :basic
|
||||
auth_name zone
|
||||
auth_basic_provider :ldap
|
||||
|
@ -84,10 +84,17 @@ module Apache
|
||||
module RegularExpressionMatcher
|
||||
def test(from, opts = {})
|
||||
from = from.gsub(@from, @to.gsub(/\$([0-9])/) { |m| '\\' + $1 })
|
||||
opts.each do |opt, value|
|
||||
from = from.gsub('%{' + opt.to_s.upcase + '}', value)
|
||||
replace_placeholders(from, opts)
|
||||
end
|
||||
from
|
||||
|
||||
def replace_placeholders(s, opts)
|
||||
opts.each do |opt, value|
|
||||
case value
|
||||
when String
|
||||
s = s.gsub('%{' + opt.to_s.upcase + '}', value)
|
||||
end
|
||||
end
|
||||
s
|
||||
end
|
||||
end
|
||||
|
||||
@ -161,6 +168,19 @@ module Apache
|
||||
|
||||
output
|
||||
end
|
||||
|
||||
def test(from, opts = {})
|
||||
ok = true
|
||||
@conditions.each do |c|
|
||||
ok = false if !c.test(from, opts)
|
||||
end
|
||||
|
||||
if ok
|
||||
super(from, opts)
|
||||
else
|
||||
replace_placeholders(from, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class RedirectMatchPermanent < MatchableThing
|
||||
@ -174,6 +194,8 @@ module Apache
|
||||
end
|
||||
|
||||
class RewriteCondition < MatchableThing
|
||||
include RegularExpressionMatcher
|
||||
|
||||
def tag; 'RewriteCond'; end
|
||||
|
||||
def rule(from, to, *opts)
|
||||
@ -203,5 +225,25 @@ module Apache
|
||||
def to_s
|
||||
"#{tag} #{[quoteize(@from), quoteize(@to), @options].compact.flatten * " "}"
|
||||
end
|
||||
|
||||
def test(from, opts = {})
|
||||
super(from, opts)
|
||||
source = replace_placeholders(@from, opts)
|
||||
|
||||
result = false
|
||||
case @to[0..0]
|
||||
when '!'
|
||||
result = !source[Regexp.new(@to[1..-1])]
|
||||
when '-'
|
||||
case @to
|
||||
when '-f'
|
||||
result = opts[:files].include? source if opts[:files]
|
||||
end
|
||||
else
|
||||
result = source[Regexp.new(@to)]
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user