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.

81 lines
1.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2015 OpenWrt.org
  3. START=60
  4. USE_PROCD=1
  5. BIN=/usr/sbin/pptpd
  6. CONFIG=/var/etc/pptpd.conf
  7. CHAP_SECRETS=/var/etc/chap-secrets
  8. OPTIONS_PPTP=/var/etc/options.pptpd
  9. validate_login_section() {
  10. uci_load_validate pptpd login "$1" "$2" \
  11. 'username:string' \
  12. 'password:string' \
  13. 'remoteip:string'
  14. }
  15. validate_pptpd_section() {
  16. uci_load_validate pptpd service "$1" "$2" \
  17. 'enabled:uinteger' \
  18. 'localip:string' \
  19. 'remoteip:string' \
  20. 'mppe:list(string):required no40 no56 stateless' \
  21. 'logwtmp:uinteger'
  22. }
  23. setup_login() {
  24. [ "$2" = 0 ] || {
  25. echo "validation failed"
  26. return 1
  27. }
  28. [ -n "$username" ] || return 0
  29. [ -n "$password" ] || return 0
  30. [ -n "$remoteip" ] || remoteip=*
  31. echo "$username pptp-server $password $remoteip" >> $CHAP_SECRETS
  32. }
  33. setup_config() {
  34. [ "$2" = 0 ] || {
  35. echo "validation failed"
  36. return 1
  37. }
  38. [ "$enabled" -eq 0 ] && return 1
  39. mkdir -p /var/etc
  40. cp /etc/pptpd.conf $CONFIG
  41. cp /etc/ppp/options.pptpd $OPTIONS_PPTP
  42. [ -n "$localip" ] && echo "localip $localip" >> $CONFIG
  43. [ -n "$remoteip" ] && echo "remoteip $remoteip" >> $CONFIG
  44. [ "$logwtmp" -eq 1 ] && echo "logwtmp" >> $CONFIG
  45. echo "mppe $(echo $mppe | sed -e 's/\s/,/g')" >> $OPTIONS_PPTP
  46. return 0
  47. }
  48. start_service() {
  49. config_load pptpd
  50. validate_pptpd_section pptpd setup_config || return
  51. config_foreach validate_login_section login setup_login
  52. ln -sfn $CHAP_SECRETS /etc/ppp/chap-secrets
  53. procd_open_instance
  54. procd_set_param command $BIN -c $CONFIG --fg -o $OPTIONS_PPTP
  55. procd_close_instance
  56. }
  57. service_triggers () {
  58. procd_add_reload_trigger "pptpd"
  59. procd_open_validate
  60. validate_pptpd_section
  61. validate_login_section
  62. procd_close_validate
  63. }