farmbot_os/farmbot_os/platform/target/configurator/captive_portal.ex

69 lines
1.8 KiB
Elixir
Raw Normal View History

2019-06-25 16:28:08 -06:00
defmodule FarmbotOS.Platform.Target.Configurator.CaptivePortal do
@moduledoc """
VintageNet Technology that handles redirecting
**all** traffic to Farmbot's configuration interface
2019-06-25 16:28:08 -06:00
"""
2019-06-25 16:28:08 -06:00
@behaviour VintageNet.Technology
require FarmbotCore.Logger
alias FarmbotOS.Configurator.CaptiveDNS
2019-06-25 16:28:08 -06:00
@impl VintageNet.Technology
2019-12-16 11:20:26 -07:00
def normalize(%{vintage_net_wifi: _} = config) do
%{config | type: VintageNetWiFi}
|> VintageNetWiFi.normalize()
2019-06-25 16:28:08 -06:00
end
def normalize(config) do
2019-12-16 11:20:26 -07:00
%{config | type: VintageNetEthernet}
|> VintageNetEthernet.normalize()
end
2019-06-25 16:28:08 -06:00
@impl VintageNet.Technology
2019-12-16 11:20:26 -07:00
def to_raw_config(ifname, %{vintage_net_wifi: _} = config, opts) do
normalized = normalize(config)
2019-06-25 16:28:08 -06:00
ifname
|> vintage_wifi(normalized, opts)
|> add_captive_dns()
2019-06-25 16:28:08 -06:00
end
def to_raw_config(ifname, config, opts) do
normalized = normalize(config)
ifname
|> vintage_ethernet(normalized, opts)
|> add_captive_dns()
end
2019-06-25 16:28:08 -06:00
@impl VintageNet.Technology
def check_system(opts) do
2019-12-16 11:20:26 -07:00
VintageNetWiFi.check_system(opts)
2019-06-25 16:28:08 -06:00
end
@impl true
def ioctl(ifname, ioctl, args) do
2019-12-16 11:20:26 -07:00
VintageNetWiFi.ioctl(ifname, ioctl, args)
2019-06-25 16:28:08 -06:00
end
defp add_captive_dns(%{ifname: ifname} = raw_config) do
child_specs = [
{CaptiveDNS, [ifname, 53]}
2019-06-25 16:28:08 -06:00
]
%{raw_config | child_specs: raw_config.child_specs ++ child_specs}
2019-06-25 16:28:08 -06:00
end
defp vintage_wifi(ifname, config, opts) do
2019-12-16 11:20:26 -07:00
config = VintageNetWiFi.normalize(config)
raw_config = VintageNetWiFi.to_raw_config(ifname, config, opts)
%{raw_config | type: VintageNetWiFi}
2019-06-25 16:28:08 -06:00
end
defp vintage_ethernet(ifname, config, opts) do
2019-12-16 11:20:26 -07:00
config = VintageNetEthernet.normalize(config)
raw_config = VintageNetEthernet.to_raw_config(ifname, config, opts)
%{raw_config | type: VintageNetEthernet}
end
2019-06-25 16:28:08 -06:00
end