|
17 | 17 | my $pgsql_available=1; |
18 | 18 | my $sqlite_available=1; |
19 | 19 | my $debug = 0; |
| 20 | +my $tail_pid = 0; |
20 | 21 | $ENV{PATH} = ''; # remove unsecure path |
21 | | -my $VERSION = '7.1'; |
| 22 | +my $VERSION = '7.2'; |
22 | 23 |
|
23 | 24 | use lib '/usr/lib/hawk/'; |
24 | 25 | use POSIX qw(setsid), qw(strftime), qw(WNOHANG); |
|
28 | 29 | eval "use DBD::SQLite; 1" or $sqlite_available = 0; |
29 | 30 |
|
30 | 31 | $SIG{"CHLD"} = \&sigChld; |
| 32 | +$SIG{"INT"} = \&sigINT; |
31 | 33 | $SIG{__DIE__} = sub { logger(@_); }; |
32 | 34 |
|
33 | 35 |
|
@@ -111,6 +113,14 @@ sub sigChld { |
111 | 113 | } |
112 | 114 | } |
113 | 115 |
|
| 116 | +# Kill children and exit |
| 117 | + |
| 118 | +sub sigINT { |
| 119 | + kill 'INT', $tail_pid; |
| 120 | + logger("Quiting"); |
| 121 | + exit 0; |
| 122 | +} |
| 123 | + |
114 | 124 | # If $_[3] is 0, store the failed login attempt to the DB |
115 | 125 | # If $_[3] is 1, store the bruteforce attempt to the DB |
116 | 126 | # The brootforce table is later checked by the cron |
@@ -455,7 +465,6 @@ sub main { |
455 | 465 | die("Error: no valid file found in monitor_list file list: $config{'monitor_list'}\n"); |
456 | 466 | } |
457 | 467 | my $log_list = "/usr/bin/sudo /usr/bin/tail -s 1.00 -F --max-unchanged-stats=30 $monitor_list |"; |
458 | | - #my $log_list = "/usr/bin/tail -s 1.00 -F --max-unchanged-stats=30 $monitor_list |"; |
459 | 468 |
|
460 | 469 | if ($debug) { |
461 | 470 | # service_ids=ftp:0 ssh:1 pop3:2 imap:3 webmail:4 cpanel:5 da:6 |
@@ -535,7 +544,7 @@ sub main { |
535 | 544 | } |
536 | 545 |
|
537 | 546 | # use tail to open all logs that should be monitored |
538 | | - open LOGS, $log_list or die "open $log_list failed: $!\n"; |
| 547 | + $tail_pid = open LOGS, $log_list or die "open $log_list failed: $!\n"; |
539 | 548 |
|
540 | 549 | # make the output of the opened logs unbuffered |
541 | 550 | select((select(HAWKLOG), $| = 1)[0]); |
@@ -894,7 +903,7 @@ =head2 write_pid() - Write the new hawk pid to the pid file |
894 | 903 | 0 on failure |
895 | 904 | 1 on success |
896 | 905 |
|
897 | | -=head2 sigChld() - Reaper of the dead childs |
| 906 | +=head2 sigChld() - Reaper of the dead children |
898 | 907 |
|
899 | 908 | Called only in case of SIG CHILD |
900 | 909 |
|
|
0 commit comments