|
@@ -3,6 +3,7 @@ import os
|
3
|
3
|
import os.path
|
4
|
4
|
import re
|
5
|
5
|
import shutil
|
|
6
|
+from subprocess import call
|
6
|
7
|
|
7
|
8
|
|
8
|
9
|
class VpnGenError(Enum):
|
|
@@ -19,9 +20,9 @@ class VpnGen:
|
19
|
20
|
ovpn_config_path = ""
|
20
|
21
|
|
21
|
22
|
def __init__(self, default_config_path, ovpn_config_path):
|
22
|
|
- self.default_config_base_dir = default_config_path
|
23
|
|
- self.default_config_file = "%s.conf" % default_config_path
|
24
|
|
- self.ovpn_config_path = ovpn_config_path
|
|
23
|
+ self.default_config_base_dir = os.path.abspath(default_config_path)
|
|
24
|
+ self.default_config_file = "%s.conf" % self.default_config_base_dir
|
|
25
|
+ self.ovpn_config_path = os.path.abspath(ovpn_config_path)
|
25
|
26
|
|
26
|
27
|
def f7(self, seq):
|
27
|
28
|
seen = set()
|
|
@@ -60,12 +61,49 @@ class VpnGen:
|
60
|
61
|
os.rmdir(base_dir)
|
61
|
62
|
shutil.copytree(self.default_config_base_dir, base_dir)
|
62
|
63
|
|
63
|
|
-
|
|
64
|
+ curdir = os.curdir
|
|
65
|
+ easyrsadir = base_dir + os.sep + "easy-rsa" + os.sep
|
|
66
|
+ pkitool = easyrsadir + "pkitool"
|
|
67
|
+ os.chdir(easyrsadir)
|
|
68
|
+
|
|
69
|
+ os.environ["KEY_COUNTRY"] = variables['KEY_COUNTRY']
|
|
70
|
+ os.environ["KEY_PROVINCE"] = variables['KEY_PROVINCE']
|
|
71
|
+ os.environ["KEY_CITY"] = variables['KEY_CITY']
|
|
72
|
+ os.environ["KEY_ORG"] = variables['KEY_ORG']
|
|
73
|
+ os.environ["KEY_OU"] = variables['KEY_ORG']
|
|
74
|
+ os.environ["KEY_CN"] = variables['KEY_ORG']
|
|
75
|
+ os.environ["KEY_NAME"] = variables['KEY_ORG']
|
|
76
|
+ os.environ["KEY_EMAIL"] = variables['KEY_EMAIL']
|
|
77
|
+ os.environ["KEY_SIZE"] = variables['KEY_SIZE']
|
|
78
|
+ os.environ["CA_EXPIRE"] = variables['CA_EXPIRE']
|
|
79
|
+ os.environ["KEY_EXPIRE"] = variables['KEY_EXPIRE']
|
|
80
|
+
|
|
81
|
+ os.environ["EASY_RSA"] = easyrsadir
|
|
82
|
+ os.environ["OPENSSL"] = "openssl"
|
|
83
|
+ os.environ["PKCS11TOOL"] = "pkcs11-tool"
|
|
84
|
+ os.environ["GREP"] = "grep"
|
|
85
|
+ os.environ["KEY_CONFIG"] = easyrsadir + "openssl.cnf"
|
|
86
|
+ os.environ["KEY_DIR"] = easyrsadir + "keys"
|
|
87
|
+ os.environ["PKCS11_MODULE_PATH"] = "dummy"
|
|
88
|
+ os.environ["PKCS11_PIN"] = "dummy"
|
|
89
|
+
|
|
90
|
+ call(["./clean-all"])
|
|
91
|
+ call([pkitool, "--initca"])
|
|
92
|
+ call([pkitool, "server"])
|
|
93
|
+ call(["./build-dh"])
|
|
94
|
+
|
|
95
|
+ os.chdir(curdir)
|
64
|
96
|
|
65
|
97
|
return VpnGenError.Success
|
66
|
98
|
|
67
|
99
|
def remove_vpn(self, vpn_name):
|
68
|
|
- return VpnGenError.ClientDoesNotExists
|
|
100
|
+ base_dir = "%s%s%s" % (self.ovpn_config_path, os.sep, vpn_name)
|
|
101
|
+ conf_file = "%s.conf" % base_dir
|
|
102
|
+ if not os.path.exists(base_dir) and not os.path.exists(conf_file):
|
|
103
|
+ return VpnGenError.VpnDoesNotExists
|
|
104
|
+ os.remove(conf_file)
|
|
105
|
+ shutil.rmtree(base_dir)
|
|
106
|
+ return VpnGenError.Success
|
69
|
107
|
|
70
|
108
|
def create_client(self, vpn_name, client_name, variables):
|
71
|
109
|
return VpnGenError.ClientDoesNotExists
|