#!/usr/bin/perl

#  Copyright (C) 1999 Hugo Haas

#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# This script is based on Martin Schulze's syslogd-listfiles 1.1 script.
# syslogf-listfiles is Copyright (C) 1997 Martin Schulze
# under GNU GPL version 2.
#
# Version 1.1 - Wed Mar  3 21:51:26 GMT 1999
#	Remove duplicates

# Global variables

$version = "1.1";
$conffile = "/etc/ippl.conf";
$protos = "(all|icmp|tcp|udp)";

# Help message

sub usage {
    printf(STDERR "
Debian GNU/Linux ippl-listfiles %s
Copyright (C) 1999 Hugo Haas.
Based on syslogd-listfiles 1.1 Copyright (C) 1997 Martin Schulze.
This is free software; see the GNU General Public Licence version 2 or later
for copying conditions. There is NO warranty.

Usage: ippl-listfiles <options>
Options: -f file	specify another configuration file
			(default: %s)
         -h | --help	display this help message 
", $version, $conffile);
}

# Parse command-line

while (@ARGV) {
    $_=shift(@ARGV);
    if (m/^-f$/) {
        $conffile = shift(@ARGV);
    }
    elsif (m/^(-h|--help)$/) {
        &usage();
        exit(0);
    }
    else {
        printf(STDERR "Unknown option: %s\n", $_);
        &usage();
        exit(1);
    }
}

# Process file

open (CONFFILE, $conffile) || die "Can't open $conffile:\n$!";

while (<CONFFILE>) {
    next if (!/^\s*log-in\s+$protos\s+([^ \t\#\n]+)/i);
    push (@files, $2);
}

close (CONFFILE);

undef %saw;
@list = grep(!$saw{$_}++, @files);

foreach $file (@list) {
    print $file . "\n";
}

