diff --git a/lib/apache/config.rb b/lib/apache/config.rb
index fe37268..45e85f0 100644
--- a/lib/apache/config.rb
+++ b/lib/apache/config.rb
@@ -8,11 +8,17 @@ module Apache
include Apache::Master
include Apache::Quoteize
include Apache::Permissions
+ include Apache::Directories
+ include Apache::Logging
def build(target = nil, &block)
reset!
self.instance_eval(&block)
+
+ File.open(target, 'w') { |f| f.puts @config * "\n" } if target
+
+ @config
end
# Reset the current settings
@@ -35,7 +41,7 @@ module Apache
#
# Split the provided name on underscores and capitalize the individual parts
def apachify(name)
- name.to_s.split("_").collect(&:capitalize).join
+ name.to_s.split("_").collect(&:capitalize).join.gsub('Ssl', 'SSL')
end
# Handle options that aren't specially handled
@@ -60,28 +66,57 @@ module Apache
end
end
+ def if_module(mod, &block)
+ blockify(apachify('if_module'), "#{mod}_module".to_sym, &block)
+ end
+
+ def directory(dir, &block)
+ directory? dir
+ blockify(apachify('directory'), dir, &block)
+ end
+
# Handle the blockification of a provided block
def blockify(tag_name, name, &block)
start = [ tag_name ]
case name
when String
- start << quoteize(name).first if name
+ start << quoteize(name).first
when Array
- start << (quoteize(*name) * " ") if name
+ start << (quoteize(*name) * " ")
+ when Symbol
+ start << name.to_s
end
start = start.join(' ')
- self << "" if (@indent == 0)
+ self << "" if (@line_indent == 0)
self << "<#{start}>"
@line_indent += 1
self.instance_eval(&block)
@line_indent -= 1
self << "#{tag_name}>"
end
+
+ def apache_include(*opts)
+ self << "Include #{opts * " "}"
+ end
+
+ private
+ def writable?(path)
+ if !File.directory? File.split(path).first
+ puts "[warn] #{path} may not be writable!"
+ end
+ end
+
+ def directory?(path)
+ if !File.directory? path
+ puts "[warn] #{path} does not exist!"
+ end
+ end
+
end
- block_methods :if_module, :directory, :virtual_host
+ block_methods :virtual_host, :files_match
end
end
diff --git a/lib/apache/directory.rb b/lib/apache/directory.rb
new file mode 100644
index 0000000..383c52c
--- /dev/null
+++ b/lib/apache/directory.rb
@@ -0,0 +1,8 @@
+module Apache
+ module Directories
+ def options(*opt)
+ opt = opt.collect { |o| apachify(o) }
+ self << "Options #{opt * " "}"
+ end
+ end
+end
diff --git a/lib/apache/logging.rb b/lib/apache/logging.rb
new file mode 100644
index 0000000..5766131
--- /dev/null
+++ b/lib/apache/logging.rb
@@ -0,0 +1,21 @@
+module Apache
+ module Logging
+ def error_log(*opts)
+ writable? opts.first
+ self << "ErrorLog #{opts * " "}"
+ end
+
+ def custom_log(*opts)
+ writable? opts.first
+ self << "CustomLog #{opts * " "}"
+ end
+
+ def combined_log_format(name = 'combined')
+ log_format '%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"', name.to_sym
+ end
+
+ def common_log_format(name = 'common')
+ log_format '%h %l %u %t \"%r\" %>s %b', name.to_sym
+ end
+ end
+end
diff --git a/lib/apache/master.rb b/lib/apache/master.rb
index 0a97bee..4a87120 100644
--- a/lib/apache/master.rb
+++ b/lib/apache/master.rb
@@ -15,10 +15,13 @@ module Apache
passenger_ruby "#{ruby_root}/bin/ruby"
end
- def order(*args)
- self << "Order #{args * ','}"
+ def enable_gzip!
+ directory '/' do
+ add_output_filter_by_type! :DEFLATE, 'text/html', 'text/plain', 'text/css', 'text/javascript', 'application/javascript'
+ browser_match! '^Mozilla/4', "gzip-only-text/html"
+ browser_match! '^Mozilla/4\.0[678]', "no-gzip"
+ browser_match! '\bMSIE', '!no-gzip', '!gzip-only-text/html'
+ end
end
-
- alias :order! :order
end
end
diff --git a/lib/apache/modules.rb b/lib/apache/modules.rb
index c080ab8..75c8fab 100644
--- a/lib/apache/modules.rb
+++ b/lib/apache/modules.rb
@@ -17,7 +17,7 @@ module Apache
modules.each { |m| self.send(m) }
self.instance_eval(&block) if block
- @modules
+ [ '' ] + @modules + [ '' ]
end
def method_missing(method, *args)
diff --git a/lib/apache/permissions.rb b/lib/apache/permissions.rb
index 99fec4f..3b62645 100644
--- a/lib/apache/permissions.rb
+++ b/lib/apache/permissions.rb
@@ -9,5 +9,26 @@ module Apache
order :allow, :deny
allow :from_all
end
+
+ def order(*args)
+ self << "Order #{args * ','}"
+ end
+
+ def default_restrictive!
+ directory '/' do
+ options :follow_sym_links
+ allow_override :none
+ deny_from_all
+ end
+ end
+
+ def no_htfiles!
+ files_match '^\.ht' do
+ deny_from_all
+ satisfy :all
+ end
+ end
+
+ alias :order! :order
end
end
diff --git a/lib/apache/rake/create.rb b/lib/apache/rake/create.rb
new file mode 100644
index 0000000..b13e358
--- /dev/null
+++ b/lib/apache/rake/create.rb
@@ -0,0 +1,24 @@
+require 'fileutils'
+require 'apache/config'
+require 'apache/rake/create'
+require 'yaml'
+
+namespace :apache do
+ desc "Create all defined configs for the specified environment"
+ task :create, :environment do |t, args|
+ APACHE_ENV = (args[:environment] || 'production').to_sym
+
+ CONFIG = YAML.load_file('config.yml')
+
+ CONFIG['source_path'] = File.expand_path(CONFIG['source'])
+ CONFIG['dest_path'] = File.expand_path(CONFIG['destination'])
+
+ FileUtils.mkdir_p CONFIG['dest_path']
+ Dir.chdir CONFIG['dest_path']
+
+ Dir[File.join(CONFIG['source_path'], '**', '*.rb')].each do |file|
+ puts file
+ require file
+ end
+ end
+end
diff --git a/lib/apache/ssl.rb b/lib/apache/ssl.rb
new file mode 100644
index 0000000..e69de29
diff --git a/spec/config_spec.rb b/spec/config_spec.rb
index 9c3f946..8f29bdc 100644
--- a/spec/config_spec.rb
+++ b/spec/config_spec.rb
@@ -29,6 +29,7 @@ describe Apache::Config, "should handle the basics of Apache config" do
it "should Apachify the name" do
Apache::Config.apachify("test").should == "Test"
Apache::Config.apachify("test_full_name").should == "TestFullName"
+ Apache::Config.apachify("ssl_option").should == "SSLOption"
end
it "should quoteize properly" do
@@ -39,13 +40,13 @@ describe Apache::Config, "should handle the basics of Apache config" do
it "should blockify a block" do
Apache::Config.blockify("Tag", [ 'part', 'part2' ]) do
something "goes here"
- end.should == ['', ' Something "goes here"', '']
+ end.should == ['', '', ' Something "goes here"', '']
Apache::Config.reset!
Apache::Config.blockify("Tag", 'part') do
something "goes here"
- end.should == ['', ' Something "goes here"', '']
+ end.should == ['', '', ' Something "goes here"', '']
end
it "should handle a build" do
diff --git a/spec/master_spec.rb b/spec/master_spec.rb
index 50964cc..2ac9afe 100644
--- a/spec/master_spec.rb
+++ b/spec/master_spec.rb
@@ -11,9 +11,17 @@ describe Apache::Master, "should provide basic helpers for configuration" do
end
Apache::Config.config.should == [
+ '',
'LoadModule "this_module" "modules/mod_this.so"',
'LoadModule "that_module" "modules/mod_that.so"',
'LoadModule "my_module" "is here"',
+ ''
]
end
+
+ it "should set up the runner" do
+ Apache::Config.runner('test', 'test2')
+
+ Apache::Config.config.should == [ 'User test', 'Group test2' ]
+ end
end
diff --git a/spec/modules_spec.rb b/spec/modules_spec.rb
index 2c6f1ec..9688795 100644
--- a/spec/modules_spec.rb
+++ b/spec/modules_spec.rb
@@ -15,9 +15,11 @@ describe Apache::Modules, "should build a list of modules" do
Apache::Modules.build(:this, :that) do
mine "my_path"
end.should == [
+ '',
'LoadModule "this_module" "modules/mod_this.so"',
'LoadModule "that_module" "modules/mod_that.so"',
- 'LoadModule "mine_module" "my_path"'
+ 'LoadModule "mine_module" "my_path"',
+ ''
]
end
end