update otp_hotp() to support 6,7,8,9 digit otp's
[freeradius.git] / dialup_admin / bin / clearsession
1 #!/usr/bin/perl
2
3 $login = 'nas-login';
4 $passwd = 'nas-password';
5
6 $host=shift || '';
7 $type = shift || 'snmp';
8 $nastype = shift || 'cisco';
9 $username=shift || '';
10 $sessionid = shift || '';
11
12 $port = 0;
13 $comm = '';
14
15 if ($type eq 'snmp'){
16 $comm = shift || 'public';
17 }
18 if ($type eq 'telnet'){
19 $port = shift || 0;
20 }
21
22
23 die "No \$host argument given\n" if ($host eq '');
24 die "No \$username argument given\n" if ($username eq '');
25
26 if ($nastype eq 'cisco' && $type eq 'telnet'){
27         die "Usage: clearsession \$host telnet cisco \$username \$sessionid \$port\n" if ($port  == 0);
28
29         if (eval require Net::Telnet::Cisco){
30                 Net::Telnet::Cisco->import();
31
32                 my $session = Net::Telnet::Cisco->new(Host => $host);
33                 $session->login($login, $passwd);
34
35                 if ($port >= 20000){  
36                         my @output = $session->cmd("sh caller user $username");
37                         foreach $line (@output){
38                                 if ($line =~ /User: $username, line (Vi\d+),/){
39                                         $session->cmd("clear interface $1");
40                                 }
41                         }
42                 }
43                 else{
44                         $session->cmd("clear line $port\n");
45                 }
46
47                 $session->close;
48         }
49 }
50 if ($nastype eq 'cisco' && $type eq 'snmp'){
51
52         $SNMPGET="/usr/local/bin/snmpget";
53         $SNMPSET="/usr/local/bin/snmpset";
54
55         die "Could not find snmpwalk binary. Please make sure that the \$SNMPGET variable points to the right location\n" if (! -x $SNMPGET);
56         die "Could not find snmpset binary. Please make sure that the \$SNMPSET variable points to the right location\n" if (! -x $SNMPSET);
57         die "Usage: clearsession \$host snmp \$username cisco \$sessionid \$community\n" if ($sessionid eq '' || $comm eq '');
58
59         if ($sessionid ne '' && $username ne ''){
60                 print "$SNMPGET -v2c -c $comm $host .iso.org.dod.internet.private.enterprises.9.9.150.1.1.3.1.2.$sessionid\n";
61                 $walk =`$SNMPGET -v2c -c $comm $host .iso.org.dod.internet.private.enterprises.9.9.150.1.1.3.1.2.$sessionid`;
62                 unless ($walk =~ /^$/){
63                         if ($walk =~ /$username/){
64                                 print "FOUND: $username\n";
65                 `$SNMPSET -v2c -c $comm $host .iso.org.dod.internet.private.enterprises.9.9.150.1.1.3.1.5.$sessionid i 1`;
66                         }
67                 }
68         }
69 }