From: Daniel Lenski Date: Tue, 17 Sep 2019 04:18:11 +0000 (-0700) Subject: log other resources loaded when verbosity > 1 (e.g. `-vv` flag) X-Git-Url: https://code.communitydata.science/nu-vpn-proxy.git/commitdiff_plain/f429acaa10d15792bf74a4c6cafcf890cd0676ad?ds=sidebyside;hp=--cc log other resources loaded when verbosity > 1 (e.g. `-vv` flag) --- f429acaa10d15792bf74a4c6cafcf890cd0676ad diff --git a/gp-saml-gui.py b/gp-saml-gui.py index 195bc3b..e34d123 100755 --- a/gp-saml-gui.py +++ b/gp-saml-gui.py @@ -24,6 +24,7 @@ class SAMLLoginView: # API reference: https://lazka.github.io/pgi-docs/#WebKit2-4.0 self.success = False + self.verbose = verbose self.ctx = WebKit2.WebContext.get_default() self.cookies = self.ctx.get_cookie_manager() @@ -38,18 +39,24 @@ class SAMLLoginView: window.set_title("SAML Login") window.connect('delete-event', Gtk.main_quit) self.wview.connect('load-changed', self.get_saml_headers) + self.wview.connect('resource-load-started', self.log_resources) if html: self.wview.load_html(html, uri) else: self.wview.load_uri(uri) + def log_resources(self, webview, resource, request): + if self.verbose > 1: + print('%s for resource %s' % (request.get_http_method() or 'Request', resource.get_uri()), file=stderr) + def get_saml_headers(self, webview, event): if event != WebKit2.LoadEvent.FINISHED: return mr = webview.get_main_resource() - print("Finished loading %s..." % mr.get_uri(), file=stderr) + if self.verbose: + print("Finished loading %s" % mr.get_uri(), file=stderr) rs = mr.get_response() h = rs.get_http_headers() if h: @@ -60,7 +67,8 @@ class SAMLLoginView: h.foreach(listify) self.saml_result = d = dict(l) if d: - print("Got SAML relevant headers, done: %r" % d, file=stderr) + if self.verbose: + print("Got SAML relevant headers, done: %r" % d, file=stderr) self.success = True Gtk.main_quit() @@ -112,15 +120,15 @@ if __name__ == "__main__": if sam is None or sr is None: p.error("This does not appear to be a SAML prelogin response ( or tags missing)") elif sam.text == 'POST': - print("Got SAML POST content, opening browser...", file=stderr) html, uri = a2b_base64(sr.text).decode(), None elif sam.text == 'REDIRECT': - print("Got SAML REDIRECT to %s, opening browser..." % sr.text, file=stderr) uri, html = sr.text, None else: p.error("Unknown SAML method (%s)" % sam.text) # spawn WebKit view to do SAML interactive login + if args.verbose: + print("Got SAML POST, opening browser...", file=stderr) slv = SAMLLoginView(uri, html, verbose=args.verbose, cookies=args.cookies) Gtk.main() if not slv.success: