104 lines
3.6 KiB
Bash
104 lines
3.6 KiB
Bash
#!/bin/bash
|
|
|
|
#The admin interface for OpenVPN
|
|
|
|
echo "Content-type: text/html"
|
|
echo ""
|
|
echo "<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>vpn.wberu.be</title>
|
|
<link href="https://ajusa.github.io/lit/dist/lit.css" rel="stylesheet">
|
|
<link href="https://fonts.googleapis.com/css?family=Nunito:300,400,700" rel="stylesheet">
|
|
</head>
|
|
<body class="m0">
|
|
<div class="c">
|
|
<header class="mb3">
|
|
<h1 class="tc mb0"><b>vpn.wberu.be</b></h1>
|
|
<h5 class="tc mb1">Service de tunnel OpenVPN</h5>
|
|
<hr>
|
|
</header>"
|
|
|
|
eval `echo "${QUERY_STRING}"|tr '&' ';'`
|
|
|
|
IP=$(wget -4qO- "http://whatismyip.akamai.com/")
|
|
|
|
newclient () {
|
|
# Generates the custom client.ovpn
|
|
case $2 in
|
|
"webaccess")
|
|
cp /etc/openvpn/client-webaccess.txt /etc/openvpn/clients/$1.ovpn
|
|
;;
|
|
"telephony")
|
|
cp /etc/openvpn/client-telephony.txt /etc/openvpn/clients/$1.ovpn
|
|
;;
|
|
esac
|
|
echo "<ca>" >> /etc/openvpn/clients/$1.ovpn
|
|
cat /etc/openvpn/easy-rsa/pki/ca.crt >> /etc/openvpn/clients/$1.ovpn
|
|
echo "</ca>" >> /etc/openvpn/clients/$1.ovpn
|
|
echo "<cert>" >> /etc/openvpn/clients/$1.ovpn
|
|
cat /etc/openvpn/easy-rsa/pki/issued/$1.crt >> /etc/openvpn/clients/$1.ovpn
|
|
echo "</cert>" >> /etc/openvpn/clients/$1.ovpn
|
|
echo "<key>" >> /etc/openvpn/clients/$1.ovpn
|
|
cat /etc/openvpn/easy-rsa/pki/private/$1.key >> /etc/openvpn/clients/$1.ovpn
|
|
echo "</key>" >> /etc/openvpn/clients/$1.ovpn
|
|
echo "<tls-auth>" >> /etc/openvpn/clients/$1.ovpn
|
|
cat /etc/openvpn/ta.key >> /etc/openvpn/clients/$1.ovpn
|
|
echo "</tls-auth>" >> /etc/openvpn/clients/$1.ovpn
|
|
}
|
|
|
|
cd /etc/openvpn/easy-rsa/
|
|
|
|
case $option in
|
|
"add") #Add a client
|
|
./easyrsa build-client-full $client nopass
|
|
# Generates the custom client.ovpn
|
|
newclient "$client" "$type"
|
|
echo " Le certificat du client <span style='color:red'>$client</span> a été ajouté.<br><br>"
|
|
;;
|
|
"revoke") #Revoke a client
|
|
./easyrsa --batch revoke $client > /dev/null
|
|
./easyrsa gen-crl > /dev/null
|
|
rm -rf pki/reqs/$client.req
|
|
rm -rf pki/private/$client.key
|
|
rm -rf pki/issued/$client.crt
|
|
rm -rf /etc/openvpn/crl.pem
|
|
cp /etc/openvpn/easy-rsa/pki/crl.pem /etc/openvpn/crl.pem
|
|
# CRL is read with each client connection, when OpenVPN is dropped to nobody
|
|
echo " Le certificat du client <span style='color:red'>$client</span> a été révoqué.<br><br>"
|
|
;;
|
|
esac
|
|
|
|
NUMBEROFCLIENTS=$(tail -n +2 /etc/openvpn/easy-rsa/pki/index.txt | grep -c "^V")
|
|
if [[ "$NUMBEROFCLIENTS" = '0' ]]; then
|
|
echo " Vous n'avez pas de clients existants."
|
|
else
|
|
while read c; do
|
|
if [[ $(echo $c | grep -c "^V") = '1' ]]; then
|
|
clientName=$(echo $c | cut -d '=' -f 2)
|
|
echo " <a href='index.sh?option=revoke&client=$clientName'><button class='btn'>Révoquer</button></a> "
|
|
echo " <a target='_blank' href='download.sh?client=$clientName'><button class='btn primary'>Télécharger</button></a>"
|
|
echo " $clientName<br>"
|
|
fi
|
|
done </etc/openvpn/easy-rsa/pki/index.txt
|
|
fi
|
|
|
|
echo "
|
|
<hr>
|
|
<form action='index.sh' method='get'>
|
|
<input type='hidden' name='option' value='add'>
|
|
<br>Nouveau client: <br>
|
|
<input class='card' type='text' name='client'>
|
|
<select class='card' name='type'>
|
|
<option value='webaccess'>Accès web</option>
|
|
<option value='telephony'>Téléphonie</option>
|
|
</select>
|
|
<button class='btn primary' type='submit'>Créer</button>
|
|
</form>
|
|
</div>
|
|
</body>
|
|
</html>"
|
|
exit 0
|