mirror of
https://github.com/os-mnemo/pan-globalprotect-okta
synced 2026-07-31 15:54:36 +02:00
Fix relative URLs.
This commit is contained in:
+9
-4
@@ -29,9 +29,11 @@ from lxml import etree
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
if sys.version_info >= (3,):
|
if sys.version_info >= (3,):
|
||||||
|
from urllib.parse import urljoin
|
||||||
text_type = str
|
text_type = str
|
||||||
binary_type = bytes
|
binary_type = bytes
|
||||||
else:
|
else:
|
||||||
|
from urlparse import urljoin
|
||||||
text_type = unicode
|
text_type = unicode
|
||||||
binary_type = str
|
binary_type = str
|
||||||
input = raw_input
|
input = raw_input
|
||||||
@@ -76,9 +78,11 @@ def parse_rjson(r):
|
|||||||
except:
|
except:
|
||||||
err('failed to parse json')
|
err('failed to parse json')
|
||||||
|
|
||||||
def parse_form(html):
|
def parse_form(html, current_url = None):
|
||||||
xform = html.find('.//form')
|
xform = html.find('.//form')
|
||||||
url = xform.attrib.get('action', '').strip()
|
url = xform.attrib.get('action', '').strip()
|
||||||
|
if not url.startswith('http'):
|
||||||
|
url = urljoin(current_url, url)
|
||||||
data = {}
|
data = {}
|
||||||
for xinput in html.findall('.//input'):
|
for xinput in html.findall('.//input'):
|
||||||
k = xinput.attrib.get('name', '').strip()
|
k = xinput.attrib.get('name', '').strip()
|
||||||
@@ -150,7 +154,7 @@ def mfa_priority(conf, ftype, fprovider):
|
|||||||
return priority
|
return priority
|
||||||
|
|
||||||
|
|
||||||
def get_redirect_url(conf, c):
|
def get_redirect_url(conf, c, current_url = None):
|
||||||
rx_base_url = re.search(r'var\s*baseUrl\s*=\s*\'([^\']+)\'', c)
|
rx_base_url = re.search(r'var\s*baseUrl\s*=\s*\'([^\']+)\'', c)
|
||||||
rx_from_uri = re.search(r'var\s*fromUri\s*=\s*\'([^\']+)\'', c)
|
rx_from_uri = re.search(r'var\s*fromUri\s*=\s*\'([^\']+)\'', c)
|
||||||
if not rx_from_uri:
|
if not rx_from_uri:
|
||||||
@@ -161,7 +165,8 @@ def get_redirect_url(conf, c):
|
|||||||
return from_uri
|
return from_uri
|
||||||
if not rx_base_url:
|
if not rx_base_url:
|
||||||
dbg(conf.get('debug'), 'not found', 'baseUri')
|
dbg(conf.get('debug'), 'not found', 'baseUri')
|
||||||
# TODO: add current url's base
|
if current_url:
|
||||||
|
return urljoin(current_url, from_uri)
|
||||||
return from_uri
|
return from_uri
|
||||||
base_url = to_b(rx_base_url.group(1)).decode('unicode_escape').strip()
|
base_url = to_b(rx_base_url.group(1)).decode('unicode_escape').strip()
|
||||||
return base_url + from_uri
|
return base_url + from_uri
|
||||||
@@ -209,7 +214,7 @@ def okta_saml(conf, s, saml_xml):
|
|||||||
log('okta saml request')
|
log('okta saml request')
|
||||||
url, data = parse_form(saml_xml)
|
url, data = parse_form(saml_xml)
|
||||||
h, c = send_req(conf, s, 'saml', url, data)
|
h, c = send_req(conf, s, 'saml', url, data)
|
||||||
redirect_url = get_redirect_url(conf, c)
|
redirect_url = get_redirect_url(conf, c, url)
|
||||||
if redirect_url is None:
|
if redirect_url is None:
|
||||||
err('did not find redirect url')
|
err('did not find redirect url')
|
||||||
return redirect_url
|
return redirect_url
|
||||||
|
|||||||
Reference in New Issue
Block a user