diff --git a/httpd/debian/control b/httpd/debian/control index 94689c37..bb86b020 100644 --- a/httpd/debian/control +++ b/httpd/debian/control @@ -9,7 +9,7 @@ XS-Ruby-Versions: all Package: symbiosis-httpd Architecture: all -Depends: apache2, libapache2-mod-php7.0, webalizer, libapache2-mod-vhost-bytemark (>= 2015:0101), ${misc:Depends}, symbiosis-common (>= 2017:0328), ruby | ruby-interpreter, ruby-eventmachine +Depends: apache2, libapache2-mod-php7.0, webalizer, libapache2-mod-vhost-bytemark (>= 2015:0101), ${misc:Depends}, symbiosis-common (>= 2017:0328), ruby | ruby-interpreter, ruby-eventmachine, ruby-diffy Recommends: php7.0-mysql | php7.0-mysqli | php7.0-mysqlnd, php7.0-curl, php7.0-imagick, php7.0-mcrypt, php7.0-mhash, php7.0-xmlrpc, php7.0-gd, geoip-database Description: Tools to manage Apache virtual hosting in Symbiosis This package contains tools to manage the virtual hosting of websites diff --git a/httpd/lib/symbiosis/config_files/apache.rb b/httpd/lib/symbiosis/config_files/apache.rb index 0a723a6b..c1453c84 100644 --- a/httpd/lib/symbiosis/config_files/apache.rb +++ b/httpd/lib/symbiosis/config_files/apache.rb @@ -2,6 +2,7 @@ require 'symbiosis/domain/http' require 'symbiosis/host' require 'tempfile' +require 'diffy' module Symbiosis module ConfigFiles @@ -36,6 +37,19 @@ def ok? end end + def diff + config = self.generate_config(self.template) + + tempfile = Tempfile.new(File.basename(self.filename)) + tempfile.puts(config) + tempfile.close(false) + + fn = ( File.exists?(self.filename) ? self.filename : '/dev/null' ) + + Diffy::Diff.new(fn, tempfile.path, :source => 'files', :include_diff_info => true) + ensure + tmpfile.unlink + end # # This checks a site has its config file linked into the sites-enabled @@ -275,7 +289,7 @@ def mandatory_ssl? false end end - + # # This returns the FQDN # diff --git a/httpd/sbin/symbiosis-httpd-configure b/httpd/sbin/symbiosis-httpd-configure index a9926764..3f94b233 100755 --- a/httpd/sbin/symbiosis-httpd-configure +++ b/httpd/sbin/symbiosis-httpd-configure @@ -33,6 +33,9 @@ # non-SSL sites. Defaults to # /etc/symbiosis/apache.d/zz-mass-hosting.template.erb # +# --diff-only, -d Show the differences in the new configuration, without +# making any changes. +# # --force, -f Force the re-creation of all sites. # # --no-reload, -n Do not reload Apache even if changes have taken place. @@ -120,12 +123,14 @@ mass_non_ssl_template = nil mass_ssl_template = nil apache2_dir = nil no_reload = false +diff_only = false opts = GetoptLong.new( [ '--help', '-h', GetoptLong::NO_ARGUMENT ], [ '--manual', '-m', GetoptLong::NO_ARGUMENT ], [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ], [ '--force', '-f', GetoptLong::NO_ARGUMENT ], + [ '--diff-only', '-d', GetoptLong::NO_ARGUMENT ], [ '--no-reload', '-n', GetoptLong::NO_ARGUMENT], [ '--no-restart', '-N', GetoptLong::NO_ARGUMENT], [ '--ssl-template', '-s', GetoptLong::REQUIRED_ARGUMENT ], @@ -156,6 +161,8 @@ begin # This is a legacy option. when '--no-restart' no_reload = true + when '--diff-only' + diff_only = true when '--help' help = true when '--manual' @@ -442,6 +449,17 @@ configurations.each do |config| # This gets apache2 to check the configuration using a temporary file. # if recreate + + # + # If we're only showing the diff, then check the config, and continue to + # the next domain. + # + if diff_only + puts config.diff.to_s(:color) + puts "\tW: Apache has rejected this configuration change" unless config.ok? + next + end + if config.ok? verbose "\tWriting configuration"