if (!defined("LIVEZILLA_PATH")) { define("LIVEZILLA_PATH", "./"); } require LIVEZILLA_PATH . "_definitions/definitions.inc.php"; require LIVEZILLA_PATH . "_lib/functions.global.inc.php"; require LIVEZILLA_PATH . "_definitions/definitions.dynamic.inc.php"; require LIVEZILLA_PATH . "_definitions/definitions.protocol.inc.php"; require LIVEZILLA_PATH . "_lib/functions.external.inc.php"; @set_error_handler("handleError"); @error_reporting(E_ALL); header("Pragma: no-cache"); header("Cache-Control: no-cache, must-revalidate"); header("Keep-Alive: timeout=5, max=100"); Server::InitDataProvider(); if (!empty($_GET["value"]) && strlen($_GET["value"]) == 16) { $ticket = VisitorChat::GetMatchingVoucher($_GET[GET_EXTERN_GROUP], $_GET["value"]); if (!empty($ticket) && !$ticket->CheckForVoid() && $ticket->Paid) { $ticket->UpdateVoucherChatTime(0, empty($ticket->FirstUsed)); $sessions = $ticket->ChatSessionsMax < 0 ? 0 : $ticket->ChatSessionsMax; if ($result = DBManager::Execute(true, "SELECT `exit` FROM `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` WHERE `chat_ticket_id`='" . DBManager::RealEscape($ticket->Id) . "' AND `exit`=0 LIMIT 1;")) { if ($row = DBManager::FetchArray($result)) { exit("lz_validate_com_chat_input_result(false,true,1,'',0,0,0,false,false,false);"); } } exit("lz_validate_com_chat_input_result(true,false,1,'" . $ticket->Id . "'," . $ticket->ChatTime . "," . $ticket->ChatTimeMax . "," . $ticket->ChatSessions . "," . $ticket->ChatSessionsMax . "," . $ticket->VoucherAutoExpire . "," . To::BoolString($ticket->VoucherAutoExpire < time()) . ");"); } else { if (!empty($ticket)) { exit("lz_validate_com_chat_input_result(false,false,1,'',0,0,0,false,false,false);"); } } }
static function Listen($_user, $init = false) { global $USER, $VOUCHER; $USER = $_user; if (!(IS_FILTERED && !FILTER_ALLOW_CHATS)) { if (!empty($_POST["p_tid"])) { $VOUCHER = VisitorChat::GetMatchingVoucher(Encoding::Base64UrlDecode($_POST[POST_EXTERN_USER_GROUP]), Encoding::Base64UrlDecode($_POST["p_tid"])); if ($VOUCHER != null) { $USER->Browsers[0]->ChatVoucherId = $VOUCHER->Id; } } if (empty($USER->Browsers[0]->ChatId)) { $USER->Browsers[0]->SetChatId(); $init = true; } if ($USER->Browsers[0]->Status == CHAT_STATUS_OPEN) { Server::InitDataBlock(array("INTERNAL")); if (!empty($_POST[POST_EXTERN_USER_GROUP]) && (empty($USER->Browsers[0]->DesiredChatGroup) || $init)) { $USER->Browsers[0]->DesiredChatGroup = Encoding::Base64UrlDecode($_POST[POST_EXTERN_USER_GROUP]); } $USER->Browsers[0]->SetCookieGroup(); $result = $USER->Browsers[0]->FindOperator(VisitorChat::$Router, $USER); if (!$result && VisitorChat::$Router->OperatorsBusy == 0) { $USER->AddFunctionCall("lz_chat_add_system_text(8,null);", false); $USER->AddFunctionCall("lz_chat_stop_system();", false); } else { if (count(VisitorChat::$Router->OperatorsAvailable) + VisitorChat::$Router->OperatorsBusy > 0) { $USER->AddFunctionCall("lz_chat_set_id('" . $USER->Browsers[0]->ChatId . "');", false); $chatPosition = VisitorChat::$Router->GetQueuePosition($USER->Browsers[0]->DesiredChatGroup); $chatWaitingTime = VisitorChat::$Router->GetQueueWaitingTime($chatPosition); ExternalChat::Login($USER, Server::$Groups[$USER->Browsers[0]->DesiredChatGroup]); $USER->Browsers[0]->SetWaiting(empty(VisitorChat::$DynamicGroup) && !($chatPosition == 1 && count(VisitorChat::$Router->OperatorsAvailable) > 0 && !(!empty($USER->Browsers[0]->DesiredChatPartner) && Server::$Operators[$USER->Browsers[0]->DesiredChatPartner]->Status == USER_STATUS_BUSY))); if (!$USER->Browsers[0]->Waiting) { $USER->Browsers[0]->ShowConnecting($USER); $USER->AddFunctionCall("lz_chat_set_status(lz_chat_data.STATUS_ALLOCATED);", false); if (Server::$Configuration->File["gl_alloc_mode"] != ALLOCATION_MODE_ALL || !empty($USER->Browsers[0]->DesiredChatPartner) || !empty(VisitorChat::$DynamicGroup)) { $USER->Browsers[0]->CreateChat(Server::$Operators[$USER->Browsers[0]->DesiredChatPartner], $USER, true); } else { $run = 0; foreach (VisitorChat::$Router->OperatorsAvailable as $intid => $am) { $USER->Browsers[0]->CreateChat(Server::$Operators[$intid], $USER, false, "", "", true, $run++ == 0); } } } else { if (!empty($_GET["acid"])) { $USER->Browsers[0]->ShowConnecting($USER); $pchatid = Encoding::Base64UrlDecode($_GET["acid"]); $result = DBManager::Execute(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` WHERE `visitor_id`='" . DBManager::RealEscape($USER->Browsers[0]->UserId) . "' AND `chat_id`='" . DBManager::RealEscape($pchatid) . "' AND (`exit` > " . (time() - 30) . " OR `exit`=0) LIMIT 1;"); if ($result && DBManager::GetRowCount($result) == 1) { $row = DBManager::FetchArray($result); if (!empty($row["waiting"])) { $posts = unserialize($row["queue_posts"]); foreach ($posts as $post) { $USER->AddFunctionCall("lz_chat_repost_from_queue('" . $post[0] . "');", false); } $USER->AddFunctionCall("lz_chat_data.QueuePostsAdded = true;", false); } } } if ($USER->Browsers[0]->IsMaxWaitingTime(true)) { displayDeclined(); return $USER; } if (empty($_GET["acid"])) { $USER->Browsers[0]->ShowQueueInformation($USER, $chatPosition, $chatWaitingTime, LocalizationManager::$TranslationStrings["client_queue_message"]); $gqmt = $USER->Browsers[0]->ShowGroupQueueInformation($USER, $USER->Browsers[0]->QueueMessageShown); if (!empty($gqmt)) { $USER->AddFunctionCall("lz_chat_add_system_text(99,'" . base64_encode($gqmt) . "');", false); } } if (!VisitorChat::$Router->WasTarget && !empty($USER->Browsers[0]->DesiredChatPartner)) { $USER->Browsers[0]->DesiredChatPartner = ""; } $USER->Browsers[0]->CreateArchiveEntry(null, $USER); } } } } else { $action = $USER->Browsers[0]->GetMaxWaitingTimeAction(false); if ($action == "MESSAGE" || $action == "FORWARD" && !$USER->Browsers[0]->CreateAutoForward($USER)) { $USER->Browsers[0]->InternalDecline(Server::$Operators[$USER->Browsers[0]->OperatorId]->SystemId); displayDeclined(); } else { if (empty($USER->Browsers[0]->ArchiveCreated) && !empty($USER->Browsers[0]->DesiredChatPartner)) { $USER->Browsers[0]->CreateChat(Server::$Operators[$USER->Browsers[0]->DesiredChatPartner], $USER, true); } activeListen(); } } if ($USER->Browsers[0]->Status <= CHAT_STATUS_WAITING && empty($_POST["p_wls"]) && empty(VisitorChat::$DynamicGroup)) { $USER->AddFunctionCall("lz_chat_show_waiting_links('" . base64_encode($wl = Server::$Groups[$USER->Browsers[0]->DesiredChatGroup]->GetWaitingLinks($USER->Browsers[0]->UserData->Text, Visitor::$BrowserLanguage)) . "');", false); } } else { displayFiltered(); } return $USER; }
function processForward() { global $USER, $GROUPS, $VOUCHER; $USER->Browsers[0]->LoadForward(); if (!empty($USER->Browsers[0]->Forward) && !$USER->Browsers[0]->Forward->Invite && !empty($USER->Browsers[0]->Forward->TargetGroupId) && !$USER->Browsers[0]->Forward->Processed) { if (!empty($VOUCHER) && !in_array($VOUCHER->TypeId, $GROUPS[$USER->Browsers[0]->Forward->TargetGroupId]->ChatVouchersRequired)) { $USER->AddFunctionCall("lz_chat_switch_com_chat_box(false);", false); } else { if (!empty($GROUPS[$USER->Browsers[0]->Forward->TargetGroupId]->ChatVouchersRequired)) { $VOUCHER = VisitorChat::GetMatchingVoucher($USER->Browsers[0]->Forward->TargetGroupId, base64UrlDecode($_POST["p_tid"])); if ($VOUCHER != null) { $USER->AddFunctionCall("lz_chat_switch_com_chat_box(true);", false); } } } $USER->AddFunctionCall("lz_chat_initiate_forwarding('" . base64_encode($USER->Browsers[0]->Forward->TargetGroupId) . "'," . parseBool($USER->Browsers[0]->Forward->Auto) . ");", false); $USER->Browsers[0]->LeaveChat($USER->Browsers[0]->Forward->InitiatorSystemId); $USER->Browsers[0]->Forward->Save(true); $USER->Browsers[0]->ExternalClose(); $USER->Browsers[0]->DesiredChatGroup = $USER->Browsers[0]->Forward->TargetGroupId; $USER->Browsers[0]->DesiredChatPartner = $USER->Browsers[0]->Forward->TargetSessId; $USER->Browsers[0]->FirstActive = time(); $USER->Browsers[0]->Save(true); $USER->Browsers[0]->SetCookieGroup(); } }
function BuildChatXML() { global $USER, $BROWSER, $GROUPS, $INPUTS; initData(array("INPUTS")); if ($this->CurrentResponseType == DATA_RESPONSE_TYPE_KEEP_ALIVE) { $this->CurrentResponseType = DATA_RESPONSE_TYPE_BASIC; } if ($this->GetAll) { $this->CurrentResponseType = DATA_RESPONSE_TYPE_STATIC; } if (!$BROWSER->Closed && ($BROWSER->Status > CHAT_STATUS_OPEN || $BROWSER->Waiting)) { if (!empty($BROWSER->DesiredChatGroup)) { $pra = !empty($BROWSER->Members[CALLER_SYSTEM_ID]) ? " pra=\"" . base64_encode($BROWSER->PostsReceived(CALLER_SYSTEM_ID)) . "\"" : ""; $cti = ""; $USER->IsChat = true; $this->XMLCurrentChat = "<chat id=\"" . base64_encode($BROWSER->ChatId) . "\" d=\"" . base64_encode(!empty($BROWSER->Declined) ? 1 : 0) . "\" p=\"" . base64_encode($BROWSER->Priority) . "\" f=\"" . base64_encode($BROWSER->FirstActive) . "\" q=\"" . base64_encode($BROWSER->Status > CHAT_STATUS_OPEN ? "0" : "1") . "\" cmb=\"" . base64_encode($BROWSER->CallMeBack) . "\" st=\"" . base64_encode($BROWSER->Activated) . "\" fn=\"" . base64_encode($BROWSER->GetInputData(111)) . "\" em=\"" . base64_encode($BROWSER->GetInputData(112)) . "\" eq=\"" . base64_encode($BROWSER->GetInputData(114)) . "\" gr=\"" . base64_encode($BROWSER->DesiredChatGroup) . "\" dcp=\"" . base64_encode($BROWSER->DesiredChatPartner) . "\" at=\"" . base64_encode($BROWSER->AllocatedTime) . "\" cp=\"" . base64_encode($BROWSER->GetInputData(116)) . "\" co=\"" . base64_encode($BROWSER->GetInputData(113)) . "\"" . $pra . $cti . ">\r\n"; foreach ($GROUPS as $groupid => $group) { if ($group->IsDynamic) { foreach ($group->Members as $member => $persistent) { if ($member == $BROWSER->SystemId) { $this->XMLCurrentChat .= "<gr p=\"" . base64_encode($persistent ? "1" : "0") . "\">" . base64_encode($groupid) . "</gr>\r\n"; } } } } if (is_array($BROWSER->Customs)) { foreach ($BROWSER->Customs as $index => $value) { if ($INPUTS[$index]->Active && $INPUTS[$index]->Custom) { $value = $INPUTS[$index]->Type == "Text" ? $BROWSER->GetInputData($index) : $value; $this->XMLCurrentChat .= " <cf index=\"" . base64_encode($index) . "\">" . base64_encode($INPUTS[$index]->GetClientValue($value)) . "</cf>\r\n"; } } } $this->XMLCurrentChat .= " <pn acc=\"" . base64_encode($BROWSER->Activated ? "1" : "0") . "\">\r\n"; foreach ($BROWSER->Members as $systemid => $member) { $this->XMLCurrentChat .= "<member id=\"" . base64_encode($systemid) . "\" st=\"" . base64_encode($member->Status) . "\" dec=\"" . base64_encode($member->Declined ? 1 : 0) . "\" />\r\n"; } $this->XMLCurrentChat .= " </pn>\r\n"; if (!empty($BROWSER->ChatVoucherId)) { $chatticket = VisitorChat::GetMatchingVoucher($BROWSER->DesiredChatGroup, $BROWSER->ChatVoucherId); if (!empty($chatticket)) { $this->XMLCurrentChat .= "<cticket>" . $chatticket->GetXML(true) . "</cticket>\r\n"; } } $v_tp = 0; if (!empty($BROWSER->Members[CALLER_SYSTEM_ID])) { if ($BROWSER->Activated == 0) { $BROWSER->LoadForward(false, true); if (!empty($BROWSER->Forward) && ($BROWSER->Forward->TargetSessId == CALLER_SYSTEM_ID || empty($BROWSER->Forward->TargetSessId))) { $BROWSER->RepostChatHistory(3, $BROWSER->ChatId, CALLER_SYSTEM_ID, 0, 0, "", "", "", false, false); $BROWSER->Forward->Destroy(); } else { $BROWSER->RepostChatHistory(3, $BROWSER->ChatId, CALLER_SYSTEM_ID, 0, 0, "", "", "", false, false); } } $v_tp = $BROWSER->Typing ? 1 : 0; } if (isset($this->Caller->ExternalChats[$BROWSER->SystemId]) && !empty($this->Caller->ExternalChats[$BROWSER->SystemId]->FileUploadRequest)) { foreach ($this->Caller->ExternalChats[$BROWSER->SystemId]->FileUploadRequest as $request) { if ($request->Error && $request->Permission != PERMISSION_NONE) { if (!$request->Closed) { $request->Close(); } $this->XMLCurrentChat .= " <fupr id=\"" . base64_encode($request->Id) . "\" cr=\"" . base64_encode($request->Created) . "\" fm=\"" . base64_encode($request->FileMask) . "\" fn=\"" . base64_encode($request->FileName) . "\" fid=\"" . base64_encode($request->FileId) . "\" cid=\"" . base64_encode($request->ChatId) . "\" error=\"" . base64_encode(true) . "\" />\r\n"; } else { if ($request->Download) { $this->XMLCurrentChat .= " <fupr pm=\"" . base64_encode($request->Permission) . "\" id=\"" . base64_encode($request->Id) . "\" cr=\"" . base64_encode($request->Created) . "\" fm=\"" . base64_encode($request->FileMask) . "\" fn=\"" . base64_encode($request->FileName) . "\" cid=\"" . base64_encode($request->ChatId) . "\" fid=\"" . base64_encode($request->FileId) . "\" download=\"" . base64_encode(true) . "\" size=\"" . base64_encode(@filesize($request->GetFile())) . "\" />\r\n"; } else { if ($request->Permission == PERMISSION_VOID) { $this->XMLCurrentChat .= " <fupr id=\"" . base64_encode($request->Id) . "\" cr=\"" . base64_encode($request->Created) . "\" fm=\"" . base64_encode($request->FileMask) . "\" fn=\"" . base64_encode($request->FileName) . "\" fid=\"" . base64_encode($request->FileId) . "\" cid=\"" . base64_encode($request->ChatId) . "\" />\r\n"; } else { if ($request->Permission == PERMISSION_NONE) { $this->XMLCurrentChat .= " <fupr pm=\"" . base64_encode($request->Permission) . "\" id=\"" . base64_encode($request->Id) . "\" cr=\"" . base64_encode($request->Created) . "\" fm=\"" . base64_encode($request->FileMask) . "\" fn=\"" . base64_encode($request->FileName) . "\" cid=\"" . base64_encode($request->ChatId) . "\" fid=\"" . base64_encode($request->FileId) . "\" />\r\n"; } else { if ($request->Permission == PERMISSION_CHAT_ARCHIVE) { $this->XMLCurrentChat .= " <fupr pm=\"" . base64_encode($request->Permission) . "\" id=\"" . base64_encode($request->Id) . "\" cr=\"" . base64_encode($request->Created) . "\" fm=\"" . base64_encode($request->FileMask) . "\" fn=\"" . base64_encode($request->FileName) . "\" cid=\"" . base64_encode($request->ChatId) . "\" fid=\"" . base64_encode($request->FileId) . "\" />\r\n"; } } } } } } } $this->XMLCurrentChat .= " </chat>\r\n"; $this->XMLTyping .= "<v id=\"" . base64_encode($BROWSER->UserId . "~" . $BROWSER->BrowserId) . "\" tp=\"" . base64_encode($v_tp) . "\" />\r\n"; } else { $this->XMLCurrentChat = " <chat />\r\n"; } } }
define("LIVEZILLA_PATH", "./"); } require LIVEZILLA_PATH . "_definitions/definitions.inc.php"; require LIVEZILLA_PATH . "_lib/objects.global.users.inc.php"; require LIVEZILLA_PATH . "_lib/functions.global.inc.php"; require LIVEZILLA_PATH . "_definitions/definitions.dynamic.inc.php"; require LIVEZILLA_PATH . "_definitions/definitions.protocol.inc.php"; require LIVEZILLA_PATH . "_lib/functions.external.inc.php"; @set_error_handler("handleError"); @error_reporting(E_ALL); header("Pragma: no-cache"); header("Cache-Control: no-cache, must-revalidate"); header("Keep-Alive: timeout=5, max=100"); initDataProvider(); if (!empty($_GET["value"]) && strlen($_GET["value"]) == 16) { $ticket = VisitorChat::GetMatchingVoucher($_GET["intgroup"], $_GET["value"]); if (!empty($ticket) && !$ticket->CheckForVoid() && $ticket->Paid) { $ticket->UpdateVoucherChatTime(0, empty($ticket->FirstUsed)); $sessions = $ticket->ChatSessionsMax < 0 ? 0 : $ticket->ChatSessionsMax; if ($result = queryDB(true, "SELECT `exit` FROM `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` WHERE `chat_ticket_id`='" . DBManager::RealEscape($ticket->Id) . "' AND `exit`=0 LIMIT 1;")) { if ($row = DBManager::FetchArray($result)) { exit("lz_validate_com_chat_input_result(false,true,1,'',0,0,0,false,false,false);"); } } exit("lz_validate_com_chat_input_result(true,false,1,'" . $ticket->Id . "'," . $ticket->ChatTime . "," . $ticket->ChatTimeMax . "," . $ticket->ChatSessions . "," . $ticket->ChatSessionsMax . "," . $ticket->VoucherAutoExpire . "," . parseBool($ticket->VoucherAutoExpire < time()) . ");"); } else { if (!empty($ticket)) { exit("lz_validate_com_chat_input_result(false,false,1,'',0,0,0,false,false,false);"); } } }