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
|
#!/bin/sh
#
# This script is called when ppp connects to the network.
#
# Here is where we'll start sendmail if needed, and will
# run the queue in either case.
#
# Written By Richard Nelson <cowboy@debian.org>
#
# NOTE: The following lines (without the #) must be in /etc/mail/sendmail.mc:
# include(`/etc/mail/dialup.m4')dnl
# include(`/etc/mail/provider.m4')dnl
#
# ALSO: make sure ipparam is specified somewhere in the ppp options;
# it will be used as the name of a file in /etc/mail/peers
#
# Exit by default, check for validity before commenting out the next line:
exit 0;
# Define our domain name (from PPP) for sendmail.
# These variables are for the use of the scripts run by run-parts
#PPP_IFACE="$1";
#PPP_TTY="$2";
#PPP_SPEED="$3";
#PPP_LOCAL="$4";
#PPP_REMOTE="$5";
#PPP_IPPARAM="$6";
if [ ! -z "$PPP_LOCAL" ]; then
addr=$PPP_LOCAL;
provider=$PPP_IPPARAM;
else
addr=$1;
provider=$2;
fi;
# Determine our fqdn from our ISP
maxloop=20;
cntr=0;
name="";
until (test ! -z "$name"); do
cntr=$(($cntr+1));
rev=$(host $addr);
name=$(echo "$rev" | grep '^Name:' | awk '{print $2}');
if [ -z "$name" ]; then
name=${rev##*domain name pointer };
name=${name%.};
fi;
test=$(echo $name | cut -d ' ' -f 1);
if [ "$name" != "**" ]; then
break;
elif (($cntr > $maxloop)); then
name='';
break;
fi;
done;
echo "addr=$addr, name=$name";
file="/etc/mail/dialup.m4";
#file="dialup.m4";
if [ ! -z "$name" ]; then
cat <<-EOT > $file;
LOCAL_CONFIG
#------------------------------------------------------------
#
# Dynamic updates from $0
#
# NOTE: the following line *MUST* be in /etc/mail/sendmail.mc
dnl include(\`/etc/mail/dialup.m4')dnl
#
# Chose one of the following options:
# * Add our true hostname as a Virtual Host (we'll accept
# mail for it, but keep our local name for SMTP AUTH, etc)
dnl C{VirtHost}$name
# * Define our true hostname (from our ISP) becomes \$j
dnl define(\`confDOMAIN_NAME', \`$name')dnl
#
# Make sure we accept mail as this name (for bounces, etc)
Cw$name
# Add our hostname to class G for genericstable support
CG$name
#------------------------------------------------------------
EOT
fi;
# Add smarthost information (if any)... But not if provider.m4 is a link !
file="/etc/mail/provider.m4";
#file="provider.m4";
if [ -f /etc/mail/peers/$provider -a ! -L $file ]; then
cat <<-EOT > $file;
LOCAL_CONFIG
#------------------------------------------------------------
#
# Dynamic updates from $0
#
# NOTE: the following line *MUST* be in /etc/mail/sendmail.mc
dnl include(\`/etc/mail/provider.m4')dnl
#
# Provider information from /etc/mail/peers/$provider
EOT
cat /etc/mail/peers/$provider >> $file;
cat <<-EOT >> $file;
#------------------------------------------------------------
EOT
fi;
#exit 0
# Build a new sendmail.cf from sendmail.mc, including our address.
# NOTE: The following lines (without the #) must be in /etc/mail/sendmail.mc:
# include(`/etc/mail/dialup.m4')dnl
# include(`/etc/mail/provider.m4')dnl
m4 /etc/mail/sendmail.mc \
> /etc/mail/sendmail.cf.pnew;
chmod 0644 /etc/mail/sendmail.cf.pnew;
chown mail:mail /etc/mail/sendmail.cf.pnew;
mv -f /etc/mail/sendmail.cf.pnew /etc/mail/sendmail.cf;
# Purge any latent host status that might cause us to *NOT* send mail
AM='-Am';
if [ ! -f /usr/share/sendmail/cf/feature/msp.m4 ]; then
AM='';
fi;
sendmail $AM -bH -O Timeout.hoststatus=1s;
# Start/reload sendmail as needed
/etc/init.d/sendmail reload; # may be up, or down
# Process the sendmail queue (background so as to not defer other ip-up work)
runq &
|