* If date calculation fails, abort
authorkkalev <kkalev>
Tue, 4 Jan 2005 14:04:00 +0000 (14:04 +0000)
committerkkalev <kkalev>
Tue, 4 Jan 2005 14:04:00 +0000 (14:04 +0000)
* Add a backup_radacct script

dialup_admin/Changelog
dialup_admin/bin/backup_radacct [new file with mode: 0755]
dialup_admin/bin/clean_radacct
dialup_admin/bin/truncate_radacct

index 91a591f..e4c4a57 100644 (file)
@@ -9,6 +9,8 @@ Ver 1.78:
 * Add a header with the page encoding before sending any page (header added in config.php3)
   This closes Bug #153
 * Fix a problem when reading username.mappings
+* If date calculation fails, abort
+* Add a backup_radacct script
 Ver 1.75:
 * A LOT of security related fixes. Now dialupadmin should hopefully be secure enough to
   be accessed by normal users (not administrators).
diff --git a/dialup_admin/bin/backup_radacct b/dialup_admin/bin/backup_radacct
new file mode 100755 (executable)
index 0000000..2194f46
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+use POSIX;
+
+$conf=shift||'/data/local/dialupadmin/conf/admin.conf';
+$back_days = 80;
+$backup_directory = "/logs/radiusd/accounting";
+
+open CONF, "<$conf"
+       or die "Could not open configuration file\n";
+while(<CONF>){
+       chomp;
+       ($key,$val)=(split /:\s*/,$_);
+       $sql_server = $val if ($key eq 'sql_server');
+       $sql_type = $val if ($key eq 'sql_type');
+       $sql_port = $val if ($key eq 'sql_port');
+       $sql_username = $val if ($key eq 'sql_username');
+       $sql_password = $val if ($key eq 'sql_password');
+       $sql_database = $val if ($key eq 'sql_database');
+       $sql_accounting_table = $val if ($key eq 'sql_accounting_table');
+       $sqlcmd = $val if ($key eq 'sql_command');
+}
+close CONF;
+
+die "sql_command directive is not set in admin.conf\n" if ($sqlcmd eq '');
+die "Could not find sql binary. Please make sure that the \$sqlcmd variable points to the right location\n" if (! -x $sqlcmd);
+if ($sql_type eq 'mysql'){
+       $sql_password = ($sql_password eq '') ? '' : "-p$sql_password";
+}
+$sql_password =~ s/(\W)/\\$1/g;
+
+($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
+$date = POSIX::strftime("%Y-%m-%d",$sec,$min,$hour,($mday - ($back_days - 1)),$mon,$year,$wday,$yday,$isdst);
+$date2 = POSIX::strftime("%Y-%m-%d",$sec,$min,$hour,($mday - ($back_days + 1)),$mon,$year,$wday,$yday,$isdst);
+$date3 = POSIX::strftime("%Y%m%d",$sec,$min,$hour,($mday - $back_days),$mon,$year,$wday,$yday,$isdst);
+if (POSIX::strftime("%Y-%m-%d %T",localtime) eq $date){
+       die "Could not set correct back date.\n";
+}
+
+$query = "SELECT * FROM $sql_accounting_table WHERE AcctStopTime < '$date' AND AcctStopTime > '$date2';";
+print "$query\n";
+open TMP, ">/tmp/backup_radacct.query"
+       or die "Could not open tmp file\n";
+print TMP $query;
+close TMP;
+$comm = "$sqlcmd -B -h $sql_server -u $sql_username $sql_password $sql_database </tmp/backup_radacct.query >$backup_directory/$date3" if ($sql_type eq 'mysql');
+$comm = "$sqlcmd  -U $sql_username -f /tmp/truncate_radacct.query $sql_database >$backup_directory/$date3" if ($sql_type eq 'pg');
+`$comm`;
+`/usr/local/bin/gzip -9 $backup_directory/$date3`;
index 3789e49..c82f664 100755 (executable)
@@ -34,6 +34,9 @@ $sql_password =~ s/(\W)/\\$1/g;
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
 $date = POSIX::strftime("%Y-%m-%d %T",$sec,$min,$hour,($mday - $back_days),$mon,$year,$wday,$yday,$isdst);
 print "$date\n";
+if (POSIX::strftime("%Y-%m-%d %T",localtime) eq $date){
+       die "Could not set correct back date.\n";
+}
 
 $query = "DELETE FROM $sql_accounting_table WHERE AcctStopTime IS NULL AND AcctStartTime < '$date';";
 print "$query\n";
index da82037..48e2d22 100755 (executable)
@@ -34,6 +34,9 @@ $sql_password =~ s/(\W)/\\$1/g;
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
 $date = POSIX::strftime("%Y-%m-%d %T",$sec,$min,$hour,($mday - $back_days),$mon,$year,$wday,$yday,$isdst);
 print "$date\n";
+if (POSIX::strftime("%Y-%m-%d %T",localtime) eq $date){
+       die "Could not set correct back date.\n";
+}
 $query = "";
 $query = "LOCK TABLES $sql_accounting_table WRITE;" if ($sql_type eq 'mysql');
 $query .= "DELETE FROM $sql_accounting_table WHERE AcctStopTime < '$date' AND AcctStopTime IS NOT NULL ;";