Changeset 1778


Ignore:
Timestamp:
2000-12-08T17:00:35+13:00 (23 years ago)
Author:
sjboddie
Message:

Implemented the new MailServer, LogEvents, EmailEvents and EmailUserEvents
configuration options.

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###########################################################################
    227
    328# This perl script may be called directly or by running build.bat on
     
    1035package build;
    1136
    12 use lib qq($ENV{'GSDLHOME'}/perllib/cpan);
    1337use FileHandle;
    1438use File::Copy;
    15 use Mail::Sendmail;
    16 
    1739
    1840BEGIN {
     
    2850}
    2951
     52use lib qq($ENV{'GSDLHOME'}/perllib/cpan);
     53use Mail::Sendmail;
    3054use parsargv;
    3155use util;
     
    434458
    435459    # get the event header
    436     my $eheader = "";
     460    my $eheader = "[Build Event]\n";
     461    $eheader .= "Date: " . scalar localtime() . "\n";
    437462    if ($event_header ne "" && open (HEADER, $event_header)) {
    438463    undef $/;
    439     $eheader = HEADER;
     464    $eheader .= <HEADER>;
    440465    $/ = "\n";
    441466    close HEADER;
    442467    } else {
    443     $eheader = "[Build Event]\n";
    444     $eheader .= "Date: " . scalar localtime() . "\n";
    445468    $eheader .= "Collection: $collection\n";
     469    $eheader .= "GSDLHOME: $ENV{'GSDLHOME'}\n";
     470    $eheader .= "Build Location: $collectdir\n";
    446471    }
    447472   
     
    460485        print LOG $eheader;
    461486        print LOG $msg;
     487        print LOG "\n";
    462488        close LOG;
    463489    }
  • trunk/gsdl/lib/gsdltimes.cpp

    r1310 r1778  
    2626#include "gsdltimes.h"
    2727
    28 
     28// returns a string of the form "YYYY/MM/DD hh:mm:ss" (expressed in
     29// Coordinated Universal Time (UTC))
    2930// returns "" if an error occurs
    3031text_t time2text (time_t time) {
     
    6364}
    6465
     66// takes a string like that returned by time2text and returns corresponding time_t
    6567// returns -1 if an error occurs
    6668time_t text2time (const text_t &timestr) {
     
    114116  return mktime (&timetm);
    115117}
     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
     123text_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  
    3939time_t text2time (const text_t &timestr);
    4040
     41
     42// returns formatted date in local or UTC time
     43// returns "" if an error occurs
     44text_t get_date (bool ltime);
     45
    4146#endif
  • trunk/gsdl/perllib/cpan/Mail/Sendmail.pm

    r1762 r1778  
    1818%mailcfg = (
    1919    # List of SMTP servers:
    20     'smtp'    => [ qw( localhost ) ],
    21     #'smtp'    => [ qw( mail.mydomain.com ) ], # example
     20    'smtp'    => [],
    2221
    2322    'from'    => '', # default sender e-mail, used when no From header in mail
     
    164163
    165164    $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
    167168
    168169    # delete non-header keys, so we don't send them later as mail headers
  • trunk/gsdl/src/recpt/collectoraction.cpp

    r1759 r1778  
    3535#include "cfgread.h"
    3636#include "gsdltools.h"
     37#include "gsdltimes.h"
    3738#include "nullproto.h"
    3839
     
    10201021   
    10211022    } 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     
    10221052      // first we need to free up the collection's collection server
    10231053      // we must do this for the local library (and I guess when using
     
    10261056      remove_colservr (collection, logout);
    10271057
     1058     
    10281059      char *collectionc = collection.getcstr();
    10291060      int rv = gsdl_call_perl ("delcol.pl", "-f", collectionc, NULL);
     
    10341065      } else {
    10351066    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);
    10361142      }
    10371143    }
     
    12511357void collectoraction::gsdl_build (cgiargsclass &args, ostream &logout) {
    12521358
     1359  outconvertclass text_t2ascii;
     1360
    12531361  text_t tmpdir = filename_cat (gsdlhome, "tmp", args["bc1tmp"]);
    12541362  if (!directory_exists (tmpdir)) {
     
    12831391  }
    12841392
     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   
    12851408  // set up build options
    12861409  text_t options = "-remove_import -out \"";
     
    13011424  if (!args["bc1inputdir4"].empty())
    13021425    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
    13031441  text_t optionfile = filename_cat (tmpdir, "build.opt");
    13041442  char *optionfilec = optionfile.getcstr();
     
    13091447    return;
    13101448  }
    1311   outconvertclass text_t2ascii;
    13121449  ofile_out << text_t2ascii << options << "\n";
    13131450  ofile_out.close();
     
    14371574  logout << "collectoraction::create_colserver: no valid nullproto found\n";
    14381575}
     1576
     1577bool 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
     1596text_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  
    8383  void remove_colservr (const text_t &collection, ostream &logout);
    8484
     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
    8590public:
    8691  collectoraction ();
  • trunk/gsdl/src/recpt/receptionist.cpp

    r1762 r1778  
    418418  // if maintainer email address is something dodgy (for now I'll define
    419419  // 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).
    421423  text_t::const_iterator maintainer_end = configinfo.maintainer.end ();
    422424  text_t::const_iterator maintainer_here = findchar (configinfo.maintainer.begin(),
     
    428430    // if MailServer isn't set it should default to mail.maintainer-domain
    429431    if (configinfo.MailServer.empty()) {
    430       configinfo.MailServer = "mail." + substr (maintainer_here, maintainer_end);
     432      configinfo.MailServer = "mail." + substr (maintainer_here+1, maintainer_end);
    431433    }
    432434  }
Note: See TracChangeset for help on using the changeset viewer.