Commit 631a70c6 authored by Patrick J Cherry's avatar Patrick J Cherry
Browse files

* symbiosis-httpd now requires geoip-database, which is neeeded by Webalizer.

Fixes #3741.
* symbiosis-generate-stats updated to be more flexible with file locations.
* symbiosis-generate-stats updated to be more verbose, when required.
* symbiosis-generate-stats now will not create the stats directory unless the
parent directory is owned by the same user.
* Symbiosis::ConfigFiles::Apache now uses Symbiosis::Domain#public_dir.
* Symbiosis::ConfigFiles::Apache has a couple of new methods, htdocs_directory
and cgibin_directory for use in templates.
* The templates have been updated to use these methods.
parent e3790807
......@@ -38,12 +38,12 @@ NameVirtualHost <%= ip %>:80
#
# The document root
#
DocumentRoot <%= domain_directory %>/public/htdocs/
DocumentRoot <%= htdocs_directory %>
#
# General CGI Handling
#
ScriptAlias /cgi-bin/ <%= domain_directory %>/public/cgi-bin/
ScriptAlias /cgi-bin/ <%= cgibin_directory %>
<Location /cgi-bin>
Options +ExecCGI
</Location>
......
......@@ -62,12 +62,12 @@ NameVirtualHost <%= ip %>:80
#
# The document root
#
DocumentRoot <%= domain_directory %>/public/htdocs
DocumentRoot <%= htdocs_directory %>
#
# General CGI Handling
#
ScriptAlias /cgi-bin/ <%= domain_directory %>/public/cgi-bin/
ScriptAlias /cgi-bin/ <%=cgibin_directory %>
<Location /cgi-bin>
Options +ExecCGI
</Location>
......@@ -114,12 +114,12 @@ NameVirtualHost <%= ip %>:80
#
# The document root
#
DocumentRoot <%= domain_directory %>/public/htdocs/
DocumentRoot <%= htdocs_directory %>
#
# General CGI Handling
#
ScriptAlias /cgi-bin/ <%= domain_directory %>/public/cgi-bin/
ScriptAlias /cgi-bin/ <%= cgibin_directory %>
<Location /cgi-bin>
Options +ExecCGI
</Location>
......
symbiosis-httpd (2012:0926) stable; urgency=low
* symbiosis-httpd now requires geoip-database, which is neeeded by
Webalizer. Fixes #3741.
* symbiosis-generate-stats updated to be more flexible with file locations.
* symbiosis-generate-stats updated to be more verbose, when required.
* symbiosis-generate-stats now will not create the stats directory unless
the parent directory is owned by the same user.
* Symbiosis::ConfigFiles::Apache now uses Symbiosis::Domain#public_dir.
* Symbiosis::ConfigFiles::Apache has a couple of new methods,
htdocs_directory and cgibin_directory for use in templates.
* The templates have been updated to use these methods.
-- Patrick J Cherry <patrick@bytemark.co.uk> Wed, 26 Sep 2012 13:20:14 +0100
symbiosis-httpd (2012:0529) stable; urgency=low
* Added manpage for symbiosis-rotate-logs.
......
......@@ -21,7 +21,7 @@ Description: A mass-hosting module for Apache 2.x
Package: symbiosis-httpd
Architecture: all
Depends: apache2, php5-mysql, php5-curl, php5-imagick, php5-mcrypt, php5-mhash, php5-xmlrpc, php5-gd, libapache2-mod-php5, webalizer, libapache2-mod-vhost-bytemark, ${misc:Depends}, symbiosis-httpd-static, symbiosis-common (>= 2012:0208), ruby1.8
Depends: apache2, php5-mysql, php5-curl, php5-imagick, php5-mcrypt, php5-mhash, php5-xmlrpc, php5-gd, libapache2-mod-php5, webalizer, libapache2-mod-vhost-bytemark, ${misc:Depends}, symbiosis-httpd-static, symbiosis-common (>= 2012:0926), ruby1.8, geoip-database
Replaces: bytemark-vhost-httpd, symbiosis-test, symbiosis-monit (<< 2011:1206), symbiosis-httpd-static
Breaks: symbiosis-monit (<< 2011:1206)
Provides: bytemark-vhost-httpd, symbiosis-httpd-static
......
require 'symbiosis/config_file'
require 'symbiosis/domain/http'
require 'tempfile'
module Symbiosis
......@@ -50,7 +51,7 @@ module Symbiosis
# Make sure the file exists, and that it is a symlink pointing to our
# config file
#
if File.symlink?(fn)
if File.symlink?(fn)
ln = File.readlink(fn)
unless ln =~ /^\//
......@@ -109,15 +110,15 @@ module Symbiosis
# Symlink away!
#
File.symlink(self.filename, fn)
nil
end
#
# This disables a site whose configuration is contained in fn. This
# function makes sure that the site is enabled, before disabling it.
#
#
#
#
#
def disable(fn = nil, force = false)
#
......@@ -187,13 +188,35 @@ module Symbiosis
# If no domain has been defined, nil is returned.
#
def domain_directory
if defined?(@domain) and @domain.is_a?(Symbiosis::Domain)
if defined?(@domain) and @domain.is_a?(Symbiosis::Domain)
@domain.directory
else
nil
end
end
#
# Returns the domain's htdocs directory.
#
def htdocs_directory
if defined?(@domain) and @domain.is_a?(Symbiosis::Domain)
@domain.htdocs_dir
else
nil
end
end
#
# Returns the domain's cgi-bin directory.
#
def cgibin_directory
if defined?(@domain) and @domain.is_a?(Symbiosis::Domain)
@domain.cgibin_dir
else
nil
end
end
#
#
# Return a ServerAlias snippet for all server aliases for a domain.
......@@ -212,11 +235,11 @@ module Symbiosis
ans = []
if defined?(@domain) and @domain.is_a?(Symbiosis::Domain)
#
#
#
#
ans << "SSLCertificateFile #{@domain.ssl_certificate_file}"
#
# Add the separate key unless the key is in the certificate.
# Add the separate key unless the key is in the certificate.
#
ans << "SSLCertificateKeyFile #{@domain.ssl_key_file}" unless @domain.ssl_certificate_file == @domain.ssl_key_file
#
......@@ -245,7 +268,7 @@ module Symbiosis
# If no domain is set, then this returns false.
#
def mandatory_ssl?
if defined?(@domain) and @domain.is_a?(Symbiosis::Domain)
if defined?(@domain) and @domain.is_a?(Symbiosis::Domain)
@domain.ssl_mandatory?
else
false
......
......@@ -42,10 +42,25 @@ module Symbiosis
#
# Returns the directory where stats files should be kept. Defaults to
# public/htdocs/stats.
# stats inside the htdocs_dir
#
def stats_dir
File.join(self.directory, "public", "htdocs", "stats")
File.join(self.htdocs_dir "stats")
end
#
# Returns the directory where HTML documents are served from. Defaults to
# public/htdocs
#
def htdocs_dir
File.join(self.public_dir, "htdocs")
end
#
# Return the directory where CGI executables are server
#
def cgibin_dir
File.join(self.public_dir, "cgi-bin")
end
end
......
......@@ -145,39 +145,18 @@ Symbiosis::Domains.each do |domain|
end
#
# OK now we need to look for a logfile, or two.
#
# access.log for HTTP accesses.
# ssl_access.log for HTTPS accesses.
#
process = Array.new()
%w( access.log.1 ssl_access.log.1 ).each do |name|
log = File.join( domain.log_dir, name )
process.push(log) if File.exists?(log)
end
#
# If we didn't find a logfile we're done.
#
if ( process.empty? )
verbose "\tSkipping this domain, no suitable logfiles found"
next
end
#
# Create a configuration file, if one wasn't found.
# Create a configuration file, if one wasn't found.
#
webalizer_conf = File.join( domain.config_dir, "webalizer.conf" )
config = Symbiosis::ConfigFiles::Webalizer.new(webalizer_conf, "#")
config.template = template
config.template = template
config.domain = domain
write_config = false
#
# This is taken from symbiosis-create-stes
# This is taken from symbiosis-create-sites
#
if ( $FORCE )
verbose "\tForcing re-creation of configuration due to --force."
......@@ -210,13 +189,99 @@ Symbiosis::Domains.each do |domain|
#
config.write if write_config
#
# OK now we need to look for a logfile, or two.
#
# access.log for HTTP accesses.
# ssl_access.log for HTTPS accesses.
#
#
# Firstly check when webalizer was last run.
#
last_run = nil
#
# If we don't have a statistics directory then we need to create it,
# and we need to create it with the domains' UID/GID. This method will not
# error if the directory already exists.
# Read webalizer config to find where the history file is kept, so we can see when
#
domain.create_dir( domain.stats_dir )
output_dir = domain.config_dir
history_name = "webalizer.hist"
File.open(config.filename) do |fh|
while line = fh.gets
case line.chomp
when /^ *HistoryName +([^ ]+)/
history_name = $1
when /^ *OutputDir +([^ ]+)/
output_dir = $1
end
end
end
#
# Make sure the output dir is absolute
#
unless output_dir =~ /^\//
output_dir = File.join(domain.config_dir, output_dir)
end
#
# Work out the history file name
#
if history_name =~ /^\//
history_file = history_name
else
history_file = File.join(output_dir, history_name)
end
#
# Now stat() it -- webalizer updates this file with each run.
#
if File.exists?(history_file)
last_run = File.stat(history_file).mtime
end
#
# Now select all the log files, and sort based on mtime.
#
process = Dir.glob(File.join(domain.log_dir,'{ssl_access,access}.log.*')).reject do |log|
last_run and File.stat(log).mtime < last_run
end.sort{|a,b| File.stat(a).mtime <=> File.stat(b).mtime}
#
# If we didn't find a logfile we're done.
#
if ( process.empty? )
verbose "\tSkipping this domain, no suitable logfiles found"
next
end
#
# Iterate through the stats directory until we find a directory that exists,
#
cdir = output_dir
while cdir != "/"
break if File.exists?(cdir)
cdir, odir = File.split(cdir)
end
#
# Now make sure that this directory is owned by the domain's owner.
#
unless File.stat(cdir).uid == domain.uid
if File.symlink?(cdir)
verbose "\tSkipping as #{File.readlink(cdir)} (symlinked from #{cdir}) is not owned by #{domain.user}."
else
verbose "\tSkipping as #{cdir} is not owned by #{domain.user}."
end
next
end
#
# If we don't have a statistics directory then we need to create it, and we
# need to create it with the domains' UID/GID. This method will not error if
# the directory already exists.
#
domain.create_dir( output_dir )
#
# Now process each logfile.
......@@ -226,9 +291,8 @@ Symbiosis::Domains.each do |domain|
#
# Now run it under sudo, as the user ID of the domain.
#
system( "cd #{domain.config_dir} && sudo -u '\##{domain.uid}' -- webalizer -q #{process.join(" ")} >/dev/null 2>/dev/null" )
quiet = ($VERBOSE ? "-d" : "-Q")
system( "cd #{domain.config_dir} && sudo -u '\##{domain.uid}' -- webalizer -c #{webalizer_conf} #{quiet} #{process.join(" ")}" )
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment