Added support for Discord using Webhooks

This commit is contained in:
dkrusky 2020-08-09 13:25:38 +00:00
parent 5ecdc75dcf
commit e369ef5428
17 changed files with 336 additions and 138 deletions

View File

@ -5,7 +5,7 @@ PHP Server Monitor
:alt: Join the chat at https://gitter.im/erickrf/nlpnet
:target: https://gitter.im/phpservermon/phpservermon
Version 3.5.0
Version 3.5.1
PHP Server Monitor is a script that checks whether your websites and servers are up and running.
It comes with a web based user interface where you can manage your services and websites,
@ -16,7 +16,7 @@ Features:
---------
* Monitor services and websites (see below).
* Email, SMS, Pushover, Telegram and Jabber notifications.
* Email, SMS, Discord, Pushover, Telegram and Jabber notifications.
* View history graphs of uptime and latency.
* User authentication with 2 levels (administrator and regular user).
* Logs of connection errors, outgoing emails and text messages.

View File

@ -89,6 +89,10 @@ The following people have contributed to the development of PHP Server Monitor:
* SMSAPI gateway
* Daniel Krusky - https://github.com/dkrusky
* Discord webhook support
Translators
+++++++++++
@ -196,4 +200,4 @@ The following libraries are being used by PHP Server Monitor:
* PHP-Pushover - https://github.com/kryap/php-pushover
* Symfony - https://symfony.com
* Random_compat - https://github.com/paragonie/random_compat
* Hammer.js - https://github.com/hammerjs/hammer.js
* Hammer.js - https://github.com/hammerjs/hammer.js

View File

@ -50,9 +50,7 @@ $sm_lang = array(
'no' => 'No',
'insert' => 'Insert',
'add_new' => 'Add new',
'update_available' => 'A new version ({version}) is available. Click <a
href="https://github.com/phpservermon/phpservermon/releases/latest" target="_blank"
rel="noopener">here</a> to download the update.',
'update_available' => 'A new version ({version}) is available. Click <a href="https://github.com/phpservermon/phpservermon/releases/latest" target="_blank" rel="noopener">here</a> to download the update.',
'back_to_top' => 'Back to top',
'go_back' => 'Go back',
'ok' => 'OK',
@ -108,31 +106,25 @@ $sm_lang = array(
'level' => 'Level',
'level_10' => 'Administrator',
'level_20' => 'User',
'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',
'email' => 'Email',
'pushover' => 'Pushover',
'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See <a
href="https://pushover.net/" target="_blank">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/" target="_blank">their website</a> for more info.',
'pushover_key' => 'Pushover Key',
'pushover_device' => 'Pushover Device',
'pushover_device_description' => 'Device name to send the message to. Leave empty to send it to all devices.',
'discord' => 'Discord',
'discord_label' => 'Discord',
'discord_description' => 'Put your <a href="https://discordjs.guide/popular-topics/webhooks.html">webhook</a> here',
'telegram' => 'Telegram',
'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_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_chat_id' => 'Telegram chat id',
'telegram_chat_id_description' => 'The message will be send to the corresponding chat.',
'telegram_get_chat_id' => 'Click here to get your chat id',
'activate_telegram' => 'Activate Telegram notifications',
'activate_telegram_description' => 'Allow Telegram notifications to be sent to the specified chat id. Without
this permission, Telegram doesn\'t allow us to send notifications to you.',
'telegram_bot_username_found' => 'The bot was found!<br><a href="%s" target="_blank" rel="noopener"><button
class="btn btn-primary">Next step</button></a> <br>This will open a chat
with the bot. Here you need to press start or type /start.',
'activate_telegram_description' => 'Allow Telegram notifications to be sent to the specified chat id. Without this permission, Telegram doesn\'t allow us to send notifications to you.',
'telegram_bot_username_found' => 'The bot was found!<br><a href="%s" target="_blank" rel="noopener"><button class="btn btn-primary">Next step</button></a> <br>This will open a chat with the bot. Here you need to press start or type /start.',
'telegram_bot_username_error_token' => '401 - Unauthorized. Please make sure that the API token is valid.',
'telegram_bot_error' => 'An error has occurred while activating Telegram notification: %s',
'jabber' => 'Jabber',
@ -146,8 +138,7 @@ $sm_lang = array(
'profile' => 'Profile',
'profile_updated' => 'Your profile has been updated.',
'error_user_name_bad_length' => 'Usernames must be between 2 and 64 characters.',
'error_user_name_invalid' => 'The username may only contain alphabetic characters (a-z, A-Z), digits (0-9),
dots (.) and underscores (_).',
'error_user_name_invalid' => 'The username may only contain alphabetic characters (a-z, A-Z), digits (0-9), dots (.) and underscores (_).',
'error_user_name_exists' => 'The given username already exists in the database.',
'error_user_email_bad_length' => 'Email addresses must be between 5 and 255 characters.',
'error_user_email_invalid' => 'The email address is invalid.',
@ -163,6 +154,7 @@ $sm_lang = array(
'status' => 'Status',
'email' => 'Email',
'sms' => 'SMS',
'discord' => 'Discord',
'pushover' => 'Pushover',
'telegram' => 'Telegram',
'jabber' => 'Jabber',
@ -201,17 +193,13 @@ $sm_lang = array(
'type_service' => 'Service',
'type_ping' => 'Ping',
'pattern' => 'Search string/pattern',
'pattern_description' => 'If this pattern is not found on the website, the server will be marked
online/offline. Regular expressions are allowed.',
'pattern_description' => 'If this pattern is not found on the website, the server will be marked online/offline. Regular expressions are allowed.',
'pattern_online' => 'Pattern indicates website is',
'pattern_online_description' => 'Online: If this pattern was found on the website, the server will be marked
online. Offline: If this pattern was not found on the website, the server
will be marked offline.',
'pattern_online_description' => 'Online: If this pattern was found on the website, the server will be marked online. Offline: If this pattern was not found on the website, the server will be marked offline.',
'redirect_check' => 'Redirecting to another domain is',
'redirect_check_description' => 'Redirect to another domain is usually a bad sign.',
'allow_http_status' => 'Allow HTTP status code',
'allow_http_status_description' => 'Mark website as online. HTTP Status codes lower then 400 are marked as
online by default. Seperate with |.',
'allow_http_status_description' => 'Mark website as online. HTTP Status codes lower then 400 are marked as online by default. Seperate with |.',
'header_name' => 'Header name',
'header_value' => 'Header value',
'header_name_description' => 'Case-sensitive.',
@ -229,6 +217,8 @@ $sm_lang = array(
'send_email' => 'Send Email',
'sms' => 'SMS',
'send_sms' => 'Send SMS',
'discord' => 'Discord',
'send_discord' => 'Send Discord notificationn',
'pushover' => 'Pushover',
'send_pushover' => 'Send Pushover notification',
'telegram' => 'Telegram',
@ -256,8 +246,7 @@ $sm_lang = array(
'warning_threshold' => 'Warning threshold',
'warning_threshold_description' => 'Number of failed checks required before it is marked offline.',
'ssl_cert_expiry_days' => 'SSL Certificate Validity',
'ssl_cert_expiry_days_description' => 'The minimum remaining days the SSL certificate is still valid. Use 0 to
disable check.',
'ssl_cert_expiry_days_description' => 'The minimum remaining days the SSL certificate is still valid. Use 0 to disable check.',
'ssl_cert_expired' => 'SSL certificate expired since',
'ssl_cert_expiring' => 'SSL certificate expiring:',
'chart_last_week' => 'Last week',
@ -268,6 +257,7 @@ $sm_lang = array(
'chart_short_time_format' => '%H:%M',
'warning_notifications_disabled_sms' => 'SMS notifications are disabled.',
'warning_notifications_disabled_email' => 'Email notifications are disabled.',
'warning_notifications_disabled_discord' => 'Discord notifications are disabled.',
'warning_notifications_disabled_pushover' => 'Pushover notifications are disabled.',
'warning_notifications_disabled_telegram' => 'Telegram notifications are disabled.',
'warning_notifications_disabled_jabber' => 'Jabber notifications are disabled.',
@ -278,8 +268,7 @@ $sm_lang = array(
'error_server_ip_bad_website' => 'The website URL is not valid.',
'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_ssl_cert_expiry_days' => 'The remaining days for SSL certificate validity must be a valid
integer greater than or equal to 0.',
'error_server_ssl_cert_expiry_days' => 'The remaining days for SSL certificate validity must be a valid integer greater than or equal to 0.',
),
'config' => array(
'general' => 'General',
@ -287,8 +276,7 @@ $sm_lang = array(
'language' => 'Language',
'show_update' => 'Check for updates?',
'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!',
'proxy' => 'Enable proxy',
'proxy_url' => 'Proxy URL',
'proxy_user' => 'Proxy username',
@ -309,27 +297,18 @@ $sm_lang = array(
'sms_gateway_username' => 'Gateway username',
'sms_gateway_password' => 'Gateway password',
'sms_from' => 'Sender\'s phone number',
'discord_status' => 'Allow sending Discord messages',
'pushover_status' => 'Allow sending Pushover messages',
'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See <a
href="https://pushover.net/" target="_blank">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/" target="_blank">their website</a> for more info.',
'pushover_clone_app' => 'Click here to create your Pushover app',
'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.',
'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_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_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.',
'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.',
'jabber_status' => 'Allow sending Jabber (XMPP) messages',
'jabber_description' => 'Visit the <a
href="http://docs.phpservermonitor.org/">documentation</a> for more info and an
install guide.',
'jabber_description' => 'Visit the <a href="http://docs.phpservermonitor.org/">documentation</a> for more info and an install guide.',
'jabber_host' => 'Host',
'jabber_host_description' => 'Host of your Jabber account provider. For Google Account use talk.google.com.',
'jabber_port' => 'Port',
@ -342,37 +321,32 @@ $sm_lang = array(
'jabber_password_description' => 'Fill only to set or change.',
'jabber_check' => 'Check your Jabber account if message was received.',
'alert_type' => 'Select when you\'d like to be notified.',
'alert_type_description' => '<b>Status change:</b> You will receive a notification when a server has a change
in status. So from online -> offline or offline -> online.<br><br><b>Offline:</b>
You will receive a notification when a server goes offline for the *FIRST TIME
ONLY*. For example, your cronjob is every 15 minutes and your server goes down at
1 am and stays down till 6 am. You will get 1 notification at 1 am and that\'s
it.<br><br><b>Always:</b> You will receive a notification every time the script
runs and a site is down, even if the site has been offline for hours.',
'alert_type_description' => '<b>Status change:</b> You will receive a notification when a server has a change in status. So from online -> offline or offline -> online.<br><br><b>Offline:</b> You will receive a notification when a server goes offline for the *FIRST TIME ONLY*. For example, your cronjob is every 15 minutes and your server goes down at 1 am and stays down till 6 am. You will get 1 notification at 1 am and that\'s it.<br><br><b>Always:</b> You will receive a notification every time the script runs and a site is down, even if the site has been offline for hours.',
'alert_type_status' => 'Status change',
'alert_type_offline' => 'Offline',
'alert_type_always' => 'Always',
'combine_notifications' => 'Combine notifications',
'combine_notifications_description' => 'Reduces the amount of notification by combining the notifications into
1 single notification. (This does not affect SMS notifications.)',
'combine_notifications_description' => 'Reduces the amount of notification by combining the notifications into 1 single notification. (This does not affect SMS notifications.)',
'alert_proxy' => 'Even if enabled, proxy is never used for services',
'alert_proxy_url' => 'Format: host:port',
'log_status' => 'Log status',
'log_status_description' => 'If log status is set to TRUE, the monitor will log the event whenever the
notification settings are passed.',
'log_status_description' => 'If log status is set to TRUE, the monitor will log the event whenever the notification settings are passed.',
'log_email' => 'Log emails sent by the script',
'log_sms' => 'Log text messages sent by the script',
'log_discord' => 'Log Discord messages sent by the script',
'log_pushover' => 'Log pushover messages sent by the script',
'log_telegram' => 'Log Telegram messages sent by the script',
'log_jabber' => 'Log Jabber messages sent by the script',
'updated' => 'The configuration has been updated.',
'tab_email' => 'Email',
'tab_sms' => 'SMS',
'tab_discord' => 'Discord',
'tab_pushover' => 'Pushover',
'tab_telegram' => 'Telegram',
'tab_jabber' => 'Jabber',
'settings_email' => 'Email settings',
'settings_sms' => 'Text message settings',
'settings_discord' => 'Discord settings',
'settings_pushover' => 'Pushover settings',
'settings_telegram' => 'Telegram settings',
'settings_jabber' => 'Jabber settings',
@ -380,13 +354,12 @@ $sm_lang = array(
'settings_log' => 'Log settings',
'settings_proxy' => 'Proxy settings',
'auto_refresh' => 'Auto-refresh',
'auto_refresh_description' => 'Auto-refresh servers page.<br><span class="small">Time in seconds, if 0 the
page won\'t refresh.</span>',
'auto_refresh_description' => 'Auto-refresh servers page.<br><span class="small">Time in seconds, if 0 the page won\'t refresh.</span>',
'test' => 'Test',
'test_email' => 'An email will be sent to the address specified in your user profile.',
'test_sms' => 'An SMS will be sent to the phone number specified in your user profile.',
'test_pushover' => 'A Pushover notification will be sent to the user key/device specified in your user
profile.',
'test_discord' => 'A Discord notification will be sent to the webhook specified in your user profile.',
'test_pushover' => 'A Pushover notification will be sent to the user key/device specified in your user profile.',
'test_telegram' => 'A Telegram notification will be sent to the chat id specified in your user profile.',
'test_jabber' => 'A Jabber notification will be sent to the jabber account specified in your user profile.',
'send' => 'Send',
@ -397,24 +370,23 @@ $sm_lang = array(
'sms_sent' => 'SMS sent',
'sms_error' => 'An error has occurred while sending the SMS: %s',
'sms_error_nomobile' => 'Unable to send test SMS: no valid phone number found in your profile.',
'discord_sent' => 'Discord notification sent',
'discord_error' => 'An error has occurred while sending the Discord notification: %s',
'discord_error_nowebhook' => 'Unable to send test Discord notification: no valid Discord webhook found in your user profile.',
'pushover_sent' => 'Pushover notification sent',
'pushover_error' => 'An error has occurred while sending the Pushover notification: %s',
'pushover_error_noapp' => 'Unable to send test notification: no Pushover App API token found in the global
configuration.',
'pushover_error_noapp' => 'Unable to send test notification: no Pushover App API token found in the global configuration.',
'pushover_error_nokey' => 'Unable to send test notification: no Pushover key found in your profile.',
'telegram_sent' => 'Telegram notification sent',
'telegram_error' => 'An error has occurred while sending the Telegram notification: %s',
'telegram_error_notoken' => 'Unable to send test notification: no Telegram API token found in the global
configuration.',
'telegram_error_notoken' => 'Unable to send test notification: no Telegram API token found in the global configuration.',
'telegram_error_noid' => 'Unable to send test notification: no chat id found in your profile.',
'jabber_sent' => 'Telegram notification sent',
'jabber_error' => 'An error has occurred while sending the Telegram notification: %s',
'jabber_error_noconfig' => 'Unable to send test notification: no Jabber account set in the global
configuration.',
'jabber_error_noconfig' => 'Unable to send test notification: no Jabber account set in the global configuration.',
'jabber_error_noaccount' => 'Unable to send test notification: no Jabber account found in your profile.',
'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',
'user_agent' => 'User Agent',
'user_agent_key_note' => 'Custom user agent used by monitor within communication with external services.',
@ -422,57 +394,37 @@ $sm_lang = array(
'notifications' => array(
'off_sms' => 'Server \'%LABEL%\' is DOWN: ip=%IP%, port=%PORT%. Error=%ERROR%',
'off_email_subject' => 'IMPORTANT: Server \'%LABEL%\' is DOWN',
'off_email_body' => 'Failed to connect to the following server:<br><br>Server: %LABEL%<br>IP: %IP%<br>Port:
%PORT%<br>Error: %ERROR%<br>Date: %DATE%',
'off_email_body' => 'Failed to connect to the following server:<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Error: %ERROR%<br>Date: %DATE%',
'off_discord_message' => 'Failed to connect to the following server:<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Error: %ERROR%<br>Date: %DATE%',
'off_pushover_title' => 'Server \'%LABEL%\' is DOWN',
'off_pushover_message' => 'Failed to connect to the following server:<br><br>Server: %LABEL%<br>IP:
%IP%<br>Port: %PORT%<br>Error: %ERROR%<br>Date: %DATE%',
'off_telegram_message' => 'Failed to connect to the following server:<br><br>Server: %LABEL%<br>IP:
%IP%<br>Port: %PORT%<br>Error: %ERROR%<br>Date: %DATE%',
'off_jabber_message' => 'Failed to connect to the following server:<br><br>Server: %LABEL%<br>IP:
%IP%<br>Port: %PORT%<br>Error: %ERROR%<br>Date: %DATE%',
'off_pushover_message' => 'Failed to connect to the following server:<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Error: %ERROR%<br>Date: %DATE%',
'off_telegram_message' => 'Failed to connect to the following server:<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Error: %ERROR%<br>Date: %DATE%',
'off_jabber_message' => 'Failed to connect to the following server:<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Error: %ERROR%<br>Date: %DATE%',
'on_sms' => 'Server \'%LABEL%\' is RUNNING: ip=%IP%, port=%PORT%, it was down for %LAST_OFFLINE_DURATION%',
'on_email_subject' => 'IMPORTANT: Server \'%LABEL%\' is RUNNING',
'on_email_body' => 'Server \'%LABEL%\' is running again, it was down for
%LAST_OFFLINE_DURATION%:<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Date:
%DATE%',
'on_email_body' => 'Server \'%LABEL%\' is running again, it was down for %LAST_OFFLINE_DURATION%:<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Date: %DATE%',
'on_discord_message' => 'Server \'%LABEL%\' is running again, it was down for: %LAST_OFFLINE_DURATION%<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Date: %DATE%',
'on_pushover_title' => 'Server \'%LABEL%\' is RUNNING',
'on_pushover_message' => 'Server \'%LABEL%\' is running again, it was down for
%LAST_OFFLINE_DURATION%:<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Date:
%DATE%',
'on_telegram_message' => 'Server \'%LABEL%\' is running again, it was down for:
%LAST_OFFLINE_DURATION%<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Date:
%DATE%',
'on_jabber_message' => 'Server \'%LABEL%\' is running again, it was down for:
%LAST_OFFLINE_DURATION%<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Date:
%DATE%',
'combi_off_email_message' => '<ul><li>Server: %LABEL%</li><li>IP: %IP%</li><li>Port: %PORT%</li><li>Error:
%ERROR%</li><li>Date: %DATE%</li></ul>',
'combi_off_pushover_message' => '<ul><li>Server: %LABEL%</li><li>IP: %IP%</li><li>Port: %PORT%</li><li>Error:
%ERROR%</li><li>Date: %DATE%</li></ul>',
'combi_off_telegram_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Error: %ERROR%<br>-
Date: %DATE%<br><br>',
'combi_off_jabber_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Error: %ERROR%<br>-
Date: %DATE%<br><br>',
'combi_on_email_message' => '<ul><li>Server: %LABEL%</li><li>IP: %IP%</li><li>Port: %PORT%</li><li>Downtime:
%LAST_OFFLINE_DURATION%</li><li>Date: %DATE%</li></ul>',
'combi_on_pushover_message' => '<ul><li>Server: %LABEL%</li><li>IP: %IP%</li><li>Port:
%PORT%</li><li>Downtime: %LAST_OFFLINE_DURATION%</li><li>Date:
%DATE%</li></ul>',
'combi_on_telegram_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Downtime:
%LAST_OFFLINE_DURATION%<br>- Date: %DATE%<br><br>',
'combi_on_jabber_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Downtime:
%LAST_OFFLINE_DURATION%<br>- Date: %DATE%<br><br>',
'on_pushover_message' => 'Server \'%LABEL%\' is running again, it was down for %LAST_OFFLINE_DURATION%:<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Date: %DATE%',
'on_telegram_message' => 'Server \'%LABEL%\' is running again, it was down for: %LAST_OFFLINE_DURATION%<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Date: %DATE%',
'on_jabber_message' => 'Server \'%LABEL%\' is running again, it was down for: %LAST_OFFLINE_DURATION%<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Date: %DATE%',
'combi_off_email_message' => '<ul><li>Server: %LABEL%</li><li>IP: %IP%</li><li>Port: %PORT%</li><li>Error: %ERROR%</li><li>Date: %DATE%</li></ul>',
'combi_off_discord_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Error: %ERROR%<br>- Date: %DATE%<br><br>',
'combi_off_pushover_message' => '<ul><li>Server: %LABEL%</li><li>IP: %IP%</li><li>Port: %PORT%</li><li>Error: %ERROR%</li><li>Date: %DATE%</li></ul>',
'combi_off_telegram_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Error: %ERROR%<br>- Date: %DATE%<br><br>',
'combi_off_jabber_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Error: %ERROR%<br>- Date: %DATE%<br><br>',
'combi_on_email_message' => '<ul><li>Server: %LABEL%</li><li>IP: %IP%</li><li>Port: %PORT%</li><li>Downtime: %LAST_OFFLINE_DURATION%</li><li>Date: %DATE%</li></ul>',
'combi_on_discord_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Downtime: %LAST_OFFLINE_DURATION%<br>- Date: %DATE%<br><br>',
'combi_on_pushover_message' => '<ul><li>Server: %LABEL%</li><li>IP: %IP%</li><li>Port: %PORT%</li><li>Downtime: %LAST_OFFLINE_DURATION%</li><li>Date: %DATE%</li></ul>',
'combi_on_telegram_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Downtime: %LAST_OFFLINE_DURATION%<br>- Date: %DATE%<br><br>',
'combi_on_jabber_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Downtime: %LAST_OFFLINE_DURATION%<br>- Date: %DATE%<br><br>',
'combi_email_subject' => 'IMPORTANT: \'%UP%\' servers UP again, \'%DOWN%\' servers DOWN',
'combi_pushover_subject' => '\'%UP%\' servers UP again, \'%DOWN%\' servers DOWN',
'combi_email_message' => '<b>The following servers went down:</b><br>%DOWN_SERVERS%<br><b>The following
servers are up again:</b><br>%UP_SERVERS%',
'combi_pushover_message' => '<b>The following servers went down:</b><br>%DOWN_SERVERS%<br><b>The following
servers are up again:</b><br>%UP_SERVERS%',
'combi_telegram_message' => '<b>The following servers went down:</b><br>%DOWN_SERVERS%<br><b>The following
servers are up again:</b><br>%UP_SERVERS%',
'combi_jabber_message' => '<b>The following servers went down:</b><br>%DOWN_SERVERS%<br><b>The following
servers are up again:</b><br>%UP_SERVERS%',
'combi_email_message' => '<b>The following servers went down:</b><br>%DOWN_SERVERS%<br><b>The following servers are up again:</b><br>%UP_SERVERS%',
'combi_discord_message' => '<b>The following servers went down:</b><br>%DOWN_SERVERS%<br><b>The following servers are up again:</b><br>%UP_SERVERS%',
'combi_pushover_message' => '<b>The following servers went down:</b><br>%DOWN_SERVERS%<br><b>The following servers are up again:</b><br>%UP_SERVERS%',
'combi_telegram_message' => '<b>The following servers went down:</b><br>%DOWN_SERVERS%<br><b>The following servers are up again:</b><br>%UP_SERVERS%',
'combi_jabber_message' => '<b>The following servers went down:</b><br>%DOWN_SERVERS%<br><b>The following servers are up again:</b><br>%UP_SERVERS%',
),
'login' => array(
'welcome_usermenu' => 'Welcome, %user_name%',
@ -489,8 +441,7 @@ $sm_lang = array(
'password_forgot' => 'Forgot password?',
'password_reset' => 'Reset password',
'password_reset_email_subject' => 'Reset your password for PHP Server Monitor',
'password_reset_email_body' => 'Please use the following link to reset your password. Please note it expires
in 1 hour.<br><br>%link%',
'password_reset_email_body' => 'Please use the following link to reset your password. Please note it expires in 1 hour.<br><br>%link%',
'error_user_incorrect' => 'The provided username could not be found.',
'error_login_incorrect' => 'The information is incorrect.',
'error_login_passwords_nomatch' => 'The provided passwords do not match.',

View File

@ -43,12 +43,14 @@ class ConfigController extends AbstractController
'email_status',
'email_smtp',
'sms_status',
'discord_status',
'pushover_status',
'telegram_status',
'jabber_status',
'log_status',
'log_email',
'log_sms',
'log_discord',
'log_pushover',
'log_telegram',
'log_jabber',
@ -208,7 +210,7 @@ class ConfigController extends AbstractController
$tpl_data[$this->default_tab . '_active'] = 'active';
$testmodals = array('email', 'sms', 'pushover', 'telegram', 'jabber');
$testmodals = array('email', 'sms', 'discord', 'pushover', 'telegram', 'jabber');
foreach ($testmodals as $modal_id) {
$modal = new \psm\Util\Module\Modal(
$this->twig,
@ -270,6 +272,8 @@ class ConfigController extends AbstractController
$this->testEmail();
} elseif (!empty($_POST['test_sms'])) {
$this->testSMS();
} elseif (!empty($_POST['test_discord'])) {
$this->testDiscord();
} elseif (!empty($_POST['test_pushover'])) {
$this->testPushover();
} elseif (!empty($_POST['test_telegram'])) {
@ -289,6 +293,8 @@ class ConfigController extends AbstractController
$this->default_tab = 'email';
} elseif (isset($_POST['sms_submit']) || !empty($_POST['test_sms'])) {
$this->default_tab = 'sms';
} elseif (isset($_POST['discord_submit']) || !empty($_POST['test_discord'])) {
$this->default_tab = 'discord';
} elseif (isset($_POST['pushover_submit']) || !empty($_POST['test_pushover'])) {
$this->default_tab = 'pushover';
} elseif (isset($_POST['telegram_submit']) || !empty($_POST['test_telegram'])) {
@ -346,6 +352,60 @@ class ConfigController extends AbstractController
}
}
/**
* Execute SMS test
*
* @todo move test to separate class
*/
protected function testDiscord()
{
$user = $this->getUser()->getUser();
if (empty($user->discord)) {
$this->addMessage(psm_get_lang('config', 'discord_error_nowebhook'), 'error');
} else {
$success = 0;
$result = 'An unknown error has occurred.';
try {
$curl = curl_init($user->discord);
$json = json_decode(
'{"content":""}',
true
);
$json['content'] = psm_get_lang('config', 'test_message');
$msg = "payload_json=" . urlencode(json_encode($json));
if(isset($curl)) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_POSTFIELDS, $msg);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$err = curl_errno($curl);
if ($err != 0 || $httpcode != 204) {
$success = 0;
// $result = ($result == '') ? 'Wrong input, please check if all values are correct!' : $result;
$error = "HTTP_code: " . $httpcode . ".\ncURL error (" . $err . "): " .
curl_strerror($err) . ". \nResult: " . $result;
$result = $error;
} else {
$success = 1;
}
curl_close($curl);
}
} catch (Exception $e) {
$success = 0;
$result = $e->getMessage();
}
if ($success === 1) {
$this->addMessage(psm_get_lang('config', 'discord_sent'), 'success');
} else {
$this->addMessage(sprintf(psm_get_lang('config', 'discord_error'), $result), 'error');
}
}
}
/**
* Execute pushover test
*
@ -444,11 +504,13 @@ class ConfigController extends AbstractController
return array(
'label_tab_email' => psm_get_lang('config', 'tab_email'),
'label_tab_sms' => psm_get_lang('config', 'tab_sms'),
'label_tab_discord' => psm_get_lang('config', 'tab_discord'),
'label_tab_pushover' => psm_get_lang('config', 'tab_pushover'),
'label_tab_telegram' => psm_get_lang('config', 'tab_telegram'),
'label_tab_jabber' => psm_get_lang('config', 'tab_jabber'),
'label_settings_email' => psm_get_lang('config', 'settings_email'),
'label_settings_sms' => psm_get_lang('config', 'settings_sms'),
'label_settings_discord' => psm_get_lang('config', 'settings_discord'),
'label_settings_pushover' => psm_get_lang('config', 'settings_pushover'),
'label_settings_telegram' => psm_get_lang('config', 'settings_telegram'),
'label_settings_jabber' => psm_get_lang('config', 'settings_jabber'),
@ -479,6 +541,8 @@ class ConfigController extends AbstractController
'label_sms_gateway_username' => psm_get_lang('config', 'sms_gateway_username'),
'label_sms_gateway_password' => psm_get_lang('config', 'sms_gateway_password'),
'label_sms_from' => psm_get_lang('config', 'sms_from'),
'label_discord_status' => psm_get_lang('config', 'discord_status'),
'label_discord_description' => psm_get_lang('config', 'discord_description'),
'label_pushover_description' => psm_get_lang('config', 'pushover_description'),
'label_pushover_status' => psm_get_lang('config', 'pushover_status'),
'label_pushover_clone_app' => psm_get_lang('config', 'pushover_clone_app'),
@ -512,6 +576,7 @@ class ConfigController extends AbstractController
'label_log_status_description' => psm_get_lang('config', 'log_status_description'),
'label_log_email' => psm_get_lang('config', 'log_email'),
'label_log_sms' => psm_get_lang('config', 'log_sms'),
'label_log_discord' => psm_get_lang('config', 'log_discord'),
'label_log_pushover' => psm_get_lang('config', 'log_pushover'),
'label_log_telegram' => psm_get_lang('config', 'log_telegram'),
'label_log_jabber' => psm_get_lang('config', 'log_jabber'),

View File

@ -81,6 +81,7 @@ abstract class AbstractServerController extends AbstractController
`s`.`active`,
`s`.`email`,
`s`.`sms`,
`s`.`discord`,
`s`.`pushover`,
`s`.`telegram`,
`s`.`jabber`,

View File

@ -55,6 +55,7 @@ class LogController extends AbstractServerController
'label_status' => psm_get_lang('log', 'status'),
'label_email' => psm_get_lang('log', 'email'),
'label_sms' => psm_get_lang('log', 'sms'),
'label_discord' => psm_get_lang('log', 'discord'),
'label_pushover' => psm_get_lang('log', 'pushover'),
'label_telegram' => psm_get_lang('log', 'telegram'),
'label_jabber' => psm_get_lang('log', 'jabber'),
@ -77,7 +78,7 @@ class LogController extends AbstractServerController
$modal->setTitle(psm_get_lang('log', 'delete_title'));
$modal->setMessage(psm_get_lang('log', 'delete_message'));
$modal->setOKButtonLabel(psm_get_lang('system', 'delete'));
$sidebar->addButton(
'clear_logn',
psm_get_lang('log', 'clear'),
@ -89,7 +90,7 @@ class LogController extends AbstractServerController
);
}
$log_types = array('status', 'email', 'sms', 'pushover', 'telegram', 'jabber');
$log_types = array('status', 'email', 'sms', 'discord', 'pushover', 'telegram', 'jabber');
foreach ($log_types as $key) {
$records = $this->getEntries($key);

View File

@ -100,6 +100,7 @@ class ServerController extends AbstractServerController
$icons = array(
'email' => 'icon-envelope',
'sms' => 'icon-mobile',
'discord' => 'icon-discord',
'pushover' => 'icon-pushover',
'telegram' => 'icon-telegram',
'jabber' => 'icon-jabber'
@ -130,6 +131,7 @@ class ServerController extends AbstractServerController
$tpl_data['config']['email'] = psm_get_conf('email_status');
$tpl_data['config']['sms'] = psm_get_conf('sms_status');
$tpl_data['config']['discord'] = psm_get_conf('discord_status');
$tpl_data['config']['pushover'] = psm_get_conf('pushover_status');
$tpl_data['config']['telegram'] = psm_get_conf('telegram_status');
@ -237,13 +239,14 @@ class ServerController extends AbstractServerController
'edit_active_selected' => $edit_server['active'],
'edit_email_selected' => $edit_server['email'],
'edit_sms_selected' => $edit_server['sms'],
'edit_discord_selected' => $edit_server['discord'],
'edit_pushover_selected' => $edit_server['pushover'],
'edit_telegram_selected' => $edit_server['telegram'],
'edit_jabber_selected' => $edit_server['jabber'],
));
}
$notifications = array('email', 'sms', 'pushover', 'telegram', 'jabber');
$notifications = array('email', 'sms', 'discord', 'pushover', 'telegram', 'jabber');
foreach ($notifications as $notification) {
if (psm_get_conf($notification . '_status') == 0) {
$tpl_data['warning_' . $notification] = true;
@ -271,7 +274,7 @@ class ServerController extends AbstractServerController
// We need the server id to encrypt the password. Encryption will be done after the server is added
$encrypted_password = '';
if (!empty($_POST['website_password'])) {
$new_password = psm_POST('website_password');
@ -311,6 +314,7 @@ class ServerController extends AbstractServerController
'active' => in_array($_POST['active'], array('yes', 'no')) ? $_POST['active'] : 'no',
'email' => in_array($_POST['email'], array('yes', 'no')) ? $_POST['email'] : 'no',
'sms' => in_array($_POST['sms'], array('yes', 'no')) ? $_POST['sms'] : 'no',
'discord' => in_array($_POST['discord'], array('yes', 'no')) ? $_POST['discord'] : 'no',
'pushover' => in_array($_POST['pushover'], array('yes', 'no')) ? $_POST['pushover'] : 'no',
'telegram' => in_array($_POST['telegram'], array('yes', 'no')) ? $_POST['telegram'] : 'no',
'jabber' => in_array($_POST['jabber'], array('yes', 'no')) ? $_POST['jabber'] : 'no',
@ -589,12 +593,14 @@ class ServerController extends AbstractServerController
'label_send_email' => psm_get_lang('servers', 'send_email'),
'label_sms' => psm_get_lang('servers', 'sms'),
'label_send_sms' => psm_get_lang('servers', 'send_sms'),
'label_discord' => psm_get_lang('servers', 'discord'),
'label_send_discord' => psm_get_lang('servers', 'send_discord'),
'label_pushover' => psm_get_lang('servers', 'pushover'),
'label_send_pushover' => psm_get_lang('servers', 'send_pushover'),
'label_telegram' => psm_get_lang('servers', 'telegram'),
'label_jabber' => psm_get_lang('servers', 'jabber'),
'label_pushover' => psm_get_lang('servers', 'pushover'),
'label_jabber' => psm_get_lang('servers', 'jabber'),
'label_send_jabber' => psm_get_lang('servers', 'send_jabber'),
'label_send_telegram' => psm_get_lang('servers', 'send_telegram'),
'label_send_jabber' => psm_get_lang('servers', 'send_jabber'),
'label_users' => psm_get_lang('servers', 'users'),
'label_warning_threshold' => psm_get_lang('servers', 'warning_threshold'),
'label_warning_threshold_description' => psm_get_lang('servers', 'warning_threshold_description'),

View File

@ -39,7 +39,7 @@ class ProfileController extends AbstractController
* @var array $profile_fields
*/
protected $profile_fields =
array('name', 'user_name', 'email', 'mobile', 'pushover_key', 'pushover_device', 'telegram_id', 'jabber');
array('name', 'user_name', 'email', 'mobile', 'discord', 'pushover_key', 'pushover_device', 'telegram_id', 'jabber');
public function __construct(Database $db, \Twig_Environment $twig)
{
@ -83,6 +83,10 @@ class ProfileController extends AbstractController
'label_pushover_key' => psm_get_lang('users', 'pushover_key'),
'label_pushover_device' => psm_get_lang('users', 'pushover_device'),
'label_pushover_device_description' => psm_get_lang('users', 'pushover_device_description'),
'label_discord' => psm_get_lang('users', 'discord'),
'label_discord_description' => psm_get_lang('users', 'discord_description'),
'label_telegram' => psm_get_lang('users', 'telegram'),
'label_telegram_description' => psm_get_lang('users', 'telegram_description'),
'label_telegram_chat_id' => psm_get_lang('users', 'telegram_chat_id'),

View File

@ -158,6 +158,7 @@ class UserController extends AbstractController
'name',
'user_name',
'mobile',
'discord',
'pushover_key',
'pushover_device',
'telegram_id',
@ -255,6 +256,7 @@ class UserController extends AbstractController
'password_repeat',
'level',
'mobile',
'discord',
'pushover_key',
'pushover_device',
'telegram_id',
@ -392,6 +394,8 @@ class UserController extends AbstractController
'label_level' => psm_get_lang('users', 'level'),
'label_level_description' => psm_get_lang('users', 'level_description'),
'label_mobile' => psm_get_lang('users', 'mobile'),
'label_discord' => psm_get_lang('users', 'discord'),
'label_discord_description' => psm_get_lang('users', 'discord_description'),
'label_pushover' => psm_get_lang('users', 'pushover'),
'label_pushover_description' => psm_get_lang('users', 'pushover_description'),
'label_pushover_key' => psm_get_lang('users', 'pushover_key'),

View File

@ -178,6 +178,8 @@ class Installer
('log_pushover', '1'),
('log_telegram', '1'),
('log_jabber', '1'),
('discord_status', '0'),
('log_jdiscord', '1'),
('log_retention_period', '365'),
('version', '" . PSM_VERSION . "'),
('version_update_check', '" . PSM_VERSION . "'),
@ -185,7 +187,7 @@ class Installer
('show_update', '1'),
('last_update_check', '0'),
('cron_running', '0'),
('cron_running_time', '0'),
('cron_running_time', '0'),
('cron_off_running', '0'),
('cron_off_running_time', '0');";
$this->execSQL($queries);
@ -212,6 +214,7 @@ class Installer
`level` tinyint(2) unsigned NOT NULL DEFAULT '20',
`name` varchar(255) NOT NULL,
`mobile` varchar(15) NOT NULL,
`discord` varchar(255) NOT NULL,
`pushover_key` varchar(255) NOT NULL,
`pushover_device` varchar(255) NOT NULL,
`telegram_id` varchar(255) NOT NULL,
@ -235,7 +238,7 @@ class Installer
PSM_DB_PREFIX . 'log' => "CREATE TABLE `" . PSM_DB_PREFIX . "log` (
`log_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`server_id` int(11) unsigned NOT NULL,
`type` enum('status','email','sms','pushover','telegram', 'jabber') NOT NULL,
`type` enum('status','email','sms','discord','pushover','telegram', 'jabber') NOT NULL,
`message` TEXT NOT NULL,
`datetime` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`log_id`)
@ -269,6 +272,7 @@ class Installer
`active` enum('yes','no') NOT NULL default 'yes',
`email` enum('yes','no') NOT NULL default 'yes',
`sms` enum('yes','no') NOT NULL default 'no',
`discord` enum('yes','no') NOT NULL default 'yes',
`pushover` enum('yes','no') NOT NULL default 'yes',
`telegram` enum('yes','no') NOT NULL default 'yes',
`jabber` enum('yes','no') NOT NULL default 'yes',
@ -697,9 +701,9 @@ class Installer
$this->log('SMTP password is now encrypted.');
}
$queries[] = 'ALTER TABLE `' . PSM_DB_PREFIX . 'users` ADD `jabber` VARCHAR( 255 )
$queries[] = 'ALTER TABLE `' . PSM_DB_PREFIX . 'users` ADD `jabber` VARCHAR( 255 )
NOT NULL AFTER `telegram_id`;';
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `jabber` ENUM( 'yes','no' )
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `jabber` ENUM( 'yes','no' )
NOT NULL DEFAULT 'yes' AFTER `telegram`;";
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX .
"log` CHANGE `type` `type` ENUM( 'status', 'email', 'sms', 'pushover', 'telegram', 'jabber' )
@ -715,4 +719,24 @@ class Installer
$this->execSQL($queries);
}
/**
* Patch for v3.5.1 release
* Added support for Discord webhooks
*/
protected function upgrade351()
{
$queries = array();
$queries[] = 'ALTER TABLE `' . PSM_DB_PREFIX . 'users` ADD `discord` VARCHAR( 255 )
NOT NULL AFTER `mobile`;';
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `discord` ENUM( 'yes','no' )
NOT NULL DEFAULT 'yes' AFTER `sms`;";
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX .
"log` CHANGE `type` `type` ENUM( 'status', 'email', 'sms', 'discord', 'pushover', 'telegram', 'jabber' )
CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE
('discord_status', '0'),
('log_discord', '1');";
$this->execSQL($queries);
}
}

View File

@ -57,6 +57,12 @@ class StatusNotifier
*/
protected $send_sms = false;
/**
* Send Discord notification?
* @var boolean $send_discord
*/
protected $send_discord = false;
/**
* Send Pushover notification?
* @var boolean $send_pushover
@ -128,6 +134,7 @@ class StatusNotifier
$this->send_emails = (bool)psm_get_conf('email_status');
$this->send_sms = (bool)psm_get_conf('sms_status');
$this->send_discord = (bool)psm_get_conf('discord_status');
$this->send_pushover = (bool)psm_get_conf('pushover_status');
$this->send_telegram = (bool)psm_get_conf('telegram_status');
$this->send_jabber = (bool)psm_get_conf('jabber_status');
@ -149,6 +156,7 @@ class StatusNotifier
if (
!$this->send_emails &&
!$this->send_sms &&
!$this->send_discord &&
!$this->send_pushover &&
!$this->send_telegram &&
!$this->send_jabber &&
@ -175,6 +183,7 @@ class StatusNotifier
'error',
'email',
'sms',
'discord',
'pushover',
'telegram',
'jabber',
@ -246,6 +255,12 @@ class StatusNotifier
$this->notifyByTxtMsg($users);
}
// check if discord is enabled for this server
if ($this->send_discord && $this->server['discord'] == 'yes') {
// yay lets wake those nerds up!
$this->combine ? $this->setCombi('discord') : $this->notifyByDiscord($users);
}
// check if pushover is enabled for this server
if ($this->send_pushover && $this->server['pushover'] == 'yes') {
// yay lets wake those nerds up!
@ -417,6 +432,86 @@ class StatusNotifier
}
}
/**
* This functions performs the discord notifications
*
* @param \PDOStatement $users
* @param array $combi contains message and subject (optional)
* @return void
*/
protected function notifyByDiscord($users, $combi = array())
{
$message_log = key_exists('message', $combi) ?
$combi['message'] :
psm_parse_msg($this->status_new, 'discord_message', $this->server);
// Remove users that have no Discord webhook
foreach ($users as $k => $user) {
if (trim($user['discord']) == '') {
unset($users[$k]);
}
}
// Validation
if (empty($users)) {
return;
}
// fix message for Discord viewing
$message = str_replace(array('<b>', '</b>'), array('**', '**'), $message_log);
$message = str_replace(array('<ul>', '</ul>'), array('', ''), $message);
$message = str_replace(array('<br>', '</li>'), array("\n", "\n"), $message);
$message = str_replace('<li>', " * ", $message);
$json = json_decode(
'{"content":""}',
true
);
$json['content'] = $message;
// Log
if (psm_get_conf('log_discord')) {
$log_id = psm_add_log($this->server_id, 'discord', $message_log);
}
foreach ($users as $user) {
// Log
if (!empty($log_id)) {
psm_add_log_user($log_id, $user['user_id']);
}
// set discord webhook and send
try {
$msg = "payload_json=" . urlencode(json_encode($json));
$curl = curl_init(trim($user['discord']));
if(isset($curl)) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_POSTFIELDS, $msg);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$err = curl_errno($curl);
if ($err != 0 || $httpcode != 204) {
// $result = ($result == '') ? 'Wrong input, please check if all values are correct!' : $result;
$error = "HTTP_code: " . $httpcode . ".\ncURL error (" . $err . "): " .
curl_strerror($err) . ". \nResult: " . $result;
$log_id = psm_add_log($this->server_id, 'discord', $error);
}
curl_close($curl);
}
} catch (Exception $e) {
$log_id = psm_add_log($this->server_id, 'discord', $e->getMessage());
}
}
}
/**
* This functions performs the pushover notifications
*
@ -619,8 +714,8 @@ class StatusNotifier
{
// find all the users with this server listed
$users = $this->db->query('
SELECT `u`.`user_id`, `u`.`name`,`u`.`email`, `u`.`mobile`, `u`.`pushover_key`,
`u`.`pushover_device`, `u`.`telegram_id`,
SELECT `u`.`user_id`, `u`.`name`,`u`.`email`, `u`.`mobile`, `u`.`discord`, `u`.`pushover_key`,
`u`.`pushover_device`, `u`.`telegram_id`,
`u`.`jabber`
FROM `' . PSM_DB_PREFIX . 'users` AS `u`
JOIN `' . PSM_DB_PREFIX . "users_servers` AS `us` ON (

View File

@ -17,6 +17,11 @@
aria-controls="config-sms" aria-selected="{% if sms_active %}true{% else %}false{% endif %}">{{
label_tab_sms }}</a>
</li>
<li class="nav-item">
<a class="nav-link {{ discord_active }}" id="config-discord-tab" data-toggle="tab" href="#config-discord"
role="tab" aria-controls="config-discord" aria-selected="{% if discord_active %}true{% else %}false{% endif %}">{{
label_tab_discord }}</a>
</li>
<li class="nav-item">
<a class="nav-link {{ pushover_active }}" id="config-pushover-tab" data-toggle="tab" href="#config-pushover"
role="tab" aria-controls="config-pushover" aria-selected="{% if pushover_active %}true{% else %}false{% endif %}">{{
@ -129,12 +134,24 @@
{{ macro.input_field("text", "sms_gateway_password", null, "sms_gateway_password", label_sms_gateway_password, sms_gateway_password, label_sms_gateway_password, "255") }}
<!-- sms sender number-->
{{ macro.input_field("text", "sms_from", null, "sms_from", label_sms_from, sms_from, "+31123456789", "255") }}
{{ macro.button_test("testSms", label_test) }}
{{ macro.input_hidden("test_sms", "0") }}
{{ macro.button_save("sms_submit", label_save) }}
</fieldset>
</div>
<div class="tab-pane {{ discord_active }}" id="config-discord" role="tabpanel" aria-labelledby="config-discord-tab">
<fieldset>
<legend>{{ label_settings_discord }}</legend>
<!-- enable discord -->
{{ macro.input_checkbox("discord_status", "discord_status[]", label_discord_status, discord_status_checked) }}
<!-- enable discord log -->
{{ macro.input_checkbox("log_discord", "log_discord[]", label_log_discord, log_discord_checked) }}
{{ macro.button_test("testDiscord", label_test) }}
{{ macro.input_hidden("test_discord", "0") }}
{{ macro.button_save("discord_submit", label_save) }}
</fieldset>
</div>
<div class="tab-pane {{ pushover_active }}" id="config-pushover" role="tabpanel" aria-labelledby="config-pushover-tab">
<fieldset>
<legend>{{ label_settings_pushover }}</legend>

View File

@ -56,6 +56,9 @@
{% if server.sms|lower == 'yes' and config.sms|lower%}
<i class="fas fa-sms" title="{{ label_sms }}"></i>
{% endif %}
{% if server.discord|lower == 'yes' and config.discord|lower%}
<i class="fas fa-comments" title="{{ label_discord }}"></i>
{% endif %}
{% if server.pushover|lower == 'yes'and config.pushover|lower %}
<span class="fa-layers">
<i class="fas fa-circle" title="{{ label_pushover }}"></i>

View File

@ -138,6 +138,8 @@
{{ macro.input_select_monitoring("email", "email", label_send_email, edit_email_selected, label_yes, label_no, warning_email, label_warning_email) }}
<!-- SMS -->
{{ macro.input_select_monitoring("sms", "sms", label_send_sms, edit_sms_selected, label_yes, label_no, warning_sms, label_warning_sms) }}
<!-- Discord -->
{{ macro.input_select_monitoring("discord", "discord", label_send_discord, edit_discord_selected, label_yes, label_no, warning_discord, label_warning_discord) }}
<!-- Pushover -->
{{ macro.input_select_monitoring("pushover", "pushover", label_send_pushover, edit_pushover_selected, label_yes, label_no, warning_pushover, label_warning_pushover) }}
<!-- Telegram -->

View File

@ -309,6 +309,19 @@
<noscript>&#8263</noscript>
{% endif %}
</li>
<li class="list-group-item">
{{ label_discord }}:
{% if discord|lower == 'yes' %}
<i class="fas fa-bell float-right"></i>
<noscript>&#10003</noscript>
{% elseif discord|lower == 'no' %}
<i class="fas fa-bell-slash float-right"></i>
<noscript>&#10005</noscript>
{% else %}
<i class="fas fa-question-circle float-right" title="Value from database should either be yes or no."></i>
<noscript>&#8263</noscript>
{% endif %}
</li>
<li class="list-group-item">
{{ label_pushover }}:
{% if pushover|lower == 'yes' %}

View File

@ -28,13 +28,19 @@
<!-- pushover device -->
{{ macro.input_field("text", "pushover_device", null, "pushover_device", label_pushover_device, pushover_device, label_pushover_device, "255", "pushover_device_help", pushover_device_description) }}
</fieldset>
<!-- Discord settings -->
<fieldset>
<legend>{{ label_discord }}</legend>
<p>{{ label_discord_description|raw }}</p>
{{ macro.input_field("text", "discord", null, "discord", label_discord, discord, label_discord, "255", "discord_help", discord_description) }}
</fieldset>
<!-- Telegram settings -->
<fieldset>
<legend>{{ label_telegram }}</legend>
<p>{{ label_telegram_description|raw }}</p>
<!-- telegram id -->
<div class="form-group">
<a class="btn btn-primary mb-2" href="{{ telegram_get_chat_id_url }}">{{ label_telegram_get_chat_id }}</a>
<a class="btn btn-primary mb-2" href="{{ telegram_get_chat_id_url }}">{{ label_telegram_get_chat_id }}</a>
</div>
{{ macro.input_field("text", "telegram_id", null, "telegram_id", label_telegram_chat_id, telegram_id, label_telegram_chat_id, "255", "telegram_id_help", telegram_id_description) }}
<button class="btn btn-primary show-modal" data-toggle="modal" data-modal-id="activateTelegram">{{ label_activate_telegram }}</button>
@ -47,4 +53,4 @@
{{ macro.input_field("text", "jabber", null, "jabber", label_jabber, jabber, label_jabber, "255", "jabber_help", jabber_description) }}
</fieldset>
{{ macro.button_save(null, label_save) }}
</form>
</form>

View File

@ -17,6 +17,8 @@
{{ macro.input_field("email", "email", null, "email", label_email, edit_value_email, null, "255") }}
<!-- Mobile -->
{{ macro.input_field("tel", "mobile", null, "mobile", label_mobile, edit_value_mobile, null, "20") }}
<!-- Discord -->
{{ macro.input_field("text", "discord", null, "discord", label_discord, edit_value_discord, null, "255") }}
<!-- Pushover_key -->
{{ macro.input_field("text", "pushover_key", null, "pushover_key", label_pushover_key, edit_value_pushover_key, null, "255") }}
<!-- Pushover_device -->