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 |
|
---|
26 | // note that the collectoraction relies on having direct access to a
|
---|
27 | // collections configuration file. this breaks the separation between
|
---|
28 | // receptionist and collection server and so is not suitable (at least
|
---|
29 | // in its current form) for use when collection servers are separate
|
---|
30 | // from the receptionist (e.g. when using the CORBA protocol).
|
---|
31 |
|
---|
32 | #include "collectoraction.h"
|
---|
33 | #include "OIDtools.h"
|
---|
34 | #include "fileutil.h"
|
---|
35 | #include "cfgread.h"
|
---|
36 |
|
---|
37 | #if !defined (__WIN32__)
|
---|
38 | #include <sys/utsname.h>
|
---|
39 | #include <unistd.h>
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | collectoraction::collectoraction () {
|
---|
43 |
|
---|
44 | recpt = NULL;
|
---|
45 | do_mkcol = false;
|
---|
46 |
|
---|
47 | cgiarginfo arg_ainfo;
|
---|
48 | arg_ainfo.shortname = "a";
|
---|
49 | arg_ainfo.longname = "action";
|
---|
50 | arg_ainfo.multiplechar = true;
|
---|
51 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
52 | arg_ainfo.argdefault = "collector";
|
---|
53 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
54 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
55 |
|
---|
56 | arg_ainfo.shortname = "cp";
|
---|
57 | arg_ainfo.longname = "collector page";
|
---|
58 | arg_ainfo.multiplechar = true;
|
---|
59 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
60 | arg_ainfo.argdefault = "intro";
|
---|
61 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
62 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
63 |
|
---|
64 | arg_ainfo.shortname = "bc1fullname";
|
---|
65 | arg_ainfo.longname = "collector specific";
|
---|
66 | arg_ainfo.multiplechar = true;
|
---|
67 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
68 | arg_ainfo.argdefault = "";
|
---|
69 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
70 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
71 |
|
---|
72 | arg_ainfo.shortname = "bc1dirname";
|
---|
73 | arg_ainfo.longname = "collector specific";
|
---|
74 | arg_ainfo.multiplechar = true;
|
---|
75 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
76 | arg_ainfo.argdefault = "";
|
---|
77 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
78 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
79 |
|
---|
80 | arg_ainfo.shortname = "bc1contactemail";
|
---|
81 | arg_ainfo.longname = "collector specific";
|
---|
82 | arg_ainfo.multiplechar = true;
|
---|
83 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
84 | arg_ainfo.argdefault = "";
|
---|
85 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
86 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
87 |
|
---|
88 | arg_ainfo.shortname = "bc1aboutdesc";
|
---|
89 | arg_ainfo.longname = "collector specific";
|
---|
90 | arg_ainfo.multiplechar = true;
|
---|
91 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
92 | arg_ainfo.argdefault = "";
|
---|
93 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
94 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
95 |
|
---|
96 | arg_ainfo.shortname = "bc1clone";
|
---|
97 | arg_ainfo.longname = "collector specific";
|
---|
98 | arg_ainfo.multiplechar = false;
|
---|
99 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
100 | arg_ainfo.argdefault = "0";
|
---|
101 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
102 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
103 |
|
---|
104 | arg_ainfo.shortname = "bc1clonecol";
|
---|
105 | arg_ainfo.longname = "collector specific";
|
---|
106 | arg_ainfo.multiplechar = true;
|
---|
107 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
108 | arg_ainfo.argdefault = "";
|
---|
109 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
110 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
111 |
|
---|
112 | arg_ainfo.shortname = "bc1inputdir1";
|
---|
113 | arg_ainfo.longname = "collector specific";
|
---|
114 | arg_ainfo.multiplechar = true;
|
---|
115 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
116 | arg_ainfo.argdefault = "";
|
---|
117 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
118 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
119 |
|
---|
120 | arg_ainfo.shortname = "bc1inputdir2";
|
---|
121 | arg_ainfo.longname = "collector specific";
|
---|
122 | arg_ainfo.multiplechar = true;
|
---|
123 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
124 | arg_ainfo.argdefault = "";
|
---|
125 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
126 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
127 |
|
---|
128 | arg_ainfo.shortname = "bc1inputdir3";
|
---|
129 | arg_ainfo.longname = "collector specific";
|
---|
130 | arg_ainfo.multiplechar = true;
|
---|
131 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
132 | arg_ainfo.argdefault = "";
|
---|
133 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
134 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
135 |
|
---|
136 | arg_ainfo.shortname = "bc1inputdir4";
|
---|
137 | arg_ainfo.longname = "collector specific";
|
---|
138 | arg_ainfo.multiplechar = true;
|
---|
139 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
140 | arg_ainfo.argdefault = "";
|
---|
141 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
142 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
143 |
|
---|
144 | // only set when one of the fields was changed in
|
---|
145 | // the "collection info" page
|
---|
146 | arg_ainfo.shortname = "bc1infochanged";
|
---|
147 | arg_ainfo.longname = "collector specific";
|
---|
148 | arg_ainfo.multiplechar = false;
|
---|
149 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
150 | arg_ainfo.argdefault = "0";
|
---|
151 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
152 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
153 |
|
---|
154 | // only set when cfg file is altered from within
|
---|
155 | // "configure collection" page
|
---|
156 | arg_ainfo.shortname = "bc1cfgchanged";
|
---|
157 | arg_ainfo.longname = "collector specific";
|
---|
158 | arg_ainfo.multiplechar = false;
|
---|
159 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
160 | arg_ainfo.argdefault = "0";
|
---|
161 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
162 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
163 | }
|
---|
164 |
|
---|
165 | collectoraction::~collectoraction () {
|
---|
166 | delete gsdlosc;
|
---|
167 | delete gsdlhomec;
|
---|
168 | }
|
---|
169 |
|
---|
170 | bool collectoraction::init (ostream & /*logout*/) {
|
---|
171 |
|
---|
172 | // set up GSDLOS and GSDLHOME environment variables
|
---|
173 | text_t gsdlos;
|
---|
174 | #if defined (__WIN32__)
|
---|
175 | gsdlos = "windows";
|
---|
176 | #else
|
---|
177 | utsname *buf = new utsname();
|
---|
178 | int i = uname (buf);
|
---|
179 | if (i == -1) gsdlos = "linux"; // uname failed
|
---|
180 | else gsdlos.setcstr (buf->sysname);
|
---|
181 | delete buf;
|
---|
182 | lc (gsdlos);
|
---|
183 | #endif
|
---|
184 |
|
---|
185 | gsdlos = "GSDLOS=" + gsdlos;
|
---|
186 | text_t setgsdlhome = "GSDLHOME=" + gsdlhome;
|
---|
187 |
|
---|
188 | // these will be cleaned up in the destructor
|
---|
189 | gsdlosc = gsdlos.getcstr();
|
---|
190 | gsdlhomec = setgsdlhome.getcstr();
|
---|
191 |
|
---|
192 | putenv (gsdlosc);
|
---|
193 | putenv (gsdlhomec);
|
---|
194 |
|
---|
195 | return true;
|
---|
196 | }
|
---|
197 |
|
---|
198 | bool collectoraction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &args,
|
---|
199 | ostream &logout) {
|
---|
200 |
|
---|
201 | if (args["cp"] != "intro") {
|
---|
202 | // authenticate the user if authentication is avaiable
|
---|
203 | args["uan"] = 1;
|
---|
204 | args["ug"] = "colbuilder";
|
---|
205 | }
|
---|
206 |
|
---|
207 | if (args["bc1infochanged"] == "1") {
|
---|
208 |
|
---|
209 | if (args["bc1dirname"].empty()) {
|
---|
210 | // we've just come from the "collection information" page for the
|
---|
211 | // first time so we'll need to create the collection with mkcol.pl
|
---|
212 | // and set up bc1dirname - we do this part here instead of in do_action
|
---|
213 | // because the bc1dirname argument must be set to its new value before
|
---|
214 | // the compressedoptions macros are set.
|
---|
215 | args["bc1dirname"] = get_directory_name (args["bc1fullname"]);
|
---|
216 | do_mkcol = true;
|
---|
217 |
|
---|
218 | } else {
|
---|
219 | // "collection information" has been changed after collection was made
|
---|
220 | // so we'll need to update the cfg file.
|
---|
221 | update_cfgfile_partial (args, logout);
|
---|
222 | }
|
---|
223 | }
|
---|
224 |
|
---|
225 | if (args["bc1cfgchanged"] == "1") {
|
---|
226 | // configuration file has been changed from the "configure collection"
|
---|
227 | // page. we need to update the file on disk and catch bc1 arguments up
|
---|
228 | // with changes.
|
---|
229 | update_cfgfile_complete (args, logout);
|
---|
230 | }
|
---|
231 |
|
---|
232 | return true;
|
---|
233 | }
|
---|
234 |
|
---|
235 | // update configuration file on disk to match bc1 arguments
|
---|
236 | void collectoraction::update_cfgfile_partial (cgiargsclass &args, ostream &logout) {
|
---|
237 |
|
---|
238 | text_t cfgfile = filename_cat(gsdlhome, "collect", args["bc1dirname"], "etc", "collect.cfg");
|
---|
239 | char *cfgfilec = cfgfile.getcstr();
|
---|
240 |
|
---|
241 | vector<text_tarray> cfgarray;
|
---|
242 |
|
---|
243 | // read in cfg file
|
---|
244 | ifstream cfg_in (cfgfilec);
|
---|
245 | if (cfg_in) {
|
---|
246 | text_tarray cfgline;
|
---|
247 | while (read_cfg_line(cfg_in, cfgline) >= 0) {
|
---|
248 | if (cfgline.size () >= 2) {
|
---|
249 | if (cfgline[0] == "creator") {
|
---|
250 | cfgline[1] = args["bc1contactemail"];
|
---|
251 | } else if (cfgline[0] == "collectionmeta") {
|
---|
252 | if (cfgline[1] == "collectionname") {
|
---|
253 | cfgline[2] = args["bc1fullname"];
|
---|
254 | } else if (cfgline[1] == "collectionextra") {
|
---|
255 | cfgline[2] = carriage_replace (args["bc1aboutdesc"], 0);
|
---|
256 | }
|
---|
257 | }
|
---|
258 | }
|
---|
259 | cfgarray.push_back (cfgline);
|
---|
260 | }
|
---|
261 | cfg_in.close();
|
---|
262 |
|
---|
263 | // now write cfg file back out
|
---|
264 | ofstream cfg_out (cfgfilec);
|
---|
265 | if (cfg_out) {
|
---|
266 | // lock the file
|
---|
267 | int fd = GSDL_GET_FILEDESC(cfg_out);
|
---|
268 | int lock_val = 1;
|
---|
269 | GSDL_LOCK_FILE (fd);
|
---|
270 | if (lock_val != 0) {
|
---|
271 | logout << "Error: Couldn't lock file " << cfgfilec << "\n";
|
---|
272 | cfg_out.close();
|
---|
273 |
|
---|
274 | } else {
|
---|
275 |
|
---|
276 | vector<text_tarray>::const_iterator this_line = cfgarray.begin();
|
---|
277 | vector<text_tarray>::const_iterator end_line = cfgarray.end();
|
---|
278 | while (this_line != end_line) {
|
---|
279 | write_cfg_line (cfg_out, *this_line);
|
---|
280 | this_line ++;
|
---|
281 | }
|
---|
282 | GSDL_UNLOCK_FILE (fd);
|
---|
283 | cfg_out.close();
|
---|
284 | }
|
---|
285 |
|
---|
286 | } else {
|
---|
287 | logout << "collectoraction::update_cfgfile_partial: unable to open "
|
---|
288 | << cfgfilec << " for output\n";
|
---|
289 | }
|
---|
290 |
|
---|
291 | } else {
|
---|
292 | logout << "collectoraction::update_cfgfile_partial: unable to open "
|
---|
293 | << cfgfilec << " for input\n";
|
---|
294 | }
|
---|
295 | delete cfgfilec;
|
---|
296 | }
|
---|
297 |
|
---|
298 | // replace configuration file on disk with that in the bc1cfgfile argument and
|
---|
299 | // catch other bc1 arguments up with those the new cfgfile contains
|
---|
300 | void collectoraction::update_cfgfile_complete (cgiargsclass &args, ostream &logout) {
|
---|
301 |
|
---|
302 | text_t cfgfile = filename_cat(gsdlhome, "collect", args["bc1dirname"], "etc", "collect.cfg");
|
---|
303 | char *cfgfilec = cfgfile.getcstr();
|
---|
304 | ofstream cfg_out (cfgfilec);
|
---|
305 |
|
---|
306 | if (cfg_out) {
|
---|
307 | // lock the file
|
---|
308 | int fd = GSDL_GET_FILEDESC(cfg_out);
|
---|
309 | int lock_val = 1;
|
---|
310 | GSDL_LOCK_FILE (fd);
|
---|
311 | if (lock_val != 0) {
|
---|
312 | logout << "Error: Couldn't lock file " << cfgfilec << "\n";
|
---|
313 | cfg_out.close();
|
---|
314 |
|
---|
315 | } else {
|
---|
316 |
|
---|
317 | outconvertclass text_t2ascii;
|
---|
318 | cfg_out << text_t2ascii << args["bc1cfgfile"];
|
---|
319 | GSDL_UNLOCK_FILE (fd);
|
---|
320 | cfg_out.close();
|
---|
321 |
|
---|
322 | // now that we've written the file we'll read it back again and
|
---|
323 | // update our bc1 arguments
|
---|
324 | ifstream cfg_in (cfgfilec);
|
---|
325 | if (cfg_in) {
|
---|
326 | text_tarray cfgline;
|
---|
327 | while (read_cfg_line(cfg_in, cfgline) >= 0) {
|
---|
328 | if (cfgline.size () >= 2) {
|
---|
329 | if (cfgline[0] == "creator") {
|
---|
330 | args["bc1contactemail"] = cfgline[1];
|
---|
331 | } else if (cfgline[0] == "collectionmeta") {
|
---|
332 | if (cfgline[1] == "collectionname") {
|
---|
333 | args["bc1fullname"] = cfgline[2];
|
---|
334 | } else if (cfgline[1] == "collectionextra") {
|
---|
335 | args["bc1aboutdesc"] = carriage_replace (cfgline[2], 1);
|
---|
336 | }
|
---|
337 | }
|
---|
338 | }
|
---|
339 | }
|
---|
340 | cfg_in.close();
|
---|
341 | } else {
|
---|
342 | logout << "collectoraction::update_cfgfile_complete: unable to open "
|
---|
343 | << cfgfilec << " for input\n";
|
---|
344 | }
|
---|
345 | }
|
---|
346 | } else {
|
---|
347 | logout << "collectoraction::update_cfgfile_complete: unable to open "
|
---|
348 | << cfgfilec << " for output\n";
|
---|
349 | }
|
---|
350 | delete cfgfilec;
|
---|
351 | }
|
---|
352 |
|
---|
353 | void collectoraction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
|
---|
354 | response_t &response,text_t &response_data,
|
---|
355 | ostream &/*logout*/) {
|
---|
356 | response = content;
|
---|
357 | response_data = "text/html";
|
---|
358 | }
|
---|
359 |
|
---|
360 | // return html for buttons used in collector bar
|
---|
361 | // color may be "green", "grey", or "yellow"
|
---|
362 | // type may be:
|
---|
363 | // "info" --> "collection information" button
|
---|
364 | // "srce" --> "source data" button
|
---|
365 | // "conf" --> "configure collection" button
|
---|
366 | // "bild" --> "build collection" button
|
---|
367 | // "view" --> "view collection" button
|
---|
368 | // if enabled is true button will be flashy rollover type and
|
---|
369 | // will be hyperlinked
|
---|
370 |
|
---|
371 | text_t collectoraction::get_button (const text_t &thispage, const text_t &color,
|
---|
372 | const text_t &type, bool enabled) {
|
---|
373 |
|
---|
374 | if ((color != "green" && color != "grey" && color != "yellow") ||
|
---|
375 | (type != "info" && type != "srce" && type != "conf" && type != "bild" && type != "view"))
|
---|
376 | return "";
|
---|
377 |
|
---|
378 | text_t prefix = "gc";
|
---|
379 | if (color == "grey") prefix = "nc";
|
---|
380 | else if (color == "yellow") prefix = "yc";
|
---|
381 |
|
---|
382 | text_t httpicon = "httpicon" + prefix + type;
|
---|
383 |
|
---|
384 | if (enabled) {
|
---|
385 | text_t gsmacro = "_gsimage_";
|
---|
386 | if (thispage == "info" || thispage == "srce" || thispage == "conf") {
|
---|
387 | gsmacro = "_gsjimage_";
|
---|
388 | }
|
---|
389 | return "<td>" + gsmacro + "(_collector:http" + type + "_,_collector:" + httpicon +
|
---|
390 | "of_,_collector:" + httpicon + "on_," + type + ",_collector:text" + type + "_)</td>\n";
|
---|
391 | } else {
|
---|
392 | return "<td>_icon" + prefix + type + "of_</td>\n";
|
---|
393 | }
|
---|
394 | }
|
---|
395 |
|
---|
396 | // set the _fullnamemenu_ macro
|
---|
397 | void collectoraction::set_fullnamemenu (displayclass &disp, cgiargsclass &args,
|
---|
398 | recptprotolistclass *protos, ostream &logout) {
|
---|
399 |
|
---|
400 | if (recpt == NULL) {
|
---|
401 | logout << "ERROR (collectoraction::set_fullnamemenu): This action does not contain\n"
|
---|
402 | << " information about any receptionists. The method set_receptionist was\n"
|
---|
403 | << " probably not called from the module which instantiated this action.\n";
|
---|
404 | return;
|
---|
405 | }
|
---|
406 |
|
---|
407 | text_t ¤tname = args["bc1clonecol"];
|
---|
408 | text_t fullnamemenu;
|
---|
409 | bool first = true;
|
---|
410 |
|
---|
411 | recptprotolistclass::iterator rprotolist_here = protos->begin();
|
---|
412 | recptprotolistclass::iterator rprotolist_end = protos->end();
|
---|
413 | while (rprotolist_here != rprotolist_end) {
|
---|
414 | if ((*rprotolist_here).p != NULL) {
|
---|
415 | text_tarray collist;
|
---|
416 | comerror_t err;
|
---|
417 | (*rprotolist_here).p->get_collection_list (collist, err, logout);
|
---|
418 | if (err == noError) {
|
---|
419 | text_tarray::iterator collist_here = collist.begin();
|
---|
420 | text_tarray::iterator collist_end = collist.end();
|
---|
421 | FilterResponse_t response;
|
---|
422 | text_tset metadata;
|
---|
423 | metadata.insert ("collectionname");
|
---|
424 |
|
---|
425 | while (collist_here != collist_end) {
|
---|
426 |
|
---|
427 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
|
---|
428 | if (cinfo != NULL) {
|
---|
429 | text_t collectionname = *collist_here;
|
---|
430 | if (!cinfo->collectionmeta["collectionname"].empty()) {
|
---|
431 | // get collection name from the collection cfg file
|
---|
432 | collectionname = cinfo->collectionmeta["collectionname"];
|
---|
433 |
|
---|
434 | } else if (get_info ("collection", *collist_here, metadata, false,
|
---|
435 | (*rprotolist_here).p, response, logout)) {
|
---|
436 | // get collection name from gdbm file
|
---|
437 | collectionname = response.docInfo[0].metadata["collectionname"].values[0];
|
---|
438 | }
|
---|
439 |
|
---|
440 | if (first) fullnamemenu = "<select name=\"bc1clonecol\">\n";
|
---|
441 | fullnamemenu += "<option value=\"" + *collist_here;
|
---|
442 | fullnamemenu.push_back ('"');
|
---|
443 | if (*collist_here == currentname) fullnamemenu += " selected";
|
---|
444 | fullnamemenu.push_back ('>');
|
---|
445 | fullnamemenu += collectionname;
|
---|
446 |
|
---|
447 | // check to see if the "collection" is writable
|
---|
448 | text_t cfg_fname = filename_cat(gsdlhome, "collect", *collist_here, "etc", "collect.cfg");
|
---|
449 | if (!file_writable(cfg_fname)) fullnamemenu += " <b>(write protected)</b>";
|
---|
450 |
|
---|
451 | fullnamemenu += "\n";
|
---|
452 |
|
---|
453 | first = false;
|
---|
454 | }
|
---|
455 | collist_here ++;
|
---|
456 | }
|
---|
457 | }
|
---|
458 | }
|
---|
459 | rprotolist_here ++;
|
---|
460 | }
|
---|
461 | if (!first) {
|
---|
462 | fullnamemenu += "</select>\n";
|
---|
463 | disp.setmacro ("fullnamemenu", "collector", fullnamemenu);
|
---|
464 | }
|
---|
465 | }
|
---|
466 |
|
---|
467 | // set the _cfgfile_ macro
|
---|
468 | void collectoraction::set_cfgfile (displayclass &disp, const text_t &dirname, ostream &logout) {
|
---|
469 |
|
---|
470 | // read in collect.cfg
|
---|
471 | text_t cfgfile = filename_cat(gsdlhome, "collect", dirname, "etc", "collect.cfg");
|
---|
472 | char *cfgfilec = cfgfile.getcstr();
|
---|
473 |
|
---|
474 | #ifdef GSDL_USE_IOS_H
|
---|
475 | ifstream cfg_ifs (cfgfilec, ios::in | ios::nocreate);
|
---|
476 | #else
|
---|
477 | ifstream cfg_ifs (cfgfilec, ios::in);
|
---|
478 | #endif
|
---|
479 |
|
---|
480 | if (cfg_ifs) {
|
---|
481 | // read in collect.cfg
|
---|
482 | text_t cfgtext;
|
---|
483 | char c;
|
---|
484 | cfg_ifs.get(c);
|
---|
485 | while (!cfg_ifs.eof ()) {
|
---|
486 | if (c=='\\') cfgtext.push_back('\\');
|
---|
487 | cfgtext.push_back(c);
|
---|
488 | cfg_ifs.get(c);
|
---|
489 | }
|
---|
490 | cfg_ifs.close();
|
---|
491 |
|
---|
492 | // define it as a macro
|
---|
493 | disp.setmacro("cfgfile","collector",cfgtext);
|
---|
494 |
|
---|
495 | } else {
|
---|
496 | logout << "collectoraction::set_cfgfile: couldn't open configuration file ("
|
---|
497 | << cfgfilec << ") for reading\n";
|
---|
498 | }
|
---|
499 | delete cfgfilec;
|
---|
500 | }
|
---|
501 |
|
---|
502 | void collectoraction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
503 | recptprotolistclass *protos, ostream &logout) {
|
---|
504 |
|
---|
505 | // define_internal_macros sets the following macros:
|
---|
506 | // _collectorbar_
|
---|
507 | // _pagescriptextra_
|
---|
508 | // _fullnamemenu_ -- if displaying the "source data" page
|
---|
509 | // _cfgfile_ -- if displaying the "configure collection" page
|
---|
510 |
|
---|
511 | text_t &collector_page = args["cp"];
|
---|
512 |
|
---|
513 | // set _pagescriptextra_ macro to _cpagescriptextra_
|
---|
514 | disp.setmacro ("pagescriptextra", "collector", "_" + collector_page + "scriptextra_");
|
---|
515 |
|
---|
516 | // set the collectorbar macro
|
---|
517 | text_t collectorbar = "<table border=0 cellspacing=4 cellpadding=0><tr>\n";
|
---|
518 |
|
---|
519 | if (collector_page == "new") {
|
---|
520 | collectorbar += get_button (collector_page, "green", "info", true);
|
---|
521 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
522 | collectorbar += get_button (collector_page, "grey", "srce", false);
|
---|
523 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
524 | collectorbar += get_button (collector_page, "grey", "conf", false);
|
---|
525 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
526 | collectorbar += get_button (collector_page, "grey", "bild", false);
|
---|
527 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
528 | collectorbar += get_button (collector_page, "grey", "view", false);
|
---|
529 |
|
---|
530 | } else if (collector_page == "info") {
|
---|
531 | collectorbar += get_button (collector_page, "yellow", "info", false);
|
---|
532 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
533 | collectorbar += get_button (collector_page, "green", "srce", true);
|
---|
534 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
535 | collectorbar += get_button (collector_page, "grey", "conf", false);
|
---|
536 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
537 | collectorbar += get_button (collector_page, "grey", "bild", false);
|
---|
538 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
539 | collectorbar += get_button (collector_page, "grey", "view", false);
|
---|
540 | collectorbar += "</tr><tr><td align=center>_icongreyuparrow_</td><td colspan=8></td>\n";
|
---|
541 |
|
---|
542 | } else if (collector_page == "srce") {
|
---|
543 | collectorbar += get_button (collector_page, "yellow", "info", true);
|
---|
544 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
545 | collectorbar += get_button (collector_page, "yellow", "srce", false);
|
---|
546 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
547 | collectorbar += get_button (collector_page, "green", "conf", true);
|
---|
548 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
549 | collectorbar += get_button (collector_page, "grey", "bild", false);
|
---|
550 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
551 | collectorbar += get_button (collector_page, "grey", "view", false);
|
---|
552 | collectorbar += "</tr><tr><td colspan=2></td><td align=center>_icongreyuparrow_</td><td colspan=6></td>\n";
|
---|
553 |
|
---|
554 | } else if (collector_page == "conf") {
|
---|
555 | collectorbar += get_button (collector_page, "yellow", "info", true);
|
---|
556 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
557 | collectorbar += get_button (collector_page, "yellow", "srce", true);
|
---|
558 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
559 | collectorbar += get_button (collector_page, "yellow", "conf", false);
|
---|
560 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
561 | collectorbar += get_button (collector_page, "green", "bild", true);
|
---|
562 | collectorbar += "<td>_icongreyarrow_</td>\n";
|
---|
563 | collectorbar += get_button (collector_page, "grey", "view", false);
|
---|
564 | collectorbar += "</tr><tr><td colspan=4></td><td align=center>_icongreyuparrow_</td><td colspan=4></td>\n";
|
---|
565 |
|
---|
566 | } else if (collector_page == "bild") {
|
---|
567 |
|
---|
568 |
|
---|
569 | }
|
---|
570 |
|
---|
571 | collectorbar += "</tr></table>\n";
|
---|
572 | disp.setmacro ("collectorbar", "collector", collectorbar);
|
---|
573 |
|
---|
574 | if (collector_page == "srce") set_fullnamemenu (disp, args, protos, logout);
|
---|
575 | if (collector_page == "conf") set_cfgfile (disp, args["bc1dirname"], logout);
|
---|
576 | }
|
---|
577 |
|
---|
578 | bool collectoraction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
|
---|
579 | browsermapclass * /*browsers*/, displayclass &disp,
|
---|
580 | outconvertclass &outconvert, ostream &textout,
|
---|
581 | ostream &/*logout*/) {
|
---|
582 |
|
---|
583 | text_t &collector_page = args["cp"];
|
---|
584 | text_t error;
|
---|
585 |
|
---|
586 | if (do_mkcol) {
|
---|
587 | // execute mkcol.pl (do_mkcol is set from within check_cgiargs)
|
---|
588 | text_t mkcol_cmd = "perl ";
|
---|
589 | mkcol_cmd += filename_cat (gsdlhome, "bin", "script", "mkcol.pl");
|
---|
590 | mkcol_cmd += " -creator \"" + args["bc1contactemail"] + "\"";
|
---|
591 | mkcol_cmd += " -title \"" + args["bc1fullname"] + "\"";
|
---|
592 | mkcol_cmd += " -about \"" + carriage_replace (args["bc1aboutdesc"], 0) + "\" ";
|
---|
593 | mkcol_cmd += args["bc1dirname"];
|
---|
594 | char *mkcol_cmdc = mkcol_cmd.getcstr();
|
---|
595 | system (mkcol_cmdc);
|
---|
596 | delete mkcol_cmdc;
|
---|
597 |
|
---|
598 | // make sure it went ok
|
---|
599 | text_t cfgfile = filename_cat (gsdlhome, "collect", args["bc1dirname"],
|
---|
600 | "etc", "collect.cfg");
|
---|
601 | if (!file_writable (cfgfile)) error = "mkcolfail";
|
---|
602 | }
|
---|
603 |
|
---|
604 | if (collector_page == "bild") {
|
---|
605 | // do the work (download, import, build)
|
---|
606 | text_t build_cmd = "perl " + filename_cat (gsdlhome, "bin", "script", "build");
|
---|
607 | if (!args["bc1inputdir1"].empty()) {
|
---|
608 | build_cmd += " -download \"" + args["bc1inputdir1"] + "\"";
|
---|
609 | }
|
---|
610 | if (!args["bc1inputdir2"].empty()) {
|
---|
611 | build_cmd += " -download \"" + args["bc1inputdir2"] + "\"";
|
---|
612 | }
|
---|
613 | if (!args["bc1inputdir3"].empty()) {
|
---|
614 | build_cmd += " -download \"" + args["bc1inputdir3"] + "\"";
|
---|
615 | }
|
---|
616 | if (!args["bc1inputdir4"].empty()) {
|
---|
617 | build_cmd += " -download \"" + args["bc1inputdir4"] + "\"";
|
---|
618 | }
|
---|
619 | build_cmd.push_back (' ');
|
---|
620 | build_cmd += args["bc1dirname"];
|
---|
621 |
|
---|
622 | #if !defined (__WIN32__)
|
---|
623 | // run in background on unix systems
|
---|
624 | build_cmd += " &";
|
---|
625 | #endif
|
---|
626 | char *build_cmdc = build_cmd.getcstr();
|
---|
627 | #if defined (__WIN32__)
|
---|
628 | gsdl_system (build_cmdc, logout);
|
---|
629 | #else
|
---|
630 | system (build_cmdc);
|
---|
631 | #endif
|
---|
632 | delete build_cmdc;
|
---|
633 | }
|
---|
634 |
|
---|
635 | if (error.empty()) {
|
---|
636 | textout << outconvert << disp << ("_collector:header_\n")
|
---|
637 | << ("_collector:" + collector_page + "content_\n")
|
---|
638 | << ("_collector:footer_\n");
|
---|
639 | } else {
|
---|
640 | textout << outconvert << disp << ("_collector:header_\n")
|
---|
641 | << ("_collector:" + error + "content_\n")
|
---|
642 | << ("_collector:footer_\n");
|
---|
643 | }
|
---|
644 |
|
---|
645 | return true;
|
---|
646 | }
|
---|
647 |
|
---|
648 | // if sw = 0 replace all carriage returns in intext with the string "\n"
|
---|
649 | // else replace all occurances of "\n" with a carriage return
|
---|
650 | text_t collectoraction::carriage_replace (const text_t &intext, int sw) {
|
---|
651 |
|
---|
652 | text_t outtext;
|
---|
653 | text_t::const_iterator here = intext.begin();
|
---|
654 | text_t::const_iterator end = intext.end();
|
---|
655 | while (here != end) {
|
---|
656 | if (sw == 0) {
|
---|
657 | if (*here == '\n') {
|
---|
658 | if ((here+1) != end && *(here+1) == '\r') here ++;
|
---|
659 | outtext += "\\n";
|
---|
660 | } else if (*here == '\r') {
|
---|
661 | if ((here+1) != end && *(here+1) == '\n') here ++;
|
---|
662 | outtext += "\\n";
|
---|
663 | } else {
|
---|
664 | outtext.push_back (*here);
|
---|
665 | }
|
---|
666 | } else if (*here == '\\' && (here+1) != end && *(here+1) == 'n') {
|
---|
667 | outtext.push_back ('\n');
|
---|
668 | here ++;
|
---|
669 | } else {
|
---|
670 | outtext.push_back (*here);
|
---|
671 | }
|
---|
672 | here ++;
|
---|
673 | }
|
---|
674 | return outtext;
|
---|
675 | }
|
---|
676 |
|
---|
677 | // create a short directory name from fullname
|
---|
678 | text_t collectoraction::get_directory_name (const text_t &fullname) {
|
---|
679 |
|
---|
680 | text_t shortname;
|
---|
681 | if (fullname.empty()) {
|
---|
682 | shortname = "coll";
|
---|
683 |
|
---|
684 | } else {
|
---|
685 |
|
---|
686 | // first make all lowercase and remove any dodgy characters
|
---|
687 | // (i.e. anything not [a-z]
|
---|
688 | text_t::const_iterator here = fullname.begin();
|
---|
689 | text_t::const_iterator end = fullname.end();
|
---|
690 | while (here != end) {
|
---|
691 | if ((*here >= 'A' && *here <= 'Z') || (*here >= 'a' && *here <= 'z') ||
|
---|
692 | (*here == ' ')) {
|
---|
693 | if (*here >= 'A' && *here <= 'Z') shortname.push_back (*here+32);
|
---|
694 | else if (*here == ' ') {
|
---|
695 | while ((*(here+1)) == ' ') here ++;
|
---|
696 | shortname.push_back (*here);
|
---|
697 | } else shortname.push_back (*here);
|
---|
698 | }
|
---|
699 | here ++;
|
---|
700 | }
|
---|
701 |
|
---|
702 | text_tarray words;
|
---|
703 | splitchar (shortname.begin(), shortname.end(), ' ', words);
|
---|
704 | int num_words = words.size();
|
---|
705 |
|
---|
706 | if (num_words == 0) {
|
---|
707 | shortname = "coll";
|
---|
708 |
|
---|
709 | } else {
|
---|
710 |
|
---|
711 | shortname.clear();
|
---|
712 | int use_words = (num_words <= 6) ? num_words : 6;
|
---|
713 | int substr_len = 6 / use_words;
|
---|
714 |
|
---|
715 | for (int i = 0; i < use_words; i++) {
|
---|
716 | if (words[i].size() < substr_len) shortname += words[i];
|
---|
717 | else shortname += substr (words[i].begin(), words[i].begin()+substr_len);
|
---|
718 | }
|
---|
719 | }
|
---|
720 | }
|
---|
721 |
|
---|
722 | // check to see if shortname is unique
|
---|
723 | text_t fulldirname = filename_cat (gsdlhome, "collect", shortname);
|
---|
724 | if (directory_exists (fulldirname)) {
|
---|
725 | int version = 0;
|
---|
726 | text_t newname;
|
---|
727 | do {
|
---|
728 | version ++;
|
---|
729 | newname = shortname;
|
---|
730 | newname.push_back ('v');
|
---|
731 | newname.appendint (version);
|
---|
732 | fulldirname = filename_cat (gsdlhome, "collect", newname);
|
---|
733 | } while (directory_exists (fulldirname));
|
---|
734 |
|
---|
735 | shortname = newname;
|
---|
736 | }
|
---|
737 |
|
---|
738 | return shortname;
|
---|
739 | }
|
---|