Skip to content

Commit d4937dd

Browse files
authored
Merge pull request #19 from brlumen/fix-undefined-variable
Added connection debug mode and more fixes.
2 parents ae76f6e + 557ca2a commit d4937dd

11 files changed

+256
-70
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Features
1313
- change the status of the bug;
1414
- adding a comment to the bug;
1515
- mention of the user in the commentary.
16-
- Respond to chat alerts about events using the built-in function "Reply to message". The answer will be added as a comment to the bug (v. >= 1.3).
17-
- Support SOCKS5 proxy server.
16+
- Respond to chat alerts about events using the built-in function "Reply to message". The answer will be added as a comment to the bug (v. >= 1.3);
17+
- Support SOCKS5 proxy server ( Requires curl >= 7.21.7 ).
1818

1919
Download
2020
--------

TelegramBot.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function register() {
2222
$this->name = 'TelegramBot';
2323
$this->description = plugin_lang_get( 'description' );
2424

25-
$this->version = '1.3.3';
25+
$this->version = '1.4.0';
2626
$this->requires = array(
2727
'MantisCore' => '2.14.0',
2828
);
@@ -85,6 +85,7 @@ function init() {
8585
require_once 'core/TelegramBot_fields_api.php';
8686
require_once 'core/TelegramBot_message_api.php';
8787
require_once 'core/TelegramBot_message_format_api.php';
88+
require_once 'core/TelegramBot_menu_api.php';
8889

8990
global $g_skip_sending_bugnote, $g_account_telegram_menu_active;
9091
$g_skip_sending_bugnote = FALSE;
@@ -100,6 +101,8 @@ function config() {
100101
'download_path' => '/tmp/',
101102
'proxy_address' => '',
102103
'time_out_server_response' => 30,
104+
'debug_connection_log_path' => '/tmp/TelegramBot_debug.log',
105+
'debug_connection_enabled' => OFF,
103106
/**
104107
* The following two config options allow you to control who should get email
105108
* notifications on different actions/statuses. The first option

core/TelegramBot_authentication_api.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,25 @@ function telegram_session_start() {
5454

5555
if( $g_tg == NULL ) {
5656
$g_tg = new \Longman\TelegramBot\Telegram( plugin_config_get( 'api_key' ), plugin_config_get( 'bot_name' ) );
57-
58-
\Longman\TelegramBot\Request::setClient( new \GuzzleHttp\Client( [
59-
'base_uri' => 'https://api.telegram.org',
60-
'timeout' => plugin_config_get( 'time_out_server_response' ),
61-
'proxy' => 'socks5://' . plugin_config_get( 'proxy_address' ),
62-
] ) );
63-
57+
58+
$t_proxy_address = plugin_config_get( 'proxy_address' );
59+
60+
$t_client_prop = array();
61+
62+
$t_client_prop['base_uri'] = 'https://api.telegram.org';
63+
$t_client_prop['timeout'] = plugin_config_get( 'time_out_server_response' );
64+
65+
if( !is_blank( $t_proxy_address ) ) {
66+
$t_client_prop['proxy'] = 'socks5://' . $t_proxy_address;
67+
}
68+
69+
\Longman\TelegramBot\Request::setClient( new \GuzzleHttp\Client( $t_client_prop ) );
70+
6471
$g_tg->setDownloadPath( plugin_config_get( 'download_path' ) );
72+
73+
if( plugin_config_get( 'debug_connection_enabled' ) == ON ) {
74+
Longman\TelegramBot\TelegramLog::initDebugLog( plugin_config_get( 'debug_connection_log_path' ) );
75+
}
6576
}
6677
}
6778

core/TelegramBot_menu_api.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/*
3+
* To change this license header, choose License Headers in Project Properties.
4+
* To change this template file, choose Tools | Templates
5+
* and open the template in the editor.
6+
*/
7+
8+
function telegrambot_print_menu_config( $p_page = '' ) {
9+
$t_pages = array(
10+
'config_page',
11+
'monitor_page',
12+
);
13+
14+
if( access_has_global_level( config_get( 'manage_plugin_threshold' ) ) ) {
15+
?>
16+
<div class="col-md-12 col-xs-12">
17+
<div class="space-10"></div>
18+
<div class="left">
19+
<div class="btn-toolbar inline">
20+
<div class="btn-group">
21+
<?php
22+
foreach( $t_pages as $t_page ) {
23+
$t_active = ( ( $t_page === $p_page ) ? ' active' : '' );
24+
?>
25+
<a class="btn btn-sm btn-white btn-primary<?php echo $t_active ?>" href="<?php echo plugin_page( $t_page ) ?>">
26+
<?php echo plugin_lang_get( $t_page ) ?>
27+
</a>
28+
29+
<?php
30+
}
31+
?>
32+
33+
</div>
34+
</div>
35+
</div>
36+
</div>
37+
<?php
38+
}
39+
}

core/TelegramBot_user_api.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function telegram_bot_associated_all_users_get() {
2424
FROM " . $t_user_relationship_table;
2525
$t_results = db_query( $t_query );
2626

27+
$t_row = array();
28+
2729
foreach( $t_results as $t_result ) {
2830
$t_row[] = $t_result['mantis_user_id'];
2931
}

lang/strings_english.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ $s_plugin_TelegramBot_proxy_address_header = 'SOCKS5 proxy server address: socks
2424
$s_plugin_TelegramBot_time_out_server_response_header = 'Server response timeout (30 seconds by default):';
2525
$s_plugin_TelegramBot_current_config = 'The bot will send updates to the following URL:';
2626
$s_plugin_TelegramBot_response_from_telegram = 'Telegram server response: ';
27+
$s_plugin_TelegramBot_debug_connection_log_path_title = 'Path to log file';
28+
$s_plugin_TelegramBot_debug_connection_enabled = 'Enable connection debug mode?';
29+
$s_plugin_TelegramBot_config_page = 'General settings';
30+
$s_plugin_TelegramBot_monitor_page = 'Users monitor';
31+
$s_plugin_TelegramBot_ERROR_CURL_VERSION = 'REQUIRED CURL >= 7.21.7 ';
2732

2833
$s_plugin_TelegramBot_bot_successfully_attached = 'The bot is successfully attached.';
2934
$s_plugin_TelegramBot_info_to_redirect_bot_page = 'Return to the chat, or wait for redirection.';

lang/strings_russian.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ $s_plugin_TelegramBot_proxy_address_header = 'Адрес socks5 прокси с
2424
$s_plugin_TelegramBot_time_out_server_response_header = 'Таймаут ожидания ответа сервера (по умолчанию 30 сек): ';
2525
$s_plugin_TelegramBot_current_config = 'Бот будет отправлять обновления на следующий URL:';
2626
$s_plugin_TelegramBot_response_from_telegram = 'Ответ сервера Telegram: ';
27+
$s_plugin_TelegramBot_debug_connection_log_path_title = 'Путь к лог файлу';
28+
$s_plugin_TelegramBot_debug_connection_enabled = 'Включить режим отладки подключения?';
29+
$s_plugin_TelegramBot_config_page = 'Общие настройки';
30+
$s_plugin_TelegramBot_monitor_page = 'Монитор пользователей';
31+
$s_plugin_TelegramBot_ERROR_CURL_VERSION = 'ТРЕБУЕТСЯ CURL >= 7.21.7 ';
2732

2833
$s_plugin_TelegramBot_bot_successfully_attached = 'Бот успешно привязан.';
2934
$s_plugin_TelegramBot_info_to_redirect_bot_page = 'Вернитесь в чат, либо дождитесь переадресации.';

lang/strings_spanish.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ $s_plugin_TelegramBot_proxy_address_header = 'Dirección del servidor proxy SOCK
2424
$s_plugin_TelegramBot_time_out_server_response_header = 'Tiempo de espera de respuesta del servidor (30 segundos de forma predeterminada):';
2525
$s_plugin_TelegramBot_current_config = 'El bot enviará actualizaciones a la siguiente URL:';
2626
$s_plugin_TelegramBot_response_from_telegram = 'Respuesta del servidor de Telegram: ';
27+
$s_plugin_TelegramBot_debug_connection_log_path_title = 'Ruta al archivo de registro';
28+
$s_plugin_TelegramBot_debug_connection_enabled = 'Habilitar el modo de depuración de conexión?';
29+
$s_plugin_TelegramBot_config_page = 'Ajustes generales';
30+
$s_plugin_TelegramBot_monitor_page = 'Monitor de usuario';
31+
$s_plugin_TelegramBot_ERROR_CURL_VERSION = 'CURL NECESARIO >= 7.21.7 ';
2732

2833
$s_plugin_TelegramBot_bot_successfully_attached = 'El robot está conectado correctamente.';
2934
$s_plugin_TelegramBot_info_to_redirect_bot_page = 'Regrese al chat, o espere la redirección.';

pages/config.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
# Copyright (c) 2018 Grigoriy Ermolaev (igflocal@gmail.com)
43
# TelegramBot for MantisBT is free software:
54
# you can redistribute it and/or modify it under the terms of the GNU
@@ -15,6 +14,8 @@
1514
# along with Customer management plugin for MantisBT.
1615
# If not, see <http://www.gnu.org/licenses/>.
1716

17+
use Mantis\Exceptions\ClientException;
18+
1819
form_security_validate( 'config' );
1920

2021
global $g_tg;
@@ -23,21 +24,37 @@
2324
$f_api_key = gpc_get_string( 'api_key' );
2425
$f_proxy_address = gpc_get_string( 'proxy_address', '' );
2526
$f_time_out_server_response = gpc_get_int( 'time_out_server_response' );
27+
$f_debug_connection_log_path = gpc_get_string( 'debug_connection_log_path', '' );
28+
$f_debug_connection_enabled = gpc_get_bool( 'debug_connection_enabled', FALSE );
2629

2730
if( plugin_config_get( 'bot_name' ) != $f_bot_name ) {
28-
plugin_config_set( 'bot_name', $f_bot_name );
31+
plugin_config_set( 'bot_name', $f_bot_name );
2932
}
3033

3134
if( plugin_config_get( 'api_key' ) != $f_api_key ) {
32-
plugin_config_set( 'api_key', $f_api_key );
35+
plugin_config_set( 'api_key', $f_api_key );
3336
}
3437

3538
if( plugin_config_get( 'proxy_address' ) != $f_proxy_address ) {
36-
plugin_config_set( 'proxy_address', $f_proxy_address );
39+
plugin_config_set( 'proxy_address', $f_proxy_address );
3740
}
3841

3942
if( plugin_config_get( 'time_out_server_response' ) != $f_time_out_server_response ) {
40-
plugin_config_set( 'time_out_server_response', $f_time_out_server_response );
43+
plugin_config_set( 'time_out_server_response', $f_time_out_server_response );
44+
}
45+
46+
if( $f_debug_connection_enabled == ON ) {
47+
if( fopen( $f_debug_connection_log_path, 'a' ) ) {
48+
plugin_config_set( 'debug_connection_enabled', $f_debug_connection_enabled );
49+
plugin_config_set( 'debug_connection_log_path', $f_debug_connection_log_path );
50+
} else {
51+
plugin_config_set( 'debug_connection_enabled', OFF );
52+
plugin_config_set( 'debug_connection_log_path', $f_debug_connection_log_path );
53+
throw new ClientException( 'Cannot access write file.', ERROR_FILE_INVALID_UPLOAD_PATH );
54+
}
55+
} else {
56+
plugin_config_set( 'debug_connection_enabled', OFF );
57+
plugin_config_set( 'debug_connection_log_path', $f_debug_connection_log_path );
4158
}
4259

4360
form_security_purge( plugin_page( 'config', true ) );

pages/config_page.php

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
layout_page_header( plugin_lang_get( 'name_plugin_description_page' ) );
2121
layout_page_begin( 'manage_overview_page.php' );
2222
print_manage_menu( 'manage_plugin_page.php' );
23+
telegrambot_print_menu_config( 'config_page' );
2324
?>
2425

2526
<div class="col-md-12 col-xs-12">
@@ -85,69 +86,49 @@
8586
</td>
8687
</tr>
8788

89+
<?php
90+
$t_curl_version = curl_version();
91+
// $t_curl_version = '7.19.7';
92+
if( $t_curl_version['version'] >= '7.21.7' ) { ?>
93+
<tr <?php echo helper_alternate_class() ?>>
94+
<th class="category" width="5%">
95+
<?php echo plugin_lang_get( 'proxy_address_header' ) ?>
96+
</th>
97+
<td class="center" colspan="1">
98+
<textarea name="proxy_address" id="proxy_address" class="form-control" rows="1"><?php echo plugin_config_get( 'proxy_address' ) == NULL ? '' : plugin_config_get( 'proxy_address' ) ?></textarea>
99+
</td>
100+
</tr>
101+
<?php
102+
} else { ?>
103+
<tr <?php echo helper_alternate_class() ?>>
104+
<th class="category" width="5%">
105+
<?php echo plugin_lang_get( 'proxy_address_header' ) ?>
106+
</th>
107+
<td class="center" colspan="1">
108+
<textarea name="proxy_address" id="proxy_address" class="form-control" rows="1" disabled="true"><?php echo plugin_lang_get( 'ERROR_CURL_VERSION' ) ?></textarea>
109+
</td>
110+
</tr>
111+
<?php
112+
} ?>
113+
88114
<tr <?php echo helper_alternate_class() ?>>
89115
<th class="category" width="5%">
90-
<?php echo plugin_lang_get( 'proxy_address_header' ) ?>
116+
<?php echo plugin_lang_get( 'debug_connection_log_path_title' ) ?>
91117
</th>
92118
<td class="center" colspan="1">
93-
<textarea name="proxy_address" id="proxy_address" class="form-control" rows="1"><?php echo plugin_config_get( 'proxy_address' ) == NULL ? '' : plugin_config_get( 'proxy_address' ) ?></textarea>
119+
<textarea name="debug_connection_log_path" id="debug_connection_log_path" class="form-control" rows="1"><?php echo plugin_config_get( 'debug_connection_log_path' ) ?></textarea>
94120
</td>
95121
</tr>
96-
97-
<?php
98-
$t_bot_name = plugin_config_get( 'bot_name' );
99-
$t_api_key = plugin_config_get( 'api_key' );
100-
101-
if( $t_bot_name && $t_api_key ) {
102-
103-
try {
104-
telegram_session_start();
105-
$t_result = Longman\TelegramBot\Request::getWebhookInfo();
106-
$t_webhook_url = $t_result->result->getUrl();
107-
} catch( Longman\TelegramBot\Exception\TelegramException $t_errors ) {
108-
$t_webhook_url = $t_errors->getMessage();
109-
}
110-
111-
if( $t_webhook_url ) {
112-
?>
113-
114-
<tr <?php echo helper_alternate_class() ?>>
115-
<td class="category" width="50%">
116-
<?php echo plugin_lang_get( 'current_config' ) ?>
117-
</td>
118-
119-
<td colspan="2">
120-
121-
<div class = "fallback">
122-
<!-- <pre>-->
123-
<?php
124-
print_r( $t_webhook_url );
125-
?>
126-
<!--</pre>-->
127-
</div>
128-
129-
</td>
130-
</tr>
131-
<?php
132-
}
133-
}
134-
?>
135-
136-
<tr <?php echo helper_alternate_class() ?>>
122+
123+
<tr <?php echo helper_alternate_class() ?>>
137124
<th class="category" width="5%">
138-
<?php echo plugin_lang_get( 'account_telegram_prefs_associated_users_head' ) ?>
125+
<?php echo plugin_lang_get( 'debug_connection_enabled' ) ?>
139126
</th>
140-
<td class="left" colspan="1">
141-
142-
<p>
143-
<?php
144-
$t_associated_user_ids = telegram_bot_associated_all_users_get();
145-
foreach( $t_associated_user_ids as $t_user_id ) {
146-
echo user_get_field( $t_user_id, 'username' ) . '</br>';
147-
}
148-
?>
149-
</p>
150-
127+
<td>
128+
<label class="inline">
129+
<input type="checkbox" class="ace" id="debug_connection_enabled" name="debug_connection_enabled" <?php check_checked( (int)plugin_config_get( 'debug_connection_enabled' ), ON ); ?> />
130+
<span class="lbl"></span>
131+
</label>
151132
</td>
152133
</tr>
153134

0 commit comments

Comments
 (0)