Catch invalid server fields for dns, ntp, and creds.

pull/610/head
connor rigby 2018-07-30 14:10:51 -07:00
parent 50c28f82ef
commit 4f8dcbbe32
No known key found for this signature in database
GPG Key ID: 24DC438382965C3B
5 changed files with 28 additions and 3 deletions

View File

@ -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.

View File

@ -1 +1 @@
6.4.6
6.4.7

View File

@ -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

View File

@ -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)

View File

@ -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