Class: WifiWand::CaptivePortalChecker

Inherits:
Object
  • Object
show all
Includes:
ProcessProbeManager
Defined in:
lib/wifi_wand/services/captive_portal_checker.rb

Constant Summary collapse

HELPER_RESULT_GRACE =

Seconds given to a probe subprocess after SIGTERM before escalating to SIGKILL. Short enough to keep overall check latency low, long enough for a clean exit.

0.5

Instance Method Summary collapse

Methods included from ProcessProbeManager

#finalize_probe, #helper_exit_poll_interval, #helper_result_grace, #probe_reaped_within_grace?, #reap_probe, #terminate_probe, #terminate_probes, #wait_for_killed_probe_reap, #wait_for_probe_exit

Constructor Details

#initialize(verbose: false, output: $stdout, runtime_config: nil, http_connectivity_timeout_in_secs: TimingConstants::HTTP_CONNECTIVITY_TIMEOUT) ⇒ CaptivePortalChecker

Returns a new instance of CaptivePortalChecker.



19
20
21
22
23
24
25
26
# File 'lib/wifi_wand/services/captive_portal_checker.rb', line 19

def initialize(verbose: false, output: $stdout, runtime_config: nil,
  http_connectivity_timeout_in_secs: TimingConstants::HTTP_CONNECTIVITY_TIMEOUT)
  @runtime_config = runtime_config || RuntimeConfig.new(
    verbose:    verbose,
    out_stream: output
  )
  @http_connectivity_timeout_in_secs = http_connectivity_timeout_in_secs
end

Instance Method Details

#captive_portal_login_required(timeout_in_secs: nil) ⇒ Symbol

Determines whether captive portal login appears to be required now by making real HTTP requests to well-known connectivity check endpoints and verifying the response status codes.

Multiple endpoints are checked concurrently so that a single misbehaving endpoint cannot cause a false captive-portal detection without adding the serial worst-case latency of back-to-back HTTP timeouts. Returns :no if any endpoint returns the expected response, :yes only when at least one endpoint returned an unexpected response and none succeeded, and :unknown when every endpoint failed with a network error.

For full details on endpoint redundancy, return-value rationale, decision flow, and terminology ("mismatch"), see docs/CONNECTIVITY_CHECKING.md section "Captive Portal Detection".

Returns:

  • (Symbol)

    :no if login does not appear to be required, :yes if login appears to be required, :unknown if the requirement could not be determined because all endpoints errored.

See Also:

  • for per-endpoint HTTP check details
  • for the configured endpoint list


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/wifi_wand/services/captive_portal_checker.rb', line 49

def (timeout_in_secs: nil)
  endpoints = captive_portal_check_endpoints

  err_output.puts "Testing captive portal via HTTP: #{endpoints.map { _1[:url] }.join(', ')}" if verbose?

  results = captive_portal_results(endpoints, timeout_in_secs: timeout_in_secs)

   = if results.include?(ConnectivityStates::CAPTIVE_PORTAL_LOGIN_NOT_REQUIRED)
    ConnectivityStates::CAPTIVE_PORTAL_LOGIN_NOT_REQUIRED
  elsif results.include?(ConnectivityStates::CAPTIVE_PORTAL_LOGIN_REQUIRED)
    ConnectivityStates::CAPTIVE_PORTAL_LOGIN_REQUIRED
  else
    ConnectivityStates::CAPTIVE_PORTAL_LOGIN_UNKNOWN
  end

  if verbose?
    status = case 
             when ConnectivityStates::CAPTIVE_PORTAL_LOGIN_NOT_REQUIRED then 'not required'
             when ConnectivityStates::CAPTIVE_PORTAL_LOGIN_REQUIRED then 'required'
             else 'unknown'
    end
    err_output.puts "Captive portal results: #{results.inspect}#{status}"
  end

  
end

#probe_endpoint(endpoint) ⇒ Hash

Shared probe interface used by the helper subprocess wrapper.

Parameters:

  • endpoint (Hash)

    captive-portal endpoint configuration

Returns:

  • (Hash)

    probe metadata including :login_required and either :actual_code or :error_class



80
81
82
# File 'lib/wifi_wand/services/captive_portal_checker.rb', line 80

def probe_endpoint(endpoint)
  perform_captive_portal_check(endpoint)
end