You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
2.8 KiB

  1. #!/bin/sh
  2. [ -x /usr/bin/sstpc ] || exit 0
  3. [ -n "$INCLUDE_ONLY" ] || {
  4. . /lib/functions.sh
  5. . ../netifd-proto.sh
  6. init_proto "$@"
  7. }
  8. proto_sstp_init_config() {
  9. proto_config_add_string "server"
  10. proto_config_add_string "username"
  11. proto_config_add_string "password"
  12. proto_config_add_string "pppd_options"
  13. proto_config_add_string "sstp_options"
  14. proto_config_add_int "log_level"
  15. proto_config_add_int "mtu"
  16. proto_config_add_boolean "ipv6"
  17. proto_config_add_boolean "defaultroute"
  18. proto_config_add_boolean "peerdns"
  19. available=1
  20. no_device=1
  21. }
  22. proto_sstp_setup() {
  23. local config="$1"; shift
  24. local iface="$2"
  25. local ifname="sstp-$config"
  26. local ip serv_addr server ipv6 defaultroute peerdns
  27. json_get_var server server && {
  28. for ip in $(resolveip -t 5 "$server"); do
  29. ( proto_add_host_dependency "$config" "$ip" )
  30. serv_addr=1
  31. done
  32. }
  33. [ -n "$serv_addr" ] || {
  34. echo "Could not resolve server address"
  35. sleep 5
  36. proto_setup_failed "$config"
  37. exit 1
  38. }
  39. json_get_vars username password pppd_options sstp_options log_level ipv6 defaultroute peerdns
  40. if [ "$ipv6" = 1 ]; then
  41. ipv6=1
  42. else
  43. ipv6=""
  44. fi
  45. if [ "$defaultroute" = 0 ]; then
  46. defaultroute=""
  47. else
  48. defaultroute=1
  49. fi
  50. if [ "$peerdns" = 0 ]; then
  51. peerdns=""
  52. else
  53. peerdns=1
  54. fi
  55. [ -n "$mtu" ] || json_get_var mtu mtu
  56. [ -n "$log_level" ] || log_level=0
  57. local load
  58. for module in slhc ppp_generic ppp_async ppp_mppe ip_gre gre pptp; do
  59. grep -q "^$module " /proc/modules && continue
  60. /sbin/insmod $module 2>&- >&-
  61. load=1
  62. done
  63. [ "$load" = "1" ] && sleep 1
  64. proto_init_update "$ifname" 1
  65. proto_send_update "$config"
  66. proto_run_command "$config" sstpc \
  67. --cert-warn \
  68. --password $password \
  69. --user $username \
  70. --log-level $log_level \
  71. --save-server-route \
  72. --ipparam $config \
  73. $sstp_options \
  74. $server \
  75. ifname $ifname \
  76. require-mschap-v2 \
  77. ${ipv6:++ipv6} \
  78. refuse-pap \
  79. noauth \
  80. ${defaultroute:+replacedefaultroute defaultroute} \
  81. ${peerdns:+usepeerdns} \
  82. ip-up-script /lib/netifd/ppp-up \
  83. ipv6-up-script /lib/netifd/ppp-up \
  84. ip-down-script /lib/netifd/ppp-down \
  85. ipv6-down-script /lib/netifd/ppp-down \
  86. ${mtu:+mtu $mtu mru $mtu} \
  87. $pppd_options
  88. # WORKAROUND: Workaround to properly register the sstp interface (As seeen in: https://forum.archive.openwrt.org/viewtopic.php?id=58007)
  89. # WORKAROUND: Start
  90. sleep 10
  91. proto_init_update "$ifname" 1
  92. proto_send_update "$config"
  93. # WORKAROUND: End
  94. # if use pppoe and sstp at same time , firewall need reload .
  95. # but don't konw why
  96. /etc/init.d/firewall reload 2>&- >&-
  97. }
  98. proto_sstp_teardown() {
  99. local interface="$1"
  100. case "$ERROR" in
  101. 11|19)
  102. proto_notify_error "$interface" AUTH_FAILED
  103. proto_block_restart "$interface"
  104. ;;
  105. 2)
  106. proto_notify_error "$interface" INVALID_OPTIONS
  107. proto_block_restart "$interface"
  108. ;;
  109. esac
  110. proto_kill_command "$interface"
  111. }
  112. [ -n "$INCLUDE_ONLY" ] || {
  113. add_protocol sstp
  114. }