developer | 056f6de | 2023-01-18 16:10:07 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | source /etc/utopia/service.d/service_wan/ppp_helpers.sh |
| 3 | |
| 4 | PPP_CONFIG_FILE=/etc/ppp/pppoe.conf |
| 5 | |
| 6 | init_pppoe (){ |
| 7 | prepare_pppd_ip_pre_up_script |
| 8 | prepare_pppd_ip_up_script |
| 9 | prepare_pppd_ipv6_up_script |
| 10 | prepare_pppd_ip_down_script |
| 11 | prepare_pppd_ipv6_down_script |
| 12 | prepare_pppd_options |
| 13 | prepare_pppd_secrets |
| 14 | echo -n > $PPP_CONFIG_FILE |
| 15 | |
| 16 | PHY_NAME=`syscfg get wan_physical_ifname` |
| 17 | echo "ETH='${PHY_NAME}'" >> $PPP_CONFIG_FILE |
| 18 | CLIENT=`syscfg get wan_proto_username` |
| 19 | IPV6CP=`syscfg get IPV6CPEn` |
| 20 | IPCP=`syscfg get IPCPEn` |
| 21 | PPP_IDLE_TIME=`syscfg get ppp_idle_time` |
| 22 | MAXMRUSIZE=`syscfg get MaxMRUSize` |
| 23 | DEFLCPINTERVAL=`syscfg get lcp_interval` |
| 24 | echo "MRU=$MAXMRUSIZE" >> $PPP_CONFIG_FILE |
| 25 | echo "USER=$CLIENT" >>$PPP_CONFIG_FILE |
| 26 | echo "IFNAME='ppp0'" >>$PPP_CONFIG_FILE |
| 27 | echo "DEMAND=no" >> $PPP_CONFIG_FILE |
| 28 | echo "DNSTYPE=SERVER" >> $PPP_CONFIG_FILE |
| 29 | echo "PEERDNS=yes" >> $PPP_CONFIG_FILE |
| 30 | echo "DNS1=" >> $PPP_CONFIG_FILE |
| 31 | echo "DNS2=" >> $PPP_CONFIG_FILE |
| 32 | echo "DEFAULTROUTE=yes" >> $PPP_CONFIG_FILE |
| 33 | echo "CONNECT_TIMEOUT=0" >> $PPP_CONFIG_FILE |
| 34 | echo "CONNECT_POLL=2" >> $PPP_CONFIG_FILE |
| 35 | CONCENTRATOR=`syscfg get wan_proto_acname` |
| 36 | echo "ACNAME=$CONCENTRATOR" >> $PPP_CONFIG_FILE |
| 37 | SERVICE=`syscfg get wan_proto_servicename` |
| 38 | echo "SERVICENAME=$SERVICE" >> $PPP_CONFIG_FILE |
| 39 | echo 'PING="."' >> $PPP_CONFIG_FILE |
| 40 | echo "CF_BASE=`basename $CONFIG`" >> $PPP_CONFIG_FILE |
| 41 | echo 'PIDFILE="/var/run/$CF_BASE-pppoe.pid"' >> $PPP_CONFIG_FILE |
| 42 | echo "SYNCHRONOUS=no" >> $PPP_CONFIG_FILE |
| 43 | echo "CLAMPMSS=1412" >> $PPP_CONFIG_FILE |
| 44 | echo "LCP_INTERVAL=$DEFLCPINTERVAL" >> $PPP_CONFIG_FILE |
| 45 | echo "LCP_FAILURE=3" >> $PPP_CONFIG_FILE |
| 46 | echo "PPPOE_TIMEOUT=80" >> $PPP_CONFIG_FILE |
| 47 | echo "FIREWALL=NONE" >> $PPP_CONFIG_FILE |
| 48 | echo 'LINUX_PLUGIN="/usr/lib/pppd/2.4.8/rp-pppoe.so"' >> $PPP_CONFIG_FILE |
| 49 | echo 'PPPOE_EXTRA=""' >> $PPP_CONFIG_FILE |
| 50 | echo 'PPPD_EXTRA=""' >> $PPP_CONFIG_FILE |
| 51 | } |
| 52 | |
| 53 | if [ "$1" == "start" ]; then |
| 54 | if [ -n "$2" ]; then |
| 55 | echo "wan_proto_username" |
| 56 | syscfg set wan_proto_username $2 |
| 57 | fi |
| 58 | if [ -n "$3" ]; then |
| 59 | echo "wan_proto_username" |
| 60 | syscfg set wan_proto_password $3 |
| 61 | fi |
| 62 | pppoe-stop |
| 63 | sleep 2 |
| 64 | init_pppoe |
| 65 | pppoe-start |
| 66 | iptables -t nat -D POSTROUTING -o ppp+ -j MASQUERADE |
| 67 | iptables -t nat -I POSTROUTING -o ppp+ -j MASQUERADE |
| 68 | elif [ "$1" == "stop" ]; then |
| 69 | pppoe-stop |
| 70 | iptables -t nat -D POSTROUTING -o ppp+ -j MASQUERADE |
| 71 | else |
| 72 | echo "Useage: $0 <start/stop> <user> <password>" |
| 73 | fi |