# PPPd Dialup Terminal Command



## RHITMacMan (Jun 16, 2002)

I have been trying to figure out a way to write a script or execute a command from the terminal to dialup my ISP using PPPd.  I notice when I type 'ps -ax' that there is a process for PPPd with part of the command.  The problem is that the command is too long and it doesn't fit on the screen.  I've tried redirecting the output to a text file but it still only captures a partial length of the command.  The command is initiated by the Internet Connect GUI app, but I want to be able to do it from the terminal.  Here's what I've been able to capture..


```
pppd serviceid 0 debug logfile /tmp/ppp.log /dev/cu.modem 115200 connect /usr/libexec/CCLEngine -l 0 -f '/
Library/Modem Scripts/Apple Internal 56K Modem (v.90)'  -v  -T '555-5555'  -E  -S 150  -s 1  -e 1  -c 1  -p 0  -d 0  -C 'Cancel' -I 
'Internet Connect' -i 'file://localhost/System/Library/SystemConfiguration/PPPControll
```

So I am wondering if there is a way to capture the whole length of the command so I can execute it from the terminal myself.  I'd like to be able to do this remotely over an SSH session.  Let me know if you have any ideas.


----------



## RHITMacMan (Jun 16, 2002)

Well, I was able to get the whole command, but it wasn't as helpful as I had hoped.  For some reason when I try to execute the command from the terminal, it does not recognize the several of the arguments passed.  Including but probably not limited to the -l and -f arguments.  Below is the full command I was able to find.  It is modified to be more generic removing my personal info.


```
pppd serviceid 0 debug logfile /tmp/ppp.log /dev/cu.modem 115200 connect /usr/libexec/CCLEngine -l 0 -f '/Library/Modem
Scripts/Apple Internal 56K Modem (v.90)'  -v  -T '555-5555'  -E  -S 150  -s 1  -e 1  -c 1  -p 0  -d 0  -C 'Cancel' -I
'Internet Connect' -i 'file://localhost/System/Library/SystemConfiguration/PPPController.bundle/Contents/
Resources/NetworkConnect.icns' busycode 122 redialcount 2 redialtimer 30 disconnect /usr/libexec/CCLEngine -m 1 -l 0 -f
'/Library/Modem Scripts/Apple Internal 56K Modem (v.90)'  -v  -E  -S 150  -C 'Cancel' -I 'Internet Connect' -i
'file://localhost/System/Library/SystemConfiguration/PPPController.bundle/Contents/Resources/NetworkConnect.icns'
remoteaddress 555-555 cancelcode 136 mru 1500 mtu 1500 receive-all ipparam 192.168.0.1 0:0 noipdefault ipcp-accept-local
ipcp-accept-remote usepeerdns noauth user yourusername password yourpassword forcedetach noccp plugin
/System/Library/SystemConfiguration/PPPController.bundle/Contents/PlugIns/PPPDialogs.ppp noaskpassword
```
(I only changed my ISP Phone number, username, and raw password...)

It may not work since some of the arguments seem to be setup to work exclusively with the Internet Connect app.  I'm not sure how to modify the command though, or write one of my own to dial up my ISP.  I'll continue take some cracks at it unless someone has any good suggestions.


----------



## RiscIt (Sep 14, 2002)

I've been trying to do the same thing. I want my wife to be able to go to a cgi script generated web page served from my computer (on the same LAN) which will trigger the connection to be opened. Obviously the script would use a command line tool to do this, so I am looking for way to initiate a dial up connection from the command line.

	If you come up with anything, please post it here.

	1 idea I've had, tho I don't know enough about applescript to do it, is to use the applescript command line tool (man osascript for more info) to open the internet connect app and tell it to connect.


----------



## RiscIt (Sep 14, 2002)

Make a new text file with a text editor (eg - bbedit)

put this text in it:

tell application "Internet Connect"
	Connect
end tell

close the file

save it, for example, as "connect.applescript"

from the command line run:  osascript /path/to/connect.applescript

Internet Connect should then open, and connect.


----------



## RHITMacMan (Sep 14, 2002)

Sweet!  I'll have to try this and see if it works.  If it works, I could write a Perl or PHP script page that anyone on the LAN could access and startup the dial-up connection.  I'll let you know how it works once I get it done.


----------



## RiscIt (Sep 14, 2002)

Ah.... You hadn't mentioned in your previous posts that this is how you wanted to use it.  I've already tried that (with perl). The problem is that the webserver is running as the user "www", which is not you. You are the one logged in, and you are the only one with access to the windowserver. Thus, the webserver can not run the script, and as a result, open the Internet Connect window. It dies a horrible death.

a possible solution would be to run the web server as your user (set in the httpd.conf file), but my machine has some path issues to deal with if I do it that way, which I can not work around without messing up a lot of things.

another solution might be to run the webserver as the root user (dangerous, but not an issue if you know what you're doing). The 2 issues I see with this are 1) I'm not positive the root user has access to the window server (does it?) and 2) the default install of apache included with os X does not allow the child apache processes to be run as root, and it would have to be rebuilt/compiled with a few permission flags set and installed the old fashioned way - something I'd rather not deal with on my nice freshly installed system.

Perhaps using an suexec wrapper for the cgi? I haven't had time to look into that possibility yet.

all this could be avoided if there was a way to allow more than 1 user at a time to access the windowserver....


----------



## RHITMacMan (Sep 14, 2002)

Actually, that was not my original intention.  I was just going to use an SSH session and execute a command from the terminal.  But after reading your earlier post, I got the idea of trying to execute this command via Perl script.  Perhaps, this won't work after all.


----------



## RiscIt (Nov 14, 2002)

Hey there. I got it working. It requires punching a hole in the sudo'ers file, but I'm willing to take that risk - there aren't a lot of people hacking away at my personal webserver, ya know?

Anyway, Add this to /etc/sudoers:

www     ALL = NOPASSWD: ALL

Note that it lets your webserver user (and thus all cgis that run under it) do whatever they want as root with a sudo command.

Here's the applescript:

tell application "Internet Connect"
	Connect
end tell

hard one, eh?

and finally, here's the perl script I use. It's quick and dirty with lots of incomplete HTML, but it works just fine. It's all my own work except the ping function is based on a script I found somewhere else (I don't remember where - I just cleaned it up and simplified it) and the ReadForm function is almost entirely from an old version of NewsPro.. I've been using it for a long time.  Here it is, I hope the forum doesn't butcher it but it will probably kill the indentations:

#!/usr/bin/perl

print "Content Type: text/html\n\n";

ReadForm();

if ($formData{'connect'} eq 'true') {
	print 'Connecting. Please Wait....';
	print qq|<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-8859-1">\n<META HTTP-EQUIV="Refresh" CONTENT="1; URL=connect.cgi?waiting=true">\n\n|;
	exit();
}


if ($formData{'waiting'} eq 'true') {
	if (test_ping()) {
		print 'Connected.';
	} else {

		print qq|<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-8859-1">\n<META HTTP-EQUIV="Refresh" CONTENT="2; URL=connect.cgi?waiting=true">\n\n|;
		print 'Connecting. Please Wait....';
		exec ('sudo -b /usr/bin/osascript ./connect.applescript >/dev/null');
	}
	exit();
}


if (test_ping()) {
	print 'Already connected.'
} else  {
	print qq|

		Not Connected.<BR><BR>

		<FORM ACTION="connect.cgi" METHOD="GET">
			<INPUT TYPE="HIDDEN" NAME="connect" VALUE="true">
			<INPUT TYPE="SUBMIT" VALUE="Click Here To Connect...">
		</FORM>
	|;
}

####################################################
# test_ping                                        #
#                                                  #
#	returns 1 if host is pingable, 0 if it is not. #
####################################################
sub test_ping
{
	my $pingcom = '/sbin/ping';
	my $ping_target = 'www.apple.com';

	my $pingcom = "ping -c 1 $ping_target | grep loss";

	@ping = `$pingcom`;
	$rece = substr($ping[0],23,1);

	if ($rece < 1) {
		return 0;
	}
	else {
		return 1;
	};

	return $result;
}


##################################################################################
# Put form data in %formData, parsing the hex all the way                        #
##################################################################################
sub ReadForm {

	if ($ENV{'REQUEST_METHOD'} eq 'POST') {
		read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});	
	}

	if ($ENV{'REQUEST_METHOD'} eq 'GET') {
		$buffer = $ENV{'QUERY_STRING'};
	}

	if ($buffer eq '') {

		return 1;
	}

	my @pairs = split(/&/, $buffer);

	foreach $pair (@pairs) {
		($name, $value) = split(/=/, $pair);
		$value =~ tr/+/ /;
		$value =~ s/%0D/\n/g;
		$value =~ s/%0A//g;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		unless($formData{$name}) {
			$formData{$name} = $value;
		} else {
			$formData{$name} .= "|x|$value";
		}
	}
	return 0;
}

That's it. Have fun.


----------

