-
Notifications
You must be signed in to change notification settings - Fork 0
/
acct_test
executable file
·59 lines (47 loc) · 1.52 KB
/
acct_test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl
#curl --globoff 'localhost:5984/test_acct/_design/test_acct/_view/timestamps_by_mac?start_key=["00-10-90-7D-35-95",0]&end_key=["00-10-90-7D-35-95",9999999999999]'
use strict;
use warnings;
use Data::Dumper;
use Time::HiRes qw(time);
use File::Temp qw(tempfile);
use Getopt::Long;
my %options = ();
GetOptions (
\%options,
"h!",
"mac=s",
"username=s",
"server=s",
"port=s",
"secret=s",
) || die("Invalid options");
my ($fh, $filename) = tempfile();
our $ACCT_DB = "test_acct2";
my @TYPES = qw(Start Stop);
my $type = $TYPES[rand(@TYPES)];
my $server = $options{server};
my $port = $options{port} // 1813;
my $secret = $options{secret};
sub fake_request {
my ($mac, $username, $input, $output, $time) = @_;
my $pod = <<EOF;
Acct-Session-Id = "$mac-00000098"
Acct-Status-Type = $type
Acct-Authentic = RADIUS
User-Name = "bob"
NAS-Port = 0
Called-Station-Id = "00-02-6F-AA-AA-AA:My Wireless"
Calling-Station-Id = "$mac"
NAS-Port-Type = Wireless-802.11
Connect-Info = "CONNECT 48Mbps 802.11b"
Acct-Session-Time = $time
Acct-Input-Octets = $input
Acct-Output-Octets = $output
Acct-Terminate-Cause = User-Request
EOF
print $fh $pod;
close($fh);
`export LD_LIBRARY_PATH=/usr/local/lib && export LD_RUN_PATH=/usr/local/lib && cat $filename | /usr/bin/radclient -x $server:$port acct $secret`;
}
fake_request($options{mac}, $options{username}, int(rand()*10000), int(rand()*10000), int(rand()*1000));