rewrite work and log file cleanup
This commit is contained in:
parent
9e2010266c
commit
f6397e9034
@ -172,6 +172,6 @@ module Apache
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
block_methods :virtual_host, :files_match, :location
|
block_methods :virtual_host, :files_match, :location, :files
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,23 +1,15 @@
|
|||||||
module Apache
|
module Apache
|
||||||
module Logging
|
module Logging
|
||||||
def error_log(*opts)
|
[ :custom, :error, :script, :rewrite ].each do |type|
|
||||||
handle_log 'ErrorLog', opts.first, opts.first, opts[1..-1]
|
class_eval <<-EOT
|
||||||
|
def #{type}_log(*opts)
|
||||||
|
handle_log '#{type.to_s.capitalize}Log', opts.first, opts.first, opts[1..-1]
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_log(*opts)
|
def rotate_#{type}_log(*opts)
|
||||||
handle_log 'CustomLog', opts.first, opts.first, opts[1..-1]
|
handle_log '#{type.to_s.capitalize}Log', opts.first, quoteize(rotatelogs(*opts[0..1])), opts[2..-1]
|
||||||
end
|
end
|
||||||
|
EOT
|
||||||
def rotate_custom_log(*opts)
|
|
||||||
handle_log 'CustomLog', opts.first, quoteize(rotatelogs(*opts[0..1])), opts[2..-1]
|
|
||||||
end
|
|
||||||
|
|
||||||
def rotate_error_log(*opts)
|
|
||||||
handle_log 'ErrorLog', opts.first, quoteize(rotatelogs(*opts[0..1])), opts[2..-1]
|
|
||||||
end
|
|
||||||
|
|
||||||
def rotate_script_log(*opts)
|
|
||||||
handle_log 'ScriptLog', opts.first, quoteize(rotatelogs(*opts[0..1])), opts[2..-1]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def combined_log_format(name = 'combined')
|
def combined_log_format(name = 'combined')
|
||||||
|
@ -46,5 +46,12 @@ module Apache
|
|||||||
end
|
end
|
||||||
|
|
||||||
alias :script_alias! :script_alias
|
alias :script_alias! :script_alias
|
||||||
|
|
||||||
|
def add_type!(mime, extension, options = {})
|
||||||
|
self << "AddType #{mime} #{extension}"
|
||||||
|
options.each do |type, value|
|
||||||
|
self << "Add#{type.to_s.capitalize} #{value} #{extension}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -31,14 +31,27 @@ module Apache
|
|||||||
|
|
||||||
self.instance_eval(&block)
|
self.instance_eval(&block)
|
||||||
|
|
||||||
@rewrites
|
@rewrites.collect(&:to_a).flatten
|
||||||
|
end
|
||||||
|
|
||||||
|
def commit!
|
||||||
|
@rewrites << @rewrite
|
||||||
|
@rewrite = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def ensure_rewrite!
|
||||||
|
@rewrite = RewriteRule.new if !@rewrite
|
||||||
end
|
end
|
||||||
|
|
||||||
def rewrite(*opts)
|
def rewrite(*opts)
|
||||||
@rewrite = RewriteRule.new
|
ensure_rewrite!
|
||||||
@rewrite.rule(*opts)
|
@rewrite.rule(*opts)
|
||||||
|
commit!
|
||||||
|
end
|
||||||
|
|
||||||
@rewrites << @rewrite
|
def cond(*opts)
|
||||||
|
ensure_rewrite!
|
||||||
|
@rewrite.cond(*opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def r301(*opts)
|
def r301(*opts)
|
||||||
@ -63,6 +76,8 @@ module Apache
|
|||||||
end
|
end
|
||||||
|
|
||||||
class MatchableThing
|
class MatchableThing
|
||||||
|
include Apache::Quoteize
|
||||||
|
|
||||||
def tag; raise 'Override this method'; end
|
def tag; raise 'Override this method'; end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@ -75,7 +90,14 @@ module Apache
|
|||||||
def rule(from, to, *opts)
|
def rule(from, to, *opts)
|
||||||
@from = from
|
@from = from
|
||||||
@to = to
|
@to = to
|
||||||
@options = opts
|
@options = opts.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def cond(from, to, *opts)
|
||||||
|
rewrite_cond = RewriteCondition.new
|
||||||
|
rewrite_cond.cond(from, to, *opts)
|
||||||
|
|
||||||
|
@conditions << rewrite_cond
|
||||||
end
|
end
|
||||||
|
|
||||||
def test(from, opts)
|
def test(from, opts)
|
||||||
@ -86,16 +108,27 @@ module Apache
|
|||||||
from
|
from
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_a
|
||||||
output = []
|
output = @conditions.collect(&:to_s)
|
||||||
|
|
||||||
@conditions.each do |condition|
|
|
||||||
|
|
||||||
|
options = @options.collect do |key, value|
|
||||||
|
case key
|
||||||
|
when :last
|
||||||
|
'L'
|
||||||
|
when :preserve_query_string
|
||||||
|
'QSA'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
output << "#{tag} #{[@from.source, @to, @options].flatten * " "}"
|
if !options.empty?
|
||||||
|
options = "[#{options * ','}]"
|
||||||
|
else
|
||||||
|
options = nil
|
||||||
|
end
|
||||||
|
|
||||||
output * "\n"
|
output << "#{tag} #{[quoteize(@from.source), quoteize(@to), options].compact.flatten * " "}"
|
||||||
|
|
||||||
|
output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -106,4 +139,13 @@ end
|
|||||||
class RedirectMatchPermanent < MatchableThing
|
class RedirectMatchPermanent < MatchableThing
|
||||||
def tag; 'RedirectMatch permanent'; end
|
def tag; 'RedirectMatch permanent'; end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class RewriteCondition < MatchableThing
|
||||||
|
def tag; 'RewriteCond'; end
|
||||||
|
alias :cond :rule
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
"#{tag} #{[quoteize(@from), quoteize(@to), @options].flatten * " "}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user