diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 59717599..dd34bb29 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -1068,23 +1068,22 @@ namespace { { protected $url; protected $json; - protected $message; /** * Send Webhook * * @return bool|string - * @var string $message + * @var array $replacements an array of the replacements * */ - public function sendWebhook($message) + public function sendWebhook($replacements) { $error = ""; $success = 1; - $this->setMessage($message); - $jsonMessage = strtr($this->json, array('#message' => $this->message)); + $replacements['#message'] = $this->stripTagsFromMessage($replacements['#message']); + $jsonMessage = strtr($this->json, $replacements); $curl = curl_init($this->url); curl_setopt($curl, CURLOPT_POST, 1); @@ -1160,7 +1159,7 @@ namespace { * @var string $message * */ - public function setMessage($message) + public function stripTagsFromMessage($message) { $message = str_replace("", "\n", $message); @@ -1171,7 +1170,7 @@ namespace { $message = str_replace("", "", $message); $message = str_replace("", "", $message); $message = strip_tags($message); - $this->message = (string)$message; + return (string)$message; } } } diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index c8e6fbe5..b9f61d65 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -136,7 +136,7 @@ $sm_lang = array( 'webhook_url' => 'Webhook Url', 'webhook_url_description' => 'Webhook public endpoint url, should start with https://.', 'webhook_json' => 'Webhook JSON', - 'webhook_json_description' => 'Define a custom json, use #message as message variable.', + 'webhook_json_description' => 'Define a custom json, use #message as message variable, other variables are #server_ip, #server_label, #server_last_offline_duration and #status', 'delete_title' => 'Delete User', 'delete_message' => 'Are you sure you want to delete user \'%1\'?', 'deleted' => 'User deleted.', @@ -315,7 +315,7 @@ $sm_lang = array( 'webhook_url' => 'Webhook Url', 'webhook_url_description' => 'Url to webhook endpoint', 'webhook_json' => 'Webhook Json', - 'webhook_json_description' => 'Customized Json, use #message as message variable.', + 'webhook_json_description' => 'Customized Json, use #message as message variable, other variables are #server_ip, #server_label, #server_last_offline_duration and #status.', 'pushover_status' => 'Allow sending Pushover messages', 'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See their website for more info.', 'pushover_clone_app' => 'Click here to create your Pushover app', diff --git a/src/psm/Util/Server/Updater/StatusNotifier.php b/src/psm/Util/Server/Updater/StatusNotifier.php index dd145db7..7b4bd1d2 100644 --- a/src/psm/Util/Server/Updater/StatusNotifier.php +++ b/src/psm/Util/Server/Updater/StatusNotifier.php @@ -316,7 +316,7 @@ class StatusNotifier } return; } - + $this->combiNotification['notifications'][$method][$status][$this->server_id] = psm_parse_msg($this->status_new, $method . '_message', $this->server, true); } @@ -631,7 +631,13 @@ class StatusNotifier } $webhook->setUrl($user['webhook_url']); $webhook->setJson($user['webhook_json']); - $webhook->sendWebhook($message); + $webhook->sendWebhook([ + '#message' => $message, + '#server_ip' => $this->server['ip'], + '#server_label' => $this->server['label'], + '#server_last_offline_duration' => $this->status_new ? $this->server['last_offline_duration'] : '', + '#status' => $this->status_new ? 'online' : 'offline' + ]); } } /** @@ -697,12 +703,12 @@ class StatusNotifier psm_parse_msg($this->status_new, 'telegram_message', $this->server); $telegram = psm_build_telegram(); $telegram->setMessage($message); - + // Log if (psm_get_conf('log_telegram')) { $log_id = psm_add_log($this->server_id, 'telegram', $message); } - + foreach ($users as $user) { // Log if (!empty($log_id)) {