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

Last change on this file since 2945 was 2939, checked in by sjboddie, 22 years ago

All error messages now go to error.txt (i.e. did away with errout.txt and
initout.txt and put what used to go to them to error.txt instead)

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 37.5 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_errorlog (cgiargsclass &/*args*/, displayclass &disp,
775 outconvertclass &outconvert,
776 ostream &textout, ostream &logout) {
777
778 text_t errfilename = filename_cat (gsdlhome, "etc", "error.txt");
779 char *cerrfilename = errfilename.getcstr();
780 if (cerrfilename == NULL) return;
781
782 textout << outconvert << disp << "_status:infoheader_(Error log)\n";
783 textout << outconvert << "<h2>Error log</h2>\n";
784 logout << flush;
785
786#ifdef GSDL_USE_IOS_H
787 ifstream errin (cerrfilename, ios::in | ios::nocreate);
788#else
789 ifstream errin (cerrfilename, ios::in);
790#endif
791
792 delete cerrfilename;
793 if (errin) {
794 textout << outconvert << "<p>The error log, "
795 << errfilename << ", contains the\n";
796 textout << outconvert << "following information:\n\n";
797 text_t errorpage = "<p><pre>\n";
798
799 char c;
800 errin.get(c);
801 while (!errin.eof ()) {
802 errorpage.push_back(c);
803 errin.get(c);
804 }
805
806 errorpage += "</pre>\n";
807 errin.close();
808 textout << outconvert << errorpage;
809
810 } else {
811 textout << outconvert << "Couldn't read error log, "
812 << errfilename << ".\n";
813 }
814
815 textout << outconvert << disp << "_status:infofooter_\n";
816}
817
818void statusaction::output_gsdlsite (cgiargsclass &/*args*/, displayclass &disp,
819 outconvertclass &outconvert,
820 ostream &textout, ostream &logout) {
821
822 textout << outconvert << disp << "_status:infoheader_(gsdlsite.cfg)\n";
823 textout << outconvert << "<h2>gsdlsite.cfg</h2>\n";
824 logout << flush;
825
826#ifdef GSDL_LOCAL_LIBRARY
827 text_t gsdlsite_cfg = filename_cat (gsdlhome, "gsdlsite.cfg");
828#else
829 text_t gsdlsite_cfg = "gsdlsite.cfg";
830#endif
831
832 char *gsdlsite_cfgc = gsdlsite_cfg.getcstr();
833#ifdef GSDL_USE_IOS_H
834 ifstream gsdlsitein (gsdlsite_cfgc, ios::in | ios::nocreate);
835#else
836 ifstream gsdlsitein (gsdlsite_cfgc, ios::in);
837#endif
838
839 delete gsdlsite_cfgc;
840
841 if (gsdlsitein) {
842 textout << "<p>The gsdlsite.cfg configuration file contains the\n"
843 << "following information:\n\n";
844 text_t gsdlsite = "<p><pre>\n";
845
846 char c;
847 gsdlsitein.get(c);
848 while (!gsdlsitein.eof ()) {
849 gsdlsite.push_back(c);
850 gsdlsitein.get(c);
851 }
852
853 gsdlsite += "</pre>\n";
854 gsdlsitein.close();
855 textout << outconvert << gsdlsite;
856
857 } else {
858 textout << "Couldn't read gsdlsite.cfg configuration file\n";
859 }
860
861 textout << outconvert << disp << "_status:infofooter_\n";
862}
863
864void statusaction::output_maincfg (cgiargsclass &/*args*/, displayclass &disp,
865 outconvertclass &outconvert,
866 ostream &textout, ostream &/*logout*/) {
867
868 text_t maincfgfile = filename_cat (gdbmhome, "etc", "main.cfg");
869
870 textout << outconvert << disp << "_status:infoheader_(main.cfg)\n"
871 << "<h2>main.cfg</h2>\n"
872 << "<p>The main configuration file, "
873 << dm_safe(maincfgfile) << ", contains the following information:<br>\n\n"
874 << "(Note that only users belonging to the \"administrator\" group "
875 << "may edit this file)<br>\n"
876 << "_status:maincfg_<br>\n"
877 << "_status:infofooter_\n";
878}
879
880void statusaction::change_maincfg (cgiargsclass &args, displayclass &disp,
881 outconvertclass &outconvert,
882 ostream &textout, ostream &logout) {
883
884 // write out the contents of the cfgfile argument to main.cfg
885 text_t cfgfile = filename_cat(gsdlhome, "etc", "main.cfg");
886 char *cfgfilec = cfgfile.getcstr();
887#ifdef __WIN32__
888 ofstream cfg_out (cfgfilec, ios::binary);
889#else
890 ofstream cfg_out (cfgfilec);
891#endif
892
893 if (cfg_out) {
894 // lock the file
895 int fd = GSDL_GET_FILEDESC(cfg_out);
896 int lock_val = 1;
897 GSDL_LOCK_FILE (fd);
898 if (lock_val != 0) {
899 logout << "statusaction::change_maincfg: Error: Couldn't lock file " << cfgfilec << "\n";
900 cfg_out.close();
901 textout << outconvert << disp << "_status:changemaincfgfail_";
902
903 } else {
904
905 outconvertclass text_t2ascii;
906 cfg_out << text_t2ascii << args["cfgfile"];
907 GSDL_UNLOCK_FILE (fd);
908 cfg_out.close();
909 textout << outconvert << disp << "_status:changemaincfgsuccess_";
910 }
911 } else {
912 logout << "statusaction::change_maincfg: Error: Couldn't open file " << cfgfilec << "for writing\n";
913 textout << outconvert << disp << "_status:changemaincfgfail_";
914 }
915}
916
917void statusaction::output_errorpage (outconvertclass &outconvert,
918 ostream &textout, ostream &/*logout*/,
919 text_t message) {
920 textout << outconvert
921 << "<html>\n"
922 << "<head>\n"
923 << "<title>Error</title>\n"
924 << "</head>\n"
925 << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
926 << "alink=\"#cc9900\" vlink=\"#666633\">\n"
927 << "<h2>Oops!</h2>\n"
928 << message
929 << "\n</body>\n"
930 << "</html>\n";
931 return;
932}
933
934
935
936statusaction::statusaction () {
937 disabled = true;
938 recpt = NULL;
939
940 // this action uses cgi variable "a"
941 cgiarginfo arg_ainfo;
942 arg_ainfo.shortname = "a";
943 arg_ainfo.longname = "action";
944 arg_ainfo.multiplechar = true;
945 arg_ainfo.defaultstatus = cgiarginfo::weak;
946 arg_ainfo.argdefault = "status";
947 arg_ainfo.savedarginfo = cgiarginfo::must;
948 argsinfo.addarginfo (NULL, arg_ainfo);
949
950 // "p" -- status page
951 arg_ainfo.shortname = "p";
952 arg_ainfo.longname = "page";
953 arg_ainfo.multiplechar = true;
954 arg_ainfo.defaultstatus = cgiarginfo::weak;
955 arg_ainfo.argdefault = "frameset";
956 arg_ainfo.savedarginfo = cgiarginfo::must;
957 argsinfo.addarginfo (NULL, arg_ainfo);
958
959 // "pr" -- protocol
960 arg_ainfo.shortname = "pr";
961 arg_ainfo.longname = "protocol";
962 arg_ainfo.multiplechar = true;
963 arg_ainfo.defaultstatus = cgiarginfo::none;
964 arg_ainfo.argdefault = "";
965 arg_ainfo.savedarginfo = cgiarginfo::can;
966 argsinfo.addarginfo (NULL, arg_ainfo);
967
968 arg_ainfo.shortname = "cfgfile";
969 arg_ainfo.longname = "configuration file contents";
970 arg_ainfo.multiplechar = true;
971 arg_ainfo.defaultstatus = cgiarginfo::weak;
972 arg_ainfo.argdefault = "";
973 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
974 argsinfo.addarginfo (NULL, arg_ainfo);
975}
976
977statusaction::~statusaction () {
978}
979
980bool statusaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &args,
981 ostream &/*logout*/) {
982
983 // only users belonging to the "administrator" group may edit
984 // the main.cfg file
985 if (args["p"] == "maincfg" || args["p"] == "changemaincfg") {
986 args["uan"] = "1";
987 args["ug"] = "administrator";
988 }
989 return true;
990}
991
992void statusaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
993 response_t &response, text_t &response_data,
994 ostream &/*logout*/) {
995 response = content;
996 response_data = "text/html";
997}
998
999
1000void statusaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
1001 recptprotolistclass * /*protos*/, ostream &logout) {
1002
1003 // define_internal_macros sets the following macros:
1004 // _maincfgfile_ the contents of the main.cfg configuration file
1005
1006 // _versionnnum_ greenstone version number (hard-coded)
1007
1008 disp.setmacro("versionnum", "status", GSDL_VERSION);
1009
1010 if (args["p"] == "maincfg") {
1011
1012 // read in main.cfg
1013 text_t maincfg = filename_cat(gsdlhome, "etc", "main.cfg");
1014 char *maincfgc = maincfg.getcstr();
1015
1016#ifdef GSDL_USE_IOS_H
1017 ifstream cfg_ifs (maincfgc, ios::in | ios::nocreate);
1018#else
1019 ifstream cfg_ifs (maincfgc, ios::in);
1020#endif
1021
1022 if (cfg_ifs) {
1023 text_t cfgtext;
1024 char c;
1025 cfg_ifs.get(c);
1026 while (!cfg_ifs.eof ()) {
1027 cfgtext.push_back(c);
1028 cfg_ifs.get(c);
1029 }
1030 cfg_ifs.close();
1031
1032 // define it as a macro
1033 disp.setmacro("maincfgfile", "status", dm_safe(cfgtext));
1034
1035 } else {
1036 logout << "statusaction::define_internal_macros: couldn't open configuration file ("
1037 << maincfgc << ") for reading\n";
1038 disp.setmacro("maincfgfile", "status", "");
1039 }
1040 delete maincfgc;
1041 }
1042}
1043
1044bool statusaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
1045 browsermapclass * /*browsers*/, displayclass &disp,
1046 outconvertclass &outconvert, ostream &textout,
1047 ostream &logout) {
1048 // make sure the status function is enabled
1049 if (disabled) {
1050 textout << outconvert
1051 << "<html>\n"
1052 << "<head>\n"
1053 << "<title>Status disabled</title>\n"
1054 << "</head>\n"
1055 << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
1056 << "alink=\"#cc9900\" vlink=\"#666633\">\n"
1057 << "<h2>Facility disabled</h2>\n"
1058 << "Sorry, the Maintenance and Administration facility is currently disabled\n"
1059 << "\n</body>\n"
1060 << "</html>\n";
1061 return true;
1062 }
1063
1064 // make sure we know about a receptionist
1065 if (recpt == NULL) {
1066 output_errorpage (outconvert, textout, logout,
1067 "The status action does not contain information\n"
1068 "about any receptionists. The method set_receptionist\n"
1069 "was probably not called from the module which instantiated\n"
1070 "this status action.\n");
1071 return true;
1072 }
1073
1074 // check to make sure status.dm was read in
1075 const recptconf &rcinfo = recpt->get_configinfo ();
1076 text_tset::const_iterator macrohere = rcinfo.macrofiles.begin ();
1077 text_tset::const_iterator macroend = rcinfo.macrofiles.end ();
1078 while (macrohere != macroend) {
1079 if (*macrohere == "status.dm") break;
1080 macrohere++;
1081 }
1082 if (macrohere == macroend) {
1083 output_errorpage (outconvert, textout, logout,
1084 "The status.dm file was not read in. This macro file is\n"
1085 "needed to display configuration and status information.\n");
1086 return true;
1087 }
1088
1089 // output the required status page
1090 text_t &arg_p = args["p"];
1091 if (arg_p == "frameset") output_frameset (args, disp, outconvert, textout, logout);
1092 else if (arg_p == "select") output_select (args, disp, outconvert, textout, logout);
1093 else if (arg_p == "welcome") output_welcome (args, protos, disp, outconvert, textout, logout);
1094 else if (arg_p == "generalinfo") output_generalinfo (args, disp, outconvert, textout, logout);
1095 else if (arg_p == "argumentinfo") output_argumentinfo (args, disp, outconvert, textout, logout);
1096 else if (arg_p == "actioninfo") output_actioninfo (args, disp, outconvert, textout, logout);
1097 else if (arg_p == "browserinfo") output_browserinfo (args, disp, outconvert, textout, logout);
1098 else if (arg_p == "protocolinfo") output_protocolinfo (args, disp, outconvert, textout, logout);
1099 else if (arg_p == "collectioninfo") output_collectioninfo (args, disp, outconvert, textout, logout);
1100 else if (arg_p == "usagelog") output_usagelog (args, disp, outconvert, textout, logout);
1101 else if (arg_p == "errorlog") output_errorlog (args, disp, outconvert, textout, logout);
1102 else if (arg_p == "gsdlsite") output_gsdlsite (args, disp, outconvert, textout, logout);
1103 else if (arg_p == "maincfg") output_maincfg (args, disp, outconvert, textout, logout);
1104 else if (arg_p == "changemaincfg") change_maincfg (args, disp, outconvert, textout, logout);
1105 else {
1106 output_errorpage (outconvert, textout, logout,
1107 "Unknown page \"" + arg_p + "\".\n");
1108 }
1109
1110 return true;
1111}
1112
1113void statusaction::configure (const text_t &key, const text_tarray &cfgline) {
1114 if ((key == "status") && (cfgline.size() == 1) &&
1115 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
1116 disabled = false;
1117 } else {
1118 // call the parent class to deal with the things which
1119 // are not dealt with here
1120 action::configure (key, cfgline);
1121 }
1122}
Note: See TracBrowser for help on using the repository browser.