Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. if [ $# -ne 3 ]
  3. then
  4. echo "Usage: mkclient clientname vpn" 1>&2
  5. exit 1
  6. fi
  7. vpn="${2}"
  8. clientname="${1}-${vpn}"
  9. vpn="vpn_${vpn}"
  10. if [ ! -d "/etc/openvpn/${vpn}" ]
  11. then
  12. echo "VPN does not exists" 1>&2
  13. exit 2
  14. fi
  15. if [ $(echo "${clientname}" | grep -c -E "^[a-zA-Z0-9\._\-]+$") != 1 ]
  16. then
  17. echo "Invalid client name"
  18. exit 3
  19. fi
  20. cd "/etc/openvpn/${vpn}/easy-rsa/keys"
  21. clientsdir="/etc/openvpn/${vpn}/clients/"
  22. clientdir="$clientsdir${clientname}/"
  23. clientslinkdir="/var/vpn/${vpn}/"
  24. if [ -a "${clientname}.crt" ] || [ -a "${clientname}.csr" ] || [ -a "${clientname}.key" ] || [ -d $clientdir ]
  25. then
  26. echo "Client ${clientname} already exists or is revoked"
  27. exit 4
  28. fi
  29. cd ..
  30. source ./vars
  31. KEY_CN="${clientname}" KEY_NAME="${clientname}" ./pkitool ${clientname}
  32. ret=$?
  33. if [ $ret != 0 ]
  34. then
  35. echo "pkitool exited with code $ret"
  36. exit 5
  37. fi
  38. cd keys
  39. echo "Copying generated files"
  40. mkdir -p $clientdir
  41. cp "${clientname}.crt" "$clientdir/${clientname}-${vpn}.crt"
  42. cp "${clientname}.key" "$clientdir/${clientname}-${vpn}.key"
  43. echo "Copying ca and ta"
  44. cd "/etc/openvpn/${vpn}"
  45. cp ca.crt "$clientdir/ca-${vpn}.crt"
  46. cp ta.key "$clientdir/ta-${vpn}.key"
  47. echo "Creating client-${vpn}.conf"
  48. cd $clientsdir
  49. sed "s/%%client%%/${clientname}/g" client.conf > "$clientdir/${clientname}.conf"
  50. echo "Creating ${clientname}.tar.bz2"
  51. tar cfj "${clientname}.tar.bz2" "${clientname}/"*
  52. echo "mkclient completed"
  53. exit 0