-
Notifications
You must be signed in to change notification settings - Fork 0
/
incoming.php
54 lines (49 loc) · 1.53 KB
/
incoming.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
<?php
// Setup Twilio
//require_once "vendor/autoload.php";
require __DIR__ . '/twilio-php-master/Twilio/autoload.php';
use Twilio\TwiML\VoiceResponse;
use Twilio\Security\RequestValidator;
function getDigits(){
$response = new VoiceResponse();
#invoke the other script triggering the api call to Invoice Ninja
$gather = $response->gather(['action' => '/process_gather.php','method' => 'GET']);
$gather->say('Please enter your account number followed by the pound sign');
$response->say('We didn\'t receive any input. Goodbye!');
echo $response;
}
$authenticate = false;
#Detect Http1.0 Authentication and present a username and password
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']))
{
$name = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
if ($name == '' && $pass == '')
{
$authenticate = true;
}
}
if ($authenticate==false)
{
header('WWW-Authenticate: Basic realm="Restricted Page Enter Details To Continue"');
header('HTTP/1.0 401 Unauthorized');
echo "Authentication Failed, Try Again";
}
else{
//Setup the token and authorization from Twilio
$token = "";
$signature = $_SERVER["HTTP_X_TWILIO_SIGNATURE"];
$validator = new RequestValidator($token);
$url = $_SERVER['REQUEST_URI'];
#domain where the twilio code is located
$domain = "";
$url = $domain.$url;
$postVars = $_POST;
// Initialize the validator
if ($validator->validate($signature, $url, $postVars)) {
getDigits();
} else {
echo "Request Invalid";
}
}
?>