#!/bin/sh # vpninfo - query PF firewall for current VPN user info # Change MYVPNPREFIX and VPNSTATUSLOG to match your site's info ############## License #################### #Copyright (c) <2009>, #All rights reserved. # #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: # * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. # * Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ############################################### MYVPNPREFIX='10.253.21' VPNSTATUSLOG='/etc/openvpn/openvpn-status.log' function pfUserInfo { TABLECOUNTEROFFSET=2 echo "PF Rules for user ${1}" pfctl -a vpnusers/${1} -sr echo echo "PF Dynamic Table Contents for user ${1}:" pfctl -a vpnusers/${1} -sr | grep __automatic | while read PFLINE do #output looks like: # pass in inet proto tcp from 192.168.1.3 to <__automatic_e44a2a86_0> port = domain flags S/SA keep state TABLECOUNTER=${TABLECOUNTEROFFSET} tables[$TABLECOUNTER]=`echo ${PFLINE} | cut -d'<' -f $TABLECOUNTER | cut -d'>' -f1` while echo $tables[${TABLECOUNTER}] | grep -q '__automatic' do TABLECOUNTER=$((${TABLECOUNTER}+1)) tables[$TABLECOUNTER]=`echo ${PFLINE} | cut -d'<' -f $TABLECOUNTER | cut -d'>' -f1` done for table in ${tables[@]} do echo "#### ${table} ###" pfctl -a vpnusers/${1} -t ${table} -T show echo done done } cat ${VPNSTATUSLOG} | grep "^${MYVPNPREFIX}" | while read i do #data looks like: #10.253.21.14,bob,75.148.93.165:3478,Wed Jun 17 09:54:22 2009 LOCALIP=`echo ${i} | cut -d, -f1` VNAME=`echo ${i} | cut -d, -f2` REMOTEIP=`echo ${i} | cut -d, -f3` CONNECTIME=`echo ${i} | cut -d, -f4` echo echo "################# ${VNAME} ######################" echo "localIP: ${LOCALIP}, remoteIP: ${REMOTEIP}" echo "Connected since: ${CONNECTIME}" echo pfUserInfo ${VNAME} done