- print(''' test-globalprotect-login.py --user={} -p '' \\\n https://{}{} {}={}\n'''.format(
- quote(un), quote(server), quote(if2auth[ifh]), quote(cn), quote(cv)), file=stderr)
-
- varvals = {
- 'HOST': quote('https://%s/%s:%s' % (server, if2auth[ifh], cn)),
- 'USER': quote(un), 'COOKIE': quote(cv),
- }
- print('\n'.join('%s=%s' % pair for pair in varvals.items()))
+ print(''' test-globalprotect-login.py --user={} --clientos={} -p '' \\\n https://{}/{} {}={}\n'''.format(
+ quote(un), quote(args.clientos), quote(server), quote(if2auth[args.interface]), quote(cn), quote(cv)), file=stderr)
+
+ if args.exec:
+ print('''Launching OpenConnect with {}, equivalent to:\n{}'''.format(args.exec, openconnect_command), file=stderr)
+ with tempfile.TemporaryFile('w+') as tf:
+ tf.write(cv)
+ tf.flush()
+ tf.seek(0)
+ # redirect stdin from this file, before it is closed by the context manager
+ # (it will remain accessible via the open file descriptor)
+ dup2(tf.fileno(), 0)
+ if args.exec == 'pkexec':
+ cmd = ["pkexec", "--user", "root", "openconnect"] + openconnect_args
+ elif args.exec == 'sudo':
+ cmd = ["sudo", "openconnect"] + openconnect_args
+ execvp(cmd[0], cmd)
+
+ else:
+ varvals = {
+ 'HOST': quote('https://%s/%s' % (server, urlpath)),
+ 'USER': quote(un), 'COOKIE': quote(cv), 'OS': quote(args.ocos),
+ }
+ print('\n'.join('%s=%s' % pair for pair in varvals.items()))
+
+if __name__ == "__main__":
+ main()