[asterisk-users] System Command not executing php

Tim King tim.compnetwork at gmail.com
Wed Aug 24 12:21:18 CDT 2011


*I have been testing this for a week now, and I am still struggling to make
it work. Here is the output from extension 11 just to show that permissions
are correct and asterisk can access faxnotify.php*

    -- Executing [11 at outb2:1] Verbose("SIP/616818xxxx-000002f6",
"Testing....") in new stack
Testing....
    -- Executing [11 at outb2:2] Set("SIP/616818xxxx-000002f6",
"FNAME=/var/lib/asterisk/bin/faxnotify.php") in new stack
    -- Executing [11 at outb2:3] Verbose("SIP/616818xxxx-000002f6", "Size:
2553") in new stack
Size: 2553
    -- Executing [11 at outb2:4] Verbose("SIP/616818xxxx-000002f6", "Mode:
100777") in new stack
Mode: 100777
    -- Executing [11 at outb2:5] Verbose("SIP/616818xxxx-000002f6",
"#!/usr/bin/php
<?php

// set some global variables here
$SUCCESS_STATUS = "FAX_SUCCESS";
$FROM_EMA") in new stack
#!/usr/bin/php
<?php

// set some global variables here
$SUCCESS_STATUS = FAX_SUCCESS;
$FROM_EMA
    -- Executing [11 at outb2:6] TrySystem("SIP/616818xxxx-000002f6",
"/var/lib/asterisk/bin/faxnotify.php") in new stack
    -- Executing [11 at outb2:7] Verbose("SIP/616818xxxx-000002f6", "SUCCESS")
in new stack
SUCCESS
    -- Executing [11 at outb2:8] Hangup("SIP/616818xxxx-000002f6", "") in new
stack
  == Spawn extension (outb2, 11, 8) exited non-zero on
'SIP/616818xxxx-000002f6'

If I execute from the command line as user asterisk the script works
correctly. If i execute extension 777 test.php is called and works
correctly. The only thing I wonder is if asterisk is somehow not correctly
passing the variables to faxnotify.php causing it to fail. Can someone
please test this configuration on their system and let me know if they see
what I am doing wrong?

This works as user asterisk.
*/var/lib/asterisk/bin/faxnotify.php NOTIFY "tim.compnetwork at gmail.com"
"6165550000" "24/08/11 : 09:00:00" "FAX_SUCCESS" "1"*
*
Here are the permissions of the folder.
*drwxr-xr-x  2 asterisk asterisk 4.0K Aug 24 13:19 .
drwxr-xr-x 13 asterisk asterisk 4.0K Aug 22 12:38 ..
-rwxrwxrwx  1 asterisk asterisk 2.5K Aug 24 11:43 faxnotify.php
-rwxr-xr-x  1 asterisk asterisk 6.4K Aug 20 10:26 fax-process.pl
-rwxrwxrwx  1 asterisk asterisk   73 Aug 24 12:52 test.php
-rwxrwxrwx  1 asterisk asterisk   60 Aug 24 11:40 test.sh
*
[outbound]*
exten => 11,1,Verbose(Testing....)
exten => 11,n,Set(FNAME=/var/lib/asterisk/bin/faxnotify.php)
exten => 11,n,Verbose(Size: ${STAT(s,${FNAME})})
exten => 11,n,Verbose(Mode: ${STAT(m,${FNAME})})
exten => 11,n,Verbose(${FILE(${FNAME},,100)})
exten => 11,n,TrySystem(${FNAME})
exten => 11,n,Verbose(${SYSTEMSTATUS})
exten => 11,n,Hangup()

exten => 777,1,System(/var/lib/asterisk/bin/test.php)
exten => 777,n,Playback(vm-goodbye)
exten => 777,n,Hangup()

*[ext-fax]*
exten => s,1,Noop(Receiving Fax for: ${FAX_RX_EMAIL} , From:
${CALLERID(all)})
exten => s,n(receivefax),StopPlaytones
exten => s,n,ReceiveFAX(${ASTSPOOLDIR}/fax/${UNIQUEID}.tif,f)
exten => s,n,ExecIf($["${FAXOPT(error)}"=""]?Set(FAXSTATUS=FAILED LICENSE
EXCEEDED))
exten => s,n,ExecIf($["${FAXOPT(error)}"!="" &&
"${FAXOPT(error)}"!="NO_ERROR"]?Set(FAXSTATUS="FAILED FAXOPT: error:
${FAXOPT(error)} status: ${FAXOPT(status)} statusstr: ${FAX
exten => s,n,Hangup
exten => h,1,GotoIf($["${FAXSTATUS:0:6}" = "FAILED"]?failed)
exten => h,n(process),GotoIf($[${LEN(${FAX_RX_EMAIL})} = 0]?end)
exten => h,n,System(${ASTVARLIBDIR}/bin/fax-process.pl --to
"${FAX_RX_EMAIL}" --from "noreply at mydomain.com" --dest "${FROM_DID}"
--subject "New fax from ${URIENCODE(${CALLERI
exten => h,n(end),Macro(hangupcall,)
exten => h,process+101(failed),Noop(FAX ${FAXSTATUS} for: ${FAX_RX_EMAIL} ,
From: ${CALLERID(all)})
exten => h,n,Macro(hangupcall,)

*[app-fax]*
include => app-fax-custom
exten => 6169804602,1,Set(FAX_RX_EMAIL=tim.compnetwork at gmail.com)
exten => 6169804602,n,Goto(ext-fax,s,1)
exten => h,1,Macro(hangupcall,)


*test.php*

<?php
exec("touch /var/lib/asterisk/bin/testfile.txt");

*faxnotify.php*

#!/usr/bin/php
<?php

// set some global variables here
$SUCCESS_STATUS = "FAX_SUCCESS";
$FROM_EMAIL = "fax at mydomain.com";
$FROM_NAME = "mydomain Fax";
$CONTACT_EMAIL = "support at mydomain.com";

if ($argc != 7) {
 echo "Usage faxnotify.php messagetype email destination timestamp
status_string pages \n ";
 echo "message type can be one of INIT or NOTIFY ";
}
echo "Starting faxnotify.php \n";


// setting up
$messtype   = $argv[1];
$email      = $argv[2];
$dest       = $argv[3];
$timestamp  = $argv[4];
$status     = $argv[5];
$numpages   = $argv[6];

$headers = "From:  $FROM_NAME <$FROM_EMAIL>";

// end setting up

if ($messtype == "INIT") { // SendFAX called successfully in the dialplan...
        $emailSubject = "Your fax to $dest has been initiated";
        $notice = "Your fax to $dest sent on $timestamp has been initiated.
You will get a notification " .
                          "email when the transmission is complete. ";
    $emailBody = "Hi!  \n\n" .  $notice . " \n\n " .
                                 "If you have any queries, please contact us
at:  $CONTACT_EMAIL";
        mail($email, $emailSubject, $emailBody, $headers);
}
else {  // meaning $messtype = "NOTIFY" ... sending of fax is complete. Need
to check if SUCCEEDED
        $tech_details = "------------------------------ \n".
                        "DESTINATION = $dest            \n".
                                        "TIMESTAMP = $timestamp         \n".
                                        "FAXOPTS_STATUSSTRING = $status \n".
                                        "NUM_PAGES = $numpages          \n".
                                        "------------------------------ \n";


        echo "Sending fax notification email to: $email from $FROM_EMAIL
\n";

        if($status == $SUCCESS_STATUS) {
          $emailSubject = "Your fax to $dest was delivered successfully";
          $notice = "This is an automated response to let you know that your
fax to " .
                                "$dest sent on $timestamp was delivered
successfully. \n";
        } else {
          $emailSubject = "Your fax to $dest could not be sent";
          $notice = "This is an automated response to let you know that your
fax to " .
                                "$dest sent on $timestamp could not be
delivered. \n";
        }

        $emailBody = "Hi!  \n\n" .  $notice . "\n\n" . $tech_details . "
\n\n " .
                                 "If you beleive there was an error please
contact:  $CONTACT_EMAIL";

        // echo $emailSubject . "\n";
        // echo $emailBody . "\n";

        // mail
        mail($email, $emailSubject, $emailBody, $headers );
        // exec("echo $email $timestamp $emailSubject >>
/var/log/asterisk/webfax.log");
        // exec("echo $emailBody >> /var/log/asterisk/webfax.log");
        // exec("echo -------------------------------- >>
/var/log/asterisk/webfax.log");
}
?>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20110824/54d360a6/attachment.htm>


More information about the asterisk-users mailing list