docker-entrypoint.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/sh
  2. #set -e
  3. export RNG=PROGRAM
  4. if [ ${mode} == "server" ]
  5. then
  6. mv /etc/openvpn/server.conf /etc/openvpn/ovpn.conf
  7. echo -e "LegacySigningMDs md2 md5\nMinimumDHBits 512\n" >> /etc/pki/tls/legacy-settings
  8. if [[ ${net} ]]
  9. then
  10. echo "push \"route ${net} 255.255.255.0\"" >> /etc/openvpn/ovpn.conf
  11. fi
  12. if [[ ${dev} && ${ip} ]]
  13. then
  14. if [ -z ${client_net} ]
  15. then
  16. client_net="10.10.20.0/24"
  17. fi
  18. trap cleanup SIGTERM EXIT
  19. cleanup()
  20. {
  21. ip addr del ${ip}/24 dev ${dev}:ovpn
  22. iptables -D FORWARD -m state --state NEW -s ${client_net} -i external -j DROP
  23. iptables -D FORWARD -s ${client_net} -d ${client_net} -i external -j DROP
  24. }
  25. ip addr add ${ip}/24 brd + dev ${dev} label ${dev}:ovpn
  26. iptables -I FORWARD 1 -m state --state NEW -s ${client_net} -i external -j DROP
  27. iptables -I FORWARD 1 -s ${client_net} -d ${client_net} -i external -j DROP
  28. exec "/usr/sbin/openvpn" "--config" "/etc/openvpn/ovpn.conf" "$@" &
  29. wait
  30. else
  31. exec "/usr/sbin/openvpn" "--config" "/etc/openvpn/ovpn.conf" "$@"
  32. fi
  33. fi
  34. if [ ${mode} == "client" ]
  35. then
  36. mv /etc/openvpn/client.conf /etc/openvpn/ovpn.conf
  37. echo "remote ${server}" >> /etc/openvpn/ovpn.conf
  38. echo -e "LegacySigningMDs md2 md5\nMinimumDHBits 512\n" >> /etc/pki/tls/legacy-settings
  39. exec "/usr/sbin/openvpn" "--config" "/etc/openvpn/ovpn.conf" "$@"
  40. fi
  41. if [ ${mode} == "keygen" ]
  42. then
  43. echo "$SSHKEY" > /tmp/keyfile
  44. chmod 0400 /tmp/keyfile
  45. exec "$@"
  46. fi