From 246ea3a8d31d487f9adad7db97891a2bdd28affa Mon Sep 17 00:00:00 2001 From: Andris Raugulis Date: Mon, 25 May 2020 22:40:02 +0000 Subject: [PATCH] Pass gateway in command-line, not in stdin. --- gp-okta.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/gp-okta.py b/gp-okta.py index 8b8559c..c1c10c3 100755 --- a/gp-okta.py +++ b/gp-okta.py @@ -934,6 +934,8 @@ def main(): cmd = conf.openconnect_cmd or 'openconnect' cmd += ' --protocol=gp -u \'{0}\'' + if gateway_name: + cmd += ' --authgroup=\'{0}\''.format(gateway_name) cmd += ' --usergroup {1}' if conf.vpn_cli_cert: cmd += ' --certificate=\'{0}\''.format(conf.vpn_cli_cert) @@ -945,23 +947,10 @@ def main(): pfmt = conf.openconnect_fmt if not pfmt: - pfmt = '' - openconnect_bin = (conf.openconnect_cmd or 'openconnect').split()[-1:][0] - openconnect_bin = os.path.expandvars(os.path.expanduser(openconnect_bin)) - with open(os.devnull, 'wb') as fnull: - p = subprocess.Popen(['command', '-v', openconnect_bin], stdin=subprocess.PIPE, stdout=fnull, stderr=subprocess.STDOUT) - _ = p.communicate()[0] - if p.returncode == 0: - p = subprocess.Popen([openconnect_bin, '-V'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - o = p.communicate()[0] - mx = re.search(r'OpenConnect version v(\d)\.(\d+)', to_u(o), flags=re.IGNORECASE) - if mx: - vmajor, vminor = mx.groups() - if vmajor >= '8' and vminor >= '05': - pfmt = '' + pfmt = '' rmnl = pfmt.endswith('>') pfmt = pfmt.replace('', cookie + '\\n') - pfmt = pfmt.replace('', gateway_name + '\\n' if len(gateway_name) > 0 else '') + pfmt = pfmt.replace('', gateway_name + '\\n' if len(gateway_name) > 0 else '') for k in ['username', 'password', 'gateway_url']: v = conf.get_value(k).strip() pfmt = pfmt.replace('<{0}>'.format(k), v + '\\n' if len(v) > 0 else '')