+# if it's a portal config response, pass along to gateway
+
+elif xml is not None and xml.tag == 'policy':
+
+ uemail = xml.find('user-email')
+ if uemail: uemail = uemail.text
+ cookies = [(cn, xml.find(cn).text) for cn in ('portal-prelogonuserauthcookie', 'portal-userauthcookie')]
+ gateways = [(e.find('description').text, e.get('name')) for e in set(chain(xml.findall('gateways/external/list/entry'), xml.findall('gateways6/external/list/entry')))]
+
+ print('''\nPortal config response response converted to new test-globalprotect-login.py invocation for gateway login:\n'''
+ ''' test-globalprotect-login.py --user={} --clientos={} -p {} {}\\\n'''
+ ''' https://{}/ssl-vpn/login.esp \\\n'''
+ ''' {}\n'''.format(
+ quote(args.user), quote(args.clientos), quote(args.password), cert_and_key, quote(gateways[0][1]),
+ ' '.join(cn+'='+quote(cv) for cn, cv in cookies),
+ file=stderr))
+
+ if uemail and uemail != args.user:
+ print('''IMPORTANT: Portal config contained different username. You might need to try\n'''
+ '''{} instead.\n'''.format(uemail))
+ if len(gateways)>1:
+ print('''Received multiple gateways. Options include:\n {}\n'''.format('\n '.join('%s => %s' % (desc, host) for desc, host in gateways)))
+