summaryrefslogtreecommitdiff
path: root/src/leap/eip/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/eip/config.py')
-rw-r--r--src/leap/eip/config.py76
1 files changed, 55 insertions, 21 deletions
diff --git a/src/leap/eip/config.py b/src/leap/eip/config.py
index 8e55d789..f38268e2 100644
--- a/src/leap/eip/config.py
+++ b/src/leap/eip/config.py
@@ -2,6 +2,7 @@ import ConfigParser
import grp
import logging
import os
+import json
import platform
import socket
@@ -14,11 +15,6 @@ from leap.eip import exceptions as eip_exceptions
logger = logging.getLogger(name=__name__)
logger.setLevel('DEBUG')
-# XXX this has to be REMOVED
-# and all these options passed in the
-# command line --> move to build_ovpn_command
-# issue #447
-
OPENVPN_CONFIG_TEMPLATE = """#Autogenerated by eip-client wizard
remote {VPN_REMOTE_HOST} {VPN_REMOTE_PORT}
@@ -114,16 +110,20 @@ def check_or_create_default_vpnconf(config):
# instead.
try:
+ # XXX by now, we're expecting
+ # only IP format for remote.
+ # We should allow also domain names,
+ # and make a reverse resolv.
remote_ip = config.get('provider',
'remote_ip')
validate_ip(remote_ip)
- except ConfigParser.NoOptionError:
- raise EIPInitNoProviderError
+ except ConfigParser.NoSectionError:
+ raise eip_exceptions.EIPInitNoProviderError
except socket.error:
# this does not look like an ip, dave
- raise EIPInitBadProviderError
+ raise eip_exceptions.EIPInitBadProviderError
if config.has_option('provider', 'remote_port'):
remote_port = config.get('provider',
@@ -158,6 +158,15 @@ def check_or_create_default_vpnconf(config):
f.write(ovpn_config)
+def get_username():
+ return os.getlogin()
+
+
+def get_groupname():
+ gid = os.getgroups()[-1]
+ return grp.getgrgid(gid).gr_name
+
+
def build_ovpn_options(daemon=False):
"""
build a list of options
@@ -175,16 +184,11 @@ def build_ovpn_options(daemon=False):
# get user/group name
# also from config.
- user = os.getlogin()
- gid = os.getgroups()[-1]
- group = grp.getgrgid(gid).gr_name
+ user = get_username()
+ group = get_groupname()
opts = []
- #moved to config files
- #opts.append('--persist-tun')
- #opts.append('--persist-key')
-
# set user and group
opts.append('--user')
opts.append('%s' % user)
@@ -219,6 +223,8 @@ def build_ovpn_options(daemon=False):
opts.append('--config')
default_provider_path = get_default_provider_path()
+
+ # XXX get rid of config_file at all
ovpncnf = get_config_file(
'openvpn.conf',
folder=default_provider_path)
@@ -233,7 +239,7 @@ def build_ovpn_options(daemon=False):
return opts
-def build_ovpn_command(config, debug=False):
+def build_ovpn_command(config, debug=False, do_pkexec_check=True):
"""
build a string with the
complete openvpn invocation
@@ -251,12 +257,11 @@ def build_ovpn_command(config, debug=False):
if config.has_option('openvpn', 'use_pkexec'):
use_pkexec = config.get('openvpn', 'use_pkexec')
- if platform.system() == "Linux" and use_pkexec:
+ if platform.system() == "Linux" and use_pkexec and do_pkexec_check:
# XXX check for both pkexec (done)
# AND a suitable authentication
# agent running.
- # (until we implement setuid helper)
logger.info('use_pkexec set to True')
if not is_pkexec_in_system():
@@ -283,7 +288,11 @@ def build_ovpn_command(config, debug=False):
'openvpn_binary')
if ovpn:
- command.append(ovpn)
+ vpn_command = ovpn
+ else:
+ vpn_command = "openvpn"
+
+ command.append(vpn_command)
daemon_mode = not debug
@@ -291,6 +300,7 @@ def build_ovpn_command(config, debug=False):
command.append(opt)
# XXX check len and raise proper error
+
return [command[0], command[1:]]
@@ -394,11 +404,35 @@ def check_vpn_keys(config):
if not os.path.isfile(keyfile):
logger.error('key file %s not found. aborting.',
keyfile)
- raise EIPInitNoKeyFileError
+ raise eip_exceptions.EIPInitNoKeyFileError
# check proper permission on keys
# bad perms? try to fix them
try:
check_and_fix_urw_only(keyfile)
except OSError:
- raise EIPInitBadKeyFilePermError
+ raise eip_exceptions.EIPInitBadKeyFilePermError
+
+
+def get_config_json(config_file=None):
+ """
+ will replace get_config function be developing them
+ in parralel for branch purposes.
+ @param: configuration file
+ @type: file
+ @rparam: configuration turples
+ @rtype: dictionary
+ """
+ if not config_file:
+ fpath = get_config_file('eip.json')
+ if not os.path.isfile(fpath):
+ dpath, cfile = os.path.split(fpath)
+ if not os.path.isdir(dpath):
+ mkdir_p(dpath)
+ with open(fpath, 'wb') as configfile:
+ configfile.flush()
+ config_file = open(fpath)
+
+ config = json.load(config_file)
+
+ return config