]>
Commit | Line | Data |
---|---|---|
ac1cfefa | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
3e30714a | 5 | # Copyright (C) 2007-2013 IPFire Team <info@ipfire.org> # |
70df8302 MT |
6 | # # |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
ac1cfefa MT |
22 | use strict; |
23 | ||
24 | # enable only the following on debugging purpose | |
90c2e164 CS |
25 | #use warnings; |
26 | #use CGI::Carp 'fatalsToBrowser'; | |
73231650 | 27 | use File::Copy; |
ac1cfefa | 28 | |
986e08d9 | 29 | require '/var/ipfire/general-functions.pl'; |
ac1cfefa MT |
30 | require "${General::swroot}/lang.pl"; |
31 | require "${General::swroot}/header.pl"; | |
32 | ||
73231650 CS |
33 | sub refreshpage{&Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='1;'>" );print "<center><img src='/images/clock.gif' alt='' /><br/><font color='red'>$Lang::tr{'pagerefresh'}</font></center>";&Header::closebox();} |
34 | ||
35 | $a = new CGI; | |
36 | ||
f2fdd0c1 CS |
37 | my %color = (); |
38 | my %mainsettings = (); | |
39 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
40 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
41 | ||
ac1cfefa MT |
42 | my %snortsettings=(); |
43 | my %checked=(); | |
5a3e0dca | 44 | my %selected=(); |
ac1cfefa MT |
45 | my %netsettings=(); |
46 | our $errormessage = ''; | |
ac1cfefa MT |
47 | our $results = ''; |
48 | our $tempdir = ''; | |
49 | our $url=''; | |
50 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
51 | ||
52 | &Header::showhttpheaders(); | |
53 | ||
54 | $snortsettings{'ENABLE_SNORT'} = 'off'; | |
55 | $snortsettings{'ENABLE_SNORT_GREEN'} = 'off'; | |
56 | $snortsettings{'ENABLE_SNORT_BLUE'} = 'off'; | |
57 | $snortsettings{'ENABLE_SNORT_ORANGE'} = 'off'; | |
1b73b07e | 58 | $snortsettings{'ENABLE_GUARDIAN'} = 'off'; |
fbfdb241 CS |
59 | $snortsettings{'GUARDIAN_INTERFACE'} = `cat /var/ipfire/red/iface`; |
60 | $snortsettings{'GUARDIAN_HOSTGATEWAYBYTE'} = '1'; | |
61 | $snortsettings{'GUARDIAN_LOGFILE'} = '/var/log/guardian/guardian.log'; | |
62 | $snortsettings{'GUARDIAN_ALERTFILE'} = '/var/log/snort/alert'; | |
63 | $snortsettings{'GUARDIAN_IGNOREFILE'} = '/var/ipfire/guardian/guardian.ignore'; | |
64 | $snortsettings{'GUARDIAN_TARGETFILE'} = '/var/ipfire/guardian/guardian.target'; | |
65 | $snortsettings{'GUARDIAN_TIMELIMIT'} = '86400'; | |
ac1cfefa | 66 | $snortsettings{'ACTION'} = ''; |
fbfdb241 | 67 | $snortsettings{'ACTION2'} = ''; |
5a3e0dca | 68 | $snortsettings{'RULES'} = ''; |
ac1cfefa MT |
69 | $snortsettings{'OINKCODE'} = ''; |
70 | $snortsettings{'INSTALLDATE'} = ''; | |
73231650 CS |
71 | $snortsettings{'FILE'} = ''; |
72 | $snortsettings{'UPLOAD'} = ''; | |
ac1cfefa MT |
73 | |
74 | &Header::getcgihash(\%snortsettings, {'wantfile' => 1, 'filevar' => 'FH'}); | |
75 | ||
395e3b90 | 76 | ####################### Added for snort rules control ################################# |
cf29614f | 77 | my $snortrulepath; # change to "/etc/snort/rules" - maniac |
395e3b90 MT |
78 | my @snortconfig; |
79 | my $restartsnortrequired = 0; | |
80 | my %snortrules; | |
81 | my $rule = ''; | |
82 | my $table1colour = ''; | |
83 | my $table2colour = ''; | |
84 | my $var = ''; | |
85 | my $value = ''; | |
86 | my $tmp = ''; | |
87 | my $linkedrulefile = ''; | |
88 | my $border = ''; | |
89 | my $checkboxname = ''; | |
90 | ||
91 | if (-e "/etc/snort/snort.conf") { | |
2999f1d2 CS |
92 | |
93 | ||
395e3b90 MT |
94 | # Open snort.conf file, read it in, close it, and re-open for writing |
95 | open(FILE, "/etc/snort/snort.conf") or die 'Unable to read snort config file.'; | |
96 | @snortconfig = <FILE>; | |
97 | close(FILE); | |
d192af92 | 98 | open(FILE, ">/etc/snort/snort.conf") or die 'Unable to write snort config file.'; |
395e3b90 | 99 | |
324bb888 | 100 | my @rules = `cd /etc/snort/rules/ && ls *.rules 2>/dev/null`; # With this loop the rule might be display with correct rulepath set |
2999f1d2 CS |
101 | foreach (@rules) { |
102 | chomp $_; | |
103 | my $temp = join(";",@snortconfig); | |
104 | if ( $temp =~ /$_/ ){next;} | |
105 | else { push(@snortconfig,"#include \$RULE_PATH/".$_);} | |
106 | } | |
f9c2147d | 107 | |
395e3b90 MT |
108 | # Loop over each line |
109 | foreach my $line (@snortconfig) { | |
429f7008 | 110 | # Trim the line |
395e3b90 MT |
111 | chomp $line; |
112 | ||
113 | # Check for a line with .rules | |
114 | if ($line =~ /\.rules$/) { | |
115 | # Parse out rule file name | |
116 | $rule = $line; | |
117 | $rule =~ s/\$RULE_PATH\///i; | |
118 | $rule =~ s/ ?include ?//i; | |
119 | $rule =~ s/\#//i; | |
120 | my $snortrulepathrule = "$snortrulepath/$rule"; | |
121 | ||
122 | # Open rule file and read in contents | |
123 | open(RULEFILE, "$snortrulepath/$rule") or die "Unable to read snort rule file for reading => $snortrulepath/$rule."; | |
124 | my @snortrulefile = <RULEFILE>; | |
125 | close(RULEFILE); | |
126 | open(RULEFILE, ">$snortrulepath/$rule") or die "Unable to write snort rule file for writing $snortrulepath/$rule"; | |
127 | ||
128 | # Local vars | |
129 | my $dashlinecnt = 0; | |
130 | my $desclook = 1; | |
131 | my $snortruledesc = ''; | |
132 | my %snortruledef = (); | |
133 | my $rulecnt = 1; | |
134 | ||
135 | # Loop over rule file contents | |
136 | foreach my $ruleline (@snortrulefile) { | |
137 | chomp $ruleline; | |
138 | ||
139 | # If still looking for a description | |
140 | if ($desclook) { | |
141 | # If line does not start with a # anymore, then done looking for a description | |
142 | if ($ruleline !~ /^\#/) { | |
143 | $desclook = 0; | |
144 | } | |
145 | ||
146 | # If see more than one dashed line, (start to) create rule file description | |
147 | if ($dashlinecnt > 1) { | |
148 | # Check for a line starting with a # | |
61196506 | 149 | if ($ruleline =~ /^\#/ and $ruleline !~ /^\#alert/) { |
395e3b90 MT |
150 | # Create tempruleline |
151 | my $tempruleline = $ruleline; | |
152 | ||
153 | # Strip off # and clean up line | |
154 | $tempruleline =~ s/\# ?//i; | |
155 | ||
156 | # Check for part of a description | |
157 | if ($snortruledesc eq '') { | |
158 | $snortruledesc = $tempruleline; | |
159 | } else { | |
160 | $snortruledesc .= " $tempruleline"; | |
161 | } | |
162 | } else { | |
163 | # Must be done | |
164 | $desclook = 0; | |
165 | } | |
166 | } | |
167 | ||
168 | # If have a dashed line, increment count | |
169 | if ($ruleline =~ /\# ?\-+/) { | |
170 | $dashlinecnt++; | |
171 | } | |
172 | } else { | |
173 | # Parse out rule file rule's message for display | |
174 | if ($ruleline =~ /(msg\:\"[^\"]+\";)/) { | |
175 | my $msg = ''; | |
176 | $msg = $1; | |
177 | $msg =~ s/msg\:\"//i; | |
178 | $msg =~ s/\";//i; | |
179 | $snortruledef{$rulecnt}{'Description'} = $msg; | |
180 | ||
181 | # Check for 'Save' and rule file displayed in query string | |
182 | if (($snortsettings{'ACTION'} eq $Lang::tr{'update'}) && ($ENV{'QUERY_STRING'} =~ /$rule/i)) { | |
183 | # Check for a disable rule which is now enabled, or an enabled rule which is now disabled | |
184 | if ((($ruleline =~ /^\#/) && (exists $snortsettings{"SNORT_RULE_$rule\_$rulecnt"})) || (($ruleline !~ /^\#/) && (!exists $snortsettings{"SNORT_RULE_$rule\_$rulecnt"}))) { | |
185 | $restartsnortrequired = 1; | |
186 | } | |
187 | ||
188 | # Strip out leading # from rule line | |
189 | $ruleline =~ s/\# ?//i; | |
190 | ||
191 | # Check if it does not exists (which means it is disabled), append a # | |
192 | if (!exists $snortsettings{"SNORT_RULE_$rule\_$rulecnt"}) { | |
193 | $ruleline = "#"." $ruleline"; | |
194 | } | |
195 | } | |
196 | ||
197 | # Check if ruleline does not begin with a #, so it is enabled | |
198 | if ($ruleline !~ /^\#/) { | |
199 | $snortruledef{$rulecnt++}{'State'} = 'Enabled'; | |
200 | } else { | |
201 | # Otherwise it is disabled | |
202 | $snortruledef{$rulecnt++}{'State'} = 'Disabled'; | |
203 | } | |
204 | } | |
205 | } | |
206 | ||
207 | # Print ruleline to RULEFILE | |
208 | print RULEFILE "$ruleline\n"; | |
209 | } | |
210 | ||
211 | # Close RULEFILE | |
212 | close(RULEFILE); | |
213 | ||
214 | # Check for 'Save' | |
215 | if ($snortsettings{'ACTION'} eq $Lang::tr{'update'}) { | |
216 | # Check for a disable rule which is now enabled, or an enabled rule which is now disabled | |
217 | if ((($line =~ /^\#/) && (exists $snortsettings{"SNORT_RULE_$rule"})) || (($line !~ /^\#/) && (!exists $snortsettings{"SNORT_RULE_$rule"}))) { | |
218 | $restartsnortrequired = 1; | |
219 | } | |
220 | ||
221 | # Strip out leading # from rule line | |
222 | $line =~ s/\# ?//i; | |
223 | ||
224 | # Check if it does not exists (which means it is disabled), append a # | |
225 | if (!exists $snortsettings{"SNORT_RULE_$rule"}) { | |
226 | $line = "# $line"; | |
227 | } | |
f9c2147d | 228 | |
395e3b90 MT |
229 | } |
230 | ||
231 | # Check for rule state | |
232 | if ($line =~ /^\#/) { | |
233 | $snortrules{$rule}{"State"} = "Disabled"; | |
234 | } else { | |
235 | $snortrules{$rule}{"State"} = "Enabled"; | |
236 | } | |
237 | ||
238 | # Set rule description | |
239 | $snortrules{$rule}{"Description"} = $snortruledesc; | |
240 | ||
241 | # Loop over sorted rules | |
242 | foreach my $ruledef (sort {$a <=> $b} keys(%snortruledef)) { | |
243 | $snortrules{$rule}{"Definition"}{$ruledef}{'Description'} = $snortruledef{$ruledef}{'Description'}; | |
244 | $snortrules{$rule}{"Definition"}{$ruledef}{'State'} = $snortruledef{$ruledef}{'State'}; | |
245 | } | |
246 | ||
247 | $snortruledesc = ''; | |
248 | print FILE "$line\n"; | |
249 | } elsif ($line =~ /var RULE_PATH/) { | |
250 | ($tmp, $tmp, $snortrulepath) = split(' ', $line); | |
251 | print FILE "$line\n"; | |
252 | } else { | |
253 | print FILE "$line\n"; | |
254 | } | |
255 | } | |
256 | close(FILE); | |
257 | ||
258 | if ($restartsnortrequired) { | |
18322edf | 259 | system('/usr/local/bin/snortctrl restart >/dev/null'); |
395e3b90 MT |
260 | } |
261 | } | |
262 | ||
263 | ####################### End added for snort rules control ################################# | |
264 | ||
5a3e0dca | 265 | if ($snortsettings{'RULES'} eq 'subscripted') { |
ace810a3 | 266 | $url=" http://www.snort.org/sub-rules/snortrules-snapshot-2961.tar.gz/$snortsettings{'OINKCODE'}"; |
5a3e0dca | 267 | } elsif ($snortsettings{'RULES'} eq 'registered') { |
ace810a3 | 268 | $url=" http://www.snort.org/reg-rules/snortrules-snapshot-2960.tar.gz/$snortsettings{'OINKCODE'}"; |
a0fa489f AF |
269 | } elsif ($snortsettings{'RULES'} eq 'community') { |
270 | $url=" http://s3.amazonaws.com/snort-org/www/rules/community/community-rules.tar.gz"; | |
ac1cfefa | 271 | } else { |
ac93c5d0 | 272 | $url="http://rules.emergingthreats.net/open/snort-2.9.0/emerging.rules.tar.gz"; |
ac1cfefa MT |
273 | } |
274 | ||
fbfdb241 | 275 | if ($snortsettings{'ACTION'} eq $Lang::tr{'save'} && $snortsettings{'ACTION2'} eq "snort" ) |
ac1cfefa MT |
276 | { |
277 | $errormessage = $Lang::tr{'invalid input for oink code'} unless ( | |
278 | ($snortsettings{'OINKCODE'} =~ /^[a-z0-9]+$/) || | |
a0fa489f AF |
279 | ($snortsettings{'RULES'} eq 'nothing' ) || |
280 | ($snortsettings{'RULES'} eq 'emerging' ) || | |
281 | ($snortsettings{'RULES'} eq 'community' )); | |
ac1cfefa MT |
282 | |
283 | &General::writehash("${General::swroot}/snort/settings", \%snortsettings); | |
284 | if ($snortsettings{'ENABLE_SNORT'} eq 'on') | |
285 | { | |
9833e7d8 | 286 | system ('/usr/bin/touch', "${General::swroot}/snort/enable"); |
ac1cfefa MT |
287 | } else { |
288 | unlink "${General::swroot}/snort/enable"; | |
f9c2147d | 289 | } |
ac1cfefa MT |
290 | if ($snortsettings{'ENABLE_SNORT_GREEN'} eq 'on') |
291 | { | |
9833e7d8 | 292 | system ('/usr/bin/touch', "${General::swroot}/snort/enable_green"); |
ac1cfefa MT |
293 | } else { |
294 | unlink "${General::swroot}/snort/enable_green"; | |
f9c2147d | 295 | } |
ac1cfefa MT |
296 | if ($snortsettings{'ENABLE_SNORT_BLUE'} eq 'on') |
297 | { | |
9833e7d8 | 298 | system ('/usr/bin/touch', "${General::swroot}/snort/enable_blue"); |
ac1cfefa MT |
299 | } else { |
300 | unlink "${General::swroot}/snort/enable_blue"; | |
f9c2147d | 301 | } |
ac1cfefa MT |
302 | if ($snortsettings{'ENABLE_SNORT_ORANGE'} eq 'on') |
303 | { | |
9833e7d8 | 304 | system ('/usr/bin/touch', "${General::swroot}/snort/enable_orange"); |
ac1cfefa MT |
305 | } else { |
306 | unlink "${General::swroot}/snort/enable_orange"; | |
307 | } | |
429f7008 DG |
308 | if ($snortsettings{'ENABLE_PREPROCESSOR_HTTP_INSPECT'} eq 'on') |
309 | { | |
310 | system ('/usr/bin/touch', "${General::swroot}/snort/enable_preprocessor_http_inspect"); | |
311 | } else { | |
312 | unlink "${General::swroot}/snort/enable_preprocessor_http_inspect"; | |
f9c2147d | 313 | } |
1b73b07e CS |
314 | if ($snortsettings{'ENABLE_GUARDIAN'} eq 'on') |
315 | { | |
316 | system ('/usr/bin/touch', "${General::swroot}/guardian/enable"); | |
317 | } else { | |
318 | unlink "${General::swroot}/guardian/enable"; | |
319 | } | |
ac1cfefa | 320 | |
429f7008 | 321 | system('/usr/local/bin/snortctrl restart >/dev/null'); |
395e3b90 | 322 | |
fbfdb241 | 323 | } elsif ($snortsettings{'ACTION'} eq $Lang::tr{'save'} && $snortsettings{'ACTION2'} eq "guardian" ){ |
90c2e164 CS |
324 | foreach my $key (keys %snortsettings){ |
325 | if ( $key !~ /^GUARDIAN/ ){ | |
326 | delete $snortsettings{$key}; | |
327 | } | |
328 | } | |
329 | &General::writehashpart("${General::swroot}/snort/settings", \%snortsettings); | |
fbfdb241 | 330 | open(IGNOREFILE, ">$snortsettings{'GUARDIAN_IGNOREFILE'}") or die "Unable to write guardian ignore file $snortsettings{'GUARDIAN_IGNOREFILE'}"; |
90c2e164 | 331 | print IGNOREFILE $snortsettings{'GUARDIAN_IGNOREFILE_CONTENT'}; |
fbfdb241 CS |
332 | close(IGNOREFILE); |
333 | open(GUARDIAN, ">/var/ipfire/guardian/guardian.conf") or die "Unable to write guardian conf /var/ipfire/guardian/guardian.conf"; | |
334 | print GUARDIAN <<END | |
335 | Interface $snortsettings{'GUARDIAN_INTERFACE'} | |
336 | HostGatewayByte $snortsettings{'GUARDIAN_HOSTGATEWAYBYTE'} | |
337 | LogFile $snortsettings{'GUARDIAN_LOGFILE'} | |
338 | AlertFile $snortsettings{'GUARDIAN_ALERTFILE'} | |
339 | IgnoreFile $snortsettings{'GUARDIAN_IGNOREFILE'} | |
340 | TargetFile $snortsettings{'GUARDIAN_TARGETFILE'} | |
341 | TimeLimit $snortsettings{'GUARDIAN_TIMELIMIT'} | |
342 | END | |
343 | ; | |
344 | close(GUARDIAN); | |
345 | system('/usr/local/bin/snortctrl restart >/dev/null'); | |
75b5a616 | 346 | } |
ac1cfefa MT |
347 | # INSTALLMD5 is not in the form, so not retrieved by getcgihash |
348 | &General::readhash("${General::swroot}/snort/settings", \%snortsettings); | |
ac1cfefa | 349 | |
73231650 | 350 | if ($snortsettings{'ACTION'} eq $Lang::tr{'download new ruleset'} || $snortsettings{'ACTION'} eq $Lang::tr{'upload new ruleset'}) { |
32810952 CS |
351 | |
352 | my @df = `/bin/df -B M /var`; | |
353 | foreach my $line (@df) { | |
354 | next if $line =~ m/^Filesystem/; | |
73231650 | 355 | my $return; |
32810952 CS |
356 | |
357 | if ($line =~ m/dev/ ) { | |
358 | $line =~ m/^.* (\d+)M.*$/; | |
359 | my @temp = split(/ +/,$line); | |
f805321a CS |
360 | if ($1<300) { |
361 | $errormessage = "$Lang::tr{'not enough disk space'} < 300MB, /var $1MB"; | |
ac1cfefa | 362 | } else { |
73231650 CS |
363 | |
364 | if ( $snortsettings{'ACTION'} eq $Lang::tr{'download new ruleset'} ){ | |
365 | ||
366 | &downloadrulesfile(); | |
367 | sleep(3); | |
368 | $return = `cat /var/tmp/log 2>/dev/null`; | |
369 | ||
370 | } elsif ( $snortsettings{'ACTION'} eq $Lang::tr{'upload new ruleset'} ) { | |
371 | my $upload = $a->param("UPLOAD"); | |
372 | open UPLOADFILE, ">/var/tmp/snortrules.tar.gz"; | |
373 | binmode $upload; | |
374 | while ( <$upload> ) { | |
375 | print UPLOADFILE; | |
376 | } | |
377 | close UPLOADFILE; | |
378 | } | |
379 | ||
380 | if ($return =~ "ERROR"){ | |
381 | $errormessage = "<br /><pre>".$return."</pre>"; | |
382 | } else { | |
383 | system("/usr/local/bin/oinkmaster.pl -v -s -u file:///var/tmp/snortrules.tar.gz -C /var/ipfire/snort/oinkmaster.conf -o /etc/snort/rules >>/var/tmp/log 2>&1 &"); | |
384 | sleep(2); | |
32810952 | 385 | } |
ac1cfefa | 386 | } |
ac1cfefa MT |
387 | } |
388 | } | |
389 | } | |
390 | ||
391 | $checked{'ENABLE_SNORT'}{'off'} = ''; | |
392 | $checked{'ENABLE_SNORT'}{'on'} = ''; | |
393 | $checked{'ENABLE_SNORT'}{$snortsettings{'ENABLE_SNORT'}} = "checked='checked'"; | |
394 | $checked{'ENABLE_SNORT_GREEN'}{'off'} = ''; | |
395 | $checked{'ENABLE_SNORT_GREEN'}{'on'} = ''; | |
396 | $checked{'ENABLE_SNORT_GREEN'}{$snortsettings{'ENABLE_SNORT_GREEN'}} = "checked='checked'"; | |
397 | $checked{'ENABLE_SNORT_BLUE'}{'off'} = ''; | |
398 | $checked{'ENABLE_SNORT_BLUE'}{'on'} = ''; | |
399 | $checked{'ENABLE_SNORT_BLUE'}{$snortsettings{'ENABLE_SNORT_BLUE'}} = "checked='checked'"; | |
400 | $checked{'ENABLE_SNORT_ORANGE'}{'off'} = ''; | |
401 | $checked{'ENABLE_SNORT_ORANGE'}{'on'} = ''; | |
402 | $checked{'ENABLE_SNORT_ORANGE'}{$snortsettings{'ENABLE_SNORT_ORANGE'}} = "checked='checked'"; | |
1b73b07e CS |
403 | $checked{'ENABLE_GUARDIAN'}{'off'} = ''; |
404 | $checked{'ENABLE_GUARDIAN'}{'on'} = ''; | |
405 | $checked{'ENABLE_GUARDIAN'}{$snortsettings{'ENABLE_GUARDIAN'}} = "checked='checked'"; | |
5a3e0dca | 406 | $selected{'RULES'}{'nothing'} = ''; |
5a3e0dca | 407 | $selected{'RULES'}{'community'} = ''; |
a0fa489f | 408 | $selected{'RULES'}{'emerging'} = ''; |
5a3e0dca MT |
409 | $selected{'RULES'}{'registered'} = ''; |
410 | $selected{'RULES'}{'subscripted'} = ''; | |
411 | $selected{'RULES'}{$snortsettings{'RULES'}} = "selected='selected'"; | |
ac1cfefa MT |
412 | |
413 | &Header::openpage($Lang::tr{'intrusion detection system'}, 1, ''); | |
414 | ||
395e3b90 | 415 | ####################### Added for snort rules control ################################# |
2c01f467 | 416 | print "<script type='text/javascript' src='/include/snortupdateutility.js'></script>"; |
395e3b90 | 417 | print <<END |
e6d8a421 | 418 | <style type="text/css"> |
395e3b90 MT |
419 | <!-- |
420 | .section { | |
421 | border: groove; | |
422 | } | |
423 | .row1color { | |
424 | border: ridge; | |
f2fdd0c1 | 425 | background-color: $color{'color22'}; |
395e3b90 MT |
426 | } |
427 | .row2color { | |
428 | border: ridge; | |
f2fdd0c1 | 429 | background-color: $color{'color20'}; |
395e3b90 MT |
430 | } |
431 | .rowselected { | |
432 | border: double #FF0000; | |
433 | background-color: #DCDCDC; | |
434 | } | |
435 | --> | |
e6d8a421 | 436 | </style> |
395e3b90 MT |
437 | END |
438 | ; | |
439 | ####################### End added for snort rules control ################################# | |
440 | ||
ac1cfefa MT |
441 | &Header::openbigbox('100%', 'left', '', $errormessage); |
442 | ||
90c2e164 CS |
443 | ############### |
444 | # DEBUG DEBUG | |
445 | # &Header::openbox('100%', 'left', 'DEBUG'); | |
446 | # my $debugCount = 0; | |
447 | # foreach my $line (sort keys %snortsettings) { | |
448 | # print "$line = $snortsettings{$line}<br />\n"; | |
449 | # $debugCount++; | |
450 | # } | |
451 | # print " Count: $debugCount\n"; | |
452 | # &Header::closebox(); | |
453 | # DEBUG DEBUG | |
454 | ############### | |
455 | ||
ac1cfefa MT |
456 | if ($errormessage) { |
457 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
458 | print "<class name='base'>$errormessage\n"; | |
459 | print " </class>\n"; | |
460 | &Header::closebox(); | |
461 | } | |
462 | ||
73231650 CS |
463 | my $return = `pidof oinkmaster.pl -x`; |
464 | chomp($return); | |
465 | if ($return) { | |
466 | &Header::openbox( 'Waiting', 1, "<meta http-equiv='refresh' content='10;'>" ); | |
467 | print <<END; | |
468 | <table> | |
469 | <tr><td> | |
470 | <img src='/images/indicator.gif' alt='$Lang::tr{'aktiv'}' /> | |
471 | <td> | |
472 | $Lang::tr{'snort working'} | |
473 | <tr><td colspan='2' align='center'> | |
474 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
f8aa0679 | 475 | <input type='image' alt='$Lang::tr{'reload'}' title='$Lang::tr{'reload'}' src='/images/view-refresh.png' /> |
73231650 CS |
476 | </form> |
477 | <tr><td colspan='2' align='left'><pre> | |
478 | END | |
479 | my @output = `tail -20 /var/tmp/log`; | |
480 | foreach (@output) { | |
481 | print "$_"; | |
482 | } | |
483 | print <<END; | |
484 | </pre> | |
485 | </table> | |
486 | END | |
487 | &Header::closebox(); | |
488 | &Header::closebigbox(); | |
489 | &Header::closepage(); | |
490 | exit; | |
491 | refreshpage(); | |
492 | } | |
493 | ||
7cc8a0e5 | 494 | &Header::openbox('100%', 'left', $Lang::tr{'intrusion detection system'}); |
ac1cfefa MT |
495 | print <<END |
496 | <form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'> | |
1b73b07e | 497 | <tr><td class='base'><input type='checkbox' name='ENABLE_SNORT_GREEN' $checked{'ENABLE_SNORT_GREEN'}{'on'} />GREEN Snort |
ac1cfefa MT |
498 | END |
499 | ; | |
500 | if ($netsettings{'BLUE_DEV'} ne '') { | |
1b73b07e | 501 | print " <input type='checkbox' name='ENABLE_SNORT_BLUE' $checked{'ENABLE_SNORT_BLUE'}{'on'} /> BLUE Snort"; |
ac1cfefa MT |
502 | } |
503 | if ($netsettings{'ORANGE_DEV'} ne '') { | |
1b73b07e | 504 | print " <input type='checkbox' name='ENABLE_SNORT_ORANGE' $checked{'ENABLE_SNORT_ORANGE'}{'on'} /> ORANGE Snort"; |
ac1cfefa | 505 | } |
1b73b07e CS |
506 | print " <input type='checkbox' name='ENABLE_SNORT' $checked{'ENABLE_SNORT'}{'on'} /> RED Snort"; |
507 | if ( -e "/var/ipfire/guardian/guardian.conf" ) { | |
508 | print " <input type='checkbox' name='ENABLE_GUARDIAN' $checked{'ENABLE_GUARDIAN'}{'on'} /> Guardian"; | |
509 | } | |
510 | ||
ac1cfefa | 511 | print <<END |
1b73b07e | 512 | </td></tr> |
ac1cfefa | 513 | <tr> |
7cc8a0e5 | 514 | <td><br><br></td> |
ac1cfefa MT |
515 | </tr> |
516 | <tr> | |
517 | <td><b>$Lang::tr{'ids rules update'}</b></td> | |
518 | </tr> | |
519 | <tr> | |
5a3e0dca MT |
520 | <td><select name='RULES'> |
521 | <option value='nothing' $selected{'RULES'}{'nothing'} >$Lang::tr{'no'}</option> | |
a0fa489f | 522 | <option value='emerging' $selected{'RULES'}{'emerging'} >$Lang::tr{'emerging rules'}</option> |
5a3e0dca MT |
523 | <option value='community' $selected{'RULES'}{'community'} >$Lang::tr{'community rules'}</option> |
524 | <option value='registered' $selected{'RULES'}{'registered'} >$Lang::tr{'registered user rules'}</option> | |
525 | <option value='subscripted' $selected{'RULES'}{'subscripted'} >$Lang::tr{'subscripted user rules'}</option> | |
526 | </select> | |
527 | </td> | |
ac1cfefa MT |
528 | </tr> |
529 | <tr> | |
530 | <td><br /> | |
4935eb8b JPT |
531 | $Lang::tr{'ids rules license'} <a href='https://www.snort.org/signup' target='_blank'>www.snort.org</a>$Lang::tr{'ids rules license1'}<br /><br /> |
532 | $Lang::tr{'ids rules license2'} <a href='https://www.snort.org/account/oinkcode' target='_blank'>Get an Oinkcode</a>, $Lang::tr{'ids rules license3'} | |
ac1cfefa MT |
533 | </td> |
534 | </tr> | |
535 | <tr> | |
5a3e0dca | 536 | <td nowrap='nowrap'>Oinkcode: <input type='text' size='40' name='OINKCODE' value='$snortsettings{'OINKCODE'}' /></td> |
ac1cfefa MT |
537 | </tr> |
538 | <tr> | |
7cc8a0e5 | 539 | <td width='30%' align='left'><br><input type='submit' name='ACTION' value='$Lang::tr{'download new ruleset'}' /> |
ac1cfefa MT |
540 | END |
541 | ; | |
42d9192e | 542 | if ( -e "/var/tmp/snortrules.tar.gz"){ |
0972c650 CS |
543 | my @Info = stat("/var/tmp/snortrules.tar.gz"); |
544 | $snortsettings{'INSTALLDATE'} = localtime($Info[9]); | |
ac1cfefa | 545 | } |
32810952 CS |
546 | print " $Lang::tr{'updates installed'}: $snortsettings{'INSTALLDATE'}</td>"; |
547 | ||
ac1cfefa MT |
548 | print <<END |
549 | </tr> | |
550 | </table> | |
7cc8a0e5 | 551 | <br><br> |
ac1cfefa MT |
552 | <table width='100%'> |
553 | <tr> | |
7cc8a0e5 | 554 | <td align='right'><input type='hidden' name='ACTION2' value='snort' /><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td> |
ac1cfefa MT |
555 | </tr> |
556 | </table> | |
557 | </form> | |
558 | END | |
559 | ; | |
560 | ||
561 | if ($results ne '') { | |
562 | print "$results"; | |
563 | } | |
564 | ||
565 | &Header::closebox(); | |
fbfdb241 CS |
566 | |
567 | ####################### Added for guardian control #################################### | |
568 | if ( -e "/var/ipfire/guardian/guardian.conf" ) { | |
569 | &Header::openbox('100%', 'LEFT', $Lang::tr{'guardian configuration'}); | |
570 | print <<END | |
571 | <form method='post' action='$ENV{'SCRIPT_NAME'}'><table width='100%'> | |
90c2e164 CS |
572 | <tr><td align='left' width='40%'>$Lang::tr{'guardian interface'}</td><td align='left'><input type='text' name='GUARDIAN_INTERFACE' value='$snortsettings{'GUARDIAN_INTERFACE'}' size="30" /></td></tr> |
573 | <tr><td align='left' width='40%'>$Lang::tr{'guardian timelimit'}</td><td align='left'><input type='text' name='GUARDIAN_TIMELIMIT' value='$snortsettings{'GUARDIAN_TIMELIMIT'}' size="30" /></td></tr> | |
574 | <tr><td align='left' width='40%'>$Lang::tr{'guardian logfile'}</td><td align='left'><input type='text' name='GUARDIAN_LOGFILE' value='$snortsettings{'GUARDIAN_LOGFILE'}' size="30" /></td></tr> | |
575 | <tr><td align='left' width='40%'>$Lang::tr{'guardian alertfile'}</td><td align='left'><input type='text' name='GUARDIAN_ALERTFILE' value='$snortsettings{'GUARDIAN_ALERTFILE'}' size="30" /></td></tr> | |
576 | <tr><td align='left' width='40%'>$Lang::tr{'guardian ignorefile'}</td><td align='left'><textarea name='GUARDIAN_IGNOREFILE_CONTENT' cols='32' rows='6' wrap='off'> | |
e55a2b81 CS |
577 | END |
578 | ; | |
579 | print `cat /var/ipfire/guardian/guardian.ignore`; | |
580 | print <<END | |
581 | </textarea></td></tr> | |
7cc8a0e5 | 582 | <tr><td align='right' colspan='2'><input type='hidden' name='ACTION2' value='guardian' /><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr> |
fbfdb241 CS |
583 | </table> |
584 | </form> | |
585 | END | |
586 | ; | |
587 | &Header::closebox(); | |
588 | } | |
589 | ||
590 | ||
591 | ||
592 | ||
395e3b90 | 593 | ####################### Added for snort rules control ################################# |
3ffee04b CS |
594 | if ( -e "${General::swroot}/snort/enable" || -e "${General::swroot}/snort/enable_green" || -e "${General::swroot}/snort/enable_blue" || -e "${General::swroot}/snort/enable_orange" ) { |
595 | &Header::openbox('100%', 'LEFT', $Lang::tr{'intrusion detection system rules'}); | |
596 | # Output display table for rule files | |
631b67b7 | 597 | print "<table width='100%'><tr><td valign='top'><table>"; |
f9c2147d | 598 | |
3ffee04b CS |
599 | print "<form method='post'>"; |
600 | ||
601 | # Local vars | |
602 | my $ruledisplaycnt = 1; | |
603 | my $rulecnt = keys %snortrules; | |
604 | $rulecnt++; | |
605 | $rulecnt = $rulecnt / 2; | |
606 | ||
607 | # Loop over each rule file | |
608 | foreach my $rulefile (sort keys(%snortrules)) { | |
609 | my $rulechecked = ''; | |
610 | ||
ce0e83b3 AF |
611 | # Hide inkompatible Block rules |
612 | if ($rulefile =~'-BLOCK.rules') { | |
613 | next; | |
614 | } | |
615 | ||
3ffee04b CS |
616 | # Check if reached half-way through rule file rules to start new column |
617 | if ($ruledisplaycnt > $rulecnt) { | |
631b67b7 | 618 | print "</table></td><td valign='top'><table>"; |
3ffee04b | 619 | $ruledisplaycnt = 0; |
2999f1d2 | 620 | } |
3ffee04b CS |
621 | |
622 | # Check if rule file is enabled | |
623 | if ($snortrules{$rulefile}{"State"} eq 'Enabled') { | |
624 | $rulechecked = 'CHECKED'; | |
625 | } | |
626 | ||
627 | # Create rule file link, vars array, and display flag | |
2999f1d2 | 628 | my $rulefilelink = "?RULEFILE=$rulefile"; |
3ffee04b CS |
629 | my $rulefiletoclose = ''; |
630 | my @queryvars = (); | |
631 | my $displayrulefilerules = 0; | |
632 | ||
633 | # Check for passed in query string | |
634 | if ($ENV{'QUERY_STRING'}) { | |
635 | # Split out vars | |
2999f1d2 | 636 | @queryvars = split(/\&/, $ENV{'QUERY_STRING'}); |
3ffee04b CS |
637 | |
638 | # Loop over values | |
639 | foreach $value (@queryvars) { | |
640 | # Split out var pairs | |
2999f1d2 | 641 | ($var, $linkedrulefile) = split(/=/, $value); |
3ffee04b CS |
642 | |
643 | # Check if var is 'RULEFILE' | |
644 | if ($var eq 'RULEFILE') { | |
645 | # Check if rulefile equals linkedrulefile | |
646 | if ($rulefile eq $linkedrulefile) { | |
647 | # Set display flag | |
648 | $displayrulefilerules = 1; | |
649 | ||
650 | # Strip out rulefile from rulefilelink | |
651 | $rulefilelink =~ s/RULEFILE=$linkedrulefile//g; | |
652 | } else { | |
653 | # Add linked rule file to rulefilelink | |
654 | $rulefilelink .= "&RULEFILE=$linkedrulefile"; | |
655 | } | |
656 | } | |
657 | } | |
658 | } | |
2999f1d2 | 659 | |
3ffee04b CS |
660 | # Strip out extra & & ? from rulefilelink |
661 | $rulefilelink =~ s/^\?\&/\?/i; | |
662 | ||
663 | # Check for a single '?' and replace with page for proper link display | |
664 | if ($rulefilelink eq '?') { | |
665 | $rulefilelink = "ids.cgi"; | |
666 | } | |
667 | ||
668 | # Output rule file name and checkbox | |
631b67b7 AH |
669 | print "<tr><td class='base' valign='top'><input type='checkbox' NAME='SNORT_RULE_$rulefile' $rulechecked> <a href='$rulefilelink'>$rulefile</a></td></tr>"; |
670 | print "<tr><td class='base' valign='top'>"; | |
3ffee04b CS |
671 | |
672 | # Check for empty 'Description' | |
673 | if ($snortrules{$rulefile}{'Description'} eq '') { | |
e6d8a421 | 674 | print "<table width='100%'><tr><td class='base'>No description available</td></tr>"; |
3ffee04b CS |
675 | } else { |
676 | # Output rule file 'Description' | |
e6d8a421 | 677 | print "<table width='100%'><tr><td class='base'>$snortrules{$rulefile}{'Description'}</td></tr>"; |
3ffee04b CS |
678 | } |
679 | ||
680 | # Check for display flag | |
681 | if ($displayrulefilerules) { | |
682 | # Rule file definition rule display | |
631b67b7 | 683 | print "<tr><td class='base' valign='top'><table border='0'><tr>"; |
3ffee04b CS |
684 | |
685 | # Local vars | |
686 | my $ruledefdisplaycnt = 0; | |
687 | my $ruledefcnt = keys %{$snortrules{$rulefile}{"Definition"}}; | |
688 | $ruledefcnt++; | |
689 | $ruledefcnt = $ruledefcnt / 2; | |
690 | ||
691 | # Loop over rule file rules | |
692 | foreach my $ruledef (sort {$a <=> $b} keys(%{$snortrules{$rulefile}{"Definition"}})) { | |
693 | # Local vars | |
694 | my $ruledefchecked = ''; | |
695 | ||
696 | # If have display 2 rules, start new row | |
697 | if (($ruledefdisplaycnt % 2) == 0) { | |
e6d8a421 | 698 | print "</tr><tr>"; |
3ffee04b CS |
699 | $ruledefdisplaycnt = 0; |
700 | } | |
701 | ||
702 | # Check for rules state | |
703 | if ($snortrules{$rulefile}{'Definition'}{$ruledef}{'State'} eq 'Enabled') { | |
704 | $ruledefchecked = 'CHECKED'; | |
705 | } | |
706 | ||
707 | # Create rule file rule's checkbox | |
708 | $checkboxname = "SNORT_RULE_$rulefile"; | |
709 | $checkboxname .= "_$ruledef"; | |
e6d8a421 | 710 | print "<td class='base'><input type='checkbox' NAME='$checkboxname' $ruledefchecked> $snortrules{$rulefile}{'Definition'}{$ruledef}{'Description'}</td>"; |
3ffee04b CS |
711 | |
712 | # Increment count | |
713 | $ruledefdisplaycnt++; | |
714 | } | |
f9c2147d | 715 | |
3ffee04b CS |
716 | # If do not have second rule for row, create empty cell |
717 | if (($ruledefdisplaycnt % 2) != 0) { | |
e6d8a421 | 718 | print "<td class='base'></td>"; |
3ffee04b CS |
719 | } |
720 | ||
721 | # Close display table | |
e6d8a421 | 722 | print "</tr></table></td></tr>"; |
2999f1d2 | 723 | } |
3ffee04b CS |
724 | |
725 | # Close display table | |
e6d8a421 | 726 | print "</table>"; |
3ffee04b CS |
727 | |
728 | # Increment ruledisplaycnt | |
2999f1d2 | 729 | $ruledisplaycnt++; |
3ffee04b | 730 | } |
e6d8a421 | 731 | print "</td></tr></table></td></tr></table>"; |
3ffee04b | 732 | print <<END |
2999f1d2 CS |
733 | <table width='100%'> |
734 | <tr> | |
7cc8a0e5 | 735 | <td width='100%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td> |
3ffee04b CS |
736 | <!-- space for future online help link --> |
737 | </td> | |
2999f1d2 CS |
738 | </tr> |
739 | </table> | |
740 | </form> | |
3ffee04b CS |
741 | END |
742 | ; | |
743 | &Header::closebox(); | |
744 | } | |
395e3b90 | 745 | |
395e3b90 | 746 | ####################### End added for snort rules control ################################# |
ac1cfefa MT |
747 | &Header::closebigbox(); |
748 | &Header::closepage(); | |
749 | ||
ac1cfefa | 750 | sub downloadrulesfile { |
73231650 CS |
751 | my $peer; |
752 | my $peerport; | |
ac1cfefa | 753 | |
73231650 | 754 | unlink("/var/tmp/log"); |
ac1cfefa MT |
755 | |
756 | unless (-e "${General::swroot}/red/active") { | |
757 | $errormessage = $Lang::tr{'could not download latest updates'}; | |
758 | return undef; | |
759 | } | |
760 | ||
ac1cfefa MT |
761 | my %proxysettings=(); |
762 | &General::readhash("${General::swroot}/proxy/settings", \%proxysettings); | |
763 | ||
764 | if ($_=$proxysettings{'UPSTREAM_PROXY'}) { | |
73231650 | 765 | ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/); |
ac1cfefa MT |
766 | } |
767 | ||
73231650 CS |
768 | if ($peer) { |
769 | system("wget -r --proxy=on --proxy-user=$proxysettings{'UPSTREAM_USER'} --proxy-passwd=$proxysettings{'UPSTREAM_PASSWORD'} -e http_proxy=http://$peer:$peerport/ -o /var/tmp/log --no-check-certificate --output-document=/var/tmp/snortrules.tar.gz $url"); | |
770 | } else { | |
771 | system("wget -r --no-check-certificate -o /var/tmp/log --output-document=/var/tmp/snortrules.tar.gz $url"); | |
ac1cfefa | 772 | } |
ac1cfefa | 773 | } |