diff --git a/composer.json b/composer.json
index a1e5c1803..885fe4db7 100755
--- a/composer.json
+++ b/composer.json
@@ -15,7 +15,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 02a84d22c..d2fde786f 100755
--- a/src/includes/functions.inc.php
+++ b/src/includes/functions.inc.php
@@ -491,6 +491,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 8c3eb986a..a9b537da5 100755
--- a/src/lang/en_US.lang.php
+++ b/src/lang/en_US.lang.php
@@ -88,6 +88,11 @@
'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 @@
'email' => 'Email',
'sms' => 'SMS',
'pushover' => 'Pushover',
+ 'pushbullet' => 'Pushbullet',
'no_logs' => 'No logs',
),
'servers' => array(
@@ -147,6 +153,7 @@
'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\'?',
@@ -175,6 +182,7 @@
'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.',
@@ -228,7 +236,11 @@
'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: '.
@@ -247,13 +259,16 @@
'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',
'settings_proxy' => 'Proxy settings',
@@ -268,6 +283,7 @@
'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',
@@ -280,6 +296,8 @@
'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',
@@ -291,11 +309,15 @@
'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 2fcaad1f0..f733c60da 100644
--- a/src/psm/Module/Config/Controller/ConfigController.php
+++ b/src/psm/Module/Config/Controller/ConfigController.php
@@ -41,10 +41,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',
);
@@ -201,6 +203,8 @@ protected function executeSave() {
$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');
@@ -292,6 +296,7 @@ protected function getLabels() {
'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'),
@@ -346,6 +351,8 @@ protected function getLabels() {
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'),
@@ -356,6 +363,7 @@ protected function getLabels() {
'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_alert_proxy' => psm_get_lang('config', 'alert_proxy'),
'label_alert_proxy_url' => psm_get_lang('config', 'alert_proxy_url'),
'label_auto_refresh' => psm_get_lang('config', 'auto_refresh'),
diff --git a/src/psm/Module/Server/Controller/AbstractServerController.php b/src/psm/Module/Server/Controller/AbstractServerController.php
index 79069e9cf..510e6f6fb 100644
--- a/src/psm/Module/Server/Controller/AbstractServerController.php
+++ b/src/psm/Module/Server/Controller/AbstractServerController.php
@@ -73,6 +73,7 @@ public function getServers($server_id = null) {
`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 ec1d3a36c..fd2f62af7 100644
--- a/src/psm/Module/Server/Controller/LogController.php
+++ b/src/psm/Module/Server/Controller/LogController.php
@@ -49,6 +49,7 @@ protected function executeIndex() {
'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 @@ protected function executeIndex() {
'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 748f54340..87ba3746a 100644
--- a/src/psm/Module/Server/Controller/ServerController.php
+++ b/src/psm/Module/Server/Controller/ServerController.php
@@ -92,6 +92,7 @@ protected function executeIndex() {
'email' => 'icon-envelope',
'sms' => 'icon-mobile',
'pushover' => 'icon-pushover',
+ 'pushbullet' => 'icon-pushbullet'
);
$servers = $this->getServers();
@@ -206,10 +207,11 @@ protected function executeEdit() {
'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 @@ protected function executeSave() {
'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') {
@@ -472,6 +475,7 @@ protected function getLabels() {
'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 f7165104e..0f3939494 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 @@ protected function executeIndex() {
'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 @@ protected function executeIndex() {
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 @@ protected function executeSave() {
}
$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 e7d093f2a..4fd06dacc 100644
--- a/src/psm/Module/User/Controller/UserController.php
+++ b/src/psm/Module/User/Controller/UserController.php
@@ -89,7 +89,7 @@ protected function executeIndex() {
$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 @@ protected function executeIndex() {
*/
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 @@ protected function executeSave() {
}
$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 @@ protected function getLabels() {
'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 @@ protected function getUserServers($user_id) {
}
return $result;
}
+
}
diff --git a/src/psm/Util/Install/Installer.php b/src/psm/Util/Install/Installer.php
index eacbb4105..b5f599dc8 100644
--- a/src/psm/Util/Install/Installer.php
+++ b/src/psm/Util/Install/Installer.php
@@ -294,6 +294,9 @@ public function upgrade($version_from, $version_to) {
if(version_compare($version_from, '3.2.0', '<')) {
$this->upgrade320();
}
+ if(version_compare($version_from, '3.3.0', '<')) {
+ $this->upgrade330();
+ }
psm_update_conf('version', $version_to);
}
@@ -478,4 +481,30 @@ protected function upgrade320() {
// 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 0edfde983..205176c64 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 @@ function __construct(Database $db) {
$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 @@ public function notify($server_id, $status_old, $status_new) {
$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 @@ public function notify($server_id, $status_old, $status_new) {
$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 @@ protected function notifyByPushover($users) {
}
}
+ /**
+ * 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 @@ protected function notifyByTxtMsg($users) {
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 076890d86..855fa2d30 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 %}