Выгрузка в csv-формат всех активных vpn-аккаунтов OpenVPN сервера с дополнительн
LDAP
openvpn
ldapsearch
Выгрузка в csv-формат всех активных vpn-аккаунтов OpenVPN сервера с дополнительной информацией из LDAP AD Windows.
#!/bin/bash
VD=”/etc/openvpn/easy-rsa/2.0/keys”
LDPAS=”secret_pass”
LDUSR=”bitrix@omega.local“
LDHST=”10.100.2.11”
LDGRP=”OU=ГК ОМЕГА,DC=omega,DC=local”
#LDGRP=”CN=Person,CN=Schema,CN=Configuration,DC=omega,DC=local”
if [ -f vpn-user-raw.txt ]; then
rm vpn-users-raw.txt
fi
### Query template
###fio=$ldapsearch \-x \-h $LDHST \-D $LDUSR \-w $LDPAS \-b ${LDGRP} \-P 3 \-a always "\(&\(sAMAccountName=${user}mail=\*)” sn cn mail -LLL | grep ^[cn] | awk ‘{ FS=”:”; print $2 }’ | mmencode -u)
#email=$ldapsearch \-x \-h $LDHST \-D $LDUSR \-w $LDPAS \-b ${LDGRP} \-P 3 \-a always "\(&\(sAMAccountName=${user}mail=\*)” mail -LLL | grep ^[mail] | awk ‘{ FS=”:”; print $2 }’)
### for debug only!
#grep ^[V] $VD/index.txt | head -n10 | awk ‘{ FS=”CN=”; 0=0; print $2}’ | awk ‘{ FS=”/”; 0=0; print $1 }’ | sort > .vpn_users
grep ^[V] $VD/index.txt | awk ‘{ FS=”CN=”; 0=0; print $2}’ | awk ‘{ FS=”/”; 0=0; print $1 }’ | sort > .vpn_users
while read user; do
if [ -f VD/user.crt ]; then
endate=$grep After $VD/${user}.crt | awk '{ FS="Not After :"; $0=$0; print $2}'
fio=$ldapsearch \-x \-h $LDHST \-D $LDUSR \-w $LDPAS \-b "$LDGRP" \-P 3 \-a always "\(&\(sAMAccountName=${user}mail=\*)” cn -LLL | grep ^[cn] | awk ‘{ FS=”:”; print $2 }’ | mmencode -u)
email=$ldapsearch \-x \-h $LDHST \-D $LDUSR \-w $LDPAS \-b "$LDGRP" \-P 3 \-a always "\(&\(sAMAccountName=${user}mail=\*)” mail -LLL | grep ^[mail] | awk ‘{ FS=”:”; print $2 }’)
wpho=$ldapsearch \-x \-h $LDHST \-D $LDUSR \-w $LDPAS \-b "$LDGRP" \-P 3 \-a always "\(&\(sAMAccountName=${user}mail=\*)” mobile -LLL | grep ^[mobile] | awk ‘{ FS=”:”; print $2 $3 $4}’)
hpho=$ldapsearch \-x \-h $LDHST \-D $LDUSR \-w $LDPAS \-b "$LDGRP" \-P 3 \-a always "\(&\(sAMAccountName=${user}mail=\*)” homePhone -LLL | grep ^[homePhone] | awk ‘{ FS=”:”; print $2 $3 $4}’)
echo fio';'user’;’email';'wpho’;’hpho';'endate
fi
done \< .vpn_users
###
https://git.gkomega.ru/sani/arsenal/blob/master/vpn/vpn_info.sh