[1419] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * collectoraction.cpp --
|
---|
| 4 | * Copyright (C) 2000 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 |
|
---|
[7371] | 26 | #include "gsdl_modules_cfg.h"
|
---|
| 27 | #ifdef GSDL_USE_COLLECTOR_ACTION
|
---|
| 28 |
|
---|
[1425] | 29 | // note that the collectoraction relies on having direct access to a
|
---|
| 30 | // collections configuration file. this breaks the separation between
|
---|
| 31 | // receptionist and collection server and so is not suitable (at least
|
---|
| 32 | // in its current form) for use when collection servers are separate
|
---|
| 33 | // from the receptionist (e.g. when using the CORBA protocol).
|
---|
| 34 |
|
---|
[2379] | 35 | // following line required to get fstream.filedesc() on darwin (Mac OS X)
|
---|
| 36 | #define _STREAM_COMPAT 1
|
---|
[2621] | 37 | // required for utsname on solaris???
|
---|
| 38 | #define _XOPEN_SOURCE 1
|
---|
| 39 | #define _XOPEN_SOURCE_EXTENDED 1
|
---|
[2379] | 40 |
|
---|
[1419] | 41 | #include "collectoraction.h"
|
---|
| 42 | #include "OIDtools.h"
|
---|
| 43 | #include "fileutil.h"
|
---|
[1425] | 44 | #include "cfgread.h"
|
---|
[1432] | 45 | #include "gsdltools.h"
|
---|
[1778] | 46 | #include "gsdltimes.h"
|
---|
[2368] | 47 | #include "argdb.h"
|
---|
[2426] | 48 | #include "cgiutils.h"
|
---|
[3007] | 49 | #include <stdio.h>
|
---|
| 50 | #include <fcntl.h>
|
---|
[15529] | 51 | #include <sys/stat.h>
|
---|
[1419] | 52 |
|
---|
| 53 | #if !defined (__WIN32__)
|
---|
| 54 | #include <sys/utsname.h>
|
---|
| 55 | #include <unistd.h>
|
---|
| 56 | #endif
|
---|
| 57 |
|
---|
[11998] | 58 | collectoraction::collectoraction ()
|
---|
| 59 | : wizardaction()
|
---|
| 60 | {
|
---|
| 61 | macro_prefix = "bc1";
|
---|
[1419] | 62 |
|
---|
| 63 | do_mkcol = false;
|
---|
[2401] | 64 | badsources = false;
|
---|
| 65 | failedsources.erase(failedsources.begin(), failedsources.end());
|
---|
[1419] | 66 |
|
---|
| 67 | cgiarginfo arg_ainfo;
|
---|
| 68 | arg_ainfo.shortname = "a";
|
---|
| 69 | arg_ainfo.longname = "action";
|
---|
| 70 | arg_ainfo.multiplechar = true;
|
---|
| 71 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 72 | arg_ainfo.argdefault = "collector";
|
---|
| 73 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 74 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 75 |
|
---|
[1796] | 76 | arg_ainfo.shortname = "p";
|
---|
| 77 | arg_ainfo.longname = "page";
|
---|
[1419] | 78 | arg_ainfo.multiplechar = true;
|
---|
| 79 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 80 | arg_ainfo.argdefault = "intro";
|
---|
| 81 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 82 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 83 |
|
---|
[1457] | 84 | // temporary directory name for this collector
|
---|
| 85 | // session
|
---|
| 86 | arg_ainfo.shortname = "bc1tmp";
|
---|
| 87 | arg_ainfo.longname = "collector specific";
|
---|
| 88 | arg_ainfo.multiplechar = true;
|
---|
| 89 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[7430] | 90 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[1457] | 91 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 92 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 93 |
|
---|
[1419] | 94 | arg_ainfo.shortname = "bc1fullname";
|
---|
| 95 | arg_ainfo.longname = "collector specific";
|
---|
| 96 | arg_ainfo.multiplechar = true;
|
---|
| 97 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[7430] | 98 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[2368] | 99 | arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
[1419] | 100 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 101 |
|
---|
| 102 | arg_ainfo.shortname = "bc1dirname";
|
---|
| 103 | arg_ainfo.longname = "collector specific";
|
---|
| 104 | arg_ainfo.multiplechar = true;
|
---|
| 105 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[7430] | 106 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[1419] | 107 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 108 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 109 |
|
---|
| 110 | arg_ainfo.shortname = "bc1contactemail";
|
---|
| 111 | arg_ainfo.longname = "collector specific";
|
---|
| 112 | arg_ainfo.multiplechar = true;
|
---|
| 113 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[7430] | 114 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[2368] | 115 | arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
[1419] | 116 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 117 |
|
---|
| 118 | arg_ainfo.shortname = "bc1aboutdesc";
|
---|
| 119 | arg_ainfo.longname = "collector specific";
|
---|
| 120 | arg_ainfo.multiplechar = true;
|
---|
| 121 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[7430] | 122 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[2368] | 123 | arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
[1419] | 124 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 125 |
|
---|
| 126 | arg_ainfo.shortname = "bc1clone";
|
---|
| 127 | arg_ainfo.longname = "collector specific";
|
---|
| 128 | arg_ainfo.multiplechar = false;
|
---|
| 129 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 130 | arg_ainfo.argdefault = "0";
|
---|
[2368] | 131 | arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
[1419] | 132 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 133 |
|
---|
| 134 | arg_ainfo.shortname = "bc1clonecol";
|
---|
| 135 | arg_ainfo.longname = "collector specific";
|
---|
| 136 | arg_ainfo.multiplechar = true;
|
---|
| 137 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[7430] | 138 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[2368] | 139 | arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
[1419] | 140 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 141 |
|
---|
[1432] | 142 | // set when cloning option has changed
|
---|
| 143 | arg_ainfo.shortname = "bc1clonechanged";
|
---|
| 144 | arg_ainfo.longname = "collector specific";
|
---|
| 145 | arg_ainfo.multiplechar = false;
|
---|
| 146 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 147 | arg_ainfo.argdefault = "0";
|
---|
[2368] | 148 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
[1432] | 149 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 150 |
|
---|
[1425] | 151 | // only set when one of the fields was changed in
|
---|
| 152 | // the "collection info" page
|
---|
| 153 | arg_ainfo.shortname = "bc1infochanged";
|
---|
| 154 | arg_ainfo.longname = "collector specific";
|
---|
| 155 | arg_ainfo.multiplechar = false;
|
---|
| 156 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 157 | arg_ainfo.argdefault = "0";
|
---|
| 158 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 159 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 160 |
|
---|
| 161 | // only set when cfg file is altered from within
|
---|
| 162 | // "configure collection" page
|
---|
[1419] | 163 | arg_ainfo.shortname = "bc1cfgchanged";
|
---|
| 164 | arg_ainfo.longname = "collector specific";
|
---|
| 165 | arg_ainfo.multiplechar = false;
|
---|
| 166 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 167 | arg_ainfo.argdefault = "0";
|
---|
| 168 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 169 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[1432] | 170 |
|
---|
[1796] | 171 | arg_ainfo.shortname = "cfgfile";
|
---|
| 172 | arg_ainfo.longname = "configuration file contents";
|
---|
| 173 | arg_ainfo.multiplechar = true;
|
---|
| 174 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[7430] | 175 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[1796] | 176 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 177 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 178 |
|
---|
[1432] | 179 | arg_ainfo.shortname = "bc1dodelete";
|
---|
| 180 | arg_ainfo.longname = "collector specific";
|
---|
| 181 | arg_ainfo.multiplechar = false;
|
---|
| 182 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 183 | arg_ainfo.argdefault = "0";
|
---|
| 184 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 185 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 186 |
|
---|
| 187 | // will be set if we arrived at the "configure collection" page
|
---|
| 188 | // via the "changing an existing collection" page
|
---|
| 189 | arg_ainfo.shortname = "bc1econf";
|
---|
| 190 | arg_ainfo.longname = "collector specific";
|
---|
| 191 | arg_ainfo.multiplechar = false;
|
---|
| 192 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 193 | arg_ainfo.argdefault = "0";
|
---|
| 194 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 195 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 196 |
|
---|
| 197 | // will be set if we arrived at the "source data" page
|
---|
| 198 | // via the "changing an existing collection" page
|
---|
| 199 | arg_ainfo.shortname = "bc1esrce";
|
---|
| 200 | arg_ainfo.longname = "collector specific";
|
---|
| 201 | arg_ainfo.multiplechar = false;
|
---|
| 202 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 203 | arg_ainfo.argdefault = "0";
|
---|
| 204 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 205 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[2401] | 206 |
|
---|
[2407] | 207 | arg_ainfo.shortname = "bc1inputnum";
|
---|
[2401] | 208 | arg_ainfo.longname = "collector specific";
|
---|
| 209 | arg_ainfo.multiplechar = true;
|
---|
| 210 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[2407] | 211 | arg_ainfo.argdefault = "3";
|
---|
[2401] | 212 | arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
| 213 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 214 |
|
---|
[2407] | 215 | arg_ainfo.shortname = "bc1input";
|
---|
[2401] | 216 | arg_ainfo.longname = "collector specific";
|
---|
| 217 | arg_ainfo.multiplechar = true;
|
---|
| 218 | arg_ainfo.multiplevalue = true;
|
---|
| 219 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[7430] | 220 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[2401] | 221 | arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
| 222 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 223 |
|
---|
[2407] | 224 | arg_ainfo.shortname = "bc1inputtype";
|
---|
[2401] | 225 | arg_ainfo.longname = "collector specific";
|
---|
| 226 | arg_ainfo.multiplechar = true;
|
---|
| 227 | arg_ainfo.multiplevalue = true;
|
---|
| 228 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[7430] | 229 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[2401] | 230 | arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
| 231 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 232 |
|
---|
| 233 | // will be set when we've just come from the "source data" page
|
---|
| 234 | arg_ainfo.shortname = "bc1fromsrce";
|
---|
| 235 | arg_ainfo.longname = "collector specific";
|
---|
| 236 | arg_ainfo.multiplechar = false;
|
---|
[2418] | 237 | arg_ainfo.multiplevalue = false;
|
---|
[2401] | 238 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 239 | arg_ainfo.argdefault = "0";
|
---|
| 240 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 241 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[1419] | 242 | }
|
---|
| 243 |
|
---|
| 244 | collectoraction::~collectoraction () {
|
---|
| 245 | }
|
---|
| 246 |
|
---|
[1759] | 247 |
|
---|
| 248 |
|
---|
[2368] | 249 | bool collectoraction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
|
---|
[3546] | 250 | recptprotolistclass * /*protos*/, ostream &logout) {
|
---|
[1419] | 251 |
|
---|
[1796] | 252 | text_t ¤t_page = args["p"];
|
---|
[1438] | 253 |
|
---|
[1461] | 254 | // note that the "bildstatus" and "bildframe1" pages don't actually do anything
|
---|
| 255 | // functional so we don't need to worry about authenticating them (it's the
|
---|
[1485] | 256 | // underlying "bild" page that does the building (and creates the frameset))
|
---|
[1461] | 257 | // This helps us overcome a bit of a problem we have with multiple pages trying
|
---|
| 258 | // to read from the key.db database at the same time.
|
---|
| 259 | if (current_page != "intro" && current_page != "bildstatus" && current_page != "bildframe1") {
|
---|
[1432] | 260 | // authenticate the user if authentication is available
|
---|
[1419] | 261 | args["uan"] = 1;
|
---|
[15160] | 262 | args["ug"] = "all-collections-editor";
|
---|
[1419] | 263 | }
|
---|
[1457] | 264 |
|
---|
| 265 | if (current_page == "new" || current_page == "existing") {
|
---|
[1419] | 266 |
|
---|
[1457] | 267 | // assign (and create) a temporary directory
|
---|
[5599] | 268 | if (assign_tmpname (args, logout)==false) {
|
---|
| 269 | // there was an error creating the tmp dir
|
---|
| 270 | message="tmpfail";
|
---|
| 271 | return true; // true because we could still parse the arguments
|
---|
| 272 | }
|
---|
[1457] | 273 |
|
---|
| 274 | // clean up any old builds left laying about in the tmp directory
|
---|
| 275 | // (note that it's possible this could take some time if there's a huge
|
---|
[11998] | 276 | // partially built collecton laying about so we'll make it an asynchronous
|
---|
[1817] | 277 | // system call)
|
---|
| 278 | gsdl_system ("perl -S cleantmp.pl", false, logout);
|
---|
[1457] | 279 | }
|
---|
| 280 |
|
---|
[2368] | 281 | if (current_page != "intro" && current_page != "bildstatus" &&
|
---|
| 282 | current_page != "bildframe1" && current_page != "new") {
|
---|
| 283 | // update arguments that were saved to the harddrive
|
---|
| 284 | text_tmap saved_args;
|
---|
[7430] | 285 | saved_args["bc1fullname"] = g_EmptyText;
|
---|
| 286 | saved_args["bc1contactemail"] = g_EmptyText;
|
---|
| 287 | saved_args["bc1aboutdesc"] = g_EmptyText;
|
---|
| 288 | saved_args["bc1clone"] = g_EmptyText;
|
---|
| 289 | saved_args["bc1clonecol"] = g_EmptyText;
|
---|
| 290 | saved_args["bc1inputnum"] = g_EmptyText;
|
---|
| 291 | saved_args["bc1input"] = g_EmptyText;
|
---|
| 292 | saved_args["bc1inputtype"] = g_EmptyText;
|
---|
[2368] | 293 |
|
---|
| 294 | // update the argdb database with any arguments that were set
|
---|
| 295 | // by previous page
|
---|
| 296 | text_tmap::iterator here = saved_args.begin();
|
---|
| 297 | text_tmap::iterator end = saved_args.end();
|
---|
| 298 | while (here != end) {
|
---|
[2418] | 299 | if (args.lookupcgiarg((*here).first).source != cgiarg_t::default_arg) {
|
---|
[2368] | 300 | (*here).second = args[(*here).first];
|
---|
| 301 | }
|
---|
[9620] | 302 | ++here;
|
---|
[2368] | 303 | }
|
---|
| 304 |
|
---|
[3300] | 305 | text_t argfile = filename_cat(gsdlhome, "tmp", args["bc1tmp"], "argdb.db");
|
---|
| 306 | argdb *args_on_disk = new argdb(argfile);
|
---|
[2368] | 307 | if (!args_on_disk->update_args(saved_args)) {
|
---|
| 308 | // error
|
---|
[3300] | 309 | logout << "collectoraction: argdb::update_args failed (" << argfile << ")\n";
|
---|
[2368] | 310 | }
|
---|
| 311 |
|
---|
| 312 | // update args from argdb
|
---|
| 313 | saved_args.erase(saved_args.begin(), saved_args.end());
|
---|
| 314 | if (!args_on_disk->get_args(saved_args)) {
|
---|
| 315 | // error
|
---|
[3300] | 316 | logout << "collectoraction: argdb::get_args failed (" << argfile << ")\n";
|
---|
[2368] | 317 | }
|
---|
| 318 | delete args_on_disk;
|
---|
| 319 | here = saved_args.begin();
|
---|
| 320 | end = saved_args.end();
|
---|
| 321 | while (here != end) {
|
---|
| 322 | if (!(*here).second.empty()) {
|
---|
| 323 | args[(*here).first] = (*here).second;
|
---|
| 324 | }
|
---|
[9620] | 325 | ++here;
|
---|
[2368] | 326 | }
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[1425] | 329 | if (args["bc1infochanged"] == "1") {
|
---|
[1457] | 330 |
|
---|
[1425] | 331 | if (args["bc1dirname"].empty()) {
|
---|
| 332 | // we've just come from the "collection information" page for the
|
---|
| 333 | // first time so we'll need to create the collection with mkcol.pl
|
---|
| 334 | // and set up bc1dirname - we do this part here instead of in do_action
|
---|
| 335 | // because the bc1dirname argument must be set to its new value before
|
---|
| 336 | // the compressedoptions macros are set.
|
---|
| 337 | args["bc1dirname"] = get_directory_name (args["bc1fullname"]);
|
---|
[1457] | 338 |
|
---|
| 339 | text_t createfile = filename_cat (gsdlhome, "tmp", args["bc1tmp"], ".create");
|
---|
| 340 | if (!file_exists (createfile)) {
|
---|
| 341 | // we could do the mkcol.pl here but I guess it's nicer to do it in do_action()
|
---|
| 342 | do_mkcol = true;
|
---|
| 343 | } else {
|
---|
| 344 | // .create file already exists but bc1dirname wasn't set ... this should only be
|
---|
| 345 | // able to occur when the "reload" (and possibly the "back" and "forward" buttons)
|
---|
| 346 | // have been used to get us here.
|
---|
| 347 | // we'll check that the bc1dirname directory exists (in case of the unlikely
|
---|
| 348 | // possibility that get_directory_name returned a different value this time
|
---|
| 349 | // than it did originally).
|
---|
| 350 | text_t coldir = filename_cat (get_collectdir(args), args["bc1dirname"]);
|
---|
| 351 | if (!directory_exists (coldir)) {
|
---|
| 352 | message = "reloaderror";
|
---|
| 353 | return true;
|
---|
| 354 | }
|
---|
| 355 | }
|
---|
[1425] | 356 | } else {
|
---|
[1457] | 357 | // "collection information" has been changed after collection already exists
|
---|
[1425] | 358 | // so we'll need to update the cfg file.
|
---|
[2518] | 359 | update_cfgfile_partial (args, false, logout);
|
---|
[1425] | 360 | }
|
---|
[1419] | 361 | }
|
---|
| 362 |
|
---|
| 363 | if (args["bc1cfgchanged"] == "1") {
|
---|
| 364 | // configuration file has been changed from the "configure collection"
|
---|
| 365 | // page. we need to update the file on disk and catch bc1 arguments up
|
---|
| 366 | // with changes.
|
---|
[1425] | 367 | update_cfgfile_complete (args, logout);
|
---|
| 368 | }
|
---|
| 369 |
|
---|
[1432] | 370 | if (args["bc1clonechanged"] == "1") {
|
---|
| 371 | // cloning option has been changed on "source data" page. if it was turned
|
---|
| 372 | // on we want to create a new collect.cfg file using the bc1clonecol cfg file
|
---|
| 373 | // as a model (we'll save the old file as collect.cfg.org). if cloning was
|
---|
| 374 | // turned off we'll revert to using the collect.cfg.org file (which will need
|
---|
| 375 | // updating in case the bc1 arguments have been altered since cloning was
|
---|
| 376 | // turned on).
|
---|
| 377 | update_cfgfile_clone (args, logout);
|
---|
[1485] | 378 |
|
---|
| 379 | // if cloning has just been turned on we'll also copy the rest of the files
|
---|
| 380 | // (excluding collect.cfg which we've already done) from the cloned collections
|
---|
| 381 | // etc directory to the new collection.
|
---|
| 382 | if (args["bc1clone"] == "1") {
|
---|
| 383 | text_t clone_etc = filename_cat(gsdlhome, "collect", args["bc1clonecol"], "etc");
|
---|
| 384 | text_t new_etc = filename_cat(get_collectdir(args), args["bc1dirname"], "etc");
|
---|
| 385 | text_tarray files;
|
---|
| 386 |
|
---|
| 387 | if (read_dir (clone_etc, files)) {
|
---|
| 388 | text_tarray::const_iterator here = files.begin();
|
---|
| 389 | text_tarray::const_iterator end = files.end();
|
---|
| 390 | while (here != end) {
|
---|
| 391 | if (*here != "collect.cfg" && *here != "collect.cfg.org") {
|
---|
| 392 | file_copy (filename_cat(clone_etc, *here), filename_cat(new_etc, *here));
|
---|
| 393 | }
|
---|
[9620] | 394 | ++here;
|
---|
[1485] | 395 | }
|
---|
| 396 | } else {
|
---|
| 397 | outconvertclass text_t2ascii;
|
---|
| 398 | logout <<text_t2ascii << "collectoraction::check_cgiargs couldn't read from "
|
---|
| 399 | << clone_etc << " directory\n";
|
---|
| 400 | }
|
---|
| 401 | }
|
---|
[1432] | 402 | }
|
---|
[1457] | 403 |
|
---|
[1507] | 404 | if (current_page == "bildstatus" || current_page == "bildcancel") {
|
---|
[1438] | 405 | // if .final file exists then build has finished
|
---|
[1457] | 406 | text_t fbld = filename_cat (gsdlhome, "tmp", args["bc1tmp"], args["bc1dirname"] + ".bld.final");
|
---|
[1438] | 407 | if (file_exists (fbld)) {
|
---|
| 408 | char *fbldc = fbld.getcstr();
|
---|
| 409 | ifstream fbld_in (fbldc);
|
---|
| 410 | if (fbld_in) {
|
---|
[2774] | 411 | failcode = fbld_in.get();
|
---|
[1438] | 412 | fbld_in.close();
|
---|
[2774] | 413 | if (failcode == '0') {
|
---|
[1649] | 414 | // success - we need to create and configure a collection server for the
|
---|
| 415 | // newly built collection (for fastcgi and local library where
|
---|
| 416 | // initialization isn't going to be redone when the user clicks the
|
---|
| 417 | // "view your new collection" button
|
---|
| 418 | create_colserver (args["bc1dirname"], logout);
|
---|
| 419 | current_page = "bilddone";
|
---|
| 420 | }
|
---|
[1438] | 421 | else current_page = "bildfail";
|
---|
| 422 | } else {
|
---|
| 423 | // assume build failed (we shouldn't get here though ... right?)
|
---|
| 424 | current_page = "bildfail";
|
---|
| 425 | }
|
---|
[7430] | 426 | delete []fbldc;
|
---|
[1438] | 427 | }
|
---|
| 428 | }
|
---|
| 429 |
|
---|
[2401] | 430 | if (args["bc1fromsrce"] == "1") {
|
---|
| 431 |
|
---|
| 432 | // we've just come from the "source data" page so we need to check that
|
---|
| 433 | // input sources are valid
|
---|
| 434 | if (!check_sources(args, logout)) {
|
---|
| 435 | args["p"] = "srce";
|
---|
| 436 | }
|
---|
| 437 | }
|
---|
| 438 |
|
---|
[1425] | 439 | return true;
|
---|
| 440 | }
|
---|
[1419] | 441 |
|
---|
[1432] | 442 | void collectoraction::update_cfgfile_clone (cgiargsclass &args, ostream &logout) {
|
---|
| 443 |
|
---|
[1457] | 444 | text_t tmpdir = filename_cat(gsdlhome, "tmp", args["bc1tmp"]);
|
---|
| 445 | text_t cfgfile = filename_cat(tmpdir, args["bc1dirname"], "etc", "collect.cfg");
|
---|
| 446 | if (!file_exists (cfgfile)) {
|
---|
| 447 | message = "tmpfail";
|
---|
| 448 | return;
|
---|
| 449 | }
|
---|
[1432] | 450 |
|
---|
[1457] | 451 | text_t cfgfile_org = filename_cat (tmpdir, "collect.cfg.org");
|
---|
| 452 |
|
---|
[1432] | 453 | if (args["bc1clone"] == "1") {
|
---|
| 454 | // cloning was turned on
|
---|
| 455 |
|
---|
| 456 | text_t cfgfile_clone = filename_cat(gsdlhome, "collect", args["bc1clonecol"], "etc", "collect.cfg");
|
---|
| 457 | if (file_exists (cfgfile_clone)) {
|
---|
| 458 | // if .org file doesn't exist already create it
|
---|
| 459 | if (!file_exists (cfgfile_org)) {
|
---|
[1457] | 460 | if (!file_copy (cfgfile, cfgfile_org)) {
|
---|
| 461 | message = "tmpfail";
|
---|
| 462 | return;
|
---|
| 463 | }
|
---|
[1432] | 464 | }
|
---|
| 465 | // copy clone collections cfg file to new collection
|
---|
[1457] | 466 | if (!file_copy (cfgfile_clone, cfgfile)) {
|
---|
| 467 | message = "tmpfail";
|
---|
| 468 | return;
|
---|
| 469 | }
|
---|
[1432] | 470 | // update the new cfg file
|
---|
[2518] | 471 | update_cfgfile_partial (args, true, logout);
|
---|
[1432] | 472 |
|
---|
| 473 | } else {
|
---|
[1457] | 474 | // can't clone non-existant or read-protected collection
|
---|
| 475 | message = "clonefail";
|
---|
[1432] | 476 | }
|
---|
| 477 |
|
---|
| 478 | } else {
|
---|
| 479 | // cloning has been turned off having been on at some point. the .org file
|
---|
| 480 | // should exist, if it doesn't we'll bail out and leave the user with the
|
---|
| 481 | // cloned copy
|
---|
| 482 | if (file_exists (cfgfile_org)) {
|
---|
| 483 | // copy original back again and update it with any recent changes
|
---|
[1457] | 484 | if (file_copy (cfgfile_org, cfgfile)) {
|
---|
[2518] | 485 | update_cfgfile_partial (args, false, logout);
|
---|
[1457] | 486 | } else {
|
---|
| 487 | message = "tmpfail";
|
---|
| 488 | }
|
---|
[1432] | 489 | }
|
---|
| 490 | }
|
---|
| 491 | }
|
---|
| 492 |
|
---|
[1425] | 493 | // update configuration file on disk to match bc1 arguments
|
---|
[2518] | 494 | // there's a special case if the clone option is true as certain parts of a
|
---|
| 495 | // config file should not be cloned (e.g. the iconcollection stuff)
|
---|
| 496 | void collectoraction::update_cfgfile_partial (cgiargsclass &args, bool clone, ostream &logout) {
|
---|
[1419] | 497 |
|
---|
[1457] | 498 | text_t cfgfile = filename_cat(get_collectdir(args), args["bc1dirname"], "etc", "collect.cfg");
|
---|
[1425] | 499 | char *cfgfilec = cfgfile.getcstr();
|
---|
| 500 |
|
---|
[2517] | 501 | #if defined (__WIN32__)
|
---|
| 502 | // make sure collect.cfg isn't read-only
|
---|
| 503 | _chmod (cfgfilec, _S_IREAD | _S_IWRITE);
|
---|
| 504 | #endif
|
---|
| 505 |
|
---|
[1425] | 506 | vector<text_tarray> cfgarray;
|
---|
| 507 |
|
---|
| 508 | // read in cfg file
|
---|
| 509 | ifstream cfg_in (cfgfilec);
|
---|
| 510 | if (cfg_in) {
|
---|
| 511 | text_tarray cfgline;
|
---|
| 512 | while (read_cfg_line(cfg_in, cfgline) >= 0) {
|
---|
| 513 | if (cfgline.size () >= 2) {
|
---|
[1432] | 514 | if (cfgline[0] == "creator" || cfgline[0] == "maintainer") {
|
---|
[1425] | 515 | cfgline[1] = args["bc1contactemail"];
|
---|
| 516 | } else if (cfgline[0] == "collectionmeta") {
|
---|
| 517 | if (cfgline[1] == "collectionname") {
|
---|
| 518 | cfgline[2] = args["bc1fullname"];
|
---|
| 519 | } else if (cfgline[1] == "collectionextra") {
|
---|
| 520 | cfgline[2] = carriage_replace (args["bc1aboutdesc"], 0);
|
---|
[2518] | 521 | } else if (clone && (cfgline[1] == "iconcollection" ||
|
---|
| 522 | cfgline[1] == "iconcollectionsmall")) {
|
---|
[7430] | 523 | cfgline[2] = g_EmptyText;
|
---|
[1425] | 524 | }
|
---|
| 525 | }
|
---|
| 526 | }
|
---|
| 527 | cfgarray.push_back (cfgline);
|
---|
| 528 | }
|
---|
| 529 | cfg_in.close();
|
---|
[1457] | 530 |
|
---|
[1425] | 531 | // now write cfg file back out
|
---|
[3007] | 532 | int fd=open(cfgfilec, O_WRONLY | O_CREAT | O_TRUNC
|
---|
| 533 | #if defined(__WIN32__)
|
---|
| 534 | | O_BINARY
|
---|
[1432] | 535 | #endif
|
---|
[3007] | 536 | );
|
---|
| 537 |
|
---|
| 538 | if (fd != -1) {
|
---|
[1425] | 539 | // lock the file
|
---|
| 540 | int lock_val = 1;
|
---|
| 541 | GSDL_LOCK_FILE (fd);
|
---|
| 542 | if (lock_val != 0) {
|
---|
| 543 | logout << "Error: Couldn't lock file " << cfgfilec << "\n";
|
---|
[3007] | 544 | close(fd);
|
---|
[1457] | 545 | message = "tmpfail";
|
---|
[1425] | 546 |
|
---|
| 547 | } else {
|
---|
| 548 |
|
---|
| 549 | vector<text_tarray>::const_iterator this_line = cfgarray.begin();
|
---|
| 550 | vector<text_tarray>::const_iterator end_line = cfgarray.end();
|
---|
| 551 | while (this_line != end_line) {
|
---|
[3007] | 552 | write_cfg_line (fd, *this_line);
|
---|
[9620] | 553 | ++this_line;
|
---|
[1425] | 554 | }
|
---|
| 555 | GSDL_UNLOCK_FILE (fd);
|
---|
[3007] | 556 | close(fd);
|
---|
[1425] | 557 | }
|
---|
| 558 |
|
---|
| 559 | } else {
|
---|
[1432] | 560 | logout << "collectoraction::update_cfgfile_partial: unable to open "
|
---|
[1425] | 561 | << cfgfilec << " for output\n";
|
---|
[1457] | 562 | message = "tmpfail";
|
---|
[1425] | 563 | }
|
---|
[1457] | 564 |
|
---|
[1425] | 565 | } else {
|
---|
[1432] | 566 | logout << "collectoraction::update_cfgfile_partial: unable to open "
|
---|
[1425] | 567 | << cfgfilec << " for input\n";
|
---|
[1457] | 568 | message = "tmpfail";
|
---|
[1419] | 569 | }
|
---|
[2517] | 570 |
|
---|
[7430] | 571 | delete []cfgfilec;
|
---|
[1425] | 572 | }
|
---|
[1419] | 573 |
|
---|
[1796] | 574 | // replace configuration file on disk with that in the cfgfile argument and
|
---|
[1425] | 575 | // catch other bc1 arguments up with those the new cfgfile contains
|
---|
| 576 | void collectoraction::update_cfgfile_complete (cgiargsclass &args, ostream &logout) {
|
---|
| 577 |
|
---|
[1457] | 578 | text_t cfgfile = filename_cat(get_collectdir(args), args["bc1dirname"], "etc", "collect.cfg");
|
---|
[1425] | 579 | char *cfgfilec = cfgfile.getcstr();
|
---|
[2517] | 580 |
|
---|
[1432] | 581 | #ifdef __WIN32__
|
---|
[2517] | 582 | // make sure collect.cfg isn't read-only
|
---|
| 583 | _chmod (cfgfilec, _S_IREAD | _S_IWRITE);
|
---|
[1432] | 584 | #endif
|
---|
[3007] | 585 |
|
---|
| 586 | int fd=open(cfgfilec, O_WRONLY | O_CREAT | O_TRUNC
|
---|
| 587 | #if defined(__WIN32__)
|
---|
| 588 | | O_BINARY
|
---|
| 589 | #endif
|
---|
| 590 | );
|
---|
| 591 |
|
---|
| 592 | if (fd) {
|
---|
[1425] | 593 | // lock the file
|
---|
| 594 | int lock_val = 1;
|
---|
| 595 | GSDL_LOCK_FILE (fd);
|
---|
| 596 | if (lock_val != 0) {
|
---|
| 597 | logout << "Error: Couldn't lock file " << cfgfilec << "\n";
|
---|
[3007] | 598 | close(fd);
|
---|
[1457] | 599 | message = "tmpfail";
|
---|
[1425] | 600 |
|
---|
| 601 | } else {
|
---|
| 602 |
|
---|
| 603 | outconvertclass text_t2ascii;
|
---|
[3036] | 604 | text_t2ascii.setinput(&args["cfgfile"]);
|
---|
[3007] | 605 | size_t buffersize=args["cfgfile"].size();
|
---|
| 606 | char *buffer=new char[buffersize];
|
---|
[3036] | 607 | buffer[0]='\n'; // just in case something goes wrong...
|
---|
[3007] | 608 | size_t num_chars;
|
---|
| 609 | convertclass::status_t status;
|
---|
| 610 | text_t2ascii.convert(buffer, buffersize, num_chars, status);
|
---|
| 611 | // ignore status - assume it is "finished" as buffer is big enough
|
---|
| 612 | write(fd, buffer, num_chars);
|
---|
[1425] | 613 | GSDL_UNLOCK_FILE (fd);
|
---|
[3007] | 614 | close(fd);
|
---|
[7430] | 615 | delete []buffer;
|
---|
[1425] | 616 |
|
---|
| 617 | // now that we've written the file we'll read it back again and
|
---|
| 618 | // update our bc1 arguments
|
---|
| 619 | ifstream cfg_in (cfgfilec);
|
---|
| 620 | if (cfg_in) {
|
---|
| 621 | text_tarray cfgline;
|
---|
| 622 | while (read_cfg_line(cfg_in, cfgline) >= 0) {
|
---|
| 623 | if (cfgline.size () >= 2) {
|
---|
| 624 | if (cfgline[0] == "creator") {
|
---|
| 625 | args["bc1contactemail"] = cfgline[1];
|
---|
| 626 | } else if (cfgline[0] == "collectionmeta") {
|
---|
| 627 | if (cfgline[1] == "collectionname") {
|
---|
| 628 | args["bc1fullname"] = cfgline[2];
|
---|
| 629 | } else if (cfgline[1] == "collectionextra") {
|
---|
| 630 | args["bc1aboutdesc"] = carriage_replace (cfgline[2], 1);
|
---|
| 631 | }
|
---|
| 632 | }
|
---|
| 633 | }
|
---|
| 634 | }
|
---|
| 635 | cfg_in.close();
|
---|
| 636 | } else {
|
---|
| 637 | logout << "collectoraction::update_cfgfile_complete: unable to open "
|
---|
| 638 | << cfgfilec << " for input\n";
|
---|
[1457] | 639 | message = "tmpfail";
|
---|
[1425] | 640 | }
|
---|
| 641 | }
|
---|
| 642 | } else {
|
---|
| 643 | logout << "collectoraction::update_cfgfile_complete: unable to open "
|
---|
| 644 | << cfgfilec << " for output\n";
|
---|
[1457] | 645 | message = "tmpfail";
|
---|
[1425] | 646 | }
|
---|
[2517] | 647 |
|
---|
[7430] | 648 | delete []cfgfilec;
|
---|
[1419] | 649 | }
|
---|
| 650 |
|
---|
| 651 |
|
---|
| 652 | // return html for buttons used in collector bar
|
---|
| 653 | // color may be "green", "grey", or "yellow"
|
---|
| 654 | // type may be:
|
---|
| 655 | // "info" --> "collection information" button
|
---|
| 656 | // "srce" --> "source data" button
|
---|
| 657 | // "conf" --> "configure collection" button
|
---|
| 658 | // "bild" --> "build collection" button
|
---|
| 659 | // "view" --> "view collection" button
|
---|
| 660 | // if enabled is true button will be flashy rollover type and
|
---|
| 661 | // will be hyperlinked
|
---|
| 662 |
|
---|
[11998] | 663 | // Wendy left a comment suggesting this be move, but where to
|
---|
| 664 | // was not specified. Into wizardaction.cpp?
|
---|
[1419] | 665 |
|
---|
[2401] | 666 | // set the _fullnamemenu_ macro (and _warnindex_ and _selectedindex_ if
|
---|
| 667 | // we're on the "srce" page)
|
---|
[1419] | 668 | void collectoraction::set_fullnamemenu (displayclass &disp, cgiargsclass &args,
|
---|
| 669 | recptprotolistclass *protos, ostream &logout) {
|
---|
| 670 |
|
---|
| 671 | if (recpt == NULL) {
|
---|
| 672 | logout << "ERROR (collectoraction::set_fullnamemenu): This action does not contain\n"
|
---|
| 673 | << " information about any receptionists. The method set_receptionist was\n"
|
---|
| 674 | << " probably not called from the module which instantiated this action.\n";
|
---|
| 675 | return;
|
---|
| 676 | }
|
---|
| 677 |
|
---|
[1796] | 678 | text_t ¤t_page = args["p"];
|
---|
[11998] | 679 | text_t currentname = args[macro_prefix+"dirname"];
|
---|
| 680 | if (current_page == "srce") currentname = args[macro_prefix + "clonecol"];
|
---|
[1419] | 681 |
|
---|
[1432] | 682 | text_tarray dirnames;
|
---|
| 683 | text_tarray fullnames;
|
---|
| 684 | vector<bool> write_protected;
|
---|
[2401] | 685 | bool is_selected = false;
|
---|
[1432] | 686 | int selected_index = 0;
|
---|
| 687 | int index = 0;
|
---|
| 688 |
|
---|
[1419] | 689 | recptprotolistclass::iterator rprotolist_here = protos->begin();
|
---|
| 690 | recptprotolistclass::iterator rprotolist_end = protos->end();
|
---|
| 691 | while (rprotolist_here != rprotolist_end) {
|
---|
| 692 | if ((*rprotolist_here).p != NULL) {
|
---|
[1437] | 693 |
|
---|
[2401] | 694 | // don't include z39.50 collections
|
---|
[2261] | 695 | comerror_t err = noError;
|
---|
[2113] | 696 | if ((*rprotolist_here).p->get_protocol_name (err) == "z3950proto") {
|
---|
[9620] | 697 | ++rprotolist_here;
|
---|
[1437] | 698 | continue;
|
---|
| 699 | }
|
---|
| 700 |
|
---|
[1419] | 701 | text_tarray collist;
|
---|
| 702 | (*rprotolist_here).p->get_collection_list (collist, err, logout);
|
---|
| 703 | if (err == noError) {
|
---|
| 704 | text_tarray::iterator collist_here = collist.begin();
|
---|
| 705 | text_tarray::iterator collist_end = collist.end();
|
---|
| 706 | while (collist_here != collist_end) {
|
---|
| 707 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
|
---|
| 708 | if (cinfo != NULL) {
|
---|
[9931] | 709 | text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]);
|
---|
| 710 | if (collectionname.empty()) {
|
---|
| 711 | collectionname = *collist_here;
|
---|
[1419] | 712 | }
|
---|
[1432] | 713 | dirnames.push_back(*collist_here);
|
---|
| 714 | fullnames.push_back(collectionname);
|
---|
[1485] | 715 | // check to see if the collection is writable
|
---|
[1432] | 716 | if (collection_protected (*collist_here)) write_protected.push_back(true);
|
---|
| 717 | else write_protected.push_back(false);
|
---|
[1485] | 718 |
|
---|
[2401] | 719 | if (*collist_here == currentname) {
|
---|
| 720 | is_selected = true;
|
---|
| 721 | selected_index = index;
|
---|
| 722 | }
|
---|
[9620] | 723 | ++index;
|
---|
[1419] | 724 | }
|
---|
[9620] | 725 | ++collist_here;
|
---|
[1419] | 726 | }
|
---|
| 727 | }
|
---|
| 728 | }
|
---|
[9620] | 729 | ++rprotolist_here;
|
---|
[1419] | 730 | }
|
---|
[1432] | 731 |
|
---|
[1485] | 732 | bool first = true;
|
---|
[11998] | 733 |
|
---|
[1485] | 734 | text_t warnindex;
|
---|
[11998] | 735 | text_t fullnamemenu = "<select name=\""+macro_prefix+"dirname\" onChange=\"menuchange();\">\n";
|
---|
| 736 |
|
---|
[2401] | 737 | if (current_page == "srce") {
|
---|
[11998] | 738 | fullnamemenu = "<select name=\""+macro_prefix+"clonecol\" onChange=\"menuchange();\">\n";
|
---|
[2401] | 739 | fullnamemenu += "<option value=defaultstructure";
|
---|
| 740 | if (!is_selected) fullnamemenu += " selected>";
|
---|
| 741 | else fullnamemenu.push_back('>');
|
---|
[3212] | 742 | fullnamemenu += "_collector:textdefaultstructure_\n";
|
---|
[2401] | 743 | }
|
---|
[11998] | 744 |
|
---|
| 745 | fullnamemenu += "<option value=\"\"></option>\n";
|
---|
| 746 |
|
---|
[9620] | 747 | for (int i = 0; i < index; ++i) {
|
---|
[1432] | 748 | // don't want write protected collections in list on "change existing
|
---|
| 749 | // collection" page
|
---|
| 750 | if (write_protected[i] && current_page == "existing") continue;
|
---|
| 751 | fullnamemenu += "<option value=\"" + dirnames[i] + "\"";
|
---|
[2401] | 752 | if ((i == 0 && !is_selected && current_page != "srce") ||
|
---|
| 753 | (is_selected && i == selected_index)) {
|
---|
| 754 | fullnamemenu += " selected";
|
---|
[9620] | 755 | ++selected_index;
|
---|
[2401] | 756 | is_selected = false;
|
---|
| 757 | }
|
---|
[1432] | 758 | fullnamemenu.push_back ('>');
|
---|
| 759 | fullnamemenu += fullnames[i];
|
---|
[1485] | 760 | fullnamemenu.push_back ('\n');
|
---|
| 761 |
|
---|
| 762 | // add to Warnindex if collection uses any dubious plugins
|
---|
| 763 | // (if creating clone collection list)
|
---|
| 764 | if (current_page == "srce") {
|
---|
[2401] | 765 | if (first) warnindex += "0,";
|
---|
| 766 | else warnindex.push_back(',');
|
---|
[1485] | 767 | if (uses_weird_plugin (dirnames[i])) {
|
---|
| 768 | warnindex += text_t (1);
|
---|
| 769 | } else {
|
---|
| 770 | warnindex += text_t (0);
|
---|
| 771 | }
|
---|
| 772 | }
|
---|
| 773 | first = false;
|
---|
[1419] | 774 | }
|
---|
[1432] | 775 | fullnamemenu += "</select>\n";
|
---|
[11998] | 776 | text_t action_name = get_action_name();
|
---|
| 777 | disp.setmacro ("fullnamemenu", action_name, fullnamemenu);
|
---|
[2401] | 778 | if (current_page == "srce") {
|
---|
[11998] | 779 | disp.setmacro ("warnindex",action_name , warnindex);
|
---|
| 780 | disp.setmacro ("selectedindex", action_name, text_t(selected_index));
|
---|
[1485] | 781 | }
|
---|
[1419] | 782 | }
|
---|
| 783 |
|
---|
[11998] | 784 |
|
---|
[2407] | 785 | // set _sourcelist_ and _badsources_ macros
|
---|
[2401] | 786 | void collectoraction::set_inputsourceboxes (displayclass &disp, cgiargsclass &args,
|
---|
| 787 | ostream &logout) {
|
---|
| 788 |
|
---|
| 789 | if (badsources) disp.setmacro ("badsources", "collector", "1");
|
---|
| 790 |
|
---|
[2407] | 791 | text_t sourcelist = get_source_box(args["bc1input"], args["bc1inputnum"].getint(),
|
---|
| 792 | args["bc1inputtype"]);
|
---|
[2401] | 793 |
|
---|
[2407] | 794 | disp.setmacro("sourcelist", "collector", sourcelist);
|
---|
[2401] | 795 |
|
---|
| 796 | // reset badsources and failedsources variables
|
---|
| 797 | badsources = false;
|
---|
| 798 | failedsources.erase(failedsources.begin(), failedsources.end());
|
---|
| 799 | }
|
---|
| 800 |
|
---|
[2407] | 801 | text_t collectoraction::get_source_box (text_t inputarglist, int numboxes,
|
---|
| 802 | text_t inputtypelist) {
|
---|
[2401] | 803 |
|
---|
[2407] | 804 | text_tarray inputvalues;
|
---|
| 805 | splitchar (inputarglist.begin(), inputarglist.end(), ',', inputvalues);
|
---|
| 806 | // remove any empty values from the end of the array
|
---|
| 807 | if (inputvalues.size()) {
|
---|
| 808 | text_tarray::iterator l = inputvalues.end() - 1;
|
---|
| 809 | text_tarray::iterator b = inputvalues.begin();
|
---|
| 810 | while ((*l).empty() && l >= b) {
|
---|
[9620] | 811 | --l;
|
---|
[2407] | 812 | }
|
---|
| 813 | inputvalues.erase(l+1, inputvalues.end());
|
---|
| 814 | }
|
---|
[2401] | 815 |
|
---|
[2407] | 816 | text_tarray inputtypes;
|
---|
| 817 | splitchar (inputtypelist.begin(), inputtypelist.end(), ',', inputtypes);
|
---|
| 818 |
|
---|
| 819 | int numvalues = inputvalues.size();
|
---|
| 820 | int numtypes = inputtypes.size();
|
---|
| 821 |
|
---|
| 822 | text_t last = "file://";
|
---|
| 823 | text_t rv;
|
---|
[9620] | 824 | for (int i = 0; i < numboxes; ++i) {
|
---|
[2407] | 825 | rv += "<nobr><select name=\"bc1inputtype\">\n";
|
---|
| 826 | rv += "<option value=\"file://\"";
|
---|
| 827 | if ((i < numtypes && inputtypes[i] == "file://") ||
|
---|
| 828 | (numboxes == 3 && i == 0 && numvalues == 0) ||
|
---|
| 829 | (i >= 3 && i >= numvalues && last == "file://")) {
|
---|
| 830 | rv += " selected";
|
---|
| 831 | last = "file://";
|
---|
[2401] | 832 | }
|
---|
[2407] | 833 | rv += ">file://\n";
|
---|
| 834 | rv += "<option value=\"http://\"";
|
---|
| 835 | if ((i < numtypes && inputtypes[i] == "http://") ||
|
---|
| 836 | (numboxes == 3 && i == 1 && numvalues == 0) ||
|
---|
| 837 | (i >= 3 && i >= numvalues && last == "http://")) {
|
---|
| 838 | rv += " selected";
|
---|
| 839 | last = "http://";
|
---|
| 840 | }
|
---|
| 841 | rv += ">http://\n";
|
---|
| 842 | rv += "<option value=\"ftp://\"";
|
---|
| 843 | if ((i < numtypes && inputtypes[i] == "ftp://") ||
|
---|
| 844 | (numboxes == 3 && i == 2 && numvalues == 0) ||
|
---|
| 845 | (i >= 3 && i >= numvalues && last == "ftp://")) {
|
---|
| 846 | rv += " selected";
|
---|
| 847 | last = "ftp://";
|
---|
| 848 | }
|
---|
| 849 | rv += ">ftp://\n";
|
---|
| 850 | rv += "</select>\n";
|
---|
| 851 | rv += "<input type=text name=\"bc1input\" value=\"";
|
---|
| 852 | if (i < numvalues) {
|
---|
[2426] | 853 | rv += dm_safe(decode_commas(inputvalues[i]));
|
---|
[2407] | 854 | }
|
---|
| 855 | rv += "\" size=50>";
|
---|
[2401] | 856 | if (badsources) {
|
---|
[2407] | 857 | if ((i < numvalues) && (!inputvalues[i].empty())) {
|
---|
[2426] | 858 | if (failedsources[decode_commas(inputvalues[i])] == "1") {
|
---|
[2407] | 859 | rv += "_iconcross_";
|
---|
[2401] | 860 | } else {
|
---|
[2407] | 861 | rv += "_icontick_";
|
---|
[2401] | 862 | }
|
---|
| 863 | } else {
|
---|
[2407] | 864 | rv += "_iconblank_";
|
---|
[2401] | 865 | }
|
---|
| 866 | }
|
---|
| 867 | if (i+1 == numboxes) {
|
---|
[2418] | 868 | if (!badsources) rv += "_iconblank_";
|
---|
| 869 | rv += "_imagemore_</nobr><br>";
|
---|
[2401] | 870 | } else {
|
---|
[2418] | 871 | rv += "</nobr><br>\n";
|
---|
[2401] | 872 | }
|
---|
| 873 | }
|
---|
| 874 |
|
---|
| 875 | return rv;
|
---|
| 876 | }
|
---|
| 877 |
|
---|
[1419] | 878 | // set the _cfgfile_ macro
|
---|
[1457] | 879 | void collectoraction::set_cfgfile (displayclass &disp, cgiargsclass &args, ostream &logout) {
|
---|
[1419] | 880 |
|
---|
[1457] | 881 | text_t &collection = args["bc1dirname"];
|
---|
| 882 | if (collection.empty()) {
|
---|
| 883 | message = "nocollection";
|
---|
| 884 | return;
|
---|
| 885 | }
|
---|
| 886 |
|
---|
[1419] | 887 | // read in collect.cfg
|
---|
[1457] | 888 | text_t cfgfile = filename_cat(get_collectdir(args), collection, "etc", "collect.cfg");
|
---|
[1419] | 889 | char *cfgfilec = cfgfile.getcstr();
|
---|
| 890 |
|
---|
| 891 | #ifdef GSDL_USE_IOS_H
|
---|
| 892 | ifstream cfg_ifs (cfgfilec, ios::in | ios::nocreate);
|
---|
| 893 | #else
|
---|
| 894 | ifstream cfg_ifs (cfgfilec, ios::in);
|
---|
| 895 | #endif
|
---|
| 896 |
|
---|
| 897 | if (cfg_ifs) {
|
---|
| 898 | // read in collect.cfg
|
---|
| 899 | text_t cfgtext;
|
---|
| 900 | char c;
|
---|
| 901 | cfg_ifs.get(c);
|
---|
| 902 | while (!cfg_ifs.eof ()) {
|
---|
| 903 | cfgtext.push_back(c);
|
---|
| 904 | cfg_ifs.get(c);
|
---|
| 905 | }
|
---|
| 906 | cfg_ifs.close();
|
---|
| 907 |
|
---|
| 908 | // define it as a macro
|
---|
[2401] | 909 | disp.setmacro("cfgfile", "collector", dm_safe(cfgtext));
|
---|
[1425] | 910 |
|
---|
| 911 | } else {
|
---|
| 912 | logout << "collectoraction::set_cfgfile: couldn't open configuration file ("
|
---|
| 913 | << cfgfilec << ") for reading\n";
|
---|
[1457] | 914 | message = "tmpfail";
|
---|
[1425] | 915 | }
|
---|
[7430] | 916 | delete []cfgfilec;
|
---|
[1419] | 917 | }
|
---|
| 918 |
|
---|
[1437] | 919 |
|
---|
[1419] | 920 | void collectoraction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
| 921 | recptprotolistclass *protos, ostream &logout) {
|
---|
| 922 |
|
---|
| 923 | // define_internal_macros sets the following macros:
|
---|
| 924 | // _collectorbar_
|
---|
| 925 | // _pagescriptextra_
|
---|
[1432] | 926 | // _fullnamemenu_ -- if displaying the "source data" page or the "changing existing
|
---|
| 927 | // collection" page
|
---|
[1419] | 928 | // _cfgfile_ -- if displaying the "configure collection" page
|
---|
[1437] | 929 | // _statusline_ -- if displaying the bildstatus page
|
---|
[1438] | 930 | // _header_ -- may be set for pages that require it
|
---|
[2774] | 931 | // _textfailmsg_ -- set to different messages depending on failcode returned
|
---|
| 932 | // by build script (if build fails)
|
---|
[1485] | 933 | // _faillog_ - set to last 6 lines of .bld file if build failed
|
---|
[1679] | 934 | // _gsdlhome_ - the gsdlhome path (dm_safe)
|
---|
[2407] | 935 | // _sourcelist_ -- "input source" text boxes
|
---|
[2401] | 936 | // _badsources_ -- will be set to "1" if we've come from the
|
---|
| 937 | // "source data" page and there's a problem
|
---|
| 938 | // with the input sources
|
---|
| 939 |
|
---|
[1796] | 940 | text_t &collector_page = args["p"];
|
---|
[1432] | 941 | int esrce = args["bc1esrce"].getint();
|
---|
| 942 | int econf = args["bc1econf"].getint();
|
---|
[1419] | 943 |
|
---|
| 944 | // set _pagescriptextra_ macro to _cpagescriptextra_
|
---|
| 945 | disp.setmacro ("pagescriptextra", "collector", "_" + collector_page + "scriptextra_");
|
---|
| 946 |
|
---|
[1457] | 947 | if (collector_page == "bildstatus" || collector_page == "bilddone" ||
|
---|
| 948 | collector_page == "bildfail" || collector_page == "bildframe1") {
|
---|
[1438] | 949 | disp.setmacro ("header", "collector", "_" + collector_page + "header_");
|
---|
[1437] | 950 | }
|
---|
| 951 |
|
---|
[1419] | 952 | // set the collectorbar macro
|
---|
[11998] | 953 | text_t collectorbar = "<table class=wizardbar border=0 cellspacing=4 cellpadding=0><tr>\n";
|
---|
[1419] | 954 |
|
---|
| 955 | if (collector_page == "new") {
|
---|
[1507] | 956 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 957 | collectorbar += get_button (args,collector_page, "green", "info", true);
|
---|
[1419] | 958 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 959 | collectorbar += get_button (args,collector_page, "grey", "srce", false);
|
---|
[1419] | 960 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 961 | collectorbar += get_button (args,collector_page, "grey", "conf", false);
|
---|
[1419] | 962 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 963 | collectorbar += get_button (args,collector_page, "grey", "bild", false);
|
---|
[1419] | 964 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 965 | collectorbar += get_button (args,collector_page, "grey", "view", false);
|
---|
[1419] | 966 |
|
---|
| 967 | } else if (collector_page == "info") {
|
---|
[1507] | 968 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 969 | collectorbar += get_button (args,collector_page, "yellow", "info", false);
|
---|
[1419] | 970 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 971 | collectorbar += get_button (args,collector_page, "green", "srce", true);
|
---|
[1419] | 972 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 973 | collectorbar += get_button (args,collector_page, "grey", "conf", false);
|
---|
[1419] | 974 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 975 | collectorbar += get_button (args,collector_page, "grey", "bild", false);
|
---|
[1419] | 976 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 977 | collectorbar += get_button (args,collector_page, "grey", "view", false);
|
---|
[1507] | 978 | collectorbar += "</tr><tr><td></td><td align=center>_icongreyuparrow_</td><td colspan=8></td>\n";
|
---|
[1419] | 979 |
|
---|
| 980 | } else if (collector_page == "srce") {
|
---|
[1507] | 981 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[1432] | 982 | if (esrce == 1) {
|
---|
| 983 | // if we came from the "change an existing collection" page previous button(s)
|
---|
| 984 | // are disabled
|
---|
[11998] | 985 | collectorbar += get_button (args,collector_page, "grey", "info", false);
|
---|
[1432] | 986 | } else {
|
---|
[11998] | 987 | collectorbar += get_button (args,collector_page, "yellow", "info", true);
|
---|
[1432] | 988 | }
|
---|
[1419] | 989 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 990 | collectorbar += get_button (args,collector_page, "yellow", "srce", false);
|
---|
[1419] | 991 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 992 | collectorbar += get_button (args,collector_page, "green", "conf", true);
|
---|
[1419] | 993 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 994 | collectorbar += get_button (args,collector_page, "green", "bild", true);
|
---|
[1419] | 995 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 996 | collectorbar += get_button (args,collector_page, "grey", "view", false);
|
---|
[1507] | 997 | collectorbar += "</tr><tr><td colspan=3></td><td align=center>_icongreyuparrow_</td><td colspan=6></td>\n";
|
---|
[1419] | 998 |
|
---|
| 999 | } else if (collector_page == "conf") {
|
---|
[1507] | 1000 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[1432] | 1001 | // disable appropriate buttons if we came from "change an existing collection"
|
---|
| 1002 | // page
|
---|
| 1003 | if (esrce == 1 || econf == 1) {
|
---|
[11998] | 1004 | collectorbar += get_button (args,collector_page, "grey", "info", false);
|
---|
[1432] | 1005 | } else {
|
---|
[11998] | 1006 | collectorbar += get_button (args,collector_page, "yellow", "info", true);
|
---|
[1432] | 1007 | }
|
---|
[1419] | 1008 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[1432] | 1009 | if (econf == 1) {
|
---|
[11998] | 1010 | collectorbar += get_button (args,collector_page, "grey", "srce", false);
|
---|
[1432] | 1011 | } else {
|
---|
[11998] | 1012 | collectorbar += get_button (args,collector_page, "yellow", "srce", true);
|
---|
[1432] | 1013 | }
|
---|
[1419] | 1014 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 1015 | collectorbar += get_button (args,collector_page, "yellow", "conf", false);
|
---|
[1419] | 1016 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 1017 | collectorbar += get_button (args,collector_page, "green", "bild", true);
|
---|
[1419] | 1018 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 1019 | collectorbar += get_button (args,collector_page, "grey", "view", false);
|
---|
[1507] | 1020 | collectorbar += "</tr><tr><td colspan=5></td><td align=center>_icongreyuparrow_</td><td colspan=4></td>\n";
|
---|
[1425] | 1021 |
|
---|
[1449] | 1022 | } else if (collector_page == "bilddone") {
|
---|
[1507] | 1023 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[1449] | 1024 | // all previous buttons grey after build was completed
|
---|
[11998] | 1025 | collectorbar += get_button (args,collector_page, "grey", "info", false);
|
---|
[1449] | 1026 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 1027 | collectorbar += get_button (args,collector_page, "grey", "srce", false);
|
---|
[1449] | 1028 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 1029 | collectorbar += get_button (args,collector_page, "grey", "conf", false);
|
---|
[1449] | 1030 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 1031 | collectorbar += get_button (args,collector_page, "yellow", "bild", false);
|
---|
[1449] | 1032 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 1033 | collectorbar += get_button (args,collector_page, "green", "view", true);
|
---|
[1507] | 1034 | collectorbar += "</tr><tr><td colspan=7></td><td align=center>_icongreyuparrow_</td><td colspan=2></td>\n";
|
---|
[1457] | 1035 |
|
---|
[1507] | 1036 | } else if (collector_page == "bildcancel" || collector_page == "bildfail") {
|
---|
| 1037 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[1457] | 1038 | // disable appropriate buttons if we came from "change an existing collection"
|
---|
| 1039 | // page
|
---|
| 1040 | if (esrce == 1 || econf == 1) {
|
---|
[11998] | 1041 | collectorbar += get_button (args,collector_page, "grey", "info", false);
|
---|
[1457] | 1042 | } else {
|
---|
[11998] | 1043 | collectorbar += get_button (args,collector_page, "yellow", "info", true);
|
---|
[1457] | 1044 | }
|
---|
| 1045 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
| 1046 | if (econf == 1) {
|
---|
[11998] | 1047 | collectorbar += get_button (args,collector_page, "grey", "srce", false);
|
---|
[1457] | 1048 | } else {
|
---|
[11998] | 1049 | collectorbar += get_button (args,collector_page, "yellow", "srce", true);
|
---|
[1457] | 1050 | }
|
---|
| 1051 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 1052 | collectorbar += get_button (args,collector_page, "yellow", "conf", true);
|
---|
[1457] | 1053 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 1054 | collectorbar += get_button (args,collector_page, "yellow", "bild", true);
|
---|
[1457] | 1055 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
[11998] | 1056 | collectorbar += get_button (args,collector_page, "grey", "view", false);
|
---|
[1419] | 1057 | }
|
---|
| 1058 |
|
---|
[2785] | 1059 | collectorbar += "</tr></table>\n";
|
---|
| 1060 | disp.setmacro ("collectorbar", "collector", collectorbar);
|
---|
| 1061 |
|
---|
[1485] | 1062 | if (collector_page == "bildfail") {
|
---|
[2774] | 1063 |
|
---|
| 1064 | text_t textfailmsg = "_textfailmsg";
|
---|
| 1065 | textfailmsg.push_back(failcode);
|
---|
| 1066 | textfailmsg.push_back('_');
|
---|
| 1067 | disp.setmacro("textfailmsg", "collector", textfailmsg);
|
---|
| 1068 |
|
---|
[1485] | 1069 | text_t bldlog = filename_cat(gsdlhome, "tmp", args["bc1tmp"], args["bc1dirname"] + ".bld");
|
---|
[1837] | 1070 | text_t rawlog = file_tail (bldlog, 6, 0);
|
---|
[1485] | 1071 | // we'll shove in some <br> tags where \n's occur
|
---|
| 1072 | text_t faillog;
|
---|
| 1073 | text_t::const_iterator here = rawlog.begin();
|
---|
| 1074 | text_t::const_iterator end = rawlog.end();
|
---|
| 1075 | while (here != end) {
|
---|
| 1076 | if (*here == '\n') faillog += "<br>";
|
---|
| 1077 | faillog.push_back (*here);
|
---|
[9620] | 1078 | ++here;
|
---|
[1485] | 1079 | }
|
---|
[1679] | 1080 | disp.setmacro ("faillog", "collector", dm_safe(faillog));
|
---|
[1485] | 1081 | }
|
---|
| 1082 |
|
---|
[1432] | 1083 | if (collector_page == "srce" || collector_page == "existing")
|
---|
| 1084 | set_fullnamemenu (disp, args, protos, logout);
|
---|
| 1085 | if (collector_page == "conf")
|
---|
[1457] | 1086 | set_cfgfile (disp, args, logout);
|
---|
[1437] | 1087 | if (collector_page == "bildstatus")
|
---|
[1457] | 1088 | set_statusline (disp, args, logout);
|
---|
[2401] | 1089 | if (collector_page == "srce") {
|
---|
| 1090 | set_inputsourceboxes (disp, args, logout);
|
---|
| 1091 | }
|
---|
[1679] | 1092 |
|
---|
| 1093 | disp.setmacro ("gsdlhome", "collector", dm_safe(gsdlhome));
|
---|
[1419] | 1094 | }
|
---|
| 1095 |
|
---|
[11998] | 1096 |
|
---|
[1419] | 1097 | bool collectoraction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
|
---|
| 1098 | browsermapclass * /*browsers*/, displayclass &disp,
|
---|
| 1099 | outconvertclass &outconvert, ostream &textout,
|
---|
[1432] | 1100 | ostream &logout) {
|
---|
[1419] | 1101 |
|
---|
[1759] | 1102 | // make sure the collector is enabled
|
---|
| 1103 | if (disabled) {
|
---|
| 1104 | textout << outconvert
|
---|
| 1105 | << "<html>\n"
|
---|
| 1106 | << "<head>\n"
|
---|
| 1107 | << "<title>Collector disabled</title>\n"
|
---|
| 1108 | << "</head>\n"
|
---|
| 1109 | << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
|
---|
| 1110 | << "alink=\"#cc9900\" vlink=\"#666633\">\n"
|
---|
| 1111 | << "<h2>Facility disabled</h2>\n"
|
---|
| 1112 | << "Sorry, the Collector end-user collection building facility is currently disabled\n"
|
---|
| 1113 | << "\n</body>\n"
|
---|
| 1114 | << "</html>\n";
|
---|
| 1115 | return true;
|
---|
| 1116 | }
|
---|
| 1117 |
|
---|
[1796] | 1118 | text_t &collector_page = args["p"];
|
---|
[1789] | 1119 | text_t &collection = args["bc1dirname"];
|
---|
| 1120 |
|
---|
[1817] | 1121 | // make sure we have perl (we won't bother with this check for the
|
---|
| 1122 | // building status pages to avoid slowing things down unneccessarily)
|
---|
| 1123 | if (collector_page != "bildstatus" && collector_page != "bildframe1" && !perl_ok(logout)) {
|
---|
[1783] | 1124 | textout << outconvert
|
---|
| 1125 | << "<html>\n"
|
---|
| 1126 | << "<head>\n"
|
---|
| 1127 | << "<title>Perl not found</title>\n"
|
---|
| 1128 | << "</head>\n"
|
---|
| 1129 | << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
|
---|
| 1130 | << "alink=\"#cc9900\" vlink=\"#666633\">\n"
|
---|
| 1131 | << "<h2>Perl not found</h2>\n"
|
---|
[2727] | 1132 | << "Greenstone could not detect perl on this system. It is therefore not\n"
|
---|
| 1133 | << "possible to build a Greenstone collection, either from the Collector or the \n"
|
---|
| 1134 | << "command-line tools, or to use the Collector for any other task.\n"
|
---|
| 1135 | << "<p>Please refer to the Greenstone Installer's Guide for details on\n"
|
---|
| 1136 | << "installing perl on your system.\n"
|
---|
[1783] | 1137 | << "\n</body>\n"
|
---|
| 1138 | << "</html>\n";
|
---|
| 1139 | return true;
|
---|
| 1140 |
|
---|
| 1141 | }
|
---|
| 1142 |
|
---|
[1425] | 1143 | if (collector_page == "bild") {
|
---|
| 1144 | // do the work (download, import, build)
|
---|
[1457] | 1145 | gsdl_build (args, logout);
|
---|
[1432] | 1146 |
|
---|
[1457] | 1147 | if (message.empty()) {
|
---|
| 1148 | // bild page is a frameset so we don't want headers and stuff
|
---|
| 1149 | textout << outconvert << disp << ("_collector:bildcontent_\n");
|
---|
[1425] | 1150 | }
|
---|
[1457] | 1151 | }
|
---|
[1419] | 1152 |
|
---|
[1457] | 1153 | if (do_mkcol == true) {
|
---|
| 1154 | // execute mkcol.pl (do_mkcol is set from within check_cgiargs)
|
---|
| 1155 | gsdl_mkcol (args, logout);
|
---|
| 1156 | do_mkcol = false; // reset for fast-cgi
|
---|
| 1157 | }
|
---|
[1425] | 1158 |
|
---|
[1457] | 1159 | if (args["bc1dodelete"] == "1") {
|
---|
| 1160 | // delete bcidirname collection
|
---|
| 1161 | if (collection_protected (collection)) {
|
---|
| 1162 | message = "delinvalid";
|
---|
[1437] | 1163 |
|
---|
[1457] | 1164 | } else {
|
---|
[1778] | 1165 |
|
---|
| 1166 | const recptconf &rcinfo = recpt->get_configinfo ();
|
---|
| 1167 | bool emailuserevents = rcinfo.EmailUserEvents;
|
---|
| 1168 |
|
---|
| 1169 | // get collection maintainer email from collect.cfg before we
|
---|
| 1170 | // delete it
|
---|
| 1171 | text_t colmaintainer;
|
---|
| 1172 | text_t cfgfile = filename_cat(gsdlhome, "collect", collection, "etc", "collect.cfg");
|
---|
| 1173 | char *cfgfilec = cfgfile.getcstr();
|
---|
| 1174 | ifstream cfg_in (cfgfilec);
|
---|
[7430] | 1175 | delete []cfgfilec;
|
---|
[1778] | 1176 | if (cfg_in) {
|
---|
| 1177 | text_tarray cfgline;
|
---|
| 1178 | while (read_cfg_line(cfg_in, cfgline) >= 0) {
|
---|
| 1179 | if (cfgline.size () == 2 && cfgline[0] == "maintainer") {
|
---|
| 1180 | colmaintainer = cfgline[1];
|
---|
| 1181 | break;
|
---|
| 1182 | }
|
---|
| 1183 | }
|
---|
| 1184 | cfg_in.close();
|
---|
| 1185 | }
|
---|
| 1186 | if (colmaintainer.empty()) {
|
---|
| 1187 | logout << outconvert
|
---|
| 1188 | << "collectoraction::do_action WARNING: Collection being deleted ("
|
---|
| 1189 | << collection << ") has no maintainer address. EmailUserEvents "
|
---|
| 1190 | << "disabled\n";
|
---|
| 1191 | emailuserevents = false;
|
---|
| 1192 | }
|
---|
| 1193 |
|
---|
[1679] | 1194 | // first we need to free up the collection's collection server
|
---|
| 1195 | // we must do this for the local library (and I guess when using
|
---|
[15597] | 1196 | // fastcgi too) as you can't delete the database file while it's
|
---|
[1679] | 1197 | // being kept open by the collection server
|
---|
| 1198 | remove_colservr (collection, logout);
|
---|
| 1199 |
|
---|
[1817] | 1200 | text_t delete_cmd = "perl -S delcol.pl -f " + collection;
|
---|
| 1201 | int rv = gsdl_system (delete_cmd, true, logout);
|
---|
[1457] | 1202 | if (rv != 0) {
|
---|
| 1203 | // deletion failed -- permissions?
|
---|
| 1204 | message = "delpermission";
|
---|
[1432] | 1205 | } else {
|
---|
[1457] | 1206 | message = "delsuccess";
|
---|
[1432] | 1207 | }
|
---|
[1778] | 1208 |
|
---|
| 1209 | // log the event
|
---|
| 1210 | if (rcinfo.LogEvents == CollectorEvents || rcinfo.LogEvents == AllEvents) {
|
---|
| 1211 |
|
---|
| 1212 | text_t eventlog = filename_cat (gsdlhome, "etc", "events.txt");
|
---|
| 1213 | char *eventlogt = eventlog.getcstr();
|
---|
| 1214 | ofstream eventl (eventlogt, ios::app);
|
---|
[7430] | 1215 | delete []eventlogt;
|
---|
[1778] | 1216 |
|
---|
| 1217 | if (eventl) {
|
---|
| 1218 | eventl << outconvert << "[Collector Event]\n"
|
---|
| 1219 | << "Date: " << get_date (true) << "\n"
|
---|
| 1220 | << "Greenstone Username: " << args["un"] << "\n"
|
---|
| 1221 | << "Collection: " << collection << "\n"
|
---|
| 1222 | << "Collection Maintainer: " << colmaintainer << "\n"
|
---|
| 1223 | << "GSDLHOME: " << gsdlhome << "\n";
|
---|
| 1224 |
|
---|
| 1225 | if (message == "delsuccess") {
|
---|
| 1226 | eventl << outconvert
|
---|
| 1227 | << "The " << collection << " collection was successfully deleted\n\n";
|
---|
| 1228 | } else {
|
---|
| 1229 | eventl << outconvert
|
---|
| 1230 | << "Attempt to delete the " << collection << " collection failed\n\n";
|
---|
| 1231 | }
|
---|
| 1232 | eventl.close();
|
---|
| 1233 |
|
---|
| 1234 | } else {
|
---|
| 1235 | logout << outconvert << "collectoraction::do_action ERROR: Couldn't open "
|
---|
| 1236 | << "event log file " << eventlog << " for appending during collection "
|
---|
| 1237 | << "deletion. LogEvents disabled\n";
|
---|
| 1238 | }
|
---|
| 1239 | }
|
---|
| 1240 |
|
---|
| 1241 | if (rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents || emailuserevents) {
|
---|
| 1242 | // use sendmail.pl perl script to send email events
|
---|
| 1243 | text_t tmpmailfile = filename_cat (gsdlhome, "tmp", args["bc1tmp"], "event.txt");
|
---|
| 1244 | char *tmpmailfilec = tmpmailfile.getcstr();
|
---|
| 1245 | ofstream tmpfile (tmpmailfilec);
|
---|
[7430] | 1246 | delete []tmpmailfilec;
|
---|
[1778] | 1247 | if (tmpfile) {
|
---|
| 1248 | tmpfile << outconvert << "[Collector Event]\n"
|
---|
| 1249 | << "Date: " << get_date (true) << "\n"
|
---|
| 1250 | << "Greenstone Username: " << args["un"] << "\n"
|
---|
| 1251 | << "Collection: " << collection << "\n"
|
---|
| 1252 | << "Collection Maintainer: " << colmaintainer << "\n"
|
---|
| 1253 | << "GSDLHOME: " << gsdlhome << "\n";
|
---|
| 1254 | if (message == "delsuccess") {
|
---|
| 1255 | tmpfile << outconvert
|
---|
| 1256 | << "The " << collection << " collection was successfully deleted\n\n";
|
---|
| 1257 | } else {
|
---|
| 1258 | tmpfile << outconvert
|
---|
| 1259 | << "Attempt to delete the " << collection << " collection failed\n\n";
|
---|
| 1260 | }
|
---|
| 1261 | tmpfile.close();
|
---|
| 1262 | text_t to;
|
---|
| 1263 | if (rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents) to += rcinfo.maintainer;
|
---|
| 1264 | if (emailuserevents) {
|
---|
| 1265 | if (!to.empty()) to.push_back (',');
|
---|
| 1266 | to += colmaintainer;
|
---|
| 1267 | }
|
---|
[1817] | 1268 | text_t sendmail_cmd = "perl -S sendmail.pl -to \"" + to + "\" -from \"" + rcinfo.maintainer;
|
---|
| 1269 | sendmail_cmd += "\" -smtp \"" + rcinfo.MailServer + "\" -subject \"Greenstone Collector Event\"";
|
---|
| 1270 | sendmail_cmd += " -msgfile \"" + tmpmailfile + "\"";
|
---|
| 1271 |
|
---|
| 1272 | gsdl_system (sendmail_cmd, false, logout);
|
---|
[1778] | 1273 |
|
---|
| 1274 | } else {
|
---|
| 1275 | logout << outconvert << "collectoraction::do_action ERROR: Couldn't open "
|
---|
| 1276 | << "temporary event log file " << tmpmailfile << " during collection "
|
---|
| 1277 | << "deletion. EmailEvents and EmailUserEvents disabled\n";
|
---|
| 1278 | }
|
---|
| 1279 | }
|
---|
[1432] | 1280 | }
|
---|
[1457] | 1281 | }
|
---|
| 1282 |
|
---|
[1507] | 1283 | if (collector_page == "bildcancel" || collector_page == "bildfail") {
|
---|
| 1284 | // cancel the build (we'll also use the cancel_build script to tidy
|
---|
| 1285 | // up if the build failed)
|
---|
[1457] | 1286 | gsdl_cancel_build (args, logout);
|
---|
| 1287 | }
|
---|
| 1288 |
|
---|
[2112] | 1289 | if (collector_page == "expt") {
|
---|
| 1290 |
|
---|
| 1291 | // export the collection - we'll do a synchronous system call to
|
---|
| 1292 | // exportcol.pl as that's the easiest way to do it. if it becomes a
|
---|
| 1293 | // problem that it's taking too long to export a large collection then
|
---|
| 1294 | // we may have to revisit this.
|
---|
| 1295 | text_t tmpfile = filename_cat (gsdlhome, "tmp", collection + "_export.txt");
|
---|
[2439] | 1296 | text_t export_cmd = "perl -S exportcol.pl -out \"" + tmpfile + "\" " + collection;
|
---|
[2112] | 1297 | gsdl_system (export_cmd, true, logout);
|
---|
| 1298 | if (file_exists (tmpfile)) {
|
---|
| 1299 | text_t returnline = file_tail (tmpfile, 1, 0);
|
---|
| 1300 | if (returnline.size() > 23 && (substr(returnline.begin(), returnline.begin()+23) == "exportcol.pl succeeded:")) {
|
---|
| 1301 | // success
|
---|
| 1302 | message = "exptsuccess";
|
---|
| 1303 | } else {
|
---|
| 1304 | message = "exptfail";
|
---|
| 1305 | }
|
---|
| 1306 | } else {
|
---|
| 1307 | message = "exptfail";
|
---|
| 1308 | }
|
---|
| 1309 | }
|
---|
| 1310 |
|
---|
[1457] | 1311 | if (message.empty()) {
|
---|
| 1312 | if (collector_page != "bild") {
|
---|
| 1313 | // output page ("bild" page was already output above)
|
---|
[1437] | 1314 | textout << outconvert << disp << ("_collector:header_\n")
|
---|
| 1315 | << ("_collector:" + collector_page + "content_\n")
|
---|
| 1316 | << ("_collector:footer_\n");
|
---|
| 1317 | }
|
---|
[1457] | 1318 | } else {
|
---|
| 1319 | // message was set somewhere (probably an error), output message page
|
---|
| 1320 | textout << outconvert << disp << ("_collector:header_\n")
|
---|
| 1321 | << ("_collector:" + message + "content_\n")
|
---|
| 1322 | << ("_collector:footer_\n");
|
---|
| 1323 | message.clear();
|
---|
[1432] | 1324 | }
|
---|
[1419] | 1325 | return true;
|
---|
| 1326 | }
|
---|
| 1327 |
|
---|
[1457] | 1328 | void collectoraction::gsdl_mkcol (cgiargsclass &args, ostream &logout) {
|
---|
| 1329 |
|
---|
| 1330 | text_t tmpdir = filename_cat (gsdlhome, "tmp", args["bc1tmp"]);
|
---|
| 1331 | if (!directory_exists (tmpdir)) {
|
---|
| 1332 | message = "tmpfail";
|
---|
[11998] | 1333 | cerr << "WE CANNOT CREATE THE DIRECTORY!!! " << endl;
|
---|
[1457] | 1334 | return;
|
---|
| 1335 | }
|
---|
| 1336 |
|
---|
| 1337 | text_t &collection = args["bc1dirname"];
|
---|
| 1338 | if (collection.empty()) {
|
---|
| 1339 | message = "nocollection";
|
---|
| 1340 | return;
|
---|
| 1341 | }
|
---|
| 1342 |
|
---|
| 1343 | // check for a .create file - if it exists then we've already created the collection
|
---|
| 1344 | text_t createfile = filename_cat (tmpdir, ".create");
|
---|
| 1345 | if (file_exists (createfile)) {
|
---|
| 1346 | return;
|
---|
| 1347 | }
|
---|
| 1348 |
|
---|
| 1349 | // set up options
|
---|
[2431] | 1350 | text_t options = "-quiet -creator \"" + args["bc1contactemail"] + "\"";
|
---|
[1457] | 1351 | options += " -title \"" + args["bc1fullname"] + "\"";
|
---|
[2370] | 1352 | options += " -about \"" + carriage_replace (args["bc1aboutdesc"] + "_collectorextra_", 0) + "\"";
|
---|
[2627] | 1353 | options += " -collectdir \"" + remove_trailing_slashes(tmpdir) + "\" ";
|
---|
[2558] | 1354 |
|
---|
[1457] | 1355 | text_t optionfile = filename_cat (tmpdir, "mkcol.opt");
|
---|
[1649] | 1356 | char *optionfilec = optionfile.getcstr();
|
---|
[1819] | 1357 | ofstream ofile_out (optionfilec);
|
---|
[7430] | 1358 | delete []optionfilec;
|
---|
[1457] | 1359 | if (!ofile_out) {
|
---|
| 1360 | message = "tmpfail";
|
---|
| 1361 | return;
|
---|
| 1362 | }
|
---|
| 1363 | outconvertclass text_t2ascii;
|
---|
| 1364 | ofile_out << text_t2ascii << options << "\n";
|
---|
| 1365 | ofile_out.close();
|
---|
[1679] | 1366 |
|
---|
[1817] | 1367 | // run mkcol.pl
|
---|
| 1368 | text_t mkcol_cmd = "perl -S mkcol.pl -optionfile \"" + optionfile;
|
---|
| 1369 | mkcol_cmd += "\" " + collection;
|
---|
[11998] | 1370 |
|
---|
| 1371 |
|
---|
[1817] | 1372 | gsdl_system (mkcol_cmd, true, logout);
|
---|
[1679] | 1373 |
|
---|
[1457] | 1374 | // make sure it went ok
|
---|
| 1375 | text_t cfgfile = filename_cat (tmpdir, collection, "etc", "collect.cfg");
|
---|
| 1376 | if (!file_writable (cfgfile)) {
|
---|
| 1377 | message = "mkcolfail";
|
---|
[1679] | 1378 | } else {
|
---|
| 1379 | // create the .create file (this file is just a place holder to let any future
|
---|
| 1380 | // pages know that the collection already exists).
|
---|
| 1381 | char *createfilec = createfile.getcstr();
|
---|
| 1382 | ofstream cfile_out (createfilec);
|
---|
[7430] | 1383 | delete []createfilec;
|
---|
[1679] | 1384 | if (cfile_out) {
|
---|
| 1385 | cfile_out << "collection created\n";
|
---|
| 1386 | cfile_out.close();
|
---|
| 1387 | } else {
|
---|
| 1388 | message = "tmpfail";
|
---|
| 1389 | return;
|
---|
| 1390 | }
|
---|
[1457] | 1391 | }
|
---|
| 1392 | }
|
---|
| 1393 |
|
---|
| 1394 |
|
---|
[2401] | 1395 | bool collectoraction::check_sources (cgiargsclass &args, ostream &logout) {
|
---|
| 1396 |
|
---|
| 1397 | bool found = false;
|
---|
| 1398 |
|
---|
[2407] | 1399 | text_tarray inputvalues;
|
---|
| 1400 | splitchar (args["bc1input"].begin(), args["bc1input"].end(), ',', inputvalues);
|
---|
[2401] | 1401 |
|
---|
[2407] | 1402 | text_tarray inputtypes;
|
---|
| 1403 | splitchar (args["bc1inputtype"].begin(), args["bc1inputtype"].end(), ',', inputtypes);
|
---|
[2401] | 1404 |
|
---|
[2407] | 1405 | int numvalues = inputvalues.size();
|
---|
| 1406 | int numtypes = inputtypes.size();
|
---|
| 1407 |
|
---|
[9620] | 1408 | for (int i = 0; i < numvalues; ++i) {
|
---|
[2426] | 1409 | text_t value = format_url(decode_commas(inputvalues[i]));
|
---|
[2407] | 1410 | text_t type = "file://"; // default
|
---|
| 1411 | if (!value.empty()) {
|
---|
| 1412 | found = true;
|
---|
| 1413 | if (i >= numtypes || inputtypes[i].empty()) {
|
---|
| 1414 | logout << "collectoraction::check_sources: WARNING type not set\n";
|
---|
| 1415 | } else {
|
---|
| 1416 | type = inputtypes[i];
|
---|
| 1417 | }
|
---|
| 1418 | if (type == "file://") {
|
---|
| 1419 | if (!file_exists(value) && !directory_exists(value)) {
|
---|
[2426] | 1420 | failedsources[decode_commas(inputvalues[i])] = "1";
|
---|
[2407] | 1421 | badsources = true;
|
---|
| 1422 | }
|
---|
| 1423 | } else if (type == "http://") {
|
---|
| 1424 | if (gsdl_system ("perl -S ping.pl -quiet http://" + value, true, logout)) {
|
---|
[2426] | 1425 | failedsources[decode_commas(inputvalues[i])] = "1";
|
---|
[2407] | 1426 | badsources = true;
|
---|
| 1427 | }
|
---|
| 1428 | } else if (type == "ftp://") {
|
---|
| 1429 | if (gsdl_system ("perl -S ping.pl -quiet ftp://" + value, true, logout)) {
|
---|
[2426] | 1430 | failedsources[decode_commas(inputvalues[i])] = "1";
|
---|
[2407] | 1431 | badsources = true;
|
---|
| 1432 | }
|
---|
| 1433 | }
|
---|
[2401] | 1434 | }
|
---|
| 1435 | }
|
---|
| 1436 |
|
---|
| 1437 | // set badsources if there weren't any sources at all
|
---|
| 1438 | if (!found) badsources = true;
|
---|
| 1439 |
|
---|
| 1440 | if (badsources) return false;
|
---|
| 1441 | return true;
|
---|
| 1442 | }
|
---|
| 1443 |
|
---|
[11998] | 1444 | text_t collectoraction::get_button(cgiargsclass &args, const text_t &thispage,
|
---|
| 1445 | const text_t &color,
|
---|
| 1446 | const text_t &type, bool enabled)
|
---|
| 1447 | {
|
---|
[2401] | 1448 |
|
---|
[11998] | 1449 | if ((color != "green" && color != "grey" && color != "yellow") ||
|
---|
| 1450 | (type != "info" && type != "srce" && type != "conf" && type != "bild" && type != "view"))
|
---|
| 1451 | return g_EmptyText;
|
---|
[2558] | 1452 |
|
---|
[11998] | 1453 | text_t href = "_http"+type+"_";
|
---|
| 1454 | text_t target = "";
|
---|
[2627] | 1455 |
|
---|
[11998] | 1456 | if (thispage == "info" || thispage == "srce" || thispage == "conf" ||
|
---|
| 1457 | thispage == "bildcancel" || thispage == "bildfail") {
|
---|
| 1458 | // call the check submit macro instead of linking directly to the page
|
---|
| 1459 | href="\"javascript:check_submit('"+type+"');\"";
|
---|
| 1460 | } else if (type == "view") {
|
---|
| 1461 | // view button is special case as it needs a target=_top
|
---|
| 1462 | target = " target=_top";
|
---|
[2558] | 1463 | }
|
---|
[11998] | 1464 |
|
---|
| 1465 | text_t tdclass = "wizardbar"+color;
|
---|
| 1466 | if (enabled) {
|
---|
| 1467 | // link to the appropriate page
|
---|
| 1468 | return "<td class="+tdclass+"><a href="+href+target+">_text"+type+"_</a></td>";
|
---|
| 1469 | }
|
---|
| 1470 | else {
|
---|
| 1471 | // just display the text
|
---|
| 1472 | return "<td class="+tdclass+">_text"+type+"_</td>";
|
---|
| 1473 | }
|
---|
[2558] | 1474 | }
|
---|
[7371] | 1475 |
|
---|
| 1476 | #endif //GSDL_USE_COLLECTOR_ACTION
|
---|