Captive-Portal

 view release on metacpan or  search on metacpan

bin/capo-ctl.pl  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

our $VERSION = '4.10';

=head1 NAME

capo-ctl.pl - Controller script for Captive::Portal

=head1 ABSTRACT

Controller script to start, stop, clear, list and purge iptables/ipsets and session entries.

=head1 SYNOPSIS

 capo-ctl.pl [-f capo.cfg] [-l log4perl.cfg] ACTION

=cut

use sigtrap qw(die untrapped normal-signals);

use Pod::Usage qw(pod2usage);
use FindBin qw($Bin $Script);
use lib "$Bin/../lib";

use Log::Log4perl qw(:easy);
use Getopt::Long qw(GetOptions);
use Try::Tiny;
use Captive::Portal;
use Captive::Portal::LockHandle;

$ENV{PATH} = '/sbin:/bin:/usr/sbin:/usr/bin';

select(STDERR) and $| = 1;
select(STDOUT) and $| = 1;

#####################################################################
# put scriptname in process table instead of plain 'perl'
# but safe the pathname for pod2usage, sigh
#####################################################################
my $pathname = $0;
$0 = $Script;

#####################################################################
# handle cmdline options and args
#####################################################################

my $cfg_file =
     $ENV{CAPTIVE_PORTAL_CONFIG}
  || -e "$Bin/../etc/local/config.pl" && "$Bin/../etc/local/config.pl"
  || -e "$Bin/../etc/config.pl" && "$Bin/../etc/config.pl";

my $log4perl =
     $ENV{CAPTIVE_PORTAL_LOG4PERL}
  || -e "$Bin/../etc/local/log4perl.conf" && "$Bin/../etc/local/log4perl.conf"
  || -e "$Bin/../etc/log4perl.conf" && "$Bin/../etc/log4perl.conf";

GetOptions(
  'loggfile=s' => \$log4perl,
  'file=s'     => \$cfg_file,
  )
  or pod2usage(
  {
    -input   => $pathname,
    -exitval => 1,
    -verbose => 1,
    -output  => \*STDERR
  }
  );

if ( $log4perl && -f $log4perl ) {
  Log::Log4perl->init($log4perl);
}
else {
  Log::Log4perl->easy_init($DEBUG);
}

=head1 OPTIONS

=over 4

=item B<--file> capo.cfg

Captive::Portal config file. By default

    $ENV{CAPTIVE_PORTAL_CONFIG} ||
    $Bin/../etc/local/config.pl ||
    $Bin/../etc/config.pl



( run in 1.573 second using v1.01-cache-2.11-cpan-5a3173703d6 )