Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

mkvpn 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #! /usr/bin/env sh
  2. if [ $# -ne 1 ]
  3. then
  4. echo "Usage: $0 vpnname" 1>&2
  5. exit 1
  6. fi
  7. vpn="vpn_$1"
  8. ovpndir="/etc/openvpn"
  9. ovpndirconf="${ovpndir}/${vpn}"
  10. webdir="/var/vpn/${vpn}"
  11. if [ -d "${ovpndirconf}" ] || [ -d "${webdir}" ]
  12. then
  13. echo "VPN already exists" 1>&2
  14. exit 2
  15. fi
  16. echo "Creating OpenVPN configuration"
  17. cd "${ovpndir}"
  18. echo -n "VPN port: "
  19. read vpnport
  20. echo -n "VPN IP range: "
  21. read vpniprange
  22. sed "s/%%VPNNAME%%/${vpn}/g" sampleconf > "${vpn}.conf"
  23. sed "s/%%VPNPORT%%/${vpnport}/g" -i "${vpn}.conf"
  24. sed "s/%%VPNIPRANGE%%/${vpniprange}/g" -i "${vpn}.conf"
  25. cp -r sampleconfdir "${ovpndirconf}"
  26. cd "${ovpndirconf}"
  27. sed "s/%%VPNNAME%%/${vpn}/g" -i clients/client.conf
  28. sed "s/%%VPNPORT%%/${vpnport}/g" -i clients/client.conf
  29. cd "easy-rsa"
  30. editor vars
  31. . ./vars
  32. export KEY_OU="${KEY_ORG}"
  33. export KEY_CN="${KEY_ORG}"
  34. export KEY_NAME="${KEY_ORG}"
  35. ./clean-all
  36. ./build-ca
  37. ./build-key-server server
  38. ./build-dh
  39. openssl ca -gencrl -keyfile keys/ca.key -cert keys/ca.crt -out keys/crl.pem -config openssl.cnf
  40. unset KEY_OU
  41. unset KEY_CN
  42. unset KEY_NAME
  43. chmod 710 keys
  44. cd keys
  45. openvpn --genkey --secret ta.key
  46. cp dh*.pem ../../
  47. cp ca.crt ../../
  48. cp ta.key ../../
  49. cp server.crt ../../
  50. cp server.key ../../
  51. cd "${ovpndir}"
  52. chown -R root:ovpn-manager "${vpn}" "${vpn}.conf"
  53. echo "Creating web configuration"
  54. mkdir "${webdir}"
  55. cd "${webdir}"
  56. echo "AuthUserFile ${webdir}/.htpasswd" >> .htaccess
  57. echo "AuthType Basic" >> .htaccess
  58. echo "AuthName \"${vpn}\"" >> .htaccess
  59. echo "Require user ovpn-root" >> .htaccess
  60. cp ../.htpasswd .