diff options
-rw-r--r-- | src/leap/base/config.py | 180 | ||||
-rw-r--r-- | src/leap/eip/config.py | 31 |
2 files changed, 118 insertions, 93 deletions
diff --git a/src/leap/base/config.py b/src/leap/base/config.py index eb9bf88a..a468a849 100644 --- a/src/leap/base/config.py +++ b/src/leap/base/config.py @@ -278,55 +278,55 @@ def get_groupname(): # json stuff # XXX merge with JSONConfig / EIPChecks as appropiate. -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: +#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: #TODO: NOT SURE WHAT this default should be, if anything - 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() - try: - return json.load(open(fpath)) - except ValueError: - raise exceptions.MissingConfigFileError - - else: + #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() + #try: + #return json.load(open(fpath)) + #except ValueError: + #raise exceptions.MissingConfigFileError +# + #else: #TODO: add validity checks of file - try: - return json.load(open(config_file)) - except IOError: - raise exceptions.MissingConfigFileError - - -def get_definition_file(url=None): - """ - """ + #try: + #return json.load(open(config_file)) + #except IOError: + #raise exceptions.MissingConfigFileError +# +# +#def get_definition_file(url=None): + #""" + #""" #TODO: determine good default location of definition file. - r = requests.get(url) - return r.json - - -def is_internet_up(): - """TODO: Build more robust network diagnosis capabilities - """ - try: - requests.get('http://128.30.52.45', timeout=1) - return True - except requests.Timeout: # as err: - pass - return False - + #r = requests.get(url) + #return r.json +# +# +#def is_internet_up(): + #"""TODO: Build more robust network diagnosis capabilities + #""" + #try: + #requests.get('http://128.30.52.45', timeout=1) + #return True + #except requests.Timeout: # as err: + #pass + #return False +# # XXX DEPRECATE. # move to eip.checks # @@ -335,49 +335,49 @@ def is_internet_up(): # moving it here transiently until I clean merge commit. # -- kali 2012-08-24 00:32 # - - -class Configuration(object): - """ - All configurations (providers et al) will be managed in this class. - """ - def __init__(self, provider_url=None): - try: +# +# +#class Configuration(object): + #""" + #All configurations (providers et al) will be managed in this class. + #""" + #def __init__(self, provider_url=None): + #try: #requests.get('foo') - self.providers = {} - self.error = False - provider_file = self.check_and_get_definition_file(provider_url) - self.providers['default'] = get_config_json(provider_file) - except (requests.HTTPError, requests.RequestException) as e: - self.error = e.message - except requests.ConnectionError as e: - if e.message == "[Errno 113] No route to host": - if not is_internet_up: + #self.providers = {} + #self.error = False + #provider_file = self.check_and_get_definition_file(provider_url) + #self.providers['default'] = get_config_json(provider_file) + #except (requests.HTTPError, requests.RequestException) as e: + #self.error = e.message + #except requests.ConnectionError as e: + #if e.message == "[Errno 113] No route to host": + #if not is_internet_up: # this was meant to be a function invocation I guess... - self.error = "No valid internet connection found" - else: - self.error = "Provider server appears currently down." - - def check_and_get_definition_file(self, provider_url): - """ - checks if provider definition.json file is present. - if not downloads one from the web. - """ - default_provider_path = get_default_provider_path() - - if not os.path.isdir(default_provider_path): - mkdir_p(default_provider_path) - - definition_file = get_config_file( - 'definition.json', - folder=default_provider_path) - - if os.path.isfile(definition_file): - return - - else: - r = requests.get(provider_url) - r.raise_for_status() - with open(definition_file, 'wb') as f: - f.write(json.dumps(r.json, indent=4)) - return definition_file + #self.error = "No valid internet connection found" + #else: + #self.error = "Provider server appears currently down." +# + #def check_and_get_definition_file(self, provider_url): + #""" + #checks if provider definition.json file is present. + #if not downloads one from the web. + #""" + #default_provider_path = get_default_provider_path() +# + #if not os.path.isdir(default_provider_path): + #mkdir_p(default_provider_path) +# + #definition_file = get_config_file( + #'definition.json', + #folder=default_provider_path) +# + #if os.path.isfile(definition_file): + #return +# + #else: + #r = requests.get(provider_url) + #r.raise_for_status() + #with open(definition_file, 'wb') as f: + #f.write(json.dumps(r.json, indent=4)) + #return definition_file diff --git a/src/leap/eip/config.py b/src/leap/eip/config.py index c3e830dd..e5fcd164 100644 --- a/src/leap/eip/config.py +++ b/src/leap/eip/config.py @@ -21,7 +21,11 @@ class EIPConfig(baseconfig.JSONLeapConfig): spec = eipspecs.eipconfig_spec def _get_slug(self): - return baseconfig.get_config_file('eip.json') + dppath = baseconfig.get_default_provider_path() + eipjsonpath = baseconfig.get_config_file( + 'eip-service.json', + folder=dppath) + return eipjsonpath def _set_slug(self, *args, **kwargs): raise AttributeError("you cannot set slug") @@ -51,6 +55,25 @@ def get_socket_path(): return socket_path +def get_eip_gateway(): + """ + return the first host in the list of hosts + under gateways list + """ + eipconfig = EIPConfig() + eipconfig.load() + conf = eipconfig.get_config() + gateways = conf.get('gateways', None) + if len(gateways) > 0: + # we just pick first + gw = gateways[0] + hosts = gw['hosts'] + if len(hosts) > 0: + return hosts[0] + else: + return "testprovider.example.org" + + def build_ovpn_options(daemon=False, socket_path=None, **kwargs): """ build a list of options @@ -87,9 +110,10 @@ def build_ovpn_options(daemon=False, socket_path=None, **kwargs): opts.append("%s" % verbosity) # remote - # XXX get remote from eip.json opts.append('--remote') - opts.append('testprovider.example.org') + gw = get_eip_gateway() + logger.debug('setting eip gateway to %s', gw) + opts.append(str(gw)) opts.append('1194') opts.append('udp') @@ -140,6 +164,7 @@ def build_ovpn_options(daemon=False, socket_path=None, **kwargs): #if daemon is True: #opts.append('--daemon') + logger.debug('vpn options: %s', opts) return opts |