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 | DESIRED_WAN_STATE=`sysevent get desired_ipv4_wan_state` |
| 5 | CURRENT_WAN_STATE=`sysevent get current_ipv4_wan_state` |
| 6 | CURRENT_LINK_STATE=`sysevent get current_ipv4_link_state` |
| 7 | WAN_IFNAME=`sysevent get wan_ifname` |
| 8 | LAN_IFNAME=`syscfg get lan_ifname` |
| 9 | |
| 10 | |
| 11 | WAN_PROTOCOL=`syscfg get wan_proto` |
| 12 | CLIENT=`syscfg get wan_proto_username` |
| 13 | PASSWORD=`syscfg get wan_proto_password` |
| 14 | |
| 15 | PPTP_OPTIONS_FILE=/etc/ppp/options.pptp |
| 16 | PPP_OPTIONS_FILE=/etc/ppp/options |
| 17 | WAN_SERVER_IPADDR=`syscfg get wan_proto_server_address` |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | init_pptp (){ |
| 24 | echo "[utopia][pptp] Configuring pptp" > /dev/console |
| 25 | prepare_pppd_ip_pre_up_script |
| 26 | prepare_pppd_ip_up_script |
| 27 | prepare_pppd_ip_down_script |
| 28 | prepare_pppd_ipv6_up_script |
| 29 | prepare_pppd_ipv6_down_script |
| 30 | |
| 31 | prepare_pppd_secrets |
| 32 | |
| 33 | |
| 34 | # create the l2tp conf file |
| 35 | |
| 36 | |
| 37 | echo -n > $PPP_OPTIONS_FILE |
| 38 | echo -n > $PPTP_OPTIONS_FILE |
| 39 | |
| 40 | |
| 41 | # create the pptp option file |
| 42 | echo "noauth" >> $PPTP_OPTIONS_FILE |
| 43 | echo "refuse-eap" >> $PPTP_OPTIONS_FILE |
| 44 | echo "user $CLIENT" >> $PPTP_OPTIONS_FILE |
| 45 | echo "password $PASSWORD" >> $PPTP_OPTIONS_FILE |
| 46 | echo "connect true" >> $PPTP_OPTIONS_FILE |
| 47 | echo "pty 'pptp $WAN_SERVER_IPADDR --nolaunchpppd'" >> $PPTP_OPTIONS_FILE |
| 48 | echo "lock" >> $PPTP_OPTIONS_FILE |
| 49 | echo "maxfail 0" >> $PPTP_OPTIONS_FILE |
| 50 | echo "usepeerdns" >> $PPTP_OPTIONS_FILE |
| 51 | echo "persist" >> $PPTP_OPTIONS_FILE |
| 52 | #echo "holdoff $PPTP_OPTIME" >> $PPTP_FILE |
| 53 | echo "ipcp-accept-remote ipcp-accept-local noipdefault" >> $PPTP_OPTIONS_FILE |
| 54 | echo "ktune" >> $PPTP_OPTIONS_FILE |
| 55 | echo "default-asyncmap" >> $PPTP_OPTIONS_FILE |
| 56 | echo "nopcomp" >> $PPTP_OPTIONS_FILE |
| 57 | echo "noaccomp" >> $PPTP_OPTIONS_FILE |
| 58 | echo "novj" >> $PPTP_OPTIONS_FILE |
| 59 | echo "nobsdcomp" >> $PPTP_OPTIONS_FILE |
| 60 | echo "nodeflate" >> $PPTP_OPTIONS_FILE |
| 61 | echo "lcp-echo-interval 10" >> $PPTP_OPTIONS_FILE |
| 62 | echo "lcp-echo-failure 6" >> $PPTP_OPTIONS_FILE |
| 63 | |
| 64 | echo "require-mppe-128" >> $PPTP_OPTIONS_FILE |
| 65 | |
| 66 | echo "debug" >> $PPTP_OPTIONS_FILE |
| 67 | echo "dump" >> $PPTP_OPTIONS_FILE |
| 68 | echo "logfd 2" >> $PPTP_OPTIONS_FILE |
| 69 | echo "logfile /var/log/pptp.log" >> $PPTP_OPTIONS_FILE |
| 70 | |
| 71 | echo "ipparam 'pptp'" >> $PPTP_OPTIONS_FILE |
| 72 | echo "ifname 'pptp-pptp'" >> $PPTP_OPTIONS_FILE |
| 73 | |
| 74 | } |
| 75 | |
| 76 | if [ "$1" == "start" ]; then |
| 77 | if [ -n "$2" ]; then |
| 78 | echo "wan_proto_username" |
| 79 | syscfg set wan_proto_username $2 |
| 80 | fi |
| 81 | if [ -n "$3" ]; then |
| 82 | echo "wan_proto_password" |
| 83 | syscfg set wan_proto_password $3 |
| 84 | fi |
| 85 | if [ -n "$4" ]; then |
| 86 | echo "wan_proto_server_address" |
| 87 | syscfg set wan_proto_server_address $4 |
| 88 | fi |
| 89 | |
| 90 | init_pptp |
| 91 | modprobe ppp_mppe > /dev/null 2>&1 |
| 92 | modprobe pptp > /dev/null 2>&1 |
| 93 | pppd file /etc/ppp/options.pptp & |
| 94 | elif [ "$1" == "stop" ]; then |
| 95 | PID=`cat /var/run/pptp-pptp.pid` |
| 96 | echo "PID $PID" |
| 97 | kill $PID |
| 98 | else |
| 99 | echo "Useage: $0 <start/stop> <user> <password> <serv_ip>" |
| 100 | fi |