/[smecontribs]/rpms/smeserver-denyhosts/contribs9/smeserver-denyhosts-2.9-bz9458-ease_to_deban.patch
ViewVC logotype

Annotation of /rpms/smeserver-denyhosts/contribs9/smeserver-denyhosts-2.9-bz9458-ease_to_deban.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Mon Mar 25 02:58:54 2019 UTC (5 years, 1 month ago) by jpp
Branch: MAIN
CVS Tags: smeserver-denyhosts-2_9-8_el6_sme
* Sun Mar 24 2019 Jean-Philipe Pialasse <tests@pialasse.com> 2.9-8.sme
- ease unban [SME: 9458]

1 jpp 1.1 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
2     --- smeserver-denyhosts-2.9.old/root/etc/e-smith/events/actions/denyhost-purge 1969-12-31 19:00:00.000000000 -0500
3     +++ smeserver-denyhosts-2.9/root/etc/e-smith/events/actions/denyhost-purge 2019-03-24 22:39:38.664000000 -0400
4     @@ -0,0 +1,64 @@
5     +#!/usr/bin/perl -w
6     +
7     +use strict;
8     +use Errno;
9     +use esmith::ConfigDB;
10     +use esmith::util;
11     +use esmith::db;
12     +use Data::Validate::IP;
13     +my $validator=Data::Validate::IP->new;
14     +
15     +my $event = $ARGV [0];
16     +my $ip = $ARGV [1];
17     +my $whitelist = $ARGV [2];
18     +my $debug=0;
19     +
20     +die "IP missing" unless defined ($ip);
21     +die "Not an IP" unless ($validator->is_ipv4($ip));
22     +
23     +
24     +die "IP $ip not banned" unless (system("grep $ip /etc/hosts.deny_ssh ".'>/dev/null 2>&1') == 0);
25     +die "can not stop denyhost" unless ( system("/etc/init.d/denyhosts","stop") ==0);
26     +
27     +# unlist
28     +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' );
29     +foreach my $file (@files) {
30     +
31     + if (system("grep $ip $file".' >/dev/null 2>&1') == 0) {
32     + print "$ip removed from $file\n" if (system("sed -i '/$ip/d' $file") == 0 && $debug )
33     + }
34     +}
35     +
36     +#(optional, whitelist) /var/lib/denyhosts/allowed-hosts
37     +if (defined($whitelist)) {
38     + # add to db
39     + my $db = esmith::ConfigDB->open
40     + || warn "Couldn't open configuration database (permissions problems?)";
41     +
42     + my $rec = $db->get('denyhosts');
43     + if ($rec)
44     + {
45     +
46     + my $prop = $rec->prop('ValidFrom') || '';
47     +
48     + my @vals = split /,/, $prop;
49     + unless (grep /^$ip$/, @vals)
50     + { # already have this entry
51     + if ($prop ne '')
52     + {
53     + $prop .= ",$ip";
54     + }
55     + else
56     + {
57     + $prop = "$ip";
58     + }
59     + $rec->set_prop('ValidFrom', $prop);
60     +
61     + system("/sbin/e-smith/expand-template /var/lib/denyhosts/allowed-hosts");
62     + print "Add to whitelist: $ip \n";
63     + }
64     + }
65     +}
66     +# /etc/init.d/denyhosts start
67     +system("/etc/init.d/denyhosts","start");
68     +
69     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
70     --- 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
71     +++ 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
72     @@ -51,4 +51,12 @@
73     <base>ERROR_STOPPING</base>
74     <trans>Error while trying to stop service</trans>
75     </entry>
76     + <entry>
77     + <base>SUCCESS_IP</base>
78     + <trans>The following IP has been unbanned</trans>
79     + </entry>
80     + <entry>
81     + <base>SUCCESS_IP_WHITE</base>
82     + <trans>The following IP has been unbanned and whitelisted</trans>
83     + </entry>
84     </lexicon>
85     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
86     --- smeserver-denyhosts-2.9.old/root/etc/e-smith/web/functions/denyhosts 2008-04-22 13:07:27.000000000 -0400
87     +++ smeserver-denyhosts-2.9/root/etc/e-smith/web/functions/denyhosts 2019-03-24 22:40:05.661000000 -0400
88     @@ -35,5 +35,10 @@
89    
90     <subroutine src="show_current_deny()"/>
91     </page>
92     + <page name="Second"
93     + pre-event="RemoveIP()">
94     + <subroutine src="print_status_message()" />
95     + <subroutine src="back()" />
96     + </page>
97     </form>
98    
99     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
100     --- smeserver-denyhosts-2.9.old/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/denyhosts.pm 2019-03-24 22:37:21.756000000 -0400
101     +++ smeserver-denyhosts-2.9/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/denyhosts.pm 2019-03-24 22:38:20.584000000 -0400
102     @@ -10,21 +10,25 @@
103     use File::Basename;
104     use Exporter;
105     use Carp;
106     +use Data::Validate::IP;
107    
108     our @ISA = qw(esmith::FormMagick Exporter);
109    
110     -our @EXPORT = qw(get_value get_prop change_settings);
111     +our @EXPORT = qw(get_value get_prop change_settings RemoveIP);
112    
113     our $VERSION = sprintf '%d.%03d', q$Revision: 1.00 $ =~ /: (\d+).(\d+)/;
114     our $db = esmith::ConfigDB->open
115     || warn "Couldn't open configuration database (permissions problems?)";
116     -
117     +my $scriptname = basename($0);
118    
119     sub new {
120     shift;
121     my $self = esmith::FormMagick->new();
122     $self->{calling_package} = (caller)[0];
123     bless $self;
124     +# if (defined($self->cgi->param('action')) && $self->cgi->param('action') eq 'RemoveIP') {
125     +# RemoveIP($self);
126     +# }
127     return $self;
128     }
129    
130     @@ -55,6 +59,7 @@
131     return CGI::FormMagick::Validator::ip_number($self, $ip);
132     }
133    
134     +
135     sub _get_valid_from
136     {
137     my $self = shift;
138     @@ -122,13 +127,17 @@
139     $q->start_table({class => "sme-border"}),"\n";
140     print $q->Tr(
141     esmith::cgi::genSmallCell($q, $self->localise('IP_ADDRESS'),"header"),
142     - esmith::cgi::genSmallCell($q, $self->localise('FIRST_SEEN'),"header"));
143     + esmith::cgi::genSmallCell($q, $self->localise('FIRST_SEEN'),"header"),
144     + esmith::cgi::genSmallCell($q, $self->localise('ACTION'),"header"));
145    
146     foreach my $val (sort ip_sort keys %vals)
147     {
148     + my $action3 ="<a href=\"$scriptname?page=0&page_stack=&Next=Next&action=RemoveIP&IP=$val&wherenext=Second\">".$self->localise('REMOVE')."</a>" .
149     + " <a href=\"$scriptname?page=0&page_stack=&Next=Next&action=RemoveIP&IP=$val&wherenext=Second&Whitelist=true\">".$self->localise('WHITELIST')."</a>" ;
150     print $q->Tr(
151     esmith::cgi::genSmallCell($q, $val, "normal"),
152     - esmith::cgi::genSmallCell($q, $vals{$val}, "normal"));
153     + esmith::cgi::genSmallCell($q, $vals{$val}, "normal"),
154     + esmith::cgi::genSmallCell($q, $action3, "normal"));
155     }
156     print '</table></td></tr>';
157     }
158     @@ -249,4 +258,50 @@
159     $fm->success('SUCCESS');
160     }
161    
162     +# validate subnet
163     +
164     +
165     +
166     +# RemoveIP after validation
167     +sub RemoveIP {
168     + my $fm = shift;
169     + my $q = $fm->{'cgi'};
170     +
171     +# my ($fm) = @_;
172     +# my $q = $fm->{'cgi'};
173     +# use Data::Dumper;
174     +#warn Dumper($fm);
175     + my %conf;
176     + my $ip = ($q->param('IP') || '');
177     + my $whitelist = ($q->param('Whitelist'))? "true" : '';
178     + #check ip
179     + my $validator=Data::Validate::IP->new;
180     +
181     + unless ($validator->is_ipv4($ip))
182     + {
183     + $fm->error('ERROR_STOPPING');
184     + return undef;
185     + }
186     + $ip = $validator->is_ipv4($ip);
187     + unless ( system( "/etc/e-smith/events/actions/denyhost-purge none $ip $whitelist".' >/dev/null 2>&1' ) == 0 )
188     + {
189     + $fm->error('ERROR_UPDATING');
190     + return undef;
191     + }
192     + if ($whitelist ne "" ) {
193     + $fm->success($fm->localise('SUCCESS_IP_WHITE').": $ip",'First');
194     + }
195     + else
196     + {
197     + $fm->success($fm->localise('SUCCESS_IP').": $ip",'First');
198     + }
199     +}
200     +
201     +sub back {
202     + my $fm = shift;
203     + my $q = $fm->{'cgi'};
204     + print "<a href='$scriptname'>".$fm->localise('Back')."</a>";
205     +return;
206     +}
207     +
208     1;

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed