All pastes #242380 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-11-07 04:55 UTC
rendered paste body
#! /usr/bin/perl -w

require "pklib.pl";

$SIG{INT} = \&cleanup;      
$SIG{TERM} = \&cleanup;
    
my @keys = qw(buncha keys go here);
my $lock = create_lock(@keys);
$pd = init_state();

fw_log_on();

while (1) {

    scan_in($lock);

    if ( $pd->{'unlocked'} ) {
        
        ( poke_fw() ) && ( allow_host() ) 
                      && ( launch_sshd() );     

        if ($pd->{'poked'}) {

            unpoke_fw();
            unallow_host();
        }

        ( $pd->{'src'}, $pd->{'unlocked'}, $pd->{'src_ip'} ) = '';
    }
}

sub cleanup {

    my $signame = shift;

    print "caught SIG$signame, cleaning up.\n";

    ( $pd->{'logging'} )    && logdown();
    ( $pd->{'poked'} )      && unpoke_fw();
    ( $pd->{'h_allow'} )    && unallow_host();
    ($tail)                 && kill 'TERM' => $tail;

    die "Cleaned up and bailing.\n";
}