/
man.yaws
42 lines (38 loc) · 1.35 KB
/
man.yaws
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<erl>
result(Status, Msg) ->
[{status, Status},
{ehtml,
{html,[],
{'div',[{class,"man"}],
{pre,[],Msg}}}}].
out(A) ->
try queryvar(A,"page") of
{ok, Page} ->
%% only allow regular chars in Page
case lists:all(fun(C) ->
if
$a =< C, C =< $z ->
true;
$A =< C, C =< $Z ->
true;
C == $_ ->
true;
C == $. ->
true;
true ->
false
end
end, Page) of
true ->
L = os:cmd("env LC_ALL=en_US.ISO-8859-1 man " ++ Page ++ " | col -b -p -x"),
result(200, L);
false ->
result(400, "illegal character detected in query arg")
end;
undefined ->
result(400, "no man page found in query arg")
catch
_:_ ->
result(400, "illegal character detected in query arg")
end.
</erl>