- The diff below implements "combined log format" used by several
  popular web traffic analyzers, when the COMBINED_LOG_FORMAT macro is
  defined. ie "gcc althttpd.c -DCOMBINED_LOG_FORMAT
  -o /usr/local/bin/althttpd"

- The date should now be in the right format. I think the reason it
  still "worked" in the wrong format is the use of the abbreviated 
  textual month in the current locale as part of the format spec which
  in the strictest sense requires analyzers to just treat that part as
  opaq text.

- Also in this diff is a quick addressing of the CGI POST handling code
  path's use of a unchecked fopen(), which kept me dead in the water
  back when I was first starting.

- btw for other list archaeologists trying to squash bugs, my problem
  with .jpg files not loading was because they somehow had the execute
  flag turned on (digital camera's FAT fs). Remember that althttpd
  simply looks at that criteria for the CGI code path. 

- Having to go to named based virtual servers over IP based virtual
  servers is what finally forced my transition from the boa web server.
  The althttpd xinetd stunnel combination makes an outstanding strategy
  for bare-minimum nonsense, low resource usage, and acceptable
  security risk. 

--- src/althttpd.c      2011-12-28 15:42:28.000000000 -0500
+++ althttpd.c  2012-05-31 00:33:05.000000000 -0400
@@ -200,11 +200,17 @@
     if( zAgent==0 || zAgent[0]==0 ) zAgent = "*";
     time(&now);
     pTm = localtime(&now);
-    strftime(zDate, sizeof(zDate), "%Y-%m-%d %H:%M:%S", pTm);
     times(&sTms);
     rScale = 1.0/(double)sysconf(_SC_CLK_TCK);
     chdir((zRoot && zRoot[0]) ? zRoot : "/");
     if( (log = fopen(zLogFile,"a"))!=0 ){
+#ifdef COMBINED_LOG_FORMAT
+      strftime(zDate, sizeof(zDate), "%d/%b/%Y:%H:%M:%S %z", pTm);
+      fprintf(log, "%s - - [%s] \"%s %s %s\" %d %d \"%s\" \"%s\"\n", 
+              zRemoteAddr, zDate, zMethod, zScript, zProtocol, 
+              zReplyStatus, nOut, zReferer, zAgent);
+#else
+      strftime(zDate, sizeof(zDate), "%Y-%m-%d %H:%M:%S", pTm);
       fprintf(log, "%s %s %s://%s%s %s %s %d %d %g %g %g %g %d %d %s
%s\n", zDate, zRemoteAddr, zHttp, zHttpHost, zScript, zReferer,
           zReplyStatus, nIn, nOut,
@@ -213,8 +219,8 @@
           rScale*sTms.tms_cutime,
           rScale*sTms.tms_cstime,
           (int)(now - beginTime),
-          nRequest, zAgent, zRM
-      );
+          nRequest, zAgent, zRM);
+#endif
       fclose(log);
       nIn = nOut = 0;
     }
@@ -1021,7 +1027,17 @@
     sprintf(zTmpNamBuf, "/tmp/-post-data-XXXXXX");
     zTmpNam = zTmpNamBuf;
     mkstemp(zTmpNam);
-    out = fopen(zTmpNam,"w");
+    if((out = fopen(zTmpNam,"w")) == NULL) {
+      StartResponse("500 Internal Server Error");
+      nOut += printf(
+        "Content-type: text/html\r\n"
+        "\r\n"
+        "\nhint: check permissions on /tmp"
+        "</body>\n");
+      MakeLogEntry(0);
+      exit(0);
+    }
+
     zBuf = SafeMalloc( len );
     alarm(15 + len/2000);
     n = fread(zBuf,1,len,stdin);


-- 
www.thomasstover.com
_______________________________________________
fossil-users mailing list
[email protected]
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to