Skip to content

Commit

Permalink
Merge pull request #610 from FarmBot/staging
Browse files Browse the repository at this point in the history
Fix DNS server config for self hosters
  • Loading branch information
ConnorRigby authored Jul 30, 2018
2 parents 50c28f8 + ec1b8c2 commit 422cbf7
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Changelog
# 6.4.7
* Fix DNS server config for self hosters.
* Add new field to `informational_settings`: `currently_on_beta`.
* Reindex farmware on bot_state crash.

# 6.4.6
* Add new RPC to reinitialize Firmware
* Tweak PinBinding debounce timeout.
* Update Linux system layer to fix sound
* Update Linux system layer to fix sound.

# 6.4.5
* Fix Firmware syncing applying _every_ setting.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.4.6
6.4.7
15 changes: 14 additions & 1 deletion lib/farmbot/bot_state/bot_state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ defmodule Farmbot.BotState do
user_env: user_env
]
initial_state = struct(__MODULE__, state_opts)
info_settings = %{initial_state.informational_settings | node_name: node()}
info_settings = %{
initial_state.informational_settings |
node_name: node(),
currently_on_beta: settings["currently_on_beta"]
}
if Process.whereis(Farmbot.Farmware.Supervisor) do
send(self(), :reindex_farmware)
end
state = %{initial_state | informational_settings: info_settings}
gen_stage_opts = [
subscribe_to: [Firmware, ConfigStorage.Dispatcher, Farmbot.PinBinding.Manager],
Expand All @@ -177,6 +184,11 @@ defmodule Farmbot.BotState do
{:noreply, [state], state}
end

def handle_info(:reindex_farmware, state) do
spawn Farmbot.Farmware.Supervisor, :reindex, []
{:noreply, [], state}
end

def handle_call({:report_soc_temp, temp}, _from, state) do
new_info_settings = %{state.informational_settings | soc_temp: temp}
state = %{state | informational_settings: new_info_settings}
Expand Down Expand Up @@ -364,6 +376,7 @@ defmodule Farmbot.BotState do
cache_bust: 0,
soc_temp: 0,
wifi_level: nil,
currently_on_beta: nil,
},
location_data: %{
position: %{x: nil, y: nil, z: nil},
Expand Down
11 changes: 11 additions & 0 deletions lib/farmbot/farmware/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ defmodule Farmbot.Farmware.Supervisor do
use Supervisor
alias Farmbot.Farmware.Installer.Repository.SyncTask

def reindex do
path = Farmbot.Farmware.Installer.install_root_path()

if path && File.exists?(path) do
for fwname <- File.ls!(path) do
{:ok, fw} = Farmbot.Farmware.lookup(fwname)
Farmbot.BotState.register_farmware(fw)
end
end
end

@doc false
def start_link do
Supervisor.start_link(__MODULE__, [], name: __MODULE__)
Expand Down
1 change: 1 addition & 0 deletions lib/farmbot/system/system.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ defmodule Farmbot.System do
end

defp write_file(reason) do
IO.puts "Farmbot powering down: #{reason}"
file = Path.join(@data_path, "last_shutdown_reason")
File.write!(file, reason)
end
Expand Down
19 changes: 19 additions & 0 deletions platform/target/bootstrap/configurator/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions platform/target/network/network.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions platform/target/network/ntp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 422cbf7

Please sign in to comment.