From bd18f14137c18509923d6c274f0fa24ce953faa0 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Mon, 22 Aug 2022 06:19:39 -0700 Subject: [PATCH] checkconnection cleanup (#1552) --- src/GamCommands.txt | 1 + src/gam/__init__.py | 27 +++++++++++---------------- src/setup.cfg | 2 +- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/GamCommands.txt b/src/GamCommands.txt index b7508d8a..e7da854b 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -872,6 +872,7 @@ Specify a collection of Users by directly specifying them or by specifying items | +gam checkconnection gam version [check|checkrc|simple|extended] [timeoffset] [location ] gam help diff --git a/src/gam/__init__.py b/src/gam/__init__.py index 3f68b45d..0bae4e41 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -723,7 +723,7 @@ def doGAMCheckForUpdates(forceCheck=False): httplib2.ServerNotFoundError, RuntimeError, ConnectionError, - socket.timeout): + TimeoutError): return @@ -776,36 +776,31 @@ def checkConnection(): for host in hosts: host = fix_hosts.get(host, host) check_line = f'Checking {host}...' - sys.stdout.write(f'{check_line:<70}') + sys.stdout.write(f'{check_line:<50}') sys.stdout.flush() gen_firewall = 'You probably have security software or a firewall on your machine or network that is preventing GAM from making Internet connections. Check your network configuration or try running GAM on a hotspot or home network to see if the problem exists only on your organization\'s network.' try: httpc.request(f'https://{host}/', 'HEAD') print(okay) except ConnectionRefusedError: - print(f'\n{not_okay} Connection refused. {gen_firewall}') + print(f'{not_okay}\n Connection refused. {gen_firewall}') except ConnectionResetError: - print(f'\n{not_okay} Connection reset by peer. {gen_firewall}') + print(f'{not_okay}\n Connection reset by peer. {gen_firewall}') except httplib2.error.ServerNotFoundError: - print(f'\n{not_okay} Failed to find server. Your DNS is probably misconfigured.') + print(f'{not_okay}\n Failed to find server. Your DNS is probably misconfigured.') except ssl.SSLError as e: if e.reason == 'SSLV3_ALERT_HANDSHAKE_FAILURE': - print(f'\n{not_okay} GAM expects to connect with TLS 1.3 or newer and that failed. If you\'re proxy / firewall is not compatible with TLS 1.3 then you can tell GAM to allow TLS 1.2 by setting GAM_TLS_MIN_VERSION=TLSv1_2 as an environment variable.') + print(f'{not_okay}\n GAM expects to connect with TLS 1.3 or newer and that failed. If your firewall / proxy server is not compatible with TLS 1.3 then you can tell GAM to allow TLS 1.2 by setting the GAM_TLS_MIN_VERSION=TLSv1_2 environment variable.') elif e.reason == 'CERTIFICATE_VERIFY_FAILED': - print(f'\n{not_okay} Certificate verification failed. If you are behind a firewall / proxy server that does TLS / SSL inspection you may need to point GAM at your certificate authority file by setting the GAM_CA_FILE=/path/to/your/certauth.pem environment variable.') + print(f'{not_okay}\n Certificate verification failed. If you are behind a firewall / proxy server that does TLS / SSL inspection you may need to point GAM at your certificate authority file by setting the GAM_CA_FILE=/path/to/your/certauth.pem environment variable.') elif e.strerror.startswith('TLS/SSL connection has been closed'): - print(f'\n{not_okay} TLS connection was closed. {gen_firewall}') + print(f'{not_okay}\n TLS connection was closed. {gen_firewall}') else: - print(e) - print(e.strerror) - print(dir(e)) - print(f'\n{not_okay} {e.reason}') + print(f'{not_okay}\n {e.reason}: {str(e)}') except TimeoutError: - print('\n{not_okay} timed out trying to connect to host') + print(f'{not_okay}\n Timed out trying to connect to host') except Exception as e: - print('Generic catchall exception...') - print(type(e)) - print(e) + print(f'{not_okay}\n {str(e)}') def doGAMVersion(checkForArgs=True): force_check = extended = simple = timeOffset = False diff --git a/src/setup.cfg b/src/setup.cfg index b77be5db..7669078e 100644 --- a/src/setup.cfg +++ b/src/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = GAM for Google Workspace -version = 6.0.22 +version = 6.0.23 description = Command line management for Google Workspaces long_description = file: readme.md long_description_content_type = text/markdown