This commit was manufactured by cvs2svn to create tag 'freeside_1_5_0pre3'.
[freeside.git] / FS / bin / freeside-sqlradius-seconds
1 #!/usr/bin/perl -Tw
2
3 use strict;
4 use Date::Parse;
5 use FS::UID qw(adminsuidsetup);
6 use FS::Record qw(qsearchs);
7 use FS::svc_acct;
8
9 my $fs_user = shift or die &usage;
10 adminsuidsetup( $fs_user );
11
12 my $target_user = shift or die &usage;
13 my $start = shift or die &usage;
14 $start = str2time($start);
15 my $stop =  scalar(@ARGV) ? str2time(shift) : time;
16
17 my $svc_acct = qsearchs( 'svc_acct', { 'username' => $target_user } );
18 die "username $target_user not found\n" unless $svc_acct;
19
20 print $svc_acct->seconds_since_sqlradacct( $start, $stop ). "\n";
21
22 sub usage {
23   die "Usage:\n\n  freeside-sqlradius-seconds freeside_username target_username start_date stop_date\n";
24 }
25
26
27 =head1 NAME
28
29 freeside-sqlradius-seconds - Real-time radacct import daemon
30
31 =head1 SYNOPSIS
32
33   freeside-sqlradius-seconds freeside_username target_username start_date [ stop_date ]
34
35 =head1 DESCRIPTION
36
37 Returns the number of seconds the specified username has been online between
38 start_date (inclusive) and stop_date (exclusive).
39 See L<FS::svc_acct/seconds_since_sqlradacct>
40
41 B<freeside_username> is a username added by freeside-adduser.
42 B<target_username> is the username of the user account to query.
43 B<start_date> and B<stop_date> are in any format Date::Parse is happy with.
44 B<stop_date> defaults to now if not specified.
45
46 =head1 BUGS
47
48 Selection of the account in question is rather simplistic in that
49 B<target_username> doesn't necessarily identify a unique account (and wouldn't
50 even if a domain was specified), and no sqlradius export is checked for.
51
52 =head1 SEE ALSO
53
54 L<FS::svc_acct/seconds_since_sqlradacct>
55
56 =cut
57
58 1;