#!/usr/local/bin/perl -Tw
# Copyright (c) 2000 River of Stars, LLC. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by River of Stars, LLC.
# 4. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
my $DEBUG = 1;
#####
# logout script
#####
use strict;
use CGI qw/:standard/;
use Sys::Syslog;
BEGIN {
push(@INC, '/usr/local/libexec/authhb', '/home/rjohnson/hb/');
}
use hbu;
#####
# setup/constants
#####
my @parml = ('key'); # valid parameter list
#####
# var declarations
#####
my($q, $ip, $er, $key, $kv, $un);
#####
# prototypes predeclarations to avoid screwing up line number reports
#####
sub loggedout ($$$);
#####
# main
#####
openlog('webhb-lo', 'pid', 'local6'); # set specialized options for syslog
$q = new CGI;
if ( $ip = $ENV{'REMOTE_ADDR'} ) {
if ( ! ($ip = ip4v($ip)) ) {
syslog ('info', 'invalid remote ip %s', $ip);
failbail ($q, $ip, "invalid remote ip $ip");
}
} else {
$ip = '192.168.1.1';
}
#syslog ('info|LOG_AUTH', 'connection from "%s" for lo', $ip);
syslog ('info', 'connection from "%s" for lo', $ip);
if ( $er = parmv($q, @parml) ) { # is someone monkeying with our params?
syslog ('err', 'parameters from %s unrecognized: %s', $ip, $er);
failbail ($q, $ip, "parameters from $ip unrecognized: $er");
}
$key = $q->param('key');
($un, my @tr) = parsekey ($key); # pull username off front of key
$kv = keyv($ip, $key);
if ( $kv ne '1' ) {
# syslog ('warning|LOG_AUTH', '%s: logout failure by "%s" on "%s" with incorrect key "%s"', $kv, $un, $ip, $key);
syslog ('warning', '%s: logout failure by "%s" on %s with incorrect key "%s"', $kv, $un, $ip, $key);
failbail ($q, $ip, "logout failure: incorrect key \"$key\"");
}
#syslog ('info|LOG_AUTH', 'user "%s" on "%s" logged off', $un, $ip);
syslog ('info', 'user "%s" on %s logged off', $un, $ip);
$er = keyr ($ip); # remove key & rules
if (defined($er) and ($er =~ m/^ERRRULE/)) { # did rule change work?
syslog ('err', '%s: rule removal failure for %s', $er, $ip);
failbail ($q, $ip, "$er: rule removal failure for $ip");
}
loggedout ($q, $ip, $key); # no problems, user logged out
closelog ();
exit 0;
sub loggedout ($$$) {
#####
# log them out
#####
my $q = shift @_;
my $ip = shift @_;
my $key = shift @_;
print $q->header(-Refresh=>"$hbu::w; URL=$hbu::e"),
$q->start_html(-title=>"Logged Off", -bgcolor=>"white", -text=>"black"),
$q->h2("Logged Off"),
$q->p("You have successfully logged off."),
$q->p("If you wish to use the network again, you will need to log in again.");
if ( $DEBUG ) {
print $q->hr,
$q->p("Here is some debugging information for the test."),
# $q->p("The argument list on the previous fetch was"),
# $q->dump,
$q->p("The key was recognized as: $key"),
$q->p("You connected from IP address: $ip"),
$q->p("The HTTP refresh header on this page tells your browser to fetch URL=$hbu::e after $hbu::w seconds.");
}
print $q->end_html;
}