### ========================== main =================================
-### set the current psad version and file revision numbers
+### set the current version
my $version = '2.2';
### default config file for psad (can be changed with
require NetAddr::IP;
require Date::Calc;
require Unix::Syslog;
+ require Cwd;
require Storable if $store_file;
Date::Calc->import(qw(Timezone This_Year Decode_Month
closedir D;
my $import_ctr = 0;
+
+ my $curr_pwd = getcwd();
chdir $config{'PSAD_DIR'} or die $!;
SRCIP: for my $src (@files) {
}
$import_ctr++;
}
+ chdir $curr_pwd or die $!;
+
return;
}
my @files = readdir D;
closedir D;
+ my $curr_pwd = getcwd();
chdir $config{'PSAD_DIR'} or die $!;
SRCIP: for my $src (@files) {
next SRCIP unless ($src =~ /$ipv4_re/ and -d $src);
rmtree $src or die
"[*] Could not remove $config{'PSAD_DIR'}/$src: $!";
}
+ chdir $curr_pwd or die $!;
return;
}
}
sub archive_data() {
+
+ my $curr_pwd = getcwd();
chdir $config{'PSAD_DIR'} or die "[*] Could not chdir ",
"$config{'PSAD_DIR'}: $!";
unless (-d $config{'SCAN_DATA_ARCHIVE_DIR'}) {
&truncate_file($fwarchive) unless $config{'ENABLE_SYSLOG_FILE'} eq 'Y';
}
unless (-e $fwdata) {
+ chdir $curr_pwd or die $!;
return;
}
open FW, "< $fwdata" or die "$fwdata exists but couldn't open it: $!";
open AR, ">> $fwarchive" or die "Could not open $fwarchive: $!";
print AR $_ for @fwlines;
close AR;
+
+ chdir $curr_pwd or die $!;
return;
}
}
sub disk_space_exceeded() {
+
+ my $curr_pwd = getcwd();
my @df_data = @{&run_command($cmds{'df'}, $config{'PSAD_DIR'})};
my ($prcnt) = ($df_data[$#df_data] =~ /(\d+)%/);
my $rv = 0;
### the disk check interval was exceeded but the utilization is ok.
$rm_data_ctr = 0;
}
+ chdir $curr_pwd or die $!;
return $rv;
}
### for wget
&check_commands({'sendmail'=>'', 'mail'=>''});
+ my $curr_pwd = getcwd();
chdir '/tmp' or die $!;
print "[+] Downloading latest signatures from:\n",
" place. You can restart psad (or use 'psad -H') to import the\n",
" new sigs.\n";
+ chdir $curr_pwd or die $!;
+
return 0;
}
sub archive_conf() {
my $file = shift;
- require Cwd;
my $curr_pwd = getcwd();
chdir $config{'CONF_ARCHIVE_DIR'} or die $!;
my ($filename) = ($file =~ m|.*/(.*)|);