#!/bin/bash 
###############################################################################
#
#	PPPSETUP  --  Script to set up pppd
#  	History:
#	  7/21/95 RSL         Script created (v1.0)
#         9/15/96 RSL         Added code to get the ISP's domainname (v1.1)
#         9/19/96 RSL         Revamped interface to use the 'dialog' 
#                             program. (v1.2)
###############################################################################

###############################################################################
#        12/8/97 KR           Added pap, chap, ms-chap, callback, & 
#                             modem init string options. (v1.66)
#                             Creates /etc/ppp/options, & pap, chap, 
#			      secrets files.
#                             More guidance.
#                             Monitor connection with tail & syslogd.
#                             Demand dialing setup with ppp-2.3.0 or later.        
###############################################################################

if [ ! "$UID" = "0" ]; then
echo
echo "NOTICE: * $LOGNAME * You need to be 'root' to run this script."
echo "You could login: root"
echo "You could also try this: # sudo pppsetup"
echo "You could also try this: # su -c pppsetup"
echo "This assumes the permissions on 'sudo' and 'su' are 4111."
echo "To give 'su' or 'sudo' these permissions, you have to be root."
echo "~# chown root.root sudo ; chmod 4111 sudo"
echo "You also need a /etc/sudoers file for 'sudo'."
echo
exit 1
fi

if ! type -all "dialog" >/dev/null 2>&1 ; then
echo
echo "Can't find 'dialog', i can't run without 'dialog' on your system."
echo "You can get a compiled ELF version of 'dialog' from here."
echo "ftp://wauug.erols.com/pub/people/kent-robotti   'dialog-0.9a.ELF.tar.gz'"
echo
exit 1
fi

if [ ! -d /tmp ]; then
mkdir /tmp
chmod 1777 /tmp
fi

stty erase ^? 2>/dev/null 
 
VERSION="1.66"

echo "PPPSETUP v$VERSION" > /tmp/txtTEMP01
echo >> /tmp/txtTEMP01
echo "Written by Robert S. Liesenfeld <xunil@bitstream.net> <IRC:Xunil>" >> /tmp/txtTEMP01
echo "Changes for 1.66 by Kent Robotti <robotti@pop.erols.com>" >> /tmp/txtTEMP01
echo >> /tmp/txtTEMP01
echo "You should get these 'DOCS' if you don't already have them." >> /tmp/txtTEMP01
echo 'ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO "PPP-HOWTO"' >> /tmp/txtTEMP01
echo 'ftp://sunsite.unc.edu/pub/Linux/docs/faqs/PPP-FAQ "PPP-FAQ"' >> /tmp/txtTEMP01
echo >> /tmp/txtTEMP01
echo "Press [Enter] to continue with pppsetup..." >> /tmp/txtTEMP01

dialog --backtitle "PPPSETUP v$VERSION ..." --textbox "/tmp/txtTEMP01" 14 70 

while [ -z "$PHONENUM" ]
do
echo "To begin setting up your PPP connection, i need to know a few things." > /tmp/txtTEMP$$
echo "For starters, what is the phone number of your (I)nternet (S)ervice" >> /tmp/txtTEMP$$ 
echo "(P)rovider?" >> /tmp/txtTEMP$$ 
echo  >> /tmp/txtTEMP$$ 
echo "Example: atdt6661776   <-For (t)one dialing.)" >> /tmp/txtTEMP$$ 
echo "Example: atdp6661776   <-For (p)ulse dialing.)" >> /tmp/txtTEMP$$ 
echo  >> /tmp/txtTEMP$$ 
echo "Tip: Add ,,,, if you have a problem connecting, no harm done." >> /tmp/txtTEMP$$ 
echo "Example: atdt6661776,,,," >> /tmp/txtTEMP$$ 
echo  >> /tmp/txtTEMP$$ 
echo "Include the: atd?  It's usally just: atdtphonenumber" >> /tmp/txtTEMP$$ 
echo  >> /tmp/txtTEMP$$ 
echo "(Note: in the USA, use atdt*70,6661776 [comma required!] to turn" >> /tmp/txtTEMP$$ 
echo " off call waiting.)" >> /tmp/txtTEMP$$ 
echo  >> /tmp/txtTEMP$$ 
	
dialog --title "PHONE NUMBER ..." --inputbox "`cat /tmp/txtTEMP$$`" 21 75 2> /tmp/rspTEMP$$   

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit
fi 

PHONENUM="`cat /tmp/rspTEMP$$`"
 
if [ -z "$PHONENUM" ]; then
clear 2>/dev/null || echo
rm -f /tmp/*TEMP*
echo "PPP configuration cancelled."
echo "No phone number."
exit
fi
done

if [ -L /dev/modem ]; then
echo -n "I found your modem!   `ls -l /dev/modem | cut -b56-108`" > /tmp/txtTEMP$$ 
echo >> /tmp/txtTEMP$$ 
echo "If correct chose CORRECT or change if not correct." >> /tmp/txtTEMP$$ 
dialog --backtitle "MODEM DEVICE ..." --menu "`cat /tmp/txtTEMP$$`" 13 60 5 \
/CORRECT/ "= (`ls -l /dev/modem | cut -b56-108`)" \
/dev/cua0 "= (COM1: under DOS)" \
/dev/cua1 "= (COM2: under DOS)" \
/dev/cua2 "= (COM3: under DOS)" \
/dev/cua3 "= (COM4: under DOS)" \
2> /tmp/rspTEMP$$
else
echo "Where is your modem /dev/cua?" > /tmp/txtTEMP$$ 
dialog --backtitle "MODEM DEVICE ..." --menu "`cat /tmp/txtTEMP$$`" 11 55 4 \
/dev/cua0 "= (COM1: under DOS)" \
/dev/cua1 "= (COM2: under DOS)" \
/dev/cua2 "= (COM3: under DOS)" \
/dev/cua3 "= (COM4: under DOS)" \
2> /tmp/rspTEMP$$
fi

DEVICE="`cat /tmp/rspTEMP$$`"

if [ -z $DEVICE ]; then
clear 2>/dev/null || echo
rm -f /tmp/*TEMP*
echo "PPP configuration cancelled."
exit 
elif [ `cat /tmp/rspTEMP$$` = "/CORRECT/" ]; then
DEVICE="/dev/modem"
else
rm -f /dev/modem 2>/dev/null
ln -sf $DEVICE /dev/modem 2>/dev/null 
DEVICE="/dev/modem"
fi

echo "What baud rate is your modem?" > /tmp/txtTEMP$$
dialog --backtitle "MODEM BAUD RATE ..." --menu "`cat /tmp/txtTEMP$$`" 14 72 7 \
460800 "460KBps  - ISDN modem..." \
230400 "230KBps  - 56Kbps modem... or ISDN modem..." \
115200 "115KBps  - 28.8, 33.6, or 56Kbps modem..." \
57600  "57.6KBps - 28.8, 33.6, or 56Kbps modem..." \
38400  "38.4KBps - Hangin ten on the net! 28.8 or 33.6..." \
19200  "19.2KBps - Better known as 14.4..." \
9600   "9600bps  - No comment..." 2> /tmp/rspTEMP$$

BAUDRATE="`cat /tmp/rspTEMP$$`"

if [ -z $BAUDRATE ]; then
clear 2>/dev/null || echo
rm -f /tmp/*TEMP*
echo "PPP configuration cancelled."
exit 
fi

echo "Does your service provider use CALLBACK?" > /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "CALLBACK is when you call your service provider and give them" >> /tmp/txtTEMP$$
echo "your phone number so they can call you back, then when they" >> /tmp/txtTEMP$$
echo "call you back you give them your login name and password." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "Most service providers don't use CALLBACK, so the answer is" >> /tmp/txtTEMP$$
echo "probably No, unless you know otherwise." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$

dialog --backtitle "CALLBACK YES or NO? ..." --yesno "`cat /tmp/txtTEMP$$`" 13 70 

if [ $? = 0 ]; then
echo "Put your phone number in the box below, so your service provider" > /tmp/txtTEMP$$
echo "can call you back." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "Example: 7771818" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$

dialog --backtitle "CALLBACK Your Phone Number? ..." --inputbox "`cat /tmp/txtTEMP$$`" 11 72 2> /tmp/cb1TEMP$$

if [ $? = 1 ]; then
clear 2>/dev/null || echo
rm -f /tmp/*TEMP*
echo "PPP configuration cancelled."
exit 
elif [ ! -s /tmp/cb1TEMP$$ ]; then
clear 2>/dev/null || echo
rm -f /tmp/*TEMP*
echo "PPP configuration cancelled."
echo "No Phone Number for Callback."
exit
fi 
fi

if [ -s /tmp/cb1TEMP$$ ]; then
CBPN="`cat /tmp/cb1TEMP$$`"
echo "I have your phone number: $CBPN" > /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "Do you have to give a Username or Login for the initial connection" >> /tmp/txtTEMP$$
echo "to $PHONENUM before you're called back." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "Example: jerry" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "If NO, just press [Enter] on a empty box and skip this." >> /tmp/txtTEMP$$

dialog --backtitle "CALLBACK INITIAL LOGIN? ..." --inputbox "`cat /tmp/txtTEMP$$`" 15 74 2> /tmp/cb1.1TEMP$$

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit 
else
CBMODLOGIN="`cat /tmp/cb1.1TEMP$$`"
fi 
fi

if [ -s /tmp/cb1TEMP$$ ]; then
echo "I have your phone number: $CBPN" > /tmp/txtTEMP$$
if [ -s /tmp/cb1.1TEMP$$ ]; then
echo "I see you have to give a Username or Login: $CBMODLOGIN" >> /tmp/txtTEMP$$
echo "for the initial connection to: $PHONENUM" >> /tmp/txtTEMP$$
fi
echo >> /tmp/txtTEMP$$
echo "Do you have to give a Password for the initial connection" >> /tmp/txtTEMP$$
echo "to $PHONENUM before you're called back." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "Example: Zoy85mWc" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "If NO, just press [Enter] on a empty box and skip this." >> /tmp/txtTEMP$$

dialog --backtitle "CALLBACK INITIAL PASSWORD? ..." --inputbox "`cat /tmp/txtTEMP$$`" 17 68 2> /tmp/cb2TEMP$$

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit 
else
CBMODPASS="`cat /tmp/cb2TEMP$$`"
fi
fi

if [ -n "$CBPN" ]; then
echo "Are they using PAP or CHAP for AUTHENTICATION?" > /tmp/txtTEMP$$
echo "If you're presented with a Username: or Login: and Password: prompt" >> /tmp/txtTEMP$$
echo "when you connect to your service provider, they're probably not" >> /tmp/txtTEMP$$
echo "using PAP or CHAP, so you can answer NO here." >> /tmp/txtTEMP$$
echo "If you're not sure, you'll have to ask you're service provider." >> /tmp/txtTEMP$$

dialog --backtitle "CALLBACK PAP-CHAP YES or NO? ..." --yesno "`cat /tmp/txtTEMP$$`" 9 72 

if [ $? = 1 ]; then
echo "What is your Username or Login to your service provider?" > /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "This is the information you'll give them when they call" >> /tmp/txtTEMP$$
echo "you back at: $CBPN" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "Example: jerry" >> /tmp/txtTEMP$$

dialog --backtitle "CALLBACK LOGIN? ..." --inputbox "`cat /tmp/txtTEMP$$`" 13 72 2> /tmp/cb3TEMP$$

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit 
fi

CBLOGIN="`cat /tmp/cb3TEMP$$`"

if [ -z "$CBLOGIN" ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
echo "No Login for Callback."
exit 
fi
fi
fi

if [ -n "$CBLOGIN" ]; then
echo "What is the Password for: $CBLOGIN" > /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "Example: Ziy79Kie" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$

dialog --backtitle "CALLBACK PASSWORD? ..." --inputbox "`cat /tmp/txtTEMP$$`" 10 64 2> /tmp/cb4TEMP$$

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit 1 
fi

CBPASS="`cat /tmp/cb4TEMP$$`"

if [ -z "$CBPASS" ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
echo "No Password for Callback."
exit 1
fi
fi

callback1() {
 cat << EOF
TIMEOUT	       10
ABORT	       BUSY    			
ABORT	       ERROR    			
ABORT	       "NO DIALTONE"   		
REPORT         "CARRIER"
REPORT         "CONNECT"
""	       "AT\&F&C0W1S0=0H0"  		
OK	       "ATDT$PHONENUM"			
TIMEOUT	       60
CONNECT	       ""				
ogin:--name:   "$CBMODLOGIN"	                
word:--word:   "$CBMODPASS"			
"NO CARRIER"   "\c"
TIMEOUT	       75
ABORT          VOICE
RING           "AT\&C1A"				
CONNECT	       ""
ogin:--name:   "$CBLOGIN"	                
word:--word:   "$CBPASS"

EOF
}

callback2() {
 cat << EOF
TIMEOUT	       10
ABORT	       BUSY    			
ABORT	       ERROR    			
ABORT	       "NO DIALTONE"   		
REPORT         "CARRIER"
REPORT         "CONNECT"
""	       "AT\&F&C0W1S0=0H0"  		
OK	       "ATDT$PHONENUM"			
TIMEOUT	       60
CONNECT	       ""				
"NO CARRIER"   "\c"
TIMEOUT	       75
ABORT          VOICE
RING           "AT\&C1A"				
CONNECT	       

EOF
}

callback3() {
 cat << EOF
TIMEOUT	       10
ABORT	       BUSY    			
ABORT	       ERROR    			
ABORT	       "NO DIALTONE"   		
REPORT         "CARRIER"
REPORT         "CONNECT"
""	       "AT\&F&C0W1S0=0H0"  		
OK	       "ATDT$PHONENUM"			
TIMEOUT	       60
CONNECT	       ""				
"NO CARRIER"   "\c"
TIMEOUT	       75
ABORT          VOICE
RING           "AT\&C1A"				
CONNECT	       ""
ogin:--name:   "$CBLOGIN"	                
word:--word:   "$CBPASS"

EOF
}

callback4() {
 cat << EOF
TIMEOUT	       10
ABORT	       BUSY    			
ABORT	       ERROR    			
ABORT	       "NO DIALTONE"   		
REPORT         "CARRIER"
REPORT         "CONNECT"
""	       "AT\&F&C0W1S0=0H0"  		
OK	       "ATDT$PHONENUM"			
TIMEOUT	       60
CONNECT	       ""				
word:--word:   "$CBMODPASS"			
"NO CARRIER"   "\c"
TIMEOUT	       75
ABORT          VOICE
RING           "AT\&C1A"				
CONNECT	       ""
ogin:--name:   "$CBLOGIN"	                
word:--word:   "$CBPASS"

EOF
}

callback5() {
 cat << EOF
TIMEOUT	       10
ABORT	       BUSY    			
ABORT	       ERROR    			
ABORT	       "NO DIALTONE"   		
REPORT         "CARRIER"
REPORT         "CONNECT"
""	       "AT\&F&C0W1S0=0H0"  		
OK	       "ATDT$PHONENUM"			
TIMEOUT	       60
CONNECT	       ""				
ogin:--name:   "$CBMODLOGIN"	                
word:--word:   "$CBMODPASS"			
"NO CARRIER"   "\c"
TIMEOUT	       75
ABORT          VOICE
RING           "AT\&C1A"				
CONNECT	       

EOF
}

callback6() {
 cat << EOF
TIMEOUT	       10
ABORT	       BUSY    			
ABORT	       ERROR    			
ABORT	       "NO DIALTONE"   		
REPORT         "CARRIER"
REPORT         "CONNECT"
""	       "AT\&F&C0W1S0=0H0"  		
OK	       "ATDT$PHONENUM"			
TIMEOUT	       60
CONNECT	       ""				
ogin:--name:   "$CBMODLOGIN"	                
"NO CARRIER"   "\c"
TIMEOUT	       75
ABORT          VOICE
RING           "AT\&C1A"				
CONNECT	       

EOF
}

callback7() {
 cat << EOF
TIMEOUT	       10
ABORT	       BUSY    			
ABORT	       ERROR    			
ABORT	       "NO DIALTONE"   		
REPORT         "CARRIER"
REPORT         "CONNECT"
""	       "AT\&F&C0W1S0=0H0"  		
OK	       "ATDT$PHONENUM"			
TIMEOUT	       60
CONNECT	       ""				
word:--word:   "$CBMODPASS"			
"NO CARRIER"   "\c"
TIMEOUT	       75
ABORT          VOICE
RING           "AT\&C1A"				
CONNECT	       

EOF
}

if [ ! -d /etc/ppp ]; then 
mkdir -p /etc/ppp
fi

if [ -s /tmp/cb1TEMP$$ ]; then
if [ -s /tmp/cb1.1TEMP$$ ] && [ -s /tmp/cb2TEMP$$ ] && [ -s /tmp/cb3TEMP$$ ] && [ -s /tmp/cb4TEMP$$ ]; then
callback1 > /etc/ppp/callback
elif [ ! -s /tmp/cb1.1TEMP$$ ] && [ ! -s /tmp/cb2TEMP$$ ] && [ ! -s /tmp/cb3TEMP$$ ] && [ ! -s /tmp/cb4TEMP$$ ]; then
callback2 > /etc/ppp/callback
elif [ ! -s /tmp/cb1.1TEMP$$ ] && [ ! -s /tmp/cb2TEMP$$ ] && [ -s /tmp/cb3TEMP$$ ] && [ -s /tmp/cb4TEMP$$ ]; then
callback3 > /etc/ppp/callback
elif [ ! -s /tmp/cb1.1TEMP$$ ] && [ -s /tmp/cb2TEMP$$ ] && [ -s /tmp/cb3TEMP$$ ] && [ -s /tmp/cb4TEMP$$ ]; then
callback4 > /etc/ppp/callback
elif [ -s /tmp/cb1.1TEMP$$ ] && [ -s /tmp/cb2TEMP$$ ] && [ ! -s /tmp/cb3TEMP$$ ] && [ ! -s /tmp/cb4TEMP$$ ]; then
callback5 > /etc/ppp/callback
elif [ -s /tmp/cb1.1TEMP$$ ] && [ ! -s /tmp/cb3TEMP$$ ] && [ ! -s /tmp/cb4TEMP$$ ]; then
callback6 > /etc/ppp/callback
elif [ -s /tmp/cb2TEMP$$ ] && [ ! -s /tmp/cb3TEMP$$ ] && [ ! -s /tmp/cb4TEMP$$ ]; then
callback7 > /etc/ppp/callback
fi
fi

if [ -s /etc/ppp/callback ]; then
chown root.root /etc/ppp/callback 2>/dev/null
chmod 600 /etc/ppp/callback 2>/dev/null
fi

if [ ! -s /tmp/cb1TEMP$$ ]; then	
echo 'The default modem init string will be: "AT\&FW1H0" OK' > /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "If you want to change it, put your init string in the box below." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "If you use \ in the init string, put it twice." >> /tmp/txtTEMP$$
echo 'Example: "AT\&F\\K3\\N3W1H0" OK' >> /tmp/txtTEMP$$
echo "M = No sound. W1 = Show CARRIER speed: 28800 etc." >> /tmp/txtTEMP$$
echo 'Put "" around each init string with "&" in it.' >> /tmp/txtTEMP$$
echo 'Put OK after each init string. Example: ATZ OK "AT\&FMW1H0" OK' >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "Just press [Enter] on a empty box to accept the default above." >> /tmp/txtTEMP$$

dialog --backtitle "MODEM INIT STRING ..." --inputbox "`cat /tmp/txtTEMP$$`" 18 74 2> /tmp/rspTEMP$$

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit 
fi 

if [ -s /tmp/rspTEMP$$ ]; then
INIT="`cat /tmp/rspTEMP$$`"
else
INIT="below"
fi
fi

echo "What is your (I)nternet (S)ervice (P)rovider's domain name?" > /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "This is usually something like..." >> /tmp/txtTEMP$$
echo "Examples: something.edu something.net something.com something.org" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$

dialog --backtitle "DOMAIN NAME ..." --inputbox "`cat /tmp/txtTEMP$$`" 11 74 2> /tmp/rspTEMP$$

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit 
fi 

DOMAINNAME="`cat /tmp/rspTEMP$$`"

echo "What is the IP address of your Internet provider's nameserver?" > /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "It's important that these IP numbers be correct." >> /tmp/txtTEMP$$
echo "The IP numbers should not be: 0.0.0.0" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "Note: Your service provider's technical support can provide you" >> /tmp/txtTEMP$$
echo "with this information.   Example: 207.132.116.5" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$

dialog --backtitle "DNS IP ADDRESS ..." --inputbox "`cat /tmp/txtTEMP$$`" 14 74 2> /tmp/rspTEMP$$

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit 
fi 

DNSIP="`cat /tmp/rspTEMP$$`"

if [ ! -s /tmp/cb3TEMP$$ ]; then   
echo "Does your service provider use PAP or CHAP?" > /tmp/txtTEMP$$
echo "If you're presented with a Username: or Login: and Password:" >> /tmp/txtTEMP$$
echo "prompt when you connect to your service provider, they're" >> /tmp/txtTEMP$$
echo "'probably' not using PAP or CHAP, so you can answer NONE." >> /tmp/txtTEMP$$
echo "I said 'probably', the only way to know for sure is to ask you're" >> /tmp/txtTEMP$$
echo "service provider, this could save you a lot of wasted time." >> /tmp/txtTEMP$$

dialog --backtitle "PAP or CHAP? ..." --menu "`cat /tmp/txtTEMP$$`" 16 72 4 \
PAP  "AUTHENTICATION" \
CHAP "AUTHENTICATION" \
MS-CHAP-80 "is microsoft's version of chap." \
NONE       "NO PAP, CHAP, or MS-CHAP-80." 2> /tmp/papTEMP

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit 
else
PAP="`cat /tmp/papTEMP`"
fi
fi

RAS() {
cat << EOF
If your RAS server is not the 'domain controller' and is not a 
'stand-alone' server, then it must make a query to the domain 
controller for your domain.

In other words, your account is not on the NT server you first 
connect to, so it needs to know the name of the domain you have 
your account on, so it can query that domain about you. 

If not sure chose Stand-alone, then try Queries if Stand-alone 
doesn't work.
EOF
}

if [ "$PAP" = "MS-CHAP-80" ]; then   
if [ -n "$DOMAINNAME" ]; then
echo > /tmp/txtTEMP$$
echo "You gave $DOMAINNAME for domain name, this will be the" >> /tmp/txtTEMP$$
echo "NT server you connect to when you dial: $PHONENUM" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
else
echo > /tmp/txtTEMP$$
fi
RAS >> /tmp/txtTEMP$$

dialog --title "MS-CHAP NT server, Stand-alone or ? ..." --menu "`cat /tmp/txtTEMP$$`" 22 72 2 \
MS-CHAP-SERVER-1 "Stand-alone..." \
MS-CHAP-SERVER-2 "Queries domain controller..." 2> /tmp/mschapTEMP

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit 
fi 

MSCHAP="`cat /tmp/mschapTEMP`"

if [ "$MSCHAP" = "MS-CHAP-SERVER-2" ]; then   
echo "Put the name of the domain you have your account on." > /tmp/txtTEMP0
echo "Example: fooboo" >> /tmp/txtTEMP0
echo >> /tmp/txtTEMP0

dialog --backtitle "MS-CHAP QUERY DOMAIN? ..." --inputbox "`cat /tmp/txtTEMP0`" 9 64 2> /tmp/rspTEMP0

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit 
fi 

MSDOMAIN="`cat /tmp/rspTEMP0`"

if [ ! -s /tmp/rspTEMP0 ]; then   
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
echo "No ms-chap query domain name given."
exit
fi 
fi
fi

if [ ! "$PAP" = "NONE" ] && [ ! -s /tmp/cb3TEMP$$ ]; then   
echo "Put your Login = Username in the box below." > /tmp/txtTEMP1
echo "Example: jerry" >> /tmp/txtTEMP1
echo >> /tmp/txtTEMP1

dialog --backtitle "PAP or CHAP LOGIN? ..." --inputbox "`cat /tmp/txtTEMP1`" 9 64 2> /tmp/rspTEMP1

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit 
fi

if [ ! -s /tmp/rspTEMP1 ]; then   
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
echo "No username for pap, chap, or ms-chap given."
exit
fi 
fi

if [ -s /tmp/rspTEMP1 ]; then 
AUTH1="`cat /tmp/rspTEMP1`"
echo "I have your Username: or Login: $AUTH1" > /tmp/txtTEMP2
echo "Now i need the Password for: $AUTH1" >> /tmp/txtTEMP2
echo "Example: Xpi9u87T" >> /tmp/txtTEMP2
dialog --backtitle "PAP or CHAP PASSWORD? ..." --inputbox "`cat /tmp/txtTEMP2`" 10 66 2> /tmp/rspTEMP2

AUTH2="`cat /tmp/rspTEMP2`"
END=""

elif [ ! -s /tmp/cb1TEMP$$ ] && [ "$PAP" = "NONE" ]; then  
END='""'
echo "If you reached this part of the script, it should be because you" > /tmp/txtTEMP$$
echo "skipped the PAP or CHAP? and CALLBACK? parts of this script." >> /tmp/txtTEMP$$
echo "In other words, your service provider is not using PAP, CHAP, or" >> /tmp/txtTEMP$$
echo "CALLBACK." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "Now comes the tough part. :) I need to know what your" >> /tmp/txtTEMP$$
echo "service provider prints to your screen when you dial in," >> /tmp/txtTEMP$$
echo "and what you respond with." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "Usally when you connect to your service provider you see a" >> /tmp/txtTEMP$$
echo "Username: or Login: prompt, and you respond with your name." >> /tmp/txtTEMP$$
echo "Then there's a Password: prompt and you respond with your" >> /tmp/txtTEMP$$
echo "password." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "If you're not sure if it's Login: or login:, just put ogin:" >> /tmp/txtTEMP$$
echo "you don't have to spell the whole thing out, the end part of" >> /tmp/txtTEMP$$
echo "what to wait for should be enough." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo 'If they put this for example "foobar fooboo ID:", you could just' >> /tmp/txtTEMP$$
echo 'put ID: or you could spell the whole thing out & put "" around it.' >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "What text should I wait for?" >> /tmp/txtTEMP$$
echo "ID:" >> /tmp/txtTEMP$$
echo "What text should I send?" >> /tmp/txtTEMP$$
echo "jerry" >> /tmp/txtTEMP$$
echo "What text should I wait for?" >> /tmp/txtTEMP$$
echo '"foobar fooboo ID:"' >> /tmp/txtTEMP$$
echo "What text should I send?" >> /tmp/txtTEMP$$
echo "jerry" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "Sometimes you may want to wait for nothing, but send something." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "What text should I wait for?" >> /tmp/txtTEMP$$
echo '""' >> /tmp/txtTEMP$$
echo "What text should I send?" >> /tmp/txtTEMP$$
echo "something" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo '"" = wait for nothing.' >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "If you don't want your password printed out, put \q in front of it." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "What text should I wait for?" >> /tmp/txtTEMP$$
echo "word:" >> /tmp/txtTEMP$$
echo "What text should I send?" >> /tmp/txtTEMP$$
echo "\qsecret" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "ogin: = Login:   name: = Username:   word: = Password:" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "For example..." >> /tmp/txtTEMP$$
echo "What text should I wait for?" >> /tmp/txtTEMP$$
echo "ogin:" >> /tmp/txtTEMP$$
echo "And what text should I send?" >> /tmp/txtTEMP$$
echo "jerry" >> /tmp/txtTEMP$$
echo "What text should I wait for?" >> /tmp/txtTEMP$$
echo "word:" >> /tmp/txtTEMP$$
echo "And what text should I send?" >> /tmp/txtTEMP$$
echo "secret" >> /tmp/txtTEMP$$
echo "What text should I wait for?" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "( End by pressing Enter on a empty = blank box. )" >> /tmp/txtTEMP$$

dialog --title "CHAT SCRIPT" --textbox "/tmp/txtTEMP$$" 22 72

MESSAGE=' '
YOUSAY=' '
while [ ! "$MESSAGE" = "" -a ! "$YOUSAY" = "" ]
do

echo "     End by pressing Enter on a empty = blank box." > /tmp/txtTEMP$$
echo "            What text should I wait for?" >> /tmp/txtTEMP$$
dialog --backtitle "EXPECT ..." --inputbox "`cat /tmp/txtTEMP$$`" 9 60 2> /tmp/rspTEMP$$	

MESSAGE="`cat /tmp/rspTEMP$$`"

if [ -z "$MESSAGE" ]; then
continue
fi

dialog --backtitle "SEND ..." --inputbox "And what text should I send?" 8 60 2> /tmp/rspTEMP$$

if [ $? = 1 ]; then
rm -f /tmp/*TEMP*
clear 2>/dev/null || echo
echo "PPP configuration cancelled."
exit 
fi

YOUSAY="`cat /tmp/rspTEMP$$`"

echo "$MESSAGE $YOUSAY" >> /tmp/sayTEMP1
	
if [ -z "$YOUSAY" ]; then
clear 2>/dev/null || echo
rm -f /tmp/*TEMP*
echo "PPP configuration cancelled."
echo "Nothing to send."
exit 
else	
continue
fi

done
fi

if [ ! -s /tmp/cb3TEMP$$ ]; then
if [ -s /tmp/cb1TEMP$$ ] && [ ! -s /tmp/cb3TEMP$$ ] && [ "$PAP" = "NONE" ]; then
clear 2>/dev/null || echo
rm -f /tmp/*TEMP*
echo "PPP configuration cancelled."
echo "You chose callback with PAP or CHAP, but answered NONE to PAP or CHAP."
exit 
elif [ ! -s /tmp/rspTEMP2 ] && [ -s /tmp/rspTEMP1 ]; then
clear 2>/dev/null || echo
rm -f /tmp/*TEMP*
echo "PPP configuration cancelled."
echo "No password for: $AUTH1"
exit 	
elif [ ! -s /tmp/sayTEMP1 ] && [ ! -s /tmp/rspTEMP2 ]; then
clear 2>/dev/null || echo
rm -f /tmp/*TEMP*
echo "PPP configuration cancelled."
echo "Nothing to wait for."
exit 
fi
fi

if dmesg 2>/dev/null | grep "PPP: version" >/dev/null 2>&1 ; then
MSG1=YES
fi
if [ -f /lib/modules/`uname -r 2>/dev/null`/net/ppp.o ]; then
MSG2=YES
fi

if [ ! -s /etc/host.conf ]; then
echo "order hosts,bind" > /etc/host.conf
echo "multi on" >> /etc/host.conf
fi

if [ -s /etc/resolv.conf ]; then
mv /etc/resolv.conf /etc/resolv.conf.old
fi

if [ -z $DOMAINNAME ]; then        
echo "search unknown.com" > /etc/resolv.conf
DOMAINNAME="unknown.com"
else
echo "search $DOMAINNAME" > /etc/resolv.conf
fi

if [ -z $DNSIP ]; then
echo "nameserver 207.132.116.5" >> /etc/resolv.conf
else
echo "nameserver $DNSIP" >> /etc/resolv.conf
fi

if [ ! -s /etc/hosts ]; then
echo "127.0.0.1       localhost" > /etc/hosts
echo "0.0.0.0         `hostname 2>/dev/null`.$DOMAINNAME `hostname 2>/dev/null`" >> /etc/hosts
fi

if [ -x /usr/sbin/pppd ]; then
PATH1="/usr/sbin/pppd"
elif [ -x /usr/bin/pppd ]; then
PATH1="/usr/bin/pppd"
elif [ -x /usr/local/bin/pppd ]; then
PATH1="/usr/local/bin/pppd"
elif [ -x /bin/pppd ]; then
PATH1="/bin/pppd"
elif [ -x /sbin/pppd ]; then
PATH1="/sbin/pppd"
else
PATH1="pppd"
fi

if [ "$PATH1" != "pppd" ]; then
chmod 4755 $PATH1 2>/dev/null
fi

if [ -x /usr/sbin/chat ]; then
PATH2="/usr/sbin/chat"
elif [ -x /usr/bin/chat ]; then
PATH2="/usr/bin/chat"
elif [ -x /usr/local/bin/chat ]; then
PATH2="/usr/local/bin/chat"
elif [ -x /bin/chat ]; then
PATH2="/bin/chat"
elif [ -x /sbin/chat ]; then
PATH2="/sbin/chat"
else
PATH2="chat"
fi

if [ ! -s /tmp/cb1TEMP$$ ]; then
echo "TIMEOUT 10" > /etc/ppp/pppscript
echo "ABORT ERROR" >> /etc/ppp/pppscript 
echo "ABORT BUSY" >> /etc/ppp/pppscript 
echo 'ABORT "NO CARRIER"' >> /etc/ppp/pppscript
echo 'ABORT "NO DIALTONE"' >> /etc/ppp/pppscript
echo 'REPORT "CARRIER"' >> /etc/ppp/pppscript
echo 'REPORT "CONNECT"' >> /etc/ppp/pppscript
if [ "$INIT" = "below" ]; then
echo '"" "AT\&FW1H0"' >> /etc/ppp/pppscript
echo 'OK "'$PHONENUM'"' >> /etc/ppp/pppscript
else
echo '"" '$INIT'' >> /etc/ppp/pppscript
echo '"'$PHONENUM'"' >> /etc/ppp/pppscript
fi
echo "TIMEOUT 75" >> /etc/ppp/pppscript
echo 'CONNECT '$END'' >> /etc/ppp/pppscript
chown root.root /etc/ppp/pppscript 2>/dev/null
chmod 600 /etc/ppp/pppscript 2>/dev/null
fi

if [ -s /tmp/sayTEMP1 ]; then
cat /tmp/sayTEMP1 >> /etc/ppp/pppscript
echo >> /etc/ppp/pppscript 
else
echo >> /etc/ppp/pppscript 
fi

echo "#!/bin/bash" > /usr/sbin/ppp-go

echo >> /usr/sbin/ppp-go
echo 'if [ "$1" = "-h" ]; then' >> /usr/sbin/ppp-go
echo 'echo "USAGE: ppp-go     <Connect print messages to screen.>"' >> /usr/sbin/ppp-go
echo 'echo "USAGE: ppp-go -c  <Remove contents of /var/log/pppd files.>"' >> /usr/sbin/ppp-go
echo 'echo "USAGE: ppp-go -cc <Remove contents of /var/log/messages & debug files.>"' >> /usr/sbin/ppp-go
echo 'echo "USAGE: ppp-go -d  <Put pppd in demand dialing mode.>"' >> /usr/sbin/ppp-go
echo 'echo "USAGE: ppp-go -h  <help>"' >> /usr/sbin/ppp-go
echo 'echo "USAGE: ppp-go -s Nseconds <Connect do not print messages to screen.>"' >> /usr/sbin/ppp-go
echo 'echo "USAGE: ppp-go -s 50       <Put any Number of seconds to connect.>"' >> /usr/sbin/ppp-go
echo "exit" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go

echo >> /usr/sbin/ppp-go
echo 'if [ "$1" = "-c" ]; then' >> /usr/sbin/ppp-go
echo "cat /dev/null >/var/log/pppd.chat.log >/var/log/pppd.debug.log" >> /usr/sbin/ppp-go
echo 'echo "Contents of /var/log/pppd files removed."' >> /usr/sbin/ppp-go
echo "exit" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go

echo >> /usr/sbin/ppp-go
echo 'if [ "$1" = "-cc" ]; then' >> /usr/sbin/ppp-go
echo "cat /dev/null >/var/log/messages >/var/log/debug" >> /usr/sbin/ppp-go
echo 'echo "Contents of /var/log/messages & debug files removed."' >> /usr/sbin/ppp-go
echo "exit" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go

echo >> /usr/sbin/ppp-go
echo 'if [ "$1" = "-d" ]; then' >> /usr/sbin/ppp-go
echo 'kill -9 2>/dev/null `cat /var/run/ppp*.pid 2>/dev/null`' >> /usr/sbin/ppp-go
echo "rm -f /var/spool/uucp/LCK* /var/lock/LCK* /var/run/ppp*.pid" >> /usr/sbin/ppp-go
echo ''$PATH1' file "/etc/ppp/options.demand" || exit 1' >> /usr/sbin/ppp-go
echo 'echo "Demand Dialing Started..."' >> /usr/sbin/ppp-go
echo "exit" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go

echo >> /usr/sbin/ppp-go
echo 'if [ "$1" = "" ]; then' >> /usr/sbin/ppp-go
echo 'kill -9 2>/dev/null `cat /var/run/ppp*.pid 2>/dev/null`' >> /usr/sbin/ppp-go
echo "rm -f /var/spool/uucp/LCK* /var/lock/LCK* /var/run/ppp*.pid" >> /usr/sbin/ppp-go
if [ -s /tmp/cb1TEMP$$ ]; then
echo ''$PATH1' connect "'$PATH2 -v -f /etc/ppp/callback'"' >> /usr/sbin/ppp-go 
else
echo ''$PATH1' connect "'$PATH2 -v -f /etc/ppp/pppscript'"' >> /usr/sbin/ppp-go 
fi

echo >> /usr/sbin/ppp-go
echo "if [ -f /var/log/pppd.chat.log ]; then" >> /usr/sbin/ppp-go
echo "tail -c 0 -f /var/log/pppd.chat.log &" >> /usr/sbin/ppp-go
echo "read" >> /usr/sbin/ppp-go
echo 'trap "" 9' >> /usr/sbin/ppp-go
echo "killall -9 tail 2>/dev/null" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go

echo >> /usr/sbin/ppp-go
echo "if ifconfig | grep P-t-P >/dev/null ; then" >> /usr/sbin/ppp-go
echo "echo" >> /usr/sbin/ppp-go
echo 'echo "* YES! connected... *"' >> /usr/sbin/ppp-go
echo "echo" >> /usr/sbin/ppp-go
echo "exit" >> /usr/sbin/ppp-go
echo "else" >> /usr/sbin/ppp-go
echo "echo" >> /usr/sbin/ppp-go
echo 'echo "* NO! not connected... *"' >> /usr/sbin/ppp-go
echo "echo" >> /usr/sbin/ppp-go
echo "exit" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go
echo >> /usr/sbin/ppp-go

echo 'if [ "$1" = "-s" ]; then' >> /usr/sbin/ppp-go
echo 'if [ ! "$2" = "" ]; then' >> /usr/sbin/ppp-go
echo 'kill -9 2>/dev/null `cat /var/run/ppp*.pid 2>/dev/null`' >> /usr/sbin/ppp-go
echo "rm -f /var/spool/uucp/LCK* /var/lock/LCK* /var/run/ppp*.pid" >> /usr/sbin/ppp-go
if [ -s /tmp/cb1TEMP$$ ]; then
echo ''$PATH1' connect "'$PATH2 -v -f /etc/ppp/callback'"' >> /usr/sbin/ppp-go 
else
echo ''$PATH1' connect "'$PATH2 -v -f /etc/ppp/pppscript'"' >> /usr/sbin/ppp-go 
fi
echo 'echo "Waiting "$2" seconds to connect..."' >> /usr/sbin/ppp-go
echo 'sleep "$2" || kill -9 2>/dev/null `cat /var/run/ppp*.pid 2>/dev/null`' >> /usr/sbin/ppp-go
echo "else" >> /usr/sbin/ppp-go
echo 'echo "USAGE: ppp-go -s Nseconds"' >> /usr/sbin/ppp-go
echo "exit 1" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go

echo >> /usr/sbin/ppp-go
echo 'if [ "$?" = "0" ]; then' >> /usr/sbin/ppp-go
echo "if ifconfig | grep P-t-P >/dev/null &&" >> /usr/sbin/ppp-go
echo "[ -s /etc/ppp/connect-errors ]; then" >> /usr/sbin/ppp-go
echo "echo" >> /usr/sbin/ppp-go
echo 'echo "* YES! connected... *"' >> /usr/sbin/ppp-go
echo 'if ! grep "connect-errors" /etc/ppp/connect-errors >/dev/null' >> /usr/sbin/ppp-go
echo "then" >> /usr/sbin/ppp-go
echo "tail -n 1 /etc/ppp/connect-errors" >> /usr/sbin/ppp-go
echo "echo" >> /usr/sbin/ppp-go
echo "exit" >> /usr/sbin/ppp-go
echo "else" >> /usr/sbin/ppp-go
echo "tail -n 2 /etc/ppp/connect-errors" >> /usr/sbin/ppp-go
echo "echo" >> /usr/sbin/ppp-go
echo "exit" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go

echo >> /usr/sbin/ppp-go
echo "if ifconfig | grep P-t-P >/dev/null ; then" >> /usr/sbin/ppp-go
echo "echo" >> /usr/sbin/ppp-go
echo 'echo "* YES! connected... *"' >> /usr/sbin/ppp-go
echo "echo" >> /usr/sbin/ppp-go
echo "exit" >> /usr/sbin/ppp-go
echo "else" >> /usr/sbin/ppp-go
echo "echo" >> /usr/sbin/ppp-go
echo 'echo "* NO! not connected... *"' >> /usr/sbin/ppp-go
echo "echo" >> /usr/sbin/ppp-go
echo "tail -n 4 /var/log/pppd.chat.log 2>/dev/null" >> /usr/sbin/ppp-go
echo "echo" >> /usr/sbin/ppp-go
echo "exit" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go
echo "fi" >> /usr/sbin/ppp-go

chmod 755 /usr/sbin/ppp-go 2>/dev/null 
	
if [ -s /etc/ppp/options ]; then
mv /etc/ppp/options /etc/ppp/options.old
fi
    
echo "lock" > /etc/ppp/options
echo "defaultroute" >> /etc/ppp/options
echo "noipdefault" >> /etc/ppp/options
echo "modem" >> /etc/ppp/options
echo "$DEVICE" >> /etc/ppp/options
echo "$BAUDRATE" >> /etc/ppp/options
echo "crtscts" >> /etc/ppp/options
echo "debug" >> /etc/ppp/options
echo "passive" >> /etc/ppp/options

if [ -n "$CBPN" ]; then
echo 'callback "'$CBPN'"' >> /etc/ppp/options
fi
  
if  [ "$MSCHAP" = "MS-CHAP-SERVER-2" ] && [ -s /tmp/rspTEMP2 ]; then
echo 'name "'$MSDOMAIN\\\\$AUTH1'"' >> /etc/ppp/options
elif [ -s /tmp/rspTEMP2 ]; then
echo 'name "'$AUTH1'"' >> /etc/ppp/options
fi

chown root.root /etc/ppp/options 2>/dev/null
chmod 600 /etc/ppp/options 2>/dev/null

if [ "$PAP" = "PAP" ]; then
echo "# PAP authentication file: /etc/ppp/pap-secrets" > /etc/ppp/pap-secrets
echo "# This file should have a permission of 600." >> /etc/ppp/pap-secrets
echo "# ~# chmod 600 /etc/ppp/pap-secrets" >> /etc/ppp/pap-secrets
echo "# Username      Server      Password      IP addresses" >> /etc/ppp/pap-secrets
echo '"'$AUTH1'"   *   "'$AUTH2'"' >> /etc/ppp/pap-secrets

chown root.root /etc/ppp/pap-secrets 2>/dev/null
chmod 600 /etc/ppp/pap-secrets 2>/dev/null
        
elif [ "$PAP" = "CHAP" ]; then
echo "# CHAP authentication file: /etc/ppp/chap-secrets" > /etc/ppp/chap-secrets
echo "# This file should have a permission of 600." >> /etc/ppp/chap-secrets
echo "# ~# chmod 600 /etc/ppp/chap-secrets" >> /etc/ppp/chap-secrets
echo "# Username      Server      Password      IP addresses" >> /etc/ppp/chap-secrets
echo '"'$AUTH1'"   $DOMAINNAME   "'$AUTH2'"' >> /etc/ppp/chap-secrets
echo '"'$DOMAINNAME'"   "'$AUTH1'"   "'$AUTH2'"' >> /etc/ppp/chap-secrets

chown root.root /etc/ppp/chap-secrets 2>/dev/null
chmod 600 /etc/ppp/chap-secrets 2>/dev/null

elif [ "$PAP" = "MS-CHAP-80" ] && [ "$MSCHAP" = "MS-CHAP-SERVER-2" ]; then
echo "# MS-CHAP authentication file: /etc/ppp/chap-secrets" > /etc/ppp/chap-secrets
echo "# This file should have a permission of 600." >> /etc/ppp/chap-secrets
echo "# ~# chmod 600 /etc/ppp/chap-secrets" >> /etc/ppp/chap-secrets
echo "# Username      RemoteHost      Password" >> /etc/ppp/chap-secrets
echo '"'$MSDOMAIN\\\\$AUTH1'"   "'$DOMAINNAME'"   "'$AUTH2'"' >> /etc/ppp/chap-secrets
echo '"'$DOMAINNAME'"   "'$MSDOMAIN\\\\$AUTH1'"   "'$AUTH2'"' >> /etc/ppp/chap-secrets

chown root.root /etc/ppp/chap-secrets 2>/dev/null
chmod 600 /etc/ppp/chap-secrets 2>/dev/null

elif [ "$PAP" = "MS-CHAP-80" ]; then
echo "# MS-CHAP authentication file: /etc/chap-secrets" > /etc/ppp/chap-secrets
echo "# This file should have a permission of 600." >> /etc/ppp/chap-secrets
echo "# ~# chmod 600 /etc/ppp/chap-secrets" >> /etc/ppp/chap-secrets
echo "# Username      RemoteHost      Password" >> /etc/ppp/chap-secrets
echo '"'$AUTH1'"   "'$DOMAINNAME'"   "'$AUTH2'"' >> /etc/ppp/chap-secrets
echo '"'$DOMAINNAME'"   "'$AUTH1'"   "'$AUTH2'"' >> /etc/ppp/chap-secrets

chown root.root /etc/ppp/chap-secrets 2>/dev/null
chmod 600 /etc/ppp/chap-secrets 2>/dev/null
fi

if [ ! -z $DOMAINNAME ] && [ "$PAP"  = "MS-CHAP-80" ]; then        
echo 'remotename "'$DOMAINNAME'"' >> /etc/ppp/options
fi

cp /etc/ppp/options /etc/ppp/options.demand

if [ -s /tmp/cb1TEMP$$ ]; then
echo 'connect "chat -v -f /etc/ppp/callback"' >> /etc/ppp/options.demand
else
echo 'connect "chat -v -f /etc/ppp/pppscript"' >> /etc/ppp/options.demand
fi

echo "ipcp-accept-local" >> /etc/ppp/options.demand
echo "ipcp-accept-remote" >> /etc/ppp/options.demand
if [ -z $DNSIP ]; then
echo "0.0.0.0:207.132.116.5" >> /etc/ppp/options.demand
else
echo "0.0.0.0:$DNSIP" >> /etc/ppp/options.demand
fi
echo "demand" >> /etc/ppp/options.demand

chown root.root /etc/ppp/options.demand 2>/dev/null
chmod 600 /etc/ppp/options.demand 2>/dev/null

if [ -f $HOME/.ppprc ]; then
mv $HOME/.ppprc $HOME/.ppprc.off
PPPRC="YES"
fi

demand() {
 cat << EOF
=========================================================================
PPP-2.3.0 and later has a demand dialing option, you can use it this way,
the options file for demand dialing will be /etc/ppp/options.demand.

Start ppp-go -d, pppd will just stay in the background until you try to 
connect to some site, then pppd will dial your service provider and make 
the ppp connection.

~# ppp-go -d        <-Start pppd this way for demand dialing.)
 #                  <-It should drop you back to #.)
 	      
~# ftp ftp.funet.fi               <-Pppd will start dialing.)             
 # lynx http://www.foo.com etc.   <-Pppd will start dialing etc.)
 # ppp-off -d       <-To end and restart pppd in demand dialing mode.)
 # ppp-off                        <-To end the ppp connection.)

~# ppp-go           <-Start pppd this way for no demand dialing.)

End...
=========================================================================

EOF
}

cp /tmp/txtTEMP01 /etc/ppp/pppsetup.txt

echo "=========================================================================" > /tmp/txtTEMP$$
echo "These are your PPP configuration files and instructions..." >> /tmp/txtTEMP$$
echo "=========================================================================" >> /tmp/txtTEMP$$
echo "                       ( Use these keys to scroll this page.> [Page Up]" >> /tmp/txtTEMP$$
echo "                                                            [Page Down]" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$

if [ ! -s /tmp/cb1TEMP$$ ]; then
echo "# This is your /etc/ppp/pppscript." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
cat /etc/ppp/pppscript >> /tmp/txtTEMP$$
else
echo "# This is your /etc/ppp/callback script." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
cat /etc/ppp/callback >> /tmp/txtTEMP$$
fi

echo "# This is your /etc/ppp/options file." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
cat /etc/ppp/options >> /tmp/txtTEMP$$

echo >> /tmp/txtTEMP$$
echo "# This is your /etc/ppp/options.demand dialing file." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
cat /etc/ppp/options.demand >> /tmp/txtTEMP$$

if [ ! -z $DOMAINNAME ] && [ "$PAP" = "MS-CHAP-80" ]; then        
echo >> /tmp/txtTEMP$$
echo "The remotename option is required for microsoft's chap-80," >> /tmp/txtTEMP$$
echo "it should be your service providers domain name." >> /tmp/txtTEMP$$
fi

echo >> /tmp/txtTEMP$$
echo "# This in your /etc/resolv.conf file." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
cat /etc/resolv.conf >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
if [ -z $DNSIP ]; then
echo "207.132.116.5   <-REMINDER: These numbers must be %100 correct.)" >> /tmp/txtTEMP$$
else
echo "$DNSIP   <-REMINDER: These numbers must be %100 correct.)" >> /tmp/txtTEMP$$
fi

if [ -z $DNSIP ]; then
echo >> /tmp/txtTEMP$$
echo "WARNING: You didn't give a IP address for your internet service" >> /tmp/txtTEMP$$
echo "providers nameserver, i put '207.132.116.5' but this may not work." >> /tmp/txtTEMP$$
fi

if [ "$PAP" = "CHAP" ] || [ "$PAP" = "MS-CHAP-80" ]; then
echo >> /tmp/txtTEMP$$
echo "# This is your /etc/ppp/chap-secrets file." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
cat /etc/ppp/chap-secrets >> /tmp/txtTEMP$$
fi

if [ "$DOMAINNAME" = "unknown.com" ] && [ "$PAP" = "MS-CHAP-80" ]; then
echo >> /tmp/txtTEMP$$
echo "You didn't give a DOMAIN NAME, that's why i put unknown.com." >> /tmp/txtTEMP$$
echo "You should change that to your service providers domain name." >> /tmp/txtTEMP$$
fi

if [ "$PAP" = "PAP" ]; then
echo >> /tmp/txtTEMP$$
echo "# This is your /etc/ppp/pap-secrets file." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
cat /etc/ppp/pap-secrets >> /tmp/txtTEMP$$
fi

if [ "$PATH1" = "pppd" ]; then
echo >> /tmp/txtTEMP$$
echo "ATENTION: I couldn't find <pppd> on your system." >> /tmp/txtTEMP$$
fi

if [ "$PATH2" = "chat" ]; then
echo >> /tmp/txtTEMP$$
echo "ATENTION: I couldn't find <chat> on your system." >> /tmp/txtTEMP$$
fi

if [ ! "$MSG1" = "YES" ] && [ ! "$MSG2" = "YES" ]; then
echo >> /tmp/txtTEMP$$
echo "ATENTION: I couldn't find 'PPP' in the kernel or as a module." >> /tmp/txtTEMP$$
echo "You'll need 'PPP' in the kernel or as a module to make a PPP connection." >> /tmp/txtTEMP$$
fi

if [ "$PPPRC" = "YES" ]; then
echo >> /tmp/txtTEMP$$
echo "ATENTION: I found a $HOME/.ppprc file and moved it to" >> /tmp/txtTEMP$$
echo ".ppprc.off, it might interfere with the PPP connection." >> /tmp/txtTEMP$$
fi

echo >> /tmp/txtTEMP$$
echo "Does everything look correct? if not, run 'pppsetup' again..." >> /tmp/txtTEMP$$

echo >> /tmp/txtTEMP$$
echo "=========================================================================" >> /tmp/txtTEMP$$
echo "To connect to your service provider." >> /tmp/txtTEMP$$
echo "=========================================================================" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "~# ppp-go" >> /tmp/txtTEMP$$
 
echo >> /tmp/txtTEMP$$
echo "registered device ppp0" >> /tmp/txtTEMP$$

echo >> /tmp/txtTEMP$$
echo "You'll hear and see the modem dialing, then once connected," >> /tmp/txtTEMP$$
echo "logging you in Login: Password: etc." >> /tmp/txtTEMP$$

echo >> /tmp/txtTEMP$$
echo "You won't see a Login: or Password:, if they're using pap or chap." >> /tmp/txtTEMP$$

echo >> /tmp/txtTEMP$$
echo "`hostname 2>/dev/null` pppd[562]: Serial connection established." >> /tmp/txtTEMP$$    
echo "`hostname 2>/dev/null` pppd[562]: Using interface ppp0" >> /tmp/txtTEMP$$              
echo "`hostname 2>/dev/null` pppd[562]: Connect: ppp0 <--> /dev/modem" >> /tmp/txtTEMP$$     
echo "`hostname 2>/dev/null` pppd[562]: local IP address 215.87.78.18" >> /tmp/txtTEMP$$      
echo "`hostname 2>/dev/null` pppd[562]: remote IP address 205.94.97.35" >> /tmp/txtTEMP$$     

echo >> /tmp/txtTEMP$$
echo "When you see a local & remote IP address like above," >> /tmp/txtTEMP$$
echo "you can press [Enter]." >> /tmp/txtTEMP$$

echo >> /tmp/txtTEMP$$
echo "`hostname 2>/dev/null` ~# ping 205.94.97.35   <-Press [Ctrl] C to stop.)" >> /tmp/txtTEMP$$
echo "`hostname 2>/dev/null`  # lynx ftp etc." >> /tmp/txtTEMP$$
echo "`hostname 2>/dev/null`  # fwhois $DOMAINNAME" >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "If you have the X window system, you could connect in a Xterm." >> /tmp/txtTEMP$$
echo "`hostname 2>/dev/null`  # startx" >> /tmp/txtTEMP$$
echo "`hostname 2>/dev/null`  # ppp-go" >> /tmp/txtTEMP$$
echo "`hostname 2>/dev/null`  # netscape mosaic etc." >> /tmp/txtTEMP$$

echo >> /tmp/txtTEMP$$
echo "You don't have a successful PPP connection until you" >> /tmp/txtTEMP$$ 
echo "receive a local & remote IP address like above." >> /tmp/txtTEMP$$
 
echo >> /tmp/txtTEMP$$
echo "If you don't connect for whatever reason e.g. Failed No" >> /tmp/txtTEMP$$ 
echo "Dialtone, Busy, No Carrier, Whatever, Exit, just press" >> /tmp/txtTEMP$$ 
echo "[Enter] at that point and try again." >> /tmp/txtTEMP$$
echo "~# ppp-go" >> /tmp/txtTEMP$$

echo >> /tmp/txtTEMP$$
echo "Don't press [Enter] if you're connecting and there's" >> /tmp/txtTEMP$$
echo "no problem, if there's no problem only press [Enter]" >> /tmp/txtTEMP$$ 
echo "when you get that local & remote IP address." >> /tmp/txtTEMP$$

echo >> /tmp/txtTEMP$$
echo "If you don't want to see any output to your terminal, you" >> /tmp/txtTEMP$$
echo "can start ppp-go -s followed by any number of seconds." >> /tmp/txtTEMP$$ 
echo "~# ppp-go -s 50   <-No output to terminal, exit in 50 seconds etc.)" >> /tmp/txtTEMP$$
echo "~# ppp-go -h      <-For help.)" >> /tmp/txtTEMP$$

echo >> /tmp/txtTEMP$$
echo "~# ppp-off   <-To end the ppp connection.)" >> /tmp/txtTEMP$$

echo >> /tmp/txtTEMP$$
echo "=========================================================================" >> /tmp/txtTEMP$$
echo "#### A copy of this text can be found in.> /etc/ppp/pppsetup.txt ####" >> /tmp/txtTEMP$$
echo "=========================================================================" >> /tmp/txtTEMP$$

echo >> /tmp/txtTEMP$$
echo "Done... You can exit now..." >> /tmp/txtTEMP$$
echo >> /tmp/txtTEMP$$
echo "End..." >> /tmp/txtTEMP$$
echo "=========================================================================" >> /tmp/txtTEMP$$

dialog --title "DONE" --clear --textbox "/tmp/txtTEMP$$" 22 78	
	  	  
clear 2>/dev/null || echo

cat /tmp/txtTEMP$$ >> /etc/ppp/pppsetup.txt

if [ ! -s /etc/syslog.conf ]; then
echo "# Log output from pppd & chat to these files." > /etc/syslog.conf
echo >> /etc/syslog.conf
echo "daemon,local2.info		/var/log/pppd.chat.log" >> /etc/syslog.conf
echo "daemon,local2.debug		/var/log/pppd.debug.log" >> /etc/syslog.conf

echo >> /etc/ppp/pppsetup.txt
demand >> /etc/ppp/pppsetup.txt
rm -f /tmp/*TEMP* 2>/dev/null

killall -9 syslogd 2>/dev/null 
syslogd & 2>/dev/null 
exit 

elif ! cat /etc/syslog.conf | grep pppd.chat.log >/dev/null ; then
echo >> /etc/syslog.conf
echo "# Log output from pppd & chat to these files." >> /etc/syslog.conf
echo >> /etc/syslog.conf
echo "daemon,local2.info		/var/log/pppd.chat.log" >> /etc/syslog.conf
echo "daemon,local2.debug		/var/log/pppd.debug.log" >> /etc/syslog.conf


echo >> /etc/ppp/pppsetup.txt
demand >> /etc/ppp/pppsetup.txt
rm -f /tmp/*TEMP* 2>/dev/null 

killall -9 syslogd 2>/dev/null 
syslogd & 2>/dev/null
exit 

else
echo >> /etc/ppp/pppsetup.txt
demand >> /etc/ppp/pppsetup.txt
rm -f /tmp/*TEMP* 2>/dev/null
exit 
fi

