• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asus-wl-520gu-7.0.1.45/src/router/pppd.mppe/pppd/plugins/radius/radiusclient/login.radius/migs/
1#!/usr/bin/perl
2#
3# ip-up
4# 
5# Script started when the PPP daemon makes a connection.
6#
7
8# This script is given:
9# interface-name tty-device speed local-IP-address remote-IP-address
10# Since this is a PPP server, local-IP-address does not change.
11
12# TODO: Clean up this file and make it really modular.
13
14use strict;
15use GDBM_File;
16
17#### RADIUS section Begins
18
19# Configuration section.
20
21# Port information database.
22my $path_portinfo = "/var/ipoint/acct/portinfo"; 
23
24
25# Radius accounting record generator.
26    my $prog_radacct = "/usr/local/lib/radiusclient/radacct";
27
28sub netmask 
29{
30    my $count = int ($_[0] / 8);
31    
32    my $c1 = ("255." x $count);
33    $c1 = substr ($c1, 0, -1) if ($count == 4);
34    my $c2 = (256 - (1<<(8 - ($_[0] - $count * 8)))) || "0";
35    $c2 .= '.' if ($count < 3);
36    my $c3 = substr (("0." x (3-$count)), 0, -1);
37    return $c1 . $c2. $c3;
38}
39
40my ($sessionid, $username, $port, $portid, $timeout, $routelist) = 
41    split (/:/, $ARGV[5]);
42
43if ($sessionid) 
44{
45# I-Way code to inform the server that we're getting in.
46
47# If there was routing, add it.  Format for $route, from the Framed-Route
48# parameter, is address/netmask gateway metric.  If gateway is 0.0.0.0,
49# add the route here.
50
51# Unescape the route list.
52    $routelist =~ s/%20/ /g;
53
54    my $route;
55
56    # Debug this.
57    open (H, ">>/tmp/ip-up.log");
58    print H "ROUTELIST: " . $routelist . "\n";
59
60    foreach $route (split ("@", $routelist)) {
61	# Split the route into the components.
62	my @routevalue = split (' ', $route);
63	my ($netmaskcmd, $gwcmd, $metriccmd);
64	my @network = split ("/", $routevalue[0]);
65	
66	if ($network[1]) {
67	    $netmaskcmd = "netmask " . netmask($network[1]);
68	}
69
70	if ($routevalue[1] eq "0.0.0.0") {
71	    $gwcmd = "gw $ARGV[4]";
72	}
73	elsif ($routevalue[1]) {
74	    $gwcmd = "gw $routevalue[1]";
75	}
76	
77	if ($routevalue[2]) {
78	    $metriccmd = "metric $routevalue[2]";
79	}
80
81	my $routecmd = "/sbin/route add -net $network[0] $netmaskcmd $gwcmd " .
82	    "$metriccmd";
83    
84	system ($routecmd);
85	print H "COMMAND: " . $routecmd . "\n";
86    }
87    close (H);
88
89# The session ID, username, raw port and ID are given to this script 
90# through the ipparam parameter of pppd 2.2.0e and above.
91
92# Generate the accounting entry, and hand it over to RADIUS.
93
94    open  (H, "| $prog_radacct -i $port");
95
96    my $cmd =
97	"Acct-Session-ID = \"$sessionid\"\n" .
98	"User-Name = \"$username\"\n" .
99	"Acct-Status-Type = Start\n" .
100	"Acct-Authentic = RADIUS\n" .
101	"Service-Type = Framed\n" .
102	"Framed-Protocol = PPP\n" .
103	"Framed-IP-Address = $ARGV[4]\n";
104
105    print H $cmd;
106    close (H);
107}
108
109# Store the username, the connection type, the IP address, the PID of pppd.
110# Index it on the port ID, since 'portman' makes use of this.
111
112my ($timenow, %s);
113$timenow = time();
114tie (%s, "GDBM_File", $path_portinfo, GDBM_WRCREAT, 0600);
115$s{$portid} = join (':', $username, "Framed-User/PPP", $ARGV[4], getppid (),
116		    $timenow, $timeout);
117untie (%s);
118
119
120#### RADIUS ends
121
122