Public feed
#724881
#!/bin/bash
# this is a script which is executed after connecting the ppp interface.
# look at man pppd for details
# the followings parameters are available:
# $1 = interface-name
# $2 = tty-device
# $3 = speed
# $4 = local-IP-address
# $5 = remote-IP-address
# $6 = ipparam
if [ "$USEPEERDNS" ]; then
if [ -x /sbin/resolvconf ]; then
conf="# Generated by ppp for $1\n"
[ -n "$DNS1" ] && conf="${conf}nameserver $DNS1\n"
[ -n "$DNS2" ] && conf="${conf}nameserver $DNS2\n"
echo -e "$conf" | resolvconf -a "$1"
else
# add the server supplied DNS entries to /etc/resolv.conf
# (taken from debian's 0000usepeerdns)
# follow any symlink to find the real file
REALRESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)
if [ "$REALRESOLVCONF" != "/etc/ppp/resolv.conf" ]; then
# merge the new nameservers with the other options from the old configuration
{
grep --invert-match '^nameserver[[:space:]]' $REALRESOLVCONF
cat /etc/ppp/resolv.conf
} > $REALRESOLVCONF.tmp
# backup the old configuration and install the new one
cp -dpP $REALRESOLVCONF $REALRESOLVCONF.pppd-backup
mv $REALRESOLVCONF.tmp $REALRESOLVCONF
# correct permissions
chmod 0644 /etc/resolv.conf
chown root:root /etc/resolv.conf
fi
fi
fi
if [ -x /etc/init.d/net.$1 ]; then
if ! /etc/init.d/net.$1 --quiet status ; then
export IN_BACKGROUND="true"
/etc/init.d/net.$1 --quiet start
fi
fi
[ -f /etc/ppp/ip-up.local ] && . /etc/ppp/ip-up.local "$@"
#######################################"
############ MODIFICATIONS################
#######################################
# Ajout de la route automatique vers le PPTP
# Gamez
# makeperl@gmail.com
# Parse de l'adresse ip
#
# parse_ip adresseip
# renvoie OCTET1
#######################################
function parse_ip () {
local IP=$1
if [ -n "$IP" ]
then
OCTET1IP=$(echo "$IP" | cut -d "." -f 1)
fi
}
# Detecte le masque reseau
# suivant OCTET1IP
#
# renvoie IPROUTE // renvoie l'adresse réseau par defaut
# renvoie MASKROUTE //masque par defaut de la classe
######################################
function detect_mask() {
RETURNACTION="FALSE";
if [ -n "$OCTET1IP" ]
then
case "$OCTET1IP" in
10)
IPROUTE="10.0.0.0";
MASKROUTE="255.0.0.0";
CIDR="8";
RETURNACTION="TRUE";
;;
172)
IPROUTE="172.16.0.0";
MASKROUTE="255.255.0.0";
CIDR="16";
RETURNACTION="TRUE";
;;
192)
IPROUTE="192.168.0.0";
MASKROUTE="255.255.255.0";
CIDR="24";
RETURNACTION="TRUE";
;;
*)
RETURNACTION="FALSE";
;;
esac
fi
}
DEV=$1;
LOCALIP=$4;
LOGFILE='/var/log/logRoute';
FORMATDATE='%d/%m/%Y-%T';
if [ -n "$LOCALIP" ] # if the local ip address is present
then
parse_ip $LOCALIP;
if [ -n "$OCTET1IP" ] # if we have the first octet
then
detect_mask $OCTET1IP ;
if [ -n "$RETURNACTION" ] && [ "$RETURNACTION" != "FALSE" ] # if we have the mask
then
route add -net $IPROUTE netmask $MASKROUTE dev $DEV
echo "`date +$FORMATDATE` Routing $IPROUTE/$CIDR via $DEV" >> $LOGFILE;
else
echo "`date +$FORMATDATE` Searching mask failled" >> $LOGFILE;
fi
else
echo "`date +$FORMATDATE` The first octet is not found" >> $LOGFILE;
fi
else
echo "`date +$FORMATDATE` Local ip of the VPN connection is not found" >> "$LOGFILE";
fi