Changeset 1778
- Timestamp:
- 2000-12-08T17:00:35+13:00 (23 years ago)
- Location:
- trunk/gsdl
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/bin/script/build
r1762 r1778 1 #!/usr/bin/perl 1 #!/usr/bin/perl -w 2 3 ########################################################################### 4 # 5 # build -- 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 # Copyright (C) 2000 New Zealand Digital Library Project 11 # 12 # This program is free software; you can redistribute it and/or modify 13 # it under the terms of the GNU General Public License as published by 14 # the Free Software Foundation; either version 2 of the License, or 15 # (at your option) any later version. 16 # 17 # This program is distributed in the hope that it will be useful, 18 # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 # GNU General Public License for more details. 21 # 22 # You should have received a copy of the GNU General Public License 23 # along with this program; if not, write to the Free Software 24 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 # 26 ########################################################################### 2 27 3 28 # This perl script may be called directly or by running build.bat on … … 10 35 package build; 11 36 12 use lib qq($ENV{'GSDLHOME'}/perllib/cpan);13 37 use FileHandle; 14 38 use File::Copy; 15 use Mail::Sendmail;16 17 39 18 40 BEGIN { … … 28 50 } 29 51 52 use lib qq($ENV{'GSDLHOME'}/perllib/cpan); 53 use Mail::Sendmail; 30 54 use parsargv; 31 55 use util; … … 434 458 435 459 # get the event header 436 my $eheader = ""; 460 my $eheader = "[Build Event]\n"; 461 $eheader .= "Date: " . scalar localtime() . "\n"; 437 462 if ($event_header ne "" && open (HEADER, $event_header)) { 438 463 undef $/; 439 $eheader = HEADER;464 $eheader .= <HEADER>; 440 465 $/ = "\n"; 441 466 close HEADER; 442 467 } else { 443 $eheader = "[Build Event]\n";444 $eheader .= "Date: " . scalar localtime() . "\n";445 468 $eheader .= "Collection: $collection\n"; 469 $eheader .= "GSDLHOME: $ENV{'GSDLHOME'}\n"; 470 $eheader .= "Build Location: $collectdir\n"; 446 471 } 447 472 … … 460 485 print LOG $eheader; 461 486 print LOG $msg; 487 print LOG "\n"; 462 488 close LOG; 463 489 } -
trunk/gsdl/lib/gsdltimes.cpp
r1310 r1778 26 26 #include "gsdltimes.h" 27 27 28 28 // returns a string of the form "YYYY/MM/DD hh:mm:ss" (expressed in 29 // Coordinated Universal Time (UTC)) 29 30 // returns "" if an error occurs 30 31 text_t time2text (time_t time) { … … 63 64 } 64 65 66 // takes a string like that returned by time2text and returns corresponding time_t 65 67 // returns -1 if an error occurs 66 68 time_t text2time (const text_t ×tr) { … … 114 116 return mktime (&timetm); 115 117 } 118 119 // returns current date and time formatted like "Thu Dec 7 23:43:38 2000" 120 // if ltime is true return value will be expressed in local time, otherwise 121 // it'll be Coordinated Universal Time (UTC) 122 // returns "" if an error occurs 123 text_t get_date (bool ltime) { 124 125 char *timestr; 126 tm *tm_ptr = NULL; 127 time_t t = time(NULL); 128 if (ltime) tm_ptr = localtime (&t); 129 else tm_ptr = gmtime (&t); 130 if (tm_ptr == NULL) return ""; 131 132 strftime (timestr, 128, "%a %b %e %T %Y", tm_ptr); 133 text_t ret = timestr; 134 return ret; 135 } -
trunk/gsdl/lib/gsdltimes.h
r1310 r1778 39 39 time_t text2time (const text_t ×tr); 40 40 41 42 // returns formatted date in local or UTC time 43 // returns "" if an error occurs 44 text_t get_date (bool ltime); 45 41 46 #endif -
trunk/gsdl/perllib/cpan/Mail/Sendmail.pm
r1762 r1778 18 18 %mailcfg = ( 19 19 # List of SMTP servers: 20 'smtp' => [ qw( localhost ) ], 21 #'smtp' => [ qw( mail.mydomain.com ) ], # example 20 'smtp' => [], 22 21 23 22 'from' => '', # default sender e-mail, used when no From header in mail … … 164 163 165 164 $smtp = $mail{'Smtp'} || $mail{'Server'} || $default_smtp_server; 166 unshift @{$mailcfg{'smtp'}}, $smtp if ($smtp and $mailcfg{'smtp'}->[0] ne $smtp); 165 # unshift @{$mailcfg{'smtp'}}, $smtp if ($smtp and $mailcfg{'smtp'}->[0] ne $smtp); 166 unshift @{$mailcfg{'smtp'}}, $smtp if $smtp; # Change here to avoid undefined value 167 # with our empty mailcfg{'smtp'} - Stefan 167 168 168 169 # delete non-header keys, so we don't send them later as mail headers -
trunk/gsdl/src/recpt/collectoraction.cpp
r1759 r1778 35 35 #include "cfgread.h" 36 36 #include "gsdltools.h" 37 #include "gsdltimes.h" 37 38 #include "nullproto.h" 38 39 … … 1020 1021 1021 1022 } else { 1023 1024 const recptconf &rcinfo = recpt->get_configinfo (); 1025 bool emailuserevents = rcinfo.EmailUserEvents; 1026 1027 // get collection maintainer email from collect.cfg before we 1028 // delete it 1029 text_t colmaintainer; 1030 text_t cfgfile = filename_cat(gsdlhome, "collect", collection, "etc", "collect.cfg"); 1031 char *cfgfilec = cfgfile.getcstr(); 1032 ifstream cfg_in (cfgfilec); 1033 delete cfgfilec; 1034 if (cfg_in) { 1035 text_tarray cfgline; 1036 while (read_cfg_line(cfg_in, cfgline) >= 0) { 1037 if (cfgline.size () == 2 && cfgline[0] == "maintainer") { 1038 colmaintainer = cfgline[1]; 1039 break; 1040 } 1041 } 1042 cfg_in.close(); 1043 } 1044 if (colmaintainer.empty()) { 1045 logout << outconvert 1046 << "collectoraction::do_action WARNING: Collection being deleted (" 1047 << collection << ") has no maintainer address. EmailUserEvents " 1048 << "disabled\n"; 1049 emailuserevents = false; 1050 } 1051 1022 1052 // first we need to free up the collection's collection server 1023 1053 // we must do this for the local library (and I guess when using … … 1026 1056 remove_colservr (collection, logout); 1027 1057 1058 1028 1059 char *collectionc = collection.getcstr(); 1029 1060 int rv = gsdl_call_perl ("delcol.pl", "-f", collectionc, NULL); … … 1034 1065 } else { 1035 1066 message = "delsuccess"; 1067 } 1068 1069 // log the event 1070 if (rcinfo.LogEvents == CollectorEvents || rcinfo.LogEvents == AllEvents) { 1071 1072 text_t eventlog = filename_cat (gsdlhome, "etc", "events.txt"); 1073 char *eventlogt = eventlog.getcstr(); 1074 ofstream eventl (eventlogt, ios::app); 1075 delete eventlogt; 1076 1077 if (eventl) { 1078 eventl << outconvert << "[Collector Event]\n" 1079 << "Date: " << get_date (true) << "\n" 1080 << "Greenstone Username: " << args["un"] << "\n" 1081 << "Collection: " << collection << "\n" 1082 << "Collection Maintainer: " << colmaintainer << "\n" 1083 << "GSDLHOME: " << gsdlhome << "\n"; 1084 1085 if (message == "delsuccess") { 1086 eventl << outconvert 1087 << "The " << collection << " collection was successfully deleted\n\n"; 1088 } else { 1089 eventl << outconvert 1090 << "Attempt to delete the " << collection << " collection failed\n\n"; 1091 } 1092 eventl.close(); 1093 1094 } else { 1095 logout << outconvert << "collectoraction::do_action ERROR: Couldn't open " 1096 << "event log file " << eventlog << " for appending during collection " 1097 << "deletion. LogEvents disabled\n"; 1098 } 1099 } 1100 1101 if (rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents || emailuserevents) { 1102 // use sendmail.pl perl script to send email events 1103 text_t tmpmailfile = filename_cat (gsdlhome, "tmp", args["bc1tmp"], "event.txt"); 1104 char *tmpmailfilec = tmpmailfile.getcstr(); 1105 ofstream tmpfile (tmpmailfilec); 1106 if (tmpfile) { 1107 tmpfile << outconvert << "[Collector Event]\n" 1108 << "Date: " << get_date (true) << "\n" 1109 << "Greenstone Username: " << args["un"] << "\n" 1110 << "Collection: " << collection << "\n" 1111 << "Collection Maintainer: " << colmaintainer << "\n" 1112 << "GSDLHOME: " << gsdlhome << "\n"; 1113 if (message == "delsuccess") { 1114 tmpfile << outconvert 1115 << "The " << collection << " collection was successfully deleted\n\n"; 1116 } else { 1117 tmpfile << outconvert 1118 << "Attempt to delete the " << collection << " collection failed\n\n"; 1119 } 1120 tmpfile.close(); 1121 text_t to; 1122 if (rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents) to += rcinfo.maintainer; 1123 if (emailuserevents) { 1124 if (!to.empty()) to.push_back (','); 1125 to += colmaintainer; 1126 } 1127 char *to_c = to.getcstr(); 1128 char *from_c = rcinfo.maintainer.getcstr(); 1129 char *smtp_c = rcinfo.MailServer.getcstr(); 1130 gsdl_call_perl ("sendmail.pl", "-to", to_c, "-from", from_c, "-smtp", smtp_c, 1131 "-subject", "Greenstone Collector Event", "-msgfile", tmpmailfilec, NULL); 1132 delete (to_c); 1133 delete (from_c); 1134 delete (smtp_c); 1135 1136 } else { 1137 logout << outconvert << "collectoraction::do_action ERROR: Couldn't open " 1138 << "temporary event log file " << tmpmailfile << " during collection " 1139 << "deletion. EmailEvents and EmailUserEvents disabled\n"; 1140 } 1141 delete (tmpmailfilec); 1036 1142 } 1037 1143 } … … 1251 1357 void collectoraction::gsdl_build (cgiargsclass &args, ostream &logout) { 1252 1358 1359 outconvertclass text_t2ascii; 1360 1253 1361 text_t tmpdir = filename_cat (gsdlhome, "tmp", args["bc1tmp"]); 1254 1362 if (!directory_exists (tmpdir)) { … … 1283 1391 } 1284 1392 1393 const recptconf &rcinfo = recpt->get_configinfo (); 1394 1395 // create the event header file if LogEvents, EmailEvents or 1396 // EmailUserEvents options are turned on. 1397 bool logevents = 1398 (rcinfo.LogEvents == CollectorEvents || rcinfo.LogEvents == AllEvents || 1399 rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents || 1400 rcinfo.EmailUserEvents); 1401 text_t ehead_file = filename_cat (tmpdir, "ehead.txt"); 1402 if (logevents) { 1403 if (!create_event_header_file (ehead_file, args, logout)) { 1404 logevents = false; 1405 } 1406 } 1407 1285 1408 // set up build options 1286 1409 text_t options = "-remove_import -out \""; … … 1301 1424 if (!args["bc1inputdir4"].empty()) 1302 1425 options += " -download \"" + args["bc1inputdir4"] + "\""; 1426 1427 if (logevents) { 1428 if (rcinfo.LogEvents == CollectorEvents || rcinfo.LogEvents == AllEvents) 1429 options += " -log_events"; 1430 if (rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents) { 1431 options += " -mail_server " + rcinfo.MailServer; 1432 options += " -email_events " + rcinfo.maintainer; 1433 if (rcinfo.EmailUserEvents) options += "," + args["bc1contactemail"]; 1434 } else if (rcinfo.EmailUserEvents) { 1435 options += " -mail_server " + rcinfo.MailServer; 1436 options += " -email_events " + args["bc1contactemail"]; 1437 } 1438 options += " -event_header " + ehead_file; 1439 } 1440 1303 1441 text_t optionfile = filename_cat (tmpdir, "build.opt"); 1304 1442 char *optionfilec = optionfile.getcstr(); … … 1309 1447 return; 1310 1448 } 1311 outconvertclass text_t2ascii;1312 1449 ofile_out << text_t2ascii << options << "\n"; 1313 1450 ofile_out.close(); … … 1437 1574 logout << "collectoraction::create_colserver: no valid nullproto found\n"; 1438 1575 } 1576 1577 bool collectoraction::create_event_header_file (const text_t &filename, cgiargsclass &args, 1578 ostream &logout) { 1579 1580 outconvertclass text_t2ascii; 1581 char *filenamec = filename.getcstr(); 1582 ofstream eheadfile (filenamec); 1583 delete filenamec; 1584 1585 if (eheadfile) { 1586 eheadfile << text_t2ascii << get_event_header (args); 1587 eheadfile.close(); 1588 return true; 1589 } 1590 1591 logout << text_t2ascii << "collectoraction::create_event_header ERROR: Couldn't create " 1592 << "Event Header file " << filename << ". Event logging disabled\n"; 1593 return false; 1594 } 1595 1596 text_t collectoraction::get_event_header (cgiargsclass &args) { 1597 text_t header = "Greenstone Username: " + args["un"] + "\n"; 1598 header += "Collection: " + args["bc1dirname"] + "\n"; 1599 header += "Collection Creator: " + args["bc1contactemail"] + "\n"; 1600 header += "GSDLHOME: " + gsdlhome + "\n"; 1601 header += "Build Location: " + get_collectdir(args) + "\n"; 1602 1603 return header; 1604 } -
trunk/gsdl/src/recpt/collectoraction.h
r1759 r1778 83 83 void remove_colservr (const text_t &collection, ostream &logout); 84 84 85 bool create_event_header_file (const text_t &filename, cgiargsclass &args, 86 ostream &logout); 87 88 text_t get_event_header (cgiargsclass &args); 89 85 90 public: 86 91 collectoraction (); -
trunk/gsdl/src/recpt/receptionist.cpp
r1762 r1778 418 418 // if maintainer email address is something dodgy (for now I'll define 419 419 // dodgy as being anything that doesn't contain '@') disable EmailEvents 420 // and EmailUserEvents 420 // and EmailUserEvents (we don't strictly need to disable EmailUserEvents 421 // in this case but we will as it seems likely that MailServer will also 422 // be screwed up if maintainer is). 421 423 text_t::const_iterator maintainer_end = configinfo.maintainer.end (); 422 424 text_t::const_iterator maintainer_here = findchar (configinfo.maintainer.begin(), … … 428 430 // if MailServer isn't set it should default to mail.maintainer-domain 429 431 if (configinfo.MailServer.empty()) { 430 configinfo.MailServer = "mail." + substr (maintainer_here , maintainer_end);432 configinfo.MailServer = "mail." + substr (maintainer_here+1, maintainer_end); 431 433 } 432 434 }
Note:
See TracChangeset
for help on using the changeset viewer.