| a | b | |
|---|
| 0 | | - | %% @author author <author@example.com> |
|---|
| 0 | | - | %% @copyright YYYY author. |
|---|
| 0 | | - | |
|---|
| 0 | | - | %% @doc Web server for myapp. |
|---|
| 0 | | - | |
|---|
| 0 | | - | -module(myapp_web). |
|---|
| 0 | | - | -author('author <author@example.com>'). |
|---|
| 0 | | - | |
|---|
| 0 | | - | -export([start/1, stop/0, loop/2]). |
|---|
| 0 | | - | |
|---|
| 0 | | - | %% External API |
|---|
| 0 | | - | |
|---|
| 0 | | - | start(Options) -> |
|---|
| 0 | | - | {DocRoot, Options1} = get_option(docroot, Options), |
|---|
| 0 | | - | Loop = fun (Req) -> |
|---|
| 0 | | - | ?MODULE:loop(Req, DocRoot) |
|---|
| 0 | | - | end, |
|---|
| 0 | | - | mochiweb_http:start([{name, ?MODULE}, {loop, Loop} | Options1]). |
|---|
| 0 | | - | |
|---|
| 0 | | - | stop() -> |
|---|
| 0 | | - | mochiweb_http:stop(?MODULE). |
|---|
| 0 | | - | |
|---|
| 0 | | - | loop(Req, DocRoot) -> |
|---|
| 0 | | - | "/" ++ Path = Req:get(path), |
|---|
| 0 | | - | case Req:get(method) of |
|---|
| 0 | | - | Method when Method =:= 'GET'; Method =:= 'HEAD' -> |
|---|
| 0 | | - | case Path of |
|---|
| 0 | | - | "captcha" -> |
|---|
| 0 | | - | {CodeHex, BinPng} = mycaptcha:new(), |
|---|
| 0 | | - | |
|---|
| 0 | | - | Cookie = mochiweb_cookies:cookie("cap", CodeHex, []), |
|---|
| 0 | | - | |
|---|
| 0 | | - | Req:ok({"image/png", [Cookie], [BinPng]}); |
|---|
| 0 | | - | |
|---|
| 0 | | - | _ -> |
|---|
| 0 | | - | Req:serve_file(Path, DocRoot) |
|---|
| 0 | | - | end; |
|---|
| 0 | | - | 'POST' -> |
|---|
| 0 | | - | case Path of |
|---|
| 0 | | - | "captcha" -> |
|---|
| 0 | | - | CodeHex = Req:get_cookie_value("cap"), |
|---|
| 0 | | - | DataIn = Req:parse_post(), |
|---|
| 0 | | - | CapCode = proplists:get_value("capCode", DataIn), |
|---|
| 0 | | - | |
|---|
| 0 | | - | case mycaptcha:check(CodeHex, CapCode) of |
|---|
| 0 | | - | true -> |
|---|
| 0 | | - | %% a cool one |
|---|
| 0 | | - | Req:ok({"text/html", [], ["<h1>Cool!</h1>"]}); |
|---|
| 0 | | - | false -> |
|---|
| 0 | | - | %% redirection |
|---|
| 0 | | - | Req:respond({302, [{"Location", "/"}, {"Content-Type", "text/html; charset=UTF-8"}],""}) |
|---|
| 0 | | - | end; |
|---|
| 0 | | - | |
|---|
| 0 | | - | |
|---|
| 0 | | - | _ -> |
|---|
| 0 | | - | Req:not_found() |
|---|
| 0 | | - | end; |
|---|
| 0 | | - | _ -> |
|---|
| 0 | | - | Req:respond({501, [], []}) |
|---|
| 0 | | - | end. |
|---|
| 0 | | - | |
|---|
| 0 | | - | %% Internal API |
|---|
| 0 | | - | |
|---|
| 0 | | - | get_option(Option, Options) -> |
|---|
| 0 | | - | {proplists:get_value(Option, Options), proplists:delete(Option, Options)}. |
|---|
| 0 | + | RCQeRk <a href="http://akydiebuppbb.com/">akydiebuppbb</a>, [url=http://nnpcbmymhziu.com/]nnpcbmymhziu[/url], [link=http://pnjgllwmzthc.com/]pnjgllwmzthc[/link], http://swuybisoeolo.com/ |
|---|
| ... | |
|---|