~ubuntu-branches/ubuntu/dapper/freeradius/dapper-updates

« back to all changes in this revision

Viewing changes to dialup_admin/bin/truncate_radacct

  • Committer: Bazaar Package Importer
  • Author(s): Paul Hampson
  • Date: 2004-12-29 20:19:42 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041229201942-uj2e95la965uthc7
Tags: 1.0.1-2
* freeradius-dialupadmin Suggests php4-mysql | php4-pgsql
   Closes: #279419
* Added a two-second pause to restart in init.d script
   Closes: #262635
* FreeRADIUS module packages now depend on the same source
  version of the main FreeRADIUS package.
   Closes: #284353
* FreeRADIUS-dialupadmin's default paths in admin.conf are
  now correct.
   Closes: #280942
* FreeRADIUS-dialupadmin's help.php3 can now find README.
   Closes: #280941
* Fixes stolen from 1.0.2 CVS:
  - Bug fix to make udpfromto code work
  - radrelay shouldn't dump core if it can't read a VP from the
    detail file.
  - Only initialize the random pool once.
  - In rlm_sql, don't escape characters twice.
  - In rlm_ldap, only claim Auth-Type if a plain text password is present.
  - Locking fixes in threading code
  - Fix building on gcc-4.0 by not trying to access static auth_port from
    other files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#
3
3
# Delete sessions from the radacct table which are older than
4
4
# $back_days
 
5
# Works with mysql and postgresql
5
6
#
6
 
use DBI;
7
7
use POSIX;
8
8
 
9
9
$conf=shift||'/usr/local/dialup_admin/conf/admin.conf';
10
10
$back_days = 90;
11
11
 
 
12
 
12
13
open CONF, "<$conf"
13
14
        or die "Could not open configuration file\n";
14
15
while(<CONF>){
15
16
        chomp;
16
17
        ($key,$val)=(split /:\s*/,$_);
 
18
        $sql_type = $val if ($key eq 'sql_type');
17
19
        $sql_server = $val if ($key eq 'sql_server');
18
20
        $sql_username = $val if ($key eq 'sql_username');
19
21
        $sql_password = $val if ($key eq 'sql_password');
20
22
        $sql_database = $val if ($key eq 'sql_database');
21
23
        $sql_accounting_table = $val if ($key eq 'sql_accounting_table');
 
24
        $sqlcmd = $val if ($key eq 'sql_command');
22
25
}
23
26
close CONF;
24
27
 
 
28
die "sql_command directive is not set in admin.conf\n" if ($sqlcmd eq '');
 
29
die "Could not find sql binary. Please make sure that the \$sqlcmd variable points to the right location\n" if (! -x $sqlcmd);
 
30
 
 
31
$sql_password = ($sql_password eq '') ? '' : "-p$sql_password";
 
32
 
25
33
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
26
34
$date = POSIX::strftime("%Y-%m-%d %T",$sec,$min,$hour,($mday - $back_days),$mon,$year,$wday,$yday,$isdst);
27
35
print "$date\n";
28
 
 
29
 
$dbh = DBI->connect("DBI:mysql:$sql_database:$sql_server","$sql_username","$sql_password");
30
 
$dbh->do("LOCK TABLES $sql_accounting_table WRITE;DELETE FROM $sql_accounting_table WHERE AcctStopTime < '$date';UNLOCK TABLES;");
31
 
$dbh->disconnect();
 
36
$query = "";
 
37
$query = "LOCK TABLES $sql_accounting_table WRITE;" if ($sql_type eq 'mysql');
 
38
$query .= "DELETE FROM $sql_accounting_table WHERE AcctStopTime < '$date' AND AcctStopTime IS NOT NULL ;";
 
39
$query .= "UNLOCK TABLES;" if ($sql_type eq 'mysql');
 
40
print "$query\n";
 
41
open TMP, ">/tmp/truncate_radacct.query"
 
42
        or die "Could not open tmp file\n";
 
43
print TMP $query;
 
44
close TMP;
 
45
$command = "$sqlcmd -h$sql_server -u$sql_username $sql_password $sql_database </tmp/truncate_radacct.query" if ($sql_type eq 'mysql');
 
46
$command = "$sqlcmd  -U $sql_username -f /tmp/truncate_radacct.query $sql_database" if ($sql_type eq 'pg');
 
47
`$command`;