add feature "add url" to email and telegram

This commit is contained in:
Wienfuchs 2021-01-23 14:26:26 +01:00
parent 17cb13364b
commit ed913c68fd
No known key found for this signature in database
GPG Key ID: B095DFF49268F245
7 changed files with 112 additions and 93 deletions

View File

@ -196,6 +196,7 @@ $sm_lang = array(
'general' => 'Allgemein',
'language' => 'Sprache',
'show_update' => 'Wöchentlich auf Aktualisierungen prüfen?',
'email_add_url' => 'Server URL an E-Mail anhängen?',
'email_status' => 'E-Mail-Versand erlauben?',
'email_from_email' => 'Absenderadresse',
'email_from_name' => 'Name des Absenders',
@ -221,6 +222,9 @@ $sm_lang = array(
'pushover_api_token_description' => 'Bevor Sie Pushover verwenden können, müssen Sie Ihre <a href="%1$s"
target="_blank" rel="noopener">Anwendung hier registrieren</a> und Ihren
Anwendungs-API-Token hier eingeben.',
'telegram_status' => 'Telegram Nachrichten erlauben?',
'telegram_add_url' => 'Server URL an Nachricht anhängen?',
'jabber_status' => 'Allow sending Jabber (XMPP) messages',
'alert_type' => 'Wann möchten Sie benachrichtigt werden?',
'alert_type_description' => '<b>Status geändert:</b> ... wenn sich der Status ändert<br>z. B. online ->
offline oder offline -> online.<br><br><b>Offline: </b>Sie bekommen eine
@ -237,6 +241,7 @@ $sm_lang = array(
'log_email' => 'E-Mail-Versand protokollieren?',
'log_sms' => 'SMS-Versand protokollieren?',
'log_pushover' => 'Pushover-Versand protokollieren?',
'log_telegram' => 'Telegram-Versand protokollieren?',
'updated' => 'Die Einstellungen wurden gespeichert.',
'tab_email' => 'E-Mail',
'tab_sms' => 'SMS',

View File

@ -297,6 +297,7 @@ $sm_lang = array(
'proxy_user' => 'Proxy username',
'proxy_password' => 'Proxy password',
'email_status' => 'Allow sending email',
'email_add_url' => 'add server url to email',
'email_from_email' => 'Email from address',
'email_from_name' => 'Email from name',
'email_smtp' => 'Enable SMTP',
@ -326,6 +327,7 @@ $sm_lang = array(
'pushover_api_token' => 'Pushover App API Token',
'pushover_api_token_description' => 'Before you can use Pushover, you need to <a href="%1$s" target="_blank" rel="noopener">register an App</a> at their website and enter the App API Token here.',
'telegram_status' => 'Allow sending Telegram messages',
'telegram_add_url' => 'add server url to message',
'telegram_description' => '<a href="https://telegram.org/" target="_blank">Telegram</a> is a chat app that makes it easy to get real-time notifications. Visit the <a href="http://docs.phpservermonitor.org/" target="_blank">documentation</a> for more info and an install guide.',
'telegram_api_token' => 'Telegram API Token',
'telegram_api_token_description' => 'Before you can use Telegram, you need to get a API token. Visit the <a href="http://docs.phpservermonitor.org/" target="_blank">documentation</a> for help.',

View File

@ -41,12 +41,14 @@ class ConfigController extends AbstractController
protected $checkboxes = array(
'proxy',
'email_status',
'email_add_url',
'email_smtp',
'sms_status',
'discord_status',
'pushover_status',
'webhook_status',
'telegram_status',
'telegram_add_url',
'jabber_status',
'log_status',
'log_email',
@ -602,6 +604,7 @@ class ConfigController extends AbstractController
'label_proxy_url' => psm_get_lang('config', 'proxy_url'),
'label_proxy_user' => psm_get_lang('config', 'proxy_user'),
'label_proxy_password' => psm_get_lang('config', 'proxy_password'),
'label_email_add_url' => psm_get_lang('config', 'email_add_url'),
'label_email_status' => psm_get_lang('config', 'email_status'),
'label_email_from_email' => psm_get_lang('config', 'email_from_email'),
'label_email_from_name' => psm_get_lang('config', 'email_from_name'),
@ -636,6 +639,7 @@ class ConfigController extends AbstractController
),
'label_telegram_description' => psm_get_lang('config', 'telegram_description'),
'label_telegram_status' => psm_get_lang('config', 'telegram_status'),
'label_telegram_add_url' => psm_get_lang('config', 'telegram_add_url'),
'label_telegram_api_token' => psm_get_lang('config', 'telegram_api_token'),
'label_telegram_api_token_description' => psm_get_lang('config', 'telegram_api_token_description'),
'label_jabber_status' => psm_get_lang('config', 'jabber_status'),

View File

@ -1,91 +1,91 @@
<?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 Victor Macko
* @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/
* @since phpservermon 3.6.0
**/
namespace psm\Txtmsg;
class Infobip extends Core
{
/**
* Send sms using the infobip.com API
*
* @var string $message
* @var string $this->password
* @var array $this->recipients
* @var array $this->originator
* @var string $recipients
*
* @var resource $curl
* @var string $err
* @var mixed $result
*
* @var int $success
* @var string $error
*
* @return bool|string
*/
public function sendSMS($message)
{
$success = 1;
$error = '';
foreach ($this->recipients as $recipient) {
$ch = curl_init();
curl_setopt(
$ch,
CURLOPT_URL,
"https://api.infobip.com/sms/1/text/query?username=" . $this->username .
"&password=" . $this->password .
"&to=" . $recipient .
"&text=" . urlencode($message) .
//add your sender id here
"&from="
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
curl_close($ch);
// Check for errors
if (is_numeric(strpos($result, "FAILED"))) {
$error = $result;
$success = 0;
}
}
if ($success == 1) {
return 1;
}
return $error;
}
}
<?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 Victor Macko
* @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/
* @since phpservermon 3.6.0
**/
namespace psm\Txtmsg;
class Infobip extends Core
{
/**
* Send sms using the infobip.com API
*
* @var string $message
* @var string $this->password
* @var array $this->recipients
* @var array $this->originator
* @var string $recipients
*
* @var resource $curl
* @var string $err
* @var mixed $result
*
* @var int $success
* @var string $error
*
* @return bool|string
*/
public function sendSMS($message)
{
$success = 1;
$error = '';
foreach ($this->recipients as $recipient) {
$ch = curl_init();
curl_setopt(
$ch,
CURLOPT_URL,
"https://api.infobip.com/sms/1/text/query?username=" . $this->username .
"&password=" . $this->password .
"&to=" . $recipient .
"&text=" . urlencode($message) .
//add your sender id here
"&from="
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
curl_close($ch);
// Check for errors
if (is_numeric(strpos($result, "FAILED"))) {
$error = $result;
$success = 0;
}
}
if ($success == 1) {
return 1;
}
return $error;
}
}

View File

@ -147,6 +147,7 @@ class Installer
('proxy_user', ''),
('proxy_password', ''),
('email_status', '1'),
('email_add_url', '0'),
('email_from_email', 'monitor@example.org'),
('email_from_name', 'Server Monitor'),
('email_smtp', ''),
@ -164,6 +165,7 @@ class Installer
('pushover_status', '0'),
('pushover_api_token', ''),
('telegram_status', '0'),
('telegram_add_url', '0'),
('telegram_api_token', ''),
('jabber_status', '1'),
('jabber_host', ''),

View File

@ -426,7 +426,8 @@ class StatusNotifier
$body = key_exists('message', $combi) ?
$combi['message'] :
psm_parse_msg($this->status_new, 'email_body', $this->server);
psm_parse_msg($this->status_new, 'email_body', $this->server);
if (bool)psm_get_conf('email_add_url')) $body .= PHP_EOL.PHP_EOL.'<a href="'.PSM_BASE_URL.'">'.PSM_BASE_URL.'</a>';
$mail->Body = $body;
$mail->AltBody = str_replace('<br/>', "\n", $body);
@ -695,8 +696,9 @@ class StatusNotifier
$message = key_exists('message', $combi) ?
$combi['message'] :
psm_parse_msg($this->status_new, 'telegram_message', $this->server);
if (bool)psm_get_conf('telegram_add_url')) $body .= PHP_EOL.PSM_BASE_URL;
$telegram = psm_build_telegram();
$telegram->setMessage($message);
$telegram->setMessage($message;
// Log
if (psm_get_conf('log_telegram')) {

View File

@ -142,6 +142,8 @@
{{ macro.input_checkbox("email_status", "email_status[]", label_email_status, email_status_checked) }}
<!-- enable email log -->
{{ macro.input_checkbox("log_email", "log_email[]", label_log_email, log_email_checked) }}
<!-- enable adding url to email -->
{{ macro.input_checkbox("email_add_url", "email_add_url[]", label_email_add_url, email_add_url_checked) }}
<!-- email name -->
{{ macro.input_field("text", "email_from_name", null, "email_from_name", label_email_from_name, email_from_name, label_email_from_name, "255") }}
<!-- email address -->
@ -222,6 +224,8 @@
{{ macro.input_checkbox("telegram_status", "telegram_status[]", label_telegram_status, telegram_status_checked) }}
<!-- enable telegram log -->
{{ macro.input_checkbox("log_telegram", "log_telegram[]", label_log_telegram, log_telegram_checked) }}
<!-- enable adding url to telegram -->
{{ macro.input_checkbox("telegram_add_url", "telegram_add_url[]", label_telegram_add_url, telegram_add_url_checked) }}
<!-- telegram key -->
{{ macro.input_field("text", "telegram_api_token", null, "telegram_api_token", label_telegram_api_token, telegram_api_token, label_telegram_api_token, "255", "telegram_api_token_help", label_telegram_api_token_description) }}
{{ macro.button_test("testTelegram", label_test) }}