def has_ipv6_access(smt): """IPv6 access is possible if we have an SMT server that has an IPv6 address and it can be accessed over IPv6""" if not smt.get_ipv6(): return False logging.info('Attempt to access update server over IPv6') try: # Per rfc3986 IPv6 addresses in a URI are enclosed in [] cert_res = requests.get('http://[%s]/smt.crt' % smt.get_ipv6(), timeout=3) except Exception: logging.info('Update server not reachable over IPv6') return False if cert_res and cert_res.status_code == 200: return True
def get_current_smt(): """Return the data for the current SMT server. The current SMT server is the server aginst which this client is registered.""" smt = get_smt_from_store(__get_registered_smt_file_path()) if not smt: return # Verify that this system is also in /etc/hosts and we are in # a consistent state # Handle entries as bytes, # Yes users put non ascii characters into /etc/hosts smt_ipv4 = smt.get_ipv4() smt_ipv6 = smt.get_ipv6() smt_fqdn = smt.get_FQDN() # A bit cumbersome to support Python 3.4 ipv4_search = '%s\s' % smt_ipv4 ipv6_search = '%s\s' % smt_ipv6 fqdn_search = '\s%s\s' % smt_fqdn hosts = open(HOSTSFILE_PATH, 'rb').read() if (not (re.search(ipv4_search.encode(), hosts) or re.search(ipv6_search.encode(), hosts)) or not re.search(fqdn_search.encode(), hosts)): os.unlink(__get_registered_smt_file_path()) return if not check_registration(smt_fqdn): return return smt
def get_current_smt(): """Return the data for the current SMT server. The current SMT server is the server aginst which this client is registered.""" smt = get_smt_from_store(__get_registered_smt_file_path()) if not smt: return # Verify that this system is also in /etc/hosts and we are in # a consistent state smt_ipv4 = smt.get_ipv4() smt_ipv6 = smt.get_ipv6() smt_fqdn = smt.get_FQDN() hosts = open(HOSTSFILE_PATH, 'r').read() if ( not ( re.search(r'%s\s' % smt_ipv4, hosts) or re.search(r'%s\s' % smt_ipv6, hosts) ) or not re.search(r'\s%s\s' % smt_fqdn, hosts) ): os.unlink(__get_registered_smt_file_path()) return if not check_registration(smt_fqdn): return return smt
def has_ipv6_access(smt): """IPv6 access is possible if we have an SMT server that has an IPv6 address and it can be accessed over IPv6""" if not smt.get_ipv6(): return False logging.info('Attempt to access update server over IPv6') protocol = 'http' # Default for backward compatibility if https_only(get_config()): protocol = 'https' try: # Per rfc3986 IPv6 addresses in a URI are enclosed in [] cert_res = requests.get('%s://[%s]/smt.crt' % (protocol, smt.get_ipv6()), timeout=3, verify=False) except Exception: logging.info('Update server not reachable over IPv6') return False if cert_res and cert_res.status_code == 200: return True
def remove_registration_data(): """Reset the instance to an unregistered state""" smt_data_file = __get_registered_smt_file_path() if os.path.exists(smt_data_file): smt = get_smt_from_store(smt_data_file) smt_ips = (smt.get_ipv4(), smt.get_ipv6()) logging.info('Clean current registration server: %s' % str(smt_ips)) server_name = smt.get_FQDN() domain_name = smt.get_domain_name() clean_hosts_file(domain_name) __remove_credentials(server_name) __remove_repos(server_name) __remove_service(server_name) os.unlink(smt_data_file) if os.path.exists('/etc/SUSEConnect'): os.unlink('/etc/SUSEConnect') else: logging.info('No current registration server set.')