From f2d14bfd1f7e93d162cb4a165000f50df8c73478 Mon Sep 17 00:00:00 2001 From: TimZ99 Date: Sun, 9 Feb 2020 20:55:34 +0100 Subject: [PATCH] Refactor --- src/includes/functions.inc.php | 89 +++++++++---------- src/lang/en_US.lang.php | 50 +++++------ .../Module/User/Controller/UserController.php | 4 +- src/psm/Util/Install/Installer.php | 22 ++--- 4 files changed, 82 insertions(+), 83 deletions(-) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index bd1a659a..f197b864 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -34,7 +34,7 @@ namespace { # ############################################### - /** +/** * Retrieve language settings from the selected language file * Return false if arg is not found * @@ -641,57 +641,56 @@ namespace { return $telegram; } - /** - * Send message via XMPP. - * - * @param string $host - * @param string $username - * @param string $password - * @param string $receiver - * @param string $message - * @param int|null $port - * @param string|null $domain - */ + /** + * Send message via XMPP. + * + * @param string $host + * @param string $username + * @param string $password + * @param string $receiver + * @param string $message + * @param int|null $port + * @param string|null $domain + */ function psm_jabber_send_message($host, $username, $password, $receiver, $message, $port = null, $domain = null) { - $options = [ - 'jid' => $username, // incl. gmail.com - 'pass' => $password, - 'domain' => $domain, // gmail.com or null - 'host' => $host, // 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 + $options = [ + 'jid' => $username, // incl. gmail.com + 'pass' => $password, + 'domain' => $domain, // gmail.com or null + 'host' => $host, // 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 - // force tls - 'force_tls' => PSM_JABBER_FORCE_TLS, - // (required) perform X-OAUTH2 - 'auth_type' => PSM_JABBER_AUTH_TYPE, //'X-OAUTH2', // auth failure with this option :( so just PLAIN ... + // force tls + 'force_tls' => PSM_JABBER_FORCE_TLS, + // (required) perform X-OAUTH2 + '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 { - $client = new JAXL($options); + try { + $client = new JAXL($options); - // Add Callbacks - $client->add_cb('on_auth_success', function () use ($client, $receiver, $message) { - JAXLLogger::info('got on_auth_success cb'); - $client->send_chat_msg($receiver, $message); - $client->send_end_stream(); + // Add Callbacks + $client->add_cb('on_auth_success', function () use ($client, $receiver, $message) { + JAXLLogger::info('got on_auth_success cb'); + $client->send_chat_msg($receiver, $message); + $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->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(); - } catch (Exception $ex) { - JAXLLogger::error('Exception: ' . $ex->getMessage()); - } + $client->start(); + } catch (Exception $ex) { + JAXLLogger::error('Exception: ' . $ex->getMessage()); + } } /** diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 9abf2bf1..ae358794 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -268,7 +268,7 @@ $sm_lang = array( 'warning_notifications_disabled_email' => 'Email 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.', + 'warning_notifications_disabled_jabber' => 'Jabber notifications are disabled.', 'error_server_no_match' => 'Server not found.', '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.', @@ -322,19 +322,19 @@ $sm_lang = array( '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.', - 'jabber_status' => 'Allow sending Jabber (XMPP) messages', - 'jabber_description' => 'Visit the 'Allow sending Jabber (XMPP) messages', + 'jabber_description' => 'Visit the documentation 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', - 'jabber_port_description' => 'Port of your Jabber provider. Default 5222. For Google Account use 5223.', - 'jabber_username' => 'Username', - 'jabber_username_description' => 'For Google Account use incl. domain so for example example@google.com.', - 'jabber_domain' => 'Domain', - 'jabber_domain_description' => 'Domain of your Jabber provider. Left empty for Google Account.', - 'jabber_password' => 'Password', + 'jabber_host' => 'Host', + 'jabber_host_description' => 'Host of your Jabber account provider. For Google Account use talk.google.com.', + 'jabber_port' => 'Port', + 'jabber_port_description' => 'Port of your Jabber provider. Default 5222. For Google Account use 5223.', + 'jabber_username' => 'Username', + 'jabber_username_description' => 'For Google Account use incl. domain so for example example@google.com.', + 'jabber_domain' => 'Domain', + 'jabber_domain_description' => 'Domain of your Jabber provider. Left empty for Google Account.', + 'jabber_password' => 'Password', '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.', @@ -360,18 +360,18 @@ $sm_lang = array( 'log_sms' => 'Log text 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', + 'log_jabber' => 'Log Jabber messages sent by the script', 'updated' => 'The configuration has been updated.', 'tab_email' => 'Email', 'tab_sms' => 'SMS', 'tab_pushover' => 'Pushover', 'tab_telegram' => 'Telegram', - 'tab_jabber' => 'Jabber', + 'tab_jabber' => 'Jabber', 'settings_email' => 'Email settings', 'settings_sms' => 'Text message settings', 'settings_pushover' => 'Pushover settings', 'settings_telegram' => 'Telegram settings', - 'settings_jabber' => 'Jabber settings', + 'settings_jabber' => 'Jabber settings', 'settings_notification' => 'Notification settings', 'settings_log' => 'Log 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 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', 'test_subject' => 'Test', '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 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 + '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_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_description' => 'Number of days to keep logs of notifications and archives of server uptime. Enter 0 to disable log cleanup.', @@ -424,7 +424,7 @@ $sm_lang = array( %IP%
Port: %PORT%
Error: %ERROR%
Date: %DATE%', 'off_telegram_message' => 'Failed to connect to the following server:

Server: %LABEL%
IP: %IP%
Port: %PORT%
Error: %ERROR%
Date: %DATE%', - 'off_jabber_message' => 'Failed to connect to the following server:

Server: %LABEL%
IP: + 'off_jabber_message' => 'Failed to connect to the following server:

Server: %LABEL%
IP: %IP%
Port: %PORT%
Error: %ERROR%
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', @@ -438,7 +438,7 @@ $sm_lang = array( 'on_telegram_message' => 'Server \'%LABEL%\' is running again, it was down for: %LAST_OFFLINE_DURATION%

Server: %LABEL%
IP: %IP%
Port: %PORT%
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%

Server: %LABEL%
IP: %IP%
Port: %PORT%
Date: %DATE%', 'combi_off_email_message' => '', 'combi_off_telegram_message' => '- Server: %LABEL%
- IP: %IP%
- Port: %PORT%
- Error: %ERROR%
- Date: %DATE%

', - 'combi_off_jabber_message' => '- Server: %LABEL%
- IP: %IP%
- Port: %PORT%
- Error: %ERROR%
- + 'combi_off_jabber_message' => '- Server: %LABEL%
- IP: %IP%
- Port: %PORT%
- Error: %ERROR%
- Date: %DATE%

', 'combi_on_email_message' => '', @@ -456,7 +456,7 @@ $sm_lang = array( %DATE%', 'combi_on_telegram_message' => '- Server: %LABEL%
- IP: %IP%
- Port: %PORT%
- Downtime: %LAST_OFFLINE_DURATION%
- Date: %DATE%

', - 'combi_on_jabber_message' => '- Server: %LABEL%
- IP: %IP%
- Port: %PORT%
- Downtime: + 'combi_on_jabber_message' => '- Server: %LABEL%
- IP: %IP%
- Port: %PORT%
- Downtime: %LAST_OFFLINE_DURATION%
- Date: %DATE%

', 'combi_email_subject' => 'IMPORTANT: \'%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:
%UP_SERVERS%', 'combi_telegram_message' => 'The following servers went down:
%DOWN_SERVERS%
The following servers are up again:
%UP_SERVERS%', - 'combi_jabber_message' => 'The following servers went down:
%DOWN_SERVERS%
The following + 'combi_jabber_message' => 'The following servers went down:
%DOWN_SERVERS%
The following servers are up again:
%UP_SERVERS%', ), 'login' => array( diff --git a/src/psm/Module/User/Controller/UserController.php b/src/psm/Module/User/Controller/UserController.php index 13a4f63b..3f4b5699 100644 --- a/src/psm/Module/User/Controller/UserController.php +++ b/src/psm/Module/User/Controller/UserController.php @@ -401,8 +401,8 @@ class UserController extends AbstractController 'label_telegram_description' => psm_get_lang('users', 'telegram_description'), 'label_telegram_id' => psm_get_lang('users', 'telegram_chat_id'), 'label_telegram_id_description' => psm_get_lang('users', 'telegram_chat_id_description'), - 'label_jabber' => psm_get_lang('users', 'jabber'), - 'label_jabber_description' => psm_get_lang('users', 'jabber_description'), + 'label_jabber' => psm_get_lang('users', 'jabber'), + 'label_jabber_description' => psm_get_lang('users', 'jabber_description'), 'label_email' => psm_get_lang('users', 'email'), 'label_servers' => psm_get_lang('menu', 'server'), 'label_save' => psm_get_lang('system', 'save'), diff --git a/src/psm/Util/Install/Installer.php b/src/psm/Util/Install/Installer.php index 512b2b5f..7d1beb1b 100644 --- a/src/psm/Util/Install/Installer.php +++ b/src/psm/Util/Install/Installer.php @@ -358,7 +358,7 @@ class Installer $this->upgrade346(); } if (version_compare($version_from, '3.4.7', '<')) { - $this->upgrade347(); + $this->upgrade347(); } psm_update_conf('version', $version_to); } @@ -688,20 +688,20 @@ class Installer $this->execSQL($queries); } - /** - * Upgrade for v3.4.7 - */ + /** + * Upgrade for v3.4.7 + */ protected function upgrade347() { - $queries = []; - $queries[] = 'ALTER TABLE `' . PSM_DB_PREFIX . 'users` ADD `jabber` VARCHAR( 255 ) + $queries = []; + $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' ) + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . + "log` CHANGE `type` `type` ENUM( 'status', 'email', 'sms', 'pushover', 'telegram', 'jabber' ) 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'), ('log_jabber', '1'), ('jabber_host', ''), @@ -709,6 +709,6 @@ class Installer ('jabber_username', ''), ('jabber_domain', ''), ('jabber_password', '');"; - $this->execSQL($queries); + $this->execSQL($queries); } }