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

Last change on this file since 2379 was 2379, checked in by jrm21, 23 years ago

added #define line for iostream stuff to work under Mac OS X.

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