private function register($loop, $me) { $buffer = ''; // Launching the linker $this->process = new \React\ChildProcess\Process('exec php linker.php', null, array('sid' => $this->sid, 'baseuri' => $this->baseuri)); $this->process->start($loop); // Buffering the incoming data and fire it once its complete $this->process->stdout->on('data', function ($output) use($me, &$buffer) { if (substr($output, -1) == "") { $out = $buffer . substr($output, 0, -1); $buffer = ''; $me->messageOut($out); } else { $buffer .= $output; } }); // The linker died, we close properly the session $this->process->on('exit', function ($output) use($me) { echo colorize($this->sid, 'yellow') . " : " . colorize("linker killed \n", 'red'); $me->process = null; $me->closeAll(); $sd = new \Modl\SessionxDAO(); $sd->delete($this->sid); }); // Debug only, if the linker output some errors $this->process->stderr->on('data', function ($output) use($me) { echo $output; }); }
function display() { // We get the informations $pop = 0; foreach (scandir(USERS_PATH) as $f) { if (is_dir(USERS_PATH . '/' . $f)) { $pop++; } } $pop = $pop - 2; // We get the global configuration $cd = new \Modl\ConfigDAO(); $config = $cd->get(); $sd = new \Modl\SessionxDAO(); $infos = array('url' => BASE_URI, 'language' => $config->locale, 'whitelist' => $config->xmppwhitelist, 'timezone' => $config->timezone, 'description' => $config->description, 'unregister' => $config->unregister, 'php_version' => phpversion(), 'version' => APP_VERSION, 'population' => $pop, 'connected' => $sd->getConnected()); $this->view->assign('json', json_encode($infos)); }
public function destroy() { $sd = new \Modl\SessionxDAO(); $sd->delete(self::$_sessionid); }
private function cleanupDBSessions() { $sd = new \Modl\SessionxDAO(); $sd->deleteEmpty(); $pd = new \Modl\PresenceDAO(); $pd->cleanPresences(); }
function ajaxLogin($form) { // We get the Server Configuration $cd = new \Modl\ConfigDAO(); $config = $cd->get(); // First we check the form $validate_login = Validator::email()->length(6, 40); $validate_password = Validator::string()->length(4, 40); $login = $form->login->value; $password = $form->pass->value; if (!$validate_login->validate($login)) { $this->showErrorBlock('login_format'); return; } if (!$validate_password->validate($password)) { $this->showErrorBlock('password_format'); return; } list($username, $host) = explode('@', $login); // Check whitelisted server if ($config->xmppwhitelist != '' && !in_array($host, explode(',', $config->xmppwhitelist))) { $this->showErrorBlock('unauthorized'); return; } // We check if we already have an open session $sd = new \Modl\SessionxDAO(); $here = $sd->getHash(sha1($username . $password . $host)); if ($here) { RPC::call('Login.setCookie', $here->session); RPC::call('movim_redirect', Route::urlize('main')); $this->showErrorBlock('conflict'); return; } // We try to get the domain $domain = \Moxl\Utils::getDomain($host); // We launch the XMPP socket RPC::call('register', $host); // We create a new session or clear the old one $s = Sessionx::start(); $s->init($username, $password, $host, $domain); \Moxl\Stanza\Stream::init($host); }
private function closeEmptySession($sid) { // No WebSockets and no linker ? We close the whole session if ($this->sessions[$sid]->countClients() == 0 && $this->sessions[$sid]->process == null) { $sd = new \Modl\SessionxDAO(); $sd->delete($sid); unset($this->sessions[$sid]); } }
private function doLogin($login, $password) { // We get the Server Configuration $cd = new \Modl\ConfigDAO(); $config = $cd->get(); // First we check the form $validate_login = Validator::email()->length(1, 254); $validate_password = Validator::stringType()->length(1, 128); if (!$validate_login->validate($login)) { $this->showErrorBlock('login_format'); return; } if (!$validate_password->validate($password)) { $this->showErrorBlock('password_format'); return; } list($username, $host) = explode('@', $login); // Check whitelisted server if ($config->xmppwhitelist != '' && !in_array($host, explode(',', $config->xmppwhitelist))) { $this->showErrorBlock('unauthorized'); return; } // We check if we already have an open session $sd = new \Modl\SessionxDAO(); $here = $sd->getHash(sha1($username . $password . $host)); if ($here) { //if($s->get('hash') == sha1($username.$password.$host)) { RPC::call('Login.setCookie', $here->session); RPC::call('MovimUtils.redirect', Route::urlize('main')); $this->showErrorBlock('conflict'); return; } $s = Session::start(); // We create a new session or clear the old one $s->set('password', $password); $s->set('username', $username); $s->set('host', $host); $s->set('jid', $login); $s->set('hash', sha1($username . $password . $host)); $s = Sessionx::start(); $s->init($username, $password, $host); // We launch the XMPP socket RPC::call('register', $host); \Moxl\Stanza\Stream::init($host); }