added additional client description to $faqprofile

This commit is contained in:
Pavel Muhortov 2024-01-04 22:10:15 +03:00
parent c206d33a72
commit a5490518ba
2 changed files with 23 additions and 18 deletions

View File

@ -91,8 +91,9 @@ ____
|-----------|--------------|------------------------|---------------| |-----------|--------------|------------------------|---------------|
| 1 |**add\|del**|add or delete client config|**REQUIRED**| | 1 |**add\|del**|add or delete client config|**REQUIRED**|
| 2 |**\<username\>**|client username|**REQUIRED**| | 2 |**\<username\>**|client username|**REQUIRED**|
| 3 |**\<password\>**|client password|| | 3 |**\<password\>**|client password|**REQUIRED**|
| 4 |**[-f]**,**[--force]**|service will restart after username delete|| | 4 |**\<additional\>**|client description||
| 5 |**[-f]**,**[--force]**|service will restart after username delete||
Example usage: Example usage:

View File

@ -102,11 +102,11 @@ createuser() {
####################################### #######################################
# shellcheck disable=SC2016 # shellcheck disable=SC2016
createcert() { createcert() {
cd ${easyrsadir} || execerror "" cd "${easyrsadir}" || execerror ""
sed -i -e '$aset_var EASYRSA_REQ_CN '"${clientname}"'' ${easyrsavar} sed -i -e '$aset_var EASYRSA_REQ_CN '"${clientname}"'' "${easyrsavar}"
# ${easyrsaexe} --passout=pass:"${clientpass}" --passin=pass:${easyrsacap} build-client-full "${clientname}" # ${easyrsaexe} --passout=pass:"${clientpass}" --passin=pass:${easyrsacap} build-client-full "${clientname}"
${easyrsaexe} --passin=pass:"${easyrsacap}" build-client-full "${clientname}" nopass ${easyrsaexe} --passin=pass:"${easyrsacap}" build-client-full "${clientname}" nopass
sed -i '/EASYRSA_REQ_CN/d' ${easyrsavar} sed -i '/EASYRSA_REQ_CN/d' "${easyrsavar}"
} }
####################################### #######################################
@ -120,7 +120,7 @@ createcert() {
# None # None
####################################### #######################################
createovpn() { createovpn() {
cd ${easyrsadir} || execerror "" cd "${easyrsadir}" || execerror ""
{ {
cat "${ovpncfgdef}" cat "${ovpncfgdef}"
echo -e '<ca>' echo -e '<ca>'
@ -146,12 +146,12 @@ createovpn() {
####################################### #######################################
createtars() { createtars() {
cp "${ovpncfgdir}/${clientname}.ovpn" "${ovpncfgdir}/vpn.cnf" cp "${ovpncfgdir}/${clientname}.ovpn" "${ovpncfgdir}/vpn.cnf"
sed -i "s#auth-user-pass#auth-user-pass /config/openvpn/vpn.txt#g" ${ovpncfgdir}/vpn.cnf sed -i "s#auth-user-pass#auth-user-pass /config/openvpn/vpn.txt#g" "${ovpncfgdir}/vpn.cnf"
{ {
echo -e "${clientname}" echo -e "${clientname}"
echo -e "${clientpass}" echo -e "${clientpass}"
} >> "${ovpncfgdir}/vpn.txt" } >> "${ovpncfgdir}/vpn.txt"
cd ${ovpncfgdir} || execerror "" cd "${ovpncfgdir}" || execerror ""
tar cf "${clientname}.tar" --remove-files vpn.cnf vpn.txt tar cf "${clientname}.tar" --remove-files vpn.cnf vpn.txt
} }
@ -166,17 +166,19 @@ createtars() {
# None # None
####################################### #######################################
createinfo() { createinfo() {
cd ${easyrsadir} || execerror cd "${easyrsadir}" || execerror ""
validuntil=$(${easyrsaexe} show-cert "${clientname}" | grep "Not After" | cut -d: -f2-) validuntil=$(${easyrsaexe} show-cert "${clientname}" | grep "Not After" | cut -d: -f2-)
faqprofile=$(cat <<END faqprofile=$(cat <<END
OpenVPN Connect client and installation instructions: OpenVPN Connect client:
https://openvpn.net/vpn-client/ https://openvpn.net/client/
OpenVPN GUI client: OpenVPN GUI client:
https://openvpn.net/community-downloads/ https://openvpn.net/community-downloads/
User Login: ${clientname} ${additional}
User Password: ${clientpass}
User Login: \`${clientname}\`
User Password: \`${clientpass}\`
Time Expired: ${validuntil} Time Expired: ${validuntil}
END END
) )
@ -185,7 +187,7 @@ END
} }
####################################### #######################################
# Send email notification about client connect # Send email notification about client config
# Globals: # Globals:
# clientname # clientname
# faqprofile # faqprofile
@ -204,13 +206,14 @@ startsendmail() {
--port "$(grep "port=" /usr/local/bin/sendmail.config | cut -d= -f2)" \ --port "$(grep "port=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
--stls "True" \ --stls "True" \
--subj "${subj}" \ --subj "${subj}" \
--text "${faqprofile}" \ --text "$(printf "%s\n" "${faqprofile}" | sed 's|`||g')" \
--file "${ovpncfgdir}/${clientname}.ovpn,${ovpncfgdir}/${clientname}.tar" \ --file "${ovpncfgdir}/${clientname}.ovpn,${ovpncfgdir}/${clientname}.tar" \
>> /dev/null 2>&1 & >> /dev/null 2>&1 &
) )
addtologs "sent mail with subject '${subj}'" addtologs "sent mail with subject '${subj}'"
} }
####################################### #######################################
# Deleting linux user # Deleting linux user
# Globals: # Globals:
@ -234,9 +237,9 @@ deleteuser() {
# None # None
####################################### #######################################
deletecert() { deletecert() {
cd ${easyrsadir} || execerror cd "${easyrsadir}" || execerror
${easyrsaexe} --batch --passin=pass:${easyrsacap} revoke "${clientname}" ${easyrsaexe} --batch --passin=pass:"${easyrsacap}" revoke "${clientname}"
${easyrsaexe} --batch --passin=pass:${easyrsacap} gen-crl ${easyrsaexe} --batch --passin=pass:"${easyrsacap}" gen-crl
} }
####################################### #######################################
@ -290,6 +293,7 @@ ovpncfgdef="${ovpncfgdir}/client.conf.default"
clienttodo=$1 clienttodo=$1
clientname=$2 clientname=$2
clientpass=$3 clientpass=$3
additional=$4
resetforce=0 resetforce=0
for argument in "${@}"; do for argument in "${@}"; do