|
30 | 30 | THE SOFTWARE. |
31 | 31 | """ |
32 | 32 | from __future__ import print_function |
33 | | -import argparse, base64, getpass, io, os, re, shlex, signal, subprocess, sys, tempfile, time, traceback |
| 33 | +import argparse, base64, getpass, io, os, re, shlex, signal, subprocess, sys, ssl, tempfile, time, traceback |
34 | 34 | import requests |
| 35 | +import requests.adapters |
35 | 36 | from lxml import etree |
36 | 37 |
|
37 | 38 | if sys.version_info >= (3,): |
@@ -153,8 +154,11 @@ def err(s): |
153 | 154 | print('[ERROR] {0}'.format(s), file=sys.stderr) |
154 | 155 | sys.exit(1) |
155 | 156 |
|
156 | | -def _remx(c, v): return re.search(r'\s*' + v + r'\s*"?[=:]\s*(?:"((?:[^"\\]|\\.)*)"|\'((?:[^\'\\]|\\.)*)\')', c) |
157 | | -_refx = lambda mx: to_b(mx.group(1)).decode('unicode_escape').strip() |
| 157 | +def _remx(c, v): |
| 158 | + return re.search(r'\s*' + v + r'\s*"?[=:]\s*(?:"((?:[^"\\]|\\.)*)"|\'((?:[^\'\\]|\\.)*)\')', c) |
| 159 | + |
| 160 | +def _refx(mx): |
| 161 | + return to_b(mx.group(1) or mx.group(2)).decode('unicode_escape').strip() |
158 | 162 |
|
159 | 163 | def parse_xml(xml): |
160 | 164 | # type: (str) -> etree._Element |
@@ -195,6 +199,14 @@ def parse_form(html, current_url=None): |
195 | 199 | data[k] = v |
196 | 200 | return url, data |
197 | 201 |
|
| 202 | +class InsecureHTTPAdapter(requests.adapters.HTTPAdapter): |
| 203 | + def __init__(self, *, ssl_context, **kwargs): |
| 204 | + self._ssl_context = ssl_context |
| 205 | + super().__init__(**kwargs) |
| 206 | + |
| 207 | + def init_poolmanager(self, connections, maxsize, **kwargs): |
| 208 | + super().init_poolmanager(connections, maxsize, **kwargs, ssl_context=self._ssl_context) |
| 209 | + |
198 | 210 | class Conf(object): |
199 | 211 | def __init__(self): |
200 | 212 | # type: () -> None |
@@ -327,6 +339,9 @@ def from_data(cls, content): |
327 | 339 | setattr(conf, k, conf._store[k].strip()) |
328 | 340 | conf.debug = conf._store.get('debug', '').lower() in ['1', 'true'] |
329 | 341 | s = requests.Session() |
| 342 | + ctx = ssl.create_default_context(ssl.Purpose.SERVER_AUTH) |
| 343 | + ctx.options |= 0x4 |
| 344 | + s.mount('https://', InsecureHTTPAdapter(ssl_context=ctx)) |
330 | 345 | s.headers['User-Agent'] = 'PAN GlobalProtect' |
331 | 346 | conf._session = s |
332 | 347 | return conf |
@@ -1103,6 +1118,7 @@ def run_openconnect(conf, do_portal_auth, urls, saml_username, cookies): |
1103 | 1118 | if conf.get_bool('execute'): |
1104 | 1119 | ecmd = [os.path.expandvars(os.path.expanduser(x)) for x in shlex.split(cmd)] |
1105 | 1120 | pp = subprocess.Popen(shlex.split(pcmd), stdout=subprocess.PIPE) |
| 1121 | + print(f"Command: {ecmd}") |
1106 | 1122 | cp = subprocess.Popen(ecmd, stdin=pp.stdout, stdout=sys.stdout) |
1107 | 1123 | if pp.stdout is not None: |
1108 | 1124 | pp.stdout.close() |
|
0 commit comments