aboutsummaryrefslogtreecommitdiff
path: root/src/Content.c
blob: b1f6c344e81ec316b04878eb8a5df42e8961abda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
 /*@@
   @file      Content.c
   @date      Wed Sep 13 23:47:43 2000
   @author    Tom Goodale
   @desc 
   The actual content of the web pages.
   Note that this need not be in this thorn, since
   it should just use the interface defined in http_Request.h
   and should never touch the internals.
   @enddesc
   @version $Header$
 @@*/

#include <stdio.h>
#include <string.h>

#include "cctk.h"

#include "util_String.h"

#include "http_Request.h"

#include "http_Auth.h"

static char *rcsid = "$Header$";

CCTK_FILEVERSION(DevThorns_httpd_Content_c)

/********************************************************************
 *********************     Local Data Types   ***********************
 ********************************************************************/

struct httpStaticPage
{
  char *page;
  unsigned int length;
  char *mime_type;
};

/********************************************************************
 ********************* Local Routine Prototypes *********************
 ********************************************************************/

static int RegisterImages(void);

static int MainPage(cGH *cctkGH, httpRequest *request, void *data);
static int ParameterPage(cGH *cctkGH, httpRequest *request, void *data);

static int ShowStaticPage(cGH *cctkGH, httpRequest *request, void *data);

static int TestPage(cGH *cctkGH, httpRequest *request, void *data);

static int AuthPage(cGH *cctkGH, httpRequest *request, void *data);

static int CompareStrings(const void *string1, const void *string2);

/********************************************************************
 ********************* Other Routine Prototypes *********************
 ********************************************************************/

/********************************************************************
 *********************     Local Data   *****************************
 ********************************************************************/

/********************************************************************
 *********************     External Routines   **********************
 ********************************************************************/

 /*@@
   @routine    HTTP_RegisterPages
   @date       Wed Sep 13 23:47:43 2000
   @author     Tom Goodale
   @desc 
   Main page registration routine.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
int HTTP_RegisterPages(void)
{
#ifdef HTTP_DEBUG
  printf("Registering index.html\n");
#endif

  /* Register the master page. */
  HTTP_RegisterPage("/index.html", MainPage, NULL);

  /* Register a duff parameters page */

  HTTP_RegisterPage("/parameters", ParameterPage, NULL);

  /* Register a test page */
  HTTP_RegisterPage("/test_page", TestPage, NULL);

  HTTP_RegisterPage("/auth_page", AuthPage, NULL);

  HTTP_AuthAddUser("user","goodale","foo","none");

  /* Registrer images */
  RegisterImages();
}

/********************************************************************
 *********************     Local Routines   *************************
 ********************************************************************/

 /*@@
   @routine    CompareStrings
   @date       Thu Sep 14 18:57:52 2000
   @author     Tom Goodale
   @desc 
   Case independent string comparison to pass to qsort.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static int CompareStrings(const void *string1, const void *string2)
{
  return Util_StrCmpi(*(const char **)string1, *(const char **)string2);
}

/******************************************************************************
 ***************************** Main Page **************************************
 ******************************************************************************/


static const char *cactus_mainheader = "                                        \
</HEAD>\n                                                                       \
<BODY BGCOLOR=\"#FFFFFF\"                                                       \
        link=\"#1B831D\" vlink=\"#768000\" alink=\"#00FF00\">\n                 \
<center><A HREF=\"http://www.cactuscode.org/\">                                 \
<img src=\"/Images/wwwcactuscodeorg.jpg\"                                       \
        alt=\"Cactus\" BORDER=0></A>                                            \
</A>                                                                            \
<table width=70% border=0><tr><td>                                              \
\n";

static const char *cactus_header = "                                            \
</HEAD>\n                                                                       \
<BODY BGCOLOR=\"#FFFFFF\"                                                       \
        link=\"#1B831D\" vlink=\"#768000\" alink=\"#00FF00\">\n                 \
<center>                                                                        \
</A>                                                                            \
<table width=70% border=0><tr><td>                                              \
\n";

static const char *cactus_footer =                                              \
"</table>"                                                                      \
"\n                                                                             \
<HR size=1>\n                                                                   \
<ADDRESS><DIV ALIGN=left>\n                                                     \
<SMALL>\n                                                                       \
<A HREF=\"http://www.cactuscode.org/\">Cactus Home Page</A><BR>\n\
Cactus Web Interface by <A HREF=\"mailto:cactusmaint@cactuscode.org\">The Cactus Team</A><BR>\n\
</SMALL></DIV></ADDRESS></BODY></HTML>\n";

static const char base_page[] =
"<HTML>\n<HEAD><TITLE>Test Page for Tom's trivial web server</TITLE></HEAD>\
<BODY BGCOLOR=\"#FFFFFF\"                                                       \
        link=\"#1B831D\" vlink=\"#768000\" alink=\"#00FF00\">\n                 \
<center><A HREF=\"http://www.cactuscode.org/\">                                 \
<img src=\"/Images/wwwcactuscodeorg.jpg\"                                       \
        alt=\"Cactus\" BORDER=0></A>                                            \
</A>                                                                            \
</BODY></HTML>";

 /*@@
   @routine    MainPage
   @date       Wed Sep 13 23:47:43 2000
   @author     Tom Goodale
   @desc 
   Displays the main page.
   @enddesc 
   @calls     
   @calledby   
   @history 
   @hdate Thu Sep 14 10:54:22 2000 @hauthor Tom Goodale
   @hdesc  Copied content format from original http thorn
           developed by Werner Benger, with the aesthetic
           enhancements of Gabrielle Allen, John Shalf and
           Ed Seidel.
   @endhistory 

@@*/
static int MainPage(cGH *cctkGH, httpRequest *request, void *data)
{
  int retval;
  char message[4098];

  /* Status message */
  strcpy(message,"HTTP/1.0 200 OK\r\n");
  
  write(request->filedes, message, strlen(message));

  /* Content-Type */
  strcpy(message,"Content-Type: text/html\r\n\r\n");

  write(request->filedes, message, strlen(message));

  /* Start the page */
  strcpy(message,"<HTML><HEAD><TITLE>Running CACTUS Status Information</TITLE>\n");

  write(request->filedes, message, strlen(message));

  /* Write out the main header part */
  write(request->filedes, cactus_mainheader, strlen(cactus_mainheader));

  /* Some blurb */
  strcpy(message, "<br>" 
                  "<center><table cellspacing=5 cellpadding=5 border=0><tr><td valign=top>"
                  "<h3>Simulation web server:</h3>" 
                  "<p>This browser is connected to a Cactus simulation which contains "
                  "a web server thorn. This thorn allows you to monitor the simulation, "
                  "and view and change parameters</p>"
                  "<p>Depending on which other thorns are active, there may be additional "
                  "features available, such as the viewing and downloading of output files</p>");

  write(request->filedes, message, strlen(message));


  /* CONFIGURATION DETAILS */

  sprintf(message, "<h3>Configuration:</h3>"
                   "<ul> <li>Flesh version <FONT COLOR=RED> %s"
                   "</FONT></li>\n"
                   "<li>Code compiled on <FONT COLOR=RED>"
                   __DATE__ "</FONT> at <FONT COLOR=RED>"__TIME__ "</font></li>\n"
                   "</ul>", CCTK_FullVersion());

  write(request->filedes, message, strlen(message));

  /******************************************************************************/

  /* NEW COLUMN */

  strcpy(message, "</td><td valign=top>");

  write(request->filedes, message, strlen(message));

  /*******************************************************************************/

  /* CURRENT STATE OF SIMULATION */

  if (cctkGH)
  {

    sprintf(message, "<H3> Current state:</h3> "
                     "<ul><li>Physical time <FONT COLOR=RED> %f"
                     "</FONT> \n"
                     "<li>Iteration number <FONT COLOR=RED> %d"
                     "</FONT></li>\n",
                     cctkGH->cctk_time,
                     cctkGH->cctk_iteration);
 
  }
  else
  {
     strcpy(message, "<li>Current cactus time is unknown</li>\n");
  }

  write(request->filedes, message, strlen(message));

  strcpy(message, "</ul>");

  write(request->filedes, message, strlen(message));

  /* LIST COMPILED THORNS */

  {
    int i;
    int nthorns;
    const char **thorns;

    nthorns = CCTK_NumCompiledThorns();

    thorns = (const char **)malloc(nthorns * sizeof(char *));

    for(i=0; i < nthorns; i++)
    {
      thorns[i] = CCTK_CompiledThorn (i);
    }

    /* Sort the thorns */
    qsort(thorns, nthorns, sizeof(char *), CompareStrings);

    strcpy(message, "<h3>Compiled thorns:</h3>"
                    "<p>This list shows all thorns compiled into the executable, "
                    "those thorns which have been activated in the parameter "
                    "file for this simulation are shown in "
                    "<font color=red>red</font></p>"
                    "<UL>");

    for(i=0; i < nthorns; i++)
    {
      strcat(message, "<LI>");
      if (CCTK_IsThornActive(thorns[i]))
      {
        sprintf(message,"%s  <FONT COLOR=red> %s </FONT>\n", message, thorns[i]); 
      }
      else
      {
        strcat(message, thorns[i]);
      }
    }
    strcat(message, "</UL>");

    free(thorns);
  }

  write(request->filedes, message, strlen(message));
  

  /* Finish table started by blurb */
  strcpy(message, "</td></tr></table>");

  write(request->filedes, message, strlen(message));
 
  /* Write out the footer part. */

  retval = write(request->filedes, cactus_footer, strlen(cactus_footer));

  /* retval = write(request->filedes, base_page, strlen(base_page)); */

  return retval;
}


/******************************************************************************
 ***************************** Parameter Page *********************************
 ******************************************************************************/

 /*@@
   @routine    ParameterPage
   @date       Wed Sep 13 23:47:43 2000
   @author     Tom Goodale
   @desc 
   Displays the parameter page.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static int ParameterPage(cGH *cctkGH, httpRequest *request, void *data)
{
  int retval;
  char message[4098];

  /* Status message */
  strcpy(message,"HTTP/1.0 200 OK\r\n");
  
  write(request->filedes, message, strlen(message));

  /* Content-Type */
  strcpy(message,"Content-Type: text/html\r\n\r\n");

  write(request->filedes, message, strlen(message));

  /* Start the page */
  strcpy(message,"<HTML><HEAD><TITLE>Running CACTUS Status Information</TITLE>\n");

  write(request->filedes, message, strlen(message));

  /* Write out the main header part */
  write(request->filedes, cactus_header, strlen(cactus_header));

  /* This is just a test to see what the actual page requested was. */
  sprintf(message, "Residual is '%s'\n", request->residual);

  write(request->filedes, message, strlen(message));

  /* Write out the footer part. */

  retval = write(request->filedes, cactus_footer, strlen(cactus_footer));

  /* retval = write(request->filedes, base_page, strlen(base_page)); */

  return retval;
}

/******************************************************************************
 ***************************** Images *****************************************
 ******************************************************************************/

#include "images/wwwcactuscodeorg.h"

 /*@@
   @routine    RegisterImages
   @date       Wed Sep 13 23:47:43 2000
   @author     Tom Goodale
   @desc 
   Registers images.  Images are static pages, so it
   registers a function which takes a data structure and
   displays it.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static int RegisterImages(void)
{
  struct httpStaticPage *image;

  image = (struct httpStaticPage *)malloc(sizeof(struct httpStaticPage));

  if(image)
  {
    image->page = (char *)malloc(sizeof(wwwcactuscodeorg));
    memcpy(image->page, wwwcactuscodeorg, sizeof(wwwcactuscodeorg));
    image->length = sizeof(wwwcactuscodeorg);
    image->mime_type = (char *)malloc(strlen("image/jpeg"));
    strcpy(image->mime_type, "image/jpeg");

#ifdef HTTP_DEBUG
    printf("Registering /Images/wwwcactuscodeorg.jpg\n");
#endif

    HTTP_RegisterPage("/Images/wwwcactuscodeorg.jpg", ShowStaticPage, (void *)image);
  }

  return 0;
}

 /*@@
   @routine    ShowStaticPages
   @date       Wed Sep 13 23:47:43 2000
   @author     Tom Goodale
   @desc 
   Displays a static page.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static int ShowStaticPage(cGH *cctkGH, httpRequest *request, void *data)
{
  int retval;
  char message[1024];
  struct httpStaticPage *page;

  if(data)
  {
    page = (struct httpStaticPage *)data;

    strcpy(message,"HTTP/1.0 200 OK\r\n"); 
  
    write(request->filedes, message, strlen(message)); 

    sprintf(message,"Content-Length: %d\r\nContent-Type: %s\r\n\r\n", page->length, page->mime_type);

    write(request->filedes, message, strlen(message));

    retval = write(request->filedes, page->page, page->length);
  }
  else
  {
    retval = -1;
  }

  
  return retval;
}


/******************************************************************************
 ***************************** Test Page **************************************
 ******************************************************************************/

static char *test_page="\n\
<html>\
  <head>\
    <title>Advanced Query</title>\
  </head>\
  <body bgcolor=\"#FFFFFF\" background=\"/Images/cac_bord.gif\" \
        link=\"#1B831D\" vlink=\"#768000\" alink=\"#00FF00\"> \
  <table width=80%>\
  <tr>\
  <td><img src=\"/Images/cac_space.gif\"></td>\
  <td>\
<TABLE><TR><TD NOWRAP=\"1\"><FONT SIZE=\"+3\"><font color=\"#047704\"><H1>Query Problem Reports</H1></font></FONT></TD> <TD WIDTH=\"100%\">&nbsp;</TD> <TD NOWRAP=\"1\"><tt><small>User:&nbsp;&nbsp;&nbsp;&nbsp; goodale<br>Database: normal<br>Access:&nbsp;&nbsp; edit</tt></small></TD></TR></TABLE><FORM ACTION=\"http:/test_page\"  ENCTYPE=\"application/x-www-form-urlencoded\">\
<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"submit query\"> or <INPUT TYPE=\"reset\" VALUE=\"reset\"><hr><center><table border=1 bgcolor=#d0d0d0><caption>Search All Text</caption><tr bgcolor=#9fbdf9><th nowrap>Search these text fields<th nowrap>using regular expression</tr>\
<tr><td>Single-line text fields:<td><INPUT TYPE=\"text\" NAME=\"text\"  SIZE=30></tr>\
<tr><td>Multi-line text fields:<td><INPUT TYPE=\"text\" NAME=\"multitext\"  SIZE=30></tr>\
</table>\
<table border=1 bgcolor=#d0d0d0><caption>Search By Date</caption><tr bgcolor=#9fbdf9><th nowrap>Date Search<th nowrap>Example: <tt>1999-04-01 05:00 GMT</tt></tr>\
<tr><td>Arrived After:<td><INPUT TYPE=\"text\" NAME=\"arrivedafter\"  SIZE=30></tr>\
<tr><td>Arrived Before:<td><INPUT TYPE=\"text\" NAME=\"arrivedbefore\"  SIZE=30></tr>\
<tr><td>Modified After:<td><INPUT TYPE=\"text\" NAME=\"modifiedafter\"  SIZE=30></tr>\
<tr><td>Modified Before:<td><INPUT TYPE=\"text\" NAME=\"modifiedbefore\"  SIZE=30></tr>\
<tr><td>Closed After:<td><INPUT TYPE=\"text\" NAME=\"closedafter\"  SIZE=30></tr>\
<tr><td>Closed Before:<td><INPUT TYPE=\"text\" NAME=\"closedbefore\"  SIZE=30></tr>\
</table>\
<table border=1 bgcolor=#d0d0d0><caption>Search Individual Fields</caption><tr bgcolor=#9fbdf9><th nowrap>Search this field<th nowrap>using regular expression, or<th nowrap>using multi-selection</tr>\
<tr valign=top><td>Category:<td><INPUT TYPE=\"text\" NAME=\"category\"  SIZE=30><td><SELECT NAME=\"category\" SIZE=4 MULTIPLE>\
<OPTION  VALUE=\"all\">all\
<OPTION  VALUE=\"CVS\">CVS\
<OPTION  VALUE=\"Cactus\">Cactus\
<OPTION  VALUE=\"CactusBase\">CactusBase\
<OPTION  VALUE=\"CactusEinstein-ADM\">CactusEinstein-ADM\
<OPTION  VALUE=\"CactusEinstein-ADMConstraints\">CactusEinstein-ADMConstraints\
<OPTION  VALUE=\"CactusEinstein-BMA\">CactusEinstein-BMA\
<OPTION  VALUE=\"CactusEinstein-Einstein\">CactusEinstein-Einstein\
<OPTION  VALUE=\"CactusEinstein-IDAnalyticBH\">CactusEinstein-IDAnalyticBH\
<OPTION  VALUE=\"CactusEinstein-IDLinearWaves\">CactusEinstein-IDLinearWaves\
<OPTION  VALUE=\"CactusEinstein\">CactusEinstein\
<OPTION  VALUE=\"CactusElliptic-EllBase\">CactusElliptic-EllBase\
<OPTION  VALUE=\"CactusElliptic-EllPETSc\">CactusElliptic-EllPETSc\
<OPTION  VALUE=\"CactusElliptic-EllSOR\">CactusElliptic-EllSOR\
<OPTION  VALUE=\"CactusElliptic-EllTest\">CactusElliptic-EllTest\
<OPTION  VALUE=\"CactusElliptic\">CactusElliptic\
<OPTION  VALUE=\"CactusPUGH-Interp\">CactusPUGH-Interp\
<OPTION  VALUE=\"CactusPUGH-PUGH\">CactusPUGH-PUGH\
<OPTION  VALUE=\"CactusPUGH\">CactusPUGH\
<OPTION  VALUE=\"CactusPUGHIO-IOASCII\">CactusPUGHIO-IOASCII\
<OPTION  VALUE=\"CactusPUGHIO-IOFlexIO\">CactusPUGHIO-IOFlexIO\
<OPTION  VALUE=\"CactusPUGHIO-IOHDF5\">CactusPUGHIO-IOHDF5\
<OPTION  VALUE=\"CactusPUGHIO-IsoSurfacer\">CactusPUGHIO-IsoSurfacer\
<OPTION  VALUE=\"CactusPUGHIO\">CactusPUGHIO\
<OPTION  VALUE=\"CactusWave\">CactusWave\
<OPTION  VALUE=\"Compiler\">Compiler\
<OPTION  VALUE=\"Documentation\">Documentation\
<OPTION  VALUE=\"IO\">IO\
<OPTION  VALUE=\"Thorns\">Thorns\
<OPTION  VALUE=\"Webpage\">Webpage\
<OPTION  VALUE=\"external\">external\
</SELECT>\
\
<tr valign=top><td>Synopsis:<td><INPUT TYPE=\"text\" NAME=\"synopsis\"  SIZE=30><td>&nbsp;\
<tr valign=top><td>Confidential:<td><INPUT TYPE=\"text\" NAME=\"confidential\"  SIZE=30><td><SELECT NAME=\"confidential\" SIZE=3 MULTIPLE>\
<OPTION  VALUE=\"all\">all\
<OPTION  VALUE=\"no\">no\
<OPTION  VALUE=\"yes\">yes\
</SELECT>\
\
<tr valign=top><td>Severity:<td><INPUT TYPE=\"text\" NAME=\"severity\"  SIZE=30><td><SELECT NAME=\"severity\" SIZE=4 MULTIPLE>\
<OPTION  VALUE=\"all\">all\
<OPTION  VALUE=\"critical\">critical\
<OPTION  VALUE=\"serious\">serious\
<OPTION  VALUE=\"non-critical\">non-critical\
</SELECT>\
\
<tr valign=top><td>Priority:<td><INPUT TYPE=\"text\" NAME=\"priority\"  SIZE=30><td><SELECT NAME=\"priority\" SIZE=4 MULTIPLE>\
<OPTION  VALUE=\"all\">all\
<OPTION  VALUE=\"high\">high\
<OPTION  VALUE=\"medium\">medium\
<OPTION  VALUE=\"low\">low\
</SELECT>\
\
<tr valign=top><td>Responsible:<td><INPUT TYPE=\"text\" NAME=\"responsible\"  SIZE=30><td><SELECT NAME=\"responsible\" SIZE=4 MULTIPLE>\
<OPTION  VALUE=\"all\">all\
<OPTION  VALUE=\"allen\">allen\
<OPTION  VALUE=\"bernd\">bernd\
<OPTION  VALUE=\"gnats-admin\">gnats-admin\
<OPTION  VALUE=\"goodale\">goodale\
<OPTION  VALUE=\"lanfer\">lanfer\
<OPTION  VALUE=\"tradke\">tradke\
<OPTION  VALUE=\"werner\">werner\
</SELECT>\
\
<tr valign=top><td>State:<td><INPUT TYPE=\"text\" NAME=\"state\"  SIZE=30><br><INPUT TYPE=\"checkbox\" NAME=\"ignoreclosed\" VALUE=\"Ignore Closed\" CHECKED>Ignore Closed<td><SELECT NAME=\"state\" SIZE=4 MULTIPLE>\
<OPTION  VALUE=\"all\">all\
<OPTION  VALUE=\"open\">open\
<OPTION  VALUE=\"analyzed\">analyzed\
<OPTION  VALUE=\"suspended\">suspended\
<OPTION  VALUE=\"feedback\">feedback\
<OPTION  VALUE=\"Cactus4.0beta7\">Cactus4.0beta7\
<OPTION  VALUE=\"Cactus4.0beta8\">Cactus4.0beta8\
<OPTION  VALUE=\"Cactus4.0beta9\">Cactus4.0beta9\
<OPTION  VALUE=\"closed\">closed\
</SELECT>\
\
<tr valign=top><td>Class:<td><INPUT TYPE=\"text\" NAME=\"class\"  SIZE=30><td><SELECT NAME=\"class\" SIZE=4 MULTIPLE>\
<OPTION  VALUE=\"all\">all\
<OPTION  VALUE=\"sw-bug\">sw-bug\
<OPTION  VALUE=\"doc-bug\">doc-bug\
<OPTION  VALUE=\"support\">support\
<OPTION  VALUE=\"feature-request\">feature-request\
<OPTION  VALUE=\"mistaken\">mistaken\
<OPTION  VALUE=\"duplicate\">duplicate\
</SELECT>\
\
<tr valign=top><td>Submitter-Id:<td><INPUT TYPE=\"text\" NAME=\"submitter_id\"  SIZE=30><td><SELECT NAME=\"submitter_id\" SIZE=3 MULTIPLE>\
<OPTION  VALUE=\"all\">all\
<OPTION  VALUE=\"test\">test\
<OPTION  VALUE=\"unknown\">unknown\
</SELECT>\
\
<tr valign=top><td>Originator:<td><INPUT TYPE=\"text\" NAME=\"originator\"  SIZE=30><td>&nbsp;\
<tr valign=top><td>Release:<td><INPUT TYPE=\"text\" NAME=\"release\"  SIZE=30><td>&nbsp;\
</table>\
<table border=1 bgcolor=#d0d0d0><caption>Select Columns to Display</caption><tr valign=top><td>Display these columns:<td><SELECT NAME=\"columns\" SIZE=14 MULTIPLE>\
<OPTION SELECTED VALUE=\"category\">category\
<OPTION  VALUE=\"confidential\">confidential\
<OPTION SELECTED VALUE=\"state\">state\
<OPTION  VALUE=\"class\">class\
<OPTION  VALUE=\"severity\">severity\
<OPTION  VALUE=\"priority\">priority\
<OPTION  VALUE=\"release\">release\
<OPTION SELECTED VALUE=\"responsible\">responsible\
<OPTION  VALUE=\"submitter_id\">submitter_id\
<OPTION SELECTED VALUE=\"originator\">originator\
<OPTION  VALUE=\"arrival_date\">arrival_date\
<OPTION  VALUE=\"last_modified\">last_modified\
<OPTION  VALUE=\"closed_date\">closed_date\
<OPTION SELECTED VALUE=\"synopsis\">synopsis\
</SELECT>\
</table>\
</center>\
<hr><INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"submit query\"> or <INPUT TYPE=\"reset\" VALUE=\"reset\"><INPUT TYPE=\"hidden\" NAME=\".cgifields\" VALUE=\"confidential\"><INPUT TYPE=\"hidden\" NAME=\".cgifields\" VALUE=\"columns\"><INPUT TYPE=\"hidden\" NAME=\".cgifields\" VALUE=\"state\"><INPUT TYPE=\"hidden\" NAME=\".cgifields\" VALUE=\"priority\"><INPUT TYPE=\"hidden\" NAME=\".cgifields\" VALUE=\"submitter_id\"><INPUT TYPE=\"hidden\" NAME=\".cgifields\" VALUE=\"severity\"><INPUT TYPE=\"hidden\" NAME=\".cgifields\" VALUE=\"class\"><INPUT TYPE=\"hidden\" NAME=\".cgifields\" VALUE=\"ignoreclosed\"><INPUT TYPE=\"hidden\" NAME=\".cgifields\" VALUE=\"responsible\"><INPUT TYPE=\"hidden\" NAME=\".cgifields\" VALUE=\"category\"></FORM><HR><!-- Included footer with navigation bar -->\
    <div align=\"center\">\
      <table border=\"0\" width=\"100%\">\
	<tr>\
	  <td bgcolor=\"#E9F4D3\" align=\"center\"   \
	    nowrap><font face=\"arial,helvetica\"><small><a href=\"/index.html\">Welcome</a></small></font>\
	  </td>\
	  <td bgcolor=\"#E9F4D3\" align=\"center\"   \
	    nowrap><font face=\"arial,helvetica\"><small><a href=\"/Documentation.html\">Documentation</a></small></font>\
	  </td>\
	  <td bgcolor=\"#E9F4D3\" align=\"center\"   \
	    nowrap><font face=\"arial,helvetica\"><small><a href=\"/Download.html\">Download</a></small></font>\
	  </td>\
	  <td bgcolor=\"#E9F4D3\" align=\"center\"   \
	    nowrap><font face=\"arial,helvetica\"><small><a href=\"/Development.html\">Development</a></small></font>\
	  </td>\
	  <td bgcolor=\"#E9F4D3\" align=\"center\"   \
	    nowrap><font face=\"arial,helvetica\"><small><a href=\"/Showcase.html\">Showcase</a></small></font>\
	  </td>\
	  <td bgcolor=\"#E9F4D3\" align=\"center\"   \
	    nowrap><font face=\"arial,helvetica\"><small><a href=\"/Links.html\">Links</a></small></font> \
	  </td>\
	</tr>\
	<tr>\
	  <td align=\"center\" colspan=\"6\">\
	    <a href=\"/index.html\"><img src=\"/images/wwwcactuscodeorg_small.jpg\" \
		border=\"0\" alt=\"CactusCode\"></a><br>\
	    <a href=\"mailto:cactus@cactuscode.org\">cactus@cactuscode.org</a>\
	    <!--#config timefmt=\"Last Modified: <i>%a %b %d, %Y</i>\" -->\
	    <!--#echo var=\"LAST_MODIFIED\" -->\
	  </td>\
      </tr>\
    </table>\
   </div>\
</td></tr></table></BODY></HTML>";

 /*@@
   @routine    TestPage
   @date       Thu Sep 14 20:42:37 2000
   @author     Tom Goodale
   @desc 
   A test page for showing how to access arguments and header lines
   and generally playing about.
   If this is called with no arguments, it displays a form.  If it is
   called with arguments it displays some info.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
static int TestPage(cGH *cctkGH, httpRequest *request, void *data)
{
  int retval;
  char message[1024];

  const char *value;
  
  strcpy(message,"HTTP/1.0 200 OK\r\n"); 
  
  write(request->filedes, message, strlen(message)); 

  strcpy(message,"Content-Type: text/html\r\n\r\n");

  write(request->filedes, message, strlen(message)); 

  if(request->n_arguments == 0)
  {
    retval = write(request->filedes, test_page, strlen(test_page));
  }
  else
  {
    strcpy(message, "<html><head><title>Advanced Query</title></head>"
                    "<body><H1> Query Result </H1><br>");

    write(request->filedes, message, strlen(message)); 

    sprintf(message, "Number of arguments is %d<hr>\n", request->n_arguments);

    write(request->filedes, message, strlen(message)); 

    value = HTTP_ArgumentValue(request, "text");

    sprintf(message, "text = %s<hr>\n", value);

    write(request->filedes, message, strlen(message)); 
    
    value = HTTP_HeaderValue(request, "Host");

    sprintf(message, "Host header = %s<hr>\n", value);

    write(request->filedes, message, strlen(message)); 

    strcpy(message, "</body></html>");

    retval = write(request->filedes, message, strlen(message));
  }

  return retval;
}


static const char *notauthorized_page =
"<HTML>\n<HEAD><TITLE>Error 401: Not Authorized</TITLE></HEAD>\
<BODY>You are not authorized to access this page</BODY>\n<HTML>\n";

static const char *authorized_page =
"<HTML>\n<HEAD><TITLE>Authorized</TITLE></HEAD>\
<BODY>Congratulations !</BODY>\n<HTML>\n";

static int AuthPage(cGH *cctkGH, httpRequest *request, void *data)
{
  int retval;
  char message[1024];

  int notauthorised;

  notauthorised = HTTP_AuthenticateBasic(request, "user");

  if(!notauthorised)
  {
    strcpy(message,"HTTP/1.0 200 Ok\r\n"); 
  
    write(request->filedes, message, strlen(message)); 

    strcpy(message,"WWW-Authenticate: Basic realm=\"foo\"\r\n"); 
  
    write(request->filedes, message, strlen(message)); 

    strcpy(message,"Content-Type: text/html\r\n\r\n");

    write(request->filedes, message, strlen(message));
  
    write(request->filedes, authorized_page, strlen(authorized_page));
  }
  else
  {
    strcpy(message,"HTTP/1.0 401 Unauthorized\r\n"); 
  
    write(request->filedes, message, strlen(message)); 

    strcpy(message,"WWW-Authenticate: Basic realm=\"foo\"\r\n"); 
  
    write(request->filedes, message, strlen(message)); 

    strcpy(message,"Content-Type: text/html\r\n\r\n");

    write(request->filedes, message, strlen(message));
  
    write(request->filedes, notauthorized_page, strlen(notauthorized_page));
  }

  return 0;
}