5 # Script started when the PPP daemon makes a connection.
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.
12 # TODO: Clean up this file and make it really modular.
17 #### RADIUS section Begins
19 # Configuration section.
21 # Port information database.
22 my $path_portinfo = "/var/ipoint/acct/portinfo";
25 # Radius accounting record generator.
26 my $prog_radacct = "/usr/local/lib/radiusclient/radacct";
30 my $count = int ($_[0] / 8);
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;
40 my ($sessionid, $username, $port, $portid, $timeout, $routelist) =
41 split (/:/, $ARGV[5]);
45 # I-Way code to inform the server that we're getting in.
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,
51 # Unescape the route list.
52 $routelist =~ s/%20/ /g;
57 open (H, ">>/tmp/ip-up.log");
58 print H "ROUTELIST: " . $routelist . "\n";
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]);
67 $netmaskcmd = "netmask " . netmask($network[1]);
70 if ($routevalue[1] eq "0.0.0.0") {
71 $gwcmd = "gw $ARGV[4]";
73 elsif ($routevalue[1]) {
74 $gwcmd = "gw $routevalue[1]";
78 $metriccmd = "metric $routevalue[2]";
81 my $routecmd = "/sbin/route add -net $network[0] $netmaskcmd $gwcmd " .
85 print H "COMMAND: " . $routecmd . "\n";
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.
92 # Generate the accounting entry, and hand it over to RADIUS.
94 open (H, "| $prog_radacct -i $port");
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";
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.
114 tie (%s, "GDBM_File", $path_portinfo, GDBM_WRCREAT, 0600);
115 $s{$portid} = join (':', $username, "Framed-User/PPP", $ARGV[4], getppid (),