#!/usr/bin/perl
# <C> btv
$user = `/usr/bin/whoami`;
$inline = `/usr/bin/tty`;
chop($user);
chop($inline);
open(HOSTS,"/etc/slip.hosts");
$x=0;
while (<HOSTS>) {
	if (substr($_,0,1) eq "#" || substr($_,0,1) eq "\n") {next;}
	($host[$x],$locip[$x],$remip[$x],$mask[$x],$opt1[$x++]) = split(/[ \t]+/,$_);
}
close (HOSTS);
$y=0;
while ($host[$y] ne $user) {
	if ($y < $x) {$y++;}
	else {last;}
}
if ($host[$y] ne $user) {
	print "You have no permission to use PPP. Go away.\n";
	exit;
}
else {
	if ($remip[$y] ne "DYNAMIC") {
		$string = "/usr/etc/pppd modem crtscts proxyarp lock passive asyncmap 0 :$remip[$y]";
		exec $string;
	}
	else {
		$z = 0;
		open(LINE,"/etc/slip.tty");
		while (<LINE>) {
			if (substr($_,0,1) eq "#" || substr($_,0,1) eq "\n") {next;}
			($line[$z],$ip[$z++]) = split(/[ \t]+/,$_);
		}
		close (LINE);
		$a = 0;
		while ($line[$a] ne $inline) {
			if ($a < $z) {$a++;}
			else {last;}
		}
		if ($line[$a] ne $inline) {
			print "There is no such line configured as $inline. Sorry.\n";
			exit;
		}
		else {
			$string = "/usr/etc/pppd modem crtscts proxyarp lock passive asyncmap 0 :$ip[$a]";
			exec $string;
		}
	}
}	