From ed913c68fdd0660f81e0057b1448ab74a25562d8 Mon Sep 17 00:00:00 2001 From: Wienfuchs Date: Sat, 23 Jan 2021 14:26:26 +0100 Subject: [PATCH] add feature "add url" to email and telegram --- src/lang/de_DE.lang.php | 5 + src/lang/en_US.lang.php | 2 + .../Config/Controller/ConfigController.php | 4 + src/psm/Txtmsg/Infobip.php | 182 +++++++++--------- src/psm/Util/Install/Installer.php | 2 + .../Util/Server/Updater/StatusNotifier.php | 6 +- .../default/module/config/config.tpl.html | 4 + 7 files changed, 112 insertions(+), 93 deletions(-) diff --git a/src/lang/de_DE.lang.php b/src/lang/de_DE.lang.php index ae0a7313..2d711bd2 100644 --- a/src/lang/de_DE.lang.php +++ b/src/lang/de_DE.lang.php @@ -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 Anwendung hier registrieren 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' => 'Status geändert: ... wenn sich der Status ändert
z. B. online -> offline oder offline -> online.

Offline: 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', diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 0d64ce17..ac05e9a9 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -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 register an App 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' => 'Telegram is a chat app that makes it easy to get real-time notifications. Visit the documentation 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 documentation for help.', diff --git a/src/psm/Module/Config/Controller/ConfigController.php b/src/psm/Module/Config/Controller/ConfigController.php index c93ca375..5285ea70 100644 --- a/src/psm/Module/Config/Controller/ConfigController.php +++ b/src/psm/Module/Config/Controller/ConfigController.php @@ -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'), diff --git a/src/psm/Txtmsg/Infobip.php b/src/psm/Txtmsg/Infobip.php index b5edc89d..21d7f880 100644 --- a/src/psm/Txtmsg/Infobip.php +++ b/src/psm/Txtmsg/Infobip.php @@ -1,91 +1,91 @@ -. - * - * @package phpservermon - * @author Victor Macko - * @copyright Copyright (c) 2008-2017 Pepijn Over - * @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; - } -} - +. + * + * @package phpservermon + * @author Victor Macko + * @copyright Copyright (c) 2008-2017 Pepijn Over + * @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; + } +} + diff --git a/src/psm/Util/Install/Installer.php b/src/psm/Util/Install/Installer.php index ab9e5fef..c15b0322 100644 --- a/src/psm/Util/Install/Installer.php +++ b/src/psm/Util/Install/Installer.php @@ -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', ''), diff --git a/src/psm/Util/Server/Updater/StatusNotifier.php b/src/psm/Util/Server/Updater/StatusNotifier.php index dd145db7..d1655d56 100644 --- a/src/psm/Util/Server/Updater/StatusNotifier.php +++ b/src/psm/Util/Server/Updater/StatusNotifier.php @@ -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.''.PSM_BASE_URL.''; $mail->Body = $body; $mail->AltBody = str_replace('
', "\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')) { diff --git a/src/templates/default/module/config/config.tpl.html b/src/templates/default/module/config/config.tpl.html index db5ab029..56fd86b7 100644 --- a/src/templates/default/module/config/config.tpl.html +++ b/src/templates/default/module/config/config.tpl.html @@ -142,6 +142,8 @@ {{ macro.input_checkbox("email_status", "email_status[]", label_email_status, email_status_checked) }} {{ macro.input_checkbox("log_email", "log_email[]", label_log_email, log_email_checked) }} + + {{ macro.input_checkbox("email_add_url", "email_add_url[]", label_email_add_url, email_add_url_checked) }} {{ macro.input_field("text", "email_from_name", null, "email_from_name", label_email_from_name, email_from_name, label_email_from_name, "255") }} @@ -222,6 +224,8 @@ {{ macro.input_checkbox("telegram_status", "telegram_status[]", label_telegram_status, telegram_status_checked) }} {{ macro.input_checkbox("log_telegram", "log_telegram[]", label_log_telegram, log_telegram_checked) }} + + {{ macro.input_checkbox("telegram_add_url", "telegram_add_url[]", label_telegram_add_url, telegram_add_url_checked) }} {{ 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) }}