首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网络安全 > 安全知识 > OpenVPN中connect/disconnect脚本,用于计费
【标  题】:OpenVPN中connect/disconnect脚本,用于计费
【关键字】:OpenVPN,connect/disconnect
【来  源】:http://blog.chinaunix.net/article.php?articleId=57653&blogId=2389

OpenVPN中connect/disconnect脚本,用于计费

用py写的,把日志写到数据库里面,剩下的由管理员操作

由于没有空查看,先复制下来,有空自己试验,修改

Hi all,

I'm tearing my hair out at this at the moment. I have set up a OpenVPN
server to serve as a vpn-gateway to my network
In the config i've defined a client-connect and a client-disconnect script.
When a client connects the client-connect script is run. When that client
disconnects the client-disconnect script is run.
The connect-script works al the time. But the disconnect-script only works
once since the openvpn service is started. After that the log says it
failed exit status 1.
But the weird thing is the scripts are almost the same. One puts a record
in the openvpn.connect table of a Mysql-database the other puts a record
in the openvpn.disconnect table.

Does any of you have the same problem. I tested with openvpn-2.0_rc6 and
openvpn-2.0_rc13.

For your reference i'll put my config and scripts below:

server config:
++++++++++++++++++++
user openvpn
group openvpn
local 192.168.111.111
port 1194
proto udp
dev tap0
persist-tun
keepalive 10 60
comp-lzo
management 127.0.0.1 1195 /etc/openvpn/management.passwd
management-log-cache 1000
mode server
tls-server
ifconfig-pool 192.168.111.112 192.168.111.140 255.255.255.0
max-clients 20
client-connect /etc/openvpn/connect
client-disconnect /etc/openvpn/disconnect
push "dhcp-option DOMAIN mydom.tld"
push "dhcp-option DNS 192.168.111.100"
push "dhcp-option WINS 192.168.111.110"
push "route-gateway 192.168.111.101"
ca /etc/openvpn/cacert.pem
cert /etc/openvpn/OVPN-cert.pem
key /etc/openvpn/OVPN.key
crl-verify /etc/openvpn/crl.pem
tls-auth /etc/openvpn/ta.key 0
dh /etc/openvpn/dh1024.pem
verb 4
status /var/openvpn/openvpn.stat
status-version 1
daemon
++++++++++++++++++++
connect:
++++++++++++++++++++
#! /usr/bin/env python
import MySQLdb,posix,time;
now = time.time()
time = int(now)

# posix.environ['common_name']
# posix.environ['trusted_ip']
# posix.environ['ifconfig_pool_remote_ip']
# posix.environ['ifconfig_pool_netmask']
# posix.environ['local_port']
# posix.environ['trusted_port']

db=MySQLdb.connect(host="localhost",
user="ovpn",
passwd="ovpnpasswd",
db="openvpn")
c = db.cursor()

c.execute("INSERT INTO connect (time, common_name, remote_ip,
pool_remote_ip, pool_netmask, local_port, remote_port) VALUES (%s, %s, %s,
%s, %s, %s,
%s)",(tijd,posix.environ['common_name'],posix.environ['trusted_ip'],posix.environ['ifconfig_pool_remote_ip'],posix.environ['ifconfig_pool_netmask'],posix.environ['local_port'],posix.environ['trusted_port']))
++++++++++++++++++++
disconnect:
++++++++++++++++++++
#! /usr/bin/env python
import MySQLdb,posix,time;
now = time.time()
time = int(now)

# posix.environ['common_name']
# posix.environ['trusted_ip']
# posix.environ['ifconfig_pool_remote_ip']
# posix.environ['ifconfig_pool_netmask']
# posix.environ['local_port']
# posix.environ['trusted_port']
# posix.environ['bytes_sent']
# posix.environ['bytes_received']

db=MySQLdb.connect(host="localhost",
user="ovpn",
passwd="ovpnpasswd",
db="openvpn")
c = db.cursor()

c.execute("""INSERT INTO disconnect (tijd, common_name,
remote_ip, pool_remote_ip, pool_netmask,
local_port, remote_port, bytes_sent, bytes_received) VALUES (%s,
%s, %s,
%s, %s, %s, %s, %s, %s)""",(tijd,posix.environ['common_name'],
posix.environ['trusted_ip'],posix.environ['ifconfig_pool_remote_ip'],
posix.environ['ifconfig_pool_netmask'],
posix.environ['local_port'],posix.environ['trusted_port'],
posix.environ['bytes_sent'],posix.environ['bytes_received']))
++++++++++++++++++++
A piece of log:
++++++++++++++++++++
Feb 15 12:45:17 titan openvpn[10829]: John_Doe/111.133.111.117:1448
[John_Doe] Inactivity timeout (--ping-restart), restarting
Feb 15 12:45:17 titan openvpn[10829]: John_Doe/111.133.111.117:1448
SIGUSR1[soft,ping-restart] received, client-instance restarting
Feb 15 12:45:17 titan openvpn[10829]: client-disconnect command failed:
shell command exited with error status: 1
++++++++++++++++++++

I hope one of you can help me sort this out.

Cheers,

Patrick






____________________________________________
Openvpn-users mailing list
Openvpn-users@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/openvpn-users
Netscreen 204 配置实例:【上一篇】
Win2K SNMP安装,信息刺探以及安全策略:【下一篇】
【相关文章】
  • 利用openvpn+linux快速建立企业VPN
  • 利用openvpn建立桥接vpn
  • OpenVPN在Linux下的安装配置和使用
  • 【随机文章】
  • 新手留意 Visual C++的界面元素图解
  • 如何用Request对象获得机器的环境参数
  • 用百度搜索"asp.net",三条结果,全是广告
  • [改造] 自杀的程序
  • 网络流量分析(二)
  • 笔记本电脑奸商招数大搜查
  • 手把手教你如何建立自己的Linux系统(LFS速成手册)
  • 免费QQ会员,蓝钻,红钻申请攻略
  • 乱七八糟
  • 记忆封存....
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.