Mar
18
pppd禁止相同用户多个连接
学习笔记 Popularity: 11%
推特教牧师发起了一个VPN公益项目,我帮忙搭建了测试用的基本的VPN server。需要禁止PPTP VPN相同用户多个连接。Poptop的用户验证是由pppd负责的,pppd自身没有这样的功能,而为10用户级别的VPN做一套MPPE+RADIUS+MySQL有点过于奢侈了。Google一下发现这里有一个利用pppd的auth-up脚本实现禁止多个连接的脚本(新连接自动踢掉旧连接),需要用一下awk,原脚本USER变量写错了,另外不知道为什么在debian下会被提示“PPID是只读变量”,更正后的脚本如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #!/bin/sh # get the username from the parameters USER=$2 # create the directory to keep pid files per user mkdir -p /var/run/pptpd-users # interlock access to directory lockfile-create /var/run/pptpd-users # if there is a session already for this user, terminate the old one if [ -f /var/run/pptpd-users/$USER ]; then kill -HUP `cat /var/run/pptpd-users/$USER` rm /var/run/pptpd-users/$USER fi # remember the pid of the pppd process PID=`awk '/PPid/ { print $2; }' /proc/$$/status` echo $PID > /var/run/pptpd-users/$USER # release interlock lockfile-remove /var/run/pptpd-users |
只有一个auth-up脚本有时会有问题:pptpd-users下的状态文件不会随用户离线而删除,又因为pid是循环使用的,当下一次用户拨入时,状态文件里记录的pid很可能是个不相关的进程。故而还需要一个auth-down脚本,在用户离线时删除状态文件。
1 2 3 4 | #!/bin/sh # get the username from the parameters USER=$2 rm /var/run/pptpd-users/$USER |
April 2nd, 2010 at 8:22 am
[...] pppd 禁止相同用户多个连接 [...]
March 19th, 2010 at 22:48 pm
last可以自动化
Reply
March 19th, 2010 at 22:55 pm
last怎么样自动化呢?
Reply
March 18th, 2010 at 14:38 pm
用awk什么的麻烦了。我都是直接看last的
Reply
March 18th, 2010 at 14:53 pm
用last怎么处理?
Reply
March 19th, 2010 at 10:04 am
但是last没法自动化我觉得。另外我怀疑这个性能不好。
Reply