Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP7 Decoder for ionCube Encoder)
- *
- * @ Version : 4.1.0.1
- * @ Author : DeZender
- * @ Release on : 29.08.2020
- * @ Official site : http://DeZender.Net
- *
- */
- class ShCommon
- {
- /**
- * @var string имя библиотеки
- */
- static protected $libName;
- /**
- * @var string путь к серверу с обновлениями
- */
- static protected $apiUrl = 'https://dev.shahfil.com/scripts/update.php';
- /**
- * Инициализация модуля
- *
- * @return void
- */
- static public function init()
- {
- $updateDiff = static::getLibraryTimeFromUpdate();
- if (86400 < $updateDiff) {
- static::sendVersionToServer();
- @touch(__FILE__);
- }
- $buildDiff = static::getLibraryTimeFromBuild();
- if (7776000 < $buildDiff) {
- static::updateLibrary();
- return NULL;
- }
- $sapiName = php_sapi_name();
- if ($sapiName == 'cli') {
- $runName = (empty($_SERVER['argv'][0]) ? __FILE__ : $_SERVER['argv'][0]);
- $runName = basename($runName);
- if ($runName == 'tmpupd.php') {
- static::cmdVersion();
- exit();
- }
- $cmd = (empty($_SERVER['argv'][1]) ? 'none' : $_SERVER['argv'][1]);
- if ($cmd == 'version') {
- static::cmdVersion();
- exit();
- }
- else if ($cmd == 'update') {
- static::cmdUpdate();
- exit();
- }
- }
- if (!empty($_GET['libcmd'])) {
- $cmd = urldecode($_GET['libcmd']);
- switch ($cmd) {
- case 'version':
- static::cmdVersion();
- exit();
- case 'update':
- static::cmdUpdate();
- exit();
- }
- }
- return NULL;
- }
- /**
- * Имя текущей библиотеки
- *
- * @return string
- */
- static public function getLibraryName()
- {
- if (isset(static::$libName)) {
- return static::$libName;
- }
- if (defined('SHLIBRARYNAME')) {
- static::$libName = SHLIBRARYNAME;
- }
- else if (class_exists('SmartApp')) {
- static::$libName = 'smartlib';
- }
- else if (defined('CJLIBVERSION')) {
- static::$libName = 'cjlibs';
- }
- else {
- static::$libName = 'unknown_' . basename(__FILE__);
- }
- return static::$libName;
- }
- /**
- * Версия библиотеки
- *
- * @return string
- */
- static public function getLibraryVersion()
- {
- $version = '1.5.7';
- if (strpos($version, '}')) {
- $version = '0.0.0';
- }
- return $version;
- }
- /**
- * Версия библиотеки на сервере
- *
- * @return string
- */
- static public function getServerVersion()
- {
- $libraryName = static::getLibraryName();
- $host = (empty($_SERVER['HTTP_HOST']) ? php_sapi_name() : $_SERVER['HTTP_HOST']);
- $host = str_replace('www.', '', $host);
- $version = static::getLibraryVersion();
- $buildTime = static::getLibraryBuildTime();
- $apiLink = static::$apiUrl . '?cmd=version' . '&lib=' . $libraryName . '&version=' . $version . '&host=' . urlencode($host) . '&buildtime=' . $buildTime;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $apiLink);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 3);
- $html = curl_exec($ch);
- preg_match('|<version>([\\d\\.]+)</version>|', $html, $match);
- if (empty($match[1])) {
- return '0.0.0';
- }
- $serverVersion = $match[1];
- return $serverVersion;
- }
- /**
- * Проверка на наличие новой версии
- *
- * @return boolean
- */
- static public function needUpdate()
- {
- $currentVersion = static::getLibraryVersion();
- $serverVersion = static::getServerVersion();
- if ($serverVersion == '0.0.0') {
- return false;
- }
- if ($currentVersion == $serverVersion) {
- return false;
- }
- return true;
- }
- /**
- * Время сборки библиотеки
- *
- * @return integer
- */
- static public function getLibraryBuildTime()
- {
- $buildTime = '1620379532';
- if (strpos($buildTime, '}')) {
- $buildTime = date('U');
- }
- $buildTime = intval($buildTime);
- return $buildTime;
- }
- /**
- * Время до которого библиотека актуальна
- *
- * @return integer
- */
- static public function getLibraryExpiryTime()
- {
- $expireTime = '0';
- if (strpos($expireTime, '}')) {
- $expireTime = 0;
- }
- $expireTime = intval($expireTime);
- return $expireTime;
- }
- /**
- * Количество дней до окончания работы
- *
- * @return integer
- */
- static public function getExpiryDays()
- {
- $expireTime = static::getLibraryExpiryTime();
- if (empty($expireTime)) {
- return 999;
- }
- $currentTime = date('U');
- $expireDiff = ceil(($expireTime - $currentTime) / 24 / 60 / 60);
- return $expireDiff;
- }
- /**
- * Количество дней с момента сборки
- *
- * @return integer
- */
- static public function getLibraryTimeFromBuild()
- {
- $buildTime = static::getLibraryBuildTime();
- $currentTime = date('U');
- $buildDiff = $currentTime - $buildTime;
- return $buildDiff;
- }
- /**
- * Количество дней с момента обновления
- *
- * @return integer
- */
- static public function getLibraryTimeFromUpdate()
- {
- $updateTime = filemtime(__FILE__);
- if (false === $updateTime) {
- $updateTime = date('U');
- }
- $currentTime = date('U');
- $buildDiff = $currentTime - $updateTime;
- return $buildDiff;
- }
- /**
- * Отметка на сервере о текущей версии
- *
- * @return void
- */
- static public function sendVersionToServer()
- {
- $libraryName = static::getLibraryName();
- $host = (empty($_SERVER['HTTP_HOST']) ? 'localhost' : $_SERVER['HTTP_HOST']);
- $host = str_replace('www.', '', $host);
- $i = strpos($host, ':');
- if (0 < $i) {
- $host = substr($host, 0, $i);
- }
- $version = static::getLibraryVersion();
- $buildTime = static::getLibraryBuildTime();
- $expireTime = static::getLibraryExpiryTime();
- $apiLink = static::$apiUrl . '?cmd=touch' . '&lib=' . $libraryName . '&version=' . $version . '&host=' . $host . '&buildtime=' . $buildTime . '&expiretime=' . $expireTime;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $apiLink);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 3);
- $html = curl_exec($ch);
- return NULL;
- }
- /**
- * Обновление библиотеки с сервера
- *
- * @return void
- */
- static public function updateLibrary()
- {
- $libraryName = static::getLibraryName();
- $host = (empty($_SERVER['HTTP_HOST']) ? 'localhost' : $_SERVER['HTTP_HOST']);
- $host = str_replace('www.', '', $host);
- $version = static::getLibraryVersion();
- $buildTime = static::getLibraryBuildTime();
- $apiLink = static::$apiUrl . '?cmd=get' . '&lib=' . $libraryName . '&version=' . $version . '&host=' . $host . '&buildtime=' . $buildTime;
- $updatedFile = file_get_contents($apiLink);
- $i = strpos($updatedFile, '<!-- start file: ');
- if ($i < 1) {
- return false;
- }
- preg_match('|crc: ([\\d\\w]+) --/>|', $updatedFile, $match);
- if (empty($match[1])) {
- return false;
- }
- $serverCrc = $match[1];
- $updatedFile = substr($updatedFile, $i);
- $i = strpos($updatedFile, '--/>');
- $updatedFile = substr($updatedFile, $i + 4);
- $i = strpos($updatedFile, '<!-- end file');
- if ($i < 1) {
- return false;
- }
- $updatedFile = substr($updatedFile, 0, $i);
- $updatedFile = trim($updatedFile);
- $updatedFile = base64_decode($updatedFile);
- $loadCrc = md5($updatedFile);
- if ($serverCrc != $loadCrc) {
- return false;
- }
- $serverVersion = static::getServerVersion();
- $tmpFile = __DIR__ . '/tmpupd.php';
- if (!is_writable(__FILE__)) {
- return false;
- }
- if (file_exists($tmpFile)) {
- $updateTime = filemtime($tmpFile);
- $nowTime = date('U');
- if (($nowTime - $updateTime) < 600) {
- return false;
- }
- }
- file_put_contents($tmpFile, $updatedFile);
- $output = shell_exec('php ' . $tmpFile . ' version 2>&1');
- if (strpos($output, 'error')) {
- @unlink($tmpFile);
- return false;
- }
- if (!strpos($output, $serverVersion)) {
- @unlink($tmpFile);
- return false;
- }
- @unlink(__FILE__ . '.bak');
- rename(__FILE__, __FILE__ . '.bak');
- rename($tmpFile, __FILE__);
- return true;
- }
- /**
- * Команда вывода версии
- */
- static protected function cmdVersion()
- {
- echo '<library>' . static::getLibraryName() . '</library>' . "\n";
- echo '<version>' . static::getLibraryVersion() . '</version>' . "\n";
- echo '<build>' . static::getLibraryBuildTime() . '</build>' . "\n";
- $expireTime = static::getLibraryExpiryTime();
- if (!empty($expireTime)) {
- echo '<expire>' . $expireTime . '</expire>' . "\n";
- echo '<expiredays>' . static::getExpiryDays() . '</expiredays>' . "\n";
- }
- return NULL;
- }
- /**
- * Команда обновления
- */
- static protected function cmdUpdate()
- {
- echo 'Module: ' . static::getLibraryName() . ' <br />' . "\n";
- echo 'Current version: ' . static::getLibraryVersion() . ' <br />' . "\n";
- echo 'Latest version: ' . static::getServerVersion() . ' <br />' . "\n";
- if (!static::needUpdate()) {
- return NULL;
- }
- echo 'Updating... ';
- $res = static::updateLibrary();
- if ($res) {
- echo 'done. <br />' . "\n";
- }
- else {
- echo 'failed. <br />' . "\n";
- }
- return NULL;
- }
- /**
- * Отправка сообщения в телешрам
- */
- static public function sendToTelegram($msg, $chatID = '33043900')
- {
- $apiKey = '610297819:AAFFwG-sdkPnu81Kz-ti7CrkRY7ljW8JP_I';
- $msg = urlencode($msg);
- $apiUrl = 'https://api.telegram.org/bot' . $apiKey . '/sendMessage?chat_id=' . $chatID . '&text=' . $msg;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $apiUrl);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $output = curl_exec($ch);
- curl_close($ch);
- return NULL;
- }
- }
- abstract class AbstractChannel
- {
- const PROTOCOL_080 = '0.8';
- const PROTOCOL_091 = '0.9.1';
- static public $PROTOCOL_CONSTANTS_CLASS;
- /** @var array */
- protected $frame_queue;
- /** @var array */
- protected $method_queue;
- /** @var bool */
- protected $auto_decode;
- /** @var string */
- protected $amqp_protocol_header;
- /** @var \PhpAmqpLib\Helper\DebugHelper */
- protected $debug;
- /** @var \PhpAmqpLib\Connection\AbstractConnection */
- protected $connection;
- /** @var string */
- protected $protocolVersion;
- /** @var int */
- protected $maxBodySize;
- /** @var \PhpAmqpLib\Helper\Protocol\Protocol080|\PhpAmqpLib\Helper\Protocol\Protocol091 */
- protected $protocolWriter;
- /** @var \PhpAmqpLib\Helper\Protocol\Wait080|\PhpAmqpLib\Helper\Protocol\Wait091 */
- protected $waitHelper;
- /** @var \PhpAmqpLib\Helper\Protocol\MethodMap080|\PhpAmqpLib\Helper\Protocol\MethodMap091 */
- protected $methodMap;
- /** @var string */
- protected $channel_id;
- /** @var \PhpAmqpLib\Wire\AMQPReader */
- protected $msg_property_reader;
- /** @var \PhpAmqpLib\Wire\AMQPReader */
- protected $wait_content_reader;
- /** @var \PhpAmqpLib\Wire\AMQPReader */
- protected $dispatch_reader;
- /**
- * @param AbstractConnection $connection
- * @param string $channel_id
- * @throws AMQPRuntimeException
- */
- public function __construct(AbstractConnection $connection, $channel_id)
- {
- $this->connection = $connection;
- $this->channel_id = $channel_id;
- $connection->channels[$channel_id] = $this;
- $this->frame_queue = [];
- $this->method_queue = [];
- $this->auto_decode = false;
- $this->msg_property_reader = new AMQPReader(NULL);
- $this->wait_content_reader = new AMQPReader(NULL);
- $this->dispatch_reader = new AMQPReader(NULL);
- $this->protocolVersion = self::getProtocolVersion();
- switch ($this->protocolVersion) {
- case '0.9.1':
- self::$PROTOCOL_CONSTANTS_CLASS = 'Constants091';
- $c = self::$PROTOCOL_CONSTANTS_CLASS;
- $this->debug = new DebugHelper($c);
- $this->amqp_protocol_header = $c::$AMQP_PROTOCOL_HEADER;
- $this->protocolWriter = new Protocol091();
- $this->waitHelper = new Wait091();
- $this->methodMap = new MethodMap091();
- break;
- case '0.8':
- self::$PROTOCOL_CONSTANTS_CLASS = 'Constants080';
- $c = self::$PROTOCOL_CONSTANTS_CLASS;
- $this->debug = new DebugHelper($c);
- $this->amqp_protocol_header = $c::$AMQP_PROTOCOL_HEADER;
- $this->protocolWriter = new Protocol080();
- $this->waitHelper = new Wait080();
- $this->methodMap = new MethodMap080();
- break;
- default:
- throw new AMQPNotImplementedException(sprintf('Protocol: %s not implemented.', $this->protocolVersion));
- }
- }
- /**
- * @return string
- * @throws AMQPOutOfRangeException
- */
- static public function getProtocolVersion()
- {
- $protocol = (defined('AMQP_PROTOCOL') ? AMQP_PROTOCOL : '0.9.1');
- if (!in_array($protocol, ['0.8', '0.9.1'], true)) {
- throw new AMQPOutOfRangeException(sprintf('Protocol version %s not implemented.', $protocol));
- }
- return $protocol;
- }
- /**
- * @return string
- */
- public function getChannelId()
- {
- return $this->channel_id;
- }
- /**
- * @param int $max_bytes Max message body size for this channel
- * @return $this
- */
- public function setBodySizeLimit($max_bytes)
- {
- $max_bytes = (int) $max_bytes;
- if (0 < $max_bytes) {
- $this->maxBodySize = $max_bytes;
- }
- return $this;
- }
- /**
- * @return AbstractConnection
- */
- public function getConnection()
- {
- return $this->connection;
- }
- /**
- * @return array
- */
- public function getMethodQueue()
- {
- return $this->method_queue;
- }
- /**
- * @return bool
- */
- public function hasPendingMethods()
- {
- return !empty($this->method_queue);
- }
- /**
- * @param string $method_sig
- * @param string $args
- * @param AMQPMessage|null $amqpMessage
- * @return mixed
- * @throws AMQPRuntimeException
- */
- public function dispatch($method_sig, $args, $amqpMessage)
- {
- if (!$this->methodMap->valid_method($method_sig)) {
- throw new AMQPNotImplementedException(sprintf('Unknown AMQP method "%s"', $method_sig));
- }
- $amqp_method = $this->methodMap->get_method($method_sig);
- if (!method_exists($this, $amqp_method)) {
- throw new AMQPNotImplementedException(sprintf('Method: "%s" not implemented by class: %s', $amqp_method, get_class($this)));
- }
- $this->dispatch_reader->reuse($args);
- if ($amqpMessage == NULL) {
- return call_user_func([$this, $amqp_method], $this->dispatch_reader);
- }
- return call_user_func([$this, $amqp_method], $this->dispatch_reader, $amqpMessage);
- }
- /**
- * @param int|float|null $timeout
- * @return array|mixed
- */
- public function next_frame($timeout = 0)
- {
- $this->debug->debug_msg('waiting for a new frame');
- if (!empty($this->frame_queue)) {
- return array_shift($this->frame_queue);
- }
- return $this->connection->wait_channel($this->channel_id, $timeout);
- }
- /**
- * @param array $method_sig
- * @param AMQPWriter|string $args
- */
- protected function send_method_frame($method_sig, $args = '')
- {
- if ($this->connection === NULL) {
- throw new AMQPChannelClosedException('Channel connection is closed.');
- }
- $this->connection->send_channel_method_frame($this->channel_id, $method_sig, $args);
- }
- /**
- * This is here for performance reasons to batch calls to fwrite from basic.publish
- *
- * @param array $method_sig
- * @param AMQPWriter|string $args
- * @param AMQPWriter $pkt
- * @return AMQPWriter
- */
- protected function prepare_method_frame($method_sig, $args = '', $pkt = NULL)
- {
- return $this->connection->prepare_channel_method_frame($this->channel_id, $method_sig, $args, $pkt);
- }
- /**
- * @return AMQPMessage
- * @throws AMQPRuntimeException
- */
- public function wait_content()
- {
- list($frame_type, $payload) = $this->next_frame();
- $this->validate_header_frame($frame_type);
- $this->wait_content_reader->reuse(mb_substr($payload, 0, 12, 'ASCII'));
- $class_id = $this->wait_content_reader->read_short();
- $weight = $this->wait_content_reader->read_short();
- $this->msg_property_reader->reuse(mb_substr($payload, 12, mb_strlen($payload, 'ASCII') - 12, 'ASCII'));
- return $this->createMessage($this->msg_property_reader, $this->wait_content_reader);
- }
- /**
- * @param AMQPReader $propertyReader
- * @param AMQPReader $contentReader
- * @return AMQPMessage
- */
- protected function createMessage($propertyReader, $contentReader)
- {
- $bodyChunks = [];
- $bodyReceivedBytes = 0;
- $message = new AMQPMessage();
- $message->load_properties($propertyReader)->setBodySize($contentReader->read_longlong());
- while (bccomp($message->getBodySize(), $bodyReceivedBytes, 0) == 1) {
- list($frame_type, $payload) = $this->next_frame();
- $this->validate_body_frame($frame_type);
- $bodyReceivedBytes = bcadd($bodyReceivedBytes, mb_strlen($payload, 'ASCII'), 0);
- if (is_int($this->maxBodySize) && ($this->maxBodySize < $bodyReceivedBytes)) {
- $message->setIsTruncated(true);
- continue;
- }
- $bodyChunks[] = $payload;
- }
- $message->setBody(implode('', $bodyChunks));
- return $message;
- }
- /**
- * Wait for some expected AMQP methods and dispatch to them.
- * Unexpected methods are queued up for later calls to this PHP
- * method.
- *
- * @param array $allowed_methods
- * @param bool $non_blocking
- * @param int|float|null $timeout
- * @return mixed
- * @throws AMQPRuntimeException
- * @throws AMQPTimeoutException
- * @throws \ErrorException
- * @throws AMQPOutOfBoundsException
- */
- public function wait($allowed_methods = NULL, $non_blocking = false, $timeout = 0)
- {
- $this->debug->debug_allowed_methods($allowed_methods);
- $deferred = $this->process_deferred_methods($allowed_methods);
- if ($deferred['dispatch'] === true) {
- return $this->dispatch_deferred_method($deferred['queued_method']);
- }
- if (true === $non_blocking) {
- $timeout = NULL;
- }
- while (true) {
- try {
- list($frame_type, $payload) = $this->next_frame($timeout);
- }
- catch (AMQPNoDataException $e) {
- break;
- }
- $this->validate_method_frame($frame_type);
- $this->validate_frame_payload($payload);
- $method_sig = $this->build_method_signature($payload);
- $args = $this->extract_args($payload);
- $this->debug->debug_method_signature('> %s', $method_sig);
- $amqpMessage = $this->maybe_wait_for_content($method_sig);
- if ($this->should_dispatch_method($allowed_methods, $method_sig)) {
- return $this->dispatch($method_sig, $args, $amqpMessage);
- }
- $this->debug->debug_method_signature('Queueing for later: %s', $method_sig);
- $this->method_queue[] = [$method_sig, $args, $amqpMessage];
- if ($non_blocking) {
- break;
- }
- }
- }
- /**
- * @param array $allowed_methods
- * @return array
- */
- protected function process_deferred_methods($allowed_methods)
- {
- $dispatch = false;
- $queued_method = [];
- foreach ($this->method_queue as $qk => $qm) {
- $this->debug->debug_msg('checking queue method ' . $qk);
- $method_sig = $qm[0];
- if (($allowed_methods == NULL) || in_array($method_sig, $allowed_methods)) {
- unset($this->method_queue[$qk]);
- $dispatch = true;
- $queued_method = $qm;
- break;
- }
- }
- return ['dispatch' => $dispatch, 'queued_method' => $queued_method];
- }
- /**
- * @param array $queued_method
- * @return mixed
- */
- protected function dispatch_deferred_method($queued_method)
- {
- $this->debug->debug_method_signature('Executing queued method: %s', $queued_method[0]);
- ....................................................................
- .................................
- .............
Add Comment
Please, Sign In to add comment