31 Header(
'Access-Control-Allow-Origin: *');
32 Header(
'Access-Control-Allow-Headers: origin, content-type, accept');
33 Header(
'X-Content-Type-Options: nosniff');
39 "PARAMETERS" =>
array(
40 "VARIABLE_ALIASES" => Array(
41 "method" => Array(
"NAME" =>
GetMessage(
'REST_PARAM_METHOD_NAME')),
46 "DEFAULT" =>
"#method#",
47 "VARIABLES" =>
array(
"method" =>
"method"),
56 $request = \Bitrix\Main\Context::getCurrent()->getRequest();
57 $server = \Bitrix\Main\Context::getCurrent()->getServer();
63 $rawPostData = trim(
$request->getInput());
65 if(isset($server[
'HTTP_CONTENT_TYPE']))
67 $requestContentType = $server[
'HTTP_CONTENT_TYPE'];
71 $requestContentType = $server[
'CONTENT_TYPE'];
74 $requestContentType = trim(preg_replace(
'/;.*$/',
'', $requestContentType));
78 switch($requestContentType)
80 case 'application/json':
86 catch(\
Bitrix\Main\ArgumentException $e)
95 if($rawPostData <>
'')
126 return $USER->CanDoOperation(
'bitrix24_config',
$userId);
129 return in_array(1, \CUser::GetUserGroup(
$userId));
139 return $USER->CanDoOperation(
'bitrix24_config');
142 return $USER->IsAdmin();
155 !empty($appInfo[
'HOLD_INSTALL_BY_TRIAL'])
156 && $appInfo[
'HOLD_INSTALL_BY_TRIAL'] ===
'Y'
171 && !empty($appInfo[
'MANIFEST'][
'CODE'])
175 \
Bitrix\Rest\Configuration\Manifest::ACCESS_TYPE_IMPORT,
176 $appInfo[
'MANIFEST'][
'CODE']
182 $hasAccess =
$USER->CanAccess(static::getInstallAccessList());
183 if ($hasAccess && is_array($appInfo))
185 return static::appCanBeInstalledByUser($appInfo);
193 return $appInfo[
'USER_INSTALL'] ===
'Y';
200 return $accessList ===
'' ?
array() : explode(
",", $accessList);
205 if(is_array($accessList))
207 $value = implode(
',', $accessList);
224 "NAME" =>
$USER->GetFirstName(),
225 "LAST_NAME" =>
$USER->GetLastName(),
226 "SECOND_NAME" =>
$USER->GetSecondName(),
227 "LOGIN" =>
$USER->GetLogin()
230 $adminList = \CRestUtil::getAdministratorIdList();
235 "FROM_USER_ID" =>
$USER->GetID(),
237 "NOTIFY_MODULE" =>
"rest",
238 "NOTIFY_TAG" =>
"REST|APP_INSTALL_NOTIFY|".$USER->GetID().
"|TO|".$id,
239 "NOTIFY_SUB_TAG" =>
"REST|APP_INSTALL_NOTIFY",
240 "NOTIFY_EVENT" =>
"admin_notification",
242 "REST_APP_INSTALL_NOTIFY_TEXT",
245 "#APP_NAME#" => $appInfo[
'APP_NAME'],
246 "#APP_CODE#" => $appInfo[
'CODE'],
247 "#APP_LINK#" => \
Bitrix\Rest\
Marketplace\Url::getApplicationDetailUrl(urlencode($appInfo[
'CODE'])),
260 $request[
'BX_LICENCE'] = BX24_HOST_NAME;
266 $request[
'BX_LICENCE'] = md5(
"BITRIX".$licenseKey.
"LICENCE");
281 return $dt ? date(
'c',
MakeTimeStamp($dt) - CTimeZone::GetOffset()) :
'';
291 if(is_array($iso8601))
293 foreach($iso8601 as
$key => $value)
295 $iso8601[
$key] = self::unConvertDateTime($value);
303 $timestamp = strtotime($iso8601);
305 if ($timestamp !==
false)
306 $date = ConvertTimeStamp($timestamp,
'SHORT');
321 if(is_array($iso8601))
323 foreach($iso8601 as
$key => $value)
325 $iso8601[
$key] = self::unConvertDateTime($value, $enableOffset);
333 $timestamp = strtotime($iso8601);
335 if ($timestamp !==
false)
339 $timestamp += CTimeZone::GetOffset();
341 $date = ConvertTimeStamp($timestamp,
'FULL');
350 if(CModule::IncludeModule(
'bitrix24'))
352 return \CBitrix24::getMemberId();
356 return \Bitrix\Rest\OAuthService::getMemberId();
362 return preg_match(
"/^http[s]{0,1}:\/\/[^\/]*?(\.apps-bitrix24\.com|\.bitrix24-cdn\.com|cdn\.bitrix24\.|app\.bitrix24\.com|upload-.*?\.s3\.amazonaws\.com\/app_local\/)/i",
$url);
365 public static function GetFile($fileId , $resizeParam =
false)
370 if(is_array($fileId))
372 $fileId = implode(
',', $fileId);
379 while($file =
$files->Fetch())
381 if($resizeParam !==
false)
393 return $bMult ? $fileSrc : $fileSrc[$fileId];
398 $regexp =
"/\\$(".$keysCache.
")([^\s]*)/i";
400 if(preg_match_all($regexp,
$query, $arMatches, PREG_SET_ORDER))
402 foreach($arMatches as $arMatch)
421 if($arMatch[0] ===
$query)
447 $resultQueryParams =
array();
449 if(is_array($queryParams))
451 foreach($queryParams as
$key => $param)
453 if($keysCache ===
null)
455 $keysCache = implode(
'|', array_keys(
$arResult));
461 $resultQueryParams[$newKey] = self::processBatchStructure($param,
$arResult, $keysCache);
465 $resultQueryParams[$newKey] = self::processBatchElement($param,
$arResult, $keysCache);
470 return $resultQueryParams;
475 $resultQueryParams =
array();
479 $queryParams =
array();
480 parse_str(
$query, $queryParams);
482 $resultQueryParams = self::processBatchStructure($queryParams,
$arResult);
485 return $resultQueryParams;
491 return \Bitrix\Rest\Event\Sender::getAuth($appId,
$userId, $additionalData, \
Bitrix\Rest\Event\Sender::getDefaultEventParams());
499 public static function getAuth($appId, $appSecret, $scope, $additionalParams, $user_id = 0)
504 \
Bitrix\Rest\Integration\OAuthModule::isSupported()
505 && CModule::IncludeModule(
'oauth')
510 $scope = implode(
',', $scope);
513 $oauth = new \Bitrix\OAuth\Client\Application();
514 $authParams = $oauth->getAuthorizeParamsInternal($appId, COAuthConstants::AUTH_RESPONSE_TYPE_AUTH_CODE,
'',
'', $scope,
array(), $user_id > 0 ? $user_id :
$USER->GetID());
516 if(is_array($authParams) && isset($authParams[COAuthConstants::AUTH_RESPONSE_TYPE_AUTH_CODE]))
518 $res = $oauth->grantAccessTokenInternal($appId, COAuthConstants::GRANT_TYPE_AUTH_CODE,
'', $authParams[COAuthConstants::AUTH_RESPONSE_TYPE_AUTH_CODE], $scope, $appSecret,
'', $additionalParams, $user_id > 0 ? $user_id :
$USER->GetID());
535 foreach(
GetModuleEvents(
'rest',
'OnRestCheckAuth',
true) as $eventHandler)
538 if($eventResult !==
null)
545 "error" =>
"NO_AUTH_FOUND",
546 "error_description" =>
"Wrong authorization data",
554 return (
new Public\Command\Auth\AuthorizeUserCommand((
int)(
$res[
'user_id'] ?? 0), $application_id))
566 if($appInfo ===
null)
573 if(!empty($appInfo[
"ACCESS"]))
575 $rights = explode(
",", $appInfo[
"ACCESS"]);
586 $hasAccess = \CRestUtil::isAdmin();
594 if(array_key_exists(
'status', $tokenInfo) && array_key_exists(
'client_id', $tokenInfo))
599 $dateFinish = $appInfo[
'DATE_FINISH'] ? $appInfo[
'DATE_FINISH']->getTimestamp() :
'';
601 if($tokenInfo[
'status'] !== $appInfo[
'STATUS'] || $tokenInfo[
'date_finish'] != $dateFinish)
603 \Bitrix\Rest\AppTable::update($appInfo[
'ID'],
array(
604 'STATUS' => $tokenInfo[
'status'],
605 'DATE_FINISH' => $tokenInfo[
'date_finish'] ? \
Bitrix\Main\Type\DateTime::createFromTimestamp($tokenInfo[
'date_finish']) :
'',
664 $dbRes = \Bitrix\Rest\AppTable::getById($appId);
669 COption::RemoveOption(
"rest",
"options_".$arApp[
'CLIENT_ID']);
670 CUserOptions::DeleteOption(
"app_options",
"params_".$arApp[
'CLIENT_ID'].
"_".$arApp[
'VERSION']);
672 CUserOptions::DeleteOption(
"app_options",
"options_".$arApp[
'CLIENT_ID'],
array());
698 catch(\
Bitrix\Main\SystemException $e)
700 $result =
array(
'error' => $e->getCode(),
'error_description' => $e->getMessage());
710 $appDetailInfo = $appDetailInfo[
'ITEMS'];
715 $queryFields =
array(
716 'CLIENT_ID' => $appDetailInfo[
'APP_CODE'],
717 'VERSION' => $appDetailInfo[
'VER'],
718 'BY_SUBSCRIPTION' => $appDetailInfo[
'BY_SUBSCRIPTION'] ===
'Y' ?
'Y' :
'N',
723 ->installApplication($queryFields);
725 if($installResult[
'result'])
728 'CLIENT_ID' => $installResult[
'result'][
'client_id'],
729 'CODE' => $appDetailInfo[
'CODE'],
731 'INSTALLED' => !empty($appDetailInfo[
'INSTALL_URL'])
734 'URL' => $appDetailInfo[
'URL'],
735 'URL_DEMO' => $appDetailInfo[
'DEMO_URL'],
736 'URL_INSTALL' => $appDetailInfo[
'INSTALL_URL'],
737 'VERSION' => $installResult[
'result'][
'version'],
738 'SCOPE' => implode(
',', $installResult[
'result'][
'scope']),
739 'STATUS' => $installResult[
'result'][
'status'],
740 'SHARED_KEY' => $appDetailInfo[
'SHARED_KEY'],
741 'CLIENT_SECRET' =>
'',
742 'APP_NAME' => $appDetailInfo[
'NAME'],
755 $appFields[
'DATE_FINISH'] =
'';
762 $addResult = \Bitrix\Rest\AppTable::update($existingApp[
'ID'], $appFields);
767 $addResult = \Bitrix\Rest\AppTable::add($appFields);
770 if($addResult->isSuccess())
772 $appId = $addResult->getId();
773 if(is_array($appDetailInfo[
'MENU_TITLE']))
775 foreach($appDetailInfo[
'MENU_TITLE'] as
$lang => $langName)
777 \Bitrix\Rest\AppLangTable::add(
array(
779 'LANGUAGE_ID' =>
$lang,
780 'MENU_NAME' => $langName
785 if($appDetailInfo[
"OPEN_API"] ===
"Y" && !empty($appFields[
"URL_INSTALL"]))
790 "EVENT_NAME" =>
"ONAPPINSTALL",
791 "EVENT_HANDLER" => $appFields[
"URL_INSTALL"],
817 $arApp = CBitrix24App::GetByID($appId);
821 'VERSION' => $arApp[
'VERSION'],
822 'PREVIOUS_VERSION' => $oldVersion,
832 CUserOptions::DeleteOption(
"app_options",
"params_".$arApp[
'APP_ID'].
"_".$arApp[
'VERSION']);
840 return \Bitrix\Rest\Engine\ScopeManager::getInstance()->listScope();
851 $eventList =
array();
893 return static::getSpecialUrl(static::METHOD_DOWNLOAD,
$query, $server);
901 'select' =>
array(
'LID',
'LANGUAGE_ID'),
902 'filter' =>
array(
'=DEF' =>
'Y',
'=ACTIVE' =>
'Y'),
903 'cache' => [
'ttl' => 86400],
907 $languageId = (string)
$site[
'LANGUAGE_ID'];
910 if($languageId ==
'')
914 $languageId = \CBitrix24::getLicensePrefix();
918 $languageId = LANGUAGE_ID;
922 if($languageId ==
'')
944 return static::getSpecialUrl(static::METHOD_UPLOAD,
$query, $server);
957 if($scope === static::GLOBAL_SCOPE)
965 .static::TOKEN_DELIMITER.$query
966 .static::TOKEN_DELIMITER.$signature;
971 if($authData[
'password_id'])
975 return static::getWebhookEndpoint(
979 ).
"?".http_build_query(
array(
985 $urlParam = array_merge(
992 return static::getEndpoint().$method.
".".$server->
getTransport().
"?".http_build_query($urlParam);
998 return static::getEndpoint().urlencode(
$userId).
'/'.urlencode($ap).
'/'.(
$method ===
'' ?
'' : urlencode(
$method).
'/');
1003 return \CHTTP::URN2URI(\
Bitrix\Main\Config\Option::get(
'rest',
'rest_server_path',
'/rest').
'/');
1010 $dbAdminList = \CGroup::GetGroupUserEx(1);
1011 while($admin = $dbAdminList->fetch())
1021 if($appInfo ===
null)
1032 empty($appInfo[
'MENU_NAME'])
1033 && empty($appInfo[
'MENU_NAME_DEFAULT'])
1034 && empty($appInfo[
'MENU_NAME_LICENSE'])
1041 elseif($appInfo[
'CODE'] === static::BITRIX_1C_APP_CODE)
if(!Loader::includeModule('messageservice')) $provider
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static get($moduleId, $name, $default="", $siteId=false)
static set($moduleId, $name, $value="", $siteId="")
static includeModule($moduleName)
static isModuleInstalled($moduleName)
static getList(array $parameters=array())
static getString($length, $caseSensitive=false)
static createFromTimestamp($timestamp)
static deleteByApp($appId)
static getByClientId($clientId)
static checkAccess(string $type, $manifestCode='')
static bind($moduleId, $eventName)
static deleteByApp(mixed $appId)
static deleteAppInstaller($appId)
static deleteByApp($appId)
static getInstall($code, $version=false, $checkHash=false, $installHash=false)
static getApplicationUrl($id=null)
static getApplicationDetailUrl($id=null, $from='')
static deleteByApp($appId)
static URN2URI($urn, $server_name='')
getTokenCheckSignature($method, $queryString)
static saveFile($fileContent, $fileName="")
static UpdateApp($appId, $oldVersion)
static getAuth($appId, $appSecret, $scope, $additionalParams, $user_id=0)
static getApplicationToken(array $application)
static getWebhookEndpoint($ap, $userId, $method='')
static CleanApp($appId, $bClean)
static canInstallApplication($appInfo=null, ?int $userId=null)
static makeAuth($res, $application_id=null)
static checkAppAccess($appId, $appInfo=null)
static getAdministratorIdList()
static ConvertDateTime($dt)
static signLicenseRequest(array $request, $licenseKey)
static GetFile($fileId, $resizeParam=false)
static appCanBeInstalledByUser(array $appInfo)
static getApplicationPage($id, $type='ID', $appInfo=null)
static getDownloadUrl($query, \CRestServer $server)
static unConvertDate($iso8601)
static getSpecialUrl($method, $query, \CRestServer $server)
static unConvertDateTime($iso8601, $enableOffset=false)
static getInstallAccessList()
static getEventList(array $description=null)
static ParseBatchQuery($query, $arResult)
static processBatchElement($query, $arResult, $keysCache='')
const HANDLER_SESSION_TTL
static getAuthForEvent($appId, $userId, array $additionalData=array())
static setInstallAccessList($accessList)
static getScopeList(array $description=null)
static getUploadUrl($query, \CRestServer $server)
static getStandardParams()
static notifyInstall($appInfo)
static processBatchStructure($queryParams, $arResult, $keysCache=null)
static updateAppStatus(array $tokenInfo)
static checkAuth($query, $scope, &$res)
static isAdmin(?int $userId=null)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
const BX_RESIZE_IMAGE_PROPORTIONAL_ALT
const SITE_DIR(!defined('LANG'))
if(!defined('SITE_ID')) $lang
if(!is_array($deviceNotifyCodes)) $access
ExecuteModuleEventEx($arEvent, $arParams=[])
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
MakeTimeStamp($datetime, $format=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"