home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / FAQ / discus_admin_1357211388 / source / cronhook.pl < prev    next >
Text File  |  2009-11-06  |  2KB  |  84 lines

  1. # FILE: cronhook.pl
  2. # DESCRIPTION: Various "hooks" for cron-based tasks
  3. #-------------------------------------------------------------------------------
  4. # DISCUS COPYRIGHT NOTICE
  5. #
  6. # Discus is copyright (c) 2002 by DiscusWare, LLC, all rights reserved.
  7. # The use of Discus is governed by the Discus License Agreement which is
  8. # available from the Discus WWW site at:
  9. #    http://www.discusware.com/discus/license
  10. #
  11. # Pursuant to the Discus License Agreement, this copyright notice may not be
  12. # removed or altered in any way.
  13. #-------------------------------------------------------------------------------
  14.  
  15. use strict;
  16. use vars qw($GLOBAL_OPTIONS $DCONF $PARAMS);
  17.  
  18. ###
  19. ### hook_manager
  20. ###
  21. ### Manages hooks by looking at command line:
  22. ###    (No arguments)      Send queued 'cron' messages
  23. ###    -sched              Run Discus scheduler
  24. ###    -pop3               Run POP3 mailbox checker
  25. ###
  26.  
  27. sub hook_manager {
  28.     if ($ENV{REQUEST_METHOD} ne "" || $ENV{REMOTE_ADDR} ne "") {
  29.         send_queued_cron_messages();
  30.         if ($GLOBAL_OPTIONS->{scanpop3} == 1) {
  31.             dreq("em-reply");
  32.             email_reply_pop3_handler();
  33.         }
  34.         header();
  35.         print "<!--cronhook-->\n";
  36.         program_exit(0);
  37.     } else {
  38.         if ($ARGV[0] eq "") {
  39.             send_queued_cron_messages();
  40.         } else {
  41.             while (my $j = shift @ARGV) {
  42.                 if ($j =~ /^\-sched/i) {
  43.                     dreq("schedule-PRO");
  44.                     schedule_daemon_once(); 
  45.                 } elsif ($j =~ /^\-pop3/i) {
  46.                     dreq("em-reply");
  47.                     email_reply_pop3_handler();
  48.                 }
  49.             }
  50.         }
  51.         program_exit(0);
  52.     }
  53. }
  54.  
  55. ###
  56. ### send_queued_cron_messages
  57. ###
  58. ### Sends out queued messages
  59. ###
  60.  
  61. sub send_queued_cron_messages {
  62.     if (opendir(DIR, "$DCONF->{admin_dir}/mailqueue")) {
  63.         my @dir = map { "$DCONF->{admin_dir}/mailqueue/$_" } grep { /\.txt$/ } readdir(DIR);
  64.         closedir(DIR);
  65.         my $tcache = time;
  66.         @dir = grep { (stat($_))[9] < ($tcache - 30) } @dir;
  67.         while (my $file = shift @dir) {
  68.             if (open(FILE, "< $file")) {
  69.                 my @J = <FILE>;
  70.                 close (FILE);
  71.                 unlink $file;
  72.                 my $cmdline = shift @J; chomp $cmdline;
  73.                 if (open (MAILPIPE, $cmdline)) {
  74.                     binmode MAILPIPE;
  75.                     print MAILPIPE @J;
  76.                     close (MAILPIPE);
  77.                 }
  78.             }
  79.         }
  80.     }
  81. }
  82.  
  83. 1;
  84.