Skip to content

Commit 08110b4

Browse files
ikev2 button is not shown if ipsec command is not found
1 parent b0164ab commit 08110b4

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

bin/gui.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ def __init_protocol__(self):
6565
self.protocolFrame.udp = Radiobutton(self.protocolFrame, text="UDP", variable=self.connectionProtocol, value=0,
6666
selectcolor=self.background_color)
6767
self.protocolFrame.udp.pack(side=LEFT)
68-
self.protocolFrame.ikev2 = Radiobutton(self.protocolFrame, text='Ikev2/IPsec', variable=self.connectionProtocol,
69-
value=2, selectcolor=self.background_color)
70-
self.protocolFrame.ikev2.pack(side=LEFT)
68+
if(IPSEC_EXISTS):
69+
self.protocolFrame.ikev2 = Radiobutton(self.protocolFrame, text='Ikev2/IPsec', variable=self.connectionProtocol,
70+
value=2, selectcolor=self.background_color)
71+
self.protocolFrame.ikev2.pack(side=LEFT)
7172
self.connectionProtocol.set(1)
7273

7374
self.protocolFrame.pack(pady=4)

bin/vpn_util/ikev2.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939

4040
logger = get_logger(__name__)
4141

42+
def ipsec_exists():
43+
"""
44+
Verifies if ipsec is existing in the os
45+
:return: a boolean: True if ipsec exists, false otherwise
46+
"""
47+
(_, err) = Popen(["sudo", "ipsec", "--version"], stdout=PIPE, stderr=PIPE).communicate()
48+
if "not found" in err:
49+
return False
50+
51+
return True
52+
4253

4354
def __ikev2_save_credentials__(username, password):
4455
"""
@@ -143,7 +154,7 @@ def ikev2_is_running():
143154
"""
144155

145156
args = ['sudo', 'ipsec', 'status']
146-
ipsec_stop_command = Popen(args, stdout=PIPE, universal_newlines=True)
157+
ipsec_stop_command = Popen(args, stdout=PIPE, stderr=PIPE, universal_newlines=True)
147158
(out, _) = ipsec_stop_command.communicate()
148159

149160
if 'ESTABLISHED' in out:
@@ -158,7 +169,7 @@ def __ikev2_ipsec_reload__():
158169
restarts ipsec (used to load saved settings)
159170
"""
160171
args = ['sudo', 'ipsec', 'reload']
161-
(out, _) = Popen(args, stdout=PIPE).communicate()
172+
(out, _) = Popen(args, stdout=PIPE, universal_newlines=True).communicate()
162173

163174
if 'not running' in out:
164175
Popen(['sudo', 'ipsec', 'start']).communicate()

bin/vpn_util/vpn.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from bin.vpn_util.ikev2 import ikev2_connect, ikev2_is_running, ikev2_disconnect
1+
from bin.vpn_util.ikev2 import ikev2_connect, ikev2_is_running, ikev2_disconnect, ipsec_exists
22
from bin.vpn_util.openvpn import *
3+
IPSEC_EXISTS = ipsec_exists()
34

45

56
def startVPN(server, protocol):

0 commit comments

Comments
 (0)