#!/usr/bin/perl -wT # vim: set sw=4 ts=4 si et: # Copyright: GPL # Written by Guido Socher # This script must have chmod 6755 and the file should be owned by root # It is a Set-UID script. Therefore you don't need to be logged in a root # to start the ppp connection. # # The ppp-on script initiates a ppp connection. This script is designed # for handling multiple phone numbers. It is useful if your provider has # a number of different modem pools with different numbers or you are # using different internet service providers. # use strict; use vars qw($opt_h); use Getopt::Std; # # # delete the environment: %ENV=(); # $ENV{'IFS'}=" "; # pppd must be somewhere in this path: $ENV{'PATH'}="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin"; $ENV{'HOME'}="/tmp"; $<=$>; my $peersfile=""; &getopts("h")||die "ERROR: No such option. -h for help\n"; &help if ($opt_h); &help unless($ARGV[0]); if ($ARGV[0]=~/^([\w\.]+)$/){ $peersfile=$1; }else{ die "ERROR: $ARGV[0], the name of the /etc/ppp/peers file may only contain letters, numbers, underscore and a dot\n"; } if ( -f "/var/lock/LCK..modem" ){ print "ppp-on: no action, ppp already up, /var/lock/LCK..modem exists\n"; exit 0; } # &dnsstaticcheck($peersfile); # if ( -f "/etc/ppp/peers/$peersfile") { # execute pppd: print `pppd call $peersfile`; }else{ die "ERROR: no file /etc/ppp/peers/$peersfile\n"; } # # Not all ISPs use dynamic DNS. For those you can add the DNS servers # to the statement below. If the ISP has dynamic DNS then # the static settings are not used. # We write the ip addresses of the the DNS into a file and the # ip-up script will read them from there. # sub dnsstaticcheck($){ my $peers=shift; my $dnsstatic="# no static dns"; if ( $peers =~ m/^(02418863200|02418863230|02418863100|oche)$/){ $dnsstatic="# uptown.oche.de 194.94.252.3 # urmel.informatik.RWTH-Aachen.DE 137.226.112.21 # some machine at oche 194.94.253.3 "; }elsif ($peers =~ m/^(o.tel.o)$/){ $dnsstatic="# o.tel.o 195.50.149.33 195.50.140.6 "; }elsif ($peers =~ m/^(talknet|019251)$/){ $dnsstatic="# talknet 195.252.143.26 194.192.187.132 "; }elsif ($peers =~ m/^(eed1|eed2)$/){ $dnsstatic="# eed 164.48.134.130 "; } open(DNSSTATIC,">/etc/ppp/dnsstatic")||die "ERROR: can not write /etc/ppp/dnsstatic\n"; print DNSSTATIC "$dnsstatic\n"; close DNSSTATIC; } # sub help{ print "Initiate a ppp connection to your ISP. You can run this as normal user and you do not need to be logged in as root. Usage: ppp-on [file-from-/etc/ppp/peers] \n"; exit; } __END__