#!/usr/bin/perl

# This script restores the original httpd.conf file once a PPP connection
# has been terminated.  This script is provided "As is" and all responsibility
# for its use is assumed by the user.  Copyright Mark A. Martin 1999.

# The Apache web server start-up and shut-down script.

$apache_ctl = '/etc/rc.d/init.d/httpd';

# The configuration file and its backup.

$config = '/etc/httpd/conf/httpd.conf';
$save   = '/etc/httpd/conf/httpd.conf.sav';

# Check to see if the PPP connection has been terminated.
# If not, wait 5 seconds and try again up to $retries times.

$retries = 2;

while (`/bin/ps axc | /bin/grep pppd`) {
    if ($retries) {
        $retries--;
        sleep 5;
    } else {
        die "Couldn\'t restore $config.\n",
            "The PPP connection is still alive after $retries retries.\n",
            "Stopped"
    }
}

# Move the old configuration file back into place and restart the web server.

if (-f $save) {
    rename $save, $config;
    system "$apache_ctl restart &> /dev/null";
} else {
    die "$save does not exist or is not\na regular file.  Stopped";
}
