Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 476 lines (415 sloc) 15.987 kb
21abc5b @klacke Initial revision
authored
1 %%%----------------------------------------------------------------------
2 %%% File : yaws_ls.erl
3 %%% Author : Claes Wikstrom <klacke@hyber.org>
455578a @vinoski major trailing whitespace cleanup
vinoski authored
4 %%% Purpose :
21abc5b @klacke Initial revision
authored
5 %%% Created : 5 Feb 2002 by Claes Wikstrom <klacke@hyber.org>
7d2bf5f @mbj4668 modified file listing layout, implemented sort based on name, date an…
mbj4668 authored
6 %%% Modified: 13 Jan 2004 by Martin Bjorklund <mbj@bluetail.com>
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
7 %%% Modified: Jan 2006 by Sébastien Bigot <sebastien.bigot@tremplin-utc.net>
21abc5b @klacke Initial revision
authored
8 %%%----------------------------------------------------------------------
9
10 -module(yaws_ls).
11 -author('klacke@hyber.org').
12
6cf3ece @klacke ""
authored
13 -include("../include/yaws.hrl").
14 -include("../include/yaws_api.hrl").
3c06a9e @klacke rearr of includefiles
authored
15 -include("yaws_debug.hrl").
16
21abc5b @klacke Initial revision
authored
17 -include_lib("kernel/include/file.hrl").
9a74e5a @klacke Major general code cleanup, finally got rid of all the export_all sta…
authored
18 -export([list_directory/6, out/1]).
21abc5b @klacke Initial revision
authored
19
54139d8 @klacke prepare for 1.81
authored
20 -define(FILE_LEN_SZ, 45).
21
92a1a27 @klacke sloppy bug that sneaked into the 1.93 release, call to undef function…
authored
22 list_directory(_Arg, CliSock, List, DirName, Req, DoAllZip) ->
7d2bf5f @mbj4668 modified file listing layout, implemented sort based on name, date an…
mbj4668 authored
23 {abs_path, Path} = Req#http_request.path,
d70b935 @mbj4668 use the same file list sort in subdirs as in parent dir
mbj4668 authored
24 {DirStr, Pos, Direction, Qry} = parse_query(Path),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
25 ?Debug("List=~p Dirname~p~n", [List, DirName]),
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
26
27 Descriptions = read_descriptions(DirName),
28
29 L0 = lists:zf(
0be3c7e @klacke untabified all of yaws
authored
30 fun(F) ->
31 File = DirName ++ [$/|F],
32 FI = file:read_file_info(File),
33 file_entry(FI, DirName, F, Qry,Descriptions)
34 end, List),
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
35
7d2bf5f @mbj4668 modified file listing layout, implemented sort based on name, date an…
mbj4668 authored
36 L1 = lists:keysort(Pos, L0),
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
37
7d2bf5f @mbj4668 modified file listing layout, implemented sort based on name, date an…
mbj4668 authored
38 L2 = if Direction == normal -> L1;
0be3c7e @klacke untabified all of yaws
authored
39 Direction == reverse -> lists:reverse(L1)
40 end,
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
41
42 L3 = [Html || {_, _, _, _, Html} <- L2],
6e96a14 @klacke indendation cleanup
authored
43
455578a @vinoski major trailing whitespace cleanup
vinoski authored
44 Body = [ doc_head(DirStr),
0be3c7e @klacke untabified all of yaws
authored
45 dir_header(DirName,DirStr),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
46 table_head(Direction),
0be3c7e @klacke untabified all of yaws
authored
47 parent_dir(),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
48 if
49 DoAllZip == true ->
0be3c7e @klacke untabified all of yaws
authored
50 allzip();
51 DoAllZip == true_nozip ->
52 [];
6e96a14 @klacke indendation cleanup
authored
53 true ->
0be3c7e @klacke untabified all of yaws
authored
54 []
55 end,
56
6e96a14 @klacke indendation cleanup
authored
57 %% if DoAllGZip == true -> alltgz() end,
58 %% if DoAllBZip2 == true -> alltbz2() end,
59
60 %% if DoAllZip == true -> alltgz() end,
61 %% if DoAllZip == true -> alltbz2() end,
0be3c7e @klacke untabified all of yaws
authored
62
63 L3,
64 table_tail(),
65 dir_footer(DirName),%yaws:address(),
66 doc_tail()
6e96a14 @klacke indendation cleanup
authored
67 ],
68
3b9e4a1 @klacke new ret vals from out/1
authored
69 B = list_to_binary(Body),
cace2ff @carsten3347 Mainly new HEAD request handling.
carsten3347 authored
70
58e3d35 @carsten3347 Deflate rehaul: Now works with dynamic pages.
carsten3347 authored
71 yaws_server:accumulate_content(B),
92a1a27 @klacke sloppy bug that sneaked into the 1.93 release, call to undef function…
authored
72 yaws_server:deliver_accumulated(CliSock),
58e3d35 @carsten3347 Deflate rehaul: Now works with dynamic pages.
carsten3347 authored
73 yaws_server:done_or_continue().
cace2ff @carsten3347 Mainly new HEAD request handling.
carsten3347 authored
74
7d2bf5f @mbj4668 modified file listing layout, implemented sort based on name, date an…
mbj4668 authored
75 parse_query(Path) ->
76 case string:tokens(Path, [$?]) of
0be3c7e @klacke untabified all of yaws
authored
77 [DirStr, [PosC, $=, DirC] = Q] ->
78 Pos = case PosC of
79 $N -> 1; % name
80 $M -> 2; % last modified
81 $S -> 3; % size
455578a @vinoski major trailing whitespace cleanup
vinoski authored
82 $D -> 4 % Description
0be3c7e @klacke untabified all of yaws
authored
83 end,
84 Dir = case DirC of
85 $r -> reverse;
86 _ -> normal
87 end,
88 {DirStr, Pos, Dir, "/?"++Q};
89 _ ->
90 {Path, 1, normal, ""}
7d2bf5f @mbj4668 modified file listing layout, implemented sort based on name, date an…
mbj4668 authored
91 end.
92
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
93 parse_description(Line) ->
94 L = string:strip(Line),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
95 Pos = string:chr(L,$ ),
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
96 Filename = string:substr(L, 1, Pos-1),
97 D = string:substr(L,Pos+1),
98 Description = string:strip(D,left),
99 {Filename,Description}.
21abc5b @klacke Initial revision
authored
100
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
101 read_descriptions(DirName) ->
102 File = DirName ++ [$/ | "MANIFEST.txt"],
103 case file:read_file(File) of
0be3c7e @klacke untabified all of yaws
authored
104 {ok,Bin} -> Lines = string:tokens(binary_to_list(Bin),"\n"),
105 lists:map(fun parse_description/1,Lines);
106 _ -> []
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
107 end.
21abc5b @klacke Initial revision
authored
108
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
109 get_description(Name,Descriptions) ->
110 case lists:keysearch(Name,1,Descriptions) of
0be3c7e @klacke untabified all of yaws
authored
111 {value, {_,Description}} -> Description;
112 _ -> []
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
113 end.
3b9e4a1 @klacke new ret vals from out/1
authored
114
21abc5b @klacke Initial revision
authored
115 doc_head(DirName) ->
ba26210 Fixed XSS vulnerability
Leon Smith authored
116 HtmlDirName = yaws_api:htmlize(yaws_api:url_decode(DirName)),
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
117 ?F("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
455578a @vinoski major trailing whitespace cleanup
vinoski authored
118 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
119 "<html>\n"
120 " <head>\n"
121 " <title>Index of ~s</title>\n"
122 " <style type=\"text/css\">\n"
7d2bf5f @mbj4668 modified file listing layout, implemented sort based on name, date an…
mbj4668 authored
123 " img { border: 0; padding: 0 2px; vertical-align: text-bottom; }\n"
e6ff280 @carsten3347 trivial CSS fix
carsten3347 authored
124 " td { font-family: monospace; padding: 2px 3px; text-align:left;\n"
7d2bf5f @mbj4668 modified file listing layout, implemented sort based on name, date an…
mbj4668 authored
125 " vertical-align: bottom; white-space: pre; }\n"
126 " td:first-child { text-align: left; padding: 2px 10px 2px 3px; }\n"
127 " table { border: 0; }\n"
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
128 " </style>\n"
129 "</head> \n"
130 "<body>\n",
131 [HtmlDirName]
132 ).
133
134 doc_tail() ->
6e96a14 @klacke indendation cleanup
authored
135 "</body>\n"
136 "</html>\n".
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
137
138 table_head(Direction) ->
7d2bf5f @mbj4668 modified file listing layout, implemented sort based on name, date an…
mbj4668 authored
139 NextDirection = if Direction == normal -> "r";
0be3c7e @klacke untabified all of yaws
authored
140 Direction == reverse -> "n"
141 end,
a664cbf @carsten3347 Modified ALT texts for better appearance in text browsers.
carsten3347 authored
142 ["<table>\n"
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
143 " <tr>\n"
144 " <td><img src=\"/icons/blank.gif\" alt=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"/><a href=\"?N=",NextDirection,"\">Name</a></td>\n"
145 " <td><a href=\"?M=",NextDirection,"\">Last Modified</a></td>\n"
146 " <td><a href=\"?S=",NextDirection,"\">Size</a></td>\n"
147 " <td><a href=\"?D=",NextDirection,"\">Description</a></td>\n"
148 " </tr>\n"
149 " <tr><th colspan=\"4\"><hr/></th></tr>\n"].
150
151 table_tail() ->
6e96a14 @klacke indendation cleanup
authored
152 " <tr><th colspan=\"4\"><hr/></th></tr>\n"
153 "</table>\n".
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
154
155
156 dir_footer(DirName) ->
157 File = DirName ++ [$/ | "README.txt"],
158 case file:read_file(File) of
0be3c7e @klacke untabified all of yaws
authored
159 {ok,Bin} -> "<pre>\n" ++ binary_to_list(Bin) ++ "</pre>\n";
160 _ -> yaws:address()
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
161 end.
162
163 dir_header(DirName,DirStr) ->
164 File = DirName ++ [$/ | "HEADER.txt"],
165 case file:read_file(File) of
0be3c7e @klacke untabified all of yaws
authored
166 {ok,Bin} -> "<pre>\n" ++ binary_to_list(Bin) ++ "</pre>\n";
167 _ -> HtmlDirName = yaws_api:htmlize(yaws_api:url_decode(DirStr)),
168 "<h1>Index of " ++ HtmlDirName ++ "</h1>\n"
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
169 end.
170
455578a @vinoski major trailing whitespace cleanup
vinoski authored
171 parent_dir() ->
172 {Gif, Alt} = list_gif(directory,"."),
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
173 ?F(" <tr>\n"
174 " <td><img src=~p alt=~p/><a href=\"..\">Parent Directory</a></td>\n"
175 " <td></td>\n"
176 " <td>-</td>\n"
177 " <td></td>\n"
178 " </tr>\n",
179 ["/icons/" ++ Gif,
0be3c7e @klacke untabified all of yaws
authored
180 Alt
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
181 ]).
21abc5b @klacke Initial revision
authored
182
2e8e005 @mbj4668 Added auto-generate all.zip to dir listings. It needs the zip comman…
mbj4668 authored
183 %% FIXME: would be nice with a good size approx. but it would require
184 %% a deep scan of possibly the entire docroot, (and also some knowledge
185 %% about zip's compression ratio in advance...)
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
186 allzip() ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
187 {Gif, Alt} = list_gif(zip,""),
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
188 ?F(" <tr>\n"
189 " <td><img src=~p alt=~p/><a href=\"all.zip\">all.zip</a></td>\n"
190 " <td></td>\n"
191 " <td>-</td>\n"
192 " <td>Build a zip archive of current directory</td>\n"
193 " </tr>\n",
194 ["/icons/" ++ Gif,
0be3c7e @klacke untabified all of yaws
authored
195 Alt]).
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
196
ca1c8b1 @karlsson Fixed a number of compiler warnings and html validation errors
karlsson authored
197 %% alltgz() ->
198 %% {Gif, Alt} = list_gif(zip,""),
199 %% ?F(" <tr>\n"
200 %% " <td><img src=~p alt=~p/><a href=\"all.tgz\">all.tgz</a></td>\n"
201 %% " <td></td>\n"
202 %% " <td>-</td>\n"
203 %% " <td>Build a gzip archive of current directory</td>\n"
204 %% " </tr>\n",
205 %% ["/icons/" ++ Gif,
206 %% Alt]).
207
208 %% alltbz2() ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
209 %% {Gif, Alt} = list_gif(zip,""),
ca1c8b1 @karlsson Fixed a number of compiler warnings and html validation errors
karlsson authored
210 %% ?F(" <tr>\n"
211 %% " <td><img src=~p alt=~p/><a href=\"all.tbz2\">all.tbz2</a></td>\n"
212 %% " <td></td>\n"
213 %% " <td>-</td>\n"
214 %% " <td>Build a bzip2 archive of current directory</td>\n"
215 %% " </tr>\n",
216 %% ["/icons/" ++ Gif,
217 %% Alt]).
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
218
219 is_user_dir(SP) ->
220 case SP of
0be3c7e @klacke untabified all of yaws
authored
221 [$/,$~ | T] -> User = string:sub_word(T,1,$/),
222 case catch yaws:user_to_home(User) of
223 {'EXIT', _} ->
224 false;
455578a @vinoski major trailing whitespace cleanup
vinoski authored
225 Home ->
0be3c7e @klacke untabified all of yaws
authored
226 {true,Home}
455578a @vinoski major trailing whitespace cleanup
vinoski authored
227 end;
0be3c7e @klacke untabified all of yaws
authored
228 _ -> false
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
229 end.
230
2e8e005 @mbj4668 Added auto-generate all.zip to dir listings. It needs the zip comman…
mbj4668 authored
231 out(A) ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
232 SP = A#arg.server_path,
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
233 PP = A#arg.appmod_prepath,
234 Dir = case is_user_dir(SP) of
0be3c7e @klacke untabified all of yaws
authored
235 {true,Home} -> Home ++ "/public_html";
236 false -> A#arg.docroot
237 end ++ PP,
6e96a14 @klacke indendation cleanup
authored
238
239 %% {html,?F("<h2>~p</h2>",[Dir])}.
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
240
c28243f @mbj4668 Fixed bad checkin
mbj4668 authored
241 YPid = self(),
6e96a14 @klacke indendation cleanup
authored
242
896b8b1 @hce Fix all.zip routine.
hce authored
243 Forbidden_Paths = accumulate_forbidden_paths(),
244 case filename:basename(A#arg.server_path) of
245 "all.zip" -> spawn_link(fun() -> zip(YPid, Dir, Forbidden_Paths) end),
246 {streamcontent, "application/zip", ""}
6e96a14 @klacke indendation cleanup
authored
247 %% "all.tgz" -> spawn_link(fun() -> tgz(YPid, Dir) end),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
248 %% {streamcontent, "application/gzip", ""};
6e96a14 @klacke indendation cleanup
authored
249 %% "all.tbz2" -> spawn_link(fun() -> tbz2(YPid, Dir) end),
250 %% {streamcontent, "application/gzip", ""}
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
251 end.
2e8e005 @mbj4668 Added auto-generate all.zip to dir listings. It needs the zip comman…
mbj4668 authored
252
8e64d3b @klacke Some minor bugs, and some dead code removed, all found by Tuncers run…
authored
253
896b8b1 @hce Fix all.zip routine.
hce authored
254 generate_random_fn() ->
255 Bytes = try crypto:rand_bytes(64) of
256 B when is_bitstring(B) ->
257 B
258 catch _:_ ->
8493ded @klacke Use a binary comprehension instead of god old list_to_binary as per s…
authored
259 %% for installations without crypto
260 << <<(random:uniform(256) - 1)>> || _ <- lists:seq(1,64) >>
896b8b1 @hce Fix all.zip routine.
hce authored
261 end,
262 << Int:512/unsigned-big-integer >> = << Bytes/binary >>,
263 integer_to_list(Int).
264
265 mktempfilename([]) ->
266 {error, no_temp_dir};
267 mktempfilename([Dir|R]) ->
268 RandomFN = generate_random_fn(),
269 Filename = filename:join(Dir, RandomFN),
270 case file:open(Filename, [write]) of
271 {ok, FileHandle} ->
272 {ok, {Filename, FileHandle}};
273 _Else ->
274 mktempfilename(R)
275 end.
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
276
896b8b1 @hce Fix all.zip routine.
hce authored
277 mktempfilename() ->
278 %% TODO: Add code to determine the temporary directory on various
279 %% operating systems.
280 PossibleDirs = ["/tmp", "/var/tmp"],
455578a @vinoski major trailing whitespace cleanup
vinoski authored
281 mktempfilename(PossibleDirs).
896b8b1 @hce Fix all.zip routine.
hce authored
282
283 zip(YPid, Dir, ForbiddenPaths) ->
284 {ok, RE_ForbiddenNames} = re:compile("\\.yaws\$"),
285 Files = dig_through_dir(Dir, ForbiddenPaths, RE_ForbiddenNames),
286 {ok, {Tempfile, TempfileH}} = mktempfilename(),
287 file:write(TempfileH, lists:foldl(fun(I, Acc) ->
288 Acc ++ I ++ "\n"
455578a @vinoski major trailing whitespace cleanup
vinoski authored
289 end, [], Files)),
896b8b1 @hce Fix all.zip routine.
hce authored
290 file:close(TempfileH),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
291 process_flag(trap_exit, true),
896b8b1 @hce Fix all.zip routine.
hce authored
292 %% TODO: find a way to directly pass the list of files to
293 %% zip. Erlang ports do not allow stdin to be closed
294 %% independently; however, zip needs stdin to be closed as an
295 %% indicator that the list of files is complete.
296 P = open_port({spawn, "zip -q -1 - -@ < " ++ Tempfile},
0be3c7e @klacke untabified all of yaws
authored
297 [{cd, Dir},use_stdio, binary, exit_status]),
896b8b1 @hce Fix all.zip routine.
hce authored
298 F = fun() ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
299 file:delete(Tempfile)
896b8b1 @hce Fix all.zip routine.
hce authored
300 end,
301 stream_loop(YPid, P, F).
302
303 accumulate_forbidden_paths() ->
304 SC = get(sc),
305 Auth = SC#sconf.authdirs,
306 lists:foldl(fun({Path, _Auth}, Acc) ->
307 Acc ++ [Path]
308 end, [], Auth).
309
310
311 %% tgz(YPid, Dir) ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
312 %% process_flag(trap_exit, true),
896b8b1 @hce Fix all.zip routine.
hce authored
313 %% P = open_port({spawn, "tar cz ."},
314 %% [{cd, Dir},use_stdio, binary, exit_status]),
315 %% stream_loop(YPid, P).
316
317 %% tbz2(YPid, Dir) ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
318 %% process_flag(trap_exit, true),
896b8b1 @hce Fix all.zip routine.
hce authored
319 %% P = open_port({spawn, "tar cj ."},
320 %% [{cd, Dir},use_stdio, binary, exit_status]),
321 %% stream_loop(YPid, P).
322
323 dir_contains_indexfile(_Dir, []) ->
324 false;
325 dir_contains_indexfile(Dir, [File|R]) ->
326 case file:read_file_info(filename:join(Dir, File)) of
327 {ok, _} ->
328 true;
329 _Else ->
330 dir_contains_indexfile(Dir, R)
331 end.
6e96a14 @klacke indendation cleanup
authored
332
896b8b1 @hce Fix all.zip routine.
hce authored
333 dir_contains_indexfile(Dir) ->
334 Indexfiles = [".yaws.auth", "index.yaws", "index.html", "index.htm"],
335 dir_contains_indexfile(Dir, Indexfiles).
336
337 dig_through_dir(Basedirlen, Dir, ForbiddenPaths, RE_ForbiddenNames) ->
338 Dir1 = string:sub_string(Dir, Basedirlen),
339 case {lists:member(Dir1, ForbiddenPaths),
340 dir_contains_indexfile(Dir)} of
341 {true,_} ->
342 [];
343 {_,true} ->
344 [];
345 {false, false} ->
346 {ok, Files} = file:list_dir(Dir),
347 lists:foldl(fun(I, Acc) ->
6e96a14 @klacke indendation cleanup
authored
348 Filename = filename:join(Dir, I),
349 case {file:read_file_info(Filename),
350 re:run(Filename, RE_ForbiddenNames)} of
351 {_, {match, _}} ->
352 Acc;
353 {{ok, #file_info{type=directory}}, _} ->
354 Acc ++ dig_through_dir(
355 Basedirlen,
356 Filename,
357 ForbiddenPaths,
358 RE_ForbiddenNames);
359 {{ok, #file_info{type=regular}}, _} ->
360 Acc ++ [string:sub_string(
361 Filename, Basedirlen)];
362 _Else ->
363 Acc %% Ignore other files
364 end
896b8b1 @hce Fix all.zip routine.
hce authored
365 end, [], Files)
366 end.
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
367
896b8b1 @hce Fix all.zip routine.
hce authored
368 dig_through_dir(Dir, ForbiddenPaths, RE_ForbiddenNames) ->
369 dig_through_dir(length(Dir) + 1,
370 Dir,
371 ForbiddenPaths,
372 RE_ForbiddenNames).
2e8e005 @mbj4668 Added auto-generate all.zip to dir listings. It needs the zip comman…
mbj4668 authored
373
896b8b1 @hce Fix all.zip routine.
hce authored
374 stream_loop(YPid, P, FinishedFun) ->
2e8e005 @mbj4668 Added auto-generate all.zip to dir listings. It needs the zip comman…
mbj4668 authored
375 receive
0be3c7e @klacke untabified all of yaws
authored
376 {P, {data, Data}} ->
377 yaws_api:stream_chunk_deliver_blocking(YPid, Data),
896b8b1 @hce Fix all.zip routine.
hce authored
378 stream_loop(YPid, P, FinishedFun);
0be3c7e @klacke untabified all of yaws
authored
379 {P, {exit_status, _}} ->
896b8b1 @hce Fix all.zip routine.
hce authored
380 yaws_api:stream_chunk_end(YPid),
381 FinishedFun();
0be3c7e @klacke untabified all of yaws
authored
382 {'EXIT', YPid, Status} ->
896b8b1 @hce Fix all.zip routine.
hce authored
383 FinishedFun(),
0be3c7e @klacke untabified all of yaws
authored
384 exit(Status);
385 Else ->
896b8b1 @hce Fix all.zip routine.
hce authored
386 FinishedFun(),
0be3c7e @klacke untabified all of yaws
authored
387 error_logger:error_msg("Could not deliver zip file: ~p\n", [Else])
2e8e005 @mbj4668 Added auto-generate all.zip to dir listings. It needs the zip comman…
mbj4668 authored
388 end.
389
390
81a2890 @carsten3347 Removed `/?N=n' etc from links for files.
carsten3347 authored
391 %% Removed code that appendended Qry to the file name.
392 %% It might still be a good idea in case type==directory.
393 %% Was that the intention?
394 %% Carsten
2e8e005 @mbj4668 Added auto-generate all.zip to dir listings. It needs the zip comman…
mbj4668 authored
395 %%
396 %% yes, that was the intention. fixed now (mbj)
397 %% ... and maybe we should just remove this conversation in the next checkin :)
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
398 file_entry({ok, FI}, _DirName, Name, Qry, Descriptions) ->
21abc5b @klacke Initial revision
authored
399 ?Debug("file_entry(~p) ", [Name]),
400 Ext = filename:extension(Name),
401 {Gif, Alt} = list_gif(FI#file_info.type, Ext),
2e8e005 @mbj4668 Added auto-generate all.zip to dir listings. It needs the zip comman…
mbj4668 authored
402 QryStr = if FI#file_info.type == directory -> Qry;
0be3c7e @klacke untabified all of yaws
authored
403 true -> ""
404 end,
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
405
406 Description = get_description(Name,Descriptions),
407
455578a @vinoski major trailing whitespace cleanup
vinoski authored
408 Entry =
0be3c7e @klacke untabified all of yaws
authored
409 ?F(" <tr>\n"
410 " <td><img src=~p alt=~p/><a href=~p title=~p>~s</a></td>\n"
411 " <td>~s</td>\n"
412 " <td>~s</td>\n"
413 " <td>~s</td>\n"
414 " </tr>\n",
415 ["/icons/" ++ Gif,
416 Alt,
417 yaws_api:url_encode(Name) ++ QryStr,
418 Name,
54139d8 @klacke prepare for 1.81
authored
419 trim(Name,?FILE_LEN_SZ),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
420 datestr(FI),
0be3c7e @klacke untabified all of yaws
authored
421 sizestr(FI),
6e96a14 @klacke indendation cleanup
authored
422 Description]),
21abc5b @klacke Initial revision
authored
423 ?Debug("Entry:~p", [Entry]),
6e96a14 @klacke indendation cleanup
authored
424
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
425 {true, {Name, FI#file_info.mtime, FI#file_info.size, Description, Entry}};
426
427 file_entry(_Err, _, _Name, _, _) ->
2129adc @klacke ""
authored
428 ?Debug("no entry for ~p: ~p", [_Name, _Err]),
21abc5b @klacke Initial revision
authored
429 false.
430
22bbba4 Fixed the indentation of directory listings.
Tobbe Tornquist authored
431 trim(L,N) ->
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
432 trim(L,N,[]).
6c7d7a4 @klacke configure/latex support and also slightly nicer listdir output by Han…
authored
433 trim([_H1,_H2,_H3]=[H|T], 3=I, Acc) ->
434 trim(T, I-1, [H|Acc]);
435 trim([_H1,_H2,_H3|_T], 3=_I, Acc) ->
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
436 lists:reverse(Acc) ++ "..&gt;";
22bbba4 Fixed the indentation of directory listings.
Tobbe Tornquist authored
437 trim([H|T], I, Acc) ->
438 trim(T, I-1, [H|Acc]);
6c7d7a4 @klacke configure/latex support and also slightly nicer listdir output by Han…
authored
439 trim([], _I, Acc) ->
22bbba4 Fixed the indentation of directory listings.
Tobbe Tornquist authored
440 lists:reverse(Acc).
21abc5b @klacke Initial revision
authored
441
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
442 %% FI -> 16-Jan-2006 23:06
455578a @vinoski major trailing whitespace cleanup
vinoski authored
443 datestr(FI) ->
31fdaae @klacke pam cleanup, add env record, yaws_ls enhancements by doccarcass@gmail…
authored
444 {{Year, Month, Day}, {Hour, Min, _}} = FI#file_info.mtime,
445 io_lib:format("~s-~s-~w ~s:~s",
0be3c7e @klacke untabified all of yaws
authored
446 [yaws:mk2(Day),yaws:month(Month),Year,
447 yaws:mk2(Hour),yaws:mk2(Min)]).
22bbba4 Fixed the indentation of directory listings.
Tobbe Tornquist authored
448
21abc5b @klacke Initial revision
authored
449 sizestr(FI) when FI#file_info.size > 1000000 ->
22bbba4 Fixed the indentation of directory listings.
Tobbe Tornquist authored
450 ?F("~.1fM", [FI#file_info.size / 1000000]);
21abc5b @klacke Initial revision
authored
451 sizestr(FI) when FI#file_info.size > 1000 ->
22bbba4 Fixed the indentation of directory listings.
Tobbe Tornquist authored
452 ?F("~wk", [trunc(FI#file_info.size / 1000)]);
2e8e005 @mbj4668 Added auto-generate all.zip to dir listings. It needs the zip comman…
mbj4668 authored
453 sizestr(FI) when FI#file_info.size == 0 ->
454 ?F("0k", []);
06a1bef @klacke ""
authored
455 sizestr(_FI) ->
22bbba4 Fixed the indentation of directory listings.
Tobbe Tornquist authored
456 ?F("1k", []). % As apache does it...
21abc5b @klacke Initial revision
authored
457
458 list_gif(directory, ".") ->
459 {"back.gif", "[DIR]"};
455578a @vinoski major trailing whitespace cleanup
vinoski authored
460 list_gif(regular, ".txt") ->
21abc5b @klacke Initial revision
authored
461 {"text.gif", "[TXT]"};
462 list_gif(regular, ".c") ->
a664cbf @carsten3347 Modified ALT texts for better appearance in text browsers.
carsten3347 authored
463 {"c.gif", "[&nbsp;&nbsp;&nbsp;]"};
21abc5b @klacke Initial revision
authored
464 list_gif(regular, ".dvi") ->
a664cbf @carsten3347 Modified ALT texts for better appearance in text browsers.
carsten3347 authored
465 {"dvi.gif", "[&nbsp;&nbsp;&nbsp;]"};
21abc5b @klacke Initial revision
authored
466 list_gif(regular, ".pdf") ->
a664cbf @carsten3347 Modified ALT texts for better appearance in text browsers.
carsten3347 authored
467 {"pdf.gif", "[&nbsp;&nbsp;&nbsp;]"};
21abc5b @klacke Initial revision
authored
468 list_gif(regular, _) ->
a664cbf @carsten3347 Modified ALT texts for better appearance in text browsers.
carsten3347 authored
469 {"layout.gif", "[&nbsp;&nbsp;&nbsp;]"};
21abc5b @klacke Initial revision
authored
470 list_gif(directory, _) ->
cd812ff @klacke ""
authored
471 {"dir.gif", "[DIR]"};
2e8e005 @mbj4668 Added auto-generate all.zip to dir listings. It needs the zip comman…
mbj4668 authored
472 list_gif(zip, _) ->
473 {"compressed.gif", "[DIR]"};
cd812ff @klacke ""
authored
474 list_gif(_, _) ->
475 {"unknown.gif", "[OTH]"}.
Something went wrong with that request. Please try again.