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.

75 lines
1.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=99
  3. USE_PROCD=1
  4. BIN=/usr/sbin/openfortivpn
  5. CONFIG=/var/etc/openfortivpn.config
  6. validate_certs_section() {
  7. uci_load_validate openfortivpn certs "$1" "$2" \
  8. 'trusted_cert:string'
  9. }
  10. validate_openfortivpn_section() {
  11. uci_load_validate openfortivpn service "$1" "$2" \
  12. 'enabled:uinteger' \
  13. 'host:string' \
  14. 'port:uinteger' \
  15. 'username:string' \
  16. 'password:string' \
  17. 'set_routes:uinteger' \
  18. 'set_dns:uinteger' \
  19. 'pppd_use_peerdns:uinteger'
  20. }
  21. setup_certs() {
  22. [ "$2" = 0 ] || {
  23. echo "validation failed"
  24. return 1
  25. }
  26. [ -n "$trusted_cert" ] || return 0
  27. echo "trusted-cert = $trusted_cert" >> $CONFIG
  28. }
  29. setup_config() {
  30. [ "$2" = 0 ] || {
  31. echo "validation failed"
  32. return 1
  33. }
  34. [ "$enabled" -eq 0 ] && return 1
  35. mkdir -p /var/etc
  36. echo '# auto-generated config file from /etc/config/openfortivpn' > $CONFIG
  37. [ -n "$host" ] && echo "host = $host" >> $CONFIG
  38. [ -n "$port" ] && echo "port = $port" >> $CONFIG
  39. [ -n "$username" ] && echo "username = $username" >> $CONFIG
  40. [ -n "$password" ] && echo "password = $password" >> $CONFIG
  41. [ -n "$set_routes" ] && echo "set-routes = $set_routes" >> $CONFIG
  42. [ -n "$set_dns" ] && echo "set-dns = $set_dns" >> $CONFIG
  43. [ -n "$pppd_use_peerdns" ] && echo "pppd-use-peerdns = $pppd_use_peerdns" >> $CONFIG
  44. return 0
  45. }
  46. start_service() {
  47. config_load openfortivpn
  48. validate_openfortivpn_section openfortivpn setup_config || return
  49. config_foreach validate_certs_section certs setup_certs
  50. procd_open_instance
  51. procd_set_param stderr 1
  52. procd_set_param command $BIN -c $CONFIG --use-syslog
  53. procd_close_instance
  54. }
  55. service_triggers () {
  56. procd_add_reload_trigger "openfortivpn"
  57. procd_open_validate
  58. validate_openfortivpn_section
  59. validate_certs_section
  60. procd_close_validate
  61. }