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.

43 lines
857 B

  1. #!/bin/sh
  2. # This script wraps openfortivpn in order to obtain the password
  3. # file from cmd and to daemonize
  4. # $1 password file
  5. # $2 is the config name
  6. # $3... are passed to openconnect
  7. test -z "$1" && exit 1
  8. pwfile=$1; shift
  9. config=$1; shift
  10. killed=0
  11. trap_with_arg() {
  12. func="$1" ; shift
  13. for sig ; do
  14. trap "$func $sig" "$sig"
  15. done
  16. }
  17. func_trap() {
  18. logger "openfortivpn-wrapper[$$]" "$config: sending signal ${1}"
  19. killed=1
  20. kill "-${1}" "$child" 2>/dev/null
  21. }
  22. trap_with_arg func_trap INT TERM KILL
  23. start_time=$(date '+%s')
  24. /usr/sbin/openfortivpn "$@" < "$pwfile" 2>/dev/null &
  25. child=$!
  26. wait $child || {
  27. [ "$killed" = 1 ] && exit 0
  28. current_time=$(date '+%s')
  29. elapsed=$((current_time-start_time))
  30. . /lib/netifd/netifd-proto.sh
  31. proto_notify_error "$config" "Failed to connect after $elapsed seconds."
  32. proto_block_restart "$config"
  33. exit 1
  34. }