9 # Command-line parameters:
12 my ( $_create, $_delete, $_help );
15 my ( $SERVER, $DOMAIN, $USERNAME, $PASSWORD, $ENCRYPT, $START );
17 my $result = GetOptions(
18 "create|c=s" => \$_create, # --create foo -> &create("foo")
19 "delete=s" => \$_delete, # --delete foo -> &delete("foo")
20 "help|h" => \$_help, # --help -> &help()
21 "server|s=s" => \$SERVER,
22 "domain|d=s" => \$DOMAIN,
23 "username|u=s" => \$USERNAME,
24 "password|p=s" => \$PASSWORD,
25 "encrypt|e" => \$ENCRYPT,
36 die "$0: too few arguments.\nTry '$0 --help' for more information.\n";
48 or die "$0: couldn't find MPPE support in kernel.\n";
51 or die "$0: couldn't find MPPE support in pppd.\n";
54 ($TUNNEL) = $TUNNEL =~ m{^(\w+)$}
55 or die "$0: invalid tunnel name.\nTry '$0 --help' for more information.\n";
56 ($SERVER) = $SERVER =~ m{^(.+)$}
57 or die "$0: invalid server.\nTry '$0 --help' for more information.\n";
58 ($USERNAME) = $USERNAME =~ m{^(.+)$}
59 or die "$0: invalid username.\nTry '$0 --help' for more information.\n";
68 # put '\' between domain and username IF specified a domain
69 $DOMAIN = "$DOMAIN\\" if $DOMAIN;
71 # create or add lines to the /etc/ppp/chap-secrets file,
72 # which holds usernames and passwords
73 my $chap_secrets_file = '/etc/ppp/chap-secrets';
74 open( FILE, ">>$chap_secrets_file" )
75 or die "$0: can't write to '$chap_secrets_file': $!\n";
77 print FILE "\n# added by pptpsetup for $TUNNEL\n$DOMAIN$USERNAME $TUNNEL \"$PASSWORD\" *\n";
81 # create a /etc/ppp/peers/$TUNNEL file
82 my $tunnel_file = "/etc/ppp/peers/$TUNNEL";
83 open( FILE, ">$tunnel_file" )
84 or die "$0: can't write to '$tunnel_file': $!\n";
86 print FILE <<"TUNNEL";
87 # written by pptpsetup
88 pty "pptp $SERVER --nolaunchpppd"
98 print FILE "require-mppe-128\n" if $ENCRYPT;
104 system("pppd call $TUNNEL updetach");
112 pptpsetup --create <TUNNEL> --server <SERVER> [--domain <DOMAIN>]
113 --username <USERNAME> [--password <PASSWORD>]
114 [--encrypt] [--start]
116 pptpsetup --delete <TUNNEL>
120 * the name you wish to use to refer to the tunnel (you choose it),
121 * the IP address or host name of the server,
122 * the authentication domain name (optional),
123 * the username you are to use,
124 * the password you are to use,
125 * whether encryption is required,
126 * whether to start the connection after configuration.
128 pptpsetup - Point-to-Point Tunneling Protocol setup
130 Copyright (C) 2006 Nelson Ferraz
132 pptpsetup comes with ABSOLUTELY NO WARRANTY; for details see source.
133 This is free software, and you are welcome to redistribute it
134 under certain conditions; see source for details.
147 ($tunnel) = $tunnel =~ m{^(\w+)$}
148 or die "$0: invalid tunnel name.\nTry '$0 --help' for more information.\n";
151 my $tunnel_file = "/etc/ppp/peers/$tunnel";
153 or die "$0: can't delete '$tunnel_file': $!\n";
155 # delete entry from chap-secrets
156 my $chap_file = '/etc/ppp/chap-secrets';
158 open( FILE, $chap_file )
159 or die "$0: can't read '$chap_file': $!\n";
165 $new_chap .= $_ unless /\b$tunnel\b/;
169 rename( $chap_file, "$chap_file.bkp" );
171 # write new chap-secrets
172 open( FILE, ">$chap_file" )
173 or die "$0: can't write '$chap_file': $!\n";
174 print FILE $new_chap;
180 ### AUXILIAR SUBS ###
182 sub Check_MPPE_in_kernel {
183 my $command = q/modprobe ppp-compress-18/;
184 if (system( $command ) == 0) {
192 sub Check_MPPE_in_pppd {
193 my $command = q/strings `which pppd`|grep -i mppe|wc --lines/;
194 my $answer = `$command`;
207 pptpsetup - Point-to-Point Tunneling Protocol setup
211 pptpsetup --create <TUNNEL> --server <SERVER> [--domain <DOMAIN>]
212 --username <USERNAME> [--password <PASSWORD>]
213 [--encrypt] [--start]
215 pptpsetup --delete <TUNNEL>
219 PPTP Client is a Linux, FreeBSD, NetBSD and OpenBSD client for the
220 proprietary Microsoft Point-to-Point Tunneling Protocol, PPTP.
222 This script configures PPTP Client on Linux.
228 =item --create TUNNEL
230 create a tunnel named TUNNEL
232 =item --delete TUNNEL
234 delete the file /etc/ppp/peers/TUNNEL and any lines from
235 /etc/ppp/chap-secrets that contains "TUNNEL" as a single word
237 =item --server SERVER
239 the IP address or host name of the server
241 =item --domain DOMAIN
243 the authentication domain name (optional)
245 =item --username USERNAME
247 the username you are to use
249 =item --password PASSWORD
251 the password you are to use. If you don't specify a password,
252 pptpsetup will ask for one.
256 whether encryption is required
260 whether the connection should be started after configuration.
266 Nelson Ferraz <nferraz at gmail.com>,
267 based on James Cameron's PPTP Client Debian HOWTO.
273 =item PPTP Client Debian HOWTO
275 http://pptpclient.sourceforge.net/howto-debian.phtml
277 =item PPTP Client Diagnosis HOWTO
279 http://pptpclient.sourceforge.net/howto-diagnosis.phtml
285 pptpsetup - Point-to-Point Tunneling Protocol setup
287 Copyright (C) 2006 Nelson Ferraz
289 This program is free software; you can redistribute it and/or modify
290 it under the terms of the GNU General Public License as published by
291 the Free Software Foundation; either version 2 of the License, or
292 (at your option) any later version.
294 This program is distributed in the hope that it will be useful,
295 but WITHOUT ANY WARRANTY; without even the implied warranty of
296 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
297 GNU General Public License for more details.
299 You should have received a copy of the GNU General Public License
300 along with this program; if not, write to the Free Software
301 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA