Esempio n. 1
0
function create_application($name, $tenant_id)
{
    $ci =& get_instance();
    $ci->load->model('vbx_settings');
    $app_name = "OpenVBX :: {$name}";
    $twilio_sid = $ci->vbx_settings->get('twilio_sid', $tenant_id);
    $twilio_token = $ci->vbx_settings->get('twilio_token', $tenant_id);
    // Rare event, sid and/or token may be empty
    if (!empty($twilio_sid) && !empty($twilio_token)) {
        error_log('Processing tenant: ' . $tenant_id);
        $account = OpenVBX::getAccount($twilio_sid, $twilio_token);
        $applications = $account->applications->getIterator(0, 1, array('FriendlyName' => $app_name));
        $application = false;
        foreach ($applications as $_application) {
            if ($_application->friendly_name == $app_name) {
                $application = $_application;
            }
        }
        $params = array('FriendlyName' => $app_name, 'VoiceUrl' => tenant_url('twiml/dial', $tenant_id), 'VoiceFallbackUrl' => asset_url('fallback/voice.php'), 'VoiceMethod' => 'POST', 'SmsUrl' => '', 'SmsFallbackUrl' => '', 'SmsMethod' => 'POST');
        if (!empty($application)) {
            error_log('Modifying app: ' . $app_name);
            $application->update($params);
        } else {
            error_log('Creating app: ' . $app_name);
            $application = $account->applications->create($app_name, $params);
        }
        error_log('Created/Updated app for tenant id: ' . $tenant_id . ' - Application Sid: ' . $application->sid);
        $ci->vbx_settings->add('application_sid', $application->sid, $tenant_id);
    } else {
        error_log('Skipped app creation for tenant "' . $tenant_id . '" - incomplete account Sid/Token pair.');
    }
}
Esempio n. 2
0
 private function input_args()
 {
     $tplvars = array();
     $tplvars['pass'] = true;
     $this->database['username'] = trim($this->input->post('database_user'));
     $this->database['password'] = $this->input->post('database_password');
     $this->database['hostname'] = trim($this->input->post('database_host') == "" ? 'localhost' : $this->input->post('database_host'));
     $this->database['database'] = trim($this->input->post('database_name') == "" ? 'OpenVBX' : $this->input->post('database_name'));
     $this->openvbx_settings = array();
     $this->openvbx = array();
     $this->openvbx_settings['twilio_sid'] = trim($this->input->post('twilio_sid'));
     $this->openvbx_settings['twilio_token'] = trim($this->input->post('twilio_token'));
     $this->openvbx['salt'] = md5(rand(10000, 99999));
     $this->openvbx_settings['from_email'] = trim($this->input->post('from_email') == "" ? '' : $this->input->post('from_email'));
     $this->openvbx_settings['theme'] = $this->input->post('theme');
     $this->openvbx_settings['iphone_theme'] = '';
     $this->openvbx_settings['trial_number'] = '(415) 599-2671';
     $this->openvbx_settings['schema-version'] = OpenVBX::getLatestSchemaVersion();
     $this->openvbx_settings['rewrite_enabled'] = !strlen($this->input->post('rewrite_enabled')) ? 0 : $this->input->post('rewrite_enabled');
     $this->user = array();
     $this->user['email'] = trim($this->input->post('admin_email'));
     $this->user['password'] = $this->input->post('admin_pw');
     $this->user['firstname'] = trim($this->input->post('admin_firstname'));
     $this->user['lastname'] = trim($this->input->post('admin_lastname'));
     $this->user['tenant_id'] = 1;
     $tplvars = array_merge($tplvars, $this->user, $this->database, $this->openvbx, $this->openvbx_settings);
     return $tplvars;
 }
Esempio n. 3
0
 public function index()
 {
     $args = func_get_args();
     $page = implode('/', $args);
     $this->section = '/p/' . $page;
     $data = $this->init_view_data();
     $title = '';
     /* Find Plugin matching page */
     $plugins = Plugin::all();
     foreach ($plugins as $plugin) {
         try {
             // First plugin wins
             $data['script'] = $plugin->getScript($page);
             if (!empty($data['script'])) {
                 PluginData::setPluginId($plugin->getPluginId());
                 OpenVBX::$currentPlugin = $plugin;
                 $plugin_info = $plugin->getInfo();
                 $page_title = $plugin->getPluginPageName($page);
                 $title = !empty($page_title) ? $page_title : $plugin_info['name'];
                 break;
             }
         } catch (PluginException $e) {
             error_log($e->getMessage());
             $ci =& get_instance();
             $ci->session->set_flashdata('error', $e->getMessage());
         }
     }
     $this->respond($title, 'page/index', $data);
 }
Esempio n. 4
0
 private function get_greeting()
 {
     $user = OpenVBX::getCurrentUser();
     $voicemail_value = $user->voicemail;
     $json['mode'] = '';
     $json['play'] = '';
     $json['say'] = '';
     if (!empty($voicemail_value)) {
         if (preg_match('/^http/i', $voicemail_value) || preg_match('/^vbx-audio-upload/i', $voicemail_value)) {
             $json['mode'] = 'play';
             $json['play'] = $voicemail_value;
             if (preg_match('/^vbx-audio-upload:\\/\\/(.*)/i', $voicemail_value, $matches)) {
                 // This is a locally hosted file, and we need to return the correct
                 // absolute URL for the file.
                 $json['play'] = real_site_url("audio-uploads/" . $matches[1]);
             }
         } else {
             $json['mode'] = 'say';
             $json['say'] = $voicemail_value;
         }
     }
     $data['json'] = $json;
     if ($this->response_type != 'json') {
         return redirect('voicemail');
     }
     $this->respond('', 'voicemail/greeting', $data);
 }
Esempio n. 5
0
 private function login($redirect)
 {
     try {
         $user = VBX_User::authenticate($this->input->post('email'), $this->input->post('pw'), $this->input->post('captcha'), $this->input->post('captcha_token'));
         if ($user) {
             $connect_auth = OpenVBX::connectAuthTenant($user->tenant_id);
             // we kick out non-admins, admins will have an opportunity to re-auth the account
             if (!$connect_auth && !$user->is_admin) {
                 $this->session->set_flashdata('error', 'Connect auth denied');
                 return redirect('auth/connect/account_deauthorized');
             }
             $userdata = array('email' => $user->email, 'user_id' => $user->id, 'is_admin' => $user->is_admin, 'loggedin' => TRUE, 'signature' => VBX_User::signature($user->id));
             $this->session->set_userdata($userdata);
             if (OpenVBX::schemaVersion() >= 24) {
                 return $this->after_login_completed($user, $redirect);
             }
             return $this->redirect($redirect);
         }
         $this->session->set_flashdata('error', 'Email address and/or password is incorrect');
         return redirect('auth/login?redirect=' . urlencode($redirect));
     } catch (GoogleCaptchaChallengeException $e) {
         $this->session->set_flashdata('error', $e->getMessage());
         $data['error'] = $e->getMessage();
         $data['captcha_url'] = $e->captcha_url;
         $data['captcha_token'] = $e->captcha_token;
     }
 }
Esempio n. 6
0
/**
 * Update each tenant to sub-account status
 * Pull full list of sub-accounts to make sure that accounts being upgraded are sub-accounts
 * Any account found to not be a sub-account of tenant 1 is assumed to be a full account
 * 
 * @return void
 */
function runUpdate_55_update_tenant_type_status()
{
    $ci =& get_instance();
    $parent_account_sid = $ci->vbx_settings->get('twilio_sid', 1);
    $parent_account_token = $ci->vbx_settings->get('twilio_token', 1);
    $parent_account = OpenVBX::getAccount($parent_account_sid, $parent_account_token);
    $subaccount_sids = array();
    foreach ($parent_account->accounts as $account) {
        array_push($subaccount_sids, $account->sid);
    }
    $tenants = $ci->db->from('tenants')->where('id >', '1')->get()->result();
    if (!empty($tenants)) {
        foreach ($tenants as $tenant) {
            $tenant_sid = $ci->vbx_settings->get('twilio_sid', $tenant->id);
            $tenant_token = $ci->vbx_settings->get('twilio_token', $tenant->id);
            if (in_array($tenant_sid, $subaccount_sids)) {
                // tenant is a sub-account of the parent
                $type = 2;
            } else {
                // tenant is a regular account, not a sub-account
                // may still be a sub of someone else, but not of this parent
                $type = 1;
            }
            $ci->db->set('type', $type)->where('id', $tenant->id)->update('tenants');
        }
    }
}
Esempio n. 7
0
 private function get_updates()
 {
     if ($this->session->userdata('loggedin') != 1 || $this->session->userdata('is_admin') != 1) {
         $data['json'] = array('message' => 'Unable to fetch updates', 'error' => true);
         return $this->respond('', '', $data);
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, 'http://openvbx.org/updates/latest.json');
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $resp = curl_exec($ch);
     if (!$resp) {
         /* Its okay we can't connect to the update system but log it */
         error_log('Unable to connect to OpenVBX Update notification server');
     }
     $data['json'] = array('message' => 'Unable to fetch updates', 'error' => true);
     if ($obj = json_decode($resp)) {
         $data['json']['upgradeAvailable'] = false;
         list($current['major'], $current['minor']) = explode('.', OpenVBX::version());
         list($latest['major'], $latest['minor']) = explode('.', $obj->version);
         if ($latest['major'] > $current['major'] || $latest['major'] == $current['major'] && $latest['minor'] > $current['minor']) {
             $data['json'] = array('error' => false);
             $data['json']['upgradeAvailable'] = true;
         }
     }
     $this->respond('', '', $data);
 }
 public function getFlows()
 {
     $flows = array();
     foreach (OpenVBX::getFlows() as $flow) {
         $flows[$flow->values['id']] = $flow->values['name'];
     }
     return $flows;
 }
Esempio n. 9
0
 public function setup()
 {
     $json['success'] = true;
     $json['message'] = '';
     try {
         $currentSchemaVersion = OpenVBX::schemaVersion();
         $upgradingToSchemaVersion = OpenVBX::getLatestSchemaVersion();
         $upgradeScriptPath = VBX_ROOT . '/updates/';
         $updates = scandir($upgradeScriptPath);
         $updatesToRun = array();
         // Collect all files named numerically in /updates and key sort the list of updates
         foreach ($updates as $i => $update) {
             if (preg_match('/^(\\d+).(sql|php)$/', $update, $matches)) {
                 $updateExtension = $matches[2];
                 $rev = $matches[1];
                 $updatesToRun[$rev] = array('type' => $updateExtension, 'filename' => $update, 'revision' => $rev);
             }
         }
         ksort($updatesToRun);
         // Cut the updates by the current schema version.
         $updatesToRun = array_slice($updatesToRun, $currentSchemaVersion);
         $tplvars = array('originalVersion' => $currentSchemaVersion, 'version' => $upgradingToSchemaVersion, 'updates' => $updatesToRun);
         foreach ($updatesToRun as $updateToRun) {
             $file = $updateToRun['filename'];
             $type = $updateToRun['type'];
             $revision = $updateToRun['revision'];
             switch ($type) {
                 case 'php':
                     require_once $upgradeScriptPath . $file;
                     $runUpdateMethod = "runUpdate_{$revision}";
                     if (!function_exists($runUpdateMethod)) {
                         throw new UpgradeException('runUpdate method missing from ' . $file . ': ' . $runUpdateMethod);
                     }
                     call_user_func($runUpdateMethod);
                     break;
                 case 'sql':
                     $sql = @file_get_contents($upgradeScriptPath . $file);
                     if (empty($sql)) {
                         throw new UpgradeException("Unable to read update: {$file}", 1);
                     }
                     foreach (explode(";", $sql) as $stmt) {
                         $stmt = trim($stmt);
                         if (!empty($stmt)) {
                             PluginData::sqlQuery($stmt);
                         }
                     }
                     break;
             }
         }
         flush_minify_caches();
     } catch (Exception $e) {
         $json['success'] = false;
         $json['message'] = $e->getMessage();
         $json['step'] = $e->getCode();
     }
     $json['tplvars'] = $tplvars;
     echo json_encode($json);
 }
Esempio n. 10
0
 /**
  * Validate that an incoming rest request is from Twilio
  *
  * @param string $failure_message
  * @return void
  */
 function validate_rest_request($failure_message = 'Could not validate this request. Goodbye.')
 {
     $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;
     }
 }
Esempio n. 11
0
 function send_message($from, $to, $message)
 {
     $from = PhoneNumber::normalizePhoneNumberToE164($from);
     $to = PhoneNumber::normalizePhoneNumberToE164($to);
     try {
         $account = OpenVBX::getAccount();
         $response = $account->messages->sendMessage($from, $to, $message);
     } catch (Exception $e) {
         throw new VBX_Sms_messageException($e->getMessage());
     }
     if (!in_array($response->status, array('sent', 'queued'))) {
         throw new VBX_Sms_messageException('SMS delivery failed. An unknown error occurred' . ' during delivery.');
     }
 }
Esempio n. 12
0
 function getAccountType()
 {
     $ci =& get_instance();
     if ($cache = $ci->api_cache->get('account-type', __CLASS__, $ci->tenant->id)) {
         return $cache;
     }
     try {
         $account = OpenVBX::getAccount();
         $account_type = $account->type;
     } catch (Exception $e) {
         throw new VBX_AccountsException($e->getMessage());
     }
     $ci->api_cache->set('account-type', $account_type, __CLASS__, $ci->tenant->id);
     return $account_type;
 }
Esempio n. 13
0
/**
 * @param string $recipient
 * @param string $subject
 * @param string $template
 * @param array $maildata
 * @return bool
 */
function openvbx_mail($recipient, $subject, $template, $maildata = array())
{
    $ci =& get_instance();
    $from_email = $ci->settings->get('from_email', $ci->tenant->id);
    if (empty($from_email)) {
        $domain = $ci->config->item('server_name');
        $from_email = "{$from} <do-not-reply@{$domain}>";
    }
    $headers = 'From: ' . $from_email . "\r\n";
    $headers .= 'Reply-To: ' . $from_email . "\r\n";
    $headers .= 'Return-Path: ' . $from_email . "\r\n";
    $headers .= 'User-Agent: OpenVBX-' . OpenVBX::version();
    $message = $ci->load->view('emails/' . $template, $maildata, true);
    log_message('debug', 'MAILING -- to: ' . $recipient . ' -- body: ' . $message);
    return mail($recipient, '[OpenVBX] ' . $subject, $message, $headers);
}
Esempio n. 14
0
 public function index($plugin)
 {
     $this->admin_only('plugin config');
     $data = $this->init_view_data();
     $plugin = Plugin::get($plugin);
     PluginData::setPluginId($plugin->getPluginId());
     OpenVBX::$currentPlugin = $plugin;
     try {
         $data['info'] = $plugin->getInfo();
         $data['script'] = $plugin->getScript('config');
     } catch (PluginException $e) {
         error_log($e->getMessage());
         $data['script'] = null;
     }
     $this->respond('', 'page/config', $data);
 }
 public function getMatches($digits)
 {
     $indexes = array();
     $matches = array();
     $users = OpenVBX::getUsers(array('is_active' => 1));
     foreach ($users as $user) {
         $fname = $user->values['first_name'];
         $lname = $user->values['last_name'];
         $fdigits = $this->stringToDigits($fname);
         $ldigits = $this->stringToDigits($lname);
         if (stristr($fdigits, $digits) || stristr($ldigits, $digits)) {
             $matches[] = $user;
         }
     }
     return $matches;
 }
Esempio n. 16
0
 function getAccountType()
 {
     if (function_exists('apc_fetch')) {
         $success = FALSE;
         $type = apc_fetch($this->cache_key, $success);
         if ($type and $success) {
             return $type;
         }
     }
     try {
         $account = OpenVBX::getAccount();
         $account_type = $account->type;
     } catch (Exception $e) {
         throw new VBX_AccountsException($e->getMessage());
     }
     if (function_exists('apc_store')) {
         $success = apc_store($this->cache_key, $account_type, self::CACHE_TIME_SEC);
     }
     return $account_type;
 }
Esempio n. 17
0
 /**
  * Perform at GET request against the API
  *
  * @throws Exception on HTTP or Json decode error
  * @param string $url 
  * @return array
  */
 public function get($url)
 {
     $getUrl = $this->apiUrl . '/' . ltrim($url, '/');
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $getUrl);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_USERAGENT, OpenVBX::getVbxUserAgentString());
     $response = curl_exec($curl);
     if (!$response) {
         $err = curl_error($curl);
         $errNo = curl_errno($curl);
         throw new Exception('HTTP communication error: ' . $errNo . ', ' . $err);
     }
     curl_close($curl);
     $decoded = json_decode($response, true);
     if ($jsonErr = $this->isJsonError()) {
         throw new Exception('JSON Error: ' . $jsonErr);
     }
     return $decoded;
 }
Esempio n. 18
0
 private function login($redirect)
 {
     try {
         $user = VBX_User::authenticate($this->input->post('email'), $this->input->post('pw'), $this->input->post('captcha'), $this->input->post('captcha_token'));
         if ($user) {
             $userdata = array('email' => $user->email, 'user_id' => $user->id, 'is_admin' => $user->is_admin, 'loggedin' => TRUE, 'signature' => VBX_User::signature($user->id));
             $this->session->set_userdata($userdata);
             if (OpenVBX::schemaVersion() >= 24) {
                 return $this->after_login_completed($user, $redirect);
             }
             return $this->redirect($redirect);
         }
         $this->session->set_flashdata('error', 'Email address and/or password is incorrect');
         return redirect('auth/login?redirect=' . urlencode($redirect));
     } catch (GoogleCaptchaChallengeException $e) {
         $this->session->set_flashdata('error', $e->getMessage());
         $data['error'] = $e->getMessage();
         $data['captcha_url'] = $e->captcha_url;
         $data['captcha_token'] = $e->captcha_token;
     }
 }
Esempio n. 19
0
 public function finish()
 {
     $error = false;
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $app_name = 'OpenVBX :: ' . $this->tenant->url_prefix;
         try {
             $account = OpenVBX::getAccount();
             /** @var Services_Twilio_Rest_Application[] $applications */
             $applications = $account->applications->getIterator(0, 10, array('FriendlyName' => $app_name));
             $application = false;
             foreach ($applications as $_application) {
                 if ($_application->friendly_name == $app_name) {
                     $application = $_application;
                 }
             }
             $params = array('FriendlyName' => $app_name, 'VoiceUrl' => site_url('twiml/dial'), 'VoiceFallbackUrl' => asset_url('fallback/voice.php'), 'VoiceMethod' => 'POST', 'SmsUrl' => '', 'SmsFallbackUrl' => '', 'SmsMethod' => 'POST');
             if ($application) {
                 $application->update($params);
             } else {
                 $application = $account->applications->create($app_name, $params);
             }
             $this->vbx_settings->add('application_sid', $application->sid, $this->tenant->id);
             $this->vbx_settings->delete('tenant_first_run', $this->tenant->id);
         } catch (Exception $e) {
             switch ($e->getCode()) {
                 case '20003':
                     $error = 'Authentication Failed. Invalid Twilio SID or Token (' . $e->getCode() . ')';
                     break;
                 default:
                     $error = $e->getMessage() . ' (' . $e->getCode() . ')';
             }
         }
     }
     if ($error) {
         $data['json'] = array('error' => true, 'message' => $error);
     } else {
         $data['json'] = array('error' => false, 'message' => null);
     }
     $this->respond('', 'welcome', $data);
 }
Esempio n. 20
0
 public function setup()
 {
     $json['success'] = true;
     $json['message'] = '';
     try {
         $currentSchemaVersion = OpenVBX::schemaVersion();
         $upgradingToSchemaVersion = OpenVBX::getLatestSchemaVersion();
         $sqlPath = VBX_ROOT . '/sql-updates/';
         $updates = scandir($sqlPath);
         $files = array();
         foreach ($updates as $i => $update) {
             if (preg_match('/^(\\d+).sql$/', $update)) {
                 $rev = intval(str_replace('.sql', '', $update));
                 $files[$rev] = $update;
             }
         }
         ksort($files);
         $files = array_slice($files, $currentSchemaVersion);
         $tplvars = array('originalVersion' => $currentSchemaVersion, 'version' => $upgradingToSchemaVersion, 'updates' => $files);
         foreach ($files as $file) {
             $sql = @file_get_contents($sqlPath . $file);
             if (empty($sql)) {
                 throw new UpgradeException("Unable to read update: {$file}", 1);
             }
             foreach (explode(";", $sql) as $stmt) {
                 $stmt = trim($stmt);
                 if (!empty($stmt)) {
                     PluginData::sqlQuery($stmt);
                 }
             }
         }
     } catch (Exception $e) {
         $json['success'] = false;
         $json['message'] = $e->getMessage();
         $json['step'] = $e->getCode();
     }
     $json['tplvars'] = $tplvars;
     echo json_encode($json);
 }
Esempio n. 21
0
 public function index($page)
 {
     $this->section = '/p/' . $page;
     $data = $this->init_view_data();
     /* Find Plugin matching page */
     $plugins = Plugin::all();
     foreach ($plugins as $plugin) {
         try {
             // First plugin wins
             $data['script'] = $plugin->getScript($page);
             if (!empty($data['script'])) {
                 PluginData::setPluginId($plugin->getPluginId());
                 OpenVBX::$currentPlugin = $plugin;
                 break;
             }
         } catch (PluginException $e) {
             error_log($e->getMessage());
             $ci =& get_instance();
             $ci->session->set_flashdata('error', $e->getMessage());
         }
     }
     $this->respond('', 'page/index', $data);
 }
Esempio n. 22
0
 /**
  * Twilio calls us when a user deauthorizes our connect account
  *
  * @return void
  */
 public function deauthorize()
 {
     $header = '405';
     // method not allowed
     if (OpenVBX::validateRequest() || 1 == 1) {
         if ($account_sid = $this->input->post('AccountSid')) {
             $result = $this->db->select('tenants.*')->from('tenants')->join('settings', 'tenants.id = settings.tenant_id')->where('settings.name = "twilio_sid"')->where('settings.value = "' . $this->db->escape_str($account_sid) . '"')->limit(1)->get()->result();
             if (!empty($result)) {
                 $tenant = current($result);
                 if ($tenant->id) {
                     log_message('info', 'AccountSid "' . $account_sid . '" deauthorized on ' . date('r') . ' (server tz: ' . date_default_timezone_get() . ')');
                     $this->setup_connect_tenant('deauthorized_client', $tenant->id);
                     $header = '204';
                     // accepted, but no content to return
                 }
             }
             $header = '400';
             // sid not found so its a bad request
         }
     }
     set_status_header($header);
     exit;
 }
Esempio n. 23
0
function runUpdate_45()
{
    set_time_limit(3600);
    $ci =& get_instance();
    $tenants = $ci->db->from('tenants')->get()->result();
    if (count($tenants)) {
        $ci->load->model('vbx_incoming_numbers');
        $numbers = $ci->vbx_incoming_numbers->get_numbers($retrieve_sandbox = true);
        foreach ($tenants as $tenant) {
            error_log("Updating to 2010: " . var_export($tenant, true));
            $twilio_sid = $ci->settings->get('twilio_sid', $tenant->id);
            $twilio_token = $ci->settings->get('twilio_token', $tenant->id);
            if (!empty($twilio_sid) && !empty($twilio_token)) {
                $account = OpenVBX::getAccount($twilio_sid, $twilio_token);
                foreach ($account->incoming_phone_numbers as $number) {
                    $number->update(array('ApiVersion' => '2010-04-01'));
                }
            } else {
                error_log('Skipped number updates for tenant "' . $tenant->id . '" - incomplete account Sid/Token pair.');
            }
        }
    }
    $ci->settings->set('schema-version', '45', 1);
}
Esempio n. 24
0
						</label>
						<?php 
        } else {
            ?>
						<input type="hidden" name="callerid" value="<?php 
            echo $c->phone;
            ?>
" />
						<?php 
        }
        ?>
                    <?php 
    } else {
        ?>
						<?php 
        if (OpenVBX::getTwilioAccountType() == 'Trial') {
            ?>
						<p>You're using a Twilio trial account, please upgrade to dial using a virtual phone number.</p>
						<?php 
        } else {
            ?>
						<p>We were unable to connect to Twilio at this time. This feature is disabled.  Try again later.</p>
						<?php 
        }
        ?>
					<?php 
    }
    ?>
					</fieldset>

					<input name="target" type="hidden" />
$user = OpenVBX::getCurrentUser();
$tenant_id = $user->values['tenant_id'];
if (isset($_POST['id'])) {
    $flows = OpenVBX::getFlows(array('id' => $_POST['id'], 'tenant_id' => $tenant_id));
    $data = $flows[0]->values['data'];
    $sms_data = $flows[0]->values['sms_data'];
    $export = md5($data . $sms_data) . ':' . base64_encode($data) . ':' . base64_encode($sms_data);
    if (isset($_POST['file'])) {
        header('Content-type: text/plain');
        header('Content-Disposition: attachment; filename=' . preg_replace('/\\W/', '', $flows[0]->values['name']) . '.ovbx');
        echo $export;
        die;
    }
}
$flows = OpenVBX::getFlows(array('tenant_id' => $tenant_id));
?>
<style>
	.vbx-export-flow form {
		margin-top: 20px;
	}
	.vbx-export-flow p {
		margin: 10px 0;
		padding: 0 20px;
	}
	.vbx-export-flow h3 {
		font-size: 14px;
		padding: 0 20px;
		margin-top: 20px;
	}
</style>
Esempio n. 26
0
 /**
  * Remove a phone number from the current account
  *
  * @param string $phone_id
  * @return bool
  */
 public function delete_number($phone_id)
 {
     try {
         $account = OpenVBX::getAccount();
         $account->incoming_phone_numbers->delete($phone_id);
     } catch (Exception $e) {
         throw new VBX_IncomingNumberException($e->getMessage());
     }
     $this->clear_cache();
     return TRUE;
 }
<?php

$user = OpenVBX::getCurrentUser();
$tenant_id = $user->values['tenant_id'];
$ci =& get_instance();
$selected = AppletInstance::getValue('list');
$queries = explode(';', file_get_contents(dirname(dirname(dirname(__FILE__))) . '/db.sql'));
foreach ($queries as $query) {
    if (trim($query)) {
        $ci->db->query($query);
    }
}
$lists = $ci->db->query(sprintf('SELECT id, name FROM subscribers_lists WHERE tenant=%d', $tenant_id))->result();
?>
<div class="vbx-applet">
<?php 
if (count($lists)) {
    ?>
	<div class="vbx-full-pane">
		<h3>List</h3>
		<fieldset class="vbx-input-container">
				<select class="medium" name="list">
<?php 
    foreach ($lists as $list) {
        ?>
					<option value="<?php 
        echo $list->id;
        ?>
"<?php 
        echo $list->id == $selected ? ' selected="selected" ' : '';
        ?>
            ?>
","<?php 
            echo date('d-M-Y', $subscriber->joined);
            ?>
"
<?php 
        }
        die;
    }
}
if (!empty($_POST['name'])) {
    $ci->db->insert('subscribers_lists', array('tenant' => $tenant_id, 'name' => htmlentities($_POST['name'])));
}
$lists = $ci->db->query(sprintf('SELECT id, name FROM subscribers_lists WHERE tenant = %d', $tenant_id))->result();
$flows = OpenVBX::getFlows(array('tenant_id' => $tenant_id));
OpenVBX::addJS('subscriptions.js');
?>
<style>
	.vbx-subscriptions h3 {
		font-size: 16px;
		font-weight: bold;
		margin-top: 0;
	}
	.vbx-subscriptions .list,
	.vbx-subscriptions .subscriber {
		clear: both;	
		width: 95%;
		overflow: hidden;
		margin: 0 auto;
		padding: 5px 0;
		border-bottom: 1px solid #eee;
Esempio n. 29
0
            } else {
                if ($no_answer_action === 'voicemail') {
                    $response->append(AudioSpeechPickerWidget::getVerbForValue($voicemail, new Say("Please leave a message.")));
                    $response->addRecord(array('transcribe' => true, 'transcribeCallback' => site_url('twiml/transcribe')));
                    $state[DIAL_ACTION] = DIAL_STATE_RECORDING;
                } else {
                    if ($no_answer_action === 'redirect') {
                        if (empty($no_answer_redirect)) {
                            $response->addHangup();
                        }
                        $response->addRedirect($no_answer_redirect);
                    } else {
                        if ($no_answer_action === 'hangup') {
                            $response->addHangup();
                        } else {
                            trigger_error("Unexpected no_answer_action");
                        }
                    }
                }
            }
            break;
        case DIAL_STATE_RECORDING:
            if (isset($_REQUEST['testing'])) {
                break;
            }
            OpenVBX::addVoiceMessage($dial_whom_user_or_group, $_REQUEST['CallGuid'], $_REQUEST['Caller'], $_REQUEST['Called'], $_REQUEST['RecordingUrl'], $_REQUEST['Duration']);
            break;
    }
}
setcookie(DIAL_COOKIE, json_encode($state), time() + 5 * 60);
$response->Respond();
Esempio n. 30
0
 public function twiml($flow, $baseURI, $instance = null)
 {
     $path = $this->applet_dir . '/twiml.php';
     if (!is_null($instance)) {
         AppletInstance::setInstance($instance);
         AppletInstance::setFlow($flow);
         AppletInstance::setBaseURI($baseURI);
         FlowStore::setFlowId($flow->id);
         // Plugin directory name is the natural key until a proper guid system is developed
         $plugin = new Plugin($this->plugin_dir_name);
         PluginData::setPluginId($plugin->getPluginId());
         OpenVBX::$currentPlugin = $plugin;
         $instance = isset($instance->data) && is_array($instance->data) ? $instance->data : array();
     } else {
         $instance = isset($this->data) && is_array($this->data) ? $this->data : array();
     }
     AppletInstance::setFlowType($this->flow_type);
     if (!file_exists($path)) {
         return '';
     }
     $output = '<?xml version="1.0" ?><Response />';
     ob_start();
     require_once APPPATH . 'libraries/twilio.php';
     // require once was hampering our ability to run an applet multiple times (ie: in integration tests)
     require $path;
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }