1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#!/usr/bin/perl
# cvt-pppconfig - utility to convert Debian pppconfig settings to diald
# config files.
# Copyright (c) 2000 Software in the Public Interest, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Written by Jeff Licquia <licquia@debian.org>.
# This program acts as a filter; it reads information from the
# pppconfig peers file referenced on the command line (or from stdin
# if none are specified) and writes a diald.options file on stdout.
# Changelog:
# 04/09/2000 Initial version.
# 08/20/2000 Fixed problem w/ hashes in usernames; added ability to
# specify a different default local and remote IP.
# Some of the pppd settings are controlled by diald instead of pppd;
# others should be passed on to pppd. All options not specified here
# get passed to pppd. (The port and speed settings get passed to
# diald as well.)
@diald_options = ("connect", "crtscts", "defaultroute",
"netmask", "modem", "mtu", "proxyarp");
# These pppd options should be suppressed if they appear in a
# pppconfig file for diald's purposes.
@diald_disallow = ("detach", "local", "xonxoff", "lock");
# These options should always be passed to pppd.
@pppd_options = ("nopersist");
# The default local/remote IP addresses may need to be changed. If
# the file exists that contains different addresses, change the
# defaults.
$deflocal = "192.168.0.1";
$defremote = "192.168.0.2";
if (-f "/etc/diald/cvtaddrs")
{
open(DEFADDRS, "/etc/diald/cvtaddrs");
($deflocal, $defremote) = <DEFADDRS>;
close DEFADDRS;
chomp $deflocal, $defremote;
}
# Now, to the nitty gritty. First, read the options file.
@pcoptions = <>;
# Write an introductory header to the options file, explaining where
# it came from.
print "# This file is autogenerated. Use 'dpkg-reconfigure diald' to change it.\n\n";
# Parse the options, writing diald-style options when necessary.
foreach $pcoption (@pcoptions)
{
# Skip & strip comments
next if $pcoption =~ /^\s*\#/;
$pcoption =~ s/\s*\#[^#]*$//;
# Snag the first keyword
$keyword = (split(/\s+/, $pcoption))[0];
# Skip if the option simply isn't allowed
next if grep(/$keyword/, @diald_disallow);
if (grep(/$keyword/, @diald_options))
{
# Diald option - include directly in diald config
print "$pcoption\n";
next;
}
if ($keyword =~ /^\d+/)
{
# Speed parameter for diald
print "speed $keyword\n";
next;
}
if ($keyword =~ /^\/dev/)
{
# Device parameter for diald
print "device $keyword\n";
next;
}
if ($keyword =~ /^(\d*):(\d*)/)
{
# IP addresses
next if ($1 !~ /\d/) and ($2 !~ /\d/);
if ($1 =~ /\d/)
{
print "local $1\n";
$nolocal = 1;
}
if ($2 =~ /\d/)
{
print "remote $2\n";
$noremote = 1;
}
next;
}
# Nothing else matches - include it as a pppd option
chomp $pcoption;
push @pppd_options, $pcoption;
}
# Write local and remote address if not already given
print "local $deflocal\n" unless $nolocal;
print "remote $defremote\n" unless $noremote;
# Write the pppd options to the diald config file
print "pppd-options ", join(" ", @pppd_options), "\n";
# Make sure the standard defaults files are also included
print "include /etc/diald/diald.defaults\n";
# All done!
|