From b78bd838a67019d281731759d948601a4a3fb30e Mon Sep 17 00:00:00 2001 From: Valentin Deville Date: Tue, 13 Sep 2016 01:07:42 +0200 Subject: [PATCH] Add Pushbullet service =) --- composer.json | 3 +- src/includes/functions.inc.php | 11 ++ src/lang/en_US.lang.php | 24 ++- .../Config/Controller/ConfigController.php | 8 + .../Controller/AbstractServerController.php | 1 + .../Server/Controller/LogController.php | 3 +- .../Server/Controller/ServerController.php | 6 +- .../User/Controller/ProfileController.php | 32 +++- .../Module/User/Controller/UserController.php | 12 +- src/psm/Util/Install/Installer.php | 29 +++ .../Util/Server/Updater/StatusNotifier.php | 63 ++++++- .../default/module/config/config.tpl.html | 178 ++++++++++-------- .../module/server/server/list.tpl.html | 2 +- .../module/server/server/update.tpl.html | 11 ++ .../default/module/user/profile.tpl.html | 27 +++ .../default/module/user/user/update.tpl.html | 16 ++ static/css/style.css | 3 + 17 files changed, 339 insertions(+), 90 deletions(-) diff --git a/composer.json b/composer.json index b307dc44..4243789d 100755 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "php-pushover/php-pushover": "dev-master", "twig/twig": "1.*", "paragonie/random_compat" : "1.1.6", - "indigophp/hash-compat" : "1.1.0" + "indigophp/hash-compat" : "1.1.0", + "ivkos/pushbullet": "3.*" }, "autoload": { "files": [ diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index ec725f67..08d0c512 100755 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -481,6 +481,17 @@ function psm_build_pushover() { return $pushover; } +/** + * Prepare a new Pushbullet util. + * + * @return \Pushbullet\Pushbullet + */ +function psm_build_pushbullet($apiKey) { + $pushbullet = new \Pushbullet\Pushbullet($apiKey); + + return $pushbullet; +} + /** * Prepare a new SMS util. * diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 07c1d5d1..2a5cd6e9 100755 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -88,6 +88,11 @@ $sm_lang = array( '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.', + 'pushbullet' => 'Pushbullet', + 'pushbullet_description' => 'Pushbullet is a service that makes it easy to get real-time notifications. See their website for more info.', + 'pushbullet_key' => 'Pushbullet Key', + 'pushbullet_device' => 'Pushbullet Device', + 'pushbullet_device_description' => 'Device name to send the message to. Leave empty to send it to all devices.', 'delete_title' => 'Delete User', 'delete_message' => 'Are you sure you want to delete user \'%1\'?', 'deleted' => 'User deleted.', @@ -112,6 +117,7 @@ $sm_lang = array( 'email' => 'Email', 'sms' => 'SMS', 'pushover' => 'Pushover', + 'pushbullet' => 'Pushbullet', 'no_logs' => 'No logs', ), 'servers' => array( @@ -146,6 +152,7 @@ $sm_lang = array( 'sms' => 'SMS', 'send_sms' => 'Send SMS', 'pushover' => 'Pushover', + 'pushbullet' => 'Pushbullet', 'users' => 'Users', 'delete_title' => 'Delete server', 'delete_message' => 'Are you sure you want to delete server \'%1\'?', @@ -174,6 +181,7 @@ $sm_lang = array( 'warning_notifications_disabled_sms' => 'SMS notifications are disabled.', 'warning_notifications_disabled_email' => 'Email notifications are disabled.', 'warning_notifications_disabled_pushover' => 'Pushover notifications are disabled.', + 'warning_notifications_disabled_pushbullet' => 'Pushbullet 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.', @@ -222,7 +230,11 @@ $sm_lang = array( '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 register an App at their website and enter the App API Token here.', - 'alert_type' => 'Select when you\'d like to be notified.', + 'pushbullet_status' => 'Allow sending Pushbullet messages', + 'pushbullet_description' => 'Pushbullet is a service that makes it easy to get real-time notifications. See their website for more info.', + 'pushbullet_api_token' => 'Pushbullet App API Token', + 'pushbullet_api_token_description' => 'Before you can use Pushbullet, you need to create token at their website and enter the App API Token here.', + '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.
'. '
Offline: '. @@ -239,13 +251,16 @@ $sm_lang = array( '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', + 'log_pushbullet' => 'Log pushbullet messages sent by the script', 'updated' => 'The configuration has been updated.', 'tab_email' => 'Email', 'tab_sms' => 'SMS', 'tab_pushover' => 'Pushover', + 'tab_pushbullet' => 'Pushbullet', 'settings_email' => 'Email settings', 'settings_sms' => 'Text message settings', 'settings_pushover' => 'Pushover settings', + 'settings_pushbullet' => 'Pushbullet settings', 'settings_notification' => 'Notification settings', 'settings_log' => 'Log settings', 'auto_refresh' => 'Auto-refresh', @@ -259,6 +274,7 @@ $sm_lang = array( '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_pushbullet' => 'A Pushbullet notification will be sent to the user key/device specified in your user profile.', 'send' => 'Send', 'test_subject' => 'Test', 'test_message' => 'Test message', @@ -271,6 +287,8 @@ $sm_lang = array( '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_nokey' => 'Unable to send test notification: no Pushover key found in your profile.', + 'pushbullet_sent' => 'Pushbullet notification sent', + 'pushbullet_error' => 'An error has occurred while sending the Pushbullet notification: %s', '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_days' => 'days', @@ -282,11 +300,15 @@ $sm_lang = array( 'off_email_body' => "Failed to connect to the following server:

Server: %LABEL%
IP: %IP%
Port: %PORT%
Error: %ERROR%
Date: %DATE%", 'off_pushover_title' => 'Server \'%LABEL%\' is DOWN', 'off_pushover_message' => "Failed to connect to the following server:

Server: %LABEL%
IP: %IP%
Port: %PORT%
Error: %ERROR%
Date: %DATE%", + 'off_pushbullet_title' => 'Server \'%LABEL%\' is DOWN', + 'off_pushbullet_message' => "Failed to connect to the following server:".PHP_EOL.PHP_EOL."Server: %LABEL%".PHP_EOL."IP/Hostname: %IP%".PHP_EOL."Port: %PORT%".PHP_EOL."Error: %ERROR%".PHP_EOL."Date: %DATE%", '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' => 'Server \'%LABEL%\' is RUNNING', 'on_pushover_message' => 'Server \'%LABEL%\' is running again:

Server: %LABEL%
IP: %IP%
Port: %PORT%
Date: %DATE%', + 'on_pushbullet_title' => 'Server \'%LABEL%\' is RUNNING', + 'on_pushbullet_message' => 'Server \'%LABEL%\' is running again:'.PHP_EOL.PHP_EOL.'Server: %LABEL%'.PHP_EOL.PHP_EOL.'IP/Hostname: %IP%'.PHP_EOL.'Port: %PORT%'.PHP_EOL.'Date: %DATE%', ), 'login' => array( 'welcome_usermenu' => 'Welcome, %user_name%', diff --git a/src/psm/Module/Config/Controller/ConfigController.php b/src/psm/Module/Config/Controller/ConfigController.php index d058de63..bdac4eb4 100644 --- a/src/psm/Module/Config/Controller/ConfigController.php +++ b/src/psm/Module/Config/Controller/ConfigController.php @@ -40,10 +40,12 @@ class ConfigController extends AbstractController { 'email_smtp', 'sms_status', 'pushover_status', + 'pushbullet_status', 'log_status', 'log_email', 'log_sms', 'log_pushover', + 'log_pushbullet', 'show_update', ); @@ -197,6 +199,8 @@ class ConfigController extends AbstractController { $this->default_tab = 'sms'; } elseif(isset($_POST['pushover_submit']) || !empty($_POST['test_pushover'])) { $this->default_tab = 'pushover'; + } elseif(isset($_POST['pushbullet_submit'])) { + $this->default_tab = 'pushbullet'; } } return $this->runAction('index'); @@ -288,6 +292,7 @@ class ConfigController extends AbstractController { '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_pushbullet' => psm_get_lang('config', 'tab_pushbullet'), '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'), @@ -336,6 +341,8 @@ class ConfigController extends AbstractController { psm_get_lang('config', 'pushover_api_token_description'), PSM_PUSHOVER_CLONE_URL ), + 'label_pushbullet_description' => psm_get_lang('config', 'pushbullet_description'), + 'label_pushbullet_status' => psm_get_lang('config', 'pushbullet_status'), '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'), @@ -346,6 +353,7 @@ class ConfigController extends AbstractController { '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_log_pushbullet' => 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.php b/src/psm/Module/Server/Controller/AbstractServerController.php index 79069e9c..510e6f6f 100644 --- a/src/psm/Module/Server/Controller/AbstractServerController.php +++ b/src/psm/Module/Server/Controller/AbstractServerController.php @@ -73,6 +73,7 @@ abstract class AbstractServerController extends AbstractController { `s`.`email`, `s`.`sms`, `s`.`pushover`, + `s`.`pushbullet`, `s`.`warning_threshold`, `s`.`warning_threshold_counter`, `s`.`timeout`, diff --git a/src/psm/Module/Server/Controller/LogController.php b/src/psm/Module/Server/Controller/LogController.php index ec1d3a36..fd2f62af 100644 --- a/src/psm/Module/Server/Controller/LogController.php +++ b/src/psm/Module/Server/Controller/LogController.php @@ -49,6 +49,7 @@ class LogController extends AbstractServerController { 'label_email' => psm_get_lang('log', 'email'), 'label_sms' => psm_get_lang('log', 'sms'), 'label_pushover' => psm_get_lang('log', 'pushover'), + 'label_pushbullet' => psm_get_lang('log', 'pushbullet'), 'label_title' => psm_get_lang('log', 'title'), 'label_server' => psm_get_lang('servers', 'server'), 'label_type' => psm_get_lang('log', 'type'), @@ -58,7 +59,7 @@ class LogController extends AbstractServerController { 'label_no_logs' => psm_get_lang('log', 'no_logs'), 'tabs' => array(), ); - $log_types = array('status', 'email', 'sms', 'pushover'); + $log_types = array('status', 'email', 'sms', 'pushover', 'pushbullet'); foreach($log_types as $key) { $records = $this->getEntries($key); diff --git a/src/psm/Module/Server/Controller/ServerController.php b/src/psm/Module/Server/Controller/ServerController.php index 0fd9a4d1..ff5fa795 100644 --- a/src/psm/Module/Server/Controller/ServerController.php +++ b/src/psm/Module/Server/Controller/ServerController.php @@ -92,6 +92,7 @@ class ServerController extends AbstractServerController { 'email' => 'icon-envelope', 'sms' => 'icon-mobile', 'pushover' => 'icon-pushover', + 'pushbullet' => 'icon-pushbullet' ); $servers = $this->getServers(); @@ -206,10 +207,11 @@ class ServerController extends AbstractServerController { 'edit_email_selected_' . $edit_server['email'] => 'selected="selected"', 'edit_sms_selected_' . $edit_server['sms'] => 'selected="selected"', 'edit_pushover_selected_' . $edit_server['pushover'] => 'selected="selected"', + 'edit_pushbullet_selected_' . $edit_server['pushbullet'] => 'selected="selected"', )); } - $notifications = array('email', 'sms', 'pushover'); + $notifications = array('email', 'sms', 'pushover', 'pushbullet'); foreach($notifications as $notification) { if(psm_get_conf($notification . '_status') == 0) { $tpl_data['warning_' . $notification] = true; @@ -268,6 +270,7 @@ class ServerController extends AbstractServerController { 'email' => in_array($_POST['email'], array('yes', 'no')) ? $_POST['email'] : 'no', 'sms' => in_array($_POST['sms'], array('yes', 'no')) ? $_POST['sms'] : 'no', 'pushover' => in_array($_POST['pushover'], array('yes', 'no')) ? $_POST['pushover'] : 'no', + 'pushbullet' => in_array($_POST['pushbullet'], array('yes', 'no')) ? $_POST['pushbullet'] : 'no', ); // make sure websites start with http:// if($clean['type'] == 'website' && substr($clean['ip'], 0, 4) != 'http') { @@ -457,6 +460,7 @@ class ServerController extends AbstractServerController { 'label_sms' => psm_get_lang('servers', 'sms'), 'label_send_sms' => psm_get_lang('servers', 'send_sms'), 'label_pushover' => psm_get_lang('servers', 'pushover'), + 'label_pushbullet' => psm_get_lang('servers', 'pushbullet'), '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'), diff --git a/src/psm/Module/User/Controller/ProfileController.php b/src/psm/Module/User/Controller/ProfileController.php index f7165104..0f393949 100644 --- a/src/psm/Module/User/Controller/ProfileController.php +++ b/src/psm/Module/User/Controller/ProfileController.php @@ -28,6 +28,7 @@ namespace psm\Module\User\Controller; use psm\Module\AbstractController; use psm\Service\Database; +use Pushbullet\Pushbullet; class ProfileController extends AbstractController { @@ -35,7 +36,7 @@ class ProfileController extends AbstractController { * Editable fields for the profile * @var array $profile_fields */ - protected $profile_fields = array('name', 'user_name', 'mobile', 'pushover_key', 'pushover_device', 'email'); + protected $profile_fields = array('name', 'user_name', 'mobile', 'pushover_key', 'pushover_device', 'email', 'pushbullet_key', 'pushbullet_device'); function __construct(Database $db, \Twig_Environment $twig) { parent::__construct($db, $twig); @@ -66,8 +67,14 @@ 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_pushbullet' => psm_get_lang('users', 'pushbullet'), + 'label_pushbullet_description' => psm_get_lang('users', 'pushbullet_description'), + 'label_pushbullet_key' => psm_get_lang('users', 'pushbullet_key'), + 'label_pushbullet_device' => psm_get_lang('users', 'pushbullet_device'), + 'label_pushbullet_device_description' => psm_get_lang('users', 'pushbullet_device_description'), 'label_email' => psm_get_lang('users', 'email'), 'label_save' => psm_get_lang('system', 'save'), + 'label_test' => psm_get_lang('config', 'test'), 'form_action' => psm_build_url(array( 'mod' => 'user_profile', 'action' => 'save', @@ -78,6 +85,14 @@ class ProfileController extends AbstractController { foreach($this->profile_fields as $field) { $tpl_data[$field] = (isset($user->$field)) ? $user->$field : ''; } + + + $modal = new \psm\Util\Module\Modal($this->twig, 'test' . ucfirst('pushbullet'), \psm\Util\Module\Modal::MODAL_TYPE_OKCANCEL); + $this->addModal($modal); + $modal->setTitle(psm_get_lang('servers', 'send_' . 'pushbullet')); + $modal->setMessage(psm_get_lang('config', 'test_' . 'pushbullet')); + $modal->setOKButtonLabel(psm_get_lang('config', 'send')); + return $this->twig->render('module/user/profile.tpl.html', $tpl_data); } @@ -133,6 +148,21 @@ class ProfileController extends AbstractController { } $this->addMessage(psm_get_lang('users', 'profile_updated'), 'success'); + if(!empty($_POST['test_pushbullet'])){ + $this->testPushbullet($clean['pushbullet_key'], $clean['pushbullet_device']); + } + return $this->executeIndex(); } + + + public function testPushbullet($apiKey, $device = null){ + $pb = new Pushbullet($apiKey); + if($device != null || $device != ''){ + $pb->device($device)->pushNote(psm_get_lang('config', 'test_subject'), psm_get_lang('config', 'test_pushbullet')); + } else{ + $test = psm_get_lang('test_subject'); + $pb->allDevices()->pushNote(psm_get_lang('config', 'test_subject'), psm_get_lang('config', 'test_pushbullet')); + } + } } \ No newline at end of file diff --git a/src/psm/Module/User/Controller/UserController.php b/src/psm/Module/User/Controller/UserController.php index e7d093f2..4fd06dac 100644 --- a/src/psm/Module/User/Controller/UserController.php +++ b/src/psm/Module/User/Controller/UserController.php @@ -89,7 +89,7 @@ class UserController extends AbstractController { $users = $this->db->select( PSM_DB_PREFIX.'users', null, - array('user_id', 'user_name', 'level', 'name', 'mobile', 'pushover_key', 'pushover_device', 'email'), + array('user_id', 'user_name', 'level', 'name', 'mobile', 'pushover_key', 'pushover_device', 'email', 'pushbullet_key', 'pushbullet_device'), null, array('name') ); @@ -133,7 +133,7 @@ class UserController extends AbstractController { */ protected function executeEdit() { $user_id = isset($_GET['id']) ? intval($_GET['id']) : 0; - $fields_prefill = array('name', 'user_name', 'mobile', 'pushover_key', 'pushover_device', 'email'); + $fields_prefill = array('name', 'user_name', 'mobile', 'pushover_key', 'pushover_device', 'email', 'pushbullet_key', 'pushbullet_device'); if($user_id == 0) { // insert mode @@ -215,7 +215,7 @@ class UserController extends AbstractController { } $user_id = (isset($_GET['id'])) ? intval($_GET['id']) : 0; - $fields = array('name', 'user_name', 'password', 'password_repeat', 'level', 'mobile', 'pushover_key', 'pushover_device', 'email'); + $fields = array('name', 'user_name', 'password', 'password_repeat', 'level', 'mobile', 'pushover_key', 'pushover_device', 'email', 'pushbullet_key', 'pushbullet_device'); $clean = array(); foreach($fields as $field) { if(isset($_POST[$field])) { @@ -333,6 +333,11 @@ class UserController 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_pushbullet' => psm_get_lang('users', 'pushbullet'), + 'label_pushbullet_description' => psm_get_lang('users', 'pushbullet_description'), + 'label_pushbullet_key' => psm_get_lang('users', 'pushbullet_key'), + 'label_pushbullet_device' => psm_get_lang('users', 'pushbullet_device'), + 'label_pushbullet_device_description' => psm_get_lang('users', 'pushbullet_device_description'), 'label_email' => psm_get_lang('users', 'email'), 'label_servers' => psm_get_lang('menu', 'server'), 'label_action' => psm_get_lang('system', 'action'), @@ -362,4 +367,5 @@ class UserController extends AbstractController { } return $result; } + } diff --git a/src/psm/Util/Install/Installer.php b/src/psm/Util/Install/Installer.php index 6c3ee490..79218e4d 100644 --- a/src/psm/Util/Install/Installer.php +++ b/src/psm/Util/Install/Installer.php @@ -290,6 +290,9 @@ class Installer { if(version_compare($version_from, '3.2.0', '<')) { $this->upgrade320(); } + if(version_compare($version_from, '3.3.0', '<')) { + $this->upgrade320(); + } psm_update_conf('version', $version_to); } @@ -469,4 +472,30 @@ class Installer { // Drop old user_id('s) column $this->execSQL("ALTER TABLE `" . PSM_DB_PREFIX . "log` DROP COLUMN `user_id`;"); } + + + /** + * Upgrade for v3.3.0 release ( ADD PUSHBULLET SERVICE, Valentin DEVILLE ) + */ + protected function upgrade330(){ + + $queries = array(); + + // ADD OPTION TO EACH SERVERS BY DEFAULT YES + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `pushbullet` ENUM('yes','no') NOT NULL DEFAULT 'yes' AFTER `pushover`;"; + + // ADD OPTION TO LOG + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "log` CHANGE `type` `type` ENUM('status','email','sms','pushover','pushbullet');"; + + // ADD OPTION TO CONFIG + $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` VALUES('pushbullet_status', 0);"; + $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` VALUES('log_pushbullet', 0);"; + + // ADD OPTION ON USER PROFILE + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "users` ADD `pushbullet_key` VARCHAR(255) NOT NULL DEFAULT '' AFTER `pushover_device`;"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "users` ADD `pushbullet_device` VARCHAR(255) NOT NULL DEFAULT '' AFTER `pushbullet_key`;"; + + $this->execSQL($queries); + + } } diff --git a/src/psm/Util/Server/Updater/StatusNotifier.php b/src/psm/Util/Server/Updater/StatusNotifier.php index 0edfde98..205176c6 100755 --- a/src/psm/Util/Server/Updater/StatusNotifier.php +++ b/src/psm/Util/Server/Updater/StatusNotifier.php @@ -60,6 +60,12 @@ class StatusNotifier { */ protected $send_pushover = false; + /** + * Send Pushbullet? + * @var boolean $send_pushbullet + */ + protected $send_pushbullet = false; + /** * Save log records? * @var boolean $save_log @@ -96,6 +102,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->send_pushbullet = psm_get_conf('pushbullet_status'); $this->save_logs = psm_get_conf('log_status'); } @@ -121,7 +128,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', 'pushover', + 'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'error', 'active', 'email', 'sms', 'pushover', 'pushbullet' )); if(empty($this->server)) { return false; @@ -188,6 +195,12 @@ class StatusNotifier { $this->notifyByPushover($users); } + // check if pushover is enabled for this server + if($this->send_pushbullet && $this->server['pushbullet'] == 'yes') { + // yay lets wake those nerds up! + $this->notifyByPusbullet($users); + } + return $notify; } @@ -278,6 +291,52 @@ class StatusNotifier { } } + /** + * This functions performs the pusubullet notifications + * + * @param array $users + * @return boolean + */ + protected function notifyByPusbullet($users) { + + // Remove users that have no pushbullet_key + foreach($users as $k => $user) { + if (trim($user['pushbullet_key']) == '') { + unset($users[$k]); + } + } + + // Validation + if (empty($users)) { + return; + } + + $title = psm_parse_msg($this->status_new, 'pushbullet_title', $this->server); + $message1 = psm_get_lang('system', 'title'); + $message2 = psm_parse_msg($this->status_new, 'pushbullet_message', $this->server); + $message = $message1 . " " . $message2; + + // Log + if(psm_get_conf('log_pushbullet')) { + $log_id = psm_add_log($this->server_id, 'pushbullet', $message); + } + + foreach($users as $user) { + // Log + if(!empty($log_id)) { + psm_add_log_user($log_id, $user['user_id']); + } + + $pushbullet = psm_build_pushbullet($user['pushbullet_key']); + + if($user['pushbullet_device'] != '') { + $pushbullet->device($user['pushbullet_device'])->pushNote($title, $message); + } else{ + $pushbullet->allDevices()->pushNote($title, $message); + } + } + } + /** * This functions performs the text message notifications * @@ -321,7 +380,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`, `u`.`pushover_key`, `u`.`pushover_device` + SELECT `u`.`user_id`, `u`.`name`,`u`.`email`, `u`.`mobile`, `u`.`pushover_key`, `u`.`pushover_device`, `u`.`pushbullet_key`, `u`.`pushbullet_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/default/module/config/config.tpl.html b/src/templates/default/module/config/config.tpl.html index 103c52a8..8e5c33b7 100644 --- a/src/templates/default/module/config/config.tpl.html +++ b/src/templates/default/module/config/config.tpl.html @@ -1,22 +1,23 @@ {% import 'main/macros.tpl.html' as macro %}
-
-
-
+
+
+
{{ label_general }}
@@ -41,8 +42,8 @@ title="{{ label_password_encrypt_key_note }}"/>
-
-
+
+
{{ label_settings_notification }}
@@ -55,38 +56,38 @@

{{ label_alert_type_description|raw }}

- -
+
+
{{ label_settings_log }}
-
- -
-
+
+ +
+
-  {{ label_log_retention_days }} +  {{ label_log_retention_days }}
- - - +
@@ -101,7 +102,7 @@
- +
@@ -118,7 +119,7 @@ - +
@@ -133,30 +134,30 @@
-
-
- - -
-
+
+
+ + +
+
- -
-
+
+
+
{{ label_settings_sms }}
- -
+ +
-
- -
-
+
+ +
+
@@ -167,12 +168,12 @@ - - - - - - + + + + + +
@@ -194,50 +195,69 @@ -
-
- - -
-
+
+
+ + +
+
- - -
-
+
+
+
+
{{ label_settings_pushover }}
- -

{{ label_pushover_description|raw }}

-
+ +

{{ label_pushover_description|raw }}

+
-
- -
-
+
+ +
+
-

+

-

{{ label_pushover_api_token_description|raw }}

+

{{ label_pushover_api_token_description|raw }}

+
+
+
+
+ +
-
-
- - -
-
- - - - {{ macro.csrf_input() }} + + +
+
+ {{ label_settings_pushbullet }} +
+
+ +

{{ label_pushbullet_description|raw }}

+
+
+
+
+ +
+
+
+ +
+
+
+ + {{ macro.csrf_input() }}
\ No newline at end of file diff --git a/src/templates/default/module/server/server/list.tpl.html b/src/templates/default/module/server/server/list.tpl.html index 08e64db3..1a7ca219 100644 --- a/src/templates/default/module/server/server/list.tpl.html +++ b/src/templates/default/module/server/server/list.tpl.html @@ -23,7 +23,7 @@
{{ server.type }}
{{ server.rtime }} s
{{ server.last_online }}
-
+
diff --git a/src/templates/default/module/server/server/update.tpl.html b/src/templates/default/module/server/server/update.tpl.html index 2378d21e..5a708885 100644 --- a/src/templates/default/module/server/server/update.tpl.html +++ b/src/templates/default/module/server/server/update.tpl.html @@ -137,6 +137,17 @@
+
+ +
+ +
+
diff --git a/src/templates/default/module/user/profile.tpl.html b/src/templates/default/module/user/profile.tpl.html index a5f390d5..7f1074e9 100644 --- a/src/templates/default/module/user/profile.tpl.html +++ b/src/templates/default/module/user/profile.tpl.html @@ -63,6 +63,33 @@ +
+
+ +
{{ label_pushbullet_description|raw }}
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ + +
+
+
+ +
+
diff --git a/src/templates/default/module/user/user/update.tpl.html b/src/templates/default/module/user/user/update.tpl.html index 7b4ef56d..35c54c84 100644 --- a/src/templates/default/module/user/user/update.tpl.html +++ b/src/templates/default/module/user/user/update.tpl.html @@ -66,6 +66,22 @@
+
+ +
{{ label_pushbullet_description|raw }}
+
+
+ +
+ +
+
+
+ +
+ +
+
diff --git a/static/css/style.css b/static/css/style.css index c306cb96..1d624dcf 100755 --- a/static/css/style.css +++ b/static/css/style.css @@ -671,4 +671,7 @@ legend{ .icon-pushover { background-position: -72px -168px; +} +.icon-pushbullet{ + background-position: -240px -120px; } \ No newline at end of file