Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pushbullet service =) #355

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -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": [
Expand Down
11 changes: 11 additions & 0 deletions src/includes/functions.inc.php
Expand Up @@ -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.
*
Expand Down
24 changes: 23 additions & 1 deletion src/lang/en_US.lang.php
Expand Up @@ -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 <a href="https://www.pushbullet.com/">their website</a> 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.',
Expand All @@ -112,6 +117,7 @@
'email' => 'Email',
'sms' => 'SMS',
'pushover' => 'Pushover',
'pushbullet' => 'Pushbullet',
'no_logs' => 'No logs',
),
'servers' => array(
Expand Down Expand Up @@ -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\'?',
Expand Down Expand Up @@ -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.',
Expand Down Expand Up @@ -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 <a href="%1$s" target="_blank">register an App</a> 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 <a href="https://www.pushbullet.com/">their website</a> for more info.',
'pushbullet_api_token' => 'Pushbullet App API Token',
'pushbullet_api_token_description' => 'Before you can use Pushbullet, you need to <a href="%1$s" target="_blank">create token</a> at their website and enter the App API Token here.',
'alert_type' => 'Select when you\'d like to be notified.',
'alert_type_description' => '<b>Status change:</b> '.
'You will receive a notifcation when a server has a change in status. So from online -> offline or offline -> online.<br/>'.
'<br /><b>Offline:</b> '.
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -291,11 +309,15 @@
'off_email_body' => "Failed to connect to the following server:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Error: %ERROR%<br/>Date: %DATE%",
'off_pushover_title' => 'Server \'%LABEL%\' is DOWN',
'off_pushover_message' => "Failed to connect to the following server:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Error: %ERROR%<br/>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:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Date: %DATE%",
'on_pushover_title' => 'Server \'%LABEL%\' is RUNNING',
'on_pushover_message' => 'Server \'%LABEL%\' is running again:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>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%',
Expand Down
8 changes: 8 additions & 0 deletions src/psm/Module/Config/Controller/ConfigController.php
Expand Up @@ -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',
);

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand All @@ -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'),
Expand Down
Expand Up @@ -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`,
Expand Down
3 changes: 2 additions & 1 deletion src/psm/Module/Server/Controller/LogController.php
Expand Up @@ -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'),
Expand All @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/psm/Module/Server/Controller/ServerController.php
Expand Up @@ -92,6 +92,7 @@ protected function executeIndex() {
'email' => 'icon-envelope',
'sms' => 'icon-mobile',
'pushover' => 'icon-pushover',
'pushbullet' => 'icon-pushbullet'
);

$servers = $this->getServers();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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'),
Expand Down
32 changes: 31 additions & 1 deletion src/psm/Module/User/Controller/ProfileController.php
Expand Up @@ -28,14 +28,15 @@
namespace psm\Module\User\Controller;
use psm\Module\AbstractController;
use psm\Service\Database;
use Pushbullet\Pushbullet;

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);
Expand Down Expand Up @@ -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',
Expand All @@ -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);
}

Expand Down Expand Up @@ -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'));
}
}
}
12 changes: 9 additions & 3 deletions src/psm/Module/User/Controller/UserController.php
Expand Up @@ -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')
);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -362,4 +367,5 @@ protected function getUserServers($user_id) {
}
return $result;
}

}
29 changes: 29 additions & 0 deletions src/psm/Util/Install/Installer.php
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

}
}