// Probes Pipelines addresses exactly as the native app does, for diagnosing // a connection that the app reports as unreachable. From app/: // // dart run tool/connection_probe.dart wss://box.tail1.ts.net:8443/connect [more...] // // With PIPELINES_WEB_AUTH_FILE (or ~/.config/pipelines/web-auth.json) present // and --sign-in, it also posts that file's password to the first address and // opens the websocket with the resulting cookie. The password is never printed. import 'dart:convert'; import 'dart:io'; import 'package:pipelines_app/core/session/server_session_io.dart' as native; import 'package:pipelines_app/core/session/session_probe.dart'; import 'package:pipelines_app/core/transport/server_url.dart'; Future main(List args) async { final signIn = args.contains('--sign-in'); final addresses = args.where((a) => !a.startsWith('--')).toList(); if (addresses.isEmpty) { stderr.writeln('usage: connection_probe.dart [--sign-in] ...'); exit(2); } var failures = 0; for (final raw in addresses) { final Uri endpoint; try { endpoint = Uri.parse(ServerUrl.validate(raw).wsUrl); } on FormatException catch (error) { stdout.writeln('$raw: invalid: ${error.message}'); failures++; continue; } final login = loginUriFor(endpoint)!; final probe = await native.probeLogin(login, const {}); final result = interpretLoginProbe(login, probe); stdout.writeln( '$endpoint: ${result.state.name}' '${result.reason == null ? '' : ' — ${result.reason}'}' ' (HTTP ${probe.status ?? 'none'}, login page: ${probe.loginPage})', ); if (result.state == SessionState.unreachable) failures++; } if (!signIn) exit(failures == 0 ? 0 : 1); final endpoint = Uri.parse(ServerUrl.validate(addresses.first).wsUrl); final login = loginUriFor(endpoint)!; final file = File( Platform.environment['PIPELINES_WEB_AUTH_FILE'] ?? '${Platform.environment['HOME']}/.config/pipelines/web-auth.json', ); final password = (jsonDecode(await file.readAsString()) as Map)['password'] as String; final signedIn = await native.postLogin(login, password); if (signedIn.cookie == null) { stdout.writeln('sign-in: FAILED — ${signedIn.error}'); exit(1); } stdout.writeln('sign-in: cookie received'); final kept = interpretLoginProbe( login, await native.probeLogin(login, {'Cookie': signedIn.cookie!}), ); stdout.writeln('kept session: ${kept.state.name}'); try { final socket = await WebSocket.connect( endpoint.toString(), headers: {'Cookie': signedIn.cookie!}, ).timeout(const Duration(seconds: 15)); stdout.writeln('websocket: connected (ready state ${socket.readyState})'); await socket.close(); } catch (error) { stdout.writeln('websocket: FAILED — $error'); exit(1); } stdout.writeln('done'); }