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

Last change on this file since 1270 was 1270, checked in by sjboddie, 24 years ago

Receptionist now caches collection information to avoid making multiple
get_collectinfo calls to collection server

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