/
var
/
www
/
vhosts
/
ihelp.ro
/
httpdocs
/
vendor
/
monolog
/
monolog
/
src
/
Monolog
/
Handler
/
/var/www/vhosts/ihelp.ro/httpdocs/vendor/monolog/monolog/src/Monolog/Handler
mkdir
upload
Name
Size
Mode
Actions
Curl/
-
0755
rm
FingersCrossed/
-
0755
rm
Slack/
-
0755
rm
SyslogUdp/
-
0755
rm
AbstractHandler.php
2637
0644
edit
dl
rm
AbstractProcessingHandler.php
1499
0644
edit
dl
rm
AbstractSyslogHandler.php
3221
0644
edit
dl
rm
AmqpHandler.php
4813
0644
edit
dl
rm
BrowserConsoleHandler.php
9237
0644
edit
dl
rm
BufferHandler.php
4546
0644
edit
dl
rm
ChromePHPHandler.php
5137
0644
edit
dl
rm
CouchDBHandler.php
2610
0644
edit
dl
rm
CubeHandler.php
5438
0644
edit
dl
rm
DeduplicationHandler.php
5942
0644
edit
dl
rm
DoctrineCouchDBHandler.php
1150
0644
edit
dl
rm
DynamoDbHandler.php
1934
0644
edit
dl
rm
ElasticaHandler.php
3670
0644
edit
dl
rm
ElasticsearchHandler.php
6953
0644
edit
dl
rm
ErrorLogHandler.php
2676
0644
edit
dl
rm
FallbackGroupHandler.php
1672
0644
edit
dl
rm
FilterHandler.php
7118
0644
edit
dl
rm
FingersCrossedHandler.php
8201
0644
edit
dl
rm
FirePHPHandler.php
5153
0644
edit
dl
rm
FleepHookHandler.php
3523
0644
edit
dl
rm
FlowdockHandler.php
3480
0644
edit
dl
rm
FormattableHandlerInterface.php
757
0644
edit
dl
rm
FormattableHandlerTrait.php
1268
0644
edit
dl
rm
GelfHandler.php
1454
0644
edit
dl
rm
GroupHandler.php
3222
0644
edit
dl
rm
Handler.php
1243
0644
edit
dl
rm
HandlerInterface.php
2786
0644
edit
dl
rm
HandlerWrapper.php
3355
0644
edit
dl
rm
IFTTTHandler.php
2268
0644
edit
dl
rm
InsightOpsHandler.php
2087
0644
edit
dl
rm
LogEntriesHandler.php
1906
0644
edit
dl
rm
LogglyHandler.php
4087
0644
edit
dl
rm
LogmaticHandler.php
2633
0644
edit
dl
rm
MailHandler.php
2245
0644
edit
dl
rm
MandrillHandler.php
2534
0644
edit
dl
rm
MissingExtensionException.php
473
0644
edit
dl
rm
MongoDBHandler.php
2364
0644
edit
dl
rm
NativeMailerHandler.php
4897
0644
edit
dl
rm
NewRelicHandler.php
5831
0644
edit
dl
rm
NoopHandler.php
908
0644
edit
dl
rm
NullHandler.php
1331
0644
edit
dl
rm
OverflowHandler.php
4309
0644
edit
dl
rm
PHPConsoleHandler.php
12209
0644
edit
dl
rm
ProcessableHandlerInterface.php
1185
0644
edit
dl
rm
ProcessableHandlerTrait.php
1618
0644
edit
dl
rm
ProcessHandler.php
5179
0644
edit
dl
rm
PsrHandler.php
2355
0644
edit
dl
rm
PushoverHandler.php
8057
0644
edit
dl
rm
RedisHandler.php
2741
0644
edit
dl
rm
RedisPubSubHandler.php
1683
0644
edit
dl
rm
RollbarHandler.php
3601
0644
edit
dl
rm
RotatingFileHandler.php
6933
0644
edit
dl
rm
SamplingHandler.php
3910
0644
edit
dl
rm
SendGridHandler.php
2936
0644
edit
dl
rm
SlackHandler.php
6930
0644
edit
dl
rm
SlackWebhookHandler.php
3988
0644
edit
dl
rm
SocketHandler.php
11995
0644
edit
dl
rm
SqsHandler.php
1748
0644
edit
dl
rm
StreamHandler.php
6564
0644
edit
dl
rm
SymfonyMailerHandler.php
3549
0644
edit
dl
rm
SyslogHandler.php
1706
0644
edit
dl
rm
SyslogUdpHandler.php
4706
0644
edit
dl
rm
TelegramBotHandler.php
8982
0644
edit
dl
rm
TestHandler.php
6462
0644
edit
dl
rm
WebRequestRecognizerTrait.php
504
0644
edit
dl
rm
WhatFailureGroupHandler.php
1863
0644
edit
dl
rm
ZendMonitorHandler.php
2850
0644
edit
dl
rm
Edit:
/var/www/vhosts/ihelp.ro/httpdocs/vendor/monolog/monolog/src/Monolog/Handler/TelegramBotHandler.php
(8982B)
<?php declare(strict_types=1); /* * This file is part of the Monolog package. * * (c) Jordi Boggiano <j.boggiano@seld.be> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Monolog\Handler; use RuntimeException; use Monolog\Level; use Monolog\Utils; use Monolog\LogRecord; /** * Handler send logs to Telegram using Telegram Bot API. * * How to use: * 1) Create telegram bot with https://telegram.me/BotFather * 2) Create a telegram channel where logs will be recorded. * 3) Add created bot from step 1 to the created channel from step 2. * * Use telegram bot API key from step 1 and channel name with '@' prefix from step 2 to create instance of TelegramBotHandler * * @link https://core.telegram.org/bots/api * * @author Mazur Alexandr <alexandrmazur96@gmail.com> */ class TelegramBotHandler extends AbstractProcessingHandler { private const BOT_API = 'https://api.telegram.org/bot'; /** * The available values of parseMode according to the Telegram api documentation */ private const AVAILABLE_PARSE_MODES = [ 'HTML', 'MarkdownV2', 'Markdown', // legacy mode without underline and strikethrough, use MarkdownV2 instead ]; /** * The maximum number of characters allowed in a message according to the Telegram api documentation */ private const MAX_MESSAGE_LENGTH = 4096; /** * Telegram bot access token provided by BotFather. * Create telegram bot with https://telegram.me/BotFather and use access token from it. */ private string $apiKey; /** * Telegram channel name. * Since to start with '@' symbol as prefix. */ private string $channel; /** * The kind of formatting that is used for the message. * See available options at https://core.telegram.org/bots/api#formatting-options * or in AVAILABLE_PARSE_MODES */ private string|null $parseMode; /** * Disables link previews for links in the message. */ private bool|null $disableWebPagePreview; /** * Sends the message silently. Users will receive a notification with no sound. */ private bool|null $disableNotification; /** * True - split a message longer than MAX_MESSAGE_LENGTH into parts and send in multiple messages. * False - truncates a message that is too long. */ private bool $splitLongMessages; /** * Adds 1-second delay between sending a split message (according to Telegram API to avoid 429 Too Many Requests). */ private bool $delayBetweenMessages; /** * Telegram message thread id, unique identifier for the target message thread (topic) of the forum; for forum supergroups only * See how to get the `message_thread_id` https://stackoverflow.com/a/75178418 */ private int|null $topic; /** * @param string $apiKey Telegram bot access token provided by BotFather * @param string $channel Telegram channel name * @param bool $splitLongMessages Split a message longer than MAX_MESSAGE_LENGTH into parts and send in multiple messages * @param bool $delayBetweenMessages Adds delay between sending a split message according to Telegram API * @param int $topic Telegram message thread id, unique identifier for the target message thread (topic) of the forum * @throws MissingExtensionException If the curl extension is missing */ public function __construct( string $apiKey, string $channel, $level = Level::Debug, bool $bubble = true, string $parseMode = null, bool $disableWebPagePreview = null, bool $disableNotification = null, bool $splitLongMessages = false, bool $delayBetweenMessages = false, int $topic = null ) { if (!extension_loaded('curl')) { throw new MissingExtensionException('The curl extension is needed to use the TelegramBotHandler'); } parent::__construct($level, $bubble); $this->apiKey = $apiKey; $this->channel = $channel; $this->setParseMode($parseMode); $this->disableWebPagePreview($disableWebPagePreview); $this->disableNotification($disableNotification); $this->splitLongMessages($splitLongMessages); $this->delayBetweenMessages($delayBetweenMessages); $this->setTopic($topic); } public function setParseMode(string $parseMode = null): self { if ($parseMode !== null && !in_array($parseMode, self::AVAILABLE_PARSE_MODES, true)) { throw new \InvalidArgumentException('Unknown parseMode, use one of these: ' . implode(', ', self::AVAILABLE_PARSE_MODES) . '.'); } $this->parseMode = $parseMode; return $this; } public function disableWebPagePreview(bool $disableWebPagePreview = null): self { $this->disableWebPagePreview = $disableWebPagePreview; return $this; } public function disableNotification(bool $disableNotification = null): self { $this->disableNotification = $disableNotification; return $this; } /** * True - split a message longer than MAX_MESSAGE_LENGTH into parts and send in multiple messages. * False - truncates a message that is too long. * @return $this */ public function splitLongMessages(bool $splitLongMessages = false): self { $this->splitLongMessages = $splitLongMessages; return $this; } /** * Adds 1-second delay between sending a split message (according to Telegram API to avoid 429 Too Many Requests). * @return $this */ public function delayBetweenMessages(bool $delayBetweenMessages = false): self { $this->delayBetweenMessages = $delayBetweenMessages; return $this; } public function setTopic(int $topic = null): self { $this->topic = $topic; return $this; } /** * @inheritDoc */ public function handleBatch(array $records): void { $messages = []; foreach ($records as $record) { if (!$this->isHandling($record)) { continue; } if (\count($this->processors) > 0) { $record = $this->processRecord($record); } $messages[] = $record; } if (\count($messages) > 0) { $this->send((string) $this->getFormatter()->formatBatch($messages)); } } /** * @inheritDoc */ protected function write(LogRecord $record): void { $this->send($record->formatted); } /** * Send request to @link https://api.telegram.org/bot on SendMessage action. */ protected function send(string $message): void { $messages = $this->handleMessageLength($message); foreach ($messages as $key => $msg) { if ($this->delayBetweenMessages && $key > 0) { sleep(1); } $this->sendCurl($msg); } } protected function sendCurl(string $message): void { $ch = curl_init(); $url = self::BOT_API . $this->apiKey . '/SendMessage'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); $params = [ 'text' => $message, 'chat_id' => $this->channel, 'parse_mode' => $this->parseMode, 'disable_web_page_preview' => $this->disableWebPagePreview, 'disable_notification' => $this->disableNotification, ]; if ($this->topic !== null) { $params['message_thread_id'] = $this->topic; } curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); $result = Curl\Util::execute($ch); if (!is_string($result)) { throw new RuntimeException('Telegram API error. Description: No response'); } $result = json_decode($result, true); if ($result['ok'] === false) { throw new RuntimeException('Telegram API error. Description: ' . $result['description']); } } /** * Handle a message that is too long: truncates or splits into several * @return string[] */ private function handleMessageLength(string $message): array { $truncatedMarker = ' (...truncated)'; if (!$this->splitLongMessages && strlen($message) > self::MAX_MESSAGE_LENGTH) { return [Utils::substr($message, 0, self::MAX_MESSAGE_LENGTH - strlen($truncatedMarker)) . $truncatedMarker]; } return str_split($message, self::MAX_MESSAGE_LENGTH); } }
Save
cmd:
run