public function reset() { $this->template->write('title', 'Reset Password'); $data = array(); $email = $this->input->post('email'); if (empty($email)) { $data['error'] = $this->session->flashdata('error'); return $this->respond('', 'reset', $data, 'login-wrapper', 'layout/login'); } $user = VBX_User::get(array('email' => $this->input->post('email'), 'is_active' => 1)); if (empty($user)) { $this->session->set_flashdata('error', 'No active account found.'); return redirect('auth/reset'); } if ($user->auth_type == 'google') { header('Location: http://www.google.com/support/accounts/bin/answer.py?answer=48598&hl=en&ctx=ch_Login&fpUrl=https%3A%2F%2Fwww.google.com%2Faccounts%2FForgotPasswd%3FfpOnly%3D1%26continue%3Dhttp%253A%252F%252Fwww.google.com%252F%26hl%3Den'); return; } else { $user = new VBX_User($user); $emailSent = $user->send_reset_notification(); if ($emailSent) { $this->session->set_flashdata('error', 'To complete the password reset, check your inbox.'); } else { $this->session->set_flashdata('error', 'The email was not sent. Contact your admin.'); } return redirect('auth/login'); } return redirect('auth/reset'); }
function runUpdate_68_update_users() { $ci =& get_instance(); $users = $ci->db->from('users')->get()->result(); if (!empty($users)) { foreach ($users as $user) { $_user = new VBX_User($user); foreach (array('online', 'last_seen', 'last_login') as $setting) { if (!is_null($user->{$setting})) { $_user->setting_set($setting, $user->{$setting}); } } } } }
/** * Display the popup for making calls with Twilio Client * * @return void */ public function client() { $caller_id = $this->input->get('callerid'); if (empty($caller_id)) { // grab user's default device $user = VBX_User::get($this->session->userdata['user_id']); $devices = $this->vbx_device->get_by_user($this->user_id); if (!empty($devices)) { $caller_id = $devices[0]->value; } } $client_params = array('callerid' => normalize_phone_to_E164($caller_id), 'application_id' => 'client'); if ($this->input->get('outgoing')) { // functionality for using the "dial" modal to initiate a call $to = normalize_phone_to_E164($this->input->get('to')); if (empty($to)) { $to = htmlspecialchars($this->input->get('to')); } $client_params = array_merge($client_params, array('to' => $to)); } elseif ($this->input->get('incoming')) { $client_params = array_merge($client_params, array('incoming' => true)); } $client_data = array('client_params' => json_encode($client_params)); $javascript = $this->load->view('client_js', $client_data, true); $this->template->add_js($javascript, 'embed', true); $data = array('title' => 'dialer', 'client_params' => $client_params); $this->respond('Dialer', 'call', $data, '', 'layout/dialer'); }
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; } }
/** * Get a DialList object try * Pass in a VBX_User or VBX_Group object to begin * * @param object users_or_group * @return object DialList */ public static function get($users_or_group) { $users = array(); $class = 'DialList'; switch (true) { case is_array($users_or_group): if (current($users_or_group) instanceof VBX_User) { // list of users, set as users list and continue $users = $users_or_group; } else { // list of user ids, populate list $users = VBX_User::get_users($users_or_group); } break; case $users_or_group instanceof VBX_Group: if (!empty($users_or_group->users)) { foreach ($users_or_group->users as $user) { array_push($users, VBX_User::get($user->user_id)); } } break; case $users_or_group instanceof VBX_User: $class = 'DialListUser'; // individual user, add to list and continue array_push($users, $users_or_group); break; } return new $class($users); }
public function __construct() { parent::__construct(); $this->user = VBX_User::get($this->session->userdata('user_id')); if (!$this->user->is_admin) { throw new SiteCachesException('Action not allowed to non-administrators'); } }
function usergroup() { $data = array(); $users = VBX_User::search(array('is_active' => 1)); $groups = VBX_Group::search(array('is_active' => 1)); $data['users_and_groups'] = array_merge($users, $groups); usort($data['users_and_groups'], "sortUsersAndGroupsByNameComparator"); $this->respond('', 'dialog/usergroup', $data); }
public function who_called($number) { if (preg_match('|^client:|', $number)) { $user_id = str_replace('client:', '', $number); $user = VBX_User::get(array('id' => $user_id)); $ret = $user->first_name . ' ' . $user->last_name . ' (client)'; } else { $ret = format_phone($number); } return $ret; }
protected function get_users() { $users = VBX_User::search(array('is_active' => 1)); $current_user = $this->session->userdata('user_id'); foreach ($users as $k => $user) { if ($user->id == $current_user) { unset($users[$k]); } } return $users; }
public function testVoicemailUserSay() { ob_start(); $this->CI->voice(1, 'f274cd'); $out = ob_get_clean(); $xml = simplexml_load_string($out); $this->assertInstanceOf('SimpleXMLElement', $xml); $user = VBX_User::get($this->user_id); // this regex match is cheap, need better reg-fu to match possible // language and voice attributes that could appear in any order $this->assertRegExp('|(<Say(.*?)>' . $user->voicemail . '</Say>)|', $out); $this->assertRegExp('|(<Record transcribeCallback="(.*?)"/>)|', $out); }
public function setUp() { parent::setUp(); // set the user's voicemail to be a recording $this->user = VBX_User::get($this->user_id); $this->user->voicemail = $this->upload_prefix . $this->filename; $this->user->save(); $this->setFlow(array('id' => 1, 'user_id' => 1, 'created' => NULL, 'updated' => NULL, 'data' => '{"start":{"name":"Call Start","data":{"next":"start/59c7d7"},"id":"start","type":"standard---start"},"59c7d7":{"name":"Voicemail","data":{"prompt_say":"","prompt_play":"","prompt_mode":"","prompt_tag":"global","number":"","library":"","permissions_id":"' . $this->user_id . '","permissions_type":"user"},"id":"59c7d7","type":"standard---voicemail"}}', 'sms_data' => NULL, 'tenant_id' => 1)); // set up our request $this->setPath('/twiml/applet/voice/1/59c7d7'); $this->setRequestMethod('POST'); // prepare the header token for request validation $this->setRequestToken(); }
public function render($data = array()) { $hasValue = empty($this->mode) ? false : true; $this->load =& load_class('Loader'); $this->load->model('vbx_audio_file'); $this->load->model('vbx_device'); // Get a list of all previously recorded items so we can populate the library $ci =& get_instance(); $ci->db->where('url IS NOT NULL'); $ci->db->where('tag', $this->tag); $ci->db->where('tenant_id', $ci->tenant->id); $ci->db->from('audio_files'); $ci->db->order_by('created DESC'); $results = $ci->db->get()->result(); foreach ($results as $i => $result) { $results[$i] = new VBX_Audio_File($result); } // Pre-fill the record text field with the the first device phone number we // find for the current user that is active. $ci =& get_instance(); $user = VBX_User::get($ci->session->userdata('user_id')); $user_phone = ''; if (count($user->devices)) { foreach ($user->devices as $device) { if ($device->is_active) { $user_phone = format_phone($device->value); break; } } } // set the caller id for recording via the phone $caller_id = ''; $ci->load->model('vbx_incoming_numbers'); try { $numbers = $ci->vbx_incoming_numbers->get_numbers(false); foreach ($numbers as $number) { // find the first number that has voice enabled // yes, this is a rather paranoid check if (isset($number->capabilities->voice) && $number->capabilities->voice > 0) { $caller_id = normalize_phone_to_E164($number->phone); break; } } } catch (VBX_IncomingNumberException $e) { // fail silently, for better or worse error_log($e->getMessage()); } $data = array_merge(array('name' => $this->name, 'hasValue' => $hasValue, 'mode' => $this->mode, 'say' => $this->say_value, 'play' => $this->play_value, 'tag' => $this->tag, 'library' => $results, 'first_device_phone_number' => $user_phone, 'caller_id' => $caller_id), $data); return parent::render($data); }
/** * Add a device to the Dialer * * @param VBX_Device $device * @return bool */ public function dialDevice($device) { $dialed = false; if ($device->is_active) { $user = VBX_User::get($device->user_id); $call_opts = array('url' => site_url('twiml/whisper?name=' . urlencode($user->first_name))); $dial = new Dial(NULL, array('action' => current_url(), 'callerId' => $this->callerId)); if (strpos($device->value, 'client:') !== false) { $dial->addClient(str_replace('client:', '', $device->value), $call_opts); } else { $dial->addNumber($device->value, $call_opts); } $this->response->append($dial); $dialed = true; } return $dialed; }
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; } }
public function testUserDialClient() { $this->setFlowVar('data', '{"start":{"name":"Call Start","data":{"next":"start/4a7eed"},"id":"start","type":"standard---start"},"4a7eed":{"name":"Dial","data":{"dial-whom-selector":"user-or-group","dial-whom-user-or-group_id":"' . $this->dial_user_id . '","dial-whom-user-or-group_type":"user","dial-whom-number":"","callerId":"","no-answer-action":"voicemail","no-answer-group-voicemail_say":"","no-answer-group-voicemail_play":"","no-answer-group-voicemail_mode":"","no-answer-group-voicemail_tag":"global","no-answer-group-voicemail_caller_id":"+14158774003","number":"","library":"","no-answer-redirect":"","no-answer-redirect-number":"start/4a7eed/e18b35","version":"3"},"id":"4a7eed","type":"standard---dial"},"e18b35":{"name":"Hangup","data":{},"id":"e18b35","type":"standard---hangup"}}'); $user = VBX_User::get($this->dial_user_id); $user->online = 1; $user->save(); ob_start(); $this->CI->voice('1', '4a7eed'); $out = ob_get_clean(); // test valid xml $xml = simplexml_load_string($out); $this->assertInstanceOf('SimpleXMLElement', $xml); // test valid user number item $user_name = $user->first_name; $user_phone = $user->devices[0]->value; $regexp = '|<Number url="(.*?)/twiml/whisper\\?name=' . $user_name . '">\\' . $user_phone . '</Number>|'; $this->assertRegExp($regexp, $out); // test valid user client item $regexp2 = '|<Client url="(.*?)/twiml/whisper\\?name=' . $user_name . '">' . $user->id . '</Client>|'; $this->assertRegExp($regexp2, $out); }
/** * Refresh the user's devices list in the dialer * * @return json */ public function refresh_dialer() { $user = VBX_User::get(array('id' => $this->session->userdata('user_id'))); $browserphone = array('call_using_options' => array()); if (count($user->devices)) { foreach ($user->devices as $device) { if (strpos($device->value, 'client:') !== false) { continue; } $browserphone['call_using_options']['device:' . $device->id] = array('title' => 'Device: ' . $device->name, 'data' => (object) array('number' => format_phone($device->value), 'name' => $device->name)); } } $data = array('browserphone' => $browserphone); $html = $this->load->view('dialer/devices', $data, true); $response['json'] = array('error' => false, 'html' => $html); $this->respond('', 'dialer/devices', $response); }
private function save_greeting() { $data['json'] = array('error' => false, 'message' => ''); $user = VBX_User::get($this->user_id); $user->voicemail = $this->input->post('voicemail'); try { $user->save(); } catch (VBX_UserException $e) { $data['json'] = array('error' => true, 'message' => $e->getMessage()); } return $data; }
private function setup_user($user) { $this->load->database(); $this->config->load('openvbx'); $this->load->model('vbx_user'); $admin = new VBX_User(); $admin->email = $user['email']; $admin->password = VBX_User::salt_encrypt($user['password']); $admin->first_name = $user['firstname']; $admin->last_name = $user['lastname']; $admin->tenant_id = $user['tenant_id']; $admin->is_admin = true; $admin->voicemail = 'Please leave a message after the beep.'; try { $admin->save(); } catch (Exception $e) { throw new InstallException($e->getMessage(), 4); } }
public static function getUsers($options = array(), $limit = -1, $offset = 0) { return VBX_User::search($options, $limit, $offset); }
private function add_tenant() { $tenant = $this->input->post('tenant'); if (!empty($tenant)) { try { $data['id'] = $this->settings->tenant($tenant['url_prefix'], urlencode($tenant['url_prefix']), ''); $this->db->trans_start(); $user = new VBX_User(); $user->fields[] = 'tenant_id'; // monkey patching to override tenant_id $user->first_name = ''; $user->last_name = ''; $user->password = ''; $user->values['tenant_id'] = $data['id']; // hidden field not in ORM $user->email = $tenant['admin_email']; $user->is_active = TRUE; $user->is_admin = TRUE; $user->auth_type = 1; try { $user->save(); $user->send_new_user_notification(); } catch (VBX_UserException $e) { throw new VBX_SettingsException($e->getMessage()); } foreach ($this->settings->setting_options as $param) { $this->settings->add($param, '', $data['id']); } $this->settings->set('from_email', $tenant['admin_email'], $data['id']); try { $twilio = new TwilioRestClient($this->twilio_sid, $this->twilio_token, $this->twilio_endpoint); $friendlyName = $tenant['url_prefix'] . ' - ' . $tenant['admin_email']; $friendlyName = substr($friendlyName, 0, 32); $response = $twilio->request("Accounts", 'POST', array('FriendlyName' => $friendlyName)); if ($response && $response->IsError != true) { $account = $response->ResponseXml; $tenant_sid = (string) $account->Account->Sid; $tenant_token = (string) $account->Account->AuthToken; $this->settings->add('twilio_sid', $tenant_sid, $data['id']); $this->settings->add('twilio_token', $tenant_token, $data['id']); } else { $message = 'Failed to create new subaccount'; if ($response && $response->ErrorMessage) { $message = $response->ErrorMessage; } throw new VBX_SettingsException($message); } $appSid = $this->create_application_for_subaccount($data['id'], $tenant['url_prefix'], $tenant_sid); $this->settings->add('application_sid', $appSid, $data['id']); } catch (Exception $e) { throw new VBX_SettingsException($e->getMessage()); } $this->db->trans_complete(); $this->session->set_flashdata('error', 'Added new tenant'); if (isset($data['id'])) { return redirect('settings/site/tenant/' . $data['id']); } } catch (VBX_SettingsException $e) { error_log($e->getMessage()); $this->db->trans_rollback(); // TODO: rollback in twilio. $this->session->set_flashdata('error', $e->getMessage()); $data['error'] = true; $data['message'] = $e->getMessage(); } } if ($this->response_type == 'html') { redirect('settings/site'); } $this->respond('', 'settings/site', $data); }
private function inbox($group = false) { $max = $this->input->get_post('max'); $offset = $this->input->get_post('offset'); $do_transcriptions = $this->vbx_settings->get('transcriptions', $this->tenant->id); if (!$max) { $max = self::PAGE_SIZE; } $this->template->add_css(asset_url('assets/c/messages.css'), 'link'); $data = $this->init_view_data(); $inbox_counts = $data['counts']; if ($group && !array_key_exists($group, $inbox_counts)) { redirect('messages/inbox'); return; } $this->template->add_js('messages/scripts' . ($group ? '/' . $group : '') . '?' . http_build_query(compact('max', 'offset')), 'dynamic'); $data['group'] = $group; $total_items = 0; $folders = array(); if (!$group) { $data['group_name'] = 'Inbox'; $groups = array_keys($inbox_counts); } else { $data['group_name'] = $inbox_counts[$group]->name; $groups = array($group); $folders[$group] = $inbox_counts[$group]; } $users = $group == 0 ? array($this->user_id) : array(); $message_options = array('group' => $groups, 'user' => $users); $messages = $this->vbx_message->get_messages($message_options, $offset, $max); $total_items = $messages['total']; $items = array(); $this->load->library('pagination'); $group_name = ''; $data['active_users'] = VBX_User::search(array('is_active' => 1)); if ($messages['total'] < 1) { $group_name = $inbox_counts[$group]->name; } else { uasort($messages['messages'], 'sort_by_date'); foreach ($messages['messages'] as $item) { $group_name = ''; $group_id = 0; if ($item->owner_type == 'group' && isset($inbox_counts[$item->owner_id])) { $group_name = $inbox_counts[$item->owner_id]->name; $group_id = $item->owner_id; } if ($item->owner_type == 'user' && isset($inbox_counts[$item->owner_id])) { $group_name = 'Inbox'; $group_id = $item->owner_id; } $this->session->set_flashdata('selected-folder', $group_name); $this->session->set_flashdata('selected-folder-id', $group_id); $short_summary = null; if (is_null($item->content_text)) { $short_summary = ' '; if ($do_transcriptions) { $short_summary = "(no transcription)"; } } else { $short_summary = substr($item->content_text, 0, 125) . (strlen($item->content_text) > 125 ? '...' : ''); } $date_recorded = date('Y-M-d\\TH:i:s+00:00', strtotime($item->created)); $date_updated = date('Y-M-d\\TH:i:s+00:00', strtotime($item->updated)); $assigned_user = null; foreach ($data['active_users'] as $u) { if ($u->id == $item->assigned_to) { $assigned_user = clone $u; } } $items[] = array('id' => $item->id, 'folder' => $group_name, 'folder_id' => $group_id, 'short_summary' => $short_summary, 'assigned' => $item->assigned_to, 'type' => $item->type, 'assigned_user' => $assigned_user, 'ticket_status' => $item->ticket_status, 'archived' => $item->status == 'archived' ? true : false, 'unread' => $item->status == 'new' ? true : false, 'recording_url' => $item->content_url, 'recording_length' => format_player_time($item->size), 'received_time' => $date_recorded, 'last_updated' => $date_updated, 'called' => format_phone($item->called), 'caller' => format_phone($item->caller), 'original_called' => $item->called, 'original_caller' => $item->caller, 'owner_type' => $item->owner_type); } $group_name = 'Inbox'; } // set up pagination $group_id = $group === false ? 0 : $group; $page_config = array('base_url' => site_url('messages/inbox/' . $group_id), 'total_rows' => $total_items, 'per_page' => $max, 'uri_segment' => 4); $this->pagination->initialize($page_config); $data['items'] = $json['messages']['items'] = $items; // render to output array $data['pagination'] = CI_Template::literal($this->pagination->create_links()); $data['transcribe'] = $do_transcriptions; /* Return current group */ if ($group !== false && $group >= 0) { // $json = $messages; $json['id'] = $group; $json['name'] = $inbox_counts[$group]->name; $json['read'] = $inbox_counts[$group]->read; $json['new'] = $inbox_counts[$group]->new; $json['messages']['total'] = $total_items; $json['messages']['offset'] = $offset; $json['messages']['max'] = $max; } else { /* Return folder summary */ foreach ($inbox_counts as $folder_count) { $folders[] = $folder_count; } $json = array('max' => $max, 'offset' => $offset, 'total' => $total_items, 'folders' => $folders); } $data['json'] = $json; $this->respond(' - ' . $group_name, 'messages/inbox', $data); }
$dial_whom_instance = null; if (is_object($dial_whom_user_or_group)) { $dial_whom_instance = get_class($dial_whom_user_or_group); } switch ($dial_whom_instance) { case 'VBX_User': foreach ($dial_whom_user_or_group->devices as $device) { if ($device->is_active == 1) { $numbers[] = $device->value; } } $voicemail = $dial_whom_user_or_group->voicemail; break; case 'VBX_Group': foreach ($dial_whom_user_or_group->users as $user) { $user = VBX_User::get($user->user_id); foreach ($user->devices as $device) { if ($device->is_active == 1) { $numbers[] = $device->value; } } } $voicemail = $no_answer_group_voicemail; break; default: $response->addSay('Missing user or group to dial'); break; } } else { if ($dial_whom_selector === 'number') { $numbers[] = $dial_whom_number;
private function get_details($message_id) { $max_annotations = $this->input->get('max_annotations'); if (empty($max_annotations)) { $max_annotations = 20; } $data = $this->init_view_data(); try { $message = $this->vbx_message->get_message($message_id); if (!$message) { throw new MessageException("Unable to retrieve message: {$message_id}"); } } catch (VBX_MessageException $e) { $this->session->set_flashdata('error', $e->getMessage()); redirect('messages/inbox'); } catch (MessageException $e) { $this->session->set_flashdata('error', $e->getMessage()); redirect('messages/inbox'); } $this->vbx_message->mark_read($message->id, $this->user_id); if ($message->owner_type == 'user' && $message->owner_id != $this->session->userdata('user_id') && !in_array($message->owner_id, array_keys($data['counts']))) { $this->session->set_flashdata('You are not allowed to view that message'); redirect('messages'); } $data['group'] = ''; if ($message->owner_type == 'group') { if (isset($data['counts'][$message->owner_id])) { $data['group'] = $data['counts'][$message->owner_id]->name; } else { $data['group'] = 'Inbox'; } } $message->pretty_called = format_phone($message->called); $message->pretty_caller = format_phone($message->caller); $data['message'] = $message; $summary = $message->content_text; $this->load->model('vbx_user'); $annotations = array(); // $users = $this->vbx_user->get_active_users(); $users = VBX_User::search(array('is_active' => 1)); $active_users = array(); foreach ($users as $active_user) { $active_users[] = array('id' => $active_user->id, 'first_name' => $active_user->first_name, 'last_name' => $active_user->last_name, 'email' => $active_user->email); } $folder_id = $message->owner_type == 'group' ? $message->owner_id : 0; $details = array('id' => $message_id, 'selected_folder' => $this->session->flashdata('selected-folder'), 'selected_folder_id' => $this->session->flashdata('selected-folder-id'), 'status' => $message->status, 'type' => $message->type, 'ticket_status' => $message->ticket_status, 'summary' => $summary, 'assigned' => $message->assigned_to, 'archived' => $message->status == 'archived' ? true : false, 'unread' => $message->status == 'new' ? true : false, 'recording_url' => preg_replace('/http:\\/\\//', 'https://', $message->content_url), 'recording_length' => format_player_time($message->size), 'received_time' => date('Y-M-d\\TH:i:s+00:00', strtotime($message->created)), 'last_updated' => date('Y-M-d\\TH:i:s+00:00', strtotime($message->updated)), 'called' => format_phone($message->called), 'caller' => format_phone($message->caller), 'original_called' => $message->called, 'original_caller' => $message->caller, 'folder' => $data['group'], 'folder_id' => $folder_id, 'message_type' => $message->type, 'active_users' => $active_users, 'owner_type' => $message->owner_type); $data = array_merge($data, $details); $data['json'] = $details; if ($max_annotations) { $annotations = $this->vbx_message->get_annotations($message_id); $items = array_slice($annotations, 0, $max_annotations); foreach ($items as $item_id => $item) { $items[$item_id]->created = date('c', strtotime($item->created)); } $max_annotations = count($annotations) > $max_annotations ? $max_annotations : count($annotations); $annotation_details = array('items' => $items, 'max' => $max_annotations, 'total' => count($annotations)); $data['annotations'] = $data['json']['annotations'] = $annotation_details; } $data['gravatars'] = $this->vbx_settings->get('gravatars', $this->tenant->id); $data['default_gravatar'] = asset_url('assets/i/user-icon.png'); $date = date('M j, Y h:i:s', strtotime($message->created)); $this->respond(' - ' . $data['group'] . " voicemail from {$message->pretty_caller} at {$date} ", 'messages/details', $data); }
function notify_message($message) { $ci =& get_instance(); $ci->load->model('vbx_user'); $ci->load->model('vbx_group'); $ci->load->model('vbx_incoming_numbers'); $recording_host = $ci->settings->get('recording_host', VBX_PARENT_TENANT); $vm_url = $message->content_url; if (!empty($recording_host) && trim($recording_host) != '') { $vm_url = str_replace('api.twilio.com', trim($recording_host), $vm_url); } $message->content_url = $vm_url; $users = array(); $notify = array(); if ($message->owner_type == 'user') { $user = VBX_User::get($message->owner_id); if (!empty($user->email)) { $notify[] = $user->email; } } $group_users = array(); if ($message->owner_type == 'group') { $user_ids = $ci->vbx_group->get_user_ids($message->owner_id); $group = $ci->vbx_group->get_by_id($message->owner_id); $owner = $group->name; } else { if ($message->owner_type == 'user') { $user_ids = array($message->owner_id); $owner = 'Personal'; } } $notification_setting = 'email_notifications_' . $message->type; $email_notify = $ci->vbx_settings->get($notification_setting, $ci->tenant->id); // check the incoming number's capabilities and don't even try to send // an SMS notification if the number is not allowed to send SMS messages $incoming_number = VBX_Incoming_numbers::get(array('phone_number' => normalize_phone_to_E164($message->called))); if (!empty($incoming_number) && $incoming_number->capabilities->sms == 1) { $sms_notify = true; } if ($email_notify || $sms_notify) { foreach ($user_ids as $user_id) { $user = VBX_User::get($user_id); $ci->load->model('vbx_device'); $ci->load->model('vbx_sms_message'); $numbers = VBX_Device::search(array('user_id' => $user_id)); $message_type = 'Voicemail'; if ($message->type == 'sms') { $message_type = 'SMS'; $owner = ''; } if ($email_notify) { $email_subject = "New {$owner} {$message_type} Notification - {$message->caller}"; openvbx_mail($user->email, $email_subject, 'message', compact('message')); } if ($sms_notify) { foreach ($numbers as $number) { if ($number->value && $number->sms) { try { $ci->vbx_sms_message->send_message($message->called, $number->value, $this->tiny_notification_message($message)); } catch (VBX_Sms_messageException $e) { log_message('error', 'unable to send sms alert, reason: ' . $e->getMessage()); } } } } // if ($sms_notify) } } // if ($email_notify || $sms_notify) }
/** * Add a device to the Dialer * * @param VBX_Device $device * @return bool */ public function dialDevice($device) { $dialed = false; if ($device->is_active) { $user = VBX_User::get($device->user_id); $dial = $this->getDial(); $call_opts = $this->callOpts(array('whisper_to' => $user->first_name)); if (strpos($device->value, 'client:') !== false) { $dial->client(str_replace('client:', '', $device->value), $call_opts); } else { $dial->number($device->value, $call_opts); } $this->state = 'calling'; $dialed = true; } return $dialed; }
public static function getUserGroupPickerValue($name = 'userGroupPicker') { $ci =& get_instance(); $ci->load->model('vbx_user'); $ci->load->model('vbx_group'); $owner_id = self::getValue($name . '_id'); $owner_type = self::getValue($name . '_type'); $owner = null; switch ($owner_type) { case 'group': $owner = VBX_Group::get(array('id' => $owner_id)); break; case 'user': $owner = VBX_User::get($owner_id); break; } return $owner; }
private function login_call($singlepass) { /* Rest API Authentication - one time pass only */ if (!empty($singlepass)) { $ra = new VBX_Rest_access(); $user_id = $ra->auth_key($singlepass); unset($_COOKIE['singlepass']); if ($user_id) { $this->session->set_userdata('user_id', $user_id); $this->session->set_userdata('loggedin', true); $this->session->set_userdata('signature', VBX_User::signature($user_id)); return true; } } return false; }
public function client_status() { $data = array('json' => array('error' => true, 'message' => 'Invalid Request')); if ($this->input->post('clientstatus')) { $online = $this->input->post('online') == 1; $user = VBX_User::get($this->session->userdata('user_id')); try { $user->setting_set('online', $online); $data['json'] = array('error' => false, 'message' => 'status updated', 'client_status' => $online ? 'online' : 'offline'); } catch (VBX_UserException $e) { $data['json'] = array('error' => true, 'message' => $e->getMessage()); } } $this->respond('', null, $data); }
/** * Validate the user's signature & state * State is generated in the welcome controller and passed through the oauth process * * @todo process $state passed back through the oauth process * * @param int $user_id * @return mixed VBX_User or false */ protected function validate_returning_user($user_id) { // jump through hoops to get around the Tenantization $userdata = $this->db->get_where('users', array('id' => $user_id))->result(); if (!empty($userdata[0])) { $user = new VBX_User($userdata[0]); $list = implode(',', array($user->id, $user->password, $user->tenant_id, $user->is_admin)); $expected_signature = VBX_User::salt_encrypt($list); $actual_signature = $this->session->userdata('signature'); if ($expected_signature == $actual_signature) { return $user; } else { return false; } } }
public static function signature($user) { if (is_numeric($user)) { $user = VBX_User::get($user); } if (!$user || !is_object($user)) { return null; } $list = implode(',', array($user->id, $user->password, $user->tenant_id, $user->is_admin)); return self::salt_encrypt($list, true); }