home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / analg211.zip / formgen.c < prev    next >
Text File  |  1997-03-14  |  9KB  |  233 lines

  1. /*** analog 2.1 ***/
  2. /* Please read Readme.html, or http://www.statslab.cam.ac.uk/~sret1/analog/  */
  3.  
  4. /*** formgen.c; generate a form for the analog form interface ***/
  5.  
  6. #include "analhea2.h"
  7.  
  8. void genopts(FILE *outf, char name[17], char plural[16], int sortby,
  9.          char codeletter)
  10. {
  11.   fprintf(outf, "\n<h3>%s options</h3>\n\n", name);
  12.   fprintf(outf, "Sort the %s \n<select name=%cs size=1>\n", name, codeletter);
  13.   fprintf(outf, "<option value=2%s>alphabetically (*)\n",
  14.       (sortby==ALPHABETICAL)?" selected":"");
  15.   fprintf(outf, "<option value=1%s>by volume of traffic (+)\n",
  16.       (sortby==BYBYTES)?" selected":"");
  17.   fprintf(outf, "<option value=0%s>by number of requests (*)\n",
  18.       (sortby==BYREQUESTS)?" selected":"");
  19.   if (codeletter != 'B' && codeletter != 'b' && codeletter != 'f') {
  20.     fprintf(outf, "<option value=4%s>by requests for pages (*)\n",
  21.         (sortby==BYPAGES)?" selected":"");
  22.   }
  23.   fprintf(outf, "</select>\n");
  24.   fprintf(outf, "<br>(*) Include all %s with at least\n", plural);
  25.   fprintf(outf,
  26.       "<input type=TEXT name=\"%ca\" maxlength=6 size=6> requests%s\n",
  27.       codeletter,
  28.       (codeletter != 'B' && codeletter != 'b' && codeletter != 'f')?"/page requests":"");
  29.   fprintf(outf, "<b>or</b> the top ");
  30.   fprintf(outf, "<input type=TEXT name=\"%cb\" maxlength=3 size=3> %s.\n",
  31.       codeletter, plural);
  32.   fprintf(outf, "<br>(+) Include all %s with at least\n", plural);
  33.   fprintf(outf, "<input type=TEXT name=\"%cc\" maxlength=6 size=6> bytes\n",
  34.       codeletter);
  35.   fprintf(outf, "transferred <b>or</b> the top ");
  36.   fprintf(outf, "<input type=TEXT name=\"%cd\" maxlength=3 size=3> %s.\n",
  37.       codeletter, plural);
  38. }
  39.  
  40. void repchoice(FILE *outf, char name[MAXSTRINGLENGTH], char codeletter,
  41.            flag qq)
  42. {
  43.   fprintf(outf, "<BR><INPUT TYPE=radio NAME=%cq VALUE=1%s> [On] ",
  44.       codeletter, qq?" checked":"");
  45.   fprintf(outf, "<INPUT TYPE=radio NAME=%cq VALUE=0%s> [Off] %s\n",
  46.       codeletter, qq?"":" checked", name);
  47. }
  48.  
  49. void formgen(void)
  50. {
  51.   extern flag xq, mq, Wq, dq, Dq, hq, Hq, oq, Sq, iq, rq, tq, Bq, bq, fq, eq, cq;
  52.   extern char reportorder[];
  53.   extern int osortby, isortby, Ssortby, rsortby, fsortby, bsortby, Bsortby, tsortby;
  54.   extern int dirlevel;
  55.   extern char *hostname, *hosturl, *logourl, *commandname;
  56.   extern char *outfile;
  57.   extern struct timestruct fromtime, totime;
  58.  
  59.   char *ro;
  60.   FILE *outf;
  61.  
  62.   if (STREQ(outfile, "stdout"))
  63.     outf = stdout;
  64.  
  65.   else if ((outf = fopen(outfile, "w")) == NULL) {
  66.     fprintf(stderr, "%s: Error: failed to open output file %s for writing.\n",
  67.         commandname, outfile);
  68.     exit(ERR);  /* shouldn't get here because also tested at the beginning */
  69.   }
  70.  
  71.   fprintf(outf, "<html><head>\n");
  72.   fprintf(outf, "<title>Analog form interface</title>\n");
  73.   fprintf(outf, "</head>\n\n");
  74.   fprintf(outf, "<body>\n");
  75.   if (hosturl[0] == '-')
  76.     fprintf(outf, "<h1><img src=\"%s\" alt=\"\"> Analog form interface for %s</h1>\n",
  77.        logourl, hostname);
  78.   else
  79.     fprintf(outf, "<h1><img src=\"%s\" alt=\"\"> Analog form interface for <a HREF=\"%s\">%s</a></h1>\n",
  80.        logourl, hosturl, hostname);    
  81.   fprintf(outf, "<form action=\""FORMPROG"\" method=\"GET\">\n");
  82.   fprintf(outf, "<hr><i>You can set any options you like below. But they should all be set to\n");
  83.   fprintf(outf, "sensible default values, so you can ignore any of them too.</i>\n");
  84.   fprintf(outf, "<hr>\n<h2>1. Report choices</h2>\n");
  85.   fprintf(outf, "<i>See <a href=\"http://www.statslab.cam.ac.uk/~sret1/analog/\">the analog\n");
  86.   fprintf(outf, "home page</a> for the meanings of the various reports.</i>\n\n");
  87.   fprintf(outf, "<p>\n<h3>Which reports do you want to see?</h3>\n");
  88.   repchoice(outf, "General statistics", 'x', xq);
  89.   
  90.   for (ro = reportorder; *ro != '\0'; ro++) {
  91.     switch(*ro) {
  92.     case 'b':
  93.       repchoice(outf, "Browser summary", 'b', bq);
  94.       break;
  95.     case 'B':
  96.       repchoice(outf, "Browser report", 'B', Bq);
  97.       break;
  98.     case 'c':
  99.       repchoice(outf, "Status code report", 'c', cq);
  100.       break;
  101.     case 'd':
  102.       repchoice(outf, "Daily summary", 'd', dq);
  103.       break;
  104.     case 'D':
  105.       repchoice(outf, "Daily report", 'D', Dq);
  106.       break;
  107.     case 'e':
  108.       repchoice(outf, "Error report", 'e', eq);
  109.       break;
  110.     case 'f':
  111.       repchoice(outf, "Referrer report", 'f', fq);
  112.       break;
  113.     case 'h':
  114.       repchoice(outf, "Hourly summary", 'h', hq);
  115.       break;
  116.     case 'H':
  117.       repchoice(outf, "Hourly report", 'H', Hq);
  118.       break;
  119.     case 'i':
  120.       repchoice(outf, "Directory report", 'i', iq);
  121.       break;
  122.     case 'm':
  123.       repchoice(outf, "Monthly report", 'm', mq);
  124.       break;
  125.     case 'o':
  126.       repchoice(outf, "Domain report", 'o', oq);
  127.       break;
  128.     case 'r':
  129.       repchoice(outf, "Request report", 'r', rq);
  130.       break;
  131.     case 'S':
  132.       repchoice(outf, "Host report", 'S', Sq);
  133.       break; 
  134.     case 't':
  135.       repchoice(outf, "File type report", 't', tq);
  136.       break;
  137.     case 'W':
  138.       repchoice(outf, "Weekly report", 'W', Wq);
  139.       break;
  140.     }
  141.   }
  142.  
  143.   fprintf(outf, "<p><i>You can now run the program: <input type=submit value=\"Produce statistics\">\n");
  144.   fprintf(outf, "<br>Or you can fill in the options below for individual reports.\n");
  145.   fprintf(outf, "You can fill in the </i>(+)<i> or </i>(*)<i> in each section according to which sort method you select.\n");
  146.   fprintf(outf, "You can use <input type=TEXT name=\"vo\" maxlength=4 size=4 value=\"10M\"> bytes to mean 10 Megabytes etc.</i>\n");
  147.  
  148.   fprintf(outf, "<hr>\n<h2>2. Detailed report options</h2>\n");
  149.   for (ro = reportorder; *ro != '\0'; ro++) {
  150.     switch(*ro) {
  151.     case 'b':
  152.       genopts(outf, "Browser summary", "browsers", bsortby, 'b');
  153.       break;
  154.     case 'B':
  155.       genopts(outf, "Browser report", "browsers", Bsortby, 'B');
  156.       break;
  157.     case 'f':
  158.       genopts(outf, "Referrer report", "referring URLs", fsortby, 'f');
  159.       break;
  160.     case 'i':
  161.       genopts(outf, "Directory report", "directories", isortby, 'i');
  162.       fprintf(outf, "<br>Print directories to depth ");
  163.       fprintf(outf, "<input type=text name=\"ie\" maxlength=1 size=1 value=%d>\n", dirlevel);
  164.       break;
  165.     case 'o':
  166.       genopts(outf, "Domain report", "domains", osortby, 'o');
  167.       break;
  168.     case 'r':
  169.       genopts(outf, "Request report", "requests", rsortby, 'r');
  170.       fprintf(outf, "<br>Show\n");
  171.       fprintf(outf, "<select name=\"rt\" size=1>\n");
  172.       fprintf(outf, "<option value=\"f\" selected>all files\n");
  173.       fprintf(outf, "<option value=\"p\">pages only\n");
  174.       fprintf(outf, "</select>\n; include links to\n");
  175.       fprintf(outf, "<select name=\"rl\" size=1>\n");
  176.       fprintf(outf, "<option value=\"f\">all files\n");
  177.       fprintf(outf, "<option value=\"p\" selected>pages only\n");
  178.       fprintf(outf, "<option value=\"n\">no files\n");
  179.       fprintf(outf, "</select>\n");
  180.       break;
  181.     case 'S':
  182.       genopts(outf, "Host report", "hosts", Ssortby, 'S');
  183.       break;
  184.     case 't':
  185.       genopts(outf, "File type report", "extensions", tsortby, 't');
  186.       break;
  187.     }
  188.   }
  189.  
  190.  
  191.   fprintf(outf, "<hr>\n\n<h2>3. Analysing only part of the logfile</h2>\n");
  192.   fprintf(outf, "<b>Only certain dates</b>\n");
  193.   fprintf(outf, "<br>You can analyse only the requests from certain dates.\n");
  194.   fprintf(outf, "Enter the range of dates below in the from <i>yymmdd</i>;\n");
  195.   fprintf(outf, "e.g., 950701 for 1st July 1995 (or fill in just one box\n");
  196.   fprintf(outf, "to limit the range of dates on just one side).");
  197.   fprintf(outf, "<br>From <input type=TEXT name=\"fr\" maxlength=10 size=6");
  198.   if (fromtime.code > -INFINITY)
  199.     fprintf(outf, " value=\"%02d%02d%02d\"", fromtime.year % 100,
  200.        fromtime.monthno + 1, fromtime.date);
  201.   fprintf(outf, ">\nto <input type=TEXT name=\"to\" maxlength=10 size=6");
  202.   if (totime.code < INFINITY)
  203.     fprintf(outf, " value=\"%02d%02d%02d\"", totime.year % 100,
  204.        totime.monthno + 1, totime.date);
  205.   fprintf(outf, ">\n\n");
  206.  
  207.   fprintf(outf, "<p><b>Only certain requested files</b>\n");
  208.   fprintf(outf, "<br>Only look at the following requested files (list, separated by commas; can contain wild character *)\n");
  209.   fprintf(outf, "<br><input type=TEXT name=\"fy\" size=60>\n");
  210.   fprintf(outf, "<br>Ignore the following files\n");
  211.   fprintf(outf, "<br><input type=TEXT name=\"fi\" size=60>\n");
  212.  
  213.   fprintf(outf, "<hr><h2>4. Layout</h2>\n");
  214.  
  215.   fprintf(outf, "<b>Your organisation's name</b> (for the title of the page)\n");
  216.   fprintf(outf, "<input type=TEXT name=\"or\" value=\"%s\" size=60>\n",
  217.      hostname);
  218.  
  219.   fprintf(outf, "<p><b>Your organisation's home page</b> (leave blank for none)\n");
  220.   fprintf(outf, "<br>URL: <input type=TEXT name=\"ho\" value=\"%s\" size=60>\n",
  221.          hosturl);
  222.  
  223.   fprintf(outf, "<hr><input type=hidden name=\"TZ\" value=\"%s\">\n",
  224.          getenv("TZ")!=NULL?getenv("TZ"):"");  /* gets it twice, but easy */
  225.   fprintf(outf, "<input type=submit value=\"Produce statistics\"> ");
  226.   fprintf(outf, "<input type=reset value=\"Reset form\">\n");
  227.   fprintf(outf, "</form>\n");
  228.   fprintf(outf, "<P> <A HREF=\"http://www.webtechs.com/html-val-svc/\">\n");
  229.   fprintf(outf, "<IMG SRC=\"http://www.webtechs.com/html-val-svc/images/valid_html.gif\" ALT=\"HTML 2.0 Conformant!\"></A>\n");
  230.   fprintf(outf, "</body></html>\n");
  231.  
  232. }
  233.