mysql_close($dblink); html_die("<br>Your IM account was updated"); } # ----- $query = "SELECT juid,jab_id,jab_passwd,type FROM jusers WHERE\n\tsip_id='{$sipuri}' and type=0"; $result = mysql_query($query, $dblink) or html_die("Invalid SQL query"); if (mysql_num_rows($result) != 1 || !($row = mysql_fetch_array($result))) { mysql_close($dblink); html_die("<br>You do not have an associated Jabber account or it is\n\t\tdisabled!<br>Press 'Enable' in order to create a new one or to activate an\n\t\told one.<br>If error persists, please inform the administrator."); } $juid = $row[0]; $jab_id = $row[1]; $jab_passwd = $row[2]; $jab_type = $row[3]; dbg_msg("Jabber User ID: {$juid}<BR>"); $fd = jab_connect($jserver, $jport); if (!$fd) { html_die("Could not connect to Jabber server"); } $buf_recv = fread($fd, 2048); while (!$buf_recv) { usleep(100); $buf_recv = fread($fd, 2048); } $jid1 = stristr($buf_recv, "id='"); $jid1 = substr($jid1, 4); if ($jid1) { $jid2 = strstr($jid1, "'"); if ($jid2) { $jid = substr($jid1, 0, strlen($jid1) - strlen($jid2)); dbg_msg("JID: {$jid}<BR>");
function reg_jab($sipname) { global $config; $jcid = $config->jcid; $sipdomain = $config->domain; # ----- # check if is already registered with Jabber gateway # ----- $sipuri = "sip:" . $sipname . "@" . $sipdomain; $dsn = $config->jab_db_type . "://" . $config->jab_db_usr . ":" . $config->jab_db_pas . "@" . $config->jab_db_srv . (empty($config->jab_db_port) ? "" : ":" . $config->jab_db_port) . "/" . $config->jab_db_db; $db = DB::connect($dsn); if (DB::isError($db)) { log_errors($db, $dummy); return 1; } # ---- $query = "SELECT jab_id FROM jusers WHERE sip_id='{$sipuri}'"; $result = $db->query($query); if (DB::isError($result)) { log_errors($result, $dummy); return 3; } if ($result->numRows() == 0) { // no Jabber account - create one $fd = jab_connect($config->jserver, $config->jport); if (!$fd) { return 4; } $buf_recv = fread($fd, 2048); while (!$buf_recv) { usleep(100); $buf_recv = fread($fd, 2048); } $jcid = $jcid + 1; jab_get_reg($fd, $jcid, $config->jserver); $buf_recv = fread($fd, 2048); while (!$buf_recv) { usleep(100); $buf_recv = fread($fd, 2048); } $jcid = $jcid + 1; $new_passwd = "qw1" . $sipname . "#"; jab_set_reg($fd, $jcid, $config->jserver, $sipname, $new_passwd); $buf_recv = fread($fd, 2048); while (!$buf_recv) { usleep(100); $buf_recv = fread($fd, 2048); } if (stristr($buf_recv, " id='{$jcid}'") && stristr($buf_recv, " type='error'")) { $db->disconnect(); jab_disconnect($fd); return 5; } # ----- # Add user in database # ----- $query = "INSERT INTO jusers (jab_id, jab_passwd, sip_id) VALUES ('{$sipname}', '{$new_passwd}', '{$sipuri}')"; $result = $db->query($query); if ($db->affectedRows() != 1) { $db->disconnect(); jab_disconnect($fd); return 6; } jab_disconnect($fd); } return 0; }