Files
alan 079924d19a Recover from zero servers, sign each machine in on its own, offer every route
- Removing the primary machine hands pipelines/runs to the next saved machine
  on native hosts; removing the last machine returns to the connect screen
  instead of stranding the app on "Server endpoint not configured".
- Add server probes the new machine and asks for its own password in the same
  page; Settings rows show Connected / Sign in required / Unreachable with the
  reason and offer Sign in; no other machine's credential is ever reused.
- Unreachable addresses explain why: a TLS failure against an IP points at the
  Tailscale name, a non-Pipelines answer points at the port.
- Discovered machines list every advertised route (LAN, Tailscale IP, Tailscale
  name) as a checklist; chosen routes are saved as one machine.
- tool/connection_probe.dart replays the native login and websocket against
  real addresses for diagnosis.
2026-11-08 23:59:20 +00:00

59 lines
1.8 KiB
Dart

import 'login_probe.dart';
/// What a server says about this device's session.
enum SessionState { signedIn, signedOut, unreachable }
/// What a probe of one server address found; [reason] explains an
/// unreachable address in words the operator can act on.
class ServerProbeResult {
const ServerProbeResult(this.state, {this.reason});
final SessionState state;
final String? reason;
}
/// The web login page for a websocket endpoint: same host and port, http(s).
Uri? loginUriFor(Uri endpoint) {
final scheme = switch (endpoint.scheme) {
'wss' || 'https' => 'https',
'ws' || 'http' => 'http',
_ => null,
};
if (scheme == null || endpoint.host.isEmpty || endpoint.userInfo.isNotEmpty) {
return null;
}
return Uri(
scheme: scheme,
host: endpoint.host,
port: endpoint.hasPort ? endpoint.port : null,
path: '/login',
);
}
/// The web login sends a signed-in visitor on and shows its form otherwise;
/// anything else on that port is not a Pipelines server.
ServerProbeResult interpretLoginProbe(Uri login, LoginProbe probe) {
final where = '${login.host}:${login.port}';
final status = probe.status;
if (status == null) {
return ServerProbeResult(
SessionState.unreachable,
reason: probe.failure ?? 'Could not reach $where.',
);
}
if (status >= 300 && status < 400) {
return const ServerProbeResult(SessionState.signedIn);
}
if (status == 200 && probe.loginPage) {
return const ServerProbeResult(SessionState.signedOut);
}
return ServerProbeResult(
SessionState.unreachable,
reason: status == 200
? '$where answered, but not with the Pipelines sign-in page. '
'Check the port: use the one in the web app\'s address bar.'
: '$where answered HTTP $status instead of the Pipelines sign-in '
'page. Check the address and port.',
);
}