/***************************************************************************/
/* PollWhen.spot   ©1993 Stu Churchill   2:250/107.97@fidonet              */
/*                                                                         */
/* $VER: PollWhen.spot 1.53 (7.9.93)                                       */
/*                                                                         */
/* This script, through the use of Spot's requesters, will add a once-only */
/* poll event to your current cron eventlist. This is useful if you want   */
/* to send crash mail during ZMH, or want to f'req a file in the early     */
/* hours of the morning, when the lines should be quieter                  */
/***************************************************************************/

options results

/***************************************************************************/
/* Set up any variables we may need for later use                          */
/***************************************************************************/

NL          = '0d'x
out_dir     = 'MAIL:Outbound'
cron_port   = 'CYBERCRON'
mailer_path = 'D:TrapDoor'
header      = NL||'PollWhen 1.53   © Stu Churchill 1993'||NL||NL

/***************************************************************************/
/* First we make sure that we can access the libraries we need             */
/***************************************************************************/

if ~show(l, 'rexxsupport.library') then do
  if ~addlib('rexxsupport.library', 0, -30) then do
    say 'Please install the rexxsupport.library in your libs: directory'
  end
end

/***************************************************************************/
/* Now we can get on with the rest of the script                           */
/***************************************************************************/

address 'SPOT'

'requestfile TITLE "Select a node to dial" PATH "'out_dir'"'
if rc > 0 then do
  exit
end
node = RESULT
if node == '' then exit
type = right(node,3)
if type = CLO | type = REQ | type = FLO | type = OUT | type = CUT then do
  node = buildaddress(node)
end
else do
  'requestnotify PROMPT "       You may only select a  #?.FLO'||NL||'#?.CLO,  #?.REQ,  #?.OUT or  #?.CUT file"'
  exit
end

'requestnumber PROMPT "At which hour of the day'||NL||'should I poll this node?" DEFAULT "2"'
if rc > 0 then do
  exit
end
hour = RESULT
if hour == '' | hour = 'RESULT' then do
  exit
end

'requestnumber PROMPT "And at which minute'||NL||'past the hour?" DEFAULT "45"'
if rc > 0 then do
  exit
end
min = RESULT
if min == '' | min = 'RESULT' then do
  exit
end

if ~show('ports',cron_port) then do
  'requestnotify PROMPT "              ** WARNING **'||NL||'Unable to locate ARexx port: '||cron_port'"'
  exit
end

address value cron_port
add_event min' 'hour' * * * :EXECONCE :OBEYQUEUE a 'mailer_path' Call 'node' Password ""'

address 'SPOT'
'requestnotify PROMPT "'header'The following event has been added to CyberCron''s eventlist;'||NL||NL||min' 'hour' ** ** ** :EXECONCE :OBEYQUEUE a 'mailer_path' Call 'node' Password ""'

exit


buildaddress: procedure
  parse arg path
  colon = lastpos('/', path)
  if colon = 0 then do
    colon = lastpos(':', path)
  end
  if colon = 0 then do
    file = path
  end
  else do
    file = (substr(path, colon + 1))
  end
  parse var file zone '.' net '.' node '.' point '.' type
  if point ~= 0 then point = 0
  node = zone':'net'/'node'.'point
  return node
