From 1df901118d3f9d8ce3b1bca66a9cc0aa3ac5ec93 Mon Sep 17 00:00:00 2001 From: Andris Raugulis Date: Mon, 3 Sep 2018 13:40:29 +0300 Subject: [PATCH] Add gateway support. Add workaround for newline bug in openconnect. --- gp-okta.conf | 2 ++ gp-okta.py | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gp-okta.conf b/gp-okta.conf index 3ce534d..0695929 100644 --- a/gp-okta.conf +++ b/gp-okta.conf @@ -5,3 +5,5 @@ username = myuser password = mypass totp.okta = ABCDEFGHIJKLMNOP totp.google = ABCDEFGHIJKLMNOP +gateway = Manual ny1-gw.example.com +bug.nl = 0 diff --git a/gp-okta.py b/gp-okta.py index f12ad4b..adc8387 100755 --- a/gp-okta.py +++ b/gp-okta.py @@ -88,7 +88,7 @@ def load_conf(cf): with io.open(cf, 'r', encoding='utf-8') as fp: for rline in fp: line = rline.strip() - mx = re.match('^\s*([^=\s]+)\s*=\s*([^\s]+)', line) + mx = re.match('^\s*([^=\s]+)\s*=\s*(.*?)\s*$', line) if mx: k, v = mx.group(1).lower(), mx.group(2) for q in '"\'': @@ -326,8 +326,18 @@ def main(): userauthcookie = paloalto_getconfig(conf, s, saml_username, prelogin_cookie) log('portal-userauthcookie: {0}'.format(userauthcookie)) - cmd = '\necho "{1}" | openconnect --protocol=gp -u "{0}" --usergroup portal:portal-userauthcookie --passwd-on-stdin {2}' - print(cmd.format(saml_username, userauthcookie, conf.get('vpn_url'))) + cmd = 'openconnect --protocol=gp -u "{0}"' + cmd += ' --usergroup portal:portal-userauthcookie' + cmd += ' --passwd-on-stdin "{2}"' + gateway = (conf.get('gateway') or '').strip() + args = [saml_username, userauthcookie, conf.get('vpn_url')] + nlbug = '\\n' if conf.get('bug.nl', '').lower() in ['1', 'true'] else '' + if len(gateway) > 0: + cmd = '\nprintf "' + nlbug + '{1}\\n{3}" | ' + cmd + args.append(gateway) + else: + cmd = '\nprintf "' + nlbug + '{1}" | ' + cmd + print(cmd.format(*args)) if __name__ == '__main__':