-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtelegram.php
105 lines (88 loc) · 3.02 KB
/
telegram.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* @author Amin Mahmoudi (MasterkinG)
* @copyright Copyright (c) 2019 - 2022, MsaterkinG32 Team, Inc. (https://masterking32.com)
* @link https://masterking32.com
* @Github https://github.com/masterking32/wow-telegram
* @Description It's not masterking32 framework !
*/
// Load required files.
require_once './tg_config/config.php';
if (!empty(Debug_Mode)) {
@error_reporting(-1);
@ini_set('display_errors', 1);
} else {
@ini_set('display_errors', 0);
if (version_compare(PHP_VERSION, '5.3', '>=')) {
@error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
} else {
@error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
}
}
require_once './tg_include/vendor/autoload.php';
function RemoteCommandWithSOAP($username, $password, $COMMAND)
{
global $soap_connection_info;
$result = '';
try {
$conn = new SoapClient(NULL, array(
'location' => 'http://' . $soap_connection_info['soap_host'] . ':' . $soap_connection_info['soap_port'] . '/',
'uri' => $soap_connection_info['soap_uri'],
'style' => SOAP_RPC,
'login' => $username,
'password' => $password
));
$result = $conn->executeCommand(new SoapParam($COMMAND, 'command'));
unset($conn);
} catch (Exception $e) {
if (!empty(Debug_Mode)) {
$result = $e;
} else {
$result = 'Have error on soap!';
}
if (strpos($e, 'There is no such command') !== false) {
$result = 'There is no such command!';
}
}
return $result;
}
// Make Telegram API
$telegram = new Telegram(TelegramBotToken);
$TelegramData = $telegram->getData();
/**
* Check have chat id and meesage
*/
if (empty($TelegramData['message'] ['text']) || empty($TelegramData['message']['chat']['id'])) {
exit();
}
$text = $TelegramData['message']['text'];
$chat_id = $TelegramData['message']['chat']['id'];
if (empty($clients)) {
echo 'No have any client!';
exit();
}
// Check all clients
foreach ($clients as $userID => $userData) {
if ($userID == $chat_id && !empty($userData['soap_user']) && !empty($userData['soap_pass'])) {
$soap_user = $userData['soap_user'];
$soap_pass = $userData['soap_pass'];
}
}
// If Chat ID is not valid send chat ID to user.
if (empty($soap_user) || empty($soap_pass)) {
$chat_id = $telegram->ChatID();
$content = array('chat_id' => $chat_id, 'text' => 'Your chat id : ' . $chat_id);
$telegram->sendMessage($content);
exit();
}
if (strpos($text, '.') === false) {
$chat_id = $telegram->ChatID();
$content = array('chat_id' => $chat_id, 'text' => 'Use .commands for see command lists.');
$telegram->sendMessage($content);
exit();
}
$resultOfExecute = RemoteCommandWithSOAP($soap_user, $soap_pass, $text);
$chat_id = $telegram->ChatID();
$content = array('chat_id' => $chat_id, 'text' => $resultOfExecute);
$telegram->sendMessage($content);
exit();