diff -Nur smeserver-denyhosts-2.9.old/root/etc/e-smith/events/actions/denyhost-purge smeserver-denyhosts-2.9/root/etc/e-smith/events/actions/denyhost-purge --- smeserver-denyhosts-2.9.old/root/etc/e-smith/events/actions/denyhost-purge 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-denyhosts-2.9/root/etc/e-smith/events/actions/denyhost-purge 2019-03-24 22:39:38.664000000 -0400 @@ -0,0 +1,64 @@ +#!/usr/bin/perl -w + +use strict; +use Errno; +use esmith::ConfigDB; +use esmith::util; +use esmith::db; +use Data::Validate::IP; +my $validator=Data::Validate::IP->new; + +my $event = $ARGV [0]; +my $ip = $ARGV [1]; +my $whitelist = $ARGV [2]; +my $debug=0; + +die "IP missing" unless defined ($ip); +die "Not an IP" unless ($validator->is_ipv4($ip)); + + +die "IP $ip not banned" unless (system("grep $ip /etc/hosts.deny_ssh ".'>/dev/null 2>&1') == 0); +die "can not stop denyhost" unless ( system("/etc/init.d/denyhosts","stop") ==0); + +# unlist +my @files = ('/etc/hosts.deny_ssh', '/var/lib/denyhosts/hosts', '/var/lib/denyhosts/hosts-restricted' , '/var/lib/denyhosts/hosts-root', '/var/lib/denyhosts/hosts-valid', '/var/lib/denyhosts/users-hosts' ); +foreach my $file (@files) { + + if (system("grep $ip $file".' >/dev/null 2>&1') == 0) { + print "$ip removed from $file\n" if (system("sed -i '/$ip/d' $file") == 0 && $debug ) + } +} + +#(optional, whitelist) /var/lib/denyhosts/allowed-hosts +if (defined($whitelist)) { + # add to db + my $db = esmith::ConfigDB->open + || warn "Couldn't open configuration database (permissions problems?)"; + + my $rec = $db->get('denyhosts'); + if ($rec) + { + + my $prop = $rec->prop('ValidFrom') || ''; + + my @vals = split /,/, $prop; + unless (grep /^$ip$/, @vals) + { # already have this entry + if ($prop ne '') + { + $prop .= ",$ip"; + } + else + { + $prop = "$ip"; + } + $rec->set_prop('ValidFrom', $prop); + + system("/sbin/e-smith/expand-template /var/lib/denyhosts/allowed-hosts"); + print "Add to whitelist: $ip \n"; + } + } +} +# /etc/init.d/denyhosts start +system("/etc/init.d/denyhosts","start"); + diff -Nur smeserver-denyhosts-2.9.old/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/denyhosts smeserver-denyhosts-2.9/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/denyhosts --- smeserver-denyhosts-2.9.old/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/denyhosts 2012-06-03 12:11:23.000000000 -0400 +++ smeserver-denyhosts-2.9/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/denyhosts 2019-03-24 22:42:50.227000000 -0400 @@ -51,4 +51,12 @@ ERROR_STOPPING Error while trying to stop service + + SUCCESS_IP + The following IP has been unbanned + + + SUCCESS_IP_WHITE + The following IP has been unbanned and whitelisted + diff -Nur smeserver-denyhosts-2.9.old/root/etc/e-smith/web/functions/denyhosts smeserver-denyhosts-2.9/root/etc/e-smith/web/functions/denyhosts --- smeserver-denyhosts-2.9.old/root/etc/e-smith/web/functions/denyhosts 2008-04-22 13:07:27.000000000 -0400 +++ smeserver-denyhosts-2.9/root/etc/e-smith/web/functions/denyhosts 2019-03-24 22:40:05.661000000 -0400 @@ -35,5 +35,10 @@ + + + + diff -Nur smeserver-denyhosts-2.9.old/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/denyhosts.pm smeserver-denyhosts-2.9/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/denyhosts.pm --- smeserver-denyhosts-2.9.old/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/denyhosts.pm 2019-03-24 22:37:21.756000000 -0400 +++ smeserver-denyhosts-2.9/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/denyhosts.pm 2019-03-24 22:38:20.584000000 -0400 @@ -10,21 +10,25 @@ use File::Basename; use Exporter; use Carp; +use Data::Validate::IP; our @ISA = qw(esmith::FormMagick Exporter); -our @EXPORT = qw(get_value get_prop change_settings); +our @EXPORT = qw(get_value get_prop change_settings RemoveIP); our $VERSION = sprintf '%d.%03d', q$Revision: 1.00 $ =~ /: (\d+).(\d+)/; our $db = esmith::ConfigDB->open || warn "Couldn't open configuration database (permissions problems?)"; - +my $scriptname = basename($0); sub new { shift; my $self = esmith::FormMagick->new(); $self->{calling_package} = (caller)[0]; bless $self; +# if (defined($self->cgi->param('action')) && $self->cgi->param('action') eq 'RemoveIP') { +# RemoveIP($self); +# } return $self; } @@ -55,6 +59,7 @@ return CGI::FormMagick::Validator::ip_number($self, $ip); } + sub _get_valid_from { my $self = shift; @@ -122,13 +127,17 @@ $q->start_table({class => "sme-border"}),"\n"; print $q->Tr( esmith::cgi::genSmallCell($q, $self->localise('IP_ADDRESS'),"header"), - esmith::cgi::genSmallCell($q, $self->localise('FIRST_SEEN'),"header")); + esmith::cgi::genSmallCell($q, $self->localise('FIRST_SEEN'),"header"), + esmith::cgi::genSmallCell($q, $self->localise('ACTION'),"header")); foreach my $val (sort ip_sort keys %vals) { + my $action3 ="".$self->localise('REMOVE')."" . + " ".$self->localise('WHITELIST')."" ; print $q->Tr( esmith::cgi::genSmallCell($q, $val, "normal"), - esmith::cgi::genSmallCell($q, $vals{$val}, "normal")); + esmith::cgi::genSmallCell($q, $vals{$val}, "normal"), + esmith::cgi::genSmallCell($q, $action3, "normal")); } print ''; } @@ -249,4 +258,50 @@ $fm->success('SUCCESS'); } +# validate subnet + + + +# RemoveIP after validation +sub RemoveIP { + my $fm = shift; + my $q = $fm->{'cgi'}; + +# my ($fm) = @_; +# my $q = $fm->{'cgi'}; +# use Data::Dumper; +#warn Dumper($fm); + my %conf; + my $ip = ($q->param('IP') || ''); + my $whitelist = ($q->param('Whitelist'))? "true" : ''; + #check ip + my $validator=Data::Validate::IP->new; + + unless ($validator->is_ipv4($ip)) + { + $fm->error('ERROR_STOPPING'); + return undef; + } + $ip = $validator->is_ipv4($ip); + unless ( system( "/etc/e-smith/events/actions/denyhost-purge none $ip $whitelist".' >/dev/null 2>&1' ) == 0 ) + { + $fm->error('ERROR_UPDATING'); + return undef; + } + if ($whitelist ne "" ) { + $fm->success($fm->localise('SUCCESS_IP_WHITE').": $ip",'First'); + } + else + { + $fm->success($fm->localise('SUCCESS_IP').": $ip",'First'); + } +} + +sub back { + my $fm = shift; + my $q = $fm->{'cgi'}; + print "".$fm->localise('Back').""; +return; +} + 1;