[BACK]Return to dir-index-bozo.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / libexec / httpd

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/libexec/httpd/dir-index-bozo.c between version 1.19.4.1.2.3 and 1.19.4.2

version 1.19.4.1.2.3, 2019/06/15 15:57:32 version 1.19.4.2, 2016/04/10 10:33:11
Line 3 
Line 3 
 /*      $eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $  */  /*      $eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $  */
   
 /*  /*
  * Copyright (c) 1997-2019 Matthew R. Green   * Copyright (c) 1997-2014 Matthew R. Green
  * All rights reserved.   * All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
Line 45 
Line 45 
   
 #include "bozohttpd.h"  #include "bozohttpd.h"
   
   static void
   directory_hr(bozohttpd_t *httpd)
   {
   
           bozo_printf(httpd,
                   "<hr noshade align=\"left\" width=\"80%%\">\r\n\r\n");
   }
   
 /*  /*
  * output a directory index.  return 1 if it actually did something..   * output a directory index.  return 1 if it actually did something..
  */   */
Line 54  bozo_dir_index(bozo_httpreq_t *request, 
Line 62  bozo_dir_index(bozo_httpreq_t *request, 
         bozohttpd_t *httpd = request->hr_httpd;          bozohttpd_t *httpd = request->hr_httpd;
         struct stat sb;          struct stat sb;
         struct dirent **de, **deo;          struct dirent **de, **deo;
           struct tm *tm;
         DIR *dp;          DIR *dp;
         char buf[MAXPATHLEN];          char buf[MAXPATHLEN];
         char *file = NULL, *printname = NULL, *p;          char spacebuf[48];
         int k, j;          char *file = NULL, *printname = NULL;
           int l, k, j, i;
   
         if (!isindex || !httpd->dir_indexing)          if (!isindex || !httpd->dir_indexing)
                 return 0;                  return 0;
Line 70  bozo_dir_index(bozo_httpreq_t *request, 
Line 80  bozo_dir_index(bozo_httpreq_t *request, 
                 file[strlen(file) - strlen(httpd->index_html)] = '\0';                  file[strlen(file) - strlen(httpd->index_html)] = '\0';
                 dirpath = file;                  dirpath = file;
         }          }
         debug((httpd, DEBUG_FAT, "bozo_dir_index: dirpath '%s'", dirpath));          debug((httpd, DEBUG_FAT, "bozo_dir_index: dirpath ``%s''", dirpath));
         if (stat(dirpath, &sb) < 0 ||          if (stat(dirpath, &sb) < 0 ||
             (dp = opendir(dirpath)) == NULL) {              (dp = opendir(dirpath)) == NULL) {
                 if (errno == EPERM)                  if (errno == EPERM)
                         bozo_http_error(httpd, 403, request,                          (void)bozo_http_error(httpd, 403, request,
                                         "no permission to open directory");                              "no permission to open directory");
                 else if (errno == ENOENT)                  else if (errno == ENOENT)
                         bozo_http_error(httpd, 404, request, "no file");                          (void)bozo_http_error(httpd, 404, request, "no file");
                 else                  else
                         bozo_http_error(httpd, 500, request, "open directory");                          (void)bozo_http_error(httpd, 500, request,
                                           "open directory");
                 goto done;                  goto done;
                 /* NOTREACHED */                  /* NOTREACHED */
         }          }
Line 106  bozo_dir_index(bozo_httpreq_t *request, 
Line 117  bozo_dir_index(bozo_httpreq_t *request, 
 #else  #else
         printname = bozostrdup(httpd, request, request->hr_file);          printname = bozostrdup(httpd, request, request->hr_file);
 #endif /* !NO_USER_SUPPORT */  #endif /* !NO_USER_SUPPORT */
         if ((p = strstr(printname, httpd->index_html)) != NULL) {  
                 if (strcmp(printname, httpd->index_html) == 0)  
                         strcpy(printname, "/"); /* is ``slashdir'' */  
                 else  
                         *p = '\0';              /* strip unwanted ``index_html'' */  
         }  
         if ((p = bozo_escape_html(httpd, printname)) != NULL) {  
                 free(printname);  
                 printname = p;  
         }  
   
         bozo_printf(httpd,          bozo_printf(httpd,
                 "<!DOCTYPE html>\r\n"                  "<html><head><title>Index of %s</title></head>\r\n",
                 "<html><head><meta charset=\"utf-8\"/>\r\n"  
                 "<style type=\"text/css\">\r\n"  
                 "table {\r\n"  
                 "\tborder-top: 1px solid black;\r\n"  
                 "\tborder-bottom: 1px solid black;\r\n"  
                 "}\r\n"  
                 "th { background: aquamarine; }\r\n"  
                 "tr:nth-child(even) { background: lavender; }\r\n"  
                 "</style>\r\n");  
         bozo_printf(httpd, "<title>Index of %s</title></head>\r\n",  
                 printname);                  printname);
         bozo_printf(httpd, "<body><h1>Index of %s</h1>\r\n",          bozo_printf(httpd, "<body><h1>Index of %s</h1>\r\n",
                 printname);                  printname);
         bozo_printf(httpd,          bozo_printf(httpd, "<pre>\r\n");
                 "<table cols=3>\r\n<thead>\r\n"  #define NAMELEN 40
                 "<tr><th>Name<th>Last modified<th align=right>Size\r\n"  #define LMODLEN 19
                 "<tbody>\r\n");          bozo_printf(httpd, "Name                                     "
               "Last modified          "
               "Size\n");
           bozo_printf(httpd, "</pre>");
           directory_hr(httpd);
           bozo_printf(httpd, "<pre>");
   
         for (j = k = scandir(dirpath, &de, NULL, alphasort), deo = de;          for (j = k = scandir(dirpath, &de, NULL, alphasort), deo = de;
             j--; de++) {              j--; de++) {
Line 148  bozo_dir_index(bozo_httpreq_t *request, 
Line 144  bozo_dir_index(bozo_httpreq_t *request, 
                      httpd->hide_dots && name[0] == '.'))                       httpd->hide_dots && name[0] == '.'))
                         continue;                          continue;
   
                 if (bozo_check_special_files(request, name, false))  
                         continue;  
   
                 snprintf(buf, sizeof buf, "%s/%s", dirpath, name);                  snprintf(buf, sizeof buf, "%s/%s", dirpath, name);
                 if (stat(buf, &sb))                  if (stat(buf, &sb))
                         nostat = 1;                          nostat = 1;
   
                   l = 0;
   
                 urlname = bozo_escape_rfc3986(httpd, name, 0);                  urlname = bozo_escape_rfc3986(httpd, name, 0);
                 htmlname = bozo_escape_html(httpd, name);                  htmlname = bozo_escape_html(httpd, name);
                 if (htmlname == NULL)                  if (htmlname == NULL)
                         htmlname = name;                          htmlname = name;
                 bozo_printf(httpd, "<tr><td>");  
                 if (strcmp(name, "..") == 0) {                  if (strcmp(name, "..") == 0) {
                         bozo_printf(httpd, "<a href=\"../\">");                          bozo_printf(httpd, "<a href=\"../\">");
                         bozo_printf(httpd, "Parent Directory");                          l += bozo_printf(httpd, "Parent Directory");
                 } else if (!nostat && S_ISDIR(sb.st_mode)) {                  } else if (S_ISDIR(sb.st_mode)) {
                         bozo_printf(httpd, "<a href=\"%s/\">", urlname);                          bozo_printf(httpd, "<a href=\"%s/\">", urlname);
                         bozo_printf(httpd, "%s/", htmlname);                          l += bozo_printf(httpd, "%s/", htmlname);
                 } else if (strchr(name, ':') != NULL) {                  } else if (strchr(name, ':') != NULL) {
                         /* RFC 3986 4.2 */                          /* RFC 3986 4.2 */
                         bozo_printf(httpd, "<a href=\"./%s\">", urlname);                          bozo_printf(httpd, "<a href=\"./%s\">", urlname);
                         bozo_printf(httpd, "%s", htmlname);                          l += bozo_printf(httpd, "%s", htmlname);
                 } else {                  } else {
                         bozo_printf(httpd, "<a href=\"%s\">", urlname);                          bozo_printf(httpd, "<a href=\"%s\">", urlname);
                         bozo_printf(httpd, "%s", htmlname);                          l += bozo_printf(httpd, "%s", htmlname);
                 }                  }
                 if (htmlname != name)                  if (htmlname != name)
                         free(htmlname);                          free(htmlname);
                 bozo_printf(httpd, "</a>");                  bozo_printf(httpd, "</a>");
   
                   /* NAMELEN spaces */
                   /*LINTED*/
                   assert(/*CONSTCOND*/sizeof(spacebuf) > NAMELEN);
                   i = (l < NAMELEN) ? (NAMELEN - l) : 0;
                   i++;
                   memset(spacebuf, ' ', (size_t)i);
                   spacebuf[i] = '\0';
                   bozo_printf(httpd, "%s", spacebuf);
                   l += i;
   
                 if (nostat)                  if (nostat)
                         bozo_printf(httpd, "<td>?<td>?\r\n");                          bozo_printf(httpd, "?                         ?");
                 else {                  else {
                         unsigned long long len;                          tm = gmtime(&sb.st_mtime);
                           strftime(buf, sizeof buf, "%d-%b-%Y %R", tm);
                         strftime(buf, sizeof buf, "%d-%b-%Y %R", gmtime(&sb.st_mtime));                          l += bozo_printf(httpd, "%s", buf);
                         bozo_printf(httpd, "<td>%s", buf);  
                           /* LMODLEN spaces */
                           /*LINTED*/
                           assert(/*CONSTCOND*/sizeof(spacebuf) > LMODLEN);
                           i = (l < (LMODLEN+NAMELEN+1)) ?
                                   ((LMODLEN+NAMELEN+1) - l) : 0;
                           i++;
                           memset(spacebuf, ' ', (size_t)i);
                           spacebuf[i] = '\0';
                           bozo_printf(httpd, "%s", spacebuf);
   
                         len = ((unsigned long long)sb.st_size + 1023) / 1024;                          bozo_printf(httpd, "%12llukB",
                         bozo_printf(httpd, "<td align=right>%llukB", len);                                      (unsigned long long)sb.st_size >> 10);
                 }                  }
                 bozo_printf(httpd, "\r\n");                  bozo_printf(httpd, "\r\n");
         }          }
Line 196  bozo_dir_index(bozo_httpreq_t *request, 
Line 209  bozo_dir_index(bozo_httpreq_t *request, 
         while (k--)          while (k--)
                 free(deo[k]);                  free(deo[k]);
         free(deo);          free(deo);
         bozo_printf(httpd, "</table>\r\n");          bozo_printf(httpd, "</pre>");
           directory_hr(httpd);
         bozo_printf(httpd, "</body></html>\r\n\r\n");          bozo_printf(httpd, "</body></html>\r\n\r\n");
         bozo_flush(httpd, stdout);          bozo_flush(httpd, stdout);
   
Line 206  done:
Line 220  done:
         return 1;          return 1;
 }  }
 #endif /* NO_DIRINDEX_SUPPORT */  #endif /* NO_DIRINDEX_SUPPORT */
   

Legend:
Removed from v.1.19.4.1.2.3  
changed lines
  Added in v.1.19.4.2

CVSweb <webmaster@jp.NetBSD.org>