Rundeck -

Given an Apache VHOST configuration file x.config.changed containing the following extra block:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^
RewriteCond %{REMOTE_ADDR} !^192.168.1.
RewriteRule .* http://maintenance.x.x [R=302,L]
Header Set Cache-Control "max-age=0, no-store"

The script below would add the a subnet 192.168.1 and an opitional IP to be excluded from the rewrite rule forwarding requests to a maintenance page:


sed -i '/RewriteCond/d' x.conf.changed

if [ -n "$1" ];then
INPUT="$(echo $1 | sed s/^/\!\^/g | sed s/\\./\\\\./g)"
sed -i '/RewriteEngine/a RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.' x.conf.changed
sed -i '/RewriteEngine/a RewriteCond %{REMOTE_ADDR} '$INPUT'' x.conf.changed
sed -i '/RewriteEngine/a RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.' x.conf.changed

cp /x/x.conf.changed /etc/apache2/sites-available/x.conf

apache2ctl -k graceful

To revert it is just replace files as x.conf.changed and x.conf.original