403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/seo/lib/Webmaster/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/seo/lib/Webmaster/Service.php
<?php

namespace Bitrix\Seo\Webmaster;

use Bitrix\Main\Application;
use Bitrix\Seo\Retargeting;

/**
 * Class Service
 *
 * @package Bitrix\Seo\LeadAds
 */
class Service extends Retargeting\Service
{
	public const GROUP = 'webmaster';
	public const TYPE_GOOGLE = 'google';
	public const METHOD_PREFIX = 'webmaster';

	/**
	 * Get type list.
	 *
	 * @return array
	 */
	public static function getTypes(): array
	{
		return [
			static::TYPE_GOOGLE,
		];
	}

	/**
	 * @inheritDoc
	 */
	public static function getMethodPrefix(): string
	{
		return self::METHOD_PREFIX;
	}

	/**
	 * Get list of added sites with statuses
	 * @return array
	 * @throws \Bitrix\Main\SystemException
	 */
	public static function getSites(): array
	{
		$engine = new Engine\Google();
		$engine->setService(static::getInstance());
		$response = $engine->getSites();

		if (!$response->isSuccess())
		{
			return ['error' => $response->getErrors()];
		}

		$result = [];
		$sites = $response->getData();

		$sites = $sites['siteEntry'] ?? [];
		foreach ($sites as $siteInfo)
		{
			$siteUrlInfo = parse_url($siteInfo['siteUrl']);
			if ($siteUrlInfo)
			{
				$errors = [];
				$hostKey = \CBXPunycode::toASCII($siteUrlInfo["host"], $errors);
				if (count($errors) > 0)
				{
					$hostKey = $siteUrlInfo["host"];
				}

				$result[$hostKey] = [
					'binded' => $siteInfo["permissionLevel"] !== "siteRestrictedUser",
					'verified' => (
						$siteInfo["permissionLevel"] !== "siteRestrictedUser"
						&& $siteInfo["permissionLevel"] !== "siteUnverifiedUser"
					),
				];
			}
		}

		return $result;
	}

	/**
	 * Add site to webmaster
	 * @param string $domain - site domain
	 * @param string $dir - subdir
	 * @return array|true[]
	 * @throws \Bitrix\Main\SystemException
	 */
	public static function addSite(string $domain, string $dir = '/'): array
	{
		$request = Application::getInstance()->getContext()->getRequest();
		$protocol = $request->isHttps() ? "https://" : "http://";

		$engine = new Engine\Google();
		$engine->setService(static::getInstance());
		$response = $engine->addSite($protocol . $domain . $dir);

		if (!$response->isSuccess())
		{
			return ['error' => implode(',', $response->getErrorMessages())];
		}

		$result = $response->getData();
		if ($result['errors'])
		{
			return ['error' => $result['errors']['message']];
		}

		return ['result' => true];
	}

	/**
	 * Get token-string for naming verify file
	 * @param string $domain - site domain
	 * @param string $dir - subdir
	 * @return array|string[]
	 * @throws \Bitrix\Main\ArgumentException
	 * @throws \Bitrix\Main\SystemException
	 */
	public static function getVerifyToken(string $domain, string $dir = '/'): array
	{
		$request = Application::getInstance()->getContext()->getRequest();
		$protocol = $request->isHttps() ? "https://" : "http://";
		$data = [
			"site" => [
				"identifier" => $protocol . $domain . $dir,
				"type" => "SITE",
			],
			"verificationMethod" => "FILE",
		];

		$engine = new Engine\Google();
		$engine->setService(static::getInstance());
		$response = $engine->getVerifyToken($data);

		if (!$response->isSuccess())
		{
			return ['error' => implode(',', $response->getErrorMessages())];
		}

		$result = $response->getData();
		if (!$result || !$result["token"])
		{
			return ['error' => 'empty response'];
		}
		if ($result['errors'])
		{
			return ['error' => $result['errors']['message']];
		}

		return ['token' => $result["token"]];
	}

	/**
	 * Pass site to verify
	 * @param string $domain - site domain
	 * @param string $dir - subdir
	 * @return array|string[]|true[]
	 * @throws \Bitrix\Main\ArgumentException
	 * @throws \Bitrix\Main\SystemException
	 */
	public static function verifySite(string $domain, string $dir = '/'): array
	{
		$request = Application::getInstance()->getContext()->getRequest();
		$protocol = $request->isHttps() ? "https://" : "http://";
		$data = [
			"site" => [
				"identifier" => $protocol . $domain . $dir,
				"type" => "SITE",
			],
		];

		$engine = new Engine\Google();
		$engine->setService(static::getInstance());
		$response = $engine->verifySite($data);

		if (!$response->isSuccess())
		{
			return ['error' => implode(',', $response->getErrorMessages())];
		}

		$result = $response->getData();
		if (!$result || !$result["token"])
		{
			return ['error' => 'empty response'];
		}
		if ($result['errors'])
		{
			return ['error' => $result['errors']['message']];
		}

		return ['result' => true];
	}

	public static function canUseMultipleClients()
	{
		return false;
	}
}


Youez - 2016 - github.com/yon3zu
LinuXploit