home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / sbin / pppoeconf < prev    next >
Encoding:
Text File  |  2006-07-12  |  16.1 KB  |  453 lines

  1. #!/bin/sh
  2. # (c) Eduard Bloch <blade@debian.org>
  3. # LICENSE: GPL
  4. # Purpose: initial PPPoE configuration on Debian
  5. # Depends: bash, pppd, pppoe, whiptail, my usepeerdns script
  6.  
  7. export TEXTDOMAINDIR="/usr/share/locale"
  8. export TEXTDOMAIN=pppoeconf
  9. export OPTSFILE="/etc/ppp/peers/dsl-provider"
  10. export INTFILE="/etc/network/interfaces"
  11.  
  12. # IMPORTANT: Do not use gdialog unless it has been fixed!
  13. DIALOG=whiptail
  14.  
  15. # Set up (X)dialog - added by Fabian Franz <knx-ppp@fabian-franz.de>
  16. XDIALOG_HIGH_DIALOG_COMPAT=1
  17. export XDIALOG_HIGH_DIALOG_COMPAT
  18. if [ -n "$DISPLAY" ] ; then
  19.     if [ -x /usr/bin/Xdialog ] ; then
  20.         DIALOG="Xdialog"
  21.         X11="-X"
  22.     elif [ -x /usr/bin/zenity ] ; then
  23.         DIALOG="zenity"
  24.         X11="-X"
  25.     fi
  26. fi
  27.  
  28. # SUID wrapper for KNOPPIX added by Klaus Knopper <knoppix@knopper.net>
  29. # mod. by EB
  30. PATH="/bin:/sbin:/usr/bin:/usr/sbin"
  31. export PATH
  32.  
  33. . /usr/bin/gettext.sh
  34.  
  35. # for non-root, try to reexec with sudo, warn otherwise
  36. if [ "`id -u`" != "0" ]; then
  37.    # sudo only 
  38.   if which sudo >/dev/null && ( sudo -l -S </dev/null >/dev/null 2>&1 ) ; then
  39.     exec sudo "$0" "$@"  || exit 1
  40.   elif which su-to-root >/dev/null; then
  41.     exec su-to-root $X11 -c "$0" "$@"  || exit 1
  42.   else
  43.     gettext "Please become root before running pppoeconf!"
  44.     echo
  45.     gettext "Press return to continue..."
  46.     echo
  47.     read
  48.     exit 1
  49.   fi
  50. fi
  51.  
  52. # EOF SUID wrapper
  53.  
  54. modprobe -q pppoe
  55. # recent ppp packages have a PPPoE discovery helper program
  56. if test -x /usr/sbin/pppoe-discovery && test -e /proc/net/pppoe ; then
  57.   kernel_pppoe=1
  58.   DISCOVERY_PROGRAM=pppoe-discovery
  59. else
  60.   DISCOVERY_PROGRAM=pppoe
  61. fi
  62. export DISCOVERY_PROGRAM
  63.  
  64. # create a default peers file if there is none
  65. if ! test -r $OPTSFILE ; then
  66.    fresh_optsfile=1
  67.    cat <<EOM > $OPTSFILE
  68. # Minimalistic default options file for DSL/PPPoE connections
  69.  
  70. noipdefault
  71. defaultroute
  72. replacedefaultroute
  73. hide-password
  74. #lcp-echo-interval 30
  75. #lcp-echo-failure 4
  76. noauth
  77. persist
  78. #mtu 1492
  79. usepeerdns
  80. EOM
  81. fi
  82. chmod 0640 $OPTSFILE
  83. chown root:dip $OPTSFILE
  84.  
  85. if ! grep -q "dsl-provider" $INTFILE ; then
  86.    printf '\niface dsl-provider inet ppp\nprovider dsl-provider\n' >> $INTFILE
  87. fi
  88.  
  89. # old crap, unreliable, does not work after reboot
  90. # if ! grep -q "line maintained by pppoeconf" $INTFILE ; then
  91. #    sed -i -e 's,provider dsl-provider$,     provider dsl-provider\n# please do not modify the following line\n     pre-up /sbin/ifconfig eth0 up # line maintained by pppoeconf\n,' $INTFILE
  92. # fi
  93.    
  94. umask 177
  95. # make a secure directory
  96. TMP="`mktemp -d -p /etc/ppp`"
  97. export TMP
  98. sectempfile="`mktemp -p $TMP`"
  99. export sectempfile
  100. trap "rm -rf '$TMP'" 0 HUP INT TRAP TERM
  101.  
  102. gettext '
  103. Most providers send the needed login information per mail. Some providers describe it in odd ways, assuming the user to input the data in their "user-friendly" setup programs. But in fact, these applications generate usuall PPP user names and passwords from the entered data. You can find the real names too and input the correct data in the dialog box.
  104.  
  105. For example, this are methods used some german providers:
  106.  
  107. Sample username (alias "login" or "login name"): 11111111111
  108.  
  109. T-Online T-DSL:
  110.   additional data:
  111.     sample T-Onlinenummer: 222222222222
  112.     sample Mitbenutzer: 0001
  113.  
  114.   complete username: 111111111111222222222222#0001@t-online.de
  115.  
  116. Telekom Business Online (DSL):
  117.  
  118.   complete username: t-online-com/111111111111@t-online-com.de
  119.  
  120. 1und1 uses another scheme (using above example):
  121.  
  122.   complete username: 1und1/11111111111
  123.  
  124. Cyberfun:
  125.  
  126.   complete username: sdt/11111111111
  127.  
  128. Komtel:
  129.   additional data:
  130.     downstream speed class: 768
  131.  
  132.   complete username: 11111111111@FoniNet-768
  133.  
  134. Net Cologne:
  135.  
  136.   complete username: 11111111111@netcologne.de
  137.  
  138. Q-DSL:
  139.  
  140.   complete username: 11111111111@q-dsl.de
  141.  
  142. Versatel:
  143.  
  144.   complete username: 11111111111@VersaNet-1024k
  145.  
  146. Webnetix:
  147.  
  148.   complete username: sdt/11111111111
  149. ' > $TMP/namehelp.txt
  150.  
  151. if test "$*" ; then 
  152.    list="$*"
  153.    force_manual=1
  154. else
  155.    list=$( LANG=C /sbin/ifconfig -a | grep "Ethernet" | grep -v irlan | cut -f1 -d" " )
  156. fi
  157.  
  158. if test "$list" ; then
  159.    test "$DIALOG" = "whiptail" && escmsg=$(gettext 'Or press ESC to abort here.')
  160.   number=`echo $list | wc -w| tr -d " "`
  161.   text=$(eval_ngettext \
  162.   'I found $number ethernet device:
  163. $list
  164.  
  165. Are all your ethernet interfaces listed above?
  166. (If No, modconf will be started so you can load the card drivers manually).
  167.  
  168. $escmsg' \
  169.   'I found $number ethernet devices:
  170. $list
  171.  
  172. Are all your ethernet interfaces listed above?
  173. (If No, modconf will be started so you can load the card drivers manually).
  174.  
  175. $escmsg' \
  176.   "$number" )
  177.   title=$(gettext 'ALL DEVICES FOUND?')
  178.   $DIALOG --title "$title" --clear --yesno "$text" 15 60
  179.   case $? in
  180.     1)
  181.     # configure and restart
  182.       modconf
  183.       $0
  184.       exit $?
  185.       ;;
  186.     255)
  187.       rm -rf "$TMP"
  188.       exit 1
  189.       ;;
  190.    esac
  191.    # now, execute an AC lookup on each interface
  192.    for mmm in '' ' -U ' ; do
  193.       for iface in $list; do
  194.          # use the first candidate only, this is done anyways, below
  195.          if test -z "`grep -l AC $TMP/*.pppoe 2>/dev/null| cut -f1 -d"." | head -n1`" ; then
  196.             title=$(gettext 'SCANNING DEVICE')
  197.             text=$(eval_gettext 'Looking for PPPoE Access Concentrator on $iface...')
  198.             if test -n "$mmm" ; then
  199.                mmode=$(gettext '(multi-modem mode)')
  200.             fi
  201.  
  202.             touch $TMP/pppoe.scan
  203.             ifconfig $iface up
  204.             ($DISCOVERY_PROGRAM $mmm -A -I $iface > $TMP/$iface.pppoe ; rm $TMP/pppoe.scan) &
  205.  
  206.             ( time=0 ; while test -f $TMP/pppoe.scan ; do time=`expr $time + 6`; echo $time; sleep 1; done ) | $DIALOG --title "$title" --gauge "$text $mmode" 10 60 0
  207.  
  208. true
  209.          fi
  210.       done
  211.    done
  212.    cd "$TMP"
  213.    if test "$force_manual" ; then
  214.       iface=$1
  215.    else
  216.       iface=`grep -l AC *.pppoe| cut -f1 -d"." | head -n1`
  217.    fi
  218.    ifacenocomma=$(echo $iface | sed -e 's/,/\\,/g')
  219.  
  220.    if test -z "$iface" ; then
  221.       title=$(gettext 'NOT CONNECTED')
  222.       text=$(eval_ngettext \
  223.       'Sorry, I scanned $number interface, but the Access Concentrator of your provider did not respond. Please check your network and modem cables. Another reason for the scan failure may also be another running pppoe process which controls the modem.' \
  224.       'Sorry, I scanned $number interfaces, but the Access Concentrator of your provider did not respond. Please check your network and modem cables. Another reason for the scan failure may also be another running pppoe process which controls the modem.' \
  225.       $number)
  226.  
  227.       $DIALOG --title "$title" --clear --msgbox "$text" 15 60
  228.       rm -rf "$TMP"
  229.       exit 1;
  230.    fi
  231. #   title=$(gettext 'DSL CONNECTION FOUND')
  232. #   text=$(eval_gettext 'I found an Access Concentrator on $iface. Should I setup PPPOE for this connection?')
  233. #   $DIALOG --title "$title" --clear --yesno "$text" 15 60
  234. #  # STATUS: interface is $iface, we can continue
  235.   
  236.   if ! test "$fresh_optsfile" ; then 
  237.      title=$(gettext 'OKAY TO MODIFY')
  238.      text=$(eval_gettext 'If you continue with this program, the configuration file $OPTSFILE will be modified. Please make sure that you have a backup copy before saying Yes.
  239.  
  240. Continue with configuration?')
  241.      $DIALOG --title "$title" --clear --yesno "$text" 22 70
  242.      if test "$?" != "0" ; then
  243.         rm -rf "$TMP"
  244.         exit 0
  245.      fi
  246.   fi
  247.  
  248.   if ! grep -q "^[[:space:]]*auto[[:space:]][^#]*$iface" $INTFILE ; then
  249.       echo >> $INTFILE
  250.       echo "auto $iface" >> $INTFILE
  251.   fi
  252.  
  253.   if ! grep -q "^[[:space:]]*iface[[:space:]]\+$iface" $INTFILE ; then
  254.       echo >> $INTFILE
  255.       echo "iface $iface inet manual" >> $INTFILE
  256.   fi
  257.  
  258. #   if test "$?" = "0"; then
  259.       if [ "$kernel_pppoe" ]; then
  260.          # interface activation code - this sucks here, pppd plugin should do it as needed
  261.          # FIXME: Make sure that it gets added to correct iface stanza! (Because it's not always added above)
  262.          PATTERN_PREUP_IFACE="pre-up /sbin/ifconfig[[:space:]]\+[^[:space:]]\+[[:space:]]\+up.#.line.maintained.by.pppoeconf"
  263.          REPLACE_PREUP_IFACE="pre-up /sbin/ifconfig $ifacenocomma up # line maintained by pppoeconf"
  264.          if grep -q "$PATTERN_PREUP_IFACE" $INTFILE; then 
  265.              sed -i -e "s,$PATTERN_PREUP_IFACE,$REPLACE_PREUP_IFACE," $INTFILE
  266.          else
  267.              echo >> $INTFILE
  268.              echo "    $REPLACE_PREUP_IFACE" >> $INTFILE
  269.          fi
  270.  
  271.          # change peers config file, sanity check first
  272. #       grep -q "^plugin.*rp-pppoe.so" $OPTSFILE || echo "plugin rp-pppoe.so $iface" >> $OPTSFILE
  273.        if [ "${iface##eth*}" = "" ]; then
  274.            # Name is eth*
  275.            grep -q "^plugin.*rp-pppoe.so" $OPTSFILE || echo "plugin rp-pppoe.so $iface" >> $OPTSFILE
  276.        else
  277.            grep -q "^plugin.*rp-pppoe.so" $OPTSFILE || echo "plugin rp-pppoe.so" >> $OPTSFILE
  278.            grep -q "^nic-$iface" $OPTSFILE || echo "nic-$iface" >> $OPTSFILE
  279.        fi
  280.  
  281.        # disable the pppoe tunnel command
  282.        if grep -q '^pty' $OPTSFILE ; then
  283.           sed -i -e 's/^pty/#pty/' $OPTSFILE
  284.        fi
  285.  
  286.        # set the interface
  287.        sed -i -e "s,^plugin.\+rp-pppoe.so[[:space:]]\+[^[:space:]]*,plugin rp-pppoe.so $ifacenocomma," $OPTSFILE
  288.        sed -i -e "s,^nic-[[:alnum:]]*,nic-$ifacenocomma," $OPTSFILE
  289.     else
  290.        # sanity check first, fix the config file
  291.  
  292.        # install the default line
  293.        grep -q '^.*pty.*pppoe.*-I' $OPTSFILE || echo 'pty "pppoe -I eth0 -T 80"' >> $OPTSFILE
  294.        # install alternative lines
  295.        grep -q '^.*pty.*pppoe.*-m.*1452' $OPTSFILE || echo '#pty "pppoe -I eth0 -T 80 -m 1452"' >> $OPTSFILE
  296.        grep -q '^.*pty.*pppoe.*-m.*1412' $OPTSFILE || echo '#pty "pppoe -I eth0 -T 80 -m 1412"' >> $OPTSFILE
  297.        # at least one must work
  298.        grep -q '^pty' $OPTSFILE || echo 'pty "pppoe -I eth0 -T 80"' >> $OPTSFILE
  299.  
  300.        # set the interface
  301.        sed -i -e "s,-I[[:space:]]*[[:alnum:]]*,-I $ifacenocomma," $OPTSFILE
  302.     fi
  303.     # fix final newline
  304.     test -e /etc/ppp/pap-secrets && ( [ $(tail -1 /etc/ppp/pap-secrets | wc -l) -eq 0 ] || echo >> /etc/ppp/pap-secrets )
  305.     test -e /etc/ppp/chap-secrets && ( [ $(tail -1 /etc/ppp/chap-secrets | wc -l) -eq 0 ] || echo >> /etc/ppp/chap-secrets )
  306. #  else
  307. #    rm -rf "$TMP"
  308. #    exit 1
  309. #  fi
  310.  
  311.   # ask about sane options
  312.   #$DIALOG --title $"POPULAR OPTIONS" --clear --yesno $"Most people using popular dialup providers prefer the options 'noauth' and 'defaultroute' in their configuration and remove the 'nodetach' option. Further, for busy providers the lcp-echo-interval could be increased. Should I check your configuration file and change these settings where neccessary?" 22 70
  313.   title=$(gettext 'POPULAR OPTIONS')
  314.   text=$(gettext "Most people using popular dialup providers prefer the options 'noauth' and 'defaultroute' in their configuration and remove the 'nodetach' option. Should I check your configuration file and change these settings where neccessary?")
  315.   $DIALOG --title "$title" --clear --yesno "$text" 22 70
  316.   if test "$?" = "0" ; then
  317.     grep -q '^noauth' $OPTSFILE || echo 'noauth' >> $OPTSFILE
  318.     grep -q '^defaultroute' $OPTSFILE  || echo 'defaultroute' >> $OPTSFILE
  319.     sed -i -e "/^nodetach.*/d" $OPTSFILE
  320. #    sed -i -e "s/^lcp-echo-interval 20$/lcp-echo-interval 60/" $OPTSFILE
  321.   fi
  322.   
  323.   user=`grep ^user $OPTSFILE|cut -f2 -d" " | tr -d '"'`
  324.   test -z "$user" && user="username"
  325.   while test "$goahead" != "yes" ; do
  326.     title=$(gettext 'ENTER USERNAME')
  327.     text=$(gettext 'Please enter the username which you usually need for the PPP login to your provider in the input box below. If you wish to see the help screen, delete the username and press OK.')
  328.     $DIALOG --nocancel --title "$title" --clear --inputbox "$text" 15 60 $user 2> "$sectempfile"
  329.     user=`cat "$sectempfile"`
  330.     case $? in
  331.     0)
  332.     if test -z "$user" ; then
  333.       $DIALOG --scrolltext --textbox "$TMP/namehelp.txt" 17 75
  334.     else
  335.       sed -i -e '/^user .*/d' $OPTSFILE
  336.       echo  "user \"$user\"" >> $OPTSFILE
  337.       goahead="yes"
  338.       export goahead
  339.     fi
  340.       ;;
  341.     *)
  342.       exit 1
  343.       rm -rf "$TMP"
  344.       ;;
  345.     esac
  346.   done
  347.  
  348.   title=$(gettext 'ENTER PASSWORD')
  349.   text=$(gettext 'Please enter the password which you usually need for the PPP login to your provider in the input box below.
  350.  
  351. NOTE: you can see the password in plain text while typing.')
  352.   $DIALOG --nocancel --title "$title" --clear --inputbox "$text" 15 60 2> "$sectempfile"
  353.   pass=`cat "$sectempfile"`
  354.   usernoslash=$(echo $user | sed -e 's,/,\\/,')
  355.   case $? in
  356.   0)
  357.     sed -i -e "/^\"*$usernoslash\"* .*/ d" /etc/ppp/pap-secrets
  358.     echo "\"$user\" * \"$pass\"" >> /etc/ppp/pap-secrets
  359.     sed -i -e "/^\"*$usernoslash\"* .*/ d" /etc/ppp/chap-secrets
  360.     echo "\"$user\" * \"$pass\"" >> /etc/ppp/chap-secrets
  361.     ;;
  362.   *)
  363.     rm -rf "$TMP"
  364.     exit 1
  365.     ;;
  366.   esac
  367.  
  368.   # ask about DNS
  369.   title=$(gettext 'USE PEER DNS')
  370.   text=$(gettext 'You need at least one DNS IP address to resolve the normal host names. Normally your provider sends you addresses of useable servers when the connection is established. Would you like to add these addresses automatically to the list of nameservers in your local /etc/resolv.conf file? (recommended)')
  371.   $DIALOG --title "$title" --clear --yesno "$text" 15 60
  372.   case $? in
  373.      0)
  374.      grep -q "^usepeerdns" $OPTSFILE || echo "usepeerdns" >> $OPTSFILE
  375.      ;;
  376.   esac
  377.   
  378.   # ask about MSS limitation
  379.   title=$(gettext 'LIMITED MSS PROBLEM')
  380.   text=$(gettext "Many providers have routers that do not support TCP packets with a MSS higher than 1460. Usually, outgoing packets have this MSS when they go through one real Ethernet link with the default MTU size (1500). Unfortunately, if you are forwarding packets from other hosts (i.e. doing masquerading) the MSS may be increased depending on the packet size and the route to the client hosts, so your client machines won't be able to connect to some sites. There is a solution: the maximum MSS can be limited by pppoe. You can find more details about this issue in the pppoe documentation.
  381.  
  382. Should pppoe clamp MSS at 1452 bytes?
  383.  
  384. If unsure, say yes.
  385.  
  386. (If you still get problems described above, try setting to 1412 in the dsl-provider file.)")
  387.   $DIALOG --title "$title" --clear --yesno "$text" 22 70
  388.   case $? in
  389.      0)
  390.      if [ "$kernel_pppoe" ]; then
  391.         printf '#!/bin/sh\n# Enable MSS clamping (autogenerated by pppoeconf)\n\niptables -o "$PPP_IFACE" --insert FORWARD 1 -p tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1400:1536 -j TCPMSS --clamp-mss-to-pmtu\n' > /etc/ppp/ip-up.d/0clampmss
  392.         printf '#!/bin/sh\n# Disable MSS clamping (autogenerated by pppoeconf)\n\niptables -L -n -v --line-numbers | grep "TCPMSS.*$PPP_IFACE.*clamp" | cut -f1 -d " " | xargs -n1 -r iptables -D FORWARD\n' > /etc/ppp/ip-down.d/0clampmss
  393.         chmod 755 /etc/ppp/ip-up.d/0clampmss /etc/ppp/ip-down.d/0clampmss
  394.      else
  395.         # disable the old line
  396.         sed -i -e 's/^pty/#&/' $OPTSFILE
  397.         # enable the one with our mss size
  398.         sed -i -e 's/^#\(pty.*-m 1452.*\)/\1/' $OPTSFILE
  399.         #rm -f "$sectempfile"
  400.      fi
  401.      ;;
  402.   esac
  403.  
  404.   if test -z "`mount | grep KNOPPIX`" ; then
  405.      title=$(gettext 'DONE')
  406.      text=$(gettext 'Your PPPD is configured now. Would you like to start the connection at boot time?')
  407.      $DIALOG --title "$title" --clear --yesno "$text" 15 60
  408.      if test "$?" = "0"; then
  409.         grep -q "^auto.*dsl-provider" $INTFILE || sed -i -e 's/^iface.*dsl-provider/auto dsl-provider\n&/' $INTFILE
  410.      else
  411.         sed -i -e '/^auto.*dsl-provider/d' $INTFILE
  412.      fi
  413.   fi
  414.  
  415.   cd /
  416.   
  417.   # end of story
  418.   rm -rf "$TMP"
  419.   
  420.   title=$(gettext 'ESTABLISH A CONNECTION')
  421.   text=$(gettext 'Now, you can make a DSL connection with "pon dsl-provider" and terminate it with "poff". Would you like to start the connection now?')
  422.   $DIALOG --title "$title" --clear --yesno "$text" 15 60
  423.   case $? in
  424.   0)
  425.     cd /
  426.     pon dsl-provider
  427.     title=$(gettext 'CONNECTION INITIATED')
  428.     text=$(gettext 'The DSL connection has been triggered. You can use the "plog" command to see the status or "ifconfig ppp0" for general interface info.')
  429.     $DIALOG --title "$title" --clear --msgbox "$text" 10 60
  430.     ;;
  431.   *)
  432.     exit 0
  433.     ;;
  434.   esac
  435.  
  436. else
  437.   title=$(gettext 'NO INTERFACE FOUND')
  438.   text=$(gettext 'Sorry, no working ethernet card could be found. If you do have an interface card which was not autodetected so far, you probably wish to load the driver manually using the modconf utility. Run modconf now?')
  439.   $DIALOG --title "$title" --clear --yesno "$text" 20 70
  440.   case $? in
  441.   0)
  442.     rm -rf "$TMP"
  443.     modconf
  444.     exec $0
  445.     exit $?
  446.     ;;
  447.   *)
  448.     rm -rf "$TMP"
  449.     exit 1
  450.     ;;
  451.   esac
  452. fi
  453.