Skip to content

Commit 7ba9811

Browse files
committed
Cleanup old error values
1 parent d8ab9a4 commit 7ba9811

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

src/RPCErrorException.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Amp\Http\Client\HttpClientBuilder;
2424
use Amp\Http\Client\Request;
2525
use Throwable;
26+
use Webmozart\Assert\Assert;
2627

2728
use const PHP_EOL;
2829

@@ -162,6 +163,7 @@ public static function isBad(string $error, int $code, string $method): bool
162163
|| is_numeric($method);
163164
}
164165

166+
private static string $auth;
165167
/**
166168
* @internal
167169
*/
@@ -176,10 +178,21 @@ private static function report(string $error, int $code, string $method): string
176178
&& !self::isBad($error, $code, $method)
177179
) {
178180
try {
181+
if (!isset(self::$auth)) {
182+
$auth = '';
183+
try {
184+
$auth = getenv('TELERPC_AUTH_TOKEN') ?: '';
185+
} catch (Throwable) {
186+
}
187+
Assert::true(preg_match('/^[a-zA-Z0-9_-]*$/', $auth) === 1, 'TELERPC_AUTH_TOKEN can only contain a-z, A-Z, 0-9, _ and -');
188+
$auth = $auth === '' ? '' : 'auth='.$auth.'&';
189+
self::$auth = $auth;
190+
}
191+
$auth = self::$auth;
179192
$res = json_decode(
180193
(
181194
HttpClientBuilder::buildDefault()
182-
->request(new Request('https://report-rpc-error.madelineproto.xyz/?method='.$method.'&code='.$code.'&error='.$error))
195+
->request(new Request('https://report-rpc-error.madelineproto.xyz/?'.$auth.'method='.$method.'&code='.$code.'&error='.$error))
183196
)->getBody()->buffer(),
184197
true,
185198
);

tools/fuzzer.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php declare(strict_types=1);
22

3+
use Amp\Http\Client\HttpClientBuilder;
4+
use Amp\Http\Client\Request;
35
use danog\MadelineProto\API;
4-
use danog\MadelineProto\Exception;
56
use danog\MadelineProto\Logger;
67
use danog\MadelineProto\PTSException;
78
use danog\MadelineProto\RPCErrorException;
@@ -59,6 +60,27 @@ function getTL(TLSchema $schema)
5960
$layer = getTL($schema);
6061
$res = '';
6162

63+
$auth = '';
64+
try {
65+
$auth = getenv('TELERPC_AUTH_TOKEN') ?: '';
66+
} catch (Throwable) {
67+
}
68+
Assert::true(preg_match('/^[a-zA-Z0-9_-]*$/', $auth) === 1, 'TELERPC_AUTH_TOKEN can only contain a-z, A-Z, 0-9, _ and -');
69+
70+
if ($auth) {
71+
$res = json_decode(
72+
(
73+
HttpClientBuilder::buildDefault()
74+
->request(new Request('https://report-rpc-error.madelineproto.xyz/?auth='.$auth.'&cleanup=1'))
75+
)->getBody()->buffer(),
76+
true,
77+
);
78+
Assert::true($res['ok']);
79+
echo "Cleaned up old reports".PHP_EOL;
80+
} else {
81+
echo "No TELERPC_AUTH_TOKEN set, not cleaning up old reports".PHP_EOL;
82+
}
83+
6284
$settings = new Settings;
6385
$settings->setSchema($schema);
6486
$settings->getLogger()->setLevel(Logger::ULTRA_VERBOSE);

0 commit comments

Comments
 (0)