source: trunk/gsdl/src/recpt/statusaction.cpp@ 533

Last change on this file since 533 was 533, checked in by sjboddie, 25 years ago

added GPL notice

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 28.2 KB
Line 
1/**********************************************************************
2 *
3 * statusaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * $Id: statusaction.cpp 533 1999-09-07 04:57:01Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.18 1999/09/07 04:57:00 sjboddie
31 added GPL notice
32
33 Revision 1.17 1999/09/03 09:53:46 rjmcnab
34 Output more configuration options for the receptionist.
35
36 Revision 1.16 1999/09/02 00:28:42 rjmcnab
37 removed dependancy on GSDL_GSDLHOME
38
39 Revision 1.15 1999/07/30 02:24:42 sjboddie
40 added collectinfo argument to some functions
41
42 Revision 1.14 1999/07/13 23:26:07 rjmcnab
43 Added support for authenaction and usersaction
44
45 Revision 1.13 1999/06/08 04:29:39 sjboddie
46 added argsinfo to the call to check_cgiargs to make it easy to set
47 args to their default if they're found to be screwed up
48
49 Revision 1.12 1999/04/06 22:20:35 rjmcnab
50 Got browsefilter working.
51
52 Revision 1.11 1999/03/31 23:44:49 rjmcnab
53 Altered the protocol so that the metadata is part of the filter.
54
55 Revision 1.10 1999/03/16 04:47:03 rjmcnab
56 Changed the list of arguments on the argument page to be the info list
57 not the current args list (there are some arguments which don't have
58 a default so they never make it onto the args list).
59
60 Revision 1.9 1999/03/11 01:26:02 rjmcnab
61 Fixed a few small formatting things.
62
63 Revision 1.8 1999/03/11 00:12:30 rjmcnab
64 Started using status.dm to handle the bulky text. Made the status
65 action use frames and added some more information.
66
67 Revision 1.7 1999/03/09 21:00:47 rjmcnab
68 Reorganised the statusaction, added more functions to comtypes.
69
70 Revision 1.6 1999/02/25 21:59:02 rjmcnab
71
72 Merged sources.
73
74 Revision 1.5 1999/02/21 22:33:58 rjmcnab
75
76 Lots of stuff :-)
77
78 Revision 1.4 1999/02/12 02:40:18 sjboddie
79
80 Added page action
81
82 Revision 1.3 1999/02/11 23:07:00 sjboddie
83
84 extended the status action
85
86 Revision 1.2 1999/02/11 01:24:06 rjmcnab
87
88 Fixed a few compiler warnings.
89
90 Revision 1.1 1999/02/11 01:01:27 rjmcnab
91
92 Initial revision.
93
94 */
95
96
97#include "statusaction.h"
98#include "fileutil.h"
99#include <assert.h>
100
101
102void statusaction::output_frameset (cgiargsclass &/*args*/, displayclass &disp,
103 outconvertclass &outconvert,
104 ostream &textout, ostream &/*logout*/) {
105 textout << outconvert << disp << "_status:frameset_\n";
106}
107
108void statusaction::output_select (cgiargsclass &/*args*/, displayclass &disp,
109 outconvertclass &outconvert,
110 ostream &textout, ostream &/*logout*/) {
111 textout << outconvert << disp << "_status:header_(selector)\n"
112 "_status:select_\n"
113 "_status:footer_\n";
114}
115
116void statusaction::output_generalinfo (cgiargsclass &/*args*/, displayclass &disp,
117 outconvertclass &outconvert,
118 ostream &textout, ostream &/*logout*/) {
119 if (recpt == NULL) return;
120 const recptconf &rcinfo = recpt->get_configinfo ();
121
122 textout << outconvert << disp << "_status:header_(General Information)\n";
123 textout << outconvert
124 << "<h2>General information</h2>\n"
125 << "<table>\n"
126 << "<tr valign=top><th>gsdlhome</th><td>\"" << rcinfo.gsdlhome
127 << "\"</td></tr>\n"
128 << "<tr valign=top><th>collection</th><td>\"" << rcinfo.collection
129 << "\"</td></tr>\n"
130 << "<tr valign=top><th>collectdir</th><td>\"" << rcinfo.collectdir
131 << "\"</td></tr>\n"
132 << "<tr valign=top><th>httpprefix</th><td>\"" << rcinfo.httpprefix
133 << "\"</td></tr>\n"
134 << "<tr valign=top><th>httpimg</th><td>\"" << rcinfo.httpimg
135 << "\"</td></tr>\n"
136 << "<tr valign=top><th>gwcgi</th><td>\"" << rcinfo.gwcgi
137 << "\"</td></tr>\n";
138
139 // macrofiles
140 textout << outconvert << "<tr valign=top><th>macrofiles</th><td>";
141 text_tarray::const_iterator macrohere = rcinfo.macrofiles.begin ();
142 text_tarray::const_iterator macroend = rcinfo.macrofiles.end ();
143 bool macrofirst = true;
144 while (macrohere != macroend) {
145 if (!macrofirst) textout << outconvert << ", ";
146 macrofirst = false;
147 textout << outconvert << "\"" << *macrohere << "\"";
148 macrohere++;
149 }
150 textout << outconvert << "</td></tr>\n";
151
152 // saveconf
153 textout << outconvert << "<tr valign=top><th>saveconf</th><td>\"" << rcinfo.saveconf
154 << "\"</td></tr>\n";
155
156 // usecookies
157 textout << outconvert << "<tr valign=top><th>usecookies</th><td>\"";
158 if (rcinfo.usecookies) textout << outconvert << "true";
159 else textout << outconvert << "false";
160 textout << outconvert << "\"</td></tr>\n";
161
162 // logcgiargs
163 textout << outconvert << "<tr valign=top><th>logcgiargs</th><td>\"";
164 if (rcinfo.logcgiargs) textout << outconvert << "true";
165 else textout << outconvert << "false";
166 textout << outconvert << "\"</td></tr>\n";
167
168 // pageparams
169 textout << outconvert << "<tr valign=top><th>pageparams</th><td>";
170 text_tmap::const_iterator params_here = rcinfo.pageparams.begin();
171 text_tmap::const_iterator params_end = rcinfo.pageparams.end();
172 bool params_first = true;
173 while (params_here != params_end) {
174 if (!params_first) textout << outconvert << ", ";
175 params_first = false;
176 textout << outconvert << "\"" << (*params_here).first << "\" != \""
177 << (*params_here).second << "\"";
178
179 params_here++;
180 }
181 textout << outconvert << "</td></tr>\n";
182
183 // macroprecedence
184 textout << outconvert << "<tr valign=top><th>macroprecedence</th><td>\"" << rcinfo.macroprecedence
185 << "\"</td></tr>\n";
186
187 // arguments
188 cgiargsinfoclass *rcargsinfo = recpt->get_cgiargsinfo_ptr ();
189 if (rcargsinfo != NULL) {
190 textout << outconvert << "<tr valign=top><th>arguments</th><td>";
191
192 cgiargsinfoclass::const_iterator argsinfohere = rcargsinfo->begin ();
193 cgiargsinfoclass::const_iterator argsinfoend = rcargsinfo->end ();
194 bool argsinfofirst = true;
195 while (argsinfohere != argsinfoend) {
196 if (!argsinfofirst) textout << outconvert << ", ";
197 argsinfofirst = false;
198 textout << outconvert << "\"" << (*argsinfohere).second.shortname << "\"";
199 argsinfohere++;
200 }
201
202 textout << outconvert << "</td></tr>\n";
203 }
204
205 // actions
206 actionmapclass *actions = recpt->get_actionmap_ptr();
207 if (actions != NULL) {
208 textout << outconvert << "<tr valign=top><th>actions</th><td>";
209
210 actionptrmap::iterator actionshere = actions->begin ();
211 actionptrmap::iterator actionsend = actions->end ();
212 bool actionsfirst = true;
213 while (actionshere != actionsend) {
214 if (!actionsfirst) textout << outconvert << ", ";
215 actionsfirst = false;
216 assert ((*actionshere).second.a != NULL);
217 if ((*actionshere).second.a != NULL) {
218 textout << outconvert << "\"" << (*actionshere).second.a->get_action_name() << "\"";
219 }
220 actionshere++;
221 }
222
223 textout << outconvert << "</td></tr>\n";
224 }
225
226 // protocols
227 recptprotolistclass *protocols = recpt->get_recptprotolist_ptr ();
228 if (protocols != NULL) {
229 textout << outconvert << "<tr valign=top><th>protocols</th><td>";
230
231 recptprotolistclass::iterator protohere = protocols->begin ();
232 recptprotolistclass::iterator protoend = protocols->end ();
233 bool protofirst = true;
234 while (protohere != protoend) {
235 if (!protofirst) textout << outconvert << ", ";
236 protofirst = false;
237 if ((*protohere).p != NULL) {
238 textout << outconvert << "\"" << (*protohere).p->get_protocol_name() << "\"";
239 }
240 protohere++;
241 }
242
243 textout << outconvert << "</td></tr>\n";
244 }
245
246 // converters
247 convertinfoclass *converters = recpt->get_convertinfo_ptr ();
248 if (converters != NULL) {
249 textout << outconvert << "<tr valign=top><th>converters</th><td>";
250
251 convertinfoclass::iterator converthere = converters->begin ();
252 convertinfoclass::iterator convertend = converters->end ();
253 bool convertfirst = true;
254 while (converthere != convertend) {
255 if (!convertfirst) textout << outconvert << ", ";
256 convertfirst = false;
257 textout << outconvert << "\"" << (*converthere).second.name << "\"";
258 converthere++;
259 }
260
261 textout << outconvert << "</td></tr>\n";
262 }
263
264 textout << outconvert << disp << "</table>\n_status:footer_\n";
265}
266
267void statusaction::output_argumentinfo (cgiargsclass &args, displayclass &disp,
268 outconvertclass &outconvert,
269 ostream &textout, ostream &/*logout*/) {
270 if (recpt == NULL) return;
271 cgiargsinfoclass *rcargsinfo = recpt->get_cgiargsinfo_ptr ();
272 if (rcargsinfo == NULL) return;
273
274 textout << outconvert << disp << "_status:header_(Argument Information)\n";
275 textout << outconvert
276 << "<h2>Argument information</h2>\n"
277 << "<table>";
278
279 // argument information
280 textout << outconvert << "<tr valign=top><th>short name</th><th>long name</th>"
281 << "<th>multiple char?</th>"
282 << "<th>default</th><th>default status</th><th>saved args</th>"
283 << "<th>current value</th></tr>\n";
284
285
286 cgiargsinfoclass::const_iterator argsinfohere = rcargsinfo->begin();
287 cgiargsinfoclass::const_iterator argsinfoend = rcargsinfo->end();
288 text_t *arg_value;
289 while (argsinfohere != argsinfoend) {
290 const cgiarginfo &ainfo = (*argsinfohere).second;
291 textout << outconvert
292 << "<tr valign=top><td>" << ainfo.shortname << "</td>\n";
293
294 textout << outconvert << "<td>" << ainfo.longname << "</td>\n";
295 if (ainfo.multiplechar) textout << outconvert << "<td>yes</td>\n";
296 else textout << outconvert << "<td>no</td>\n";
297 textout << outconvert << "<td>" << ainfo.argdefault << "</td>\n";
298 switch (ainfo.defaultstatus) {
299 case cgiarginfo::none: textout << outconvert << "<td>none</td>\n"; break;
300 case cgiarginfo::weak: textout << outconvert << "<td>weak</td>\n"; break;
301 case cgiarginfo::good: textout << outconvert << "<td>good</td>\n"; break;
302 case cgiarginfo::config: textout << outconvert << "<td>config</td>\n"; break;
303 case cgiarginfo::imperative: textout << outconvert << "<td>imperative</td>\n"; break;
304 }
305 switch (ainfo.savedarginfo) {
306 case cgiarginfo::mustnot: textout << outconvert << "<td>mustnot</td>\n"; break;
307 case cgiarginfo::can: textout << outconvert << "<td>can</td>\n"; break;
308 case cgiarginfo::must: textout << outconvert << "<td>must</td>\n"; break;
309 }
310
311 arg_value = args.getarg (ainfo.shortname);
312 if (arg_value == NULL) textout << outconvert << "<td></td></tr>\n";
313 else textout << outconvert << "<td>\"" << *arg_value << "\"</td></tr>\n";
314
315 argsinfohere ++;
316 }
317
318 textout << outconvert << disp << "</table>\n_status:footer_\n";
319}
320
321void statusaction::output_actioninfo (cgiargsclass &/*args*/, displayclass &disp,
322 outconvertclass &outconvert,
323 ostream &textout, ostream &/*logout*/) {
324 if (recpt == NULL) return;
325 actionmapclass *actions = recpt->get_actionmap_ptr();
326
327 textout << outconvert << disp << "_status:header_(Action Information)\n";
328 textout << outconvert
329 << "<h2>Action information</h2>\n"
330 << "<table>";
331
332 // action information
333 if (actions != NULL) {
334 textout << outconvert
335 << "<tr><th>action name</th><th>cgi arguments</th></tr>\n";
336
337 actionptrmap::iterator actionshere = actions->begin ();
338 actionptrmap::iterator actionsend = actions->end ();
339 while (actionshere != actionsend) {
340 assert ((*actionshere).second.a != NULL);
341 if ((*actionshere).second.a != NULL) {
342 textout << outconvert
343 << "<tr><td>" << (*actionshere).second.a->get_action_name()
344 << "</td><td>";
345
346 cgiargsinfoclass argsinfo = (*actionshere).second.a->getargsinfo();
347 cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin ();
348 cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end ();
349 bool aifirst = true;
350 while (argsinfohere != argsinfoend) {
351 if (!aifirst) textout << outconvert << ", ";
352 aifirst = false;
353 textout << outconvert << (*argsinfohere).second.shortname;
354 argsinfohere++;
355 }
356
357 textout << outconvert << "</td></tr>\n";
358 }
359 actionshere++;
360 }
361 }
362
363 textout << outconvert << disp << "</table>\n_status:footer_\n";
364}
365
366void statusaction::output_protocolinfo (cgiargsclass &/*args*/, displayclass &disp,
367 outconvertclass &outconvert,
368 ostream &textout, ostream &logout) {
369 if (recpt == NULL) return;
370 const recptconf &rcinfo = recpt->get_configinfo ();
371 bool colspecific = !rcinfo.collection.empty();
372 bool unreachablecol = false;
373
374 recptprotolistclass *rprotolist = recpt->get_recptprotolist_ptr ();
375 if (rprotolist == NULL) return;
376
377 textout << outconvert << disp << "_status:header_(Protocol Information)\n";
378 textout << outconvert
379 << "<h2>Protocol information</h2>\n"
380 << "<table>\n"
381 << "<tr><th>protocol</th><th>collections</th></tr>\n";
382
383 text_t protoname;
384 recptprotolistclass::iterator rprotolist_here = rprotolist->begin();
385 recptprotolistclass::iterator rprotolist_end = rprotolist->end();
386 while (rprotolist_here != rprotolist_end) {
387 if ((*rprotolist_here).p != NULL) {
388 protoname = (*rprotolist_here).p->get_protocol_name();
389 textout << outconvert
390 << "<tr><td>"
391 << protoname
392 << "</td><td>";
393
394 text_tarray collist;
395 comerror_t err;
396 (*rprotolist_here).p->get_collection_list (collist, err, logout);
397 if (err == noError) {
398 text_tarray::iterator collist_here = collist.begin();
399 text_tarray::iterator collist_end = collist.end();
400 bool first = true;
401 while (collist_here != collist_end) {
402 if (!first) textout << outconvert << ", ";
403 first = false;
404
405 if (colspecific && *collist_here != rcinfo.collection) {
406 unreachablecol = true;
407 textout << outconvert << "\"" << *collist_here << "\"";
408 } else {
409 textout << outconvert << disp
410 << "\"<a href=\"_gwcgi_?e=_compressedoptions_&a=status&sp=collectioninfo&pr="
411 << protoname
412 << "&c="
413 << *collist_here
414 << "\">"
415 << *collist_here
416 << "</a>\"";
417 }
418
419 collist_here++;
420 }
421
422 } else {
423 textout << outconvert << "Error (" << get_comerror_string (err)
424 << ") while getting collect list\n";
425 }
426
427 textout << outconvert
428 << "</td></tr>\n";
429 }
430
431 rprotolist_here++;
432 }
433
434 textout << outconvert << "</table>\n";
435 if (unreachablecol) {
436 textout << outconvert
437 << "<b>Warning:</b> the receptionist is running in collection specific\n"
438 << "mode making some of the collections unreachable.\n";
439 }
440 textout << outconvert << disp << "_status:footer_\n";
441}
442
443void statusaction::output_collectioninfo (cgiargsclass &args, displayclass &disp,
444 outconvertclass &outconvert,
445 ostream &textout, ostream &logout) {
446 if (recpt == NULL) return;
447
448 textout << outconvert << disp << "_status:header_(Collection info)\n";
449 textout << outconvert << "<h2>Collection info</h2>\n";
450
451 // get the list of protocols
452 recptprotolistclass *rprotolist = recpt->get_recptprotolist_ptr ();
453 if (rprotolist == NULL) return;
454
455 // look for the desired protocol
456 text_t &arg_pr = args["pr"];
457 text_t &arg_c = args["c"];
458 recptproto *rproto;
459 recptprotolistclass::iterator rprotolist_here = rprotolist->begin();
460 recptprotolistclass::iterator rprotolist_end = rprotolist->end();
461 while (rprotolist_here != rprotolist_end) {
462 rproto = (*rprotolist_here).p;
463 if (rproto != NULL && rproto->get_protocol_name() == arg_pr) {
464 // see if the protocol has the collection
465 bool hascollection;
466 comerror_t err;
467 rproto->has_collection (arg_c, hascollection, err, logout);
468 if (err == noError && hascollection) break;
469 }
470 rprotolist_here++;
471 }
472
473 if (rprotolist_here == rprotolist_end) {
474 textout << outconvert << "Protocol \"" << arg_pr << "\" with collection \""
475 << arg_c << "\" was not found\n";
476
477 } else {
478 ColInfoResponse_t collectinfo;
479 comerror_t err;
480
481 rproto->get_collectinfo (arg_c, collectinfo, err, logout);
482 if (err == noError) {
483 textout << outconvert << "<table>\n"
484 << "<tr><th>collection name</th><td>\""
485 << collectinfo.shortInfo.name
486 << "\"</td></tr>\n"
487
488 << "<tr><th>host</th><td>\""
489 << collectinfo.shortInfo.host
490 << "\"</td></tr>\n"
491
492 << "<tr><th>port</th><td>\""
493 << collectinfo.shortInfo.port
494 << "\"</td></tr>\n"
495
496 << "<tr><th>is public?</th><td>";
497 if (collectinfo.isPublic) textout << outconvert << "true";
498 else textout << outconvert << "false";
499 textout << outconvert
500 << "</td></tr>\n"
501
502 << "<tr><th>is beta?</th><td>";
503 if (collectinfo.isBeta) textout << outconvert << "true";
504 else textout << outconvert << "false";
505 textout << outconvert
506 << "</td></tr>\n"
507
508 << "<tr><th>build date</th><td>\""
509 << collectinfo.buildDate
510 << "\"</td></tr>\n"
511
512 << "<tr><th>interface languages</th><td>";
513 text_tarray::iterator languages_here = collectinfo.languages.begin();
514 text_tarray::iterator languages_end = collectinfo.languages.end();
515 bool languages_first = true;
516 while (languages_here != languages_end) {
517 if (!languages_first) textout << outconvert << ", ";
518 languages_first = false;
519 textout << outconvert << "\"" << *languages_here << "\"";
520 languages_here++;
521 }
522 textout << outconvert
523 << "</td></tr>\n"
524
525 << "<tr><th>number of documents</th><td>\""
526 << collectinfo.numDocs
527 << "\"</td></tr>\n"
528
529 << "<tr><th>number of words</th><td>\""
530 << collectinfo.numWords
531 << "\"</td></tr>\n"
532
533 << "<tr><th>number of bytes</th><td>\""
534 << collectinfo.numBytes
535 << "\"</td></tr>\n"
536
537 << "</table>";
538
539 } else {
540 textout << outconvert << "Error (" << get_comerror_string (err)
541 << ") while getting collect information\n";
542 }
543
544
545 InfoFiltersResponse_t filterinfo;
546 InfoFilterOptionsRequest_t filteroptions_request;
547 InfoFilterOptionsResponse_t filteroptions;
548 rproto->get_filterinfo (arg_c, filterinfo, err, logout);
549 if (err == noError) {
550 text_tset::iterator filternames_here = filterinfo.filterNames.begin();
551 text_tset::iterator filternames_end = filterinfo.filterNames.end();
552 while (filternames_here != filternames_end) {
553 textout << outconvert
554 << "<hr>\n"
555 << "<h3>Filter options for \"" << (*filternames_here) << "\"</h3>\n"
556 << "<table>\n"
557 << "<tr><th>option name</th><th>type</th><th>repeatable</th>"
558 << "<th>default value</th><th>valid values</th></tr>\n";
559
560 filteroptions_request.clear();
561 filteroptions_request.filterName = *filternames_here;
562 rproto->get_filteroptions (arg_c, filteroptions_request,
563 filteroptions, err, logout);
564 if (err == noError) {
565 FilterOption_tmap::iterator filteropt_here =
566 filteroptions.filterOptions.begin();
567 FilterOption_tmap::iterator filteropt_end =
568 filteroptions.filterOptions.end();
569 while (filteropt_here != filteropt_end) {
570 textout << outconvert
571 << "<tr><td>\""
572 << (*filteropt_here).second.name
573 << "\"</td>\n"
574
575 << "<td>";
576 text_t type_string;
577 switch ((*filteropt_here).second.type) {
578 case FilterOption_t::booleant: type_string = "boolean"; break;
579 case FilterOption_t::integert: type_string = "integer"; break;
580 case FilterOption_t::enumeratedt: type_string = "enumerated"; break;
581 case FilterOption_t::stringt: type_string = "string"; break;
582 }
583 textout << outconvert
584 << type_string
585 << "</td>\n"
586
587 << "<td>";
588 text_t repeat_string;
589 switch ((*filteropt_here).second.repeatable) {
590 case FilterOption_t::onePerQuery: repeat_string = "one per query"; break;
591 case FilterOption_t::onePerTerm: repeat_string = "one per term"; break;
592 case FilterOption_t::nPerTerm: repeat_string = "n per term"; break;
593 }
594 textout << outconvert
595 << repeat_string
596 << "</td>\n"
597
598 << "<td>\""
599 << (*filteropt_here).second.defaultValue
600 << "\"</td>\n"
601
602 << "<td>";
603
604 text_tarray::iterator valid_here =
605 (*filteropt_here).second.validValues.begin();
606 text_tarray::iterator valid_end =
607 (*filteropt_here).second.validValues.end();
608 bool valid_first = true;
609 while (valid_here != valid_end) {
610 if (!valid_first) textout << outconvert << ", ";
611 valid_first = false;
612 textout << outconvert << "\"" << *valid_here << "\"";
613 valid_here++;
614 }
615 textout << outconvert
616 << "</td></tr>\n";
617
618 filteropt_here++;
619 }
620
621 textout << outconvert
622 << "</table>\n";
623
624 } else {
625 textout << outconvert << "Error (" << get_comerror_string (err)
626 << ") while getting filter option information\n";
627 }
628
629 filternames_here++;
630 }
631
632 } else {
633 textout << outconvert << "Error (" << get_comerror_string (err)
634 << ") while getting filter information\n";
635 }
636 }
637
638 textout << outconvert << disp << "_status:footer_\n";
639}
640
641void statusaction::output_initlog (cgiargsclass &/*args*/, displayclass &disp,
642 outconvertclass &outconvert,
643 ostream &textout, ostream &/*logout*/) {
644 if (recpt == NULL) return;
645 const recptconf &rcinfo = recpt->get_configinfo ();
646 text_t initfilename = filename_cat (rcinfo.gsdlhome, "etc", "initout.txt");
647 char *cinitfilename = initfilename.getcstr();
648 if (cinitfilename == NULL) return;
649
650 textout << outconvert << disp << "_status:header_(Init log)\n";
651 textout << outconvert << "<h2>Init log</h2>\n";
652
653 ifstream initin (cinitfilename, ios::in | ios::nocreate);
654 delete cinitfilename;
655 if (initin) {
656 textout << outconvert << "<p>The initialisation error log, "
657 << initfilename << ", contains the\n";
658 textout << outconvert << "following information:\n\n";
659 text_t errorpage = "<p><pre>\n";
660
661 char c;
662 initin.get(c);
663 while (!initin.eof ()) {
664 errorpage.push_back(c);
665 initin.get(c);
666 }
667
668 errorpage += "</pre>\n";
669 initin.close();
670 textout << outconvert << errorpage;
671
672 } else {
673 textout << outconvert << "Couldn't read initialisation error log, "
674 << initfilename << ".\n";
675 }
676
677 textout << outconvert << disp << "_status:footer_\n";
678}
679
680void statusaction::output_errorlog (cgiargsclass &/*args*/, displayclass &disp,
681 outconvertclass &outconvert,
682 ostream &textout, ostream &logout) {
683 if (recpt == NULL) return;
684 const recptconf &rcinfo = recpt->get_configinfo ();
685 text_t errfilename = filename_cat (rcinfo.gsdlhome, "etc", "errout.txt");
686 char *cerrfilename = errfilename.getcstr();
687 if (cerrfilename == NULL) return;
688
689 textout << outconvert << disp << "_status:header_(Error log)\n";
690 textout << outconvert << "<h2>Error log</h2>\n";
691 logout << flush;
692
693 ifstream errin (cerrfilename, ios::in | ios::nocreate);
694 delete cerrfilename;
695 if (errin) {
696 textout << outconvert << "<p>The error log, "
697 << errfilename << ", contains the\n";
698 textout << outconvert << "following information:\n\n";
699 text_t errorpage = "<p><pre>\n";
700
701 char c;
702 errin.get(c);
703 while (!errin.eof ()) {
704 errorpage.push_back(c);
705 errin.get(c);
706 }
707
708 errorpage += "</pre>\n";
709 errin.close();
710 textout << outconvert << errorpage;
711
712 } else {
713 textout << outconvert << "Couldn't read error log, "
714 << errfilename << ".\n";
715 }
716
717 textout << outconvert << disp << "_status:footer_\n";
718}
719
720void statusaction::output_errorpage (outconvertclass &outconvert,
721 ostream &textout, ostream &/*logout*/,
722 text_t message) {
723 textout << outconvert
724 << "<html>\n"
725 << "<head>\n"
726 << "<title>Error</title>\n"
727 << "</head>\n"
728 << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
729 << "alink=\"#cc9900\" vlink=\"#666633\">\n"
730 << "<h2>Oops!</h2>\n"
731 << message
732 << "\n</body>\n"
733 << "</html>\n";
734 return;
735}
736
737
738
739statusaction::statusaction () {
740 disabled = true;
741 recpt = NULL;
742
743 // this action uses cgi variable "a"
744 cgiarginfo arg_ainfo;
745 arg_ainfo.shortname = "a";
746 arg_ainfo.longname = "action";
747 arg_ainfo.multiplechar = true;
748 arg_ainfo.defaultstatus = cgiarginfo::weak;
749 arg_ainfo.argdefault = "status";
750 arg_ainfo.savedarginfo = cgiarginfo::must;
751 argsinfo.addarginfo (NULL, arg_ainfo);
752
753 // "sp" -- status page
754 arg_ainfo.shortname = "sp";
755 arg_ainfo.longname = "status page";
756 arg_ainfo.multiplechar = true;
757 arg_ainfo.defaultstatus = cgiarginfo::good;
758 arg_ainfo.argdefault = "frameset";
759 arg_ainfo.savedarginfo = cgiarginfo::can;
760 argsinfo.addarginfo (NULL, arg_ainfo);
761
762 // "pr" -- protocol
763 arg_ainfo.shortname = "pr";
764 arg_ainfo.longname = "protocol";
765 arg_ainfo.multiplechar = true;
766 arg_ainfo.defaultstatus = cgiarginfo::none;
767 arg_ainfo.argdefault = "";
768 arg_ainfo.savedarginfo = cgiarginfo::can;
769 argsinfo.addarginfo (NULL, arg_ainfo);
770}
771
772statusaction::~statusaction () {
773}
774
775bool statusaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &args,
776 ostream &/*logout*/) {
777 // authenticate the user if authentication is avaiable
778 args["uan"] = 1;
779 args["ug"] = "administrator";
780
781 return true;
782}
783
784void statusaction::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
785 text_t &response_data, ostream &/*logout*/) {
786 response = content;
787 response_data = "text/html";
788}
789
790bool statusaction::do_action (cgiargsclass &args, const ColInfoResponse_t &/*collectinfo*/,
791 recptproto */*collectproto*/, displayclass &disp,
792 outconvertclass &outconvert, ostream &textout,
793 ostream &logout) {
794 // make sure the status function is enabled
795 if (disabled) {
796 output_errorpage (outconvert, textout, logout,
797 "The status action is disabled. "
798 "See the documentation (what documentation!) on how "
799 "to enable it.");
800 return true;
801 }
802
803 // make sure we know about a receptionist
804 if (recpt == NULL) {
805 output_errorpage (outconvert, textout, logout,
806 "The status action does not contain information\n"
807 "about any receptionists. The method set_receptionist\n"
808 "was probably not called from the module which instantiated\n"
809 "this status action.\n");
810 return true;
811 }
812
813 // check to make sure status.dm was read in
814 const recptconf &rcinfo = recpt->get_configinfo ();
815 text_tarray::const_iterator macrohere = rcinfo.macrofiles.begin ();
816 text_tarray::const_iterator macroend = rcinfo.macrofiles.end ();
817 while (macrohere != macroend) {
818 if (*macrohere == "status.dm") break;
819 macrohere++;
820 }
821 if (macrohere == macroend) {
822 output_errorpage (outconvert, textout, logout,
823 "The status.dm file was not read in. This macro file is\n"
824 "needed to display configuration and status information.\n");
825 return true;
826 }
827
828 // output the required status page
829 text_t &arg_sp = args["sp"];
830 if (arg_sp == "frameset") output_frameset (args, disp, outconvert, textout, logout);
831 else if (arg_sp == "select") output_select (args, disp, outconvert, textout, logout);
832 else if (arg_sp == "generalinfo") output_generalinfo (args, disp, outconvert, textout, logout);
833 else if (arg_sp == "argumentinfo") output_argumentinfo (args, disp, outconvert, textout, logout);
834 else if (arg_sp == "actioninfo") output_actioninfo (args, disp, outconvert, textout, logout);
835 else if (arg_sp == "protocolinfo") output_protocolinfo (args, disp, outconvert, textout, logout);
836 else if (arg_sp == "collectioninfo") output_collectioninfo (args, disp, outconvert, textout, logout);
837 else if (arg_sp == "initlog") output_initlog (args, disp, outconvert, textout, logout);
838 else if (arg_sp == "errorlog") output_errorlog (args, disp, outconvert, textout, logout);
839 else {
840 output_errorpage (outconvert, textout, logout,
841 "Unknown page \"" + arg_sp + "\".\n");
842 }
843
844 return true;
845}
846
847void statusaction::configure (const text_t &key, const text_tarray &cfgline) {
848 if ((key == "status") && (cfgline.size() == 1) &&
849 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
850 disabled = false;
851 } else {
852 // call the parent class to deal with the things which
853 // are not dealt with here
854 action::configure (key, cfgline);
855 }
856}
857
Note: See TracBrowser for help on using the repository browser.