From 6cc81b55f2466cd7526f47da6980e3eb47041457 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 27 Aug 2018 13:04:51 +0200 Subject: Disable web interface --- lib/app/chat.ex | 2 +- lib/application.ex | 2 +- lib/cli/cli.ex | 2 +- lib/web/httprouter.ex | 53 -------------------------------------------------- lib/web/httprouter.ex_ | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 56 deletions(-) delete mode 100644 lib/web/httprouter.ex create mode 100644 lib/web/httprouter.ex_ (limited to 'lib') diff --git a/lib/app/chat.ex b/lib/app/chat.ex index b93e7b3..42991ce 100644 --- a/lib/app/chat.ex +++ b/lib/app/chat.ex @@ -132,7 +132,7 @@ defmodule SApp.Chat do def handle_cast({:deferred_insert, list}, state) do new_store = ML.insert_many(state.store, list, (fn msg -> msg_callback(state.channel, msg) end)) - %{state | store: new_store} + {:noreply, %{state | store: new_store}} end defp push_messages(state, to, start, num) do diff --git a/lib/application.ex b/lib/application.ex index 5262677..f933019 100644 --- a/lib/application.ex +++ b/lib/application.ex @@ -25,7 +25,7 @@ defmodule Shard.Application do Shard.Manager, # Web UI - Plug.Adapters.Cowboy.child_spec(:http, SWeb.HTTPRouter, [], port: listen_port + 1000) + # Plug.Adapters.Cowboy.child_spec(:http, SWeb.HTTPRouter, [], port: listen_port + 1000) ] # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html diff --git a/lib/cli/cli.ex b/lib/cli/cli.ex index 3f83cb1..c281d57 100644 --- a/lib/cli/cli.ex +++ b/lib/cli/cli.ex @@ -47,7 +47,7 @@ defmodule SCLI do pid end - defp handle_command(pid, ["join", qchan]) do + defp handle_command(_pid, ["join", qchan]) do list = for {_chid, manifest, chpid} <- :ets.tab2list(:shard_db), {:chat, chan} = manifest, do: {chan, chpid} diff --git a/lib/web/httprouter.ex b/lib/web/httprouter.ex deleted file mode 100644 index 57af9f9..0000000 --- a/lib/web/httprouter.ex +++ /dev/null @@ -1,53 +0,0 @@ -defmodule SWeb.HTTPRouter do - use Plug.Router - use Plug.ErrorHandler - - plug Plug.Parsers, parsers: [:urlencoded, :multipart] - - plug :match - plug :dispatch - - get "/" do - main_page(conn) - end - - post "/" do - if Map.has_key?(conn.params, "msg") do - SApp.Chat.send(conn.params["msg"]) - end - if Map.has_key?(conn.params, "nick") do - Shard.Identity.set_nickname(conn.params["nick"]) - end - if Map.has_key?(conn.params, "peer") do - [ipstr, portstr] = String.split(conn.params["peer"], ":") - {:ok, ip} = :inet.parse_address (to_charlist ipstr) - {port, _} = Integer.parse portstr - Shard.Manager.add_peer(ip, port) - end - - main_page(conn) - end - - match _ do - send_resp(conn, 404, "Oops!") - end - - def main_page(conn) do - {:ok, messages, _} = GenServer.call(SApp.Chat.Log, {:read, nil, 42}) - - msgtxt = messages - |> Enum.map(fn {ts, nick, msg} -> "#{ts |> DateTime.from_unix! |> DateTime.to_iso8601} <#{nick}> #{msg}\n" end) - - peerlist = SNet.ConnSupervisor - |> DynamicSupervisor.which_children - |> Enum.map(fn {_, pid, _, _} -> "#{GenServer.call(pid, :get_host_str)}\n" end) - - conn - |> put_resp_content_type("text/html") - |> send_resp(200, "
#{msgtxt}
" <> - "
" <> - "
" <> - "
#{peerlist}
" <> - "
") - end -end diff --git a/lib/web/httprouter.ex_ b/lib/web/httprouter.ex_ new file mode 100644 index 0000000..57af9f9 --- /dev/null +++ b/lib/web/httprouter.ex_ @@ -0,0 +1,53 @@ +defmodule SWeb.HTTPRouter do + use Plug.Router + use Plug.ErrorHandler + + plug Plug.Parsers, parsers: [:urlencoded, :multipart] + + plug :match + plug :dispatch + + get "/" do + main_page(conn) + end + + post "/" do + if Map.has_key?(conn.params, "msg") do + SApp.Chat.send(conn.params["msg"]) + end + if Map.has_key?(conn.params, "nick") do + Shard.Identity.set_nickname(conn.params["nick"]) + end + if Map.has_key?(conn.params, "peer") do + [ipstr, portstr] = String.split(conn.params["peer"], ":") + {:ok, ip} = :inet.parse_address (to_charlist ipstr) + {port, _} = Integer.parse portstr + Shard.Manager.add_peer(ip, port) + end + + main_page(conn) + end + + match _ do + send_resp(conn, 404, "Oops!") + end + + def main_page(conn) do + {:ok, messages, _} = GenServer.call(SApp.Chat.Log, {:read, nil, 42}) + + msgtxt = messages + |> Enum.map(fn {ts, nick, msg} -> "#{ts |> DateTime.from_unix! |> DateTime.to_iso8601} <#{nick}> #{msg}\n" end) + + peerlist = SNet.ConnSupervisor + |> DynamicSupervisor.which_children + |> Enum.map(fn {_, pid, _, _} -> "#{GenServer.call(pid, :get_host_str)}\n" end) + + conn + |> put_resp_content_type("text/html") + |> send_resp(200, "
#{msgtxt}
" <> + "
" <> + "
" <> + "
#{peerlist}
" <> + "
") + end +end -- cgit v1.2.3