-
Notifications
You must be signed in to change notification settings - Fork 2
/
webhook.php
46 lines (44 loc) · 1.12 KB
/
webhook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
use Telegram\Bot\Api;
require 'vendor/autoload.php';
if(file_exists('../.env')) {
$dotenv = new Dotenv\Dotenv(__DIR__.'/../');
$dotenv->load();
}
if(isset($_GET['url'])) {
$url = $_GET['url'];
} else {
$url = $_SERVER['HTTP_HOST'];
}
if(filter_var('https://'.$url, FILTER_VALIDATE_URL) == false) {
echo 'Invalid url for get certificate: '.$url;
die();
}
$g = stream_context_create (array("ssl" => array(
"capture_peer_cert" => true,
"verify_peer" => false,
"verify_peer_name" => false
)));
$r = stream_socket_client("ssl://{$url}:443", $errno, $errstr, 30,
STREAM_CLIENT_CONNECT, $g);
if(!$r) {
echo 'Domain dont exists or dont is over ssl';
die();
}
$cont = stream_context_get_params($r);
openssl_x509_export($cont["options"]["ssl"]["peer_certificate"], $certificate);
$certificate = trim($certificate, "\n");
echo '<pre>';
echo $certificate;
echo '</pre>';
$telegram = new Api();
$response = $telegram->setWebhook([
'url' => 'https://'.$url,
'certificate' => $certificate
]);
echo '<pre>';
var_dump([
'url' => 'https://'.$url,
'response' => $response
]);
echo '</pre>';