diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 75600c40..c55150d8 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -413,6 +413,19 @@ function psm_build_mail($from_name = null, $from_email = null) { return $phpmailer; } +/** + + * Prepare a new Pushover util. + * + * @return \psm\Util\Pushover + */ +function psm_build_pushover() { + $pushover = new \psm\Util\Pushover(); + $pushover->setToken(psm_get_conf('pushover_api_token')); + + return $pushover; +} + /** * Prepare a new SMS util. * diff --git a/src/lang/de_DE.lang.php b/src/lang/de_DE.lang.php index 03ed78c2..cdeabccc 100644 --- a/src/lang/de_DE.lang.php +++ b/src/lang/de_DE.lang.php @@ -81,6 +81,9 @@ $sm_lang = array( 'level_description' => 'Administrators have full access: they can manage servers, users and edit the global configuration.
Users can only view and run the updater for the servers that have been assigned to them.', 'mobile' => 'Mobil', 'email' => 'Email', + 'pushover' => 'Pushover', + 'pushover_key' => 'Pushover Key', + 'pushover_device' => 'Pushover Device', 'delete_title' => 'Delete User', 'delete_message' => 'Are you sure you want to delete user \'%1\'?', 'deleted' => 'User deleted.', @@ -104,6 +107,7 @@ $sm_lang = array( 'status' => 'Status', 'email' => 'Email', 'sms' => 'SMS', + 'pushover' => 'Pushover', 'no_logs' => 'No logs', ), 'servers' => array( @@ -127,6 +131,7 @@ $sm_lang = array( 'send_email' => 'Email', 'sms' => 'SMS', 'send_sms' => 'SMS', + 'pushover' => 'Pushover', 'users' => 'Users', 'delete_title' => 'Delete Server', 'delete_message' => 'Are you sure you want to delete server \'%1\'?', @@ -186,6 +191,8 @@ $sm_lang = array( 'sms_gateway_username' => 'Gateway Benutzername', 'sms_gateway_password' => 'Gateway Passwort', 'sms_from' => 'SMS Sendernummer', + 'pushover_status' => 'Pushover Nachricht senden erlauben?', + 'pushover_api_token' => 'Pushover App API Token', 'alert_type' => 'Wann möchten Sie benachrichtig werden?
', 'alert_type_description' => 'Status geändert: '. '... wenn sich der Status ändert
'. @@ -203,13 +210,16 @@ $sm_lang = array( 'log_status_description' => 'Ist der Log Status auf TRUE (ein Hacken) gesetzt, wird jeder Status protokolliert.', 'log_email' => 'Email Log per Script senden?', 'log_sms' => 'SMS Log per Script senden?', + 'log_pushover' => 'Pushover Log per Script senden?', 'updated' => 'Die Einstellungen wurden gespeichert.', 'nochanges' => 'The configuration didn\'t change.', 'tab_email' => 'Email', 'tab_sms' => 'SMS', + 'tab_pushover' => 'Pushover', 'tab_log' => 'Log', 'settings_email' => 'Email', 'settings_sms' => 'SMS Nachricht', + 'settings_pushover' => 'Pushover', 'settings_notification' => 'Benachrichtigung', 'settings_log' => 'Log', 'auto_refresh' => 'Auto-refresh', @@ -235,9 +245,17 @@ $sm_lang = array( 'off_sms' => 'Server \'%LABEL%\' ist Offline: ip=%IP%, port=%PORT%. Fehler=%ERROR%', 'off_email_subject' => 'Wichtig: Server \'%LABEL%\' ist Offline', 'off_email_body' => "Kann keine Verbindung zum Server aufbauen:

Server: %LABEL%
IP: %IP%
Port: %PORT%
Fehler: %ERROR%
Datum: %DATE%", + 'off_pushover_title' => '\'%LABEL%\' Offline', + 'off_pushover_message' => 'Server \'%LABEL%\'
ist Offline
IP: %IP%
Port: %PORT%
Fehler: %ERROR%', + 'off_pushover_url_title' => 'SERVER MONITOR', + 'off_pushover_url' => '%MONITORURL%', 'on_sms' => 'Server \'%LABEL%\' ist wieder Online: ip=%IP%, port=%PORT%', 'on_email_subject' => 'Wichtig: Server \'%LABEL%\' ist wieder Online', 'on_email_body' => "Server '%LABEL%' läuft wieder:

Server: %LABEL%
IP: %IP%
Port: %PORT%
Datum: %DATE%", + 'on_pushover_title' => '\'%LABEL%\' Online', + 'on_pushover_message' => 'Server \'%LABEL%\'
ist wieder Online
IP: %IP%
Port: %PORT%', + 'on_pushover_url_title' => 'SERVER MONITOR', + 'on_pushover_url' => '%MONITORURL%', ), 'login' => array( 'welcome_usermenu' => 'Welcome, %user_name%', diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index bce95b89..5868625f 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -81,6 +81,9 @@ $sm_lang = array( 'level_description' => 'Administrators have full access: they can manage servers, users and edit the global configuration.
Users can only view and run the updater for the servers that have been assigned to them.', 'mobile' => 'Mobile', 'email' => 'Email', + 'pushover' => 'Pushover', + 'pushover_key' => 'Pushover Key', + 'pushover_device' => 'Pushover Device', 'delete_title' => 'Delete User', 'delete_message' => 'Are you sure you want to delete user \'%1\'?', 'deleted' => 'User deleted.', @@ -104,6 +107,7 @@ $sm_lang = array( 'status' => 'Status', 'email' => 'Email', 'sms' => 'SMS', + 'pushover' => 'Pushover', 'no_logs' => 'No logs', ), 'servers' => array( @@ -127,6 +131,7 @@ $sm_lang = array( 'send_email' => 'Send Email', 'sms' => 'SMS', 'send_sms' => 'Send SMS', + 'send_pushover' => 'Send Pushover', 'users' => 'Users', 'delete_title' => 'Delete server', 'delete_message' => 'Are you sure you want to delete server \'%1\'?', @@ -186,6 +191,8 @@ $sm_lang = array( 'sms_gateway_username' => 'Gateway username', 'sms_gateway_password' => 'Gateway password', 'sms_from' => 'Sender\'s phone number', + 'pushover_status' => 'Allow sending pushover messages', + 'pushover_api_token' => 'Pushover App API Token', 'alert_type' => 'Select when you\'d like to be notified.
', 'alert_type_description' => 'Status change: '. 'You will receive a notifcation when a server has a change in status. So from online -> offline or offline -> online.
'. @@ -203,13 +210,16 @@ $sm_lang = array( '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_pushover' => 'Log pushover messages sent by the script', 'updated' => 'The configuration has been updated.', 'nochanges' => 'The configuration didn\'t change.', 'tab_email' => 'Email', 'tab_sms' => 'SMS', + 'tab_pushover' => 'Pushover', 'tab_log' => 'Log', 'settings_email' => 'Email settings', 'settings_sms' => 'Text message settings', + 'settings_pushover' => 'Pushover settings', 'settings_notification' => 'Notification settings', 'settings_log' => 'Log settings', 'auto_refresh' => 'Auto-refresh', @@ -235,9 +245,17 @@ $sm_lang = 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:

Server: %LABEL%
IP: %IP%
Port: %PORT%
Error: %ERROR%
Date: %DATE%", + 'off_pushover_title' => '\'%LABEL%\' Offline', + 'off_pushover_message' => 'Server \'%LABEL%\'
ist Offline
IP: %IP%
Port: %PORT%
Fehler: %ERROR%', + 'off_pushover_url_title' => 'SERVER MONITOR', + 'off_pushover_url' => '%MONITORURL%', 'on_sms' => 'Server \'%LABEL%\' is RUNNING: ip=%IP%, port=%PORT%', 'on_email_subject' => 'IMPORTANT: Server \'%LABEL%\' is RUNNING', 'on_email_body' => "Server '%LABEL%' is running again:

Server: %LABEL%
IP: %IP%
Port: %PORT%
Date: %DATE%", + 'on_pushover_title' => '\'%LABEL%\' Online', + 'on_pushover_message' => 'Server \'%LABEL%\'
ist wieder Online
IP: %IP%
Port: %PORT%', + 'on_pushover_url_title' => 'SERVER MONITOR', + 'on_pushover_url' => '%MONITORURL%', ), 'login' => array( 'welcome_usermenu' => 'Welcome, %user_name%', diff --git a/src/psm/Module/Config/Controller/ConfigController.class.php b/src/psm/Module/Config/Controller/ConfigController.class.php index f072f242..51bc51c6 100644 --- a/src/psm/Module/Config/Controller/ConfigController.class.php +++ b/src/psm/Module/Config/Controller/ConfigController.class.php @@ -40,9 +40,11 @@ class ConfigController extends AbstractController { 'email_status', 'email_smtp', 'sms_status', + 'pushover_status', 'log_status', 'log_email', 'log_sms', + 'log_pushover', 'show_update', ); @@ -60,6 +62,7 @@ class ConfigController extends AbstractController { 'sms_gateway_username', 'sms_gateway_password', 'sms_from', + 'pushover_api_token', ); private $default_tab = 'general'; @@ -249,9 +252,11 @@ class ConfigController extends AbstractController { 'subtitle' => psm_get_lang('menu', 'config'), 'label_tab_email' => psm_get_lang('config', 'tab_email'), 'label_tab_sms' => psm_get_lang('config', 'tab_sms'), + 'label_tab_pushover' => psm_get_lang('config', 'tab_pushover'), 'label_tab_log' => psm_get_lang('config', 'tab_log'), 'label_settings_email' => psm_get_lang('config', 'settings_email'), 'label_settings_sms' => psm_get_lang('config', 'settings_sms'), + 'label_settings_pushover' => psm_get_lang('config', 'settings_pushover'), 'label_settings_notification' => psm_get_lang('config', 'settings_notification'), 'label_settings_log' => psm_get_lang('config', 'settings_log'), 'label_general' => psm_get_lang('config', 'general'), @@ -279,6 +284,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_pushover_status' => psm_get_lang('config', 'pushover_status'), + 'label_pushover_api_token' => psm_get_lang('config', 'pushover_api_token'), 'label_alert_type' => psm_get_lang('config', 'alert_type'), 'label_alert_type_description' => psm_get_lang('config', 'alert_type_description'), 'label_alert_type_status' => psm_get_lang('config', 'alert_type_status'), @@ -288,6 +295,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_pushover' => psm_get_lang('config', 'log_pushover'), 'label_auto_refresh' => psm_get_lang('config', 'auto_refresh'), 'label_auto_refresh_servers' => psm_get_lang('config', 'auto_refresh_servers'), 'label_seconds' => psm_get_lang('config', 'seconds'), diff --git a/src/psm/Module/Server/Controller/AbstractServerController.class.php b/src/psm/Module/Server/Controller/AbstractServerController.class.php index c2ac5955..daa5434f 100644 --- a/src/psm/Module/Server/Controller/AbstractServerController.class.php +++ b/src/psm/Module/Server/Controller/AbstractServerController.class.php @@ -73,6 +73,7 @@ abstract class AbstractServerController extends AbstractController { `s`.`active`, `s`.`email`, `s`.`sms`, + `s`.`pushover`, `s`.`warning_threshold`, `s`.`warning_threshold_counter`, `s`.`timeout` @@ -101,6 +102,7 @@ abstract class AbstractServerController extends AbstractController { $server['active'] = psm_get_lang('system', $server['active']); $server['email'] = psm_get_lang('system', $server['email']); $server['sms'] = psm_get_lang('system', $server['sms']); + $server['pushover'] = psm_get_lang('system', $server['pushover']); $server['url_view'] = psm_build_url(array( 'mod' => 'server', 'action' => 'view', diff --git a/src/psm/Module/Server/Controller/LogController.class.php b/src/psm/Module/Server/Controller/LogController.class.php index 61683541..8c75a883 100644 --- a/src/psm/Module/Server/Controller/LogController.class.php +++ b/src/psm/Module/Server/Controller/LogController.class.php @@ -50,6 +50,7 @@ class LogController extends AbstractServerController { $entries['status'] = $this->getEntries('status'); $entries['email'] = $this->getEntries('email'); $entries['sms'] = $this->getEntries('sms'); + $entries['pushover'] = $this->getEntries('pushover'); // get users $users = $this->db->select(PSM_DB_PREFIX.'users', null, array('user_id','name')); @@ -156,6 +157,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_pushover' => psm_get_lang('log', 'pushover'), 'label_title' => psm_get_lang('log', 'title'), 'label_server' => psm_get_lang('servers', 'server'), 'label_type' => psm_get_lang('log', 'type'), diff --git a/src/psm/Module/Server/Controller/ServerController.class.php b/src/psm/Module/Server/Controller/ServerController.class.php index 1fd582c2..15a3dd97 100644 --- a/src/psm/Module/Server/Controller/ServerController.class.php +++ b/src/psm/Module/Server/Controller/ServerController.class.php @@ -209,6 +209,7 @@ class ServerController extends AbstractServerController { 'edit_active_selected_' . $edit_server['active'] => 'selected="selected"', 'edit_email_selected_' . $edit_server['email'] => 'selected="selected"', 'edit_sms_selected_' . $edit_server['sms'] => 'selected="selected"', + 'edit_pushover_selected_' . $edit_server['pushover'] => 'selected="selected"', )); } @@ -227,6 +228,7 @@ class ServerController extends AbstractServerController { return $this->executeIndex(); } + $clean = array( 'label' => trim(strip_tags(psm_POST('label', ''))), 'ip' => trim(strip_tags(psm_POST('ip', ''))), @@ -410,6 +412,7 @@ 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_send_pushover' => psm_get_lang('servers', 'send_pushover'), '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'), @@ -444,4 +447,4 @@ class ServerController extends AbstractServerController { } return $result; } -} +} \ No newline at end of file diff --git a/src/psm/Module/User/Controller/ProfileController.class.php b/src/psm/Module/User/Controller/ProfileController.class.php index a9d11158..dfc09b19 100644 --- a/src/psm/Module/User/Controller/ProfileController.class.php +++ b/src/psm/Module/User/Controller/ProfileController.class.php @@ -36,7 +36,7 @@ class ProfileController extends AbstractController { * Editable fields for the profile * @var array $profile_fields */ - protected $profile_fields = array('name', 'user_name', 'mobile', 'email'); + protected $profile_fields = array('name', 'user_name', 'mobile', 'pushover_key', 'pushover_device', 'email'); function __construct(Database $db, Template $tpl) { parent::__construct($db, $tpl); @@ -132,6 +132,8 @@ class ProfileController extends AbstractController { 'label_password_repeat' => psm_get_lang('users', 'password_repeat'), 'label_level' => psm_get_lang('users', 'level'), 'label_mobile' => psm_get_lang('users', 'mobile'), + 'label_pushover_key' => psm_get_lang('users', 'pushover_key'), + 'label_pushover_device' => psm_get_lang('users', 'pushover_device'), 'label_email' => psm_get_lang('users', 'email'), 'label_save' => psm_get_lang('system', 'save'), ) @@ -139,4 +141,4 @@ class ProfileController extends AbstractController { return parent::createHTMLLabels(); } -} +} \ No newline at end of file diff --git a/src/psm/Module/User/Controller/UserController.class.php b/src/psm/Module/User/Controller/UserController.class.php index 46bbe1af..7a7db8a1 100644 --- a/src/psm/Module/User/Controller/UserController.class.php +++ b/src/psm/Module/User/Controller/UserController.class.php @@ -94,7 +94,7 @@ class UserController extends AbstractController { $users = $this->db->select( PSM_DB_PREFIX.'users', null, - array('user_id', 'user_name', 'level', 'name', 'mobile', 'email'), + array('user_id', 'user_name', 'level', 'name', 'mobile', 'pushover_key', 'pushover_device', 'email'), null, array('name') ); @@ -121,7 +121,7 @@ class UserController extends AbstractController { protected function executeEdit() { $this->setTemplateId('user_update', 'user/user.tpl.html'); $user_id = isset($_GET['id']) ? intval($_GET['id']) : 0; - $fields_prefill = array('name', 'user_name', 'mobile', 'email'); + $fields_prefill = array('name', 'user_name', 'mobile', 'pushover_key', 'pushover_device', 'email'); if($user_id == 0) { // insert mode @@ -196,7 +196,7 @@ class UserController extends AbstractController { } $user_id = (isset($_GET['id'])) ? intval($_GET['id']) : 0; - $fields = array('name', 'user_name', 'password', 'password_repeat', 'level', 'mobile', 'email'); + $fields = array('name', 'user_name', 'password', 'password_repeat', 'level', 'mobile', 'pushover_key', 'pushover_device', 'email'); $clean = array(); foreach($fields as $field) { if(isset($_POST[$field])) { @@ -300,6 +300,9 @@ class UserController extends AbstractController { 'label_level_20' => psm_get_lang('users', 'level_20'), 'label_level_description' => psm_get_lang('users', 'level_description'), 'label_mobile' => psm_get_lang('users', 'mobile'), + 'label_pushover' => psm_get_lang('users', 'pushover'), + 'label_pushover_key' => psm_get_lang('users', 'pushover_key'), + 'label_pushover_device' => psm_get_lang('users', 'pushover_device'), 'label_email' => psm_get_lang('users', 'email'), 'label_servers' => psm_get_lang('menu', 'server'), 'label_action' => psm_get_lang('system', 'action'), diff --git a/src/psm/Util/Install/Installer.class.php b/src/psm/Util/Install/Installer.class.php index 3634aca6..c5cef4b3 100644 --- a/src/psm/Util/Install/Installer.class.php +++ b/src/psm/Util/Install/Installer.class.php @@ -126,7 +126,7 @@ class Installer { $this->log('Populating database...'); $queries = array(); - $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "servers` (`ip`, `port`, `label`, `type`, `pattern`, `status`, `error`, `rtime`, `last_online`, `last_check`, `active`, `email`, `sms`) VALUES ('http://sourceforge.net/index.php', 80, 'SourceForge', 'website', '', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes'), ('smtp.gmail.com', 465, 'Gmail SMTP', 'service', '', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes')"; + $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "servers` (`ip`, `port`, `label`, `type`, `pattern`, `status`, `error`, `rtime`, `last_online`, `last_check`, `active`, `email`, `sms`, `pushover`) VALUES ('http://sourceforge.net/index.php', 80, 'SourceForge', 'website', '', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes'), ('smtp.gmail.com', 465, 'Gmail SMTP', 'service', '', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes', 'yes')"; $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "users_servers` (`user_id`,`server_id`) VALUES (1, 1), (1, 2);"; $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE ('language', 'en_US'), @@ -143,10 +143,13 @@ class Installer { ('sms_gateway_username', 'username'), ('sms_gateway_password', 'password'), ('sms_from', '1234567890'), + ('pushover_status', '1'), + ('pushover_api_token', ''), ('alert_type', 'status'), ('log_status', '1'), ('log_email', '1'), ('log_sms', '1'), + ('log_pushover', '1'), ('version', '" . PSM_VERSION . "'), ('version_update_check', '" . PSM_VERSION . "'), ('auto_refresh_servers', '0'), @@ -177,6 +180,8 @@ class Installer { `level` tinyint(2) unsigned NOT NULL DEFAULT '20', `name` varchar(255) NOT NULL, `mobile` varchar(15) NOT NULL, + `pushover_key` varchar(255) NOT NULL, + `pushover_device` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, PRIMARY KEY (`user_id`), UNIQUE KEY `unique_username` (`user_name`) @@ -216,6 +221,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', + `pushover` enum('yes','no') NOT NULL default 'no', `warning_threshold` mediumint(1) unsigned NOT NULL DEFAULT '1', `warning_threshold_counter` mediumint(1) unsigned NOT NULL DEFAULT '0', `timeout` smallint(1) unsigned NULL DEFAULT NULL, @@ -392,6 +398,15 @@ class Installer { protected function upgrade310() { $queries = array(); + $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUES ('pushover_status', '1');"; + $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUES ('log_pushover', '1');"; + $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUES ('pushover_api_token', '');"; + + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "users` ADD `pushover_key` VARCHAR( 255 ) NOT NULL AFTER `mobile`;"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "users` ADD `pushover_device` VARCHAR( 255 ) NOT NULL AFTER `pushover_key`;"; + + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `pushover` ENOM( 'yes','no' ) NOT NULL DEFAULT 'no' AFTER `sms`;"; + $queries[] = "CREATE TABLE IF NOT EXISTS `" . PSM_DB_PREFIX . "users_preferences` ( `user_id` int(11) unsigned NOT NULL, `key` varchar(255) NOT NULL, diff --git a/src/psm/Util/Pushover.class.php b/src/psm/Util/Pushover.class.php new file mode 100644 index 00000000..406fff2d --- /dev/null +++ b/src/psm/Util/Pushover.class.php @@ -0,0 +1,54 @@ +. + * + * @package phpservermon + * @author Pepijn Over + * @copyright Copyright (c) 2008-2014 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.0.0 + **/ + +namespace psm\Util; + +/** + * Pushover is not using namespaces so unable to load files in autoloader. + */ +require_once(PSM_PATH_VENDOR . '/Pushover/Pushover.php'); + +/** + * PSM Pushover utility + * + * The Pushover is an open source lib that can be found in vendor/Pushover. + * + * @see \Pushover + */ +class Pushover extends \Pushover { + + /** + * Open new Pushover + * + * @param boolean $exceptions + */ + function __construct($exceptions = false) { + parent::__construct($exceptions); + + } +} \ No newline at end of file diff --git a/src/psm/Util/Updater/Autorun.class.php b/src/psm/Util/Updater/Autorun.class.php index 681456e1..1327a506 100644 --- a/src/psm/Util/Updater/Autorun.class.php +++ b/src/psm/Util/Updater/Autorun.class.php @@ -69,7 +69,7 @@ class Autorun { )"; } - $sql = "SELECT `s`.`server_id`,`s`.`ip`,`s`.`port`,`s`.`label`,`s`.`type`,`s`.`pattern`,`s`.`status`,`s`.`active`,`s`.`email`,`s`.`sms` + $sql = "SELECT `s`.`server_id`,`s`.`ip`,`s`.`port`,`s`.`label`,`s`.`type`,`s`.`pattern`,`s`.`status`,`s`.`active`,`s`.`email`,`s`.`sms`,`s`.`pushover` FROM `".PSM_DB_PREFIX."servers` AS `s` {$sql_join} WHERE `active`='yes' "; diff --git a/src/psm/Util/Updater/StatusNotifier.class.php b/src/psm/Util/Updater/StatusNotifier.class.php index 816ebcde..f0423cde 100644 --- a/src/psm/Util/Updater/StatusNotifier.class.php +++ b/src/psm/Util/Updater/StatusNotifier.class.php @@ -54,6 +54,12 @@ class StatusNotifier { */ protected $send_sms = false; + /** + * Send sms? + * @var boolean $send_pushover + */ + protected $send_pushover = false; + /** * Save log records? * @var boolean $save_log @@ -89,6 +95,7 @@ class StatusNotifier { $this->send_emails = psm_get_conf('email_status'); $this->send_sms = psm_get_conf('sms_status'); + $this->send_pushover = psm_get_conf('pushover_status'); $this->save_logs = psm_get_conf('log_status'); } @@ -114,7 +121,7 @@ class StatusNotifier { $this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array( 'server_id' => $server_id, ), array( - 'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'error', 'active', 'email', 'sms', + 'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'error', 'active', 'email', 'sms', 'pushover', )); if(empty($this->server)) { return false; @@ -169,6 +176,12 @@ class StatusNotifier { $this->notifyByTxtMsg(); } + // check if pushover is enabled for this server + if($this->send_pushover && $this->server['pushover'] == 'yes') { + // yay lets wake those nerds up! + $this->notifyByPushover(); + } + return $notify; } @@ -210,6 +223,60 @@ class StatusNotifier { } } + /** + * This functions performs the pushover notifications + * + * @return boolean + */ + protected function notifyByPushover() { + $userlist = array(); + + $users = $this->getUsers($this->server_id); + + if (empty($users)) { + return false; + } + + // build pushover object with some default values + $pushover = psm_build_pushover(); + + if($this->status_new === true) + { + $pushover->setPriority(0); + }else + { + $pushover->setPriority(2); + $pushover->setRetry(300); //Used with Priority = 2; Pushover will resend the notification every 60 seconds until the user accepts. + $pushover->setExpire(3600); //Used with Priority = 2; Pushover will resend the notification every 60 seconds for 3600 seconds. After that point, it stops sending notifications. + } + //$pushover->setCallback('http://some.url/runscript.php'); // The callback parameter must be a URL (HTTP or HTTPS) that is reachable from the Internet that our servers will call out to as soon as the notification has been acknowledged. + $pushover->setTimestamp(time()); + //$pushover->setDebug(true); + //$pushover->setSound('bike'); + + $this->server['MONITORURL']=$url = "http".(!empty($_SERVER['HTTPS'])?"s":"").":\/\/".$_SERVER['SERVER_NAME']; + + $message = psm_parse_msg($this->status_new, 'pushover_message', $this->server); + + $pushover->setTitle(psm_parse_msg($this->status_new, 'pushover_title', $this->server)); + $pushover->setMessage(str_replace('
', "\n", $message)); + + $pushover->setUrl(psm_parse_msg($this->status_new, 'pushover_url', $this->server)); + $pushover->setUrlTitle(psm_parse_msg($this->status_new, 'pushover_url_title', $this->server)); + + // go through empl + foreach ($users as $user) { + $pushover->setUser($user['pushover_key']); + $pushover->setDevice($user['pushover_device']); + $pushover->send(); + } + + if(psm_get_conf('log_pushover')) { + // save to log + psm_add_log($this->server_id, 'pushover', $message, implode(',', $userlist)); + } + } + /** * This functions performs the text message notifications * @@ -257,7 +324,7 @@ class StatusNotifier { public function getUsers($server_id) { // find all the users with this server listed $users = $this->db->query(" - SELECT `u`.`user_id`, `u`.`name`,`u`.`email`, `u`.`mobile` + SELECT `u`.`user_id`, `u`.`name`,`u`.`email`, `u`.`mobile`, `u`.`pushover_key`, `u`.`pushover_device` FROM `".PSM_DB_PREFIX."users` AS `u` JOIN `".PSM_DB_PREFIX."users_servers` AS `us` ON ( `us`.`user_id`=`u`.`user_id` diff --git a/src/templates/config/config.tpl.html b/src/templates/config/config.tpl.html index 28daab5a..a70aa156 100755 --- a/src/templates/config/config.tpl.html +++ b/src/templates/config/config.tpl.html @@ -4,6 +4,7 @@
  • {label_general}
  • {label_tab_email}
  • {label_tab_sms}
  • +
  • {label_tab_pushover}
  • {label_tab_log}
  • @@ -157,7 +158,26 @@
    -
    +
    +
    + {label_settings_pushover} +
    +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    +
    +
    +
    {label_settings_log}
    @@ -170,6 +190,9 @@
    +
    + +
    diff --git a/src/templates/server/log.tpl.html b/src/templates/server/log.tpl.html index af14b59c..3ae62bf1 100755 --- a/src/templates/server/log.tpl.html +++ b/src/templates/server/log.tpl.html @@ -4,6 +4,7 @@
  • {label_status}
  • {label_email}
  • {label_sms}
  • +
  • {label_pushover}
  • @@ -15,6 +16,9 @@
    {content_sms}
    +
    + {content_pushover} +
    diff --git a/src/templates/server/server.tpl.html b/src/templates/server/server.tpl.html index 503e53a7..61e2d5d4 100644 --- a/src/templates/server/server.tpl.html +++ b/src/templates/server/server.tpl.html @@ -12,6 +12,7 @@ {label_monitoring} {label_email} {label_sms} + {label_pushover} {label_action} @@ -140,6 +141,15 @@
    +
    + +
    + +
    +
    diff --git a/src/templates/server/view.tpl.html b/src/templates/server/view.tpl.html index 87fed922..d72c83c0 100644 --- a/src/templates/server/view.tpl.html +++ b/src/templates/server/view.tpl.html @@ -67,6 +67,10 @@ {label_sms}: {sms} + + {label_send_pushover}: + {pushover} + {label_timeout}: {timeout} s diff --git a/src/templates/user/profile.tpl.html b/src/templates/user/profile.tpl.html index fd158fb2..b426f77e 100755 --- a/src/templates/user/profile.tpl.html +++ b/src/templates/user/profile.tpl.html @@ -36,7 +36,19 @@
    - + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    diff --git a/src/templates/user/user.tpl.html b/src/templates/user/user.tpl.html index 18ed4dac..b9734a65 100755 --- a/src/templates/user/user.tpl.html +++ b/src/templates/user/user.tpl.html @@ -7,6 +7,7 @@ {label_level} {label_email} {label_mobile} + {label_pushover} {label_servers} {label_action} @@ -14,6 +15,13 @@ + {name} + {user_name} + {label_level_{level}} + {mobile} + {pushover_device} + {email} + {emp_servers}
    @@ -111,7 +119,19 @@
    - + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    diff --git a/vendor/Pushover/Pushover.php b/vendor/Pushover/Pushover.php new file mode 100644 index 00000000..99049d6a --- /dev/null +++ b/vendor/Pushover/Pushover.php @@ -0,0 +1,452 @@ + + * @version 0.2 + * @package php-pushover + * @example test.php + * @link https://pushover.net/api + * @license BSD License + */ + +class Pushover +{ + // api url + const API_URL = 'https://api.pushover.net/1/messages.xml'; + + /** + * Application API token + * + * @var string + */ + private $_token; + + /** + * User API token + * + * @var string + */ + private $_user; + + /** + * Turn on/off debug mode + * + * @var bool + */ + private $_debug = false; + + /** + * Title of the message + * + * @var string + */ + private $_title; + + /** + * The message itself (up to 512 characters) + * + * @var string + */ + private $_message; + + /** + * Timestamp in Unix timestamp format + * + * @var int + */ + private $_timestamp; + + /** + * User's device (user specific) + * + * @var string + */ + private $_device; + + /** + * Priority of the message. Can be 0, 1 or 2. High-priority messages (1) override a user's "quiet hours" setting and will always be delivered any time they are received. High priority messages are highlighted in red in the Android and iOS clients. Emergency Priority (2) messages work similar to High-Priority messages, but they are repeated until the message is acknowledged by the user. + * + * @var string + */ + private $_priority = 0; + + /** + * Include a Supplementary URL (up to 200 characters) + * + * @var string + */ + private $_url; + + /** + * Title of the included URL (up to 50 characters) + * + * @var string + */ + private $_url_title; + + /** + * The Retry parameter is only used when the Priority is set to 2 (or emergency-priority), and specifies how often (in seconds) the Pushover servers will send the same notification to the user. In a situation where your user might be in a noisy environment or sleeping, retrying the notification (with sound and vibration) will help get his or her attention. This parameter must have a value of at least 30 seconds between retries. + * + * @var int + */ + private $_retry; + + /** + * The expire parameter is only used when the Priority is set to 2 (or emergency-priority), and specifies how many seconds your notification will continue to be retried for. If the notification has not been acknowledged in expire seconds, it will be marked as expired and will stop being sent to the user. This parameter must have a maximum value of at most 86400 seconds (24 hours). + * + * @var int + */ + private $_expire; + + /** + * The optional callback parameter may be supplied with a publicly-accessible URL that our servers will send a request to when the user has acknowledged your notification. + * + * @var string + */ + private $_callback; + + /** + * The sound parameter. Get an up-to-date sound list from https://api.pushover.net/1/sounds.json?token= + * + * @var int + */ + private $_sound; + + /** + * Default constructor + */ + public function __construct () { + } + + /** + * Set API token + * + * @param string $token Your app API key. + * + * @return void + */ + public function setToken ($token) { + $this->_token = (string)$token; + } + + /** + * Get API token + * + * @return string + */ + public function getToken () { + return $this->_token; + } + + /** + * Set API user + * + * @param string $user The user's API key. + * + * @return void + */ + public function setUser ($user) { + $this->_user = (string)$user; + } + + /** + * Get API user + * + * @return string + */ + public function getUser () { + return $this->_user; + } + + /** + * Set message title + * + * @param string $title Title of push notification. + * + * @return void + */ + public function setTitle ($title) { + $this->_title = (string)$title; + } + + /** + * Get message title + * + * @return string + */ + public function getTitle () { + return $this->_title; + } + + /** + * Set Retry Time + * + * @param int $retry The retry time (in seconds). Must have a value of at least 30 seconds. + */ + public function setRetry ($retry) { + $this->_retry = (int)$retry; + } + + /** + * Get Retry Time + * + * @return int + */ + public function getRetry() { + return $this->_retry; + } + + /** + * Set Expire Time + * + * @param int $expire The expiry time (in seconds). Must have a maximum value of at most, 86400 seconds. + */ + public function setExpire ($expire) { + $this->_expire = (int)$expire; + } + + /** + * Get Expire Time + * + * @return string + */ + public function getExpire () { + return $this->_expire; + } + + /** + * Set Callback URL + * + * @param string $callback a publically-accessible URL that Pushover sends a request to when the user has acknowledged your notification. + */ + public function setCallback ($callback) { + $this->_callback = $callback; + } + + /** + * Get Callback URL + * + * @return int + */ + public function getCallback() { + return $this->_callback; + } + + /** + * Set message + * + * @param string $msg Message of push notification. + * + * @return void + */ + public function setMessage ($msg) { + $this->_message = (string)$msg; + } + + /** + * Get message + * + * @return string + */ + public function getMessage () { + return $this->_message; + } + + /** + * Set device + * + * @param string $device Leave this empty if you want to send to all user's devices. This can be user specific! + * + * @return void + */ + public function setDevice ($device) { + $this->_device = (string)$device; + } + + /** + * Get device + * + * @return string + */ + public function getDevice () { + return $this->_device; + } + + /** + * Set timestamp + * + * Messages are stored on the Pushover servers with a timestamp of when they were initially received through the API. This timestamp is sent to and shown on client devices, and messages are listed in order of these timestamps. In most cases, this default timestamp is acceptable. This is not for scheduling! + * + * @param int $time dispaly time on device + * + * @return void + */ + public function setTimestamp ($time) { + $this->_timestamp = (int)$time; + } + + /** + * Get timestamp + * + * @return int + */ + public function getTimestamp () { + return $this->_timestamp; + } + + /** + * Set priority (-1, 0 or 1) + * + * -1 Low priority notifications. + * 0 Default. + * 1 triggers a high-priority alert that always generates sound and vibration. + * 2 triggers the same high-priority alert that #1 does; but is repeated until the notification is acknowledged by the user. + * + * @param int $priority priority level. + * + * @return void + */ + public function setPriority ($priority) { + $this->_priority = (int)$priority; + } + + /** + * Get priority + * + * @return int + */ + public function getPriority () { + return $this->_priority; + } + + /** + * Set url + * + * @param string $url Add an url to your notification. + * + * @return void + */ + public function setUrl ($url) { + $this->_url = (string)$url; + } + + /** + * Get url + * + * @return string + */ + public function getUrl () { + return $this->_url; + } + + /** + * Set url title + * + * @param string $url_title A title if you want to show a text instead of the actual url. + * + * @return void + */ + public function setUrlTitle ($url_title) { + $this->_url_title = (string)$url_title; + } + + /** + * Get url title + * + * @return string + */ + public function getUrlTitle () { + return $this->_url_title; + } + + /** + * Set debug mode + * + * @param bool $debug Enable this to receive detailed input and output info. + * + * @return void + */ + public function setDebug ($debug) { + $this->_debug = (boolean)$debug; + } + + /** + * Get debug mode + * + * @return bool + */ + public function getDebug () { + return $this->_debug; + } + + /** + * Set sound + * + * @param string $sound If no sound parameter is specified, the user's default tone will play. If the user has not chosen a custom sound, the standard Pushover sound will play. + * + * @return void + */ + public function setSound ($sound) { + $this->_sound = (string)$sound; + } + + /** + * Get sound + * + * @return string + */ + public function getSound () { + return $this->_sound; + } + + /** + * Send message to Pushover API + * + * @return bool + */ + public function send() { + if(!Empty($this->_token) && !Empty($this->_user) && !Empty($this->_message)) { + if(!isset($this->_timestamp)) $this->setTimestamp(time()); + + $c = curl_init(); + curl_setopt($c, CURLOPT_URL, self::API_URL); + curl_setopt($c, CURLOPT_HEADER, false); + /* + if possible, set CURLOPT_SSL_VERIFYPEER to true.. + - http://www.tehuber.com/phps/cabundlegen.phps + */ + curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($c, CURLOPT_RETURNTRANSFER, true); + curl_setopt($c, CURLOPT_POSTFIELDS, array( + 'token' => $this->getToken(), + 'user' => $this->getUser(), + 'title' => $this->getTitle(), + 'message' => $this->getMessage(), + 'device' => $this->getDevice(), + 'priority' => $this->getPriority(), + 'timestamp' => $this->getTimestamp(), + 'expire' => $this->getExpire(), + 'retry' => $this->getRetry(), + 'callback' => $this->getCallback(), + 'url' => $this->getUrl(), + 'sound' => $this->getSound(), + 'url_title' => $this->getUrlTitle() + )); + $response = curl_exec($c); + $xml = simplexml_load_string($response); + + if($this->getDebug()) { + return array('output' => $xml, 'input' => $this); + } + else { + return ($xml->status == 1) ? true : false; + } + } + } +} +?> \ No newline at end of file