This commit is contained in:
TimZ99 2020-02-09 20:55:34 +01:00
parent cad814ae0f
commit f2d14bfd1f
No known key found for this signature in database
GPG Key ID: 4D8268DC68E8339D
4 changed files with 82 additions and 83 deletions

View File

@ -34,7 +34,7 @@ namespace {
# #
############################################### ###############################################
/** /**
* Retrieve language settings from the selected language file * Retrieve language settings from the selected language file
* Return false if arg is not found * Return false if arg is not found
* *
@ -641,57 +641,56 @@ namespace {
return $telegram; return $telegram;
} }
/** /**
* Send message via XMPP. * Send message via XMPP.
* *
* @param string $host * @param string $host
* @param string $username * @param string $username
* @param string $password * @param string $password
* @param string $receiver * @param string $receiver
* @param string $message * @param string $message
* @param int|null $port * @param int|null $port
* @param string|null $domain * @param string|null $domain
*/ */
function psm_jabber_send_message($host, $username, $password, $receiver, $message, $port = null, $domain = null) function psm_jabber_send_message($host, $username, $password, $receiver, $message, $port = null, $domain = null)
{ {
$options = [ $options = [
'jid' => $username, // incl. gmail.com 'jid' => $username, // incl. gmail.com
'pass' => $password, 'pass' => $password,
'domain' => $domain, // gmail.com or null 'domain' => $domain, // gmail.com or null
'host' => $host, // talk.google.com 'host' => $host, // talk.google.com
'port' => $port, // talk.google.com needs to have 5223 ... 5222 - CN problem - gmail.com vs talk.google.com 'port' => $port, // talk.google.com needs to have 5223 ... 5222 - CN problem - gmail.com vs talk.google.com
'log_path' => __DIR__ . '/../../logs/jaxl.log', // own log 'log_path' => __DIR__ . '/../../logs/jaxl.log', // own log
// force tls // force tls
'force_tls' => PSM_JABBER_FORCE_TLS, 'force_tls' => PSM_JABBER_FORCE_TLS,
// (required) perform X-OAUTH2 // (required) perform X-OAUTH2
'auth_type' => PSM_JABBER_AUTH_TYPE, //'X-OAUTH2', // auth failure with this option :( so just PLAIN ... 'auth_type' => PSM_JABBER_AUTH_TYPE, //'X-OAUTH2', // auth failure with this option :( so just PLAIN ...
'log_level' => PSM_JABBER_DEBUG_LEVEL 'log_level' => PSM_JABBER_DEBUG_LEVEL
]; ];
try { try {
$client = new JAXL($options); $client = new JAXL($options);
// Add Callbacks // Add Callbacks
$client->add_cb('on_auth_success', function () use ($client, $receiver, $message) { $client->add_cb('on_auth_success', function () use ($client, $receiver, $message) {
JAXLLogger::info('got on_auth_success cb'); JAXLLogger::info('got on_auth_success cb');
$client->send_chat_msg($receiver, $message); $client->send_chat_msg($receiver, $message);
$client->send_end_stream(); $client->send_end_stream();
});
$client->add_cb('on_auth_failure', function ($reason) use ($client) {
$client->send_end_stream();
JAXLLogger::info('got on_auth_failure cb with reason: ' . $reason);
});
$client->add_cb('on_disconnect', function () use ($client) {
JAXLLogger::info('got on_disconnect cb');
});
}); $client->start();
$client->add_cb('on_auth_failure', function ($reason) use ($client) { } catch (Exception $ex) {
$client->send_end_stream(); JAXLLogger::error('Exception: ' . $ex->getMessage());
JAXLLogger::info('got on_auth_failure cb with reason: ' . $reason); }
});
$client->add_cb('on_disconnect', function () use ($client) {
JAXLLogger::info('got on_disconnect cb');
});
$client->start();
} catch (Exception $ex) {
JAXLLogger::error('Exception: ' . $ex->getMessage());
}
} }
/** /**

View File

@ -268,7 +268,7 @@ $sm_lang = array(
'warning_notifications_disabled_email' => 'Email notifications are disabled.', 'warning_notifications_disabled_email' => 'Email notifications are disabled.',
'warning_notifications_disabled_pushover' => 'Pushover notifications are disabled.', 'warning_notifications_disabled_pushover' => 'Pushover notifications are disabled.',
'warning_notifications_disabled_telegram' => 'Telegram notifications are disabled.', 'warning_notifications_disabled_telegram' => 'Telegram notifications are disabled.',
'warning_notifications_disabled_jabber' => 'Jabber notifications are disabled.', 'warning_notifications_disabled_jabber' => 'Jabber notifications are disabled.',
'error_server_no_match' => 'Server not found.', 'error_server_no_match' => 'Server not found.',
'error_server_label_bad_length' => 'The label must be between 1 and 255 characters.', 'error_server_label_bad_length' => 'The label must be between 1 and 255 characters.',
'error_server_ip_bad_length' => 'The domain / IP must be between 1 and 255 characters.', 'error_server_ip_bad_length' => 'The domain / IP must be between 1 and 255 characters.',
@ -322,19 +322,19 @@ $sm_lang = array(
'telegram_api_token' => 'Telegram API Token', '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 'telegram_api_token_description' => 'Before you can use Telegram, you need to get a API token. Visit the <a
href="http://docs.phpservermonitor.org/">documentation</a> for help.', href="http://docs.phpservermonitor.org/">documentation</a> for help.',
'jabber_status' => 'Allow sending Jabber (XMPP) messages', 'jabber_status' => 'Allow sending Jabber (XMPP) messages',
'jabber_description' => 'Visit the <a 'jabber_description' => 'Visit the <a
href="http://docs.phpservermonitor.org/">documentation</a> for more info and an href="http://docs.phpservermonitor.org/">documentation</a> for more info and an
install guide.', install guide.',
'jabber_host' => 'Host', 'jabber_host' => 'Host',
'jabber_host_description' => 'Host of your Jabber account provider. For Google Account use talk.google.com.', 'jabber_host_description' => 'Host of your Jabber account provider. For Google Account use talk.google.com.',
'jabber_port' => 'Port', 'jabber_port' => 'Port',
'jabber_port_description' => 'Port of your Jabber provider. Default 5222. For Google Account use 5223.', 'jabber_port_description' => 'Port of your Jabber provider. Default 5222. For Google Account use 5223.',
'jabber_username' => 'Username', 'jabber_username' => 'Username',
'jabber_username_description' => 'For Google Account use incl. domain so for example example@google.com.', 'jabber_username_description' => 'For Google Account use incl. domain so for example example@google.com.',
'jabber_domain' => 'Domain', 'jabber_domain' => 'Domain',
'jabber_domain_description' => 'Domain of your Jabber provider. Left empty for Google Account.', 'jabber_domain_description' => 'Domain of your Jabber provider. Left empty for Google Account.',
'jabber_password' => 'Password', 'jabber_password' => 'Password',
'jabber_password_description' => 'Fill only to set or change.', 'jabber_password_description' => 'Fill only to set or change.',
'jabber_check' => 'Check your Jabber account if message was received.', 'jabber_check' => 'Check your Jabber account if message was received.',
'alert_type' => 'Select when you\'d like to be notified.', 'alert_type' => 'Select when you\'d like to be notified.',
@ -360,18 +360,18 @@ $sm_lang = array(
'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', 'log_telegram' => 'Log Telegram messages sent by the script',
'log_jabber' => 'Log Jabber messages sent by the script', 'log_jabber' => 'Log Jabber 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',
'tab_pushover' => 'Pushover', 'tab_pushover' => 'Pushover',
'tab_telegram' => 'Telegram', 'tab_telegram' => 'Telegram',
'tab_jabber' => 'Jabber', 'tab_jabber' => 'Jabber',
'settings_email' => 'Email settings', 'settings_email' => 'Email settings',
'settings_sms' => 'Text message settings', 'settings_sms' => 'Text message settings',
'settings_pushover' => 'Pushover settings', 'settings_pushover' => 'Pushover settings',
'settings_telegram' => 'Telegram settings', 'settings_telegram' => 'Telegram settings',
'settings_jabber' => 'Jabber settings', 'settings_jabber' => 'Jabber settings',
'settings_notification' => 'Notification settings', 'settings_notification' => 'Notification settings',
'settings_log' => 'Log settings', 'settings_log' => 'Log settings',
'settings_proxy' => 'Proxy settings', 'settings_proxy' => 'Proxy settings',
@ -385,7 +385,7 @@ $sm_lang = array(
'test_pushover' => 'A Pushover notification will be sent to the user key/device specified in your user 'test_pushover' => 'A Pushover notification will be sent to the user key/device specified in your user
profile.', profile.',
'test_telegram' => 'A Telegram notification will be sent to the chat id 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.', 'test_jabber' => 'A Jabber notification will be sent to the jabber account specified in your user profile.',
'send' => 'Send', 'send' => 'Send',
'test_subject' => 'Test', 'test_subject' => 'Test',
'test_message' => 'Test message', 'test_message' => 'Test message',
@ -404,11 +404,11 @@ $sm_lang = array(
'telegram_error_notoken' => 'Unable to send test notification: no Telegram API token found in the global 'telegram_error_notoken' => 'Unable to send test notification: no Telegram API token found in the global
configuration.', configuration.',
'telegram_error_noid' => 'Unable to send test notification: no chat id found in your profile.', 'telegram_error_noid' => 'Unable to send test notification: no chat id found in your profile.',
'jabber_sent' => 'Telegram notification sent', 'jabber_sent' => 'Telegram notification sent',
'jabber_error' => 'An error has occurred while sending the Telegram notification: %s', '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 'jabber_error_noconfig' => 'Unable to send test notification: no Jabber account set in the global
configuration.', configuration.',
'jabber_error_noaccount' => 'Unable to send test notification: no Jabber account found in your profile.', 'jabber_error_noaccount' => 'Unable to send test notification: no Jabber account found in your profile.',
'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 'log_retention_period_description' => 'Number of days to keep logs of notifications and archives of server
uptime. Enter 0 to disable log cleanup.', uptime. Enter 0 to disable log cleanup.',
@ -424,7 +424,7 @@ $sm_lang = array(
%IP%<br>Port: %PORT%<br>Error: %ERROR%<br>Date: %DATE%', %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: '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%', %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: '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%', %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_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_subject' => 'IMPORTANT: Server \'%LABEL%\' is RUNNING',
@ -438,7 +438,7 @@ $sm_lang = array(
'on_telegram_message' => 'Server \'%LABEL%\' is running again, it was down for: '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: %LAST_OFFLINE_DURATION%<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Date:
%DATE%', %DATE%',
'on_jabber_message' => 'Server \'%LABEL%\' is running again, it was down for: '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: %LAST_OFFLINE_DURATION%<br><br>Server: %LABEL%<br>IP: %IP%<br>Port: %PORT%<br>Date:
%DATE%', %DATE%',
'combi_off_email_message' => '<ul><li>Server: %LABEL%</li><li>IP: %IP%</li><li>Port: %PORT%</li><li>Error: 'combi_off_email_message' => '<ul><li>Server: %LABEL%</li><li>IP: %IP%</li><li>Port: %PORT%</li><li>Error:
@ -447,7 +447,7 @@ $sm_lang = array(
%ERROR%</li><li>Date: %DATE%</li></ul>', %ERROR%</li><li>Date: %DATE%</li></ul>',
'combi_off_telegram_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Error: %ERROR%<br>- 'combi_off_telegram_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Error: %ERROR%<br>-
Date: %DATE%<br><br>', Date: %DATE%<br><br>',
'combi_off_jabber_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Error: %ERROR%<br>- 'combi_off_jabber_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Error: %ERROR%<br>-
Date: %DATE%<br><br>', Date: %DATE%<br><br>',
'combi_on_email_message' => '<ul><li>Server: %LABEL%</li><li>IP: %IP%</li><li>Port: %PORT%</li><li>Downtime: '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>', %LAST_OFFLINE_DURATION%</li><li>Date: %DATE%</li></ul>',
@ -456,7 +456,7 @@ $sm_lang = array(
%DATE%</li></ul>', %DATE%</li></ul>',
'combi_on_telegram_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Downtime: 'combi_on_telegram_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Downtime:
%LAST_OFFLINE_DURATION%<br>- Date: %DATE%<br><br>', %LAST_OFFLINE_DURATION%<br>- Date: %DATE%<br><br>',
'combi_on_jabber_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Downtime: 'combi_on_jabber_message' => '- Server: %LABEL%<br>- IP: %IP%<br>- Port: %PORT%<br>- Downtime:
%LAST_OFFLINE_DURATION%<br>- Date: %DATE%<br><br>', %LAST_OFFLINE_DURATION%<br>- Date: %DATE%<br><br>',
'combi_email_subject' => 'IMPORTANT: \'%UP%\' servers UP again, \'%DOWN%\' servers DOWN', 'combi_email_subject' => 'IMPORTANT: \'%UP%\' servers UP again, \'%DOWN%\' servers DOWN',
'combi_pushover_subject' => '\'%UP%\' servers UP again, \'%DOWN%\' servers DOWN', 'combi_pushover_subject' => '\'%UP%\' servers UP again, \'%DOWN%\' servers DOWN',
@ -466,7 +466,7 @@ $sm_lang = array(
servers are up again:</b><br>%UP_SERVERS%', 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 '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%', 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 '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%', servers are up again:</b><br>%UP_SERVERS%',
), ),
'login' => array( 'login' => array(

View File

@ -401,8 +401,8 @@ class UserController extends AbstractController
'label_telegram_description' => psm_get_lang('users', 'telegram_description'), 'label_telegram_description' => psm_get_lang('users', 'telegram_description'),
'label_telegram_id' => psm_get_lang('users', 'telegram_chat_id'), 'label_telegram_id' => psm_get_lang('users', 'telegram_chat_id'),
'label_telegram_id_description' => psm_get_lang('users', 'telegram_chat_id_description'), 'label_telegram_id_description' => psm_get_lang('users', 'telegram_chat_id_description'),
'label_jabber' => psm_get_lang('users', 'jabber'), 'label_jabber' => psm_get_lang('users', 'jabber'),
'label_jabber_description' => psm_get_lang('users', 'jabber_description'), 'label_jabber_description' => psm_get_lang('users', 'jabber_description'),
'label_email' => psm_get_lang('users', 'email'), 'label_email' => psm_get_lang('users', 'email'),
'label_servers' => psm_get_lang('menu', 'server'), 'label_servers' => psm_get_lang('menu', 'server'),
'label_save' => psm_get_lang('system', 'save'), 'label_save' => psm_get_lang('system', 'save'),

View File

@ -358,7 +358,7 @@ class Installer
$this->upgrade346(); $this->upgrade346();
} }
if (version_compare($version_from, '3.4.7', '<')) { if (version_compare($version_from, '3.4.7', '<')) {
$this->upgrade347(); $this->upgrade347();
} }
psm_update_conf('version', $version_to); psm_update_conf('version', $version_to);
} }
@ -688,20 +688,20 @@ class Installer
$this->execSQL($queries); $this->execSQL($queries);
} }
/** /**
* Upgrade for v3.4.7 * Upgrade for v3.4.7
*/ */
protected function upgrade347() protected function upgrade347()
{ {
$queries = []; $queries = [];
$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`;'; 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`;"; NOT NULL DEFAULT 'yes' AFTER `telegram`;";
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX .
"log` CHANGE `type` `type` ENUM( 'status', 'email', 'sms', 'pushover', 'telegram', 'jabber' ) "log` CHANGE `type` `type` ENUM( 'status', 'email', 'sms', 'pushover', 'telegram', 'jabber' )
CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;"; CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE
('jabber_status', '0'), ('jabber_status', '0'),
('log_jabber', '1'), ('log_jabber', '1'),
('jabber_host', ''), ('jabber_host', ''),
@ -709,6 +709,6 @@ class Installer
('jabber_username', ''), ('jabber_username', ''),
('jabber_domain', ''), ('jabber_domain', ''),
('jabber_password', '');"; ('jabber_password', '');";
$this->execSQL($queries); $this->execSQL($queries);
} }
} }