summaryrefslogtreecommitdiff
path: root/lib/lsg_web/controllers/irc_controller.ex
diff options
context:
space:
mode:
authorhref <href@random.sh>2018-02-17 21:21:42 +0100
committerhref <href@random.sh>2018-02-17 21:21:42 +0100
commit50c6a09ff64cb081b27a0c30790b86873449d172 (patch)
treeba1bebfc7e367f169276692e0ac02709d62d6516 /lib/lsg_web/controllers/irc_controller.ex
parenttxt: fix against malicious filenames (aka 'fuck you shiv') (diff)
:)
Diffstat (limited to 'lib/lsg_web/controllers/irc_controller.ex')
-rw-r--r--lib/lsg_web/controllers/irc_controller.ex11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/lsg_web/controllers/irc_controller.ex b/lib/lsg_web/controllers/irc_controller.ex
index a5a68f7..bff5476 100644
--- a/lib/lsg_web/controllers/irc_controller.ex
+++ b/lib/lsg_web/controllers/irc_controller.ex
@@ -2,9 +2,11 @@ defmodule LSGWeb.IrcController do
use LSGWeb, :controller
def index(conn, _) do
+ doc = LSG.IRC.TxtHandler.irc_doc()
commands = for mod <- Application.get_env(:lsg, :irc)[:handlers] do
mod.irc_doc()
end
+ |> Enum.reject(fn(i) -> i == nil end)
render conn, "index.html", commands: commands
end
@@ -12,13 +14,16 @@ defmodule LSGWeb.IrcController do
def txt(conn, _), do: do_txt(conn, nil)
defp do_txt(conn, nil) do
- render conn, "txts.html", data: data()
+ doc = LSG.IRC.TxtHandler.irc_doc()
+ data = data()
+ lines = Enum.reduce(data, 0, fn({_, lines}, acc) -> acc + Enum.count(lines) end)
+ render conn, "txts.html", data: data, doc: doc, files: Enum.count(data), lines: lines
end
defp do_txt(conn, txt) do
data = data()
if Map.has_key?(data, txt) do
- render(conn, "txt.html", name: txt, data: data[txt])
+ render(conn, "txt.html", name: txt, data: data[txt], doc: nil)
else
conn
|> put_status(404)
@@ -26,7 +31,7 @@ defmodule LSGWeb.IrcController do
end
defp data() do
- dir = Application.get_env(:lsg, LSG.IRC.TxtHandler)[:directory]
+ dir = Application.get_env(:lsg, :data_path) <> "/irc.txt/"
Path.wildcard(dir <> "/*.txt")
|> Enum.reduce(%{}, fn(path, m) ->
path = String.split(path, "/")