/********************************************************************** * * statusaction.cpp -- * Copyright (C) 1999 The New Zealand Digital Library Project * * A component of the Greenstone digital library software * from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *********************************************************************/ #include "gsdl_modules_cfg.h" #ifdef GSDL_USE_STATUS_ACTION // following line required to get fstream.filedesc() on darwin (Mac OS X) #define _STREAM_COMPAT 1 #include "statusaction.h" #include "fileutil.h" #include "htmlutils.h" #include "gsdltools.h" #include #include #include // for open() stuff void statusaction::output_frameset (cgiargsclass &/*args*/, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) { textout << outconvert << disp << "_status:frameset_\n"; } void statusaction::output_select (cgiargsclass &/*args*/, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) { textout << outconvert << disp << "_status:header_(selector)\n" "_status:select_\n" "_status:footer_\n"; } void statusaction::output_welcome (cgiargsclass &args, recptprotolistclass *protos, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { if (recpt == NULL) return; textout << outconvert << disp << "_status:infoheader_(_titlewelcome_)\n" << "_status:welcome_" << "\n" << "" << "\n"; recptprotolistclass::iterator rprotolist_here = protos->begin(); recptprotolistclass::iterator rprotolist_end = protos->end(); while (rprotolist_here != rprotolist_end) { if ((*rprotolist_here).p != NULL) { comerror_t err; text_t protoname = (*rprotolist_here).p->get_protocol_name(err); text_tarray collist; (*rprotolist_here).p->get_collection_list (collist, err, logout); if (err == noError) { text_tarray::iterator collist_here = collist.begin(); text_tarray::iterator collist_end = collist.end(); while (collist_here != collist_end) { textout << outconvert << disp << ""; ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout); if (cinfo != NULL) { text_t collname = cinfo->get_collectionmeta("collectionname", args["l"]); if (collname.empty()) { collname = *collist_here; } textout << ""; if (cinfo->isPublic) textout << ""; else textout << ""; if (cinfo->buildDate > 0) textout << outconvert << ""; else textout << ""; } else { textout << ""; } textout << "\n"; ++collist_here; } } } ++rprotolist_here; } textout << "
abbrev.collectionpublic?running?
" << *collist_here << ""; if (cinfo->buildDate > 0) textout << outconvert << disp << ""; textout << outconvert << disp << collname; if (cinfo->buildDate > 0) textout << ""; textout << "yesnoyesno
\n"; textout << outconvert << disp << "_status:infofooter_\n"; } void statusaction::output_generalinfo (cgiargsclass &/*args*/, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) { if (recpt == NULL) return; const recptconf &rcinfo = recpt->get_configinfo (); textout << outconvert << disp << "_status:infoheader_(General Information)\n"; textout << outconvert << "

General information

\n" << "\n" << "\n" << "\n" << "\n" << "\n" << "\n" << "\n"; // macrofiles textout << outconvert << "\n"; // saveconf textout << outconvert << "\n"; // usecookies textout << outconvert << "\n"; // logcgiargs textout << outconvert << "\n"; // pageparams textout << outconvert << "\n"; // macroprecedence textout << outconvert << "\n"; // arguments cgiargsinfoclass *rcargsinfo = recpt->get_cgiargsinfo_ptr (); if (rcargsinfo != NULL) { textout << outconvert << "\n"; } // actions actionmapclass *actions = recpt->get_actionmap_ptr(); if (actions != NULL) { textout << outconvert << "\n"; } // browsers browsermapclass *browsers = recpt->get_browsermap_ptr(); if (browsers != NULL) { textout << outconvert << "\n"; } // protocols recptprotolistclass *protocols = recpt->get_recptprotolist_ptr (); if (protocols != NULL) { textout << outconvert << "\n"; } // converters convertinfoclass *converters = recpt->get_convertinfo_ptr (); if (converters != NULL) { textout << outconvert << "\n"; } textout << outconvert << disp << "
gsdlhome\"" << rcinfo.gsdlhome << "\"
collection\"" << rcinfo.collection << "\"
collectdir\"" << rcinfo.collectdir << "\"
httpprefix\"" << rcinfo.httpprefix << "\"
httpimg\"" << rcinfo.httpimg << "\"
gwcgi\"" << rcinfo.gwcgi << "\"
macrofiles"; text_tset::const_iterator macrohere = rcinfo.macrofiles.begin (); text_tset::const_iterator macroend = rcinfo.macrofiles.end (); bool macrofirst = true; while (macrohere != macroend) { if (!macrofirst) textout << outconvert << ", "; macrofirst = false; textout << outconvert << "\"" << *macrohere << "\""; ++macrohere; } textout << outconvert << "
saveconf\"" << rcinfo.saveconf << "\"
usecookies\""; if (rcinfo.usecookies) textout << outconvert << "true"; else textout << outconvert << "false"; textout << outconvert << "\"
logcgiargs\""; if (rcinfo.logcgiargs) textout << outconvert << "true"; else textout << outconvert << "false"; textout << outconvert << "\"
pageparams"; text_tmap::const_iterator params_here = rcinfo.pageparams.begin(); text_tmap::const_iterator params_end = rcinfo.pageparams.end(); bool params_first = true; while (params_here != params_end) { if (!params_first) textout << outconvert << ", "; params_first = false; textout << outconvert << "\"" << (*params_here).first << "\" != \"" << (*params_here).second << "\""; ++params_here; } textout << outconvert << "
macroprecedence\"" << rcinfo.macroprecedence << "\"
arguments"; cgiargsinfoclass::const_iterator argsinfohere = rcargsinfo->begin (); cgiargsinfoclass::const_iterator argsinfoend = rcargsinfo->end (); bool argsinfofirst = true; while (argsinfohere != argsinfoend) { if (!argsinfofirst) textout << outconvert << ", "; argsinfofirst = false; textout << outconvert << "\"" << (*argsinfohere).second.shortname << "\""; ++argsinfohere; } textout << outconvert << "
actions"; actionptrmap::iterator actionshere = actions->begin (); actionptrmap::iterator actionsend = actions->end (); bool actionsfirst = true; while (actionshere != actionsend) { if (!actionsfirst) textout << outconvert << ", "; actionsfirst = false; assert ((*actionshere).second.a != NULL); if ((*actionshere).second.a != NULL) { textout << outconvert << "\"" << (*actionshere).second.a->get_action_name() << "\""; } ++actionshere; } textout << outconvert << "
browsers"; browserptrmap::iterator browsershere = browsers->begin (); browserptrmap::iterator browsersend = browsers->end (); bool browsersfirst = true; while (browsershere != browsersend) { if (!browsersfirst) textout << outconvert << ", "; browsersfirst = false; assert ((*browsershere).second.b != NULL); if ((*browsershere).second.b != NULL) { textout << outconvert << "\"" << (*browsershere).second.b->get_browser_name() << "\""; } ++browsershere; } textout << outconvert << "
protocols"; recptprotolistclass::iterator protohere = protocols->begin (); recptprotolistclass::iterator protoend = protocols->end (); bool protofirst = true; while (protohere != protoend) { comerror_t err; if (!protofirst) textout << outconvert << ", "; protofirst = false; if ((*protohere).p != NULL) { textout << outconvert << "\"" << (*protohere).p->get_protocol_name(err) << "\""; } ++protohere; } textout << outconvert << "
converters"; convertinfoclass::iterator converthere = converters->begin (); convertinfoclass::iterator convertend = converters->end (); bool convertfirst = true; while (converthere != convertend) { if (!convertfirst) textout << outconvert << ", "; convertfirst = false; textout << outconvert << "\"" << (*converthere).second.name << "\""; ++converthere; } textout << outconvert << "
\n_status:infofooter_\n"; } void statusaction::output_argumentinfo (cgiargsclass &args, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) { if (recpt == NULL) return; cgiargsinfoclass *rcargsinfo = recpt->get_cgiargsinfo_ptr (); if (rcargsinfo == NULL) return; textout << outconvert << disp << "_status:infoheader_(Argument Information)\n"; textout << outconvert << "

Argument information

\n" << ""; // argument information textout << outconvert << "" << "" << "" << "" << "\n"; cgiargsinfoclass::const_iterator argsinfohere = rcargsinfo->begin(); cgiargsinfoclass::const_iterator argsinfoend = rcargsinfo->end(); text_t *arg_value; while (argsinfohere != argsinfoend) { const cgiarginfo &ainfo = (*argsinfohere).second; textout << outconvert << "\n"; textout << outconvert << "\n"; if (ainfo.multiplechar) textout << outconvert << "\n"; else textout << outconvert << "\n"; if (ainfo.multiplevalue) textout << outconvert << "\n"; else textout << outconvert << "\n"; textout << outconvert << "\n"; switch (ainfo.defaultstatus) { case cgiarginfo::none: textout << outconvert << "\n"; break; case cgiarginfo::weak: textout << outconvert << "\n"; break; case cgiarginfo::good: textout << outconvert << "\n"; break; case cgiarginfo::config: textout << outconvert << "\n"; break; case cgiarginfo::imperative: textout << outconvert << "\n"; break; } switch (ainfo.savedarginfo) { case cgiarginfo::mustnot: textout << outconvert << "\n"; break; case cgiarginfo::can: textout << outconvert << "\n"; break; case cgiarginfo::must: textout << outconvert << "\n"; break; } arg_value = args.getarg (ainfo.shortname); if (arg_value == NULL) textout << outconvert << "\n"; else textout << outconvert << "\n"; ++argsinfohere; } textout << outconvert << disp << "
short namelong namemultiple char?multiple value?defaultdefault statussaved argscurrent value
" << ainfo.shortname << "" << ainfo.longname << "yesnoyesno" << ainfo.argdefault << "noneweakgoodconfigimperativemustnotcanmust
\"" << *arg_value << "\"
\n_status:infofooter_\n"; } void statusaction::output_actioninfo (cgiargsclass &/*args*/, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) { if (recpt == NULL) return; actionmapclass *actions = recpt->get_actionmap_ptr(); textout << outconvert << disp << "_status:infoheader_(Action Information)\n"; textout << outconvert << "

Action information

\n" << ""; // action information if (actions != NULL) { textout << outconvert << "\n"; actionptrmap::iterator actionshere = actions->begin (); actionptrmap::iterator actionsend = actions->end (); while (actionshere != actionsend) { assert ((*actionshere).second.a != NULL); if ((*actionshere).second.a != NULL) { textout << outconvert << "\n"; } ++actionshere; } } textout << outconvert << disp << "
action namecgi arguments
" << (*actionshere).second.a->get_action_name() << ""; cgiargsinfoclass *argsinfo = (*actionshere).second.a->getargsinfo(); cgiargsinfoclass::const_iterator argsinfohere = argsinfo->begin (); cgiargsinfoclass::const_iterator argsinfoend = argsinfo->end (); bool aifirst = true; while (argsinfohere != argsinfoend) { if (!aifirst) textout << outconvert << ", "; aifirst = false; textout << outconvert << (*argsinfohere).second.shortname; ++argsinfohere; } textout << outconvert << "
\n_status:infofooter_\n"; } void statusaction::output_browserinfo (cgiargsclass &/*args*/, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) { if (recpt == NULL) return; browsermapclass *browsers = recpt->get_browsermap_ptr(); textout << outconvert << disp << "_status:infoheader_(Browser Information)\n"; textout << outconvert << "

Browser information

\n" << ""; // browser information if (browsers != NULL) { textout << outconvert << "\n"; browserptrmap::iterator browsershere = browsers->begin (); browserptrmap::iterator browsersend = browsers->end (); while (browsershere != browsersend) { assert ((*browsershere).second.b != NULL); if ((*browsershere).second.b != NULL) { textout << outconvert << "\n"; } ++browsershere; } } textout << outconvert << disp << "
browser namedefault formatstring
" << (*browsershere).second.b->get_browser_name() << "" << html_safe ((*browsershere).second.b->get_default_formatstring()) << "
\n_status:infofooter_\n"; } void statusaction::output_protocolinfo (cgiargsclass &/*args*/, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { if (recpt == NULL) return; const recptconf &rcinfo = recpt->get_configinfo (); bool colspecific = !rcinfo.collection.empty(); bool unreachablecol = false; recptprotolistclass *rprotolist = recpt->get_recptprotolist_ptr (); if (rprotolist == NULL) return; textout << outconvert << disp << "_status:infoheader_(Protocol Information)\n"; textout << outconvert << "

Protocol information

\n" << "\n" << "\n"; text_t protoname; recptprotolistclass::iterator rprotolist_here = rprotolist->begin(); recptprotolistclass::iterator rprotolist_end = rprotolist->end(); while (rprotolist_here != rprotolist_end) { if ((*rprotolist_here).p != NULL) { comerror_t err; protoname = (*rprotolist_here).p->get_protocol_name(err); textout << outconvert << "\n"; } ++rprotolist_here; } textout << outconvert << "
protocolcollections
" << protoname << ""; text_tarray collist; (*rprotolist_here).p->get_collection_list (collist, err, logout); if (err == noError) { text_tarray::iterator collist_here = collist.begin(); text_tarray::iterator collist_end = collist.end(); bool first = true; while (collist_here != collist_end) { if (!first) textout << outconvert << ", "; first = false; if (colspecific && *collist_here != rcinfo.collection) { unreachablecol = true; textout << outconvert << "\"" << *collist_here << "\""; } else { textout << outconvert << disp << "\"" << *collist_here << "\""; } ++collist_here; } } else { textout << outconvert << "Error (" << get_comerror_string (err) << ") while getting collect list\n"; } textout << outconvert << "
\n"; if (unreachablecol) { textout << outconvert << "Warning: the receptionist is running in collection specific\n" << "mode making some of the collections unreachable.\n"; } textout << outconvert << disp << "_status:infofooter_\n"; } void statusaction::output_collectioninfo (cgiargsclass &args, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { if (recpt == NULL) return; textout << outconvert << disp << "_status:infoheader_(Collection info)\n"; textout << outconvert << "

Collection info

\n"; // get the list of protocols recptprotolistclass *rprotolist = recpt->get_recptprotolist_ptr (); if (rprotolist == NULL) return; // look for the desired protocol text_t &arg_pr = args["pr"]; text_t &arg_c = args["c"]; recptproto *rproto = NULL; recptprotolistclass::iterator rprotolist_here = rprotolist->begin(); recptprotolistclass::iterator rprotolist_end = rprotolist->end(); while (rprotolist_here != rprotolist_end) { rproto = (*rprotolist_here).p; comerror_t err; if (rproto != NULL && rproto->get_protocol_name(err) == arg_pr) { // see if the protocol has the collection bool hascollection; rproto->has_collection (arg_c, hascollection, err, logout); if (err == noError && hascollection) break; } ++rprotolist_here; } if (rprotolist_here == rprotolist_end) { textout << outconvert << "Protocol \"" << arg_pr << "\" with collection \"" << arg_c << "\" was not found\n"; } else { // rproto can't be NULL to get here ColInfoResponse_t *collectinfo = recpt->get_collectinfo_ptr (rproto, arg_c, logout); if (collectinfo != NULL) { textout << outconvert << "\n" << "\n" << "\n" << "\n" << "\n" << "\n" << "\n" << "\n"; textout << "\n"; textout << "\n"; textout << outconvert << "\n" << "\n" << "\n" << "\n" << "\n" << "\n" << "
collection name\"" << collectinfo->shortInfo.name << "\"
host\"" << collectinfo->shortInfo.host << "\"
port\"" << collectinfo->shortInfo.port << "\"
is public?"; if (collectinfo->isPublic) textout << outconvert << "true"; else textout << outconvert << "false"; textout << outconvert << "
is beta?"; if (collectinfo->isBeta) textout << outconvert << "true"; else textout << outconvert << "false"; textout << outconvert << "
build date\"" << collectinfo->buildDate << "\"
interface languages"; text_tarray::iterator languages_here = collectinfo->languages.begin(); text_tarray::iterator languages_end = collectinfo->languages.end(); bool languages_first = true; while (languages_here != languages_end) { if (!languages_first) textout << outconvert << ", "; languages_first = false; textout << outconvert << "\"" << *languages_here << "\""; ++languages_here; } textout << "
collection metadata\n"; collectionmeta_map::iterator meta_here = collectinfo->collectionmeta.begin(); collectionmeta_map::iterator meta_end = collectinfo->collectionmeta.end(); while (meta_here != meta_end) { textout << outconvert << "\n"; ++meta_here; } textout << "
" << (*meta_here).first << "" ; text_tmap lang_map = (*meta_here).second; text_tmap::iterator lang_here = lang_map.begin(); text_tmap::iterator lang_end = lang_map.end(); while (lang_here != lang_end) { textout << outconvert << "\n"; ++lang_here; } textout << outconvert << "
" << (*lang_here).first << "" << (*lang_here).second << "
format info\n"; text_tmap::iterator format_here = collectinfo->format.begin(); text_tmap::iterator format_end = collectinfo->format.end(); while (format_here != format_end) { textout << outconvert << "\n"; ++format_here; } textout << "
" << (*format_here).first << "" << html_safe((*format_here).second) << "
building info\n"; text_tmap::iterator building_here = collectinfo->building.begin(); text_tmap::iterator building_end = collectinfo->building.end(); while (building_here != building_end) { textout << outconvert << "\n"; ++building_here; } textout << "
" << (*building_here).first << "" << (*building_here).second << "
number of documents\"" << collectinfo->numDocs << "\"
number of sections\"" << collectinfo->numSections << "\"
number of words\"" << collectinfo->numWords << "\"
number of bytes\"" << collectinfo->numBytes << "\"
preferred receptionist\"" << collectinfo->receptionist << "\"
"; } else { textout << "ERROR (statusaction::output_collectioninfo): while getting collect information\n"; } InfoFiltersResponse_t filterinfo; InfoFilterOptionsRequest_t filteroptions_request; InfoFilterOptionsResponse_t filteroptions; comerror_t err; rproto->get_filterinfo (arg_c, filterinfo, err, logout); if (err == noError) { text_tset::iterator filternames_here = filterinfo.filterNames.begin(); text_tset::iterator filternames_end = filterinfo.filterNames.end(); while (filternames_here != filternames_end) { textout << outconvert << "
\n" << "

Filter options for \"" << (*filternames_here) << "\"

\n" << "\n" << "" << "\n"; filteroptions_request.clear(); filteroptions_request.filterName = *filternames_here; rproto->get_filteroptions (arg_c, filteroptions_request, filteroptions, err, logout); if (err == noError) { FilterOption_tmap::iterator filteropt_here = filteroptions.filterOptions.begin(); FilterOption_tmap::iterator filteropt_end = filteroptions.filterOptions.end(); while (filteropt_here != filteropt_end) { textout << outconvert << "\n" << "\n" << "\n" << "\n" << "\n"; ++filteropt_here; } textout << outconvert << "
option nametyperepeatabledefault valuevalid values
\"" << (*filteropt_here).second.name << "\""; text_t type_string; switch ((*filteropt_here).second.type) { case FilterOption_t::booleant: type_string = "boolean"; break; case FilterOption_t::integert: type_string = "integer"; break; case FilterOption_t::enumeratedt: type_string = "enumerated"; break; case FilterOption_t::stringt: type_string = "string"; break; } textout << outconvert << type_string << ""; text_t repeat_string; switch ((*filteropt_here).second.repeatable) { case FilterOption_t::onePerQuery: repeat_string = "one per query"; break; case FilterOption_t::onePerTerm: repeat_string = "one per term"; break; case FilterOption_t::nPerTerm: repeat_string = "n per term"; break; } textout << outconvert << repeat_string << "\"" << (*filteropt_here).second.defaultValue << "\""; text_tarray::iterator valid_here = (*filteropt_here).second.validValues.begin(); text_tarray::iterator valid_end = (*filteropt_here).second.validValues.end(); bool valid_first = true; while (valid_here != valid_end) { if (!valid_first) textout << outconvert << ", "; valid_first = false; textout << outconvert << "\"" << *valid_here << "\""; ++valid_here; } textout << outconvert << "
\n"; } else { textout << outconvert << "Error (" << get_comerror_string (err) << ") while getting filter option information\n"; } ++filternames_here; } } else { textout << outconvert << "Error (" << get_comerror_string (err) << ") while getting filter information\n"; } } textout << outconvert << disp << "_status:infofooter_\n"; } void statusaction::output_usagelog (cgiargsclass &/*args*/, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) { // output last 100 lines of usage.txt text_t logfilename = filename_cat (gsdlhome, "etc", "usage.txt"); textout << outconvert << disp << "_status:infoheader_(Usage log)\n"; textout << outconvert << "

Usage log

\n"; textout << outconvert << "

The usage log, " << logfilename << ", contains the\n" << "following information:\n" << "

(note that if this file is more than 100 lines long only the last 100 lines will\n" << "be displayed on this page)\n\n" << "

\n";

  // note that we're expecting lines to be no more than 1500 characters on
  // average - should fix this file_tail() thing sometime
  textout << outconvert << file_tail (logfilename, 100, 1500);

  textout << outconvert << disp << "
\n" << "_status:infofooter_\n"; } void statusaction::output_errorlog (cgiargsclass &/*args*/, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { text_t errfilename = filename_cat (gsdlhome, "etc", "error.txt"); char *cerrfilename = errfilename.getcstr(); if (cerrfilename == NULL) return; textout << outconvert << disp << "_status:infoheader_(Error log)\n"; textout << outconvert << "

Error log

\n"; logout << flush; #ifdef GSDL_USE_IOS_H ifstream errin (cerrfilename, ios::in | ios::nocreate); #else ifstream errin (cerrfilename, ios::in); #endif delete []cerrfilename; if (errin) { textout << outconvert << "

The error log, " << errfilename << ", contains the\n"; textout << outconvert << "following information:\n\n"; text_t errorpage = "

\n";

    char c;
    errin.get(c);
    while (!errin.eof ()) {
      errorpage.push_back(c);
      errin.get(c);
    }
    
    errorpage += "
\n"; errin.close(); textout << outconvert << errorpage; } else { textout << outconvert << "Couldn't read error log, " << errfilename << ".\n"; } textout << outconvert << disp << "_status:infofooter_\n"; } void statusaction::output_gsdlsite (cgiargsclass &/*args*/, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { textout << outconvert << disp << "_status:infoheader_(gsdlsite.cfg)\n"; textout << outconvert << "

gsdlsite.cfg

\n"; logout << flush; #ifdef GSDL_LOCAL_LIBRARY text_t gsdlsite_cfg = filename_cat (gsdlhome, "gsdlsite.cfg"); #else text_t gsdlsite_cfg = "gsdlsite.cfg"; #endif char *gsdlsite_cfgc = gsdlsite_cfg.getcstr(); #ifdef GSDL_USE_IOS_H ifstream gsdlsitein (gsdlsite_cfgc, ios::in | ios::nocreate); #else ifstream gsdlsitein (gsdlsite_cfgc, ios::in); #endif delete []gsdlsite_cfgc; if (gsdlsitein) { textout << "

The gsdlsite.cfg configuration file contains the\n" << "following information:\n\n"; text_t gsdlsite = "

\n";

    char c;
    gsdlsitein.get(c);
    while (!gsdlsitein.eof ()) {
      gsdlsite.push_back(c);
      gsdlsitein.get(c);
    }
    
    gsdlsite += "
\n"; gsdlsitein.close(); textout << outconvert << gsdlsite; } else { textout << "Couldn't read gsdlsite.cfg configuration file\n"; } textout << outconvert << disp << "_status:infofooter_\n"; } void statusaction::output_maincfg (cgiargsclass &/*args*/, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) { text_t maincfgfile = filename_cat (dbhome, "etc", "main.cfg"); textout << outconvert << disp << "_status:infoheader_(main.cfg)\n" << "

main.cfg

\n" << "

The main configuration file, " << dm_safe(maincfgfile) << ", contains the following information:
\n\n" << "(Note that only users belonging to the \"administrator\" group " << "may edit this file)
\n" << "_status:maincfg_
\n" << "_status:infofooter_\n"; } void statusaction::change_maincfg (cgiargsclass &args, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { // write out the contents of the cfgfile argument to main.cfg text_t cfgfile = filename_cat(gsdlhome, "etc", "main.cfg"); char *cfgfilec = cfgfile.getcstr(); int fd=open(cfgfilec, O_WRONLY | O_CREAT | O_TRUNC #if defined(__WIN32__) | O_BINARY #endif ); if (fd != -1) { int lock_val = 1; GSDL_LOCK_FILE (fd); if (lock_val != 0) { logout << "statusaction::change_maincfg: Error: Couldn't lock file " << cfgfilec << "\n"; textout << outconvert << disp << "_status:changemaincfgfail_"; close (fd); } else { outconvertclass text_t2ascii; text_t2ascii.setinput(&args["cfgfile"]); size_t buffersize=args["cfgfile"].size(); char *buffer=new char[buffersize]; size_t num_chars; convertclass::status_t status; text_t2ascii.convert(buffer, buffersize, num_chars, status); // ignore status - assume it is "finished" as buffer is big enough write(fd, buffer, num_chars); GSDL_UNLOCK_FILE (fd); delete []buffer; close (fd); textout << outconvert << disp << "_status:changemaincfgsuccess_"; } } else { logout << "statusaction::change_maincfg: Error: Couldn't open file " << cfgfilec << "for writing\n"; textout << outconvert << disp << "_status:changemaincfgfail_"; } delete []cfgfilec; } void statusaction::output_errorpage (outconvertclass &outconvert, ostream &textout, ostream &/*logout*/, text_t message) { textout << outconvert << "\n" << "\n" << "Error\n" << "\n" << "\n" << "

Oops!

\n" << message << "\n\n" << "\n"; return; } statusaction::statusaction () { disabled = true; recpt = NULL; // this action uses cgi variable "a" cgiarginfo arg_ainfo; arg_ainfo.shortname = "a"; arg_ainfo.longname = "action"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = "status"; arg_ainfo.savedarginfo = cgiarginfo::must; argsinfo.addarginfo (NULL, arg_ainfo); // "p" -- status page arg_ainfo.shortname = "p"; arg_ainfo.longname = "page"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = "frameset"; arg_ainfo.savedarginfo = cgiarginfo::must; argsinfo.addarginfo (NULL, arg_ainfo); // "pr" -- protocol arg_ainfo.shortname = "pr"; arg_ainfo.longname = "protocol"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::none; arg_ainfo.argdefault = g_EmptyText; arg_ainfo.savedarginfo = cgiarginfo::can; argsinfo.addarginfo (NULL, arg_ainfo); arg_ainfo.shortname = "cfgfile"; arg_ainfo.longname = "configuration file contents"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = g_EmptyText; arg_ainfo.savedarginfo = cgiarginfo::mustnot; argsinfo.addarginfo (NULL, arg_ainfo); } statusaction::~statusaction () { } bool statusaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &args, recptprotolistclass * /*protos*/, ostream &/*logout*/) { // only users belonging to the "administrator" group may edit // the main.cfg file if (args["p"] == "maincfg" || args["p"] == "changemaincfg") { args["uan"] = "1"; args["ug"] = "administrator"; } return true; } void statusaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/, response_t &response, text_t &response_data, ostream &/*logout*/) { response = content; response_data = "text/html"; } void statusaction::define_internal_macros (displayclass &disp, cgiargsclass &args, recptprotolistclass * /*protos*/, ostream &logout) { // define_internal_macros sets the following macros: // _maincfgfile_ the contents of the main.cfg configuration file // _versionnnum_ greenstone version number (hard-coded) disp.setmacro("versionnum", "status", GSDL_VERSION); if (args["p"] == "maincfg") { // read in main.cfg text_t maincfg = filename_cat(gsdlhome, "etc", "main.cfg"); char *maincfgc = maincfg.getcstr(); #ifdef GSDL_USE_IOS_H ifstream cfg_ifs (maincfgc, ios::in | ios::nocreate); #else ifstream cfg_ifs (maincfgc, ios::in); #endif if (cfg_ifs) { text_t cfgtext; char c; cfg_ifs.get(c); while (!cfg_ifs.eof ()) { cfgtext.push_back(c); cfg_ifs.get(c); } cfg_ifs.close(); // define it as a macro disp.setmacro("maincfgfile", "status", dm_safe(cfgtext)); } else { logout << "statusaction::define_internal_macros: couldn't open configuration file (" << maincfgc << ") for reading\n"; disp.setmacro("maincfgfile", "status", g_EmptyText); } delete []maincfgc; } } bool statusaction::do_action (cgiargsclass &args, recptprotolistclass *protos, browsermapclass * /*browsers*/, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { // make sure the status function is enabled if (disabled) { textout << outconvert << "\n" << "\n" << "Status disabled\n" << "\n" << "\n" << "

Facility disabled

\n" << "Sorry, the Maintenance and Administration facility is currently disabled\n" << "\n\n" << "\n"; return true; } // make sure we know about a receptionist if (recpt == NULL) { output_errorpage (outconvert, textout, logout, "The status action does not contain information\n" "about any receptionists. The method set_receptionist\n" "was probably not called from the module which instantiated\n" "this status action.\n"); return true; } // check to make sure status.dm was read in const recptconf &rcinfo = recpt->get_configinfo (); text_tset::const_iterator macrohere = rcinfo.macrofiles.begin (); text_tset::const_iterator macroend = rcinfo.macrofiles.end (); while (macrohere != macroend) { if (*macrohere == "status.dm") break; ++macrohere; } if (macrohere == macroend) { output_errorpage (outconvert, textout, logout, "The status.dm file was not read in. This macro file is\n" "needed to display configuration and status information.\n"); return true; } // output the required status page text_t &arg_p = args["p"]; if (arg_p == "frameset") output_frameset (args, disp, outconvert, textout, logout); else if (arg_p == "select") output_select (args, disp, outconvert, textout, logout); else if (arg_p == "welcome") output_welcome (args, protos, disp, outconvert, textout, logout); else if (arg_p == "generalinfo") output_generalinfo (args, disp, outconvert, textout, logout); else if (arg_p == "argumentinfo") output_argumentinfo (args, disp, outconvert, textout, logout); else if (arg_p == "actioninfo") output_actioninfo (args, disp, outconvert, textout, logout); else if (arg_p == "browserinfo") output_browserinfo (args, disp, outconvert, textout, logout); else if (arg_p == "protocolinfo") output_protocolinfo (args, disp, outconvert, textout, logout); else if (arg_p == "collectioninfo") output_collectioninfo (args, disp, outconvert, textout, logout); else if (arg_p == "usagelog") output_usagelog (args, disp, outconvert, textout, logout); else if (arg_p == "errorlog") output_errorlog (args, disp, outconvert, textout, logout); else if (arg_p == "gsdlsite") output_gsdlsite (args, disp, outconvert, textout, logout); else if (arg_p == "maincfg") output_maincfg (args, disp, outconvert, textout, logout); else if (arg_p == "changemaincfg") change_maincfg (args, disp, outconvert, textout, logout); else { output_errorpage (outconvert, textout, logout, "Unknown page \"" + arg_p + "\".\n"); } return true; } void statusaction::configure (const text_t &key, const text_tarray &cfgline) { if ((key == "status") && (cfgline.size() == 1) && (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) { disabled = false; } else { // call the parent class to deal with the things which // are not dealt with here action::configure (key, cfgline); } } #endif //GSDL_USE_STATUS_ACTION