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.'); } }
function create_application($name, $tenant_id) { $ci =& get_instance(); $ci->load->model('vbx_settings'); $appName = "OpenVBX :: {$name}"; $twilio_sid = $ci->vbx_settings->get('twilio_sid', $tenant_id); $twilio_token = $ci->vbx_settings->get('twilio_token', $tenant_id); $twilio = new TwilioRestClient($twilio_sid, $twilio_token, 'https://api.twilio.com/2010-04-01'); $response = $twilio->request("Accounts/{$twilio_sid}/Applications", 'GET', array('FriendlyName' => $appName)); if ($response->IsError) { if ($response->HttpStatus > 400) { throw new Exception($response->ErrorMessage); } } // If we found an existing application, update the urls. $foundApp = intval($response->ResponseXml->Applications['total']); if ($foundApp) { $appSid = (string) $response->ResponseXml->Applications->Application->Sid; $response = $twilio->request("Accounts/{$twilio_sid}/Applications/{$appSid}", 'POST', array('FriendlyName' => $appName, 'VoiceUrl' => tenant_url('twiml/dial', $tenant_id), 'VoiceFallbackUrl' => asset_url('fallback/voice.php'), 'VoiceMethod' => 'POST', 'SmsUrl' => '', 'SmsFallbackUrl' => '', 'SmsMethod' => 'POST')); if ($response->IsError) { if ($response->HttpStatus > 400) { throw new Exception($response->ErrorMessage); } } // Otherwise, lets create a new application for openvbx } else { $response = $twilio->request("Accounts/{$twilio_sid}/Applications", 'POST', array('FriendlyName' => $appName, 'VoiceUrl' => tenant_url('twiml/dial', $tenant_id), 'VoiceFallbackUrl' => asset_url('fallback/voice.php'), 'VoiceMethod' => 'POST', 'SmsUrl' => '', 'SmsFallbackUrl' => '', 'SmsMethod' => 'POST')); if ($response->IsError) { if ($response->HttpStatus > 400) { throw new Exception($response->ErrorMessage); } } $appSid = (string) $response->ResponseXml->Application->Sid; } // Update the settings for this tenant $ci->vbx_settings->add('application_sid', $appSid, $tenant_id); }
private function create_application_for_subaccount($tenant_id, $name, $accountSid) { $appName = "OpenVBX - {$name}"; $twilio = new TwilioRestClient($this->twilio_sid, $this->twilio_token, $this->twilio_endpoint); $response = $twilio->request("Accounts/{$accountSid}/Applications", "GET", array("FriendlyName" => $appName)); if ($response->IsError) { if ($response->HttpStatus > 400) { throw new VBX_SettingsException($response->ErrorMessage); } } // If we found an existing application, update the urls. $foundApp = intval($response->ResponseXml->Applications['total']); if ($foundApp) { $appSid = (string) $response->ResponseXml->Applications->Application->Sid; $response = $twilio->request("Accounts/{$accountSid}/Applications/{$appSid}", 'POST', array('FriendlyName' => $appName, 'VoiceUrl' => tenant_url('twiml/dial', $tenant_id), 'VoiceFallbackUrl' => asset_url('fallback/voice.php'), 'VoiceMethod' => 'POST', 'SmsUrl' => '', 'SmsFallbackUrl' => '', 'SmsMethod' => 'POST')); if ($response->IsError) { if ($response->HttpStatus > 400) { throw new VBX_SettingsException("Failed to create application: " . $response->ErrorMessage); } } // Otherwise, lets create a new application for openvbx } else { $response = $twilio->request("Accounts/{$accountSid}/Applications", 'POST', array('FriendlyName' => $appName, 'VoiceUrl' => tenant_url('twiml/dial', $tenant_id), 'VoiceFallbackUrl' => asset_url('fallback/voice.php'), 'VoiceMethod' => 'POST', 'SmsUrl' => '', 'SmsFallbackUrl' => '', 'SmsMethod' => 'POST')); if ($response->IsError) { if ($response->HttpStatus > 400) { throw new VBX_SettingsException("Failed to create application: " . $response->ErrorMessage); } } $appSid = (string) $response->ResponseXml->Application->Sid; } return $appSid; }
function set_password() { $ci =& get_instance(); $ci->load->helper('email'); $password = random_str(); $this->password = self::salt_encrypt($password); try { $result = $this->save(); // $message = "Your new password is $password\n\n" . tenant_url('', $this->tenant_id); $maildata = array('password' => $password, 'tenant_url' => tenant_url('', $this->tenant_id)); openvbx_mail($this->email, 'Your new password', 'password-reset', $maildata); } catch (Exception $e) { error_log($e->getMessage()); return false; } return $result; }
public function send_new_user_notification() { // Set a random invitation code for resetting password $this->invite_code = $this->generate_invite_code(); $this->save(); // Email the user the reset url $maildata = array('invite_code' => $this->invite_code, 'name' => $this->first_name, 'reset_url' => tenant_url("/auth/reset/{$this->invite_code}", $this->tenant_id)); return openvbx_mail($this->email, 'Welcome aboard', 'welcome-user', $maildata); }
private function create_application_for_subaccount($tenant_id, $name, $accountSid) { $appName = "OpenVBX - {$name}"; $application = false; try { /** @var Services_Twilio_Rest_Accounts $accounts */ $accounts = OpenVBX::getAccounts(); $sub_account = $accounts->get($accountSid); foreach ($sub_account->applications as $_application) { if ($_application->friendly_name == $appName) { /** @var Services_Twilio_Rest_Application $application */ $application = $_application; } } } catch (Exception $e) { throw new VBX_SettingsException($e->getMessage()); } $params = array('FriendlyName' => $appName, 'VoiceUrl' => tenant_url('twiml/dial', $tenant_id), 'VoiceFallbackUrl' => asset_url('fallback/voice.php'), 'VoiceMethod' => 'POST', 'SmsUrl' => '', 'SmsFallbackUrl' => '', 'SmsMethod' => 'POST'); try { if (!empty($application)) { $application->update($params); } else { $application = $sub_account->applications->create($appName, $params); } } catch (Exception $e) { throw new VBX_SettingsException($e->getMessage(), $e->getCode()); } return $application->sid; }
function set_password() { $ci =& get_instance(); $ci->load->helper('email'); $password = random_str(); $this->password = self::salt_encrypt($password); try { $result = $this->save(); $message = "Your new password is {$password}\n\n" . tenant_url('', $this->tenant_id); openvbx_mail($this->email, 'OpenVBX Password', $message); } catch (Exception $e) { error_log($e->getMessage()); return false; } return $result; }
</form> <br class="clear" /> <table class="vbx-items-grid"> <tbody> <?php foreach ($tenants as $tenant) { ?> <tr class="items-row"> <td class="url-tenant"><a href="<?php echo tenant_url('', $tenant->id); ?> "><?php echo tenant_url('', $tenant->id); ?> </a></td> <td class="type-tenant"><?php switch ($tenant->type) { case VBX_Settings::AUTH_TYPE_FULL: echo 'Full'; break; case VBX_Settings::AUTH_TYPE_CONNECT: echo 'Twilio Connect'; break; case VBX_Settings::AUTH_TYPE_SUBACCOUNT: echo 'Sub-Account'; break; } ?>
public function send_new_user_notification() { /* Set a random invitation code for resetting password */ $this->invite_code = substr(self::salt_encrypt(mt_rand()), 0, 20); $this->save(); /* Email the user the reset url */ $maildata = array('invite_code' => $this->invite_code, 'name' => $this->first_name, 'reset_url' => tenant_url("/auth/reset/{$this->invite_code}", $this->tenant_id)); openvbx_mail($this->email, 'Welcome aboard', 'welcome-user', $maildata); }
<div id="hd"> <h1 id="openvbx-logo"><a href="<?php echo tenant_url(''); ?> " class="navigate-away"><span class="replace">OpenVBX</span></a></h1> <span id="openvbx-assets" class="hide"><a href="<?php echo asset_url(''); ?> " class="navigate-away"><span class="replace">OpenVBX</span></a></span> </div><!-- #hd -->