Skip to content
Snippets Groups Projects
blockpage.pl 7.47 KiB
#!/usr/bin/perl
#
# annotated by suhu <stefan.huber@stusta.de> on 2016-10-22
# this file is called from the proxy with e.g.
# proxy.stusta.de:81/blockpage.pl/blocked/10.150.51.80
#
# Wolfgang Walter meinte "FM steht für FehlerMelsung, dass man leichter grepen
#                         kann"

use strict;
use warnings;

use IO::File;
use FCGI;
use Linux::Inotify2;
use File::Slurp;
use File::Basename;
use NetAddr::IP;
use NetAddr::IP::Util;
use Encode;

# array of block types, that means either dynamic or permanent
my @blocktypes = ( 'dynamic', 'permanent' );

# array of filetypes
# apparently this script can load a blocklist and html templates
my @filetypes = ( 'blocklist', 'error_page_template' );

# standard path. here the list of blocked ips should be.
my $incoming = '/home/scp-rec/incoming';

# hashmap for the block page templates, access with
# $templates{'dynamic'} or $templates{'permanent'}
my %templates;

# hashmap of blocked accounts:
# access: $blocklists{'dynamic'}{"10.150.51.80"} = "awesome guy"
my %blocklists;

# hash
my %readconfig;


my $stats;
my $updates = 0;

my $handling_request = 0;
my $exit_requested = 0;

my $notifier;
my $request;
my $isfcgi;

# apparently this scrip is to be run in background and can get unix
# handler requests
sub sig_handler_exit {
	$exit_requested = 1;
	$handling_request or exit(0);
}

$SIG{USR1} = \&sig_handler_exit;
$SIG{TERM} = \&sig_handler_exit;
$SIG{PIPE} = sub { die 'SIGPIPE\n'; };

# this subroutine loads both error page templates into the templates hashmap
sub load_error_page_template {
	my ($blocktype, $filepath) = (@_);

	my $content;
	eval {