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

Last change on this file since 668 was 543, checked in by rjmcnab, 25 years ago

removed some compiler warnings

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