Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Added many features and fixes #376

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions OpenVBX/controllers/audiofiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,17 @@ function add_from_twilio_recording()

function prompt_for_recording_twiml()
{
validate_rest_request();

if(!validate_rest_request()) {
$response = new TwimlResponse;
$response->say('Could not validate this request. Goodbye.', array(
'voice' => $ci->vbx_settings->get('voice', $ci->tenant->id),
'language' => $ci->vbx_settings->get('voice_language', $ci->tenant->id)
));
$response->hangup();
$response->respond();
exit;
}

$response = new TwimlResponse;
$audioFile = VBX_Audio_File::get(array('recording_call_sid' => $this->input->get_post('CallSid')));

Expand All @@ -266,8 +275,17 @@ function prompt_for_recording_twiml()

function replay_recording_twiml()
{
validate_rest_request();

if(!validate_rest_request()) {
$response = new TwimlResponse;
$response->say('Could not validate this request. Goodbye.', array(
'voice' => $ci->vbx_settings->get('voice', $ci->tenant->id),
'language' => $ci->vbx_settings->get('voice_language', $ci->tenant->id)
));
$response->hangup();
$response->respond();
exit;
}

$response = new TwimlResponse;

if ($this->input->get_post('RecordingUrl'))
Expand All @@ -294,8 +312,17 @@ function replay_recording_twiml()

function accept_or_reject_recording_twiml()
{
validate_rest_request();

if(!validate_rest_request()) {
$response = new TwimlResponse;
$response->say('Could not validate this request. Goodbye.', array(
'voice' => $ci->vbx_settings->get('voice', $ci->tenant->id),
'language' => $ci->vbx_settings->get('voice_language', $ci->tenant->id)
));
$response->hangup();
$response->respond();
exit;
}

$response = new TwimlResponse;
$digits = clean_digits($this->input->get_post('Digits'));
$call_sid = $this->input->get_post('CallSid');
Expand Down
2 changes: 1 addition & 1 deletion OpenVBX/controllers/numbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,4 @@ public function refresh_select() {

$this->respond('', 'dialer/numbers', $response);
}
}
}
20 changes: 17 additions & 3 deletions OpenVBX/controllers/twiml.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ function index()

function start_sms($flow_id)
{
validate_rest_request();
if(!validate_rest_request()) {
$response = new TwimlResponse;
$response->message('Could not validate this request. Goodbye.');
$response->respond();
exit;
}

log_message("info", "Calling SMS Flow $flow_id");
$body = $this->input->get_post('Body');
Expand Down Expand Up @@ -104,8 +109,17 @@ function start_sms($flow_id)

function start_voice($flow_id)
{
validate_rest_request();

if(!validate_rest_request()) {
$response = new TwimlResponse;
$response->say('Could not validate this request. Goodbye.', array(
'voice' => $ci->vbx_settings->get('voice', $ci->tenant->id),
'language' => $ci->vbx_settings->get('voice_language', $ci->tenant->id)
));
$response->hangup();
$response->respond();
exit;
}

log_message("info", "Calling Voice Flow $flow_id");
$this->flow_type = 'voice';

Expand Down
67 changes: 67 additions & 0 deletions OpenVBX/helpers/token_helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
$ci = &get_instance();

$ci->load->helper('format_helper');

function token_replace($input, $reset = false) {
static $tokens = null;

if(!isset($tokens) || $reset){
$tokens = array();
$token_names = token_names();
foreach ($token_names as $token) {
if(isset($_REQUEST[$token])) {
$tokens['{' . $token . '}'] = $_REQUEST[$token];
switch ($token) {
case 'To':
case 'From':
$tokens['{' . $token . '_Formatted}'] = format_phone($_REQUEST[$token]);
break;
default:
}
}
}
}

return strtr($input, $tokens);
}

function token_list() {
$token_list = '';
foreach(token_names() as $token){
$token_list .= "<li>{{$token}}</li>";
}
return "<ul>$token_list</ul>";
}

function token_names(){
return array(
'CallSid',
'AccountSid',
'From',
'To',
'CallStatus',
'ApiVersion',
'Direction',
'ForwardedFrom',
'CallerName',
'FromCity',
'FromState',
'FromZip',
'FromCountry',
'ToCity',
'ToState',
'ToZip',
'ToCountry',
'DialCallStatus',
'DialCallSid',
'DialCallDuration',
'RecordingUrl',

'MessageSid',
'Body',
'NumMedia',
'MediaContentType1',
'MediaUrl1',
);
}
16 changes: 3 additions & 13 deletions OpenVBX/helpers/twilio_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,13 @@ function generate_capability_token($allow_incoming = true) {
* @param string $failure_message
* @return void
*/
function validate_rest_request($failure_message = 'Could not validate this request. Goodbye.') {
function validate_rest_request() {
$ci =& get_instance();
if ($ci->tenant->type == VBX_Settings::AUTH_TYPE_CONNECT)
{
return;
}

if (!OpenVBX::validateRequest()) {
$response = new TwimlResponse;
$response->say($failure_message, array(
'voice' => $ci->vbx_settings->get('voice', $ci->tenant->id),
'language' => $ci->vbx_settings->get('voice_language', $ci->tenant->id)
));
$response->hangup();
$response->respond();
exit;
return true;
}
return OpenVBX::validateRequest();
}
}

Expand Down
9 changes: 9 additions & 0 deletions OpenVBX/libraries/User_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function __construct()
$this->load->model('vbx_rest_access');
$this->load->model('vbx_message');
$this->load->model('vbx_incoming_numbers');
$this->load->model('vbx_outgoing_caller_ids');
$this->load->model('vbx_device');

// When we're in testing mode, allow access to set Hiccup configuration
Expand Down Expand Up @@ -373,13 +374,21 @@ protected function get_twilio_numbers()
{
/* Retrieve twilio numbers w/o sandbox */
$numbers = $this->vbx_incoming_numbers->get_numbers();
$callerIds = $this->vbx_outgoing_caller_ids->get_caller_ids();
$numbers = array_merge($numbers, $callerIds);
}
catch(VBX_IncomingNumberException $e)
{
error_log($e->getMessage());
throw new User_ControllerException($e->getMessage());
/* Silent fail */
}
catch (VBX_OutgoingCallerIdException $e)
{
error_log($e->getMessage());
throw new User_ControllerException($e->getMessage());
/* Silent fail */
}

return $numbers;
}
Expand Down
88 changes: 88 additions & 0 deletions OpenVBX/models/vbx_outgoing_caller_ids.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* "The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/

* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.

* The Original Code is OpenVBX, released June 15, 2010.

* The Initial Developer of the Original Code is Twilio Inc.
* Portions created by Twilio Inc. are Copyright (C) 2010.
* All Rights Reserved.

* Contributor(s):
**/

require_once(APPPATH . 'libraries/twilio.php');

class VBX_OutgoingCallerIdException extends Exception {}

class VBX_Outgoing_caller_ids extends Model
{
public function __construct()
{
parent::__construct();
}

public function get_caller_ids()
{
$ci =& get_instance();
$cache_key = 'outgoing-caller-ids';
if ($cache = $ci->api_cache->get($cache_key, __CLASS__, $ci->tenant->id))
{
return $cache;
}

$caller_ids = array();
try {
$account = OpenVBX::getAccount();
foreach ($account->outgoing_caller_ids as $caller_id)
{
// check that caller_id is a proper instance type
$caller_ids[] = $this->parseOutgoingCallerId($caller_id);
}
}
catch (Exception $e) {
$msg = 'Unable to fetch Numbers: ';
switch ($e->getCode())
{
case 20003:
$msg .= 'Authentication Failed.';
break;
default:
$msg .= $e->getMessage();
}
throw new VBX_OutgoingCallerIdException($msg, $e->getCode());
}

$ci->api_cache->set('outgoing-caller-ids', $caller_ids, __CLASS__, $ci->tenant->id);

return $caller_ids;
}

private function parseOutgoingCallerId($item)
{
$num = new stdClass();
$num->id = $item->sid;
$num->name = $item->friendly_name;
$num->phone = format_phone($item->phone_number);
$num->phone_number = $item->phone_number;
$num->capabilities = new stdClass();
$num->capabilities->voice = true;
$num->capabilities->sms = false;

return $num;
}

protected function clear_cache()
{
$ci =& get_instance();
$ci->api_cache->invalidate(__CLASS__, $ci->tenant->id);
}
}
2 changes: 1 addition & 1 deletion assets/c/applet.css
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@
.radio-table .radio-table-row.on .content-cell { background-color: #e5f6ff; }
.radio-table .radio-table-row.off .content-cell { background-color: #eee; }

.radio-table .radio-table-row.fist .content-cell {
.radio-table .radio-table-row.first .content-cell {
-moz-border-radius-topright: 4px; /* FF1+ */
-webkit-border-top-right-radius: 4px; /* Saf3+, Chrome */
-khtml-border-top-right-radius: 4px; /* Konqueror */
Expand Down
10 changes: 10 additions & 0 deletions plugins/sms/applets/sms/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$(document).ready(function(){
var app = $('.flow-instance.standard---sms');

$('.radio-table .radio-cell input', app).live('click', function(event) {
var table = $(event.target).closest('.radio-table');
var table_row = $(event.target).closest('.radio-table-row');
$('.radio-table-row', table).removeClass('on').addClass('off');
table_row.removeClass('off').addClass('on');
});
});
Loading