-
Notifications
You must be signed in to change notification settings - Fork 1
/
sendfaxnotify.php
84 lines (70 loc) · 2.73 KB
/
sendfaxnotify.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/php
<?php
/**
* @file
* Pierre Bastoul (@hiousi)
* freepbx ARI module to send a fax uploaded from web
* http://code.google.com/p/webfax-ari-module
* require digium's FFA
*
* $Rev:: $:
* $Author:: $:
* $Date:: $:
*
*
*/
// set some global variables here
$SUCCESS_STATUS = "FAX_SUCCESS";
$FROM_EMAIL = "[email protected]";
$FROM_NAME = "fax";
$CONTACT_EMAIL = "[email protected]";
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 have any queries, please contact us at: $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");
}
?>