pptpd.init 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_validate_section pptpd login "${1}" \
  11. 'username:string' \
  12. 'password:string'
  13. }
  14. validate_pptpd_section() {
  15. uci_validate_section pptpd service "${1}" \
  16. 'enabled:uinteger' \
  17. 'localip:string' \
  18. 'remoteip:string' \
  19. 'mppe:list(string):required no40 no56 stateless' \
  20. 'logwtmp:uinteger'
  21. }
  22. setup_login() {
  23. validate_login_section "${1}" || {
  24. echo "validation failed"
  25. return 1
  26. }
  27. [ -n "${username}" ] || return 0
  28. [ -n "${password}" ] || return 0
  29. echo "${username} pptp-server ${password} *" >> $CHAP_SECRETS
  30. }
  31. setup_config() {
  32. local enabled localip remoteip mppe
  33. validate_pptpd_section "${1}" || {
  34. echo "validation failed"
  35. return 1
  36. }
  37. [ "$enabled" -eq 0 ] && return 1
  38. mkdir -p /var/etc
  39. cp /etc/pptpd.conf $CONFIG
  40. cp /etc/ppp/options.pptpd $OPTIONS_PPTP
  41. [ -n "$localip" ] && echo "localip $localip" >> $CONFIG
  42. [ -n "$remoteip" ] && echo "remoteip $remoteip" >> $CONFIG
  43. [ "$logwtmp" -eq 1 ] && echo "logwtmp" >> $CONFIG
  44. echo "mppe $(echo $mppe | sed -e 's/\s/,/g')" >> $OPTIONS_PPTP
  45. return 0
  46. }
  47. start_service() {
  48. config_load pptpd
  49. setup_config pptpd || return
  50. config_foreach setup_login login
  51. ln -sfn $CHAP_SECRETS /etc/ppp/chap-secrets
  52. procd_open_instance
  53. procd_set_param command $BIN -c $CONFIG --fg -o $OPTIONS_PPTP
  54. procd_close_instance
  55. }