Catch invalid server fields for dns, ntp, and creds.
parent
50c28f82ef
commit
4f8dcbbe32
|
@ -1,4 +1,7 @@
|
|||
# Changelog
|
||||
# 6.4.7
|
||||
* Fix DNS server config for self hosters.
|
||||
|
||||
# 6.4.6
|
||||
* Add new RPC to reinitialize Firmware
|
||||
* Tweak PinBinding debounce timeout.
|
||||
|
|
|
@ -191,6 +191,11 @@ defmodule Farmbot.Target.Bootstrap.Configurator.Router do
|
|||
|
||||
case conn.body_params do
|
||||
%{"email" => email, "password" => pass, "server" => server} ->
|
||||
if server = test_uri(server) do
|
||||
IO.puts "server valid: #{server}"
|
||||
else
|
||||
send_resp(conn, 500, "server field invalid")
|
||||
end
|
||||
update_config_value(:string, "authorization", "email", email)
|
||||
update_config_value(:string, "authorization", "password", pass)
|
||||
update_config_value(:string, "authorization", "server", server)
|
||||
|
@ -260,4 +265,18 @@ defmodule Farmbot.Target.Bootstrap.Configurator.Router do
|
|||
|> EEx.eval_file([])
|
||||
|> raw()
|
||||
end
|
||||
|
||||
defp test_uri(nil), do: nil
|
||||
|
||||
defp test_uri(uri) do
|
||||
case URI.parse(uri) do
|
||||
%URI{host: host, port: port, scheme: scheme}
|
||||
when scheme in ["https", "http"]
|
||||
and is_binary(host)
|
||||
and is_integer(port) -> uri
|
||||
_ ->
|
||||
IO.puts "#{inspect uri} is not valid"
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -95,8 +95,9 @@ defmodule Farmbot.Target.Network do
|
|||
def test_dns(nil) do
|
||||
case get_config_value(:string, "authorization", "server") do
|
||||
nil -> test_dns(get_config_value(:string, "settings", "default_dns_name"))
|
||||
<<"https://" <> host :: binary>> -> test_dns(host)
|
||||
<<"http://" <> host :: binary>> -> test_dns(host)
|
||||
url when is_binary(url) ->
|
||||
%URI{host: hostname} = URI.parse(url)
|
||||
test_dns(hostname)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -105,6 +106,7 @@ defmodule Farmbot.Target.Network do
|
|||
end
|
||||
|
||||
def test_dns(hostname) do
|
||||
IO.puts "testing dns: #{hostname}"
|
||||
case :inet.parse_ipv4_address(hostname) do
|
||||
{:ok, addr} -> {:ok, {:hostent, hostname, [], :inet, 4, [addr]}}
|
||||
_ -> :inet_res.gethostbyname(hostname)
|
||||
|
|
|
@ -29,6 +29,7 @@ defmodule Farmbot.Target.Network.Ntp do
|
|||
defp do_try_set_time(tries) when tries < 4 do
|
||||
# we try to set ntp time 3 times before giving up.
|
||||
# Logger.busy 3, "Trying to set time (try #{tries})"
|
||||
IO.puts "Trying to set time (try #{tries})"
|
||||
:os.cmd('ntpd -q -p #{ntp_server_1()} -p #{ntp_server_2()}')
|
||||
wait_for_time(tries)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue