Hopefully get OpenVPN working
diff --git a/xos/observers/vpn/steps/sync_vpntenant.yaml b/xos/observers/vpn/steps/sync_vpntenant.yaml
index 82193d0..83e5216 100644
--- a/xos/observers/vpn/steps/sync_vpntenant.yaml
+++ b/xos/observers/vpn/steps/sync_vpntenant.yaml
@@ -4,15 +4,17 @@
connection: ssh
user: ubuntu
sudo: yes
+ vars:
+
tasks:
- - name: install apache
- apt: name=apache2 state=present update_cache=yes
+ - name: install openvpn
+ apt: name=openvpn state=present update_cache=yes
- - name: write message
- shell: echo "{{ server_key }}" > /var/www/html/index.html
+ - name: write key
+ shell: printf "{{ server_key }}" > /opt/xos/observers/vpn/static.key
- - name: stop apache
- service: name=apache2 state=stopped
+ - name: write config
+ shell: printf "dev tun\nifconfig 10.8.0.1 10.8.0.2\nsecret /opt/xos/observers/vpn/static.key\nkeepalive 10 60\nping-timer-rem\npersist-tun\npersist-key" > /opt/xos/observers/vpn/server.conf
- - name: start apache
- service: name=apache2 state=started
+ - name: start openvpn
+ shell: openvpn /opt/xos/observers/vpn/server.conf
diff --git a/xos/vpn/admin.py b/xos/vpn/admin.py
index 4010e0f..4640de2 100644
--- a/xos/vpn/admin.py
+++ b/xos/vpn/admin.py
@@ -4,6 +4,7 @@
from core.models import User
from django import forms
from django.contrib import admin
+from subprocess import Popen, PIPE
from vpn.models import VPNService, VPNTenant, VPN_KIND
class VPNServiceAdmin(ReadOnlyAwareAdmin):
@@ -45,8 +46,8 @@
def __init__(self, *args, **kwargs):
super(VPNTenantForm, self).__init__(*args, **kwargs)
self.fields['kind'].widget.attrs['readonly'] = True
- # Make the server_key read only
- self.fields['server_key'].widget.attrs['readonly'] = True
+ # Make the server_key disabled
+ self.fields['server_key'].widget.attrs['disabled'] = True
self.fields[
'provider_service'].queryset = VPNService.get_service_objects().all()
@@ -60,14 +61,20 @@
# If there is not an instance then we need to set initial values.
if (not self.instance) or (not self.instance.pk):
self.fields['creator'].initial = get_request().user
- self.fields['server_key'].initial = "hello world!"
+ self.fields['server_key'].initial = generate_VPN_Key()
if VPNService.get_service_objects().exists():
self.fields["provider_service"].initial = VPNService.get_service_objects().all()[0]
def save(self, commit=True):
self.instance.creator = self.cleaned_data.get("creator")
+ self.instance.servery_key = self.cleaned_data.get("sever_key")
return super(VPNTenantForm, self).save(commit=commit)
+ def generate_VPN_Key():
+ proc = Popen("openvpn --genkey --secret /dev/stdout", shell=True, stdout=PIPE)
+ (stdout, stderr) = proc.communicate()
+ return stdout
+
class Meta:
model = VPNTenant