def run(self): # To work around funky GC conflicts with C++ code by ensuring QApplication terminates last global app cfg = config.load() argv = sys.argv.copy() if self.display_mode == config.DisplayMode.HIDDEN: argv += ["-platform", "minimal"] app = QApplication(argv) # In order to make Python able to handle signals force_python_execution = QTimer() force_python_execution.start(200) def ignore(): pass force_python_execution.timeout.connect(ignore) web = WebBrowser(cfg.auto_fill_rules, self._states.put) startup_info = self._commands.get() logger.info("Browser started", startup_info=startup_info) logger.info("Loading page", url=startup_info.url) web.authenticate_at(QUrl(startup_info.url), startup_info.credentials) web.show() rc = app.exec_() logger.info("Exiting browser") return rc
def main(): parser = create_argparser() args = parser.parse_args() if (args.profile_path or args.use_profile_selector) and (args.server or args.usergroup): parser.error( "--profile/--profile-selector and --server/--usergroup are mutually exclusive" ) if not args.profile_path and not args.server and not config.load( ).default_profile: if os.path.exists("/opt/cisco/anyconnect/profile"): args.profile_path = "/opt/cisco/anyconnect/profile" else: parser.error( "No AnyConnect profile can be found. One of --profile or --server arguments required." ) if args.use_profile_selector and not args.profile_path: parser.error( "No AnyConnect profile can be found. --profile argument is required." ) return app.run(args)
def run(self): # To work around funky GC conflicts with C++ code by ensuring QApplication terminates last global app args = create_argparser().parse_known_args()[0] configure_logger(logging.getLogger(), args.log_level) cfg = config.load() app = QApplication(sys.argv) # In order to make Python able to handle signals force_python_execution = QTimer() force_python_execution.start(200) def ignore(): pass force_python_execution.timeout.connect(ignore) web = WebBrowser(cfg.auto_fill_rules, self._states.put) startup_info = self._commands.get() logger.info("Browser started", startup_info=startup_info) logger.info("Loading page", url=startup_info.url) web.authenticate_at(QUrl(startup_info.url), startup_info.credentials) web.show() rc = app.exec_() logger.info("Exiting browser") return rc
def run(args): configure_logger(logging.getLogger(), args.log_level) cfg = config.load() try: if os.name == "nt": asyncio.set_event_loop(asyncio.ProactorEventLoop()) auth_response, selected_profile = asyncio.get_event_loop().run_until_complete( _run(args, cfg) ) except KeyboardInterrupt: logger.warn("CTRL-C pressed, exiting") return 130 except ValueError as e: msg, retval = e.args logger.error(msg) return retval except Terminated: logger.warn("Browser window terminated, exiting") return 2 except AuthResponseError as exc: logger.error( f'Required attributes not found in response ("{exc}", does this endpoint do SSO?), exiting' ) return 3 except HTTPError as exc: logger.error(f"Request error: {exc}") return 4 config.save(cfg) if args.authenticate: logger.warn("Exiting after login, as requested") details = { "host": selected_profile.vpn_url, "cookie": auth_response.session_token, "fingerprint": auth_response.server_cert_hash, } if args.authenticate == "json": print(json.dumps(details, indent=4)) elif args.authenticate == "shell": print( "\n".join(f"{k.upper()}={shlex.quote(v)}" for k, v in details.items()) ) return 0 try: return run_openconnect( auth_response, selected_profile, args.proxy, args.openconnect_args ) except KeyboardInterrupt: logger.warn("CTRL-C pressed, exiting") return 0 finally: handle_disconnect(cfg.on_disconnect)
async def _run(args): cfg = config.load() credentials = None if cfg.credentials: credentials = cfg.credentials elif args.user: credentials = Credentials(args.user) credentials.password = getpass.getpass( prompt=f"Password ({args.user}): ") cfg.credentials = credentials if cfg.default_profile and not (args.use_profile_selector or args.server): selected_profile = cfg.default_profile elif args.use_profile_selector or args.profile_path: profiles = get_profiles(Path(args.profile_path)) if not profiles: logger.error("No profile found") return 17 selected_profile = await select_profile(profiles) if not selected_profile: logger.error("No profile selected") return 18 elif args.server: selected_profile = config.HostProfile(args.server, args.usergroup, args.authgroup) else: raise ValueError( "Cannot determine server address. Invalid arguments specified.") cfg.default_profile = selected_profile config.save(cfg) display_mode = config.DisplayMode[args.browser_display_mode.upper()] auth_response = await authenticate_to(selected_profile, credentials, display_mode) if args.authenticate: logger.warn("Exiting after login, as requested") details = { "host": selected_profile.vpn_url, "cookie": auth_response.session_token, "fingerprint": auth_response.server_cert_hash, } if args.authenticate == "json": print(json.dumps(details, indent=4)) elif args.authenticate == "shell": print("\n".join(f"{k.upper()}={shlex.quote(v)}" for k, v in details.items())) return 0 return await run_openconnect(auth_response, selected_profile, args.openconnect_args)
def run(self): # To work around funky GC conflicts with C++ code by ensuring QApplication terminates last global app signal.signal(signal.SIGTERM, on_sigterm) signal.signal(signal.SIGINT, signal.SIG_DFL) cfg = config.load() argv = sys.argv.copy() if self.display_mode == config.DisplayMode.HIDDEN: argv += ["-platform", "minimal"] app = QApplication(argv) if self.proxy: parsed = urlparse(self.proxy) if parsed.scheme.startswith("socks5"): proxy_type = QNetworkProxy.Socks5Proxy elif parsed.scheme.startswith("http"): proxy_type = QNetworkProxy.HttpProxy else: raise ValueError("Unsupported proxy type", parsed.scheme) proxy = QNetworkProxy(proxy_type, parsed.hostname, parsed.port) QNetworkProxy.setApplicationProxy(proxy) # In order to make Python able to handle signals force_python_execution = QTimer() force_python_execution.start(200) def ignore(): pass force_python_execution.timeout.connect(ignore) web = WebBrowser(cfg.auto_fill_rules, self._states.put) startup_info = self._commands.get() logger.info("Browser started", startup_info=startup_info) logger.info("Loading page", url=startup_info.url) web.authenticate_at(QUrl(startup_info.url), startup_info.credentials) web.show() rc = app.exec_() logger.info("Exiting browser") return rc
async def _run(args): cfg = config.load() credentials = None if cfg.credentials: credentials = cfg.credentials elif args.user: credentials = Credentials(args.user) credentials.password = getpass.getpass( prompt=f"Password ({args.user}): ") cfg.credentials = credentials if cfg.default_profile and not (args.use_profile_selector or args.server): selected_profile = cfg.default_profile elif args.use_profile_selector or args.profile_path: profiles = get_profiles(Path(args.profile_path)) if not profiles: logger.error("No profile found") return 17 selected_profile = await select_profile(profiles) if not selected_profile: logger.error("No profile selected") return 18 elif args.server: selected_profile = config.HostProfile(args.server, args.usergroup) else: raise ValueError( "Cannot determine server address. Invalid arguments specified.") cfg.default_profile = selected_profile config.save(cfg) session_token = await authenticate_to(selected_profile, credentials) if args.login_only: logger.warn("Exiting after login, as requested") return 0 return await run_openconnect(session_token, selected_profile, args.openconnect_args)