--- dir_cgi-orig-2.c 2006-02-04 14:57:58.000000000 +0100 +++ dir_cgi.c 2006-06-23 11:02:13.000000000 +0200 @@ -40,6 +40,8 @@ #include #include #include +#include +#include struct cgi_dir_entry { char *name; @@ -48,6 +50,7 @@ time_t last_modified; }; + static int cde_compare(const void *a, const void *b) { return strcmp(((struct cgi_dir_entry *) a)->name, ((struct cgi_dir_entry *) b)->name); @@ -108,6 +111,14 @@ } } +static char *iso_date(const time_t t) +{ + static char buf[20]; + + strftime(buf, 20, "%Y-%m-%d %T", gmtime(&t)); + return buf; +} + static int sort_and_print(struct cgi_dir_entry *p, size_t n) { int notinroot; @@ -120,45 +131,57 @@ printf("Cache-Control: max-age=900\n"); printf("Content-Type: text/html\n\n"); script_name = getenv("SCRIPT_NAME"); - printf("index"); + printf("<html><head><title>Index"); if (script_name) { notinroot = strcmp(script_name, "/"); printf(" of %s", script_name); } else notinroot = 1; - printf("

index"); + printf("\n"); + printf("\n"); + printf("

Index"); if (script_name) printf(" of %s", script_name); - printf("

\n"); - printf("

directories:

\n"); + printf("
\n"); + printf("
%-19s  %12s  %s\n\n", "Last modified", "Size", "Name");
+
 	for (i = 0; i < n; i++) {
 		if (S_ISDIR(p[i].mode)) {
-			printf("
  • "); escape_html_print(p[i].name); - printf("
  • \n"); + printf("/\n"); } } - printf("

    files:

    \n"); + + printf("

    \n"); + printf("%s", getenv("SERVER_SOFTWARE")); + printf("\n"); return 0; } static int hide_name(const char *s) { - return s[0] == 0 || s[0] == '.'; + if (getenv("SHOW_DOTFILES")) + return s[0] == 0 || (s[0] == '.' && !s[1] ) || access(s, R_OK); + return s[0] == 0 || (s[0] == '.' && s[1] != '.') || access(s, R_OK); } static int do_dir(const char *dirname) @@ -218,3 +241,4 @@ { return do_dir("."); } +