Esempio n. 1
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("iq", $arMessage) || !array_key_exists("bind", $arMessage["iq"]) || $arMessage['iq']['bind']['.']['xmlns'] != 'urn:ietf:params:xml:ns:xmpp-bind') {
         return false;
     }
     $type = "";
     if (array_key_exists("type", $arMessage["iq"]["."])) {
         $type = $arMessage["iq"]["."]["type"];
     }
     if ($type == "set") {
         $resource = $arMessage["iq"]["bind"]["resource"]["#"];
         if (strlen($resource) <= 0) {
             $resource = "bx";
         }
         $senderClient->SetResource($resource);
         $arMessageTmp = array("iq" => array("." => array("type" => "result", "to" => htmlspecialcharsbx($senderClient->GetClientDomain()) . "/" . $senderClient->GetStreamId(), "id" => $arMessage['iq']['.']['id']), "bind" => array("." => array("xmlns" => "urn:ietf:params:xml:ns:xmpp-bind"), "jid" => array("#" => $senderJId . "/" . $resource))));
         $messageTmp = CXMPPParser::ToXml($arMessageTmp);
         $senderClient->__Send($messageTmp);
     } else {
         $arMessageTmp = array("iq" => array("." => array("type" => "result", "from" => $senderClient->GetClientDomain(), "id" => $arMessage['iq']['.']['id'])));
         $messageTmp = CXMPPParser::ToXml($arMessageTmp);
         $senderClient->__Send($messageTmp);
     }
     return true;
 }
Esempio n. 2
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("iq", $arMessage) || !array_key_exists("ping", $arMessage["iq"]) || $arMessage['iq']['ping']['.']['xmlns'] != 'urn:xmpp:ping') {
         return false;
     }
     $to = "";
     if (array_key_exists("to", $arMessage["iq"]["."])) {
         $to = $arMessage["iq"]["."]["to"];
     }
     if (!empty($to) && $to != $senderClient->GetClientDomain()) {
         return false;
     }
     $arResult = array("iq" => array("." => array("type" => "result", "from" => $senderClient->GetClientDomain(), "id" => $arMessage['iq']['.']['id'], "to" => $senderClient->GetJIdWithResource())));
     return $arResult;
 }
Esempio n. 3
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (!$senderClient->IsAuthenticated()) {
         return false;
     }
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("iq", $arMessage)) {
         return false;
     }
     $to = "";
     if (array_key_exists("to", $arMessage["iq"]["."])) {
         $to = $arMessage["iq"]["."]["to"];
     }
     if (strlen($to) > 0 && strpos($to, "@") !== false) {
         $arResult = true;
         $arMessage["iq"]["."]["to"] = CXMPPUtility::GetJIdWithResource($arMessage["iq"]["."]["to"], "");
         $server = CXMPPServer::GetServer();
         $server->Send($to, $arMessage, $senderClient->GetClientDomain());
     } else {
         if ($arMessage["iq"]["."]["type"] == "get" && $arMessage["iq"]["query"]["."]["xmlns"] == "http://jabber.org/protocol/disco#items") {
             $arResult = array("iq" => array("." => array("type" => "result", "from" => $senderClient->GetClientDomain(), "id" => $arMessage['iq']['.']['id']), "query" => array("." => array("xmlns" => "http://jabber.org/protocol/disco#items"))));
         } elseif ($arMessage["iq"]["."]["type"] == "set" && $arMessage["iq"]["session"]["."]["xmlns"] == "urn:ietf:params:xml:ns:xmpp-session") {
             $arResult = array("iq" => array("." => array("type" => "result", "from" => $senderClient->GetClientDomain(), "id" => $arMessage['iq']['.']['id'])));
         } else {
             $arResult = array("iq" => array("." => array("type" => "error", "from" => $senderClient->GetClientDomain(), "id" => $arMessage['iq']['.']['id']), "error" => array("." => array("type" => "cancel"), "feature-not-implemented" => array("." => array("xmlns" => "urn:ietf:params:xml:ns:xmpp-stanzas")))));
         }
         //$arResult = CXMPPUtility::GetErrorArray($senderJId, "iq", "cancel", "feature-not-implemented", "", $arMessage['iq']['.']['id'], "");
     }
     return $arResult;
 }
Esempio n. 4
0
 function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (array_key_exists("message", $arMessage)) {
         if (!array_key_exists(".", $arMessage["message"])) {
             return false;
         }
         $type = "normal";
         if (array_key_exists("type", $arMessage["message"]["."])) {
             $type = $arMessage["message"]["."]["type"];
         }
         if ($type != "error") {
             return false;
         }
         return true;
     } elseif (array_key_exists("iq", $arMessage)) {
         if (!array_key_exists(".", $arMessage["iq"])) {
             return false;
         }
         $type = "";
         if (array_key_exists("type", $arMessage["iq"]["."])) {
             $type = $arMessage["iq"]["."]["type"];
         }
         if ($type != "error") {
             return false;
         }
         $to = "";
         if (array_key_exists("to", $arMessage["iq"]["."])) {
             $to = $arMessage["iq"]["."]["to"];
         }
         if (!empty($to) && $to != $senderClient->GetClientDomain()) {
             return false;
         }
         return true;
     }
     return false;
 }
Esempio n. 5
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (!$senderClient->IsAuthenticated()) {
         return false;
     }
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("iq", $arMessage)) {
         return false;
     }
     if (!array_key_exists("sharedgroup", $arMessage["iq"])) {
         return false;
     }
     $arResult = array("iq" => array("." => array("type" => "result", "from" => CXMPPServer::GetDomain(), "id" => $arMessage['iq']['.']['id']), "sharedgroup" => array("." => array("xmlns" => "http://www.jivesoftware.org/protocol/sharedgroup"))));
     if (is_array($GLOBALS["BX_JHGDHGFJKDFSDG67"][$senderClient->GetClientDomain()])) {
         foreach ($GLOBALS["BX_JHGDHGFJKDFSDG67"][$senderClient->GetClientDomain()] as $g) {
             $arResult["iq"]["sharedgroup"]["group"][] = array("#" => $g);
         }
     }
     return $arResult;
 }
Esempio n. 6
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (!$senderClient->IsAuthenticated()) {
         return false;
     }
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("iq", $arMessage)) {
         return false;
     }
     if ($arMessage['iq']['query']['.']['xmlns'] != 'jabber:iq:roster' && ($arMessage['iq']['query']['.']['xmlns'] != 'jabber:iq:private' || $arMessage['iq']['query']['roster']['.']['xmlns'] != 'roster:delimiter')) {
         return false;
     }
     if ($arMessage['iq']['query']['.']['xmlns'] == 'jabber:iq:roster') {
         $arResult = array("iq" => array("." => array("type" => "result", "to" => $senderJId, "id" => $arMessage['iq']['.']['id']), "query" => array("." => array("xmlns" => $arMessage['iq']['query']['.']['xmlns']))));
         if ($this->intranet) {
             $clientDomain = $senderClient->GetClientDomain();
             if (!array_key_exists($clientDomain, $this->rosterCache)) {
                 $this->rosterCache[$clientDomain] = array();
             }
             if (!array_key_exists($clientDomain, $this->rosterCacheAlt)) {
                 $this->rosterCacheAlt[$clientDomain] = array();
             }
             if ($senderClient->IsSubGroupsSupported() && count($this->rosterCache[$clientDomain]) <= 0 || !$senderClient->IsSubGroupsSupported() && count($this->rosterCacheAlt[$clientDomain]) <= 0) {
                 $arDepCache = array();
                 $arDepCacheValue = array();
                 $dbUsers = CUser::GetList($b = "LAST_NAME", $o = "asc", array("ACTIVE" => "Y", "!UF_DEPARTMENT" => false), array('SELECT' => array('UF_*')));
                 while ($arUser = $dbUsers->Fetch()) {
                     $arT = array("." => array("subscription" => "both", "name" => CUser::FormatName($this->nameTemplate, $arUser), "jid" => CXMPPUtility::GetJId($arUser, $clientDomain)));
                     if (is_array($arUser['UF_DEPARTMENT']) && count($arUser['UF_DEPARTMENT']) > 0) {
                         $arNewDep = array_diff($arUser['UF_DEPARTMENT'], $arDepCache);
                         if (count($arNewDep) > 0) {
                             $dbRes = CIBlockSection::GetList(array('SORT' => 'ASC'), array('ID' => $arNewDep));
                             while ($arSect = $dbRes->Fetch()) {
                                 $arDepCache[] = $arSect['ID'];
                                 $dbRes1 = CIBlockSection::GetNavChain($arSect['IBLOCK_ID'], $arSect['ID']);
                                 while ($arSect1 = $dbRes1->Fetch()) {
                                     if ($senderClient->IsSubGroupsSupported()) {
                                         if (strlen($arDepCacheValue[$arSect['ID']]) > 0) {
                                             $arDepCacheValue[$arSect['ID']] .= "/";
                                         }
                                         $arDepCacheValue[$arSect['ID']] .= htmlspecialcharsbx($arSect1['NAME']);
                                     } else {
                                         if (strlen($arDepCacheValue[$arSect['ID']]) > 0) {
                                             $arDepCacheValue[$arSect['ID']] = "/" . $arDepCacheValue[$arSect['ID']];
                                         }
                                         $arDepCacheValue[$arSect['ID']] = htmlspecialcharsbx($arSect1['NAME']) . $arDepCacheValue[$arSect['ID']];
                                     }
                                 }
                             }
                         }
                         foreach ($arUser['UF_DEPARTMENT'] as $key => $sect) {
                             if (strlen($arDepCacheValue[$sect]) > 0) {
                                 $arT["group"][] = array("#" => $arDepCacheValue[$sect]);
                                 if (!is_array($GLOBALS["BX_JHGDHGFJKDFSDG67"])) {
                                     $GLOBALS["BX_JHGDHGFJKDFSDG67"] = array();
                                 }
                                 if (!is_array($GLOBALS["BX_JHGDHGFJKDFSDG67"][$clientDomain])) {
                                     $GLOBALS["BX_JHGDHGFJKDFSDG67"][$clientDomain] = array();
                                 }
                                 if (!in_array($arDepCacheValue[$sect], $GLOBALS["BX_JHGDHGFJKDFSDG67"][$clientDomain])) {
                                     $GLOBALS["BX_JHGDHGFJKDFSDG67"][$clientDomain][] = $arDepCacheValue[$sect];
                                 }
                             }
                         }
                     }
                     if ($senderClient->IsSubGroupsSupported()) {
                         $this->rosterCache[$clientDomain][] = $arT;
                     } else {
                         $this->rosterCacheAlt[$clientDomain][] = $arT;
                     }
                 }
             }
             if ($senderClient->IsSubGroupsSupported()) {
                 foreach ($this->rosterCache[$clientDomain] as $ar) {
                     if ($senderClient->GetJId() != $ar["."]["jid"]) {
                         $arResult["iq"]["query"]["item"][] = $ar;
                     }
                 }
             } else {
                 foreach ($this->rosterCacheAlt[$clientDomain] as $ar) {
                     if ($senderClient->GetJId() != $ar["."]["jid"]) {
                         $arResult["iq"]["query"]["item"][] = $ar;
                     }
                 }
             }
         } else {
             $ar = array();
             $dbFriends = CSocNetUserRelations::GetRelatedUsers($senderClient->GetId(), SONET_RELATIONS_FRIEND);
             while ($arFriends = $dbFriends->GetNext()) {
                 $pref = $senderClient->GetId() == $arFriends["FIRST_USER_ID"] ? "SECOND" : "FIRST";
                 $name = CUser::FormatName($this->nameTemplate, array("NAME" => $arFriends[$pref . "_USER_NAME"], "LAST_NAME" => $arFriends[$pref . "_USER_LAST_NAME"], "SECOND_NAME" => $arFriends[$pref . "_USER_SECOND_NAME"], "LOGIN" => $arFriends[$pref . "_USER_LOGIN"]), true);
                 $arT = array("." => array("subscription" => "both", "name" => $name, "jid" => CXMPPUtility::GetJId(array("LOGIN" => $arFriends[$pref . "_USER_LOGIN"]), $senderClient->GetClientDomain())));
                 $ar[] = $arT;
             }
             $arResult["iq"]["query"]["item"] = $ar;
         }
         $senderClient->Send($arResult);
         $server = CXMPPServer::GetServer();
         $server->SendPresenceMessages($senderJId, $senderClient->GetClientDomain());
         $server->SendPresenceMessages2($senderJId, $senderClient->GetClientDomain());
     } elseif ($arMessage['iq']['query']['.']['xmlns'] == 'jabber:iq:private' && $arMessage['iq']['query']['roster']['.']['xmlns'] == 'roster:delimiter') {
         $arResult = array("iq" => array("." => array("type" => "result", "to" => $senderJId, "id" => $arMessage['iq']['.']['id']), "query" => array("." => array("xmlns" => 'jabber:iq:private'), "roster" => array("." => array("xmlns" => 'roster:delimiter'), "#" => "/"))));
         $senderClient->SetSubGroupsSupport(true);
         $senderClient->Send($arResult);
     }
     return true;
 }
Esempio n. 7
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (!$senderClient->IsAuthenticated()) {
         return false;
     }
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("message", $arMessage) || !array_key_exists(".", $arMessage["message"])) {
         return false;
     }
     $type = "normal";
     if (array_key_exists("type", $arMessage["message"]["."])) {
         $type = $arMessage["message"]["."]["type"];
     }
     if ($type == "error") {
         return false;
     }
     $mid = "";
     if (array_key_exists("id", $arMessage["message"]["."])) {
         $mid = $arMessage["message"]["."]["id"];
     }
     if (!in_array($type, array("chat", "groupchat", "headline", "normal"))) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "modify", "bad-request", "", $mid, "", $senderClient->GetClientDomain());
     }
     $recipientJId = "";
     if (array_key_exists("to", $arMessage["message"]["."])) {
         $recipientJId = $arMessage["message"]["."]["to"];
     }
     if (strlen($recipientJId) <= 0) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "modify", "bad-request", "", $mid, "", $senderClient->GetClientDomain());
     }
     $body = "";
     if (array_key_exists("body", $arMessage["message"])) {
         $body = $arMessage["message"]["body"]["#"];
     }
     if (strlen($body) <= 0) {
         return true;
     }
     //$body = CXMPPReceiveMessage::htmlspecialcharsback($body);
     //$body = html_entity_decode($body);
     $body = html_entity_decode($body, ENT_COMPAT, SITE_CHARSET);
     $body = str_replace("&apos;", "'", $body);
     $arSender = CXMPPUtility::GetUserByJId($senderJId);
     if (!$arSender) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "auth", "forbidden", $recipientJId, $mid, "", $senderClient->GetClientDomain());
     }
     $arRecipient = CXMPPUtility::GetUserByJId($recipientJId);
     if (!$arRecipient) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "cancel", "item-not-found", $recipientJId, $mid, "", $senderClient->GetClientDomain());
     }
     if (!CSocNetUserPerms::CanPerformOperation($arSender["ID"], $arRecipient["ID"], "message", false)) {
         return CXMPPUtility::GetErrorArray($senderJId, "message", "auth", "forbidden", $recipientJId, $mid, "", $senderClient->GetClientDomain());
     }
     if (IsModuleInstalled("im") && CModule::IncludeModule("im")) {
         $arMessageFields = array("FROM_USER_ID" => $arSender["ID"], "TO_USER_ID" => $arRecipient["ID"], "MESSAGE" => $body);
         CIMMessage::Add($arMessageFields);
     } else {
         $arMessageFields = array("=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE_TYPE" => SONET_MESSAGE_PRIVATE, "FROM_USER_ID" => $arSender["ID"], "TO_USER_ID" => $arRecipient["ID"], "MESSAGE" => $body);
         CSocNetMessages::Add($arMessageFields);
     }
     return true;
 }
Esempio n. 8
0
 public function _Authenticate($id, $login, $jid, $provider = "", $resource = "")
 {
     $id = intval($id);
     $this->authenticated = false;
     if ($id <= 0 || strlen($login) <= 0 || strlen($jid) <= 0) {
         return false;
     }
     $this->id = $id;
     $this->login = $login;
     $this->provider = $provider;
     $this->jid = strtolower($jid);
     $this->resource = $resource;
     $server = CXMPPServer::GetServer();
     $server->_IndexClient($this->jid, $this->xmppId, $this->GetClientDomain());
     $this->authenticated = true;
     CXMPPUtility::Show("Authenticate " . $this->jid . " (" . $this->xmppId . ")", 5);
     $this->ChangeWorkPresence("Authenticate", "");
     CXMPPClient::SetLastActivityDate($this->id, time(), true);
     return true;
 }
Esempio n. 9
0
 private function __ReportKernel()
 {
     foreach ($this->arClientsIndex as $clientDomain => $arDomainClientsIndex) {
         if (!CXMPPUtility::SelectDatabase($clientDomain)) {
             continue;
         }
         if (count($arDomainClientsIndex) <= 0) {
             continue;
         }
         foreach ($arDomainClientsIndex as $jid => $arId) {
             foreach ($arId as $id) {
                 if (array_key_exists($id, $this->arClients)) {
                     if ($this->arClients[$id]->IsConnected() && $this->arClients[$id]->IsAuthenticated()) {
                         $idTmp = $this->arClients[$id]->GetId();
                         CUser::SetLastActivityDate($idTmp);
                         CXMPPClient::SetLastActivityDate($idTmp);
                     }
                 }
             }
         }
         $arOnlineOnSiteTmp = array();
         $dbUsers = CUser::GetList($b = "LOGIN", $o = "DESC", array("ACTIVE" => "Y", "LAST_ACTIVITY" => 600, "!UF_DEPARTMENT" => false), array('FIELDS' => array('ID', 'LOGIN')));
         while ($arUser = $dbUsers->Fetch()) {
             $arOnlineOnSiteTmp[] = CXMPPUtility::GetJId($arUser, $clientDomain);
         }
         if (!is_array($this->arOnlineOnSite[$clientDomain])) {
             $this->arOnlineOnSite[$clientDomain] = array();
         }
         $arOffline = array_diff($this->arOnlineOnSite[$clientDomain], $arOnlineOnSiteTmp);
         foreach ($arOffline as $jid) {
             if (!array_key_exists($jid, $this->arClientsIndex[$clientDomain]) || array_key_exists($jid, $this->arClientsIndex[$clientDomain]) && count($this->arClientsIndex[$clientDomain][$jid]) <= 0) {
                 $this->SendAll(array("presence" => array("." => array("type" => "unavailable", "from" => $jid))));
             }
         }
         $arOnline = array_diff($arOnlineOnSiteTmp, $this->arOnlineOnSite[$clientDomain]);
         foreach ($arOnline as $jid) {
             if (!array_key_exists($jid, $this->arClientsIndex[$clientDomain]) || array_key_exists($jid, $this->arClientsIndex[$clientDomain]) && count($this->arClientsIndex[$clientDomain][$jid]) <= 0) {
                 $this->SendAll(array("presence" => array("." => array("from" => $jid))));
             }
         }
         $this->arOnlineOnSite[$clientDomain] = $arOnlineOnSiteTmp;
     }
 }
Esempio n. 10
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (!$senderClient->IsAuthenticated()) {
         return false;
     }
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("iq", $arMessage) || !array_key_exists("vcard", $arMessage["iq"]) || $arMessage["iq"]["vcard"]["."]["xmlns"] != "vcard-temp") {
         return false;
     }
     $type = "";
     if (array_key_exists("type", $arMessage["iq"]["."])) {
         $type = $arMessage["iq"]["."]["type"];
     }
     if ($type == "get") {
         $to = $arMessage["iq"]["."]["to"];
         $arUser = CXMPPUtility::GetUserByJId($to);
         if ($arUser) {
             $photoType = "";
             $photo = "";
             if (intval($arUser["PERSONAL_PHOTO"]) > 0) {
                 $imageFile = CFile::GetFileArray($arUser["PERSONAL_PHOTO"]);
                 if ($imageFile !== false) {
                     $arFileTmp = CFile::ResizeImageGet($imageFile, array("width" => 300, "height" => 300), BX_RESIZE_IMAGE_PROPORTIONAL, false);
                     if (is_array($arFileTmp)) {
                         $arFileTmp = CFile::MakeFileArray($arFileTmp["src"]);
                     }
                     $photoType = $imageFile["CONTENT_TYPE"];
                     if (File_Exists($arFileTmp["tmp_name"])) {
                         $photo = File_Get_Contents($arFileTmp["tmp_name"]);
                         $photo = Base64_Encode($photo);
                     }
                 }
             }
             if (empty($photo)) {
                 $photoType = "image/gif";
                 if (File_Exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/images/socialnetwork/nopic_user_150.gif")) {
                     $photo = File_Get_Contents($_SERVER["DOCUMENT_ROOT"] . "/bitrix/images/socialnetwork/nopic_user_150.gif");
                     $photo = Base64_Encode($photo);
                 }
             }
             $arResult = array("iq" => array("." => array("type" => "result", "from" => $to, "to" => $senderJId, "id" => $arMessage['iq']['.']['id']), "vCard" => array("." => array("xmlns" => "vcard-temp", "prodid" => '-//HandGen//NONSGML vGen v1.0//EN', "version" => '2.0'), "FN" => array("#" => CUser::FormatName($this->nameTemplate, $arUser)), "N" => array("FAMILY" => array("#" => $arUser["LAST_NAME"]), "GIVEN" => array("#" => $arUser["NAME"]), "MIDDLE" => array("#" => $arUser["SECOND_NAME"])), "NICKNAME" => array("#" => CUser::FormatName($this->nameTemplate, $arUser)), "BDAY" => array("#" => ConvertDateTime($arUser["PERSONAL_BIRTHDAY"], "YYYY-MM-DD", SITE_ID)), "ORG" => array("ORGNAME" => array("#" => $arUser["WORK_COMPANY"]), "ORGUNIT" => array("#" => $arUser["WORK_DEPARTMENT"])), "TITLE" => array("#" => $arUser["WORK_POSITION"]), "EMAIL" => array("INTERNET" => array("#" => ""), "PREF" => array("#" => ""), "USERID" => array("#" => $arUser["EMAIL"])), "JABBERID" => array("#" => $to), "PHOTO" => array("TYPE" => array("#" => $photoType), "BINVAL" => array("#" => $photo)))));
             if (strlen($arUser["WORK_FAX"]) > 0) {
                 $arResult["iq"]["vCard"]["TEL"][] = array("WORK" => array("#" => ""), "FAX" => array("#" => ""), "NUMBER" => array("#" => $arUser["WORK_FAX"]));
             }
             if (strlen($arUser["PERSONAL_MOBILE"]) > 0) {
                 $arResult["iq"]["vCard"]["TEL"][] = array("HOME" => array("#" => ""), "CELL" => array("#" => ""), "NUMBER" => array("#" => $arUser["PERSONAL_MOBILE"]));
             }
             if (strlen($arUser["WORK_PHONE"]) > 0) {
                 $arResult["iq"]["vCard"]["TEL"][] = array("WORK" => array("#" => ""), "VOICE" => array("#" => ""), "NUMBER" => array("#" => $arUser["WORK_PHONE"]));
             }
             if (strlen($arUser["PERSONAL_PHONE"]) > 0) {
                 $arResult["iq"]["vCard"]["TEL"][] = array("HOME" => array("#" => ""), "VOICE" => array("#" => ""), "NUMBER" => array("#" => $arUser["PERSONAL_PHONE"]));
             }
             if (strlen($arUser["PERSONAL_FAX"]) > 0) {
                 $arResult["iq"]["vCard"]["TEL"][] = array("HOME" => array("#" => ""), "FAX" => array("#" => ""), "NUMBER" => array("#" => $arUser["PERSONAL_FAX"]));
             }
             if (strlen($arUser["WORK_STREET"]) > 0 || strlen($arUser["WORK_CITY"]) > 0 || strlen($arUser["WORK_COUNTRY"]) > 0) {
                 $arResult["iq"]["vCard"]["ADR"][] = array("WORK" => array("#" => ""), "EXTADD" => array("#" => ""), "STREET" => array("#" => $arUser["WORK_STREET"]), "LOCALITY" => array("#" => $arUser["WORK_CITY"]), "REGION" => array("#" => $arUser["WORK_STATE"]), "PCODE" => array("#" => $arUser["WORK_ZIP"]), "CTRY" => array("#" => GetCountryByID($arUser["WORK_COUNTRY"])));
             }
             if (strlen($arUser["PERSONAL_STREET"]) > 0 || strlen($arUser["PERSONAL_CITY"]) > 0 || strlen($arUser["PERSONAL_COUNTRY"]) > 0) {
                 $arResult["iq"]["vCard"]["ADR"][] = array("HOME" => array("#" => ""), "EXTADD" => array("#" => ""), "STREET" => array("#" => $arUser["PERSONAL_STREET"]), "LOCALITY" => array("#" => $arUser["PERSONAL_CITY"]), "REGION" => array("#" => $arUser["PERSONAL_STATE"]), "PCODE" => array("#" => $arUser["PERSONAL_ZIP"]), "CTRY" => array("#" => GetCountryByID($arUser["PERSONAL_COUNTRY"])));
             }
             if ($senderJId != $to) {
                 $arResult["iq"]["."]["from"] = $to;
             }
             //print_r($arResult);echo "\n*****************************************\n";
         } else {
             $arResult = array("iq" => array("." => array("type" => "error", "to" => $senderJId, "id" => $arMessage['iq']['.']['id']), "vCard" => array("." => array("xmlns" => "vcard-temp")), "error" => array("." => array("type" => "cancel"), "item-not-found" => array("." => array("xmlns" => "urn:ietf:params:xml:ns:xmpp-stanzas")))));
             if ($senderJId != $to) {
                 $arResult["iq"]["."]["from"] = $to;
             }
         }
     } elseif ($type == "set") {
         $arResult = array("iq" => array("." => array("type" => "result", "from" => $senderClient->GetClientDomain(), "id" => $arMessage['iq']['.']['id'])));
     }
     return $arResult;
 }
Esempio n. 11
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if ($senderClient->IsAuthenticated() && !array_key_exists("stream:stream", $arMessage)) {
         return false;
     }
     $server = CXMPPServer::GetServer();
     $arResult = true;
     if (array_key_exists("stream:stream", $arMessage)) {
         if ($senderClient->IsAuthenticated()) {
             $senderClient->SetStreamId("bx" . rand(1000, 9999));
             $message = sprintf('<' . '?xml version="1.0" encoding="UTF-8"?' . '><stream:stream xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" id="%s" from="%s" version="1.0"><stream:features><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/><ping xmlns="urn:xmpp:ping"/></stream:features>', $senderClient->GetStreamId(), htmlspecialcharsbx($senderClient->GetClientDomain()));
             $senderClient->__Send($message);
         } else {
             $version = "";
             if (is_array($arMessage["stream:stream"]["."]) && array_key_exists("version", $arMessage["stream:stream"]["."])) {
                 $version = $arMessage["stream:stream"]["."]["version"];
             }
             $to = "";
             if (is_array($arMessage["stream:stream"]["."]) && array_key_exists("to", $arMessage["stream:stream"]["."])) {
                 $to = $arMessage["stream:stream"]["."]["to"];
             }
             if (CXMPPUtility::IsBitrix24Mode()) {
                 $senderClient->SetClientDomain($to);
             } else {
                 $senderClient->SetClientDomain(CXMPPServer::GetDomain());
             }
             if (CXMPPUtility::SelectDatabase($senderClient->GetClientDomain())) {
                 $bAllowSasl = false;
                 if (strlen($version) > 0) {
                     $ar = explode(".", $version);
                     $majorV = intval($ar[0]);
                     if ($majorV >= 1) {
                         $bAllowSasl = true;
                     }
                 }
                 if ($bAllowSasl) {
                     $senderClient->SetAuthenticationType("SASL");
                 } else {
                     $senderClient->SetAuthenticationType("NON-SASL");
                 }
                 if ($bAllowSasl) {
                     $message = sprintf('<?xml version="1.0"?><stream:stream xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" id="%s" from="%s" version="1.0"><stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism></mechanisms><auth xmlns="http://jabber.org/features/iq-auth"/></stream:features>', rand(1000, 9999), htmlspecialcharsbx($senderClient->GetClientDomain()));
                 } else {
                     $message = sprintf('<?xml version="1.0"?><stream:stream xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" id="%s" from="%s">', rand(1000, 9999), htmlspecialcharsbx($senderClient->GetClientDomain()));
                 }
                 $senderClient->__Send($message);
             } else {
                 $senderClient->Disconnect();
             }
         }
     } elseif (array_key_exists("auth", $arMessage) && $senderClient->GetAuthenticationType() == "SASL") {
         $mechanism = "PLAIN";
         if (array_key_exists("mechanism", $arMessage["auth"]["."])) {
             $mechanism = strtoupper($arMessage["auth"]["."]["mechanism"]);
         }
         $message = '';
         if ($mechanism == "PLAIN") {
             $r = base64_decode($arMessage["auth"]["#"]);
             if (strlen($r) > 0) {
                 if (substr($r, 0, 1) == "") {
                     $r = "z" . $r;
                 }
                 $arResp = explode("", $r);
                 $jid = $arResp[0];
                 $login = $arResp[1];
                 $pwd = $arResp[2];
                 if (strlen($login) > 0) {
                     $authResult = $GLOBALS["USER"]->Login($login, $pwd, "N");
                     CXMPPUtility::Show("!S " . $login . ": " . (is_array($authResult) ? Print_R($authResult, true) : $authResult), 0);
                     if ($authResult === true) {
                         $message = '<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>';
                         $senderClient->_Authenticate($GLOBALS["USER"]->GetID(), $login, CXMPPUtility::GetJId(array("LOGIN" => $login), $senderClient->GetClientDomain()), false, $arMessage['iq']['query']['resource']['#']);
                     } else {
                         $message = '<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure></stream:stream>';
                     }
                 } else {
                     $message = '<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><temporary-auth-failure/></failure></stream:stream>';
                 }
             } else {
                 $message = '<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><temporary-auth-failure/></failure></stream:stream>';
             }
         } else {
             $message = '<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><invalid-mechanism/></failure></stream:stream>';
         }
         $senderClient->__Send($message);
     } elseif (array_key_exists("iq", $arMessage) && $senderClient->GetAuthenticationType() == "NON-SASL") {
         $message = '';
         if ($arMessage['iq']['query']['.']['xmlns'] == 'jabber:iq:auth') {
             $type = $arMessage['iq']['.']['type'];
             if (!in_array($type, array("get", "set"))) {
                 return;
             }
             if ($type == 'get') {
                 $message = sprintf('<iq type="result" id="%s" from="%s"><query xmlns="%s"><username>%s</username><password/><resource/></query></iq>', htmlspecialcharsbx($arMessage['iq']['.']['id']), htmlspecialcharsbx($senderClient->GetClientDomain()), htmlspecialcharsbx($arMessage['iq']['query']['.']['xmlns']), htmlspecialcharsbx($arMessage['iq']['query']['username']['#']));
             } elseif ($type == 'set') {
                 $username = $arMessage['iq']['query']['username']['#'];
                 $password = $arMessage['iq']['query']['password']['#'];
                 $authResult = $GLOBALS["USER"]->Login($username, $password, "N");
                 CXMPPUtility::Show("!N " . $username . ": " . (is_array($authResult) ? print_r($authResult, true) : $authResult), 0);
                 if ($authResult === true) {
                     $message = sprintf('<iq type="result" id="%s" from="%s"/>', htmlspecialcharsbx($arMessage['iq']['.']['id']), htmlspecialcharsbx($senderClient->GetClientDomain()));
                     $senderClient->_Authenticate($GLOBALS["USER"]->GetID(), $username, CXMPPUtility::GetJId(array("LOGIN" => $username), $senderClient->GetClientDomain()), false, $arMessage['iq']['query']['resource']['#']);
                 } else {
                     $message = sprintf('<iq type="error" id="%s" from="%s"><error code="401" type="auth"><not-authorized xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>', htmlspecialcharsbx($arMessage['iq']['.']['id']), htmlspecialcharsbx($senderClient->GetClientDomain()));
                 }
             }
         } else {
             $message = '<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><invalid-mechanism/></failure></stream:stream>';
         }
         $senderClient->__Send($message);
     }
     return $arResult;
 }
Esempio n. 12
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (!$senderClient->IsAuthenticated()) {
         return false;
     }
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("presence", $arMessage) || !array_key_exists(".", $arMessage["presence"])) {
         return false;
     }
     $type = "available";
     if (array_key_exists("type", $arMessage["presence"]["."])) {
         $type = $arMessage["presence"]["."]["type"];
     }
     if ($type == "error") {
         return false;
     }
     // available (empty) - Signals that the sender is online and available for communication.
     // unavailable - Signals that the sender is no longer available for communication.
     // subscribe - The sender wishes to subscribe to the recipient's presence.
     // subscribed - The sender has allowed the recipient to receive their presence.
     // unsubscribe - The sender is unsubscribing from another entity's presence.
     // unsubscribed - The subscription request has been denied or a previously-granted subscription has been cancelled.
     // probe - A request for an entity's current presence; SHOULD be generated only by a server on behalf of a user.
     // error - An error has occurred regarding processing or delivery of a previously-sent presence stanza.
     if (!in_array($type, array("available", "unavailable", "subscribe", "subscribed", "unsubscribe", "unsubscribed", "probe"))) {
         return CXMPPUtility::GetErrorArray($senderJId, "presence", "modify", "bad-request", "", "", "", $senderClient->GetClientDomain());
     }
     $to = "";
     if (array_key_exists("to", $arMessage["presence"]["."])) {
         $to = $arMessage["presence"]["."]["to"];
     }
     $server = CXMPPServer::GetServer();
     if (strlen($to) <= 0) {
         $server->SendAll($arMessage, $senderClient->GetClientDomain());
     } else {
         $server->Send($to, $arMessage, $senderClient->GetClientDomain());
     }
     if (!in_array($type, array("available"))) {
         return true;
     }
     $userJId = $senderJId;
     $show = "online";
     if (array_key_exists("show", $arMessage["presence"])) {
         $show = $arMessage["presence"]["show"]["#"];
     }
     $status = "";
     if (array_key_exists("status", $arMessage["presence"])) {
         $status = $arMessage["presence"]["status"]["#"];
     }
     $priority = 0;
     if (array_key_exists("priority", $arMessage["presence"])) {
         $priority = intval($arMessage["presence"]["priority"]["#"]);
     }
     $arUser = CXMPPUtility::GetUserByJId($userJId);
     if (!$arUser) {
         return CXMPPUtility::GetErrorArray($senderJId, "presence", "auth", "forbidden", "", "", "", $senderClient->GetClientDomain());
     }
     CUser::SetLastActivityDate($arUser["ID"]);
     CXMPPFactory::SendUnreadMessages($senderJId, $senderClient->GetClientDomain());
     $senderClient->ChangeWorkPresence("Status", $show);
     return true;
 }