michael@202: #! @l_prefix@/bin/perl michael@202: # michael@202: # wakeup.agi 1.1 michael@202: # michael@202: # A wakeup agi script for Asterisk michael@202: # michael@202: # Copyright (C) 2007 michael@202: # michael@202: # Jonas Arndt michael@202: # michael@202: # This program is free software, distributed under the terms of the michael@202: # GNU General Public License v2. michael@202: # michael@202: # michael@202: # This program is free software: you can redistribute it and/or modify michael@202: # it under the terms of the GNU General Public License as published by michael@202: # the Free Software Foundation, either version 3 of the License, or michael@202: # (at your option) any later version. michael@202: # michael@202: # This program is distributed in the hope that it will be useful, michael@202: # but WITHOUT ANY WARRANTY; without even the implied warranty of michael@202: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the michael@202: # GNU General Public License for more details. michael@202: # michael@202: # You should have received a copy of the GNU General Public License michael@202: # along with this program. If not, see . michael@202: # michael@202: michael@202: use strict; michael@202: use Time::Local; michael@202: $|=1; michael@202: # Setup some variables michael@202: my %AGI; my $DEBUG=0; michael@202: # Some constants michael@202: my $OUTDIR="@l_prefix@/var/asterisk/spool/outgoing"; michael@202: my $WAKEDIR="@l_prefix@/var/asterisk/spool/tmp"; michael@202: my $debugfile="@l_prefix@/var/asterisk/spool/tmp/wakeup.log"; michael@202: my $DEBUGOUT = "filehandle"; michael@202: my $CALL = "filehandle"; michael@202: my $TOUCH = "/usr/bin/touch"; michael@202: michael@202: ############ check_result ########## michael@202: # Use this to check the result of # michael@202: # a sent command # michael@202: # I pretty much stole this from # michael@202: # the regular agi-test.agi # michael@202: #################################### michael@202: sub checkresult { michael@202: my ($res) = @_; michael@202: my $retval; michael@202: chomp $res; michael@202: if ($res =~ /^200/) { michael@202: $res =~ /result=(-?\d+)/; michael@202: if (!length($1)) { michael@202: print DEBUGOUT "FAIL ($res)\n"; michael@202: exit(1); michael@202: } elsif ($DEBUG=1) { michael@202: print DEBUGOUT "PASS ($1)\n"; michael@202: } michael@202: } else { michael@202: print STDERR "FAIL (unexpected result '$res')\n"; michael@202: exit(1); michael@202: } michael@202: } michael@202: michael@319: ############ send_file #### michael@319: # Use this to send a wave # michael@319: # file on the channel # michael@319: ########################### michael@202: sub send_file { michael@202: my ($myfile) = @_; michael@202: chomp($myfile); michael@202: if ($DEBUG == 1 ) { michael@202: print DEBUGOUT "Sending stream $myfile \n"; michael@202: } michael@202: print "STREAM FILE $myfile \"0123456789\"\n"; michael@202: my $result = ; michael@202: &checkresult($result); michael@202: $result =~ /result=(-?\d+)/; michael@202: return $1; michael@202: } michael@202: michael@202: ############ hangup ############### michael@319: # Use this to hang up a channel # michael@202: #################################### michael@202: sub hangup { michael@202: if ($DEBUG == 1 ) { michael@202: print DEBUGOUT "Hanging up \n"; michael@202: } michael@202: print "HANGUP \"\" \n"; michael@202: my $result = ; michael@202: &checkresult($result); michael@202: } michael@202: michael@202: ############ say_number ############ michael@202: # Use this to say a number # michael@202: # over the channel # michael@202: # # michael@202: #################################### michael@202: sub say_number { michael@202: my ($mynumber) = @_; michael@202: chomp($mynumber); michael@202: if ($DEBUG == 1 ) { michael@202: print DEBUGOUT "Saying number $mynumber \n"; michael@202: } michael@202: print "SAY NUMBER $mynumber \"0123456789\"\n"; michael@202: my $result = ; michael@202: &checkresult($result); michael@202: $result =~ /result=(-?\d+)/; michael@202: return $1; michael@202: } michael@202: michael@319: ############ say_digits ################### michael@319: # Use this to say digits over the channel # michael@319: ########################################### michael@202: sub say_digits { michael@202: my ($mynumber) = @_; michael@202: chomp($mynumber); michael@202: if ($DEBUG == 1 ) { michael@202: print DEBUGOUT "Saying digits $mynumber \n"; michael@202: } michael@202: print "SAY DIGITS $mynumber \"0123456789\"\n"; michael@202: my $result = ; michael@202: &checkresult($result); michael@202: } michael@202: michael@319: ######## get_choice ############ michael@319: # Use this to receive a DTMF # michael@319: # choice from the channel # michael@319: ################################ michael@202: sub get_choice { michael@202: if ($DEBUG == 1 ) { michael@202: print DEBUGOUT "Getting choice \n"; michael@202: } michael@202: print "WAIT FOR DIGIT 15000\n"; michael@202: my $result = ; michael@202: &checkresult($result); michael@202: $result =~ /result=(-?\d+)/; michael@202: return $1; michael@202: } michael@202: michael@319: ###### answer ###### michael@319: # Anser the channel # michael@319: ##################### michael@202: sub answer { michael@202: if ($DEBUG == 1 ) { michael@202: print DEBUGOUT "Answering the channel \n"; michael@202: } michael@202: print "ANSWER\n"; michael@202: my $result = ; michael@202: &checkresult($result); michael@202: $result =~ /result=(-?\d+)/; michael@202: return $1; michael@202: } michael@202: michael@202: ######## get_data ################## michael@202: # Feed with (file, maxnumbers) # michael@202: # where file is the sound file # michael@202: # to be played and maxnumbers is # michael@202: # the maximum amount of digits to # michael@202: # allow in the answer # michael@202: #################################### michael@202: sub get_data { michael@202: my @mydata = @_; michael@202: my $myfile = $mydata[0]; michael@202: my $mymax = $mydata[1]; michael@202: if ($DEBUG == 1 ) { michael@202: print DEBUGOUT "Getting data \n"; michael@202: } michael@202: print "GET DATA $myfile 15000 $mymax \n"; michael@202: my $result = ; michael@202: &checkresult($result); michael@202: $result =~ /result=(-?\d+)/; michael@202: return $1; michael@202: } michael@202: michael@202: ###### check_outstanding_calls ##### michael@202: # Are there any outstanding wakeup # michael@202: # calls for this extensions? # michael@202: # Pass the extension to the # michael@202: # function. The function returns # michael@202: # a list of files # michael@202: #################################### michael@202: sub check_outstanding_calls { michael@202: my $myext = @_; michael@202: #opendir DIR, $WAKEDIR; michael@202: opendir DIR, $OUTDIR; michael@202: my @files = grep {/$myext/} readdir(DIR); michael@202: closedir DIR; michael@202: return @files; michael@202: } michael@202: michael@202: ######## get_extension ############# michael@202: # Receive the AIG variable and # michael@202: # return the extension # michael@202: #################################### michael@202: sub get_extension { michael@202: my (@aig) = @_; michael@202: if ($aig[11] == '') { michael@202: print STDERR "No extension found in function get_exension \n"; michael@202: return "FAIL"; michael@202: } michael@202: my $myext = $aig[11]; michael@202: return $myext; michael@202: } michael@202: michael@202: ######## get_context ############### michael@202: # Receive the AIG variable and # michael@202: # return the context # michael@202: #################################### michael@202: sub get_context { michael@202: my (@aig) = @_; michael@202: if ($aig[8] == '') { michael@202: print STDERR "No extension found in function get_exension \n"; michael@202: return "FAIL"; michael@202: } michael@202: my $mycont = $aig[8]; michael@202: return $mycont; michael@202: } michael@202: michael@202: ########### get_clid ############### michael@202: # Receive the AIG variable and # michael@202: # return the clid # michael@202: #################################### michael@202: sub get_clid { michael@202: my (@aig) = @_; michael@202: if ($aig[1] == '') { michael@202: print STDERR "No clid found in function get_clid \n"; michael@202: return "FAIL"; michael@202: } michael@202: my $myext = $aig[1]; michael@202: return $myext; michael@202: } michael@319: michael@319: ############### init_agi ################## michael@319: # Use this to initialize the AGI variable # michael@319: ########################################### michael@202: sub init_agi { michael@202: while() { michael@202: chomp; michael@202: last unless length($_); michael@202: if (/^agi_(\w+)\:\s+(.*)$/) { michael@202: $AGI{$1} = $2; michael@202: } michael@202: } michael@202: } michael@202: michael@319: ######### ascii2num ########## michael@319: # Removes 48 to get a number # michael@319: # out of the asciss return # michael@319: ############################## michael@202: sub ascii2num { michael@202: my ($asc) = @_; michael@202: my $ret; michael@202: $ret = $asc - 48; michael@202: return $ret; michael@202: } michael@202: michael@319: ############# Welcome ############## michael@202: # This is the welcome menu # michael@202: #################################### michael@202: sub welcome { michael@202: my $ret = 0; michael@202: $ret = &send_file("welcome"); michael@202: if ($ret == 0) { michael@202: $ret = &send_file("for-wakeup-call"); michael@202: } michael@202: if ($ret == 0) { michael@202: $ret = &send_file("press-1"); michael@202: } michael@202: if ($ret == 0) { michael@202: $ret = &send_file("for-a-list-of"); michael@202: } michael@202: if ($ret == 0) { michael@202: $ret = &send_file("or"); michael@202: } michael@202: if ($ret == 0) { michael@202: $ret = &send_file("to-cancel-wakeup"); michael@202: } michael@202: if ($ret != 0) { michael@202: $ret = &ascii2num($ret); michael@202: } michael@202: if ($ret == 0) { michael@202: $ret = &get_data("press-2",1); michael@202: } michael@202: if ($ret == 1) { michael@202: $ret = &schedule_new(); michael@202: } elsif ($ret == 2) { michael@202: &manage_calls(); michael@202: } else { michael@202: $ret = &send_file("goodbye"); michael@202: } michael@202: } michael@202: michael@202: ######### manage_calls ############# michael@202: # This is what is called if you # michael@202: # want to manage already scheduled # michael@202: # wakeup calls # michael@202: #################################### michael@202: sub manage_calls { michael@202: my $checker = "false"; michael@202: my @calls; michael@202: my $del; michael@202: #my $ret; michael@202: my $hours; michael@202: my $minutes; michael@202: # Send out a welcome message and ask for return michael@202: @calls = &check_outstanding_calls($AGI{callerid}); michael@202: if ($#calls + 1 == 0) { michael@202: $del = &send_file("not-rqsted-wakeup"); michael@202: $del = &send_file("goodbye"); michael@202: } else { michael@202: foreach (@calls) { michael@202: $del = 0; michael@202: my $wakefile = $_; michael@202: my @wakeup = split /\./, $_; michael@202: my $time = $wakeup[0]; michael@202: $_ = $time; michael@202: /(^[0-9][0-9])/; michael@202: my $hours = $1; michael@202: /^[0-9][0-9]([0-9][0-9])/; michael@202: my $minutes = $1; michael@202: $del = &send_file("rqsted-wakeup-for"); michael@202: if ($del == 0) { michael@202: $del = &say_number($hours); michael@202: } michael@202: if ($del == 0) { michael@202: if ($minutes >= 10 ) { michael@202: $del = &say_number($minutes); michael@202: } elsif ($minutes > 0 && $minutes < 10) { michael@202: $del = &send_file("digits/oh"); michael@202: $del = &say_number($minutes); michael@202: } michael@202: } michael@202: if ($del == 0) { michael@202: $del = &send_file("digits/oclock"); michael@202: } michael@202: if ($del == 0) { michael@202: $del = &send_file("to-cancel-wakeup"); michael@202: } michael@202: if ($del == 0) { michael@202: $del = &send_file("press-1"); michael@202: } michael@202: if ($del == 0) { michael@202: $del = &send_file("otherwise-press"); michael@202: } michael@202: if ($del != 0) { michael@202: $del = &ascii2num($del); michael@202: } michael@202: if ($del == 0) { michael@202: $del = &get_data("digits/2",1); michael@202: } michael@202: if ($del == 1) { michael@202: my @sysargs = ("rm", "-f", "$WAKEDIR/$wakefile", "$OUTDIR/$wakefile"); michael@202: system(@sysargs) == 0 michael@202: or die "system @sysargs failed: $?"; michael@202: $del = &send_file("cancelled"); michael@202: } michael@202: } michael@202: $del = &send_file("goodbye"); michael@202: } michael@202: } michael@202: michael@319: ######## schedule_new ########## michael@319: # This is the menu to schedule # michael@319: # a new wakeup call # michael@319: ################################ michael@202: sub schedule_new { michael@202: my $checker = "false"; michael@202: my $ret_var; michael@202: my $ret_dummy = 0; michael@202: my $time; michael@202: my $perm; michael@202: my $file; michael@202: my $calltype; michael@202: my $extension; michael@202: my $context; michael@202: my $hours; michael@202: my $minutes; michael@202: if ($DEBUG == 1 ) { michael@202: print DEBUGOUT "From schedule_new\n"; michael@202: } michael@202: while ( $checker eq "false" ) { michael@202: $ret_var = &send_file("to-rqst-wakeup-call"); michael@202: if ($ret_var != 0) { michael@202: my $tmp = &get_data("silence/1",3); michael@202: $ret_var = &ascii2num($ret_var); michael@202: $ret_var = $ret_var . $tmp; michael@202: } else { michael@202: $ret_var = &get_data("enter-a-time",4); michael@202: } michael@202: # if ($ret_var < 1300 && $ret_var >= 0100) { michael@202: # my $pm = &get_data("1-for-am-2-for-pm",1); michael@202: # if ($pm == 2 && $ret_var <= 1159) { michael@202: # $ret_var = $ret_var + 1200; michael@202: # $checker = "true"; michael@202: # } elsif ($pm == 1 && $ret_var > 1159) { michael@202: # $ret_var = $ret_var - 1200; michael@202: # # Fix the zero michael@202: # $ret_var = "00" . $ret_var; michael@202: # $checker = "true"; michael@202: # } else { michael@202: # $checker = "true"; michael@202: # } michael@202: # } elsif ($ret_var > 2359) { michael@202: # $ret_dummy = &send_file("please-try-again"); michael@202: # } else { michael@202: # $checker = "true"; michael@202: # } michael@202: if ($ret_var > 2359) { michael@202: $ret_dummy = &send_file("please-try-again"); michael@202: } else { michael@202: $checker = "true"; michael@202: } michael@202: } michael@202: $perm = 0; michael@202: $perm = &send_file("wakeup-for-one-time"); michael@202: if ($perm == 0) { michael@202: $perm = &send_file("press-1"); michael@202: } michael@202: if ($perm == 0) { michael@202: $perm = &send_file("for-a-daily-wakeup-call"); michael@202: } michael@202: if ($perm != 0) { michael@202: $perm = &ascii2num($perm); michael@202: } michael@202: if ($perm == 0) { michael@202: $perm = $perm = &get_data("press-2",1); michael@202: } michael@202: # Open the file and populate it with data michael@202: $extension = $AGI{callerid}; michael@202: $context = $AGI{context}; michael@202: if ($perm == 2) { michael@202: $file = "$WAKEDIR/$ret_var.perm.1.$extension.call"; michael@202: $calltype = "perm"; michael@202: open (CALL, '>', $file) or die "Cannot open call file for write :$!"; michael@202: } else { michael@202: $file = "$WAKEDIR/$ret_var.temp.1.$extension.call"; michael@202: $calltype = "temp"; michael@202: open (CALL, '>', $file) or die "Cannot open call file for write :$!"; michael@202: } michael@202: my $myprint = "channel: Local" . "/" . $extension . "@" . $context . "\n"; michael@202: print CALL $myprint; michael@202: print CALL "maxretries: 3\n"; michael@202: print CALL "retrytime: 60\n"; michael@202: print CALL "waittime: 60\n"; michael@202: print CALL "callerid: \"AsterPBX Weckruf\" <$AGI{extension}>\n"; michael@202: print CALL "application: AGI\n"; michael@202: print CALL "data: wakeup|$ret_var.$calltype.1.$extension.call\n"; michael@202: close ($CALL); michael@202: # Now touch the file michael@202: # Get the time variable michael@202: $time = get_time_string($ret_var); michael@202: my @command = ("$TOUCH", "-t", "$time", "${file}"); michael@202: system(@command) == 0 michael@202: or die "system @command failed: $?"; michael@202: # Move it to the OUT directory michael@202: my @command = ("mv", "${file}", "${OUTDIR}/"); michael@202: system(@command) == 0 michael@202: or die "system @command failed: $?"; michael@202: michael@202: # Stream out the wakeup michael@202: $_ = $ret_var; michael@202: /(^[0-9][0-9])/; michael@202: my $hours = $1; michael@202: /^[0-9][0-9]([0-9][0-9])/; michael@202: my $minutes = $1; michael@202: $ret_dummy = &send_file("rqsted-wakeup-for"); michael@202: $ret_dummy = &say_number($hours); michael@202: if ($minutes >= 10 ) { michael@202: &say_number($minutes); michael@202: } elsif ($minutes > 0 && $minutes < 10) { michael@202: &send_file("digits/oh"); michael@202: &say_number($minutes); michael@202: } michael@202: $ret_dummy = &send_file("digits/oclock"); michael@202: $ret_dummy = &send_file("goodbye"); michael@202: return $ret_var; michael@202: } michael@202: michael@202: ######## get_time_string ########### michael@202: # This will return the time string # michael@319: # when inputing a string like hhmi # michael@202: #################################### michael@202: sub get_time_string { michael@202: my ($intime) = @_; michael@202: my $minutes = substr($intime, 2, 4); michael@202: my $hours = substr($intime, 0, 2); michael@202: my $tmpepoch; michael@202: my $day; michael@202: my $month; michael@202: my $ret_val; michael@202: my $epoch = time(); michael@202: my @timedata = localtime($epoch); michael@202: # Insert the minutes and hours from input michael@202: $timedata[1] = $minutes; michael@202: $timedata[2] = $hours; michael@202: # Get tmpepoch michael@202: $tmpepoch = timelocal(@timedata); michael@202: #Now compare them michael@202: if ($tmpepoch < $epoch) { # Means it is tomorrow michael@202: $tmpepoch += 86400; # Add 24 hours michael@202: } michael@202: # Now get the new timedata michael@202: my @timedata = localtime($tmpepoch); michael@202: $minutes = $timedata[1]; michael@202: $hours = $timedata[2]; michael@202: $day = $timedata[3]; michael@202: $month = $timedata[4] + 1; michael@202: #Correct the "First hour after midnight" problem michael@202: if ($minutes < 10) { michael@202: $minutes = "0" . $minutes; michael@202: } michael@202: if ($hours < 10) { michael@202: $hours = "0" . $hours; michael@202: } michael@202: if ($day < 10) { michael@202: $day = "0" . $day; michael@202: } michael@202: if ($month < 10) { michael@202: $month = "0" . $month; michael@202: } michael@202: $ret_val = $month . $day . $hours . $minutes; michael@202: return $ret_val; michael@202: } michael@202: michael@319: ############ new_time ################ michael@319: # This will return the time string # michael@319: # with a time set 10 minute into # michael@319: # the future. The string is MMDDhhmi # michael@319: ###################################### michael@202: sub new_time { michael@202: my ($input) = @_; michael@202: my @timedata; michael@202: my $minutes; michael@202: my $hours; michael@202: my $day; michael@202: my $month; michael@202: my $ret_val; michael@202: my $epoc = time(); michael@202: if ($input eq "10m") { michael@202: # add 10 minutes michael@202: $epoc += 600; michael@202: #$epoc += 120; #just for debugs michael@202: } else { michael@202: # add 24 hours michael@202: $epoc += 86400; michael@202: } michael@202: @timedata = localtime($epoc); michael@202: $minutes = $timedata[1]; michael@202: $hours = $timedata[2]; michael@202: $day = $timedata[3]; michael@202: $month = $timedata[4] + 1; michael@202: #Correct the "First hour after midnight" problem michael@202: if ($minutes < 10) { michael@202: $minutes = "0" . $minutes; michael@202: } michael@202: if ($hours < 10) { michael@202: $hours = "0" . $hours; michael@202: } michael@202: if ($day < 10) { michael@202: $day = "0" . $day; michael@202: } michael@202: if ($month < 10) { michael@202: $month = "0" . $month; michael@202: } michael@202: $ret_val = $month . $day . $hours . $minutes; michael@202: return $ret_val; michael@202: } michael@202: michael@319: ########### snooze ########## michael@319: # This is the menu to snooze # michael@319: # the wakeup call # michael@319: ############################## michael@202: sub snooze { michael@202: my ($oldfile) = @_; michael@202: my $newfile; michael@202: my $extension; michael@202: my $context; michael@202: my @filestore = split (/\./, $oldfile); michael@202: my @permstore = split (/\./, $oldfile); michael@202: my $time; michael@202: my $ret_var = 0; michael@202: my $ret_dummy; michael@202: my $myprint; michael@202: # Answer the channel michael@202: &answer(); michael@202: # Is this a reoccuring call, then add 24h michael@202: if ($permstore[1] eq "perm") { michael@202: $permstore[2] += 1; #Just to get a new file name michael@202: $newfile = join(".",@permstore); michael@202: $extension = $AGI{extension}; michael@202: $context = $AGI{context}; michael@202: # Open the file michael@202: open (CALL, '>', "${WAKEDIR}/${newfile}") or die "Cannot open call file for write :$!"; michael@202: $myprint = "channel: Local" . "/" . $extension . "@" . $context . "\n"; michael@202: print CALL $myprint; michael@202: print CALL "maxretries: 3\n"; michael@202: print CALL "retrytime: 60\n"; michael@202: print CALL "waittime: 60\n"; michael@202: print CALL "callerid: \"AsterPBX Weckruf\" <$AGI{callerid}>\n"; michael@202: print CALL "application: AGI\n"; michael@202: print CALL "data: wakeup|$newfile\n"; michael@202: close ($CALL); michael@202: # Get a time 24h from now michael@202: $time = &new_time("24h"); michael@202: # Touch the file with the new time michael@202: my @command = ("$TOUCH", "-t", "$time", "${WAKEDIR}/${newfile}"); michael@202: system(@command) == 0 michael@202: or die "system @command failed: $?"; michael@202: # Now move it michael@202: my @command = ("mv", "${WAKEDIR}/${newfile}", "${OUTDIR}/${newfile}"); michael@202: system(@command) == 0 michael@202: or die "system @command failed: $?"; michael@202: } michael@202: #Replace the file name time with snooze michael@202: $filestore[1] = "snooze"; michael@202: # Also add 10 minutes to the name michael@202: $time = new_time("10m"); michael@202: $filestore[0] = substr($time, 4, 8); michael@202: # Get the new file name michael@202: $newfile = join(".",@filestore); michael@202: $ret_var = &send_file("this-is-yr-wakeup-call"); michael@202: if ($ret_var == 0 ) { michael@202: $ret_var = &send_file("to-confirm-wakeup"); michael@202: } michael@202: if ($ret_var == 0 ) { michael@202: $ret_var = &send_file("press-1"); michael@202: } michael@202: if ($ret_var == 0 ) { michael@202: $ret_var = &send_file("to-snooze-for"); michael@202: } michael@202: if ($ret_var == 0 ) { michael@202: $ret_var = &send_file("digits/10"); michael@202: } michael@202: if ($ret_var == 0 ) { michael@202: $ret_var = &send_file("minutes"); michael@202: } michael@202: if ($ret_var != 0 ) { michael@202: $ret_var = &ascii2num($ret_var); michael@202: } michael@202: if ($ret_var == 0 ) { michael@202: $ret_var = &get_data("press-2",1); michael@202: } michael@202: if ($ret_var == 2 ) { michael@202: # Populate some variables michael@202: $time = &new_time("10m"); michael@202: $extension = $AGI{extension}; michael@202: $context = $AGI{context}; michael@202: # Open the file michael@202: open (CALL, '>', "${WAKEDIR}/${newfile}") or die "Cannot open call file for write :$!"; michael@202: $myprint = "channel: Local" . "/" . $extension . "@" . $context . "\n"; michael@202: print CALL $myprint; michael@202: print CALL "maxretries: 3\n"; michael@202: print CALL "retrytime: 60\n"; michael@202: print CALL "waittime: 60\n"; michael@202: print CALL "callerid: \"AsterPBX Weckruf\" <$AGI{callerid}>\n"; michael@202: print CALL "application: AGI\n"; michael@202: print CALL "data: wakeup|$newfile\n"; michael@202: close ($CALL); michael@202: # Touch the file with the new time michael@202: my @command = ("$TOUCH", "-t", "$time", "${WAKEDIR}/${newfile}"); michael@202: system(@command) == 0 michael@202: or die "system @command failed: $?"; michael@202: # Now move it michael@202: my @command = ("mv", "${WAKEDIR}/${newfile}", "${OUTDIR}/${newfile}"); michael@202: system(@command) == 0 michael@202: or die "system @command failed: $?"; michael@202: $ret_dummy = &send_file("goodbye"); michael@202: michael@202: } elsif ($ret_var == 1) { michael@202: $ret_dummy = &send_file("goodbye"); michael@202: } else { michael@202: $ret_dummy = &send_file("goodbye"); michael@202: } michael@202: michael@202: # Stream out the wakeup michael@202: return 0; michael@202: } michael@202: michael@319: ######## main program ######## michael@319: # Here goes the main program # michael@319: ############################## michael@202: my $numargs = $#ARGV + 1; michael@202: if ($DEBUG == 1) { michael@202: open (DEBUGOUT, '>', $debugfile) or die "Cannot open $debugfile for write :$!"; michael@202: } michael@202: michael@202: # Start by reading in the stuff Asterisk is sending michael@202: &init_agi(); # Comment out in case of debug outside Asterisk michael@202: michael@202: # If DEBUG is set, dump the AGI variable michael@202: if ($DEBUG == 1) { michael@202: foreach my $i (sort keys %AGI) { michael@202: print DEBUGOUT " -- $i = $AGI{$i}\n"; michael@202: } michael@202: } michael@202: michael@202: if ( $numargs == 0 ) { michael@202: &welcome(); michael@202: &hangup(); michael@202: exit(0); michael@202: } elsif ( $ARGV[0] eq "move" ) { michael@202: &move(); michael@202: &hangup(); michael@202: exit(0); michael@202: } else { michael@202: &snooze($ARGV[0]); michael@202: &hangup(); michael@202: exit(0); michael@202: } michael@202: michael@202: if ($DEBUG ==1) { michael@202: close $DEBUGOUT; michael@202: }