perl<<'EOF'
use strict;
use Sys::Hostname;

my ( $service, $action, $ticket ) = @ARGV;

my $hostname = hostname();
if ( $hostname =~ /(hostgator|websitedns|prodns|ehost|ideahost|hostclear|websitewelcome|webhostsunucusu|minidedicated)/ ) {
	die "[!] Do NOT run this on shared/reseller servers!\n";
}

if ( $action !~ /^(enable|disable)$/ ) {
	die "[!] Action not specified\n";
}

if ( -f '/root/.lockdown' ) {
	open(my $DAT, '<', '/root/.lockdown');
		my $ticket = <$DAT>;
	close($DAT);
	if ( $ticket ) {
		die "[!] Server is already locked down. See ticket $ticket\n";
	} else {
		die "[!] Server is already locked down. No ticket found\n";
	}
}

my %ports = (
	'http' => [
		80,
		81,
		443,
		8080,
		8000
	],
	'exim' => [
		25,
		26,
		587,
		110,
		143,
		993
	],
);


my $job;
if ( $action eq 'disable' ) {
	$job = '-I';
	open(my $WAT, '>', '/root/.lockdown');
		print $WAT $ticket;
	close($WAT);
} elsif ( $action eq 'enable' ) {
	$job = '-D';
	unlink('/root/.lockdown');
}

foreach my $port ( @{$ports{$service}} ) {
	system("iptables $job INPUT -p tcp --dport $port -j DROP");
	system("iptables $job OUTPUT -p tcp --dport $port -j DROP");
}
EOF
