#!/usr/bin/perl
#
# This is part 2 of the ppp-on script. It will perform the connection
# protocol for the desired connection.

$telephone = $ARGV[0];
$username = $ARGV[1];
$password = $ARGV[2];
$script = $ARGV[3];

$com = "/usr/sbin/chat -v				\
	TIMEOUT		3				\
	ABORT		'\nBUSY\r'			\
	ABORT		'\nNO ANSWER\r'			\
	ABORT		'\nRINGING\r\n\r\nRINGING\r'	\
	''		ATZ				\
	'OK-+++\c-OK'	ATH0				\
	TIMEOUT		30				\
	OK		ATDT$telephone			\
	CONNECT		''";

if ($script)
{
	if (open(FILE, "/etc/ppp/$script"))
	{
		while (<FILE>) {
			$com = "$com $_ "; }
		close FILE;
	}
	$com =~ s/USERNAME/$username/;
	$com =~ s/PASSWORD/$password/;
}

$com =~ s/\n//g;

exec $com;
