commit 357efc9b89710a1ed6f4544aae54ff9761c57971 from: jrmu date: Tue Mar 7 15:15:00 2023 UTC Safer writes commit - 4a735b997384098182ff11ac0c93cb0b0a794984 commit + 357efc9b89710a1ed6f4544aae54ff9761c57971 blob - 258bb9db5be5d0996d84148bf4f038769cea4a55 blob + af1bae59f74297fdd1b70187b06f561e5c000f61 --- botnow +++ botnow @@ -7,7 +7,15 @@ use IO::Socket; use IO::Select; use OpenBSD::Pledge; use OpenBSD::Unveil; +use File::Copy qw(copy); +# Returns date in YYYYMMDD format +sub date { + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); + my $localtime = sprintf("%04d%02d%02d", $year+1900, $mon+1, $mday); + return $localtime; +} + # Read from filename and return array of lines without trailing newlines sub readarray { my ($filename) = @_; @@ -29,6 +37,8 @@ sub readstr { # Write str to filename sub writefile { my ($filename, $str) = @_; + my $date = date(); + copy($filename, $filename.date()) or die "Could not make backup of $filename"; open(my $fh, '>', "$filename") or die "Could not write to $filename"; print $fh $str; close $fh; @@ -51,13 +61,6 @@ sub gettime { return $localtime; } -# Returns date in YYYYMMDD format -sub date { - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); - my $localtime = sprintf("%04d%02d%02d", $year+1900, $mon+1, $mday); - return $localtime; -} - sub mail { my( $from, $to, $fromname, $subject, $body )=@_; my $msg = <<"EOF";