Advertisement
kisslo

openvpn_revoke_user.sh

May 22nd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.04 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Debian 8.5 x64
  4. # OpenVPN version 2.3.4
  5. # 06/07/2016
  6.  
  7.  
  8. # Check Arguments
  9. if [ $# -eq 0 ] || [ $# -gt 2 ]
  10. then
  11.         /bin/echo ''
  12.         /bin/echo 'This script is meant to be used in the following manner:'  
  13.         /bin/echo ''
  14.         /bin/echo $0 '$1' '$2'
  15.         /bin/echo ''
  16.         /bin/echo ' ***where $1 = client#/android#/ios# depending on type and operating system of client***'
  17.         /bin/echo ' ***where $2 = "remove" to revoke client and remove his files***'
  18.         /bin/echo ''
  19.         /bin/echo ''
  20. else        
  21.     # Check if client certs/keys/profiles already exist
  22.     if [ $# -eq 1 ] && [ -e /etc/openvpn/easy-rsa-master/keys/$1/$1.ovpn ]
  23.     then
  24.                 /etc/openvpn/easy-rsa-master/easyrsa3/easyrsa revoke $1
  25.                 /etc/openvpn/easy-rsa-master/easyrsa3/easyrsa gen-crl
  26.         exit 1
  27.     fi
  28.         if [ "$2" != "remove" ] && [ -e /etc/openvpn/easy-rsa-master/keys/$1/$1.ovpn ]
  29.         then
  30.                 /bin/echo ''
  31.                 /bin/echo 'This script is meant to be used in the following manner:'  
  32.                 /bin/echo ''
  33.                 /bin/echo $0 '$1' '$2'
  34.                 /bin/echo ''
  35.                 /bin/echo ' ***where $1 = client#/android#/ios# depending on type and operating system of client***'
  36.                 /bin/echo ' ***where $2 = "remove" to revoke client and remove his files***'
  37.                 /bin/echo ''
  38.                 /bin/echo ''
  39.         else
  40.             if [ -e /etc/openvpn/easy-rsa-master/keys/$1/$1.ovpn ]
  41.             then
  42.                         /etc/openvpn/easy-rsa-master/easyrsa3/easyrsa revoke $1
  43.                 /bin/rm /etc/openvpn/easy-rsa-master/easyrsa3/pki/issued/$1.crt
  44.                         /bin/rm /etc/openvpn/easy-rsa-master/easyrsa3/pki/private/$1.key
  45.                         /bin/rm /etc/openvpn/easy-rsa-master/easyrsa3/pki/reqs/$1.req
  46.                         /bin/rm -R /etc/openvpn/easy-rsa-master/keys/$1
  47.                 #/bin/sed -i "/\<CN=$1\>/d" /etc/openvpn/easy-rsa-master/easyrsa3/pki/index.txt
  48.                         /etc/openvpn/easy-rsa-master/easyrsa3/easyrsa gen-crl
  49.             else
  50.                 /bin/echo "It seems that user $1 doesn't exists!!!"
  51.                 exit 1
  52.             fi
  53.         fi
  54. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement