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.

63 lines
1.2 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. validate_login_section() {
  9. uci_validate_section pptpd login "${1}" \
  10. 'username:string' \
  11. 'password:string'
  12. }
  13. validate_pptpd_section() {
  14. uci_validate_section pptpd service "${1}" \
  15. 'enabled:uinteger' \
  16. 'localip:string' \
  17. 'remoteip:string'
  18. }
  19. setup_login() {
  20. validate_login_section "${1}" || {
  21. echo "validation failed"
  22. return 1
  23. }
  24. [ -n "${username}" ] || return 0
  25. [ -n "${password}" ] || return 0
  26. echo "${username} pptp-server ${password} *" >> $CHAP_SECRETS
  27. }
  28. setup_config() {
  29. validate_pptpd_section "${1}" || {
  30. echo "validation failed"
  31. return 1
  32. }
  33. [ "$enabled" -eq 0 ] && return 1
  34. mkdir -p /var/etc
  35. cp /etc/pptpd.conf $CONFIG
  36. [ -n "$localip" ] && echo "localip $localip" >> $CONFIG
  37. [ -n "$remoteip" ] && echo "remoteip $remoteip" >> $CONFIG
  38. return 0
  39. }
  40. start_service() {
  41. config_load pptpd
  42. setup_config pptpd || return
  43. config_foreach setup_login login
  44. ln -sfn $CHAP_SECRETS /etc/ppp/chap-secrets
  45. procd_open_instance
  46. procd_set_param command $BIN -c $CONFIG
  47. procd_close_instance
  48. }