上文《使用脚本一键安装l2tp+IPSec服务端组件异地局网》我们记录了在服务器上安装L2TP+IPSec服务端,这里我们有时候需要区分用户,每个用户登录之后需要记录下,避免出现安全隐患,所以这里的话,我们来添加下用户的登录日志:
1)修改/etc/ppp/ip-up文件,在此处添加如下信息:
echo "##################################" >> /var/log/pptpd.log echo "Now User $PEERNAME is connected!!!" >> /var/log/pptpd.log echo "##################################" >> /var/log/pptpd.log echo "time: `date -d today +%F_%T`" >> /var/log/pptpd.log echo "clientIP: $6" >> /var/log/pptpd.log echo "username: $PEERNAME" >> /var/log/pptpd.log echo "device: $1" >> /var/log/pptpd.log echo "vpnIP: $4" >> /var/log/pptpd.log echo "assignIP: $5" >> /var/log/pptpd.log
2)修改/etc/ppp/ip-down文件,在此处添加如下信息:
echo "#####################################" >> /var/log/pptpd.log echo "Now User $PEERNAME is disconnected!!!" >> /var/log/pptpd.log echo "#####################################" >> /var/log/pptpd.log echo "time: `date -d today +%F_%T`" >> /var/log/pptpd.log echo "clientIP: $6" >> /var/log/pptpd.log echo "username: $PEERNAME" >> /var/log/pptpd.log echo "device: $1" >> /var/log/pptpd.log echo "vpnIP: $4" >> /var/log/pptpd.log echo "assignIP: $5" >> /var/log/pptpd.log echo "connect time: $CONNECT_TIME s" >> /var/log/pptpd.log echo "bytes sent: $BYTES_SENT B" >> /var/log/pptpd.log echo "bytes rcvd: $BYTES_RCVD B" >> /var/log/pptpd.log sum_bytes=$(($BYTES_SENT+$BYTES_RCVD)) sum=`echo "scale=2;$sum_bytes/1024/1024"|bc` echo "bytes sum: $sum MB" >> /var/log/pptpd.log ave=`echo "scale=2;$sum_bytes/1024/$CONNECT_TIME"|bc` echo "average speed: $ave KB/s" >> /var/log/pptpd.log
以上两个信息添加完毕之后,只要有用户登录或者离开就会在 /var/log/pptpd.log日志里面留下记录,如下图:
这里有个问题,就是获取客户端的clientip获取不到,这里算是个bug,我先查查问题。
还没有评论,来说两句吧...