Skip to content

Commit

Permalink
Add client conf file auto package while dial vpn proto settings changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
r4ntix committed Oct 10, 2014
1 parent 0163a31 commit 6c09f20
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions scripts/packconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ cd "$static_dir" 2>/dev/null || {
exit 1
} >&2

sed -e 's/$/\r/' /usr/local/flexgw/rc/openvpn-client.conf > /usr/local/flexgw/rc/openvpn-client.ovpn

command="$1"
case "$command" in
"" | "-h" | "--help" )
Expand Down
17 changes: 14 additions & 3 deletions website/vpn/dial/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
class VpnConfig(object):
''' read and set config for vpn config file.'''
conf_file = '/etc/openvpn/server.conf'
client_conf_file = '/usr/local/flexgw/rc/openvpn-client.conf'

conf_template = 'dial/server.conf'
client_conf_template = 'dial/client.conf'

def __init__(self, conf_file=None):
if conf_file:
Expand All @@ -46,11 +48,14 @@ def _commit_conf_file(self):
subnets = ["%s %s" % (i.split('/')[0].strip(),
exchange_maskint(int(i.split('/')[1].strip())))
for i in r_subnet.split(',')]
data = render_template(self.conf_template, ipool=ipool, subnets=subnets,
c2c=c2c, duplicate=duplicate, proto=proto)
server_data = render_template(self.conf_template, ipool=ipool, subnets=subnets,
c2c=c2c, duplicate=duplicate, proto=proto)
client_data = render_template(self.client_conf_template, proto=proto)
try:
with open(self.conf_file, 'w') as f:
f.write(data)
f.write(server_data)
with open(self.client_conf_file, 'w') as f:
f.write(client_data)
except:
return False
return True
Expand Down Expand Up @@ -135,6 +140,11 @@ def _reload_conf(self):
message = u"VPN 服务重载失败!%s"
return self._exec(cmd, message)

def _package_client_conf(self):
cmd = ['/usr/local/flexgw/scripts/packconfig', 'all']
message = u"客户端配置文件打包失败!"
return self._exec(cmd, message)

@property
def start(self):
if self.status:
Expand All @@ -160,6 +170,7 @@ def reload(self):
message = u'VPN 服务配置文件修改失败,请重试!'
flash(message, 'alert')
return False
self._package_client_conf()
if not self.status:
flash(u'设置成功!VPN 服务未启动,请通过「VPN服务管理」启动VPN 服务。', 'alert')
return False
Expand Down
21 changes: 21 additions & 0 deletions website/vpn/dial/templates/dial/client.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
client
dev tun
{% if proto == 'tcp' %}
proto tcp
{% else %}
proto udp
{% endif %}

# please replace EIP to your real eip address.
remote EIP 1194

resolv-retry infinite
pull
nobind
persist-key
persist-tun
comp-lzo
verb 3
ca ca.crt
cipher AES-128-CBC
auth-user-pass

0 comments on commit 6c09f20

Please sign in to comment.