Add Pushbullet service =)
parent
68c087025d
commit
b78bd838a6
|
@ -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": [
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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 <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.',
|
||||
|
@ -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,6 +230,10 @@ $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 <a href="%1$s" target="_blank">register an App</a> at their website and enter the App API Token here.',
|
||||
'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/>'.
|
||||
|
@ -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:<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%',
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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`,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<li class="{{ email_active }}"><a href="#config-email" data-toggle="tab">{{ label_tab_email }}</a></li>
|
||||
<li class="{{ sms_active }}"><a href="#config-sms" data-toggle="tab">{{ label_tab_sms }}</a></li>
|
||||
<li class="{{ pushover_active }}"><a href="#config-pushover" data-toggle="tab">{{ label_tab_pushover }}</a></li>
|
||||
<li class="{{ pushbullet_active }}"><a href="#config-pushbullet" data-toggle="tab">{{ label_tab_pushbullet }}</a></li>
|
||||
</ul>
|
||||
<div class="tab-content well">
|
||||
<div id="config-general" class="tab-pane {{ general_active }}">
|
||||
|
@ -238,6 +239,25 @@
|
|||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div id="config-pushbullet" class="tab-pane {{ pushbullet_active }}">
|
||||
<fieldset>
|
||||
<legend>{{ label_settings_pushbullet }}</legend>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox" for="pushbullet_status"><input type="checkbox" id="pushbullet_status" name="pushbullet_status[]" {{ pushbullet_status_checked|raw }} /> {{ label_pushbullet_status }}</label>
|
||||
<p class="help-block">{{ label_pushbullet_description|raw }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox"><input type="checkbox" id="log_pushbullet" name="log_pushbullet[]" {{ log_pushbullet_checked|raw }} /> {{ label_log_pushbullet }}</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button class="btn btn-success" type="submit" name="pushbullet_submit">{{ label_save }}</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
{{ macro.csrf_input() }}
|
||||
</form>
|
|
@ -23,7 +23,7 @@
|
|||
<td class="nowrap visible-desktop"><div class="table-cell-title">{{ server.type }}</div></td>
|
||||
<td class="nowrap hidden-phone"><div class="table-cell-title">{{ server.rtime }} s</div></td>
|
||||
<td class="nowrap hidden-phone"><div class="table-cell-title">{{ server.last_online }}</div></td>
|
||||
<td class="tight hidden-phone"><div class="table-cell-title"><i class="{{ server.active_icon }}" title="{{ server.active_title }}"></i> <i class="{{ server.email_icon }}" title="{{ label_email }}"></i> <i class="{{ server.sms_icon }}" title="{{ label_sms }}"></i> <i class="{{ server.pushover_icon }}" title="Pushover"></i></div></td>
|
||||
<td class="tight hidden-phone"><div class="table-cell-title"><i class="{{ server.active_icon }}" title="{{ server.active_title }}"></i> <i class="{{ server.email_icon }}" title="{{ label_email }}"></i> <i class="{{ server.sms_icon }}" title="{{ label_sms }}"></i> <i class="{{ server.pushover_icon }}" title="Pushover"></i> <i class="{{ server.pushbullet_icon }}" title="Pusbullet"></i></div></td>
|
||||
<td class="tight hidden-phone">
|
||||
<div class="table-cell-title">
|
||||
<a class="btn btn-small" href="{{ server.url_view|raw }}"><i class="icon-chart"></i></a>
|
||||
|
|
|
@ -137,6 +137,17 @@
|
|||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group {{ control_class_pushbullet }}">
|
||||
<label class="control-label" for="pushbullet">{{ label_pushbullet }}
|
||||
{% if warning_pushbullet %} <p class="help-inline"><i class="icon-warning-sign" data-toggle="tooltip" title="{{ label_warning_pushbullet }}"></i></p> {% endif %}
|
||||
</label>
|
||||
<div class="controls">
|
||||
<select id="pushbullet" name="pushbullet">
|
||||
<option value="yes" {{ edit_pushbullet_selected_yes|raw }}>{{ label_yes }}</option>
|
||||
<option value="no" {{ edit_pushbullet_selected_no|raw }}>{{ label_no }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
|
|
|
@ -63,6 +63,33 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span6">
|
||||
<div class="control-group">
|
||||
<label class="control-label">{{ label_pushbullet }}</label>
|
||||
<div class="controls">{{ label_pushbullet_description|raw }} </div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="pushbullet_key">{{ label_pushbullet_key }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" id="pushbullet_key" name="pushbullet_key" value="{{ pushbullet_key }}" maxlength="255" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="pushbullet_device">{{ label_pushbullet_device }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" id="pushbullet_device" name="pushbullet_device" value="{{ pushbullet_device }}" maxlength="255" data-toggle="tooltip" title="{{ label_pushbullet_device_description }}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<button class="btn btn-primary show-modal" data-modal-id="testPushbullet">{{ label_test }}</button>
|
||||
<input type="hidden" name="test_pushbullet" value="0" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button class="btn btn-success" type="submit" name="pushbullet_submit">{{ label_save }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="form-actions">
|
||||
|
|
|
@ -66,6 +66,22 @@
|
|||
<input type="text" id="pushover_device" name="pushover_device" value="{{ edit_value_pushover_device }}" maxlength="255" data-toggle="tooltip" title="{{ label_pushover_device_description }}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">{{ label_pushbullet }}</label>
|
||||
<div class="controls">{{ label_pushbullet_description|raw }} </div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="pushbullet_key">{{ label_pushbullet_key }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" id="pushbullet_key" name="pushbullet_key" value="{{ edit_value_pushbullet_key }}" maxlength="255" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="pushbullet_device">{{ label_pushbullet_device }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" id="pushbullet_device" name="pushbullet_device" value="{{ edit_value_pushbullet_device }}" maxlength="255" data-toggle="tooltip" title="{{ label_pushbullet_device_description }}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="server_id">{{ label_servers }}</label>
|
||||
<div class="controls">
|
||||
|
|
|
@ -672,3 +672,6 @@ legend{
|
|||
.icon-pushover {
|
||||
background-position: -72px -168px;
|
||||
}
|
||||
.icon-pushbullet{
|
||||
background-position: -240px -120px;
|
||||
}
|
Loading…
Reference in New Issue