$rsSites = CSite::GetByID(CExtranet::GetExtranetSiteID()); if (($arExtranetSite = $rsSites->Fetch()) && $arExtranetSite["ACTIVE"] != "N") { $data["whiteList"] = array($arExtranetSite["DIR"] . "mobile/"); $data["appmap"] = array("main" => array("url" => $arExtranetSite["DIR"] . "mobile/index.php", "bx24ModernStyle" => true), "menu" => array("url" => $arExtranetSite["DIR"] . "mobile/left.php"), "right" => array("url" => $arExtranetSite["DIR"] . "mobile/im/right.php")); if (\Bitrix\MobileApp\Mobile::getInstance()->getApiVersion() >= 10) { $data["appmap"]["right"] = array("url" => $arExtranetSite["DIR"] . "mobile/im/right.php"); } } } if (toUpper(SITE_CHARSET) != "UTF-8") { $data = $APPLICATION->ConvertCharsetArray($data, SITE_CHARSET, "utf-8"); } } $needAppPass = \Bitrix\Main\Context::getCurrent()->getServer()->get("HTTP_BX_APP_PASS"); $appUUID = \Bitrix\Main\Context::getCurrent()->getServer()->get("HTTP_BX_APP_UUID"); $deviceName = \Bitrix\Main\Context::getCurrent()->getServer()->get("HTTP_BX_DEVICE_NAME"); if ($needAppPass == 'mobile' && $USER->GetParam("APPLICATION_ID") === null) { if (strlen($appUUID) > 0) { $result = ApplicationPasswordTable::getList(array('select' => array('ID'), 'filter' => array('USER_ID' => $USER->GetID(), 'CODE' => $appUUID))); if ($row = $result->fetch()) { ApplicationPasswordTable::delete($row['ID']); } } $password = ApplicationPasswordTable::generatePassword(); $res = ApplicationPasswordTable::add(array('USER_ID' => $USER->GetID(), 'APPLICATION_ID' => 'mobile', 'PASSWORD' => $password, 'CODE' => $appUUID, 'DATE_CREATE' => new Main\Type\DateTime(), 'COMMENT' => GetMessage("MD_GENERATE_BY_MOBILE") . (strlen($deviceName) > 0 ? " (" . $deviceName . ")" : ""), 'SYSCOMMENT' => GetMessage("MD_MOBILE_APPLICATION"))); if ($res->isSuccess()) { $data["appPassword"] = $password; } } } return $data;
CHTTP::SetStatus("401 Unauthorized"); } else { $answer = array("success" => true, "sessionId" => session_id(), "bitrixSessionId" => bitrix_sessid()); if (($_POST['renew_password'] == 'y' || $_POST['otp'] != '') && $USER->GetParam("APPLICATION_ID") === null) { $code = ''; if (strlen($_POST['user_os_mark']) > 0) { $code = md5($_POST['user_os_mark'] . $_POST['user_account']); } if ($code != '') { $orm = ApplicationPasswordTable::getList(array('select' => array('ID'), 'filter' => array('USER_ID' => $USER->GetID(), 'CODE' => $code))); if ($row = $orm->fetch()) { ApplicationPasswordTable::delete($row['ID']); } } $password = ApplicationPasswordTable::generatePassword(); $res = ApplicationPasswordTable::add(array('USER_ID' => $USER->GetID(), 'APPLICATION_ID' => 'desktop', 'PASSWORD' => $password, 'DATE_CREATE' => new Main\Type\DateTime(), 'CODE' => $code, 'COMMENT' => GetMessage('DESKTOP_APP_GENERATOR'), 'SYSCOMMENT' => GetMessage('DESKTOP_APP_TITE'))); if ($res->isSuccess()) { $answer["appPassword"] = $password; } } } if (isset($_REQUEST['json']) && $_REQUEST['json'] == 'y') { header('Content-Type: application/json'); echo Main\Web\Json::encode($answer); } else { echo toJsObject($answer); } function toJsObject(array $answer) { $answerParts = array(); foreach ($answer as $attr => $value) {
if (ApplicationPasswordTable::getRow(array("filter" => array("=ID" => $id, "=USER_ID" => $USER->GetID()))) !== null) { $result = ApplicationPasswordTable::delete($id); if ($result->isSuccess()) { $answer["success"] = true; $answer["message"] = Loc::getMessage("main_app_passwords_ajax_deleted"); } else { $answer["message"] = implode("<br>", $result->getErrorMessages()); } } } elseif ($post["action"] == "add") { //adding a new application password $appManager = ApplicationManager::getInstance(); $applications = $appManager->getApplications(); $password = ApplicationPasswordTable::generatePassword(); if (isset($applications[$post['APPLICATION_ID']])) { $date = new Main\Type\DateTime(); $result = ApplicationPasswordTable::add(array('USER_ID' => $USER->GetID(), 'APPLICATION_ID' => $post['APPLICATION_ID'], 'PASSWORD' => $password, 'DATE_CREATE' => $date, 'COMMENT' => $post['COMMENT'], 'SYSCOMMENT' => $post['SYSCOMMENT'])); if ($result->isSuccess()) { $answer["success"] = true; $answer["id"] = $result->getId(); $answer["date_create"] = $date->toString(); $answer["password"] = '******' . implode(str_split($password, 4), '</span><span>') . '</span>'; } else { $answer["message"] = implode("<br>", $result->getErrorMessages()); } } else { $answer["message"] = Loc::getMessage("main_app_passwords_ajax_no_app"); } } } echo Json::encode($answer);