Added Telegram Bot Notification
parent
50ab06640e
commit
06074d7fbc
|
@ -4,7 +4,7 @@ Changelog
|
||||||
|
|
||||||
not yet released
|
not yet released
|
||||||
----------------
|
----------------
|
||||||
|
* #171: Implement Telegram Bot Notifications.
|
||||||
|
|
||||||
|
|
||||||
v3.2.0 (released April 15, 2017)
|
v3.2.0 (released April 15, 2017)
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
/**
|
/**
|
||||||
* Current PSM version
|
* Current PSM version
|
||||||
*/
|
*/
|
||||||
define('PSM_VERSION', '3.2.1');
|
define('PSM_VERSION', '3.3.0');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL to check for updates. Will not be checked if turned off on config page.
|
* URL to check for updates. Will not be checked if turned off on config page.
|
||||||
|
|
|
@ -83,6 +83,8 @@ $sm_lang = array(
|
||||||
'level_description' => '<b>Administrators</b> have full access: they can manage servers, users and edit the global configuration.<br/><b>Users</b> can only view and run the updater for the servers that have been assigned to them.',
|
'level_description' => '<b>Administrators</b> have full access: they can manage servers, users and edit the global configuration.<br/><b>Users</b> can only view and run the updater for the servers that have been assigned to them.',
|
||||||
'mobile' => 'Mobile',
|
'mobile' => 'Mobile',
|
||||||
'email' => 'Email',
|
'email' => 'Email',
|
||||||
|
'telegram_user_code' => 'Telegram User Code',
|
||||||
|
'telegram_user_code_description' => 'Enter your code informed by your telegram bot.',
|
||||||
'pushover' => 'Pushover',
|
'pushover' => 'Pushover',
|
||||||
'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See <a href="https://pushover.net/">their website</a> for more info.',
|
'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See <a href="https://pushover.net/">their website</a> for more info.',
|
||||||
'pushover_key' => 'Pushover Key',
|
'pushover_key' => 'Pushover Key',
|
||||||
|
@ -112,10 +114,12 @@ $sm_lang = array(
|
||||||
'email' => 'Email',
|
'email' => 'Email',
|
||||||
'sms' => 'SMS',
|
'sms' => 'SMS',
|
||||||
'pushover' => 'Pushover',
|
'pushover' => 'Pushover',
|
||||||
|
'telegram' => 'Telegram',
|
||||||
'no_logs' => 'No logs',
|
'no_logs' => 'No logs',
|
||||||
),
|
),
|
||||||
'servers' => array(
|
'servers' => array(
|
||||||
'server' => 'Server',
|
'server' => 'Server',
|
||||||
|
'telegram' => 'Telegram',
|
||||||
'status' => 'Status',
|
'status' => 'Status',
|
||||||
'label' => 'Label',
|
'label' => 'Label',
|
||||||
'domain' => 'Domain/IP',
|
'domain' => 'Domain/IP',
|
||||||
|
@ -185,10 +189,12 @@ $sm_lang = array(
|
||||||
'error_server_ip_bad_website' => 'The website URL is not valid.',
|
'error_server_ip_bad_website' => 'The website URL is not valid.',
|
||||||
'error_server_type_invalid' => 'The selected server type is invalid.',
|
'error_server_type_invalid' => 'The selected server type is invalid.',
|
||||||
'error_server_warning_threshold_invalid' => 'The warning threshold must be a valid integer greater than 0.',
|
'error_server_warning_threshold_invalid' => 'The warning threshold must be a valid integer greater than 0.',
|
||||||
|
'send_telegram' => 'Retrieve information from Bot'
|
||||||
),
|
),
|
||||||
'config' => array(
|
'config' => array(
|
||||||
'general' => 'General',
|
'general' => 'General',
|
||||||
'language' => 'Language',
|
'language' => 'Language',
|
||||||
|
'tab_telegram' => 'Telegram Bot',
|
||||||
'show_update' => 'Check for updates?',
|
'show_update' => 'Check for updates?',
|
||||||
'password_encrypt_key' => 'The encryption key password',
|
'password_encrypt_key' => 'The encryption key password',
|
||||||
'password_encrypt_key_note' => 'This key is used to encrypt passwords that are stored on servers for access to websites. If the key will change the stored password is invalid!',
|
'password_encrypt_key_note' => 'This key is used to encrypt passwords that are stored on servers for access to websites. If the key will change the stored password is invalid!',
|
||||||
|
@ -250,6 +256,7 @@ $sm_lang = array(
|
||||||
'log_email' => 'Log emails sent by the script',
|
'log_email' => 'Log emails sent by the script',
|
||||||
'log_sms' => 'Log text messages sent by the script',
|
'log_sms' => 'Log text messages sent by the script',
|
||||||
'log_pushover' => 'Log pushover messages sent by the script',
|
'log_pushover' => 'Log pushover messages sent by the script',
|
||||||
|
'log_telegram' => 'Log telegram messages sent by the script',
|
||||||
'updated' => 'The configuration has been updated.',
|
'updated' => 'The configuration has been updated.',
|
||||||
'tab_email' => 'Email',
|
'tab_email' => 'Email',
|
||||||
'tab_sms' => 'SMS',
|
'tab_sms' => 'SMS',
|
||||||
|
@ -259,6 +266,7 @@ $sm_lang = array(
|
||||||
'settings_pushover' => 'Pushover settings',
|
'settings_pushover' => 'Pushover settings',
|
||||||
'settings_notification' => 'Notification settings',
|
'settings_notification' => 'Notification settings',
|
||||||
'settings_log' => 'Log settings',
|
'settings_log' => 'Log settings',
|
||||||
|
'settings_telegram' => 'Telegram Settings',
|
||||||
'settings_proxy' => 'Proxy settings',
|
'settings_proxy' => 'Proxy settings',
|
||||||
'auto_refresh' => 'Auto-refresh',
|
'auto_refresh' => 'Auto-refresh',
|
||||||
'auto_refresh_servers' =>
|
'auto_refresh_servers' =>
|
||||||
|
@ -286,6 +294,12 @@ $sm_lang = array(
|
||||||
'log_retention_period' => 'Log retention period',
|
'log_retention_period' => 'Log retention period',
|
||||||
'log_retention_period_description' => 'Number of days to keep logs of notifications and archives of server uptime. Enter 0 to disable log cleanup.',
|
'log_retention_period_description' => 'Number of days to keep logs of notifications and archives of server uptime. Enter 0 to disable log cleanup.',
|
||||||
'log_retention_days' => 'days',
|
'log_retention_days' => 'days',
|
||||||
|
'telegram_bot_api_key' => 'TelegramBot\'s ApiKey',
|
||||||
|
'telegram_api_token_description' => 'Before using BOT, see the guide on how to create and get your ApiKey on your TelegramBot by <a href="%1$s" target="_blank">clicking here</a>.',
|
||||||
|
'test_telegram' => 'To test if your key is ok let\'s retrieve the information from your bot.',
|
||||||
|
'telegram_status' => 'Enable sending messages with the Telegram',
|
||||||
|
'telegram_sent' => '%s is configured correctly.',
|
||||||
|
'telegram_error' => 'TelegramBotError',
|
||||||
),
|
),
|
||||||
// for newlines in the email messages use <br/>
|
// for newlines in the email messages use <br/>
|
||||||
'notifications' => array(
|
'notifications' => array(
|
||||||
|
|
|
@ -82,7 +82,9 @@ $sm_lang = array(
|
||||||
'level_20' => 'Usuário',
|
'level_20' => 'Usuário',
|
||||||
'level_description' => '<b>Administradores</b> Tem total acesso: podem gerenciar servidores, usuários e configurações globais.<br/><b>Usuários</b> só podem executar atualizações para servidores que lhe foram atribuídos.',
|
'level_description' => '<b>Administradores</b> Tem total acesso: podem gerenciar servidores, usuários e configurações globais.<br/><b>Usuários</b> só podem executar atualizações para servidores que lhe foram atribuídos.',
|
||||||
'mobile' => 'Celular',
|
'mobile' => 'Celular',
|
||||||
'email' => 'Email',
|
'email' => 'Email',
|
||||||
|
'telegram_user_code' => 'Código do Telegram',
|
||||||
|
'telegram_user_code_description' => 'Digite o código informado pelo seu bot do telegram.',
|
||||||
'pushover' => 'Pushover',
|
'pushover' => 'Pushover',
|
||||||
'pushover_description' => 'Pushover para enviar notificações em real-tome. Veja <a href="https://pushover.net/">o website</a> para mais informações.',
|
'pushover_description' => 'Pushover para enviar notificações em real-tome. Veja <a href="https://pushover.net/">o website</a> para mais informações.',
|
||||||
'pushover_key' => 'Pushover Key',
|
'pushover_key' => 'Pushover Key',
|
||||||
|
@ -112,11 +114,13 @@ $sm_lang = array(
|
||||||
'email' => 'Email',
|
'email' => 'Email',
|
||||||
'sms' => 'SMS',
|
'sms' => 'SMS',
|
||||||
'pushover' => 'Pushover',
|
'pushover' => 'Pushover',
|
||||||
|
'telegram' => 'Telegram',
|
||||||
'no_logs' => 'Sem logs',
|
'no_logs' => 'Sem logs',
|
||||||
),
|
),
|
||||||
'servers' => array(
|
'servers' => array(
|
||||||
'server' => 'Servidor',
|
'server' => 'Servidor',
|
||||||
'status' => 'Status',
|
'status' => 'Status',
|
||||||
|
'telegram' => 'Telegram',
|
||||||
'label' => 'Etiqueta',
|
'label' => 'Etiqueta',
|
||||||
'domain' => 'Domínio/IP',
|
'domain' => 'Domínio/IP',
|
||||||
'timeout' => 'Timeout',
|
'timeout' => 'Timeout',
|
||||||
|
@ -171,10 +175,12 @@ $sm_lang = array(
|
||||||
'error_server_ip_bad_website' => 'A URL não é válida.',
|
'error_server_ip_bad_website' => 'A URL não é válida.',
|
||||||
'error_server_type_invalid' => 'O tipo de servidor selecionado não é valido.',
|
'error_server_type_invalid' => 'O tipo de servidor selecionado não é valido.',
|
||||||
'error_server_warning_threshold_invalid' => 'O limite de aviso deve ser um número inteiro maior que 0.',
|
'error_server_warning_threshold_invalid' => 'O limite de aviso deve ser um número inteiro maior que 0.',
|
||||||
|
'send_telegram' => 'Recuperar informações de Bot'
|
||||||
),
|
),
|
||||||
'config' => array(
|
'config' => array(
|
||||||
'general' => 'Geral',
|
'general' => 'Geral',
|
||||||
'language' => 'Idioma',
|
'language' => 'Idioma',
|
||||||
|
'tab_telegram' => 'Telegram Bot',
|
||||||
'show_update' => 'verificar atualizações semanalmente?',
|
'show_update' => 'verificar atualizações semanalmente?',
|
||||||
'email_status' => 'Habilitar envio de email?',
|
'email_status' => 'Habilitar envio de email?',
|
||||||
'email_from_email' => 'Endereço do envio de email',
|
'email_from_email' => 'Endereço do envio de email',
|
||||||
|
@ -228,6 +234,7 @@ $sm_lang = array(
|
||||||
'log_email' => 'Registrar no Log os envios de email feitos pelo script?',
|
'log_email' => 'Registrar no Log os envios de email feitos pelo script?',
|
||||||
'log_sms' => 'Registrar no Log os envios de mensagens de texto feitos pelo script?',
|
'log_sms' => 'Registrar no Log os envios de mensagens de texto feitos pelo script?',
|
||||||
'log_pushover' => 'Log pushover messages sent by the script',
|
'log_pushover' => 'Log pushover messages sent by the script',
|
||||||
|
'log_telegram' => 'Registrar Log de mensagens enviadas pelo script',
|
||||||
'updated' => 'A configuração foi atualizada.',
|
'updated' => 'A configuração foi atualizada.',
|
||||||
'tab_email' => 'Email',
|
'tab_email' => 'Email',
|
||||||
'tab_sms' => 'Texto',
|
'tab_sms' => 'Texto',
|
||||||
|
@ -236,7 +243,8 @@ $sm_lang = array(
|
||||||
'settings_sms' => 'Configuração de mensagens de texto',
|
'settings_sms' => 'Configuração de mensagens de texto',
|
||||||
'settings_pushover' => 'Pushover settings',
|
'settings_pushover' => 'Pushover settings',
|
||||||
'settings_notification' => 'Configuração de notificações',
|
'settings_notification' => 'Configuração de notificações',
|
||||||
'settings_log' => 'Configuração de Logs',
|
'settings_log' => 'Configuração de Logs',
|
||||||
|
'settings_telegram' => 'Configurações Telegram',
|
||||||
'auto_refresh' => 'Atualizar automaticamente',
|
'auto_refresh' => 'Atualizar automaticamente',
|
||||||
'auto_refresh_servers' =>
|
'auto_refresh_servers' =>
|
||||||
'Atualizar automaticamente a página de servidores.<br/>'.
|
'Atualizar automaticamente a página de servidores.<br/>'.
|
||||||
|
@ -263,6 +271,12 @@ $sm_lang = array(
|
||||||
'log_retention_period' => 'Período de retenção do Log',
|
'log_retention_period' => 'Período de retenção do Log',
|
||||||
'log_retention_period_description' => 'Número de dias para manter os registros de notificações e arquivos de tempo de atividade do servidor. Digite 0 para desativar a limpeza de registro.',
|
'log_retention_period_description' => 'Número de dias para manter os registros de notificações e arquivos de tempo de atividade do servidor. Digite 0 para desativar a limpeza de registro.',
|
||||||
'log_retention_days' => 'dias',
|
'log_retention_days' => 'dias',
|
||||||
|
'telegram_bot_api_key' => 'ApiKey do TelegramBot',
|
||||||
|
'telegram_api_token_description' => 'Antes de usar o BOT, veja o guia de como criar e obter o seu ApiKey em seu TelegramBot <a href="%1$s" target="_blank">clicando aqui</a>.',
|
||||||
|
'test_telegram' => 'Para testar se sua chave está ok vamos recuperar as informações de seu bot.',
|
||||||
|
'telegram_status' => 'Habilitar envio de mensagens via Telegram',
|
||||||
|
'telegram_sent' => '%s está configurado corretamente.',
|
||||||
|
'telegram_error' => 'Erro em TelegramBot',
|
||||||
),
|
),
|
||||||
// for newlines in the email messages use <br/>
|
// for newlines in the email messages use <br/>
|
||||||
'notifications' => array(
|
'notifications' => array(
|
||||||
|
|
|
@ -41,10 +41,12 @@ class ConfigController extends AbstractController {
|
||||||
'email_smtp',
|
'email_smtp',
|
||||||
'sms_status',
|
'sms_status',
|
||||||
'pushover_status',
|
'pushover_status',
|
||||||
|
'telegram_status',
|
||||||
'log_status',
|
'log_status',
|
||||||
'log_email',
|
'log_email',
|
||||||
'log_sms',
|
'log_sms',
|
||||||
'log_pushover',
|
'log_pushover',
|
||||||
|
'log_telegram',
|
||||||
'show_update',
|
'show_update',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -66,6 +68,7 @@ class ConfigController extends AbstractController {
|
||||||
'sms_gateway_password',
|
'sms_gateway_password',
|
||||||
'sms_from',
|
'sms_from',
|
||||||
'pushover_api_token',
|
'pushover_api_token',
|
||||||
|
'telegram_api_token',
|
||||||
);
|
);
|
||||||
|
|
||||||
private $default_tab = 'general';
|
private $default_tab = 'general';
|
||||||
|
@ -135,7 +138,7 @@ class ConfigController extends AbstractController {
|
||||||
|
|
||||||
$tpl_data[$this->default_tab . '_active'] = 'active';
|
$tpl_data[$this->default_tab . '_active'] = 'active';
|
||||||
|
|
||||||
$testmodals = array('email', 'sms', 'pushover');
|
$testmodals = array('email', 'sms', 'pushover', 'telegram');
|
||||||
foreach($testmodals as $modal_id) {
|
foreach($testmodals as $modal_id) {
|
||||||
$modal = new \psm\Util\Module\Modal($this->twig, 'test' . ucfirst($modal_id), \psm\Util\Module\Modal::MODAL_TYPE_OKCANCEL);
|
$modal = new \psm\Util\Module\Modal($this->twig, 'test' . ucfirst($modal_id), \psm\Util\Module\Modal::MODAL_TYPE_OKCANCEL);
|
||||||
$this->addModal($modal);
|
$this->addModal($modal);
|
||||||
|
@ -186,6 +189,8 @@ class ConfigController extends AbstractController {
|
||||||
$this->testSMS();
|
$this->testSMS();
|
||||||
} elseif(!empty($_POST['test_pushover'])) {
|
} elseif(!empty($_POST['test_pushover'])) {
|
||||||
$this->testPushover();
|
$this->testPushover();
|
||||||
|
} elseif(!empty($_POST['test_telegram'])) {
|
||||||
|
$this->testTelegram();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($language_refresh) {
|
if($language_refresh) {
|
||||||
|
@ -201,6 +206,8 @@ class ConfigController extends AbstractController {
|
||||||
$this->default_tab = 'sms';
|
$this->default_tab = 'sms';
|
||||||
} elseif(isset($_POST['pushover_submit']) || !empty($_POST['test_pushover'])) {
|
} elseif(isset($_POST['pushover_submit']) || !empty($_POST['test_pushover'])) {
|
||||||
$this->default_tab = 'pushover';
|
$this->default_tab = 'pushover';
|
||||||
|
} elseif(isset($_POST['telegram_submit']) || !empty($_POST['test_telegram'])) {
|
||||||
|
$this->default_tab = 'telegram';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->runAction('index');
|
return $this->runAction('index');
|
||||||
|
@ -227,6 +234,38 @@ class ConfigController extends AbstractController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute telegram test
|
||||||
|
*
|
||||||
|
* @todo move test to separate class
|
||||||
|
*/
|
||||||
|
protected function testTelegram() {
|
||||||
|
|
||||||
|
//$this->addMessage('Erro : hahaha', 'error');
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$api = new \psm\Service\Telegram(psm_get_conf('telegram_api_token'));
|
||||||
|
|
||||||
|
$result = $api->getMe();
|
||||||
|
|
||||||
|
if($result && $result->ok) {
|
||||||
|
$this->addMessage(
|
||||||
|
sprintf(psm_get_lang('config', 'telegram_sent'), $result->result->username),
|
||||||
|
'success');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \Exception(json_encode($result));
|
||||||
|
//$this->addMessage(psm_get_lang('config', 'telegram_sent'), 'success');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->addMessage(psm_get_lang('config', 'telegram_error') . ': ' . $e->getMessage(), 'error');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute SMS test
|
* Execute SMS test
|
||||||
*
|
*
|
||||||
|
@ -289,6 +328,7 @@ class ConfigController extends AbstractController {
|
||||||
|
|
||||||
protected function getLabels() {
|
protected function getLabels() {
|
||||||
return array(
|
return array(
|
||||||
|
'label_tab_telegram' => psm_get_lang('config', 'tab_telegram'),
|
||||||
'label_tab_email' => psm_get_lang('config', 'tab_email'),
|
'label_tab_email' => psm_get_lang('config', 'tab_email'),
|
||||||
'label_tab_sms' => psm_get_lang('config', 'tab_sms'),
|
'label_tab_sms' => psm_get_lang('config', 'tab_sms'),
|
||||||
'label_tab_pushover' => psm_get_lang('config', 'tab_pushover'),
|
'label_tab_pushover' => psm_get_lang('config', 'tab_pushover'),
|
||||||
|
@ -298,6 +338,7 @@ class ConfigController extends AbstractController {
|
||||||
'label_settings_notification' => psm_get_lang('config', 'settings_notification'),
|
'label_settings_notification' => psm_get_lang('config', 'settings_notification'),
|
||||||
'label_settings_log' => psm_get_lang('config', 'settings_log'),
|
'label_settings_log' => psm_get_lang('config', 'settings_log'),
|
||||||
'label_settings_proxy' => psm_get_lang('config', 'settings_proxy'),
|
'label_settings_proxy' => psm_get_lang('config', 'settings_proxy'),
|
||||||
|
'label_settings_telegram' => psm_get_lang('config', 'settings_telegram'),
|
||||||
'label_general' => psm_get_lang('config', 'general'),
|
'label_general' => psm_get_lang('config', 'general'),
|
||||||
'label_language' => psm_get_lang('config', 'language'),
|
'label_language' => psm_get_lang('config', 'language'),
|
||||||
'label_show_update' => psm_get_lang('config', 'show_update'),
|
'label_show_update' => psm_get_lang('config', 'show_update'),
|
||||||
|
@ -356,6 +397,7 @@ class ConfigController extends AbstractController {
|
||||||
'label_log_email' => psm_get_lang('config', 'log_email'),
|
'label_log_email' => psm_get_lang('config', 'log_email'),
|
||||||
'label_log_sms' => psm_get_lang('config', 'log_sms'),
|
'label_log_sms' => psm_get_lang('config', 'log_sms'),
|
||||||
'label_log_pushover' => psm_get_lang('config', 'log_pushover'),
|
'label_log_pushover' => psm_get_lang('config', 'log_pushover'),
|
||||||
|
'label_log_telegram' => psm_get_lang('config', 'log_telegram'),
|
||||||
'label_alert_proxy' => psm_get_lang('config', 'alert_proxy'),
|
'label_alert_proxy' => psm_get_lang('config', 'alert_proxy'),
|
||||||
'label_alert_proxy_url' => psm_get_lang('config', 'alert_proxy_url'),
|
'label_alert_proxy_url' => psm_get_lang('config', 'alert_proxy_url'),
|
||||||
'label_auto_refresh' => psm_get_lang('config', 'auto_refresh'),
|
'label_auto_refresh' => psm_get_lang('config', 'auto_refresh'),
|
||||||
|
@ -366,6 +408,12 @@ class ConfigController extends AbstractController {
|
||||||
'label_log_retention_period' => psm_get_lang('config', 'log_retention_period'),
|
'label_log_retention_period' => psm_get_lang('config', 'log_retention_period'),
|
||||||
'label_log_retention_period_description' => psm_get_lang('config', 'log_retention_period_description'),
|
'label_log_retention_period_description' => psm_get_lang('config', 'log_retention_period_description'),
|
||||||
'label_log_retention_days' => psm_get_lang('config', 'log_retention_days'),
|
'label_log_retention_days' => psm_get_lang('config', 'log_retention_days'),
|
||||||
|
'label_telegram_status' => psm_get_lang('config', 'telegram_status'),
|
||||||
|
'label_telegram_bot_api_key' => psm_get_lang('config', 'telegram_bot_api_key'),
|
||||||
|
'label_telegram_api_token_description' => sprintf(
|
||||||
|
psm_get_lang('config', 'telegram_api_token_description'),
|
||||||
|
'https://core.telegram.org/bots#3-how-do-i-create-a-bot'
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -75,6 +75,7 @@ abstract class AbstractServerController extends AbstractController {
|
||||||
`s`.`email`,
|
`s`.`email`,
|
||||||
`s`.`sms`,
|
`s`.`sms`,
|
||||||
`s`.`pushover`,
|
`s`.`pushover`,
|
||||||
|
`s`.`telegram`,
|
||||||
`s`.`warning_threshold`,
|
`s`.`warning_threshold`,
|
||||||
`s`.`warning_threshold_counter`,
|
`s`.`warning_threshold_counter`,
|
||||||
`s`.`timeout`,
|
`s`.`timeout`,
|
||||||
|
|
|
@ -49,6 +49,7 @@ class LogController extends AbstractServerController {
|
||||||
'label_email' => psm_get_lang('log', 'email'),
|
'label_email' => psm_get_lang('log', 'email'),
|
||||||
'label_sms' => psm_get_lang('log', 'sms'),
|
'label_sms' => psm_get_lang('log', 'sms'),
|
||||||
'label_pushover' => psm_get_lang('log', 'pushover'),
|
'label_pushover' => psm_get_lang('log', 'pushover'),
|
||||||
|
'label_telegram' => psm_get_lang('log', 'telegram'),
|
||||||
'label_title' => psm_get_lang('log', 'title'),
|
'label_title' => psm_get_lang('log', 'title'),
|
||||||
'label_server' => psm_get_lang('servers', 'server'),
|
'label_server' => psm_get_lang('servers', 'server'),
|
||||||
'label_type' => psm_get_lang('log', 'type'),
|
'label_type' => psm_get_lang('log', 'type'),
|
||||||
|
@ -58,7 +59,7 @@ class LogController extends AbstractServerController {
|
||||||
'label_no_logs' => psm_get_lang('log', 'no_logs'),
|
'label_no_logs' => psm_get_lang('log', 'no_logs'),
|
||||||
'tabs' => array(),
|
'tabs' => array(),
|
||||||
);
|
);
|
||||||
$log_types = array('status', 'email', 'sms', 'pushover');
|
$log_types = array('status', 'email', 'sms', 'pushover', 'telegram');
|
||||||
|
|
||||||
foreach($log_types as $key) {
|
foreach($log_types as $key) {
|
||||||
$records = $this->getEntries($key);
|
$records = $this->getEntries($key);
|
||||||
|
|
|
@ -92,6 +92,7 @@ class ServerController extends AbstractServerController {
|
||||||
'email' => 'icon-envelope',
|
'email' => 'icon-envelope',
|
||||||
'sms' => 'icon-mobile',
|
'sms' => 'icon-mobile',
|
||||||
'pushover' => 'icon-pushover',
|
'pushover' => 'icon-pushover',
|
||||||
|
'telegram' => 'icon-star', //TODO: Add telegram icon
|
||||||
);
|
);
|
||||||
|
|
||||||
$servers = $this->getServers();
|
$servers = $this->getServers();
|
||||||
|
@ -208,10 +209,11 @@ class ServerController extends AbstractServerController {
|
||||||
'edit_email_selected_' . $edit_server['email'] => 'selected="selected"',
|
'edit_email_selected_' . $edit_server['email'] => 'selected="selected"',
|
||||||
'edit_sms_selected_' . $edit_server['sms'] => 'selected="selected"',
|
'edit_sms_selected_' . $edit_server['sms'] => 'selected="selected"',
|
||||||
'edit_pushover_selected_' . $edit_server['pushover'] => 'selected="selected"',
|
'edit_pushover_selected_' . $edit_server['pushover'] => 'selected="selected"',
|
||||||
|
'edit_telegram_selected_' . $edit_server['telegram'] => 'selected="selected"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$notifications = array('email', 'sms', 'pushover');
|
$notifications = array('email', 'sms', 'pushover', 'telegram');
|
||||||
foreach($notifications as $notification) {
|
foreach($notifications as $notification) {
|
||||||
if(psm_get_conf($notification . '_status') == 0) {
|
if(psm_get_conf($notification . '_status') == 0) {
|
||||||
$tpl_data['warning_' . $notification] = true;
|
$tpl_data['warning_' . $notification] = true;
|
||||||
|
@ -272,6 +274,7 @@ class ServerController extends AbstractServerController {
|
||||||
'email' => in_array($_POST['email'], array('yes', 'no')) ? $_POST['email'] : 'no',
|
'email' => in_array($_POST['email'], array('yes', 'no')) ? $_POST['email'] : 'no',
|
||||||
'sms' => in_array($_POST['sms'], array('yes', 'no')) ? $_POST['sms'] : 'no',
|
'sms' => in_array($_POST['sms'], array('yes', 'no')) ? $_POST['sms'] : 'no',
|
||||||
'pushover' => in_array($_POST['pushover'], array('yes', 'no')) ? $_POST['pushover'] : 'no',
|
'pushover' => in_array($_POST['pushover'], array('yes', 'no')) ? $_POST['pushover'] : 'no',
|
||||||
|
'telegram' => in_array($_POST['telegram'], array('yes', 'no')) ? $_POST['telegram'] : 'no',
|
||||||
);
|
);
|
||||||
// make sure websites start with http://
|
// make sure websites start with http://
|
||||||
if($clean['type'] == 'website' && substr($clean['ip'], 0, 4) != 'http') {
|
if($clean['type'] == 'website' && substr($clean['ip'], 0, 4) != 'http') {
|
||||||
|
@ -479,6 +482,7 @@ class ServerController extends AbstractServerController {
|
||||||
'label_sms' => psm_get_lang('servers', 'sms'),
|
'label_sms' => psm_get_lang('servers', 'sms'),
|
||||||
'label_send_sms' => psm_get_lang('servers', 'send_sms'),
|
'label_send_sms' => psm_get_lang('servers', 'send_sms'),
|
||||||
'label_pushover' => psm_get_lang('servers', 'pushover'),
|
'label_pushover' => psm_get_lang('servers', 'pushover'),
|
||||||
|
'label_telegram' => psm_get_lang('servers', 'telegram'),
|
||||||
'label_users' => psm_get_lang('servers', 'users'),
|
'label_users' => psm_get_lang('servers', 'users'),
|
||||||
'label_warning_threshold' => psm_get_lang('servers', 'warning_threshold'),
|
'label_warning_threshold' => psm_get_lang('servers', 'warning_threshold'),
|
||||||
'label_warning_threshold_description' => psm_get_lang('servers', 'warning_threshold_description'),
|
'label_warning_threshold_description' => psm_get_lang('servers', 'warning_threshold_description'),
|
||||||
|
|
|
@ -35,7 +35,7 @@ class ProfileController extends AbstractController {
|
||||||
* Editable fields for the profile
|
* Editable fields for the profile
|
||||||
* @var array $profile_fields
|
* @var array $profile_fields
|
||||||
*/
|
*/
|
||||||
protected $profile_fields = array('name', 'user_name', 'mobile', 'pushover_key', 'pushover_device', 'email');
|
protected $profile_fields = array('name', 'user_name', 'mobile', 'pushover_key', 'pushover_device', 'email', 'telegram_user_code');
|
||||||
|
|
||||||
function __construct(Database $db, \Twig_Environment $twig) {
|
function __construct(Database $db, \Twig_Environment $twig) {
|
||||||
parent::__construct($db, $twig);
|
parent::__construct($db, $twig);
|
||||||
|
@ -61,6 +61,10 @@ class ProfileController extends AbstractController {
|
||||||
'label_password_repeat' => psm_get_lang('users', 'password_repeat'),
|
'label_password_repeat' => psm_get_lang('users', 'password_repeat'),
|
||||||
'label_level' => psm_get_lang('users', 'level'),
|
'label_level' => psm_get_lang('users', 'level'),
|
||||||
'label_mobile' => psm_get_lang('users', 'mobile'),
|
'label_mobile' => psm_get_lang('users', 'mobile'),
|
||||||
|
|
||||||
|
'label_telegram_user_code' => psm_get_lang('users', 'telegram_user_code'),
|
||||||
|
'label_telegram_user_code_description' => psm_get_lang('users', 'user_code_description'),
|
||||||
|
|
||||||
'label_pushover' => psm_get_lang('users', 'pushover'),
|
'label_pushover' => psm_get_lang('users', 'pushover'),
|
||||||
'label_pushover_description' => psm_get_lang('users', 'pushover_description'),
|
'label_pushover_description' => psm_get_lang('users', 'pushover_description'),
|
||||||
'label_pushover_key' => psm_get_lang('users', 'pushover_key'),
|
'label_pushover_key' => psm_get_lang('users', 'pushover_key'),
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHP Server Monitor
|
||||||
|
* Monitor your servers and websites.
|
||||||
|
*
|
||||||
|
* This file is part of PHP Server Monitor.
|
||||||
|
* PHP Server Monitor is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* PHP Server Monitor is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* @package phpservermon
|
||||||
|
* @author Pepijn Over <pep@mailbox.org>
|
||||||
|
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
|
||||||
|
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
|
||||||
|
* @version Release: @package_version@
|
||||||
|
* @link http://www.phpservermonitor.org/
|
||||||
|
**/
|
||||||
|
|
||||||
|
namespace psm\Service;
|
||||||
|
|
||||||
|
class Telegram {
|
||||||
|
|
||||||
|
private $apiKey;
|
||||||
|
|
||||||
|
public function __construct($apiKey) {
|
||||||
|
if(empty($apiKey)) {
|
||||||
|
throw new \Exception('ApiKey is not defined');
|
||||||
|
}
|
||||||
|
$this->apiKey = $apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getUrl() {
|
||||||
|
return 'https://api.telegram.org/bot' . $this->apiKey . '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function doGet ($method) {
|
||||||
|
$request = file_get_contents($this->getUrl() . $method);
|
||||||
|
return json_decode($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available Telegram Methods
|
||||||
|
*/
|
||||||
|
public function sendMessage($obj) {
|
||||||
|
return $this->doGet('sendMessage?' . http_build_query($obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMe() {
|
||||||
|
return $this->doGet('getMe');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUpdates($offset = null) {
|
||||||
|
if(is_null($offset))
|
||||||
|
return $this->doGet('getUpdates');
|
||||||
|
else
|
||||||
|
return $this->doGet('getUpdates?offset=' . $offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -190,6 +190,7 @@ class Installer {
|
||||||
`pushover_key` varchar(255) NOT NULL,
|
`pushover_key` varchar(255) NOT NULL,
|
||||||
`pushover_device` varchar(255) NOT NULL,
|
`pushover_device` varchar(255) NOT NULL,
|
||||||
`email` varchar(255) NOT NULL,
|
`email` varchar(255) NOT NULL,
|
||||||
|
`telegram_user_code` varchar(255) NOT NULL,
|
||||||
PRIMARY KEY (`user_id`),
|
PRIMARY KEY (`user_id`),
|
||||||
UNIQUE KEY `unique_username` (`user_name`)
|
UNIQUE KEY `unique_username` (`user_name`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
|
||||||
|
@ -207,7 +208,7 @@ class Installer {
|
||||||
PSM_DB_PREFIX . 'log' => "CREATE TABLE `" . PSM_DB_PREFIX . "log` (
|
PSM_DB_PREFIX . 'log' => "CREATE TABLE `" . PSM_DB_PREFIX . "log` (
|
||||||
`log_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
`log_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`server_id` int(11) unsigned NOT NULL,
|
`server_id` int(11) unsigned NOT NULL,
|
||||||
`type` enum('status','email','sms','pushover') NOT NULL,
|
`type` enum('status','email','sms','pushover', 'telegram') NOT NULL,
|
||||||
`message` varchar(255) NOT NULL,
|
`message` varchar(255) NOT NULL,
|
||||||
`datetime` timestamp NOT NULL default CURRENT_TIMESTAMP,
|
`datetime` timestamp NOT NULL default CURRENT_TIMESTAMP,
|
||||||
PRIMARY KEY (`log_id`)
|
PRIMARY KEY (`log_id`)
|
||||||
|
@ -235,6 +236,7 @@ class Installer {
|
||||||
`email` enum('yes','no') NOT NULL default 'yes',
|
`email` enum('yes','no') NOT NULL default 'yes',
|
||||||
`sms` enum('yes','no') NOT NULL default 'no',
|
`sms` enum('yes','no') NOT NULL default 'no',
|
||||||
`pushover` enum('yes','no') NOT NULL default 'yes',
|
`pushover` enum('yes','no') NOT NULL default 'yes',
|
||||||
|
`telegram` enum('yes','no') NOT NULL default 'no',
|
||||||
`warning_threshold` mediumint(1) unsigned NOT NULL DEFAULT '1',
|
`warning_threshold` mediumint(1) unsigned NOT NULL DEFAULT '1',
|
||||||
`warning_threshold_counter` mediumint(1) unsigned NOT NULL DEFAULT '0',
|
`warning_threshold_counter` mediumint(1) unsigned NOT NULL DEFAULT '0',
|
||||||
`timeout` smallint(1) unsigned NULL DEFAULT NULL,
|
`timeout` smallint(1) unsigned NULL DEFAULT NULL,
|
||||||
|
@ -298,7 +300,10 @@ class Installer {
|
||||||
}
|
}
|
||||||
if(version_compare($version_from, '3.2.1', '<')) {
|
if(version_compare($version_from, '3.2.1', '<')) {
|
||||||
$this->upgrade321();
|
$this->upgrade321();
|
||||||
|
} if(version_compare($version_from, '3.3.0', '<')) {
|
||||||
|
$this->upgrade320();
|
||||||
}
|
}
|
||||||
|
|
||||||
psm_update_conf('version', $version_to);
|
psm_update_conf('version', $version_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,4 +497,15 @@ class Installer {
|
||||||
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD COLUMN `header_name` VARCHAR(255) AFTER `pattern`, ADD COLUMN `header_value` VARCHAR(255) AFTER `header_name`";
|
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD COLUMN `header_name` VARCHAR(255) AFTER `pattern`, ADD COLUMN `header_value` VARCHAR(255) AFTER `header_name`";
|
||||||
$this->execSQL($queries);
|
$this->execSQL($queries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade for v3.3.0 release
|
||||||
|
*/
|
||||||
|
protected function upgrade330() {
|
||||||
|
$queries = array();
|
||||||
|
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "log` CHANGE `type` `type` ENUM( 'status', 'email', 'sms', 'pushover', 'telegram' ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;";
|
||||||
|
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "users` ADD `telegram_user_code` VARCHAR( 255 ) NOT NULL AFTER `pushover_device`;";
|
||||||
|
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `telegram` ENUM( 'yes', 'no' ) NOT NULL AFTER `pushover` DEFAULT `no`;";
|
||||||
|
$this->execSQL($queries);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,5 +77,38 @@ class UpdateManager extends ContainerAware {
|
||||||
$archive = new ArchiveManager($this->container->get('db'));
|
$archive = new ArchiveManager($this->container->get('db'));
|
||||||
$archive->archive();
|
$archive->archive();
|
||||||
$archive->cleanup();
|
$archive->cleanup();
|
||||||
|
|
||||||
|
// telegram send code
|
||||||
|
if(psm_get_conf('telegram_status')) {
|
||||||
|
$telegram = new \psm\Service\Telegram(psm_get_conf('telegram_api_token'));
|
||||||
|
|
||||||
|
$offset = psm_get_conf('telegram_updates_offset');
|
||||||
|
if(empty($offset)) {
|
||||||
|
$updates = $telegram->getUpdates();
|
||||||
|
} else {
|
||||||
|
$updates = $telegram->getUpdates($offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($updates && $updates->ok) {
|
||||||
|
foreach($updates->result as $result) {
|
||||||
|
|
||||||
|
if($result->update_id == $offset) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$telegram->sendMessage(
|
||||||
|
[
|
||||||
|
'chat_id' => $result->message->chat->id,
|
||||||
|
'text' => 'Hello ' . $result->message->chat->first_name . ' ' . $result->message->chat->last_name . "\n" .
|
||||||
|
'Your PhpServerMon code is ' . $result->message->chat->id
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
psm_update_conf('telegram_updates_offset', $result->update_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -60,6 +60,12 @@ class StatusNotifier {
|
||||||
*/
|
*/
|
||||||
protected $send_pushover = false;
|
protected $send_pushover = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send telegram?
|
||||||
|
* @var boolean $send_telegram
|
||||||
|
*/
|
||||||
|
protected $send_telegram = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save log records?
|
* Save log records?
|
||||||
* @var boolean $save_log
|
* @var boolean $save_log
|
||||||
|
@ -96,6 +102,7 @@ class StatusNotifier {
|
||||||
$this->send_emails = psm_get_conf('email_status');
|
$this->send_emails = psm_get_conf('email_status');
|
||||||
$this->send_sms = psm_get_conf('sms_status');
|
$this->send_sms = psm_get_conf('sms_status');
|
||||||
$this->send_pushover = psm_get_conf('pushover_status');
|
$this->send_pushover = psm_get_conf('pushover_status');
|
||||||
|
$this->send_telegram = psm_get_conf('telegram_status');
|
||||||
$this->save_logs = psm_get_conf('log_status');
|
$this->save_logs = psm_get_conf('log_status');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +128,7 @@ class StatusNotifier {
|
||||||
$this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array(
|
$this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array(
|
||||||
'server_id' => $server_id,
|
'server_id' => $server_id,
|
||||||
), array(
|
), array(
|
||||||
'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'header_name', 'header_value', 'error', 'active', 'email', 'sms', 'pushover',
|
'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'header_name', 'header_value', 'error', 'active', 'email', 'sms', 'pushover', 'telegram',
|
||||||
));
|
));
|
||||||
if(empty($this->server)) {
|
if(empty($this->server)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -188,6 +195,12 @@ class StatusNotifier {
|
||||||
$this->notifyByPushover($users);
|
$this->notifyByPushover($users);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if telegram is enabled for this server
|
||||||
|
if($this->send_telegram && $this->server['telegram'] == 'yes') {
|
||||||
|
// yay lets wake those nerds up!
|
||||||
|
$this->notifyByTelegram($users);
|
||||||
|
}
|
||||||
|
|
||||||
return $notify;
|
return $notify;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,6 +237,53 @@ class StatusNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This functions performs the telegram notifications
|
||||||
|
*
|
||||||
|
* @param array $users
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
protected function notifyByTelegram($users) {
|
||||||
|
// Remove users that have no pushover_key
|
||||||
|
foreach($users as $k => $user) {
|
||||||
|
if (trim($user['telegram_user_code']) == '') {
|
||||||
|
unset($users[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validation
|
||||||
|
if (empty($users)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = psm_parse_msg($this->status_new, 'email_body', $this->server);
|
||||||
|
$body = str_replace('<br/>', "\n", $body);
|
||||||
|
|
||||||
|
//if(psm_get_conf('log_telegram')) {
|
||||||
|
$log_id = psm_add_log($this->server_id, 'telegram', $body);
|
||||||
|
//}
|
||||||
|
|
||||||
|
$telegram = new \psm\Service\Telegram(psm_get_conf('telegram_api_token'));
|
||||||
|
|
||||||
|
// go through empl
|
||||||
|
foreach ($users as $user) {
|
||||||
|
if(!empty($log_id)) {
|
||||||
|
psm_add_log_user($log_id, $user['user_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uc = $user['telegram_user_code'];
|
||||||
|
$telegram->sendMessage(
|
||||||
|
[
|
||||||
|
'chat_id' => $uc,
|
||||||
|
'text' => $body
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This functions performs the pushover notifications
|
* This functions performs the pushover notifications
|
||||||
*
|
*
|
||||||
|
@ -321,7 +381,7 @@ class StatusNotifier {
|
||||||
public function getUsers($server_id) {
|
public function getUsers($server_id) {
|
||||||
// find all the users with this server listed
|
// find all the users with this server listed
|
||||||
$users = $this->db->query("
|
$users = $this->db->query("
|
||||||
SELECT `u`.`user_id`, `u`.`name`,`u`.`email`, `u`.`mobile`, `u`.`pushover_key`, `u`.`pushover_device`
|
SELECT `u`.`user_id`, `u`.`name`,`u`.`email`, `u`.`mobile`, `u`.`pushover_key`, `u`.`pushover_device`, `u`.`telegram_user_code`
|
||||||
FROM `".PSM_DB_PREFIX."users` AS `u`
|
FROM `".PSM_DB_PREFIX."users` AS `u`
|
||||||
JOIN `".PSM_DB_PREFIX."users_servers` AS `us` ON (
|
JOIN `".PSM_DB_PREFIX."users_servers` AS `us` ON (
|
||||||
`us`.`user_id`=`u`.`user_id`
|
`us`.`user_id`=`u`.`user_id`
|
||||||
|
|
|
@ -105,7 +105,7 @@ class StatusUpdater {
|
||||||
$save = array(
|
$save = array(
|
||||||
'last_check' => date('Y-m-d H:i:s'),
|
'last_check' => date('Y-m-d H:i:s'),
|
||||||
'error' => $this->error,
|
'error' => $this->error,
|
||||||
'rtime' => $this->rtime,
|
'rtime' => empty($this->rtime) ? 0 : $this->rtime,
|
||||||
);
|
);
|
||||||
|
|
||||||
// log the uptime before checking the warning threshold,
|
// log the uptime before checking the warning threshold,
|
||||||
|
@ -119,6 +119,7 @@ class StatusUpdater {
|
||||||
$save['warning_threshold_counter'] = 0;
|
$save['warning_threshold_counter'] = 0;
|
||||||
} else {
|
} else {
|
||||||
// server is offline, increase the error counter
|
// server is offline, increase the error counter
|
||||||
|
|
||||||
$save['warning_threshold_counter'] = $this->server['warning_threshold_counter'] + 1;
|
$save['warning_threshold_counter'] = $this->server['warning_threshold_counter'] + 1;
|
||||||
|
|
||||||
if($save['warning_threshold_counter'] < $this->server['warning_threshold']) {
|
if($save['warning_threshold_counter'] < $this->server['warning_threshold']) {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<li class="{{ email_active }}"><a href="#config-email" data-toggle="tab">{{ label_tab_email }}</a></li>
|
<li class="{{ email_active }}"><a href="#config-email" data-toggle="tab">{{ label_tab_email }}</a></li>
|
||||||
<li class="{{ sms_active }}"><a href="#config-sms" data-toggle="tab">{{ label_tab_sms }}</a></li>
|
<li class="{{ sms_active }}"><a href="#config-sms" data-toggle="tab">{{ label_tab_sms }}</a></li>
|
||||||
<li class="{{ pushover_active }}"><a href="#config-pushover" data-toggle="tab">{{ label_tab_pushover }}</a></li>
|
<li class="{{ pushover_active }}"><a href="#config-pushover" data-toggle="tab">{{ label_tab_pushover }}</a></li>
|
||||||
|
<li class="{{ telegram_active }}"><a href="#config-telegram" data-toggle="tab">{{ label_tab_telegram }}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content well">
|
<div class="tab-content well">
|
||||||
<div id="config-general" class="tab-pane {{ general_active }}">
|
<div id="config-general" class="tab-pane {{ general_active }}">
|
||||||
|
@ -232,7 +233,7 @@
|
||||||
<button class="btn btn-success" type="submit" name="sms_submit">{{ label_save }}</button>
|
<button class="btn btn-success" type="submit" name="sms_submit">{{ label_save }}</button>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<div id="config-pushover" class="tab-pane {{ pushover_active }}">
|
<div id="config-pushover" class="tab-pane {{ pushover_active }}">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{{ label_settings_pushover }}</legend>
|
<legend>{{ label_settings_pushover }}</legend>
|
||||||
|
@ -265,7 +266,43 @@
|
||||||
<button class="btn btn-success" type="submit" name="pushover_submit">{{ label_save }}</button>
|
<button class="btn btn-success" type="submit" name="pushover_submit">{{ label_save }}</button>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="config-telegram" class="tab-pane {{ telegram_active }}">
|
||||||
|
<fieldset>
|
||||||
|
<legend>{{ label_settings_telegram }}</legend>
|
||||||
|
<div class="control-group">
|
||||||
|
<div class="controls">
|
||||||
|
<label class="checkbox" for="telegram_status"><input type="checkbox" id="telegram_status" name="telegram_status[]" {{ telegram_status_checked|raw }} /> {{ label_telegram_status }}</label>
|
||||||
|
<p class="help-block">{{ label_telegram_description|raw }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<div class="controls">
|
||||||
|
<label class="checkbox"><input type="checkbox" id="log_telegram" name="log_telegram[]" {{ log_telegram_checked|raw }} /> {{ label_log_telegram }}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label" for="pushover_api_token">{{ label_telegram_bot_api_key }}</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" id="telegram_api_token" name="telegram_api_token" value="{{ telegram_api_token }}" maxlength="255" />
|
||||||
|
<p class="help-block">{{ label_telegram_api_token_description|raw }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<div class="controls">
|
||||||
|
<button class="btn btn-primary show-modal" data-modal-id="testTelegram">{{ label_test }}</button>
|
||||||
|
<input type="hidden" name="test_telegram" value="0" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<button class="btn btn-success" type="submit" name="telegram_submit">{{ label_save }}</button>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{ macro.csrf_input() }}
|
{{ macro.csrf_input() }}
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<li><a href="#log_email_content" data-toggle="tab">{{ label_email }}</a></li>
|
<li><a href="#log_email_content" data-toggle="tab">{{ label_email }}</a></li>
|
||||||
<li><a href="#log_sms_content" data-toggle="tab">{{ label_sms }}</a></li>
|
<li><a href="#log_sms_content" data-toggle="tab">{{ label_sms }}</a></li>
|
||||||
<li><a href="#log_pushover_content" data-toggle="tab">{{ label_pushover }}</a></li>
|
<li><a href="#log_pushover_content" data-toggle="tab">{{ label_pushover }}</a></li>
|
||||||
|
<li><a href="#log_telegram_content" data-toggle="tab">{{ label_telegram }}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content well">
|
<div class="tab-content well">
|
||||||
{% for tab in tabs %}
|
{% for tab in tabs %}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<td class="nowrap visible-desktop"><div class="table-cell-title">{{ server.type }}</div></td>
|
<td class="nowrap visible-desktop"><div class="table-cell-title">{{ server.type }}</div></td>
|
||||||
<td class="nowrap hidden-phone"><div class="table-cell-title">{{ server.rtime }} s</div></td>
|
<td class="nowrap hidden-phone"><div class="table-cell-title">{{ server.rtime }} s</div></td>
|
||||||
<td class="nowrap hidden-phone"><div class="table-cell-title">{{ server.last_online }}</div></td>
|
<td class="nowrap hidden-phone"><div class="table-cell-title">{{ server.last_online }}</div></td>
|
||||||
<td class="tight hidden-phone"><div class="table-cell-title"><i class="{{ server.active_icon }}" title="{{ server.active_title }}"></i> <i class="{{ server.email_icon }}" title="{{ label_email }}"></i> <i class="{{ server.sms_icon }}" title="{{ label_sms }}"></i> <i class="{{ server.pushover_icon }}" title="Pushover"></i></div></td>
|
<td class="tight hidden-phone"><div class="table-cell-title"><i class="{{ server.active_icon }}" title="{{ server.active_title }}"></i> <i class="{{ server.email_icon }}" title="{{ label_email }}"></i> <i class="{{ server.sms_icon }}" title="{{ label_sms }}"></i> <i class="{{ server.pushover_icon }}" title="Pushover"></i> <i class="{{ server.telegram_icon }}" title="{{ label_telegram }}"></i> </div></td>
|
||||||
<td class="tight hidden-phone">
|
<td class="tight hidden-phone">
|
||||||
<div class="table-cell-title">
|
<div class="table-cell-title">
|
||||||
<a class="btn btn-small" href="{{ server.url_view|raw }}"><i class="icon-chart"></i></a>
|
<a class="btn btn-small" href="{{ server.url_view|raw }}"><i class="icon-chart"></i></a>
|
||||||
|
|
|
@ -146,6 +146,17 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="control-group {{ control_class_telegram }}">
|
||||||
|
<label class="control-label" for="telegram">{{ label_telegram }}
|
||||||
|
{% if warning_telegram %} <p class="help-inline"><i class="icon-warning-sign" data-toggle="tooltip" title="{{ label_warning_telegram }}"></i></p> {% endif %}
|
||||||
|
</label>
|
||||||
|
<div class="controls">
|
||||||
|
<select id="telegram" name="telegram">
|
||||||
|
<option value="yes" {{ edit_telegram_selected_yes|raw }}>{{ label_yes }}</option>
|
||||||
|
<option value="no" {{ edit_telegram_selected_no|raw }}>{{ label_no }}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
|
|
@ -69,6 +69,10 @@
|
||||||
<td>{{ label_pushover }}:</td>
|
<td>{{ label_pushover }}:</td>
|
||||||
<td>{{ pushover }}</td>
|
<td>{{ pushover }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ label_telegram }}:</td>
|
||||||
|
<td>{{ telegram }}</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ label_timeout }}:</td>
|
<td>{{ label_timeout }}:</td>
|
||||||
<td>{{ timeout }} s</td>
|
<td>{{ timeout }} s</td>
|
||||||
|
|
|
@ -62,6 +62,13 @@
|
||||||
<input type="text" id="pushover_device" name="pushover_device" value="{{ pushover_device }}" maxlength="255" data-toggle="tooltip" title="{{ label_pushover_device_description }}" />
|
<input type="text" id="pushover_device" name="pushover_device" value="{{ pushover_device }}" maxlength="255" data-toggle="tooltip" title="{{ label_pushover_device_description }}" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label" for="mobile">{{ label_telegram_user_code }}</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" id="telegram_user_code" name="telegram_user_code" value="{{ telegram_user_code }}" maxlength="255" data-toggle="tooltip" title="{{ label_telegram_user_code_description }}" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row-fluid">
|
<div class="row-fluid">
|
||||||
|
|
Loading…
Reference in New Issue