diff options
author | Josef Gustafsson <josef.gson@gmail.com> | 2015-09-04 12:18:19 +0200 |
---|---|---|
committer | Josef Gustafsson <josef.gson@gmail.com> | 2015-09-04 12:18:19 +0200 |
commit | d1a2f978fb626c904fb1278c792d992ec4563acf (patch) | |
tree | e0ae1a38f9d4fc4c14b433222bff70e64bb1ac83 /src/catlfish_web.erl | |
parent | 4596485adffb636c014362bc982ee0b952c77f26 (diff) |
stripping away everything except what is necessary for nagiosnagios
Diffstat (limited to 'src/catlfish_web.erl')
-rw-r--r-- | src/catlfish_web.erl | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/src/catlfish_web.erl b/src/catlfish_web.erl deleted file mode 100644 index d49aaa1..0000000 --- a/src/catlfish_web.erl +++ /dev/null @@ -1,74 +0,0 @@ -%%% Copyright (c) 2014-2015, NORDUnet A/S. -%%% See LICENSE for licensing information. - --module(catlfish_web). --export([start/3, loop/2]). - -start(Options, Module, Name) -> - lager:debug("Starting catlfish web server: ~p", [Module]), - Loop = fun (Req) -> - ?MODULE:loop(Req, Module) - end, - mochiweb_http:start([{name, Name}, {loop, Loop} | Options]). - - -add_auth(Path, {Code, Headers, Data}) -> - AuthHeader = http_auth:create_auth("REPLY", Path, Data), - lager:debug("sent auth header: ~p", [AuthHeader]), - {Code, [{"X-Catlfish-Auth", AuthHeader} | Headers], Data}. - -loop(Req, Module) -> - "/" ++ Path = Req:get(path), - try - Starttime = os:timestamp(), - AuthHeader = Req:get_header_value("X-Catlfish-Auth"), - case Req:get(method) of - 'GET' -> - Query = Req:parse_qs(), - {_, RawQuery, _} = mochiweb_util:urlsplit_path(Req:get(raw_path)), - Result = case http_auth:verify_auth(AuthHeader, "GET", "/" ++ Path, RawQuery) of - failure -> - {403, [{"Content-Type", "text/plain"}], "Invalid credentials"}; - success -> - lager:debug("GET ~p ~p", [Path, Query]), - add_auth("/" ++ Path, Module:request(get, Path, Query)); - noauth -> - lager:debug("GET ~p ~p", [Path, Query]), - Module:request(get, Path, Query) - end, - lager:debug("GET finished: ~p us", [timer:now_diff(os:timestamp(), Starttime)]), - case Result of - none -> - Req:respond({404, [{"Content-Type", "text/plain"}], "Page not found"}); - _ -> - Req:respond(Result) - end; - 'POST' -> - Body = Req:recv_body(), - Result = case http_auth:verify_auth(AuthHeader, "POST", "/" ++ Path, Body) of - failure -> - {403, [{"Content-Type", "text/plain"}], "Invalid credentials"}; - success -> - lager:debug("POST ~p ~p", [Path, Body]), - add_auth("/" ++ Path, Module:request(post, Path, Body)); - noauth -> - lager:debug("POST ~p ~p", [Path, Body]), - Module:request(post, Path, Body) - end, - lager:debug("POST finished: ~p us", [timer:now_diff(os:timestamp(), Starttime)]), - case Result of - none -> - Req:respond({404, [{"Content-Type", "text/plain"}], "Page not found"}); - _ -> - Req:respond(Result) - end; - _ -> - Req:respond({501, [], []}) - end - catch - Type:What -> - [CrashFunction | Stack] = erlang:get_stacktrace(), - lager:error("Crash in ~p for path ~p: ~p ~p~n~p~n~p~n", [Module, Path, Type, What, CrashFunction, Stack]), - Req:respond({500, [{"Content-Type", "text/plain"}], - "Internal Server Error\n"}) - end. |