Merge branch 'develop' of https://github.com/remmedia/phpservermon into remmedia-develop

Conflicts:
	src/lang/de_DE.lang.php
	src/lang/en_US.lang.php
	src/psm/Module/Server/Controller/ServerController.class.php
	src/templates/server/view.tpl.html
This commit is contained in:
Pepijn Over 2014-07-30 15:03:57 +02:00
commit 6b4668937d
20 changed files with 743 additions and 13 deletions

View File

@ -413,6 +413,19 @@ function psm_build_mail($from_name = null, $from_email = null) {
return $phpmailer;
}
/**
* Prepare a new Pushover util.
*
* @return \psm\Util\Pushover
*/
function psm_build_pushover() {
$pushover = new \psm\Util\Pushover();
$pushover->setToken(psm_get_conf('pushover_api_token'));
return $pushover;
}
/**
* Prepare a new SMS util.
*

View File

@ -81,6 +81,9 @@ $sm_lang = array(
'level_description' => '<b>Administrators</b> have full access: they can manage servers, users and edit the global configuration.<br/><b>Users</b> can only view and run the updater for the servers that have been assigned to them.',
'mobile' => 'Mobil',
'email' => 'Email',
'pushover' => 'Pushover',
'pushover_key' => 'Pushover Key',
'pushover_device' => 'Pushover Device',
'delete_title' => 'Delete User',
'delete_message' => 'Are you sure you want to delete user \'%1\'?',
'deleted' => 'User deleted.',
@ -104,6 +107,7 @@ $sm_lang = array(
'status' => 'Status',
'email' => 'Email',
'sms' => 'SMS',
'pushover' => 'Pushover',
'no_logs' => 'No logs',
),
'servers' => array(
@ -127,6 +131,7 @@ $sm_lang = array(
'send_email' => 'Email',
'sms' => 'SMS',
'send_sms' => 'SMS',
'pushover' => 'Pushover',
'users' => 'Users',
'delete_title' => 'Delete Server',
'delete_message' => 'Are you sure you want to delete server \'%1\'?',
@ -186,6 +191,8 @@ $sm_lang = array(
'sms_gateway_username' => 'Gateway Benutzername',
'sms_gateway_password' => 'Gateway Passwort',
'sms_from' => 'SMS Sendernummer',
'pushover_status' => 'Pushover Nachricht senden erlauben?',
'pushover_api_token' => 'Pushover App API Token',
'alert_type' => 'Wann m&ouml;chten Sie benachrichtig werden?<br/>',
'alert_type_description' => '<b>Status ge&auml;ndert:</b> '.
'... wenn sich der Status &auml;ndert<br/>'.
@ -203,13 +210,16 @@ $sm_lang = array(
'log_status_description' => 'Ist der Log Status auf TRUE (ein Hacken) gesetzt, wird jeder Status protokolliert.',
'log_email' => 'Email Log per Script senden?',
'log_sms' => 'SMS Log per Script senden?',
'log_pushover' => 'Pushover Log per Script senden?',
'updated' => 'Die Einstellungen wurden gespeichert.',
'nochanges' => 'The configuration didn\'t change.',
'tab_email' => 'Email',
'tab_sms' => 'SMS',
'tab_pushover' => 'Pushover',
'tab_log' => 'Log',
'settings_email' => 'Email',
'settings_sms' => 'SMS Nachricht',
'settings_pushover' => 'Pushover',
'settings_notification' => 'Benachrichtigung',
'settings_log' => 'Log',
'auto_refresh' => 'Auto-refresh',
@ -235,9 +245,17 @@ $sm_lang = array(
'off_sms' => 'Server \'%LABEL%\' ist Offline: ip=%IP%, port=%PORT%. Fehler=%ERROR%',
'off_email_subject' => 'Wichtig: Server \'%LABEL%\' ist Offline',
'off_email_body' => "Kann keine Verbindung zum Server aufbauen:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Fehler: %ERROR%<br/>Datum: %DATE%",
'off_pushover_title' => '\'%LABEL%\' Offline',
'off_pushover_message' => 'Server \'%LABEL%\'<br/>ist Offline<br/>IP: %IP%<br/>Port: %PORT%<br/>Fehler: %ERROR%',
'off_pushover_url_title' => 'SERVER MONITOR',
'off_pushover_url' => '%MONITORURL%',
'on_sms' => 'Server \'%LABEL%\' ist wieder Online: ip=%IP%, port=%PORT%',
'on_email_subject' => 'Wichtig: Server \'%LABEL%\' ist wieder Online',
'on_email_body' => "Server '%LABEL%' l&auml;uft wieder:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Datum: %DATE%",
'on_pushover_title' => '\'%LABEL%\' Online',
'on_pushover_message' => 'Server \'%LABEL%\'<br/>ist wieder Online<br/>IP: %IP%<br/>Port: %PORT%',
'on_pushover_url_title' => 'SERVER MONITOR',
'on_pushover_url' => '%MONITORURL%',
),
'login' => array(
'welcome_usermenu' => 'Welcome, %user_name%',

View File

@ -81,6 +81,9 @@ $sm_lang = array(
'level_description' => '<b>Administrators</b> have full access: they can manage servers, users and edit the global configuration.<br/><b>Users</b> can only view and run the updater for the servers that have been assigned to them.',
'mobile' => 'Mobile',
'email' => 'Email',
'pushover' => 'Pushover',
'pushover_key' => 'Pushover Key',
'pushover_device' => 'Pushover Device',
'delete_title' => 'Delete User',
'delete_message' => 'Are you sure you want to delete user \'%1\'?',
'deleted' => 'User deleted.',
@ -104,6 +107,7 @@ $sm_lang = array(
'status' => 'Status',
'email' => 'Email',
'sms' => 'SMS',
'pushover' => 'Pushover',
'no_logs' => 'No logs',
),
'servers' => array(
@ -127,6 +131,7 @@ $sm_lang = array(
'send_email' => 'Send Email',
'sms' => 'SMS',
'send_sms' => 'Send SMS',
'send_pushover' => 'Send Pushover',
'users' => 'Users',
'delete_title' => 'Delete server',
'delete_message' => 'Are you sure you want to delete server \'%1\'?',
@ -186,6 +191,8 @@ $sm_lang = array(
'sms_gateway_username' => 'Gateway username',
'sms_gateway_password' => 'Gateway password',
'sms_from' => 'Sender\'s phone number',
'pushover_status' => 'Allow sending pushover messages',
'pushover_api_token' => 'Pushover App API Token',
'alert_type' => 'Select when you\'d like to be notified.<br/>',
'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/>'.
@ -203,13 +210,16 @@ $sm_lang = array(
'log_status_description' => 'If log status is set to TRUE, the monitor will log the event whenever the Notification settings are passed.',
'log_email' => 'Log emails sent by the script',
'log_sms' => 'Log text messages sent by the script',
'log_pushover' => 'Log pushover messages sent by the script',
'updated' => 'The configuration has been updated.',
'nochanges' => 'The configuration didn\'t change.',
'tab_email' => 'Email',
'tab_sms' => 'SMS',
'tab_pushover' => 'Pushover',
'tab_log' => 'Log',
'settings_email' => 'Email settings',
'settings_sms' => 'Text message settings',
'settings_pushover' => 'Pushover settings',
'settings_notification' => 'Notification settings',
'settings_log' => 'Log settings',
'auto_refresh' => 'Auto-refresh',
@ -235,9 +245,17 @@ $sm_lang = array(
'off_sms' => 'Server \'%LABEL%\' is DOWN: ip=%IP%, port=%PORT%. Error=%ERROR%',
'off_email_subject' => 'IMPORTANT: Server \'%LABEL%\' is DOWN',
'off_email_body' => "Failed to connect to the following server:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Error: %ERROR%<br/>Date: %DATE%",
'off_pushover_title' => '\'%LABEL%\' Offline',
'off_pushover_message' => 'Server \'%LABEL%\'<br/>ist Offline<br/>IP: %IP%<br/>Port: %PORT%<br/>Fehler: %ERROR%',
'off_pushover_url_title' => 'SERVER MONITOR',
'off_pushover_url' => '%MONITORURL%',
'on_sms' => 'Server \'%LABEL%\' is RUNNING: ip=%IP%, port=%PORT%',
'on_email_subject' => 'IMPORTANT: Server \'%LABEL%\' is RUNNING',
'on_email_body' => "Server '%LABEL%' is running again:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Date: %DATE%",
'on_pushover_title' => '\'%LABEL%\' Online',
'on_pushover_message' => 'Server \'%LABEL%\'<br/>ist wieder Online<br/>IP: %IP%<br/>Port: %PORT%',
'on_pushover_url_title' => 'SERVER MONITOR',
'on_pushover_url' => '%MONITORURL%',
),
'login' => array(
'welcome_usermenu' => 'Welcome, %user_name%',

View File

@ -40,9 +40,11 @@ class ConfigController extends AbstractController {
'email_status',
'email_smtp',
'sms_status',
'pushover_status',
'log_status',
'log_email',
'log_sms',
'log_pushover',
'show_update',
);
@ -60,6 +62,7 @@ class ConfigController extends AbstractController {
'sms_gateway_username',
'sms_gateway_password',
'sms_from',
'pushover_api_token',
);
private $default_tab = 'general';
@ -249,9 +252,11 @@ class ConfigController extends AbstractController {
'subtitle' => psm_get_lang('menu', 'config'),
'label_tab_email' => psm_get_lang('config', 'tab_email'),
'label_tab_sms' => psm_get_lang('config', 'tab_sms'),
'label_tab_pushover' => psm_get_lang('config', 'tab_pushover'),
'label_tab_log' => psm_get_lang('config', 'tab_log'),
'label_settings_email' => psm_get_lang('config', 'settings_email'),
'label_settings_sms' => psm_get_lang('config', 'settings_sms'),
'label_settings_pushover' => psm_get_lang('config', 'settings_pushover'),
'label_settings_notification' => psm_get_lang('config', 'settings_notification'),
'label_settings_log' => psm_get_lang('config', 'settings_log'),
'label_general' => psm_get_lang('config', 'general'),
@ -279,6 +284,8 @@ class ConfigController extends AbstractController {
'label_sms_gateway_username' => psm_get_lang('config', 'sms_gateway_username'),
'label_sms_gateway_password' => psm_get_lang('config', 'sms_gateway_password'),
'label_sms_from' => psm_get_lang('config', 'sms_from'),
'label_pushover_status' => psm_get_lang('config', 'pushover_status'),
'label_pushover_api_token' => psm_get_lang('config', 'pushover_api_token'),
'label_alert_type' => psm_get_lang('config', 'alert_type'),
'label_alert_type_description' => psm_get_lang('config', 'alert_type_description'),
'label_alert_type_status' => psm_get_lang('config', 'alert_type_status'),
@ -288,6 +295,7 @@ class ConfigController extends AbstractController {
'label_log_status_description' => psm_get_lang('config', 'log_status_description'),
'label_log_email' => psm_get_lang('config', 'log_email'),
'label_log_sms' => psm_get_lang('config', 'log_sms'),
'label_log_pushover' => psm_get_lang('config', 'log_pushover'),
'label_auto_refresh' => psm_get_lang('config', 'auto_refresh'),
'label_auto_refresh_servers' => psm_get_lang('config', 'auto_refresh_servers'),
'label_seconds' => psm_get_lang('config', 'seconds'),

View File

@ -73,6 +73,7 @@ abstract class AbstractServerController extends AbstractController {
`s`.`active`,
`s`.`email`,
`s`.`sms`,
`s`.`pushover`,
`s`.`warning_threshold`,
`s`.`warning_threshold_counter`,
`s`.`timeout`
@ -101,6 +102,7 @@ abstract class AbstractServerController extends AbstractController {
$server['active'] = psm_get_lang('system', $server['active']);
$server['email'] = psm_get_lang('system', $server['email']);
$server['sms'] = psm_get_lang('system', $server['sms']);
$server['pushover'] = psm_get_lang('system', $server['pushover']);
$server['url_view'] = psm_build_url(array(
'mod' => 'server',
'action' => 'view',

View File

@ -50,6 +50,7 @@ class LogController extends AbstractServerController {
$entries['status'] = $this->getEntries('status');
$entries['email'] = $this->getEntries('email');
$entries['sms'] = $this->getEntries('sms');
$entries['pushover'] = $this->getEntries('pushover');
// get users
$users = $this->db->select(PSM_DB_PREFIX.'users', null, array('user_id','name'));
@ -156,6 +157,7 @@ class LogController extends AbstractServerController {
'label_status' => psm_get_lang('log', 'status'),
'label_email' => psm_get_lang('log', 'email'),
'label_sms' => psm_get_lang('log', 'sms'),
'label_pushover' => psm_get_lang('log', 'pushover'),
'label_title' => psm_get_lang('log', 'title'),
'label_server' => psm_get_lang('servers', 'server'),
'label_type' => psm_get_lang('log', 'type'),

View File

@ -209,6 +209,7 @@ class ServerController extends AbstractServerController {
'edit_active_selected_' . $edit_server['active'] => 'selected="selected"',
'edit_email_selected_' . $edit_server['email'] => 'selected="selected"',
'edit_sms_selected_' . $edit_server['sms'] => 'selected="selected"',
'edit_pushover_selected_' . $edit_server['pushover'] => 'selected="selected"',
));
}
@ -227,6 +228,7 @@ class ServerController extends AbstractServerController {
return $this->executeIndex();
}
$clean = array(
'label' => trim(strip_tags(psm_POST('label', ''))),
'ip' => trim(strip_tags(psm_POST('ip', ''))),
@ -410,6 +412,7 @@ class ServerController extends AbstractServerController {
'label_send_email' => psm_get_lang('servers', 'send_email'),
'label_sms' => psm_get_lang('servers', 'sms'),
'label_send_sms' => psm_get_lang('servers', 'send_sms'),
'label_send_pushover' => psm_get_lang('servers', 'send_pushover'),
'label_users' => psm_get_lang('servers', 'users'),
'label_warning_threshold' => psm_get_lang('servers', 'warning_threshold'),
'label_warning_threshold_description' => psm_get_lang('servers', 'warning_threshold_description'),
@ -444,4 +447,4 @@ class ServerController extends AbstractServerController {
}
return $result;
}
}
}

View File

@ -36,7 +36,7 @@ class ProfileController extends AbstractController {
* Editable fields for the profile
* @var array $profile_fields
*/
protected $profile_fields = array('name', 'user_name', 'mobile', 'email');
protected $profile_fields = array('name', 'user_name', 'mobile', 'pushover_key', 'pushover_device', 'email');
function __construct(Database $db, Template $tpl) {
parent::__construct($db, $tpl);
@ -132,6 +132,8 @@ class ProfileController extends AbstractController {
'label_password_repeat' => psm_get_lang('users', 'password_repeat'),
'label_level' => psm_get_lang('users', 'level'),
'label_mobile' => psm_get_lang('users', 'mobile'),
'label_pushover_key' => psm_get_lang('users', 'pushover_key'),
'label_pushover_device' => psm_get_lang('users', 'pushover_device'),
'label_email' => psm_get_lang('users', 'email'),
'label_save' => psm_get_lang('system', 'save'),
)
@ -139,4 +141,4 @@ class ProfileController extends AbstractController {
return parent::createHTMLLabels();
}
}
}

View File

@ -94,7 +94,7 @@ class UserController extends AbstractController {
$users = $this->db->select(
PSM_DB_PREFIX.'users',
null,
array('user_id', 'user_name', 'level', 'name', 'mobile', 'email'),
array('user_id', 'user_name', 'level', 'name', 'mobile', 'pushover_key', 'pushover_device', 'email'),
null,
array('name')
);
@ -121,7 +121,7 @@ class UserController extends AbstractController {
protected function executeEdit() {
$this->setTemplateId('user_update', 'user/user.tpl.html');
$user_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$fields_prefill = array('name', 'user_name', 'mobile', 'email');
$fields_prefill = array('name', 'user_name', 'mobile', 'pushover_key', 'pushover_device', 'email');
if($user_id == 0) {
// insert mode
@ -196,7 +196,7 @@ class UserController extends AbstractController {
}
$user_id = (isset($_GET['id'])) ? intval($_GET['id']) : 0;
$fields = array('name', 'user_name', 'password', 'password_repeat', 'level', 'mobile', 'email');
$fields = array('name', 'user_name', 'password', 'password_repeat', 'level', 'mobile', 'pushover_key', 'pushover_device', 'email');
$clean = array();
foreach($fields as $field) {
if(isset($_POST[$field])) {
@ -300,6 +300,9 @@ class UserController extends AbstractController {
'label_level_20' => psm_get_lang('users', 'level_20'),
'label_level_description' => psm_get_lang('users', 'level_description'),
'label_mobile' => psm_get_lang('users', 'mobile'),
'label_pushover' => psm_get_lang('users', 'pushover'),
'label_pushover_key' => psm_get_lang('users', 'pushover_key'),
'label_pushover_device' => psm_get_lang('users', 'pushover_device'),
'label_email' => psm_get_lang('users', 'email'),
'label_servers' => psm_get_lang('menu', 'server'),
'label_action' => psm_get_lang('system', 'action'),

View File

@ -126,7 +126,7 @@ class Installer {
$this->log('Populating database...');
$queries = array();
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "servers` (`ip`, `port`, `label`, `type`, `pattern`, `status`, `error`, `rtime`, `last_online`, `last_check`, `active`, `email`, `sms`) VALUES ('http://sourceforge.net/index.php', 80, 'SourceForge', 'website', '', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes'), ('smtp.gmail.com', 465, 'Gmail SMTP', 'service', '', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes')";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "servers` (`ip`, `port`, `label`, `type`, `pattern`, `status`, `error`, `rtime`, `last_online`, `last_check`, `active`, `email`, `sms`, `pushover`) VALUES ('http://sourceforge.net/index.php', 80, 'SourceForge', 'website', '', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes'), ('smtp.gmail.com', 465, 'Gmail SMTP', 'service', '', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes', 'yes')";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "users_servers` (`user_id`,`server_id`) VALUES (1, 1), (1, 2);";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE
('language', 'en_US'),
@ -143,10 +143,13 @@ class Installer {
('sms_gateway_username', 'username'),
('sms_gateway_password', 'password'),
('sms_from', '1234567890'),
('pushover_status', '1'),
('pushover_api_token', ''),
('alert_type', 'status'),
('log_status', '1'),
('log_email', '1'),
('log_sms', '1'),
('log_pushover', '1'),
('version', '" . PSM_VERSION . "'),
('version_update_check', '" . PSM_VERSION . "'),
('auto_refresh_servers', '0'),
@ -177,6 +180,8 @@ class Installer {
`level` tinyint(2) unsigned NOT NULL DEFAULT '20',
`name` varchar(255) NOT NULL,
`mobile` varchar(15) NOT NULL,
`pushover_key` varchar(255) NOT NULL,
`pushover_device` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `unique_username` (`user_name`)
@ -216,6 +221,7 @@ class Installer {
`active` enum('yes','no') NOT NULL default 'yes',
`email` enum('yes','no') NOT NULL default 'yes',
`sms` enum('yes','no') NOT NULL default 'no',
`pushover` enum('yes','no') NOT NULL default 'no',
`warning_threshold` mediumint(1) unsigned NOT NULL DEFAULT '1',
`warning_threshold_counter` mediumint(1) unsigned NOT NULL DEFAULT '0',
`timeout` smallint(1) unsigned NULL DEFAULT NULL,
@ -392,6 +398,15 @@ class Installer {
protected function upgrade310() {
$queries = array();
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUES ('pushover_status', '1');";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUES ('log_pushover', '1');";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUES ('pushover_api_token', '');";
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "users` ADD `pushover_key` VARCHAR( 255 ) NOT NULL AFTER `mobile`;";
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "users` ADD `pushover_device` VARCHAR( 255 ) NOT NULL AFTER `pushover_key`;";
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `pushover` ENOM( 'yes','no' ) NOT NULL DEFAULT 'no' AFTER `sms`;";
$queries[] = "CREATE TABLE IF NOT EXISTS `" . PSM_DB_PREFIX . "users_preferences` (
`user_id` int(11) unsigned NOT NULL,
`key` varchar(255) NOT NULL,

View File

@ -0,0 +1,54 @@
<?php
/**
* PHP Server Monitor
* Monitor your servers and websites.
*
* This file is part of PHP Server Monitor.
* PHP Server Monitor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PHP Server Monitor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
*
* @package phpservermon
* @author Pepijn Over <pep@neanderthal-technology.com>
* @copyright Copyright (c) 2008-2014 Pepijn Over <pep@neanderthal-technology.com>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 3.0.0
**/
namespace psm\Util;
/**
* Pushover is not using namespaces so unable to load files in autoloader.
*/
require_once(PSM_PATH_VENDOR . '/Pushover/Pushover.php');
/**
* PSM Pushover utility
*
* The Pushover is an open source lib that can be found in vendor/Pushover.
*
* @see \Pushover
*/
class Pushover extends \Pushover {
/**
* Open new Pushover
*
* @param boolean $exceptions
*/
function __construct($exceptions = false) {
parent::__construct($exceptions);
}
}

View File

@ -69,7 +69,7 @@ class Autorun {
)";
}
$sql = "SELECT `s`.`server_id`,`s`.`ip`,`s`.`port`,`s`.`label`,`s`.`type`,`s`.`pattern`,`s`.`status`,`s`.`active`,`s`.`email`,`s`.`sms`
$sql = "SELECT `s`.`server_id`,`s`.`ip`,`s`.`port`,`s`.`label`,`s`.`type`,`s`.`pattern`,`s`.`status`,`s`.`active`,`s`.`email`,`s`.`sms`,`s`.`pushover`
FROM `".PSM_DB_PREFIX."servers` AS `s`
{$sql_join}
WHERE `active`='yes' ";

View File

@ -54,6 +54,12 @@ class StatusNotifier {
*/
protected $send_sms = false;
/**
* Send sms?
* @var boolean $send_pushover
*/
protected $send_pushover = false;
/**
* Save log records?
* @var boolean $save_log
@ -89,6 +95,7 @@ class StatusNotifier {
$this->send_emails = psm_get_conf('email_status');
$this->send_sms = psm_get_conf('sms_status');
$this->send_pushover = psm_get_conf('pushover_status');
$this->save_logs = psm_get_conf('log_status');
}
@ -114,7 +121,7 @@ class StatusNotifier {
$this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array(
'server_id' => $server_id,
), array(
'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'error', 'active', 'email', 'sms',
'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'error', 'active', 'email', 'sms', 'pushover',
));
if(empty($this->server)) {
return false;
@ -169,6 +176,12 @@ class StatusNotifier {
$this->notifyByTxtMsg();
}
// check if pushover is enabled for this server
if($this->send_pushover && $this->server['pushover'] == 'yes') {
// yay lets wake those nerds up!
$this->notifyByPushover();
}
return $notify;
}
@ -210,6 +223,60 @@ class StatusNotifier {
}
}
/**
* This functions performs the pushover notifications
*
* @return boolean
*/
protected function notifyByPushover() {
$userlist = array();
$users = $this->getUsers($this->server_id);
if (empty($users)) {
return false;
}
// build pushover object with some default values
$pushover = psm_build_pushover();
if($this->status_new === true)
{
$pushover->setPriority(0);
}else
{
$pushover->setPriority(2);
$pushover->setRetry(300); //Used with Priority = 2; Pushover will resend the notification every 60 seconds until the user accepts.
$pushover->setExpire(3600); //Used with Priority = 2; Pushover will resend the notification every 60 seconds for 3600 seconds. After that point, it stops sending notifications.
}
//$pushover->setCallback('http://some.url/runscript.php'); // The callback parameter must be a URL (HTTP or HTTPS) that is reachable from the Internet that our servers will call out to as soon as the notification has been acknowledged.
$pushover->setTimestamp(time());
//$pushover->setDebug(true);
//$pushover->setSound('bike');
$this->server['MONITORURL']=$url = "http".(!empty($_SERVER['HTTPS'])?"s":"").":\/\/".$_SERVER['SERVER_NAME'];
$message = psm_parse_msg($this->status_new, 'pushover_message', $this->server);
$pushover->setTitle(psm_parse_msg($this->status_new, 'pushover_title', $this->server));
$pushover->setMessage(str_replace('<br/>', "\n", $message));
$pushover->setUrl(psm_parse_msg($this->status_new, 'pushover_url', $this->server));
$pushover->setUrlTitle(psm_parse_msg($this->status_new, 'pushover_url_title', $this->server));
// go through empl
foreach ($users as $user) {
$pushover->setUser($user['pushover_key']);
$pushover->setDevice($user['pushover_device']);
$pushover->send();
}
if(psm_get_conf('log_pushover')) {
// save to log
psm_add_log($this->server_id, 'pushover', $message, implode(',', $userlist));
}
}
/**
* This functions performs the text message notifications
*
@ -257,7 +324,7 @@ class StatusNotifier {
public function getUsers($server_id) {
// find all the users with this server listed
$users = $this->db->query("
SELECT `u`.`user_id`, `u`.`name`,`u`.`email`, `u`.`mobile`
SELECT `u`.`user_id`, `u`.`name`,`u`.`email`, `u`.`mobile`, `u`.`pushover_key`, `u`.`pushover_device`
FROM `".PSM_DB_PREFIX."users` AS `u`
JOIN `".PSM_DB_PREFIX."users_servers` AS `us` ON (
`us`.`user_id`=`u`.`user_id`

View File

@ -4,6 +4,7 @@
<li class="{general_active}"><a href="#config-general" data-toggle="tab">{label_general}</a></li>
<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="{logging_active}"><a href="#config-logging" data-toggle="tab">{label_tab_log}</a></li>
</ul>
<div class="tab-content well">
@ -157,7 +158,26 @@
</div>
</fieldset>
</div>
<div id="config-logging" class="tab-pane {logging_active}">
<div id="config-pushover" class="tab-pane {pushover_active}">
<fieldset>
<legend>{label_settings_pushover}</legend>
<div class="control-group">
<div class="controls">
<label class="checkbox" for="pushover_status"><input type="checkbox" id="pushover_status" name="pushover_status[]" {pushover_status_checked} /> {label_pushover_status}</label>
</div>
</div>
<div class="control-group">
<label class="control-label" for="pushover_api">{label_pushover_api_token}</label>
<div class="controls">
<input type="text" id="pushover_api_token" name="pushover_api_token" value="{pushover_api_token}" maxlength="255" />
</div>
</div>
<div class="form-actions">
<button class="btn btn-success" type="submit">{label_save}</button>
</div>
</fieldset>
</div>
<div id="config-logging" class="tab-pane">
<fieldset>
<legend>{label_settings_log}</legend>
<div class="control-group">
@ -170,6 +190,9 @@
<div class="control-group">
<label class="checkbox"><input type="checkbox" id="log_sms" name="log_sms[]" {log_sms_checked} /> {label_log_sms}</label>
</div>
<div class="control-group">
<label class="checkbox"><input type="checkbox" id="log_pushover" name="log_pushover[]" {log_pushover_checked} /> {label_log_pushover}</label>
</div>
<div class="form-actions">
<button class="btn btn-success" type="submit" name="logging_submit">{label_save}</button>
</div>

View File

@ -4,6 +4,7 @@
<li class="active"><a href="#log_status_content" data-toggle="tab">{label_status}</a></li>
<li><a href="#log_email_content" data-toggle="tab">{label_email}</a></li>
<li><a href="#log_sms_content" data-toggle="tab">{label_sms}</a></li>
<li><a href="#log_pushover_content" data-toggle="tab">{label_pushover}</a></li>
</ul>
<div class="tab-content well">
<div class="tab-pane active" id="log_status_content">
@ -15,6 +16,9 @@
<div class="tab-pane" id="log_sms_content">
{content_sms}
</div>
<div class="tab-pane" id="log_pushover_content">
{content_pushover}
</div>
</div>
</div>
<!--%%tpl_server_log_list-->

View File

@ -12,6 +12,7 @@
<th class="hidden-phone">{label_monitoring}</th>
<th class="visible-desktop">{label_email}</th>
<th class="visible-desktop">{label_sms}</th>
<th class="visible-desktop">{label_pushover}</th>
<th class="hidden-phone">{label_action}</th>
</tr>
</thead>
@ -140,6 +141,15 @@
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="pushover">{label_send_pushover}</label>
<div class="controls">
<select id="pushover" name="pushover">
<option value="yes" {edit_pushover_selected_yes}>{label_yes}</option>
<option value="no" {edit_pushover_selected_no}>{label_no}</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="warning_threshold">{label_warning_threshold}</label>
<div class="controls">

View File

@ -67,6 +67,10 @@
<td>{label_sms}:</td>
<td>{sms}</td>
</tr>
<tr>
<td>{label_send_pushover}:</td>
<td>{pushover}</td>
</tr>
<tr>
<td>{label_timeout}:</td>
<td>{timeout} s</td>

View File

@ -36,7 +36,19 @@
</div>
</div>
<div class="control-group">
<label class="control-label" for="mobile">{label_mobile}</label>
<label class="control-label" for="mobile">{label_pushover_key}</label>
<div class="controls">
<input type="text" id="pushover_key" name="pushover_key" value="{pushover_key}" maxlength="255" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="mobile">{label_pushover_device}</label>
<div class="controls">
<input type="text" id="pushover_device" name="pushover_device" value="{pushover_device}" maxlength="255" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="email">{label_email}</label>
<div class="controls">
<input type="text" id="mobile" name="mobile" value="{mobile}" maxlength="15" />
</div>

View File

@ -7,6 +7,7 @@
<th class="visible-desktop">{label_level}</th>
<th class="hidden-phone">{label_email}</th>
<th class="hidden-phone">{label_mobile}</th>
<th class="hidden-pushover">{label_pushover}</th>
<th class="hidden-phone">{label_servers}</th>
<th class="hidden-phone tight">{label_action}</th>
</tr>
@ -14,6 +15,13 @@
<tbody>
<!--%tpl_repeat_users-->
<tr>
<td>{name}</td>
<td>{user_name}</td>
<td>{label_level_{level}}</td>
<td>{mobile}</td>
<td>{pushover_device}</td>
<td>{email}</td>
<td>{emp_servers}</td>
<td>
<div class="table-body">
<div class="table-cell-title">
@ -111,7 +119,19 @@
</div>
</div>
<div class="control-group">
<label class="control-label" for="mobile">{label_mobile}</label>
<label class="control-label" for="pushover_key">{label_pushover_key}</label>
<div class="controls">
<input type="text" id="pushover_key" name="pushover_key" value="{edit_value_pushover_key}" maxlength="255" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="pushover_device">{label_pushover_device}</label>
<div class="controls">
<input type="text" id="pushover_device" name="pushover_device" value="{edit_value_pushover_device}" maxlength="255" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="email">{label_email}</label>
<div class="controls">
<input type="text" id="mobile" name="mobile" value="{edit_value_mobile}" maxlength="15" />
</div>

452
vendor/Pushover/Pushover.php vendored Normal file
View File

@ -0,0 +1,452 @@
<?php
/**
* php-pushover
*
* https://github.com/kryap/php-pushover
*
* PHP service wrapper for the pushover.net API: https://pushover.net/api
*
* @author Chris Schalenborgh <chris.s@kryap.com>
* @version 0.2
* @package php-pushover
* @example test.php
* @link https://pushover.net/api
* @license BSD License
*/
class Pushover
{
// api url
const API_URL = 'https://api.pushover.net/1/messages.xml';
/**
* Application API token
*
* @var string
*/
private $_token;
/**
* User API token
*
* @var string
*/
private $_user;
/**
* Turn on/off debug mode
*
* @var bool
*/
private $_debug = false;
/**
* Title of the message
*
* @var string
*/
private $_title;
/**
* The message itself (up to 512 characters)
*
* @var string
*/
private $_message;
/**
* Timestamp in Unix timestamp format
*
* @var int
*/
private $_timestamp;
/**
* User's device (user specific)
*
* @var string
*/
private $_device;
/**
* Priority of the message. Can be 0, 1 or 2. High-priority messages (1) override a user's "quiet hours" setting and will always be delivered any time they are received. High priority messages are highlighted in red in the Android and iOS clients. Emergency Priority (2) messages work similar to High-Priority messages, but they are repeated until the message is acknowledged by the user.
*
* @var string
*/
private $_priority = 0;
/**
* Include a Supplementary URL (up to 200 characters)
*
* @var string
*/
private $_url;
/**
* Title of the included URL (up to 50 characters)
*
* @var string
*/
private $_url_title;
/**
* The Retry parameter is only used when the Priority is set to 2 (or emergency-priority), and specifies how often (in seconds) the Pushover servers will send the same notification to the user. In a situation where your user might be in a noisy environment or sleeping, retrying the notification (with sound and vibration) will help get his or her attention. This parameter must have a value of at least 30 seconds between retries.
*
* @var int
*/
private $_retry;
/**
* The expire parameter is only used when the Priority is set to 2 (or emergency-priority), and specifies how many seconds your notification will continue to be retried for. If the notification has not been acknowledged in expire seconds, it will be marked as expired and will stop being sent to the user. This parameter must have a maximum value of at most 86400 seconds (24 hours).
*
* @var int
*/
private $_expire;
/**
* The optional callback parameter may be supplied with a publicly-accessible URL that our servers will send a request to when the user has acknowledged your notification.
*
* @var string
*/
private $_callback;
/**
* The sound parameter. Get an up-to-date sound list from https://api.pushover.net/1/sounds.json?token=
*
* @var int
*/
private $_sound;
/**
* Default constructor
*/
public function __construct () {
}
/**
* Set API token
*
* @param string $token Your app API key.
*
* @return void
*/
public function setToken ($token) {
$this->_token = (string)$token;
}
/**
* Get API token
*
* @return string
*/
public function getToken () {
return $this->_token;
}
/**
* Set API user
*
* @param string $user The user's API key.
*
* @return void
*/
public function setUser ($user) {
$this->_user = (string)$user;
}
/**
* Get API user
*
* @return string
*/
public function getUser () {
return $this->_user;
}
/**
* Set message title
*
* @param string $title Title of push notification.
*
* @return void
*/
public function setTitle ($title) {
$this->_title = (string)$title;
}
/**
* Get message title
*
* @return string
*/
public function getTitle () {
return $this->_title;
}
/**
* Set Retry Time
*
* @param int $retry The retry time (in seconds). Must have a value of at least 30 seconds.
*/
public function setRetry ($retry) {
$this->_retry = (int)$retry;
}
/**
* Get Retry Time
*
* @return int
*/
public function getRetry() {
return $this->_retry;
}
/**
* Set Expire Time
*
* @param int $expire The expiry time (in seconds). Must have a maximum value of at most, 86400 seconds.
*/
public function setExpire ($expire) {
$this->_expire = (int)$expire;
}
/**
* Get Expire Time
*
* @return string
*/
public function getExpire () {
return $this->_expire;
}
/**
* Set Callback URL
*
* @param string $callback a publically-accessible URL that Pushover sends a request to when the user has acknowledged your notification.
*/
public function setCallback ($callback) {
$this->_callback = $callback;
}
/**
* Get Callback URL
*
* @return int
*/
public function getCallback() {
return $this->_callback;
}
/**
* Set message
*
* @param string $msg Message of push notification.
*
* @return void
*/
public function setMessage ($msg) {
$this->_message = (string)$msg;
}
/**
* Get message
*
* @return string
*/
public function getMessage () {
return $this->_message;
}
/**
* Set device
*
* @param string $device Leave this empty if you want to send to all user's devices. This can be user specific!
*
* @return void
*/
public function setDevice ($device) {
$this->_device = (string)$device;
}
/**
* Get device
*
* @return string
*/
public function getDevice () {
return $this->_device;
}
/**
* Set timestamp
*
* Messages are stored on the Pushover servers with a timestamp of when they were initially received through the API. This timestamp is sent to and shown on client devices, and messages are listed in order of these timestamps. In most cases, this default timestamp is acceptable. This is not for scheduling!
*
* @param int $time dispaly time on device
*
* @return void
*/
public function setTimestamp ($time) {
$this->_timestamp = (int)$time;
}
/**
* Get timestamp
*
* @return int
*/
public function getTimestamp () {
return $this->_timestamp;
}
/**
* Set priority (-1, 0 or 1)
*
* -1 Low priority notifications.
* 0 Default.
* 1 triggers a high-priority alert that always generates sound and vibration.
* 2 triggers the same high-priority alert that #1 does; but is repeated until the notification is acknowledged by the user.
*
* @param int $priority priority level.
*
* @return void
*/
public function setPriority ($priority) {
$this->_priority = (int)$priority;
}
/**
* Get priority
*
* @return int
*/
public function getPriority () {
return $this->_priority;
}
/**
* Set url
*
* @param string $url Add an url to your notification.
*
* @return void
*/
public function setUrl ($url) {
$this->_url = (string)$url;
}
/**
* Get url
*
* @return string
*/
public function getUrl () {
return $this->_url;
}
/**
* Set url title
*
* @param string $url_title A title if you want to show a text instead of the actual url.
*
* @return void
*/
public function setUrlTitle ($url_title) {
$this->_url_title = (string)$url_title;
}
/**
* Get url title
*
* @return string
*/
public function getUrlTitle () {
return $this->_url_title;
}
/**
* Set debug mode
*
* @param bool $debug Enable this to receive detailed input and output info.
*
* @return void
*/
public function setDebug ($debug) {
$this->_debug = (boolean)$debug;
}
/**
* Get debug mode
*
* @return bool
*/
public function getDebug () {
return $this->_debug;
}
/**
* Set sound
*
* @param string $sound If no sound parameter is specified, the user's default tone will play. If the user has not chosen a custom sound, the standard Pushover sound will play.
*
* @return void
*/
public function setSound ($sound) {
$this->_sound = (string)$sound;
}
/**
* Get sound
*
* @return string
*/
public function getSound () {
return $this->_sound;
}
/**
* Send message to Pushover API
*
* @return bool
*/
public function send() {
if(!Empty($this->_token) && !Empty($this->_user) && !Empty($this->_message)) {
if(!isset($this->_timestamp)) $this->setTimestamp(time());
$c = curl_init();
curl_setopt($c, CURLOPT_URL, self::API_URL);
curl_setopt($c, CURLOPT_HEADER, false);
/*
if possible, set CURLOPT_SSL_VERIFYPEER to true..
- http://www.tehuber.com/phps/cabundlegen.phps
*/
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POSTFIELDS, array(
'token' => $this->getToken(),
'user' => $this->getUser(),
'title' => $this->getTitle(),
'message' => $this->getMessage(),
'device' => $this->getDevice(),
'priority' => $this->getPriority(),
'timestamp' => $this->getTimestamp(),
'expire' => $this->getExpire(),
'retry' => $this->getRetry(),
'callback' => $this->getCallback(),
'url' => $this->getUrl(),
'sound' => $this->getSound(),
'url_title' => $this->getUrlTitle()
));
$response = curl_exec($c);
$xml = simplexml_load_string($response);
if($this->getDebug()) {
return array('output' => $xml, 'input' => $this);
}
else {
return ($xml->status == 1) ? true : false;
}
}
}
}
?>