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; } }
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); }
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 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); }
/** * Attempt to log in the user * * @param VBX_User $user * @param string $password * @return mixed VBX_User on success, bool FALSE on failure */ protected function login_openvbx($user, $password) { if (!self::authenticate($user, $password)) { return FALSE; } else { // Login succeeded if (OpenVBX::schemaVersion() >= 24) { $user->last_login = new MY_ModelLiteral('UTC_TIMESTAMP()'); // auto-upgrade old passwords if (OpenVBX::schemaVersion() > 63 && strlen($user->password) == 40) { $user->password = self::salt_encrypt($password); $user->save(); } try { $user->setting_set('last_login', new MY_ModelLiteral('UTC_TIMESTAMP()')); } catch (VBX_UserException $e) { $this->error_message('login', $e->getMessage()); return FALSE; } } return $user; } }
/** * Returns the version of the database schema * * @static * @return int */ public static function schemaVersion() { if (empty(self::$schemaVersion)) { $ci =& get_instance(); if ($ci->db) { $reenable_cache = false; $ci->load->model('vbx_settings'); if (isset($ci->cache) && $ci->cache->enabled()) { $ci->cache->enabled(false); $reenable_cache = true; } self::$schemaVersion = $ci->vbx_settings->get('schema-version', VBX_PARENT_TENANT); if ($reenable_cache) { $ci->cache->enabled(true); } } } return self::$schemaVersion; }
function login_openvbx($user, $password) { if ($user->password != self::salt_encrypt($password)) { return FALSE; } else { // Login succeeded if (OpenVBX::schemaVersion() >= 24) { $user->last_login = new MY_ModelLiteral('UTC_TIMESTAMP()'); try { $user->save(); } catch (VBX_UserException $e) { $this->error_message('login', $e->getMessage()); return FALSE; } } return $user; } }
</div><!-- #vbx-main --> </div><!-- .yui-b --> </div> <div class="yui-b"> <div class="vbx-sidebar"> </div><!-- .vbx-sidebar --> </div><!-- .yui-b --> </div><!-- #bd .error-404 --> <div id="ft"> <p class="copyright">OpenVBX • <em>v</em><?php echo OpenVBX::version(); ?> r<?php echo OpenVBX::schemaVersion(); ?> — Powered by <a href="http://twilio.com/">Twilio Inc.</a> • <a href="http://www.twilio.com/legal/tos">Terms</a> • <a href="http://www.twilio.com/legal/privacy">Privacy</a></p> </div><!-- #ft --> </div><!-- #wrapper --> </div><!-- #doc --> </body> </html>
private function upgrade_check() { $currentSchemaVersion = OpenVBX::schemaVersion(false); $upgradingToSchemaVersion = OpenVBX::getLatestSchemaVersion(); if ($currentSchemaVersion != $upgradingToSchemaVersion) { redirect('upgrade'); } }