/** * Can only be fetched once. The XMPP Session is not valid anymore on refresh. User will have to relogin manually. * @return array */ public static function getPrebindInfo() { require GO::config()->root_path . 'modules/chat/xmpp-prebind-php/lib/XmppPrebind.php'; GO::debug("CHAT: Pre binding to XMPP HOST: " . self::getXmppHost() . " BOSH URI: " . self::getBoshUri() . " with user " . GO::user()->username); if (isset(GO::session()->values['chat']['p'])) { try { $xmppPrebind = new \XmppPrebind(self::getXmppHost(), self::getBoshUri(), GO::config()->product_name, strpos(self::getBoshUri(), 'https') !== false, false); if ($xmppPrebind->connect(GO::user()->username, \GO\Base\Util\Crypt::decrypt(GO::session()->values['chat']['p']))) { $xmppPrebind->auth(); GO::debug("CHAT: connect successfull"); // array containing sid, rid and jid $ret = $xmppPrebind->getSessionInfo(); $ret['prebind'] = "true"; return $ret; } else { GO::debug("CHAT: failed to connect"); } } catch (\Exception $e) { GO::debug("CHAT: Authentication failed: " . $e); } } else { GO::debug("CHAT: Password not set"); } $ret = array('prebind' => 'false', 'jid' => '', 'sid' => '', 'rid' => ''); return $ret; }
function render_page($event) { $rcmail = rcube::get_instance(); // TODO: exclude some more actions // excluding notes and calender for now, because converse.js breaks roundcube functions there if ($rcmail->task == 'login' || !empty($_REQUEST['_extwin']) || $rcmail->task == 'notes' || $rcmail->task == 'calendar') { return; } // map session language with converse.js locale $locale = 'en'; $userlang = $rcmail->get_user_language(); $userlang_ = substr($userlang, 0, 2); $locales = array('af', 'de', 'en', 'es', 'fr', 'he', 'hu', 'id', 'it', 'ja', 'nl', 'pt_BR', 'ru', 'zh'); if (in_array($userlang, $locales)) { $locale = $userlang; } else { if (in_array($userlang_, $locales)) { $locale = $userlang_; } } $converse_prop = array('prebind' => false, 'expose_rid_and_sid' => $this->_config_get('converse_xmpp_enable_always', array(), false), 'bosh_service_url' => $this->_config_get('converse_xmpp_bosh_url', array(), '/http-bind'), 'debug' => $this->debug); $converse_prop = array_merge($this->converseconfig, $converse_prop); // prebind if (!empty($_SESSION['converse_xmpp_prebind']) && empty($_SESSION['xmpp'])) { // prebinding disabled by user if ($this->_config_get('converse_prebind', $args, 1) != 1) { $rcmail->session->remove('converse_xmpp_prebind'); } else { if ($this->_config_get('converse_xmpp_old_style_prebind')) { // old prebind code, will be removed in the future $args = $_SESSION['converse_xmpp_prebind']; $xsess = new XmppPrebindSession($args['bosh_prebind_url'], $args['host'], $args['user'], $rcmail->decrypt($args['pass'])); $xsess->debug = $this->debug; if ($xsess->init_connection() && $xsess->bind()) { $converse_prop['prebind'] = true; $converse_prop['bosh_service_url'] = $args['bosh_url']; $converse_prop['jid'] = $xsess->jid; $converse_prop['sid'] = $xsess->sid; $converse_prop['rid'] = $xsess->rid; } else { $rcmail->session->remove('xmpp'); } } else { // newer prebind code, using candy chat's prebind library if ($this->devel_mode) { require_once __DIR__ . '/devel/xmpp-prebind-php/lib/XmppPrebind.php'; } else { require_once __DIR__ . '/php/xmpp-prebind-php/lib/XmppPrebind.php'; } $args = $_SESSION['converse_xmpp_prebind']; if (strpos($args['user'], '@')) { list($args['user'], $args['host']) = preg_split('/@/', $args['user']); } $xsess = new XmppPrebind($args['host'], $args['bosh_prebind_url'], $this->resource_prefix . uniqid(), false, $this->debug); $success = true; try { $xsess->connect($args['user'], $rcmail->decrypt($args['pass'])); $xsess->auth(); } catch (Exception $e) { rcube::raise_error("Converse-XMPP: Prebind failure: " . $e->getMessage()); $success = false; } if ($success) { $sinfo = $xsess->getSessionInfo(); $converse_prop['prebind'] = true; $converse_prop['bosh_service_url'] = $args['bosh_url']; $converse_prop['jid'] = $sinfo['jid']; $converse_prop['sid'] = $sinfo['sid']; $converse_prop['rid'] = $sinfo['rid']; } else { $rcmail->session->remove('xmpp'); } } } } else { if (!empty($_SESSION['xmpp'])) { $converse_prop['prebind'] = true; $converse_prop += (array) $_SESSION['xmpp']; } else { if (!$this->_config_get('converse_xmpp_enable_always', array(), false)) { return; } } } if ($this->devel_mode) { $this->include_script('devel/converse.js/components/requirejs/require.js'); $this->include_script('js/main.js'); $this->include_stylesheet('devel/converse.js/converse.css'); } else { $this->include_script('js/' . $this->jsfile); $this->include_stylesheet('css/converse.min.css'); } $this->include_script('js/converse-rcmail.js'); $skin_path = $this->local_skin_path(); if (is_file($this->home . "/{$skin_path}/converse.css")) { $this->include_stylesheet("{$skin_path}/converse.css"); } $this->api->output->add_footer(html::div(array('id' => "conversejs"), '')); $this->api->output->add_script(' define("jquery", [], function() { return jQuery; }); require.config({ baseUrl: "' . $this->urlbase . 'devel/converse.js" }); require(["converse"], function (converse) { var args = ' . $rcmail->output->json_serialize($converse_prop) . '; args.i18n = locales["' . $locale . '"]; rcmail_converse_init(converse, args); }); ', 'foot'); }
<?php include 'xmpp-prebind-php/lib/XmppPrebind.php'; include 'config.php'; $xmppPrebind = new XmppPrebind($server, $boshUrl, 'conversejs', false, false); $xmppPrebind->connect($username, $password); $xmppPrebind->auth(); $sessionInfo = $xmppPrebind->getSessionInfo(); // array containing sid, rid and jid header('Content-Type: application/json'); echo json_encode($sessionInfo);