added pushover

This commit is contained in:
lange@rem-media.de 2014-06-13 17:34:09 +02:00
parent 5123137bf0
commit e92b243a37
20 changed files with 749 additions and 13 deletions

View File

@ -409,6 +409,18 @@ function psm_build_mail($from_name = null, $from_email = null) {
return $phpmailer; 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;
}
/** /**
* Generate a new link to the current monitor * Generate a new link to the current monitor
* @param array $params key value pairs * @param array $params key value pairs

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.', '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', 'mobile' => 'Mobil',
'email' => 'Email', 'email' => 'Email',
'pushover' => 'Pushover',
'pushover_key' => 'Pushover Key',
'pushover_device' => 'Pushover Device',
'updated' => 'Benutzer bearbeitet.', 'updated' => 'Benutzer bearbeitet.',
'inserted' => 'Benutzer eingetragen.', 'inserted' => 'Benutzer eingetragen.',
'profile' => 'Profile', 'profile' => 'Profile',
@ -101,6 +104,7 @@ $sm_lang = array(
'status' => 'Status', 'status' => 'Status',
'email' => 'Email', 'email' => 'Email',
'sms' => 'SMS', 'sms' => 'SMS',
'pushover' => 'Pushover',
), ),
'servers' => array( 'servers' => array(
'server' => 'Server', 'server' => 'Server',
@ -117,6 +121,7 @@ $sm_lang = array(
'monitoring' => 'Monitoring', 'monitoring' => 'Monitoring',
'send_email' => 'Email', 'send_email' => 'Email',
'send_sms' => 'SMS', 'send_sms' => 'SMS',
'send_pushover' => 'Pushover',
'updated' => 'Server aktualisiert.', 'updated' => 'Server aktualisiert.',
'inserted' => 'Server eingetragen.', 'inserted' => 'Server eingetragen.',
'latency' => 'Antwortzeit', 'latency' => 'Antwortzeit',
@ -162,6 +167,8 @@ $sm_lang = array(
'sms_gateway_username' => 'Gateway Benutzername', 'sms_gateway_username' => 'Gateway Benutzername',
'sms_gateway_password' => 'Gateway Passwort', 'sms_gateway_password' => 'Gateway Passwort',
'sms_from' => 'SMS Sendernummer', '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' => 'Wann m&ouml;chten Sie benachrichtig werden?<br/>',
'alert_type_description' => '<b>Status ge&auml;ndert:</b> '. 'alert_type_description' => '<b>Status ge&auml;ndert:</b> '.
'... wenn sich der Status &auml;ndert<br/>'. '... wenn sich der Status &auml;ndert<br/>'.
@ -179,12 +186,15 @@ $sm_lang = array(
'log_status_description' => 'Ist der Log Status auf TRUE (ein Hacken) gesetzt, wird jeder Status protokolliert.', 'log_status_description' => 'Ist der Log Status auf TRUE (ein Hacken) gesetzt, wird jeder Status protokolliert.',
'log_email' => 'Email Log per Script senden?', 'log_email' => 'Email Log per Script senden?',
'log_sms' => 'SMS Log per Script senden?', 'log_sms' => 'SMS Log per Script senden?',
'log_pushover' => 'Pushover Log per Script senden?',
'updated' => 'Die Einstellungen wurden gespeichert.', 'updated' => 'Die Einstellungen wurden gespeichert.',
'tab_email' => 'Email', 'tab_email' => 'Email',
'tab_sms' => 'SMS', 'tab_sms' => 'SMS',
'tab_pushover' => 'Pushover',
'tab_log' => 'Log', 'tab_log' => 'Log',
'settings_email' => 'Email', 'settings_email' => 'Email',
'settings_sms' => 'SMS Nachricht', 'settings_sms' => 'SMS Nachricht',
'settings_pushover' => 'Pushover',
'settings_notification' => 'Benachrichtigung', 'settings_notification' => 'Benachrichtigung',
'settings_log' => 'Log', 'settings_log' => 'Log',
'auto_refresh' => 'Auto-refresh', 'auto_refresh' => 'Auto-refresh',
@ -200,9 +210,17 @@ $sm_lang = array(
'off_sms' => 'Server \'%LABEL%\' ist Offline: ip=%IP%, port=%PORT%. Fehler=%ERROR%', 'off_sms' => 'Server \'%LABEL%\' ist Offline: ip=%IP%, port=%PORT%. Fehler=%ERROR%',
'off_email_subject' => 'Wichtig: Server \'%LABEL%\' ist Offline', '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_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_sms' => 'Server \'%LABEL%\' ist wieder Online: ip=%IP%, port=%PORT%',
'on_email_subject' => 'Wichtig: Server \'%LABEL%\' ist wieder Online', '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_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( 'login' => array(
'welcome_usermenu' => 'Welcome, %user_name%', '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.', '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', 'mobile' => 'Mobile',
'email' => 'Email', 'email' => 'Email',
'pushover' => 'Pushover',
'pushover_key' => 'Pushover Key',
'pushover_device' => 'Pushover Device',
'updated' => 'User updated.', 'updated' => 'User updated.',
'inserted' => 'User added.', 'inserted' => 'User added.',
'profile' => 'Profile', 'profile' => 'Profile',
@ -101,6 +104,7 @@ $sm_lang = array(
'status' => 'Status', 'status' => 'Status',
'email' => 'Email', 'email' => 'Email',
'sms' => 'SMS', 'sms' => 'SMS',
'pushover' => 'Pushover',
), ),
'servers' => array( 'servers' => array(
'server' => 'Server', 'server' => 'Server',
@ -117,6 +121,7 @@ $sm_lang = array(
'monitoring' => 'Monitoring', 'monitoring' => 'Monitoring',
'send_email' => 'Send Email', 'send_email' => 'Send Email',
'send_sms' => 'Send SMS', 'send_sms' => 'Send SMS',
'send_pushover' => 'Send Pushover',
'updated' => 'Server updated.', 'updated' => 'Server updated.',
'inserted' => 'Server added.', 'inserted' => 'Server added.',
'latency' => 'Latency', 'latency' => 'Latency',
@ -162,6 +167,8 @@ $sm_lang = array(
'sms_gateway_username' => 'Gateway username', 'sms_gateway_username' => 'Gateway username',
'sms_gateway_password' => 'Gateway password', 'sms_gateway_password' => 'Gateway password',
'sms_from' => 'Sender\'s phone number', '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' => 'Select when you\'d like to be notified.<br/>',
'alert_type_description' => '<b>Status change:</b> '. '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/>'. 'You will receive a notifcation when a server has a change in status. So from online -> offline or offline -> online.<br/>'.
@ -179,12 +186,15 @@ $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_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_email' => 'Log emails sent by the script',
'log_sms' => 'Log text messages 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.', 'updated' => 'The configuration has been updated.',
'tab_email' => 'Email', 'tab_email' => 'Email',
'tab_sms' => 'SMS', 'tab_sms' => 'SMS',
'tab_pushover' => 'Pushover',
'tab_log' => 'Log', 'tab_log' => 'Log',
'settings_email' => 'Email settings', 'settings_email' => 'Email settings',
'settings_sms' => 'Text message settings', 'settings_sms' => 'Text message settings',
'settings_pushover' => 'Pushover settings',
'settings_notification' => 'Notification settings', 'settings_notification' => 'Notification settings',
'settings_log' => 'Log settings', 'settings_log' => 'Log settings',
'auto_refresh' => 'Auto-refresh', 'auto_refresh' => 'Auto-refresh',
@ -200,9 +210,17 @@ $sm_lang = array(
'off_sms' => 'Server \'%LABEL%\' is DOWN: ip=%IP%, port=%PORT%. Error=%ERROR%', 'off_sms' => 'Server \'%LABEL%\' is DOWN: ip=%IP%, port=%PORT%. Error=%ERROR%',
'off_email_subject' => 'IMPORTANT: Server \'%LABEL%\' is DOWN', '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_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_sms' => 'Server \'%LABEL%\' is RUNNING: ip=%IP%, port=%PORT%',
'on_email_subject' => 'IMPORTANT: Server \'%LABEL%\' is RUNNING', '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_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( 'login' => array(
'welcome_usermenu' => 'Welcome, %user_name%', 'welcome_usermenu' => 'Welcome, %user_name%',

View File

@ -40,9 +40,11 @@ class ConfigController extends AbstractController {
'email_status', 'email_status',
'email_smtp', 'email_smtp',
'sms_status', 'sms_status',
'pushover_status',
'log_status', 'log_status',
'log_email', 'log_email',
'log_sms', 'log_sms',
'log_pushover',
'show_update', 'show_update',
); );
@ -60,6 +62,7 @@ class ConfigController extends AbstractController {
'sms_gateway_username', 'sms_gateway_username',
'sms_gateway_password', 'sms_gateway_password',
'sms_from', 'sms_from',
'pushover_api_token',
); );
function __construct(Database $db, Template $tpl) { function __construct(Database $db, Template $tpl) {
@ -182,9 +185,11 @@ class ConfigController extends AbstractController {
'subtitle' => psm_get_lang('menu', 'config'), 'subtitle' => psm_get_lang('menu', 'config'),
'label_tab_email' => psm_get_lang('config', 'tab_email'), 'label_tab_email' => psm_get_lang('config', 'tab_email'),
'label_tab_sms' => psm_get_lang('config', 'tab_sms'), '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_tab_log' => psm_get_lang('config', 'tab_log'),
'label_settings_email' => psm_get_lang('config', 'settings_email'), 'label_settings_email' => psm_get_lang('config', 'settings_email'),
'label_settings_sms' => psm_get_lang('config', 'settings_sms'), '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_notification' => psm_get_lang('config', 'settings_notification'),
'label_settings_log' => psm_get_lang('config', 'settings_log'), 'label_settings_log' => psm_get_lang('config', 'settings_log'),
'label_general' => psm_get_lang('config', 'general'), 'label_general' => psm_get_lang('config', 'general'),
@ -210,6 +215,8 @@ class ConfigController extends AbstractController {
'label_sms_gateway_username' => psm_get_lang('config', 'sms_gateway_username'), 'label_sms_gateway_username' => psm_get_lang('config', 'sms_gateway_username'),
'label_sms_gateway_password' => psm_get_lang('config', 'sms_gateway_password'), 'label_sms_gateway_password' => psm_get_lang('config', 'sms_gateway_password'),
'label_sms_from' => psm_get_lang('config', 'sms_from'), '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' => psm_get_lang('config', 'alert_type'),
'label_alert_type_description' => psm_get_lang('config', 'alert_type_description'), 'label_alert_type_description' => psm_get_lang('config', 'alert_type_description'),
'label_alert_type_status' => psm_get_lang('config', 'alert_type_status'), 'label_alert_type_status' => psm_get_lang('config', 'alert_type_status'),
@ -219,6 +226,7 @@ class ConfigController extends AbstractController {
'label_log_status_description' => psm_get_lang('config', 'log_status_description'), 'label_log_status_description' => psm_get_lang('config', 'log_status_description'),
'label_log_email' => psm_get_lang('config', 'log_email'), 'label_log_email' => psm_get_lang('config', 'log_email'),
'label_log_sms' => psm_get_lang('config', 'log_sms'), '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' => psm_get_lang('config', 'auto_refresh'),
'label_auto_refresh_servers' => psm_get_lang('config', 'auto_refresh_servers'), 'label_auto_refresh_servers' => psm_get_lang('config', 'auto_refresh_servers'),
'label_seconds' => psm_get_lang('config', 'seconds'), 'label_seconds' => psm_get_lang('config', 'seconds'),

View File

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

View File

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

View File

@ -160,6 +160,7 @@ class ServerController extends AbstractServerController {
'edit_active_selected_' . $edit_server['active'] => 'selected="selected"', 'edit_active_selected_' . $edit_server['active'] => 'selected="selected"',
'edit_email_selected_' . $edit_server['email'] => 'selected="selected"', 'edit_email_selected_' . $edit_server['email'] => 'selected="selected"',
'edit_sms_selected_' . $edit_server['sms'] => 'selected="selected"', 'edit_sms_selected_' . $edit_server['sms'] => 'selected="selected"',
'edit_pushover_selected_' . $edit_server['pushover'] => 'selected="selected"',
)); ));
break; break;
@ -187,6 +188,7 @@ class ServerController extends AbstractServerController {
'active' => in_array($_POST['active'], array('yes', 'no')) ? $_POST['active'] : 'no', 'active' => in_array($_POST['active'], array('yes', 'no')) ? $_POST['active'] : 'no',
'email' => in_array($_POST['email'], array('yes', 'no')) ? $_POST['email'] : 'no', 'email' => in_array($_POST['email'], array('yes', 'no')) ? $_POST['email'] : 'no',
'sms' => in_array($_POST['sms'], array('yes', 'no')) ? $_POST['sms'] : 'no', 'sms' => in_array($_POST['sms'], array('yes', 'no')) ? $_POST['sms'] : 'no',
'pushover' => in_array($_POST['pushover'], array('yes', 'no')) ? $_POST['pushover'] : 'no',
); );
// check for edit or add // check for edit or add
@ -312,6 +314,7 @@ class ServerController extends AbstractServerController {
'label_monitoring' => psm_get_lang('servers', 'monitoring'), 'label_monitoring' => psm_get_lang('servers', 'monitoring'),
'label_send_email' => psm_get_lang('servers', 'send_email'), 'label_send_email' => psm_get_lang('servers', 'send_email'),
'label_send_sms' => psm_get_lang('servers', 'send_sms'), 'label_send_sms' => psm_get_lang('servers', 'send_sms'),
'label_send_pushover' => psm_get_lang('servers', 'send_pushover'),
'label_warning_threshold' => psm_get_lang('servers', 'warning_threshold'), 'label_warning_threshold' => psm_get_lang('servers', 'warning_threshold'),
'label_warning_threshold_description' => psm_get_lang('servers', 'warning_threshold_description'), 'label_warning_threshold_description' => psm_get_lang('servers', 'warning_threshold_description'),
'label_action' => psm_get_lang('system', 'action'), 'label_action' => psm_get_lang('system', 'action'),
@ -327,4 +330,4 @@ class ServerController extends AbstractServerController {
return parent::createHTMLLabels(); return parent::createHTMLLabels();
} }
} }

View File

@ -36,7 +36,7 @@ class ProfileController extends AbstractController {
* Editable fields for the profile * Editable fields for the profile
* @var array $profile_fields * @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) { function __construct(Database $db, Template $tpl) {
parent::__construct($db, $tpl); parent::__construct($db, $tpl);
@ -132,6 +132,8 @@ class ProfileController extends AbstractController {
'label_password_repeat' => psm_get_lang('users', 'password_repeat'), 'label_password_repeat' => psm_get_lang('users', 'password_repeat'),
'label_level' => psm_get_lang('users', 'level'), 'label_level' => psm_get_lang('users', 'level'),
'label_mobile' => psm_get_lang('users', 'mobile'), '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_email' => psm_get_lang('users', 'email'),
'label_save' => psm_get_lang('system', 'save'), 'label_save' => psm_get_lang('system', 'save'),
) )
@ -139,4 +141,4 @@ class ProfileController extends AbstractController {
return parent::createHTMLLabels(); return parent::createHTMLLabels();
} }
} }

View File

@ -88,7 +88,7 @@ class UserController extends AbstractController {
$users = $this->db->select( $users = $this->db->select(
PSM_DB_PREFIX.'users', PSM_DB_PREFIX.'users',
null, null,
array('user_id', 'user_name', 'level', 'name', 'mobile', 'email'), array('user_id', 'user_name', 'level', 'name', 'mobile', 'pushover_key', 'pushover_device', 'email'),
null, null,
array('name') array('name')
); );
@ -115,7 +115,7 @@ class UserController extends AbstractController {
protected function executeEdit() { protected function executeEdit() {
$this->setTemplateId('user_update', 'user/user.tpl.html'); $this->setTemplateId('user_update', 'user/user.tpl.html');
$user_id = isset($_GET['id']) ? intval($_GET['id']) : 0; $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) { if($user_id == 0) {
// insert mode // insert mode
@ -190,7 +190,7 @@ class UserController extends AbstractController {
} }
$user_id = (isset($_GET['id'])) ? intval($_GET['id']) : 0; $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(); $clean = array();
foreach($fields as $field) { foreach($fields as $field) {
if(isset($_POST[$field])) { if(isset($_POST[$field])) {
@ -292,6 +292,9 @@ class UserController extends AbstractController {
'label_level_20' => psm_get_lang('users', 'level_20'), 'label_level_20' => psm_get_lang('users', 'level_20'),
'label_level_description' => psm_get_lang('users', 'level_description'), 'label_level_description' => psm_get_lang('users', 'level_description'),
'label_mobile' => psm_get_lang('users', 'mobile'), '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_email' => psm_get_lang('users', 'email'),
'label_servers' => psm_get_lang('menu', 'server'), 'label_servers' => psm_get_lang('menu', 'server'),
'label_action' => psm_get_lang('system', 'action'), 'label_action' => psm_get_lang('system', 'action'),
@ -324,4 +327,4 @@ class UserController extends AbstractController {
} }
return $result; return $result;
} }
} }

View File

@ -126,7 +126,7 @@ class Installer {
$this->log('Populating database...'); $this->log('Populating database...');
$queries = array(); $queries = array();
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "servers` (`ip`, `port`, `label`, `type`, `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`, `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 . "users_servers` (`user_id`,`server_id`) VALUES (1, 1), (1, 2);";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE
('language', 'en_US'), ('language', 'en_US'),
@ -143,10 +143,13 @@ class Installer {
('sms_gateway_username', 'username'), ('sms_gateway_username', 'username'),
('sms_gateway_password', 'password'), ('sms_gateway_password', 'password'),
('sms_from', '1234567890'), ('sms_from', '1234567890'),
('pushover_status', '1'),
('pushover_api_token', ''),
('alert_type', 'status'), ('alert_type', 'status'),
('log_status', '1'), ('log_status', '1'),
('log_email', '1'), ('log_email', '1'),
('log_sms', '1'), ('log_sms', '1'),
('log_pushover', '1'),
('version', '" . PSM_VERSION . "'), ('version', '" . PSM_VERSION . "'),
('version_update_check', '" . PSM_VERSION . "'), ('version_update_check', '" . PSM_VERSION . "'),
('auto_refresh_servers', '0'), ('auto_refresh_servers', '0'),
@ -177,6 +180,8 @@ class Installer {
`level` tinyint(2) unsigned NOT NULL DEFAULT '20', `level` tinyint(2) unsigned NOT NULL DEFAULT '20',
`name` varchar(255) NOT NULL, `name` varchar(255) NOT NULL,
`mobile` varchar(15) NOT NULL, `mobile` varchar(15) NOT NULL,
`pushover_key` varchar(255) NOT NULL,
`pushover_device` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL, `email` varchar(255) NOT NULL,
PRIMARY KEY (`user_id`), PRIMARY KEY (`user_id`),
UNIQUE KEY `unique_username` (`user_name`) UNIQUE KEY `unique_username` (`user_name`)
@ -210,6 +215,7 @@ class Installer {
`active` enum('yes','no') NOT NULL default 'yes', `active` enum('yes','no') NOT NULL default 'yes',
`email` enum('yes','no') NOT NULL default 'yes', `email` enum('yes','no') NOT NULL default 'yes',
`sms` enum('yes','no') NOT NULL default 'no', `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` mediumint(1) unsigned NOT NULL DEFAULT '1',
`warning_threshold_counter` mediumint(1) unsigned NOT NULL DEFAULT '0', `warning_threshold_counter` mediumint(1) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`server_id`) PRIMARY KEY (`server_id`)
@ -264,6 +270,10 @@ class Installer {
// upgrade to 3.0.0 // upgrade to 3.0.0
$this->upgrade300(); $this->upgrade300();
} }
if(version_compare($version_from, '3.0.1', '<')) {
// upgrade to 3.0.1
$this->upgrade301();
}
psm_update_conf('version', $version_to); psm_update_conf('version', $version_to);
} }
@ -378,4 +388,21 @@ class Installer {
} }
$this->execSQL("ALTER TABLE `".PSM_DB_PREFIX."users` DROP `server_id`;"); $this->execSQL("ALTER TABLE `".PSM_DB_PREFIX."users` DROP `server_id`;");
} }
}
/**
* Upgrade for v3.0.1 Pushover release
*/
protected function upgrade301() {
$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`;";
$this->execSQL($queries);
}
}

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` FROM `".PSM_DB_PREFIX."servers` AS `s`
{$sql_join} {$sql_join}
WHERE `active`='yes' "; WHERE `active`='yes' ";

View File

@ -54,6 +54,12 @@ class StatusNotifier {
*/ */
protected $send_sms = false; protected $send_sms = false;
/**
* Send sms?
* @var boolean $send_pushover
*/
protected $send_pushover = false;
/** /**
* Save log records? * Save log records?
* @var boolean $save_log * @var boolean $save_log
@ -89,6 +95,7 @@ class StatusNotifier {
$this->send_emails = psm_get_conf('email_status'); $this->send_emails = psm_get_conf('email_status');
$this->send_sms = psm_get_conf('sms_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'); $this->save_logs = psm_get_conf('log_status');
} }
@ -114,7 +121,7 @@ class StatusNotifier {
$this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array( $this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array(
'server_id' => $server_id, 'server_id' => $server_id,
), array( ), 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)) { if(empty($this->server)) {
return false; return false;
@ -169,6 +176,12 @@ class StatusNotifier {
$this->notifyByTxtMsg(); $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; 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 * This functions performs the text message notifications
* *
@ -280,7 +347,7 @@ class StatusNotifier {
public function getUsers($server_id) { public function getUsers($server_id) {
// find all the users with this server listed // find all the users with this server listed
$users = $this->db->query(" $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` FROM `".PSM_DB_PREFIX."users` AS `u`
JOIN `".PSM_DB_PREFIX."users_servers` AS `us` ON ( JOIN `".PSM_DB_PREFIX."users_servers` AS `us` ON (
`us`.`user_id`=`u`.`user_id` `us`.`user_id`=`u`.`user_id`

View File

@ -4,6 +4,7 @@
<li class="active"><a href="#config-general" data-toggle="tab">{label_general}</a></li> <li class="active"><a href="#config-general" data-toggle="tab">{label_general}</a></li>
<li><a href="#config-email" data-toggle="tab">{label_tab_email}</a></li> <li><a href="#config-email" data-toggle="tab">{label_tab_email}</a></li>
<li><a href="#config-sms" data-toggle="tab">{label_tab_sms}</a></li> <li><a href="#config-sms" data-toggle="tab">{label_tab_sms}</a></li>
<li><a href="#config-pushover" data-toggle="tab">{label_tab_pushover}</a></li>
<li><a href="#config-logging" data-toggle="tab">{label_tab_log}</a></li> <li><a href="#config-logging" data-toggle="tab">{label_tab_log}</a></li>
</ul> </ul>
<div class="tab-content well"> <div class="tab-content well">
@ -138,6 +139,25 @@
<input type="text" id="sms_from" name="sms_from" value="{sms_from}" maxlength="255" /> <input type="text" id="sms_from" name="sms_from" value="{sms_from}" maxlength="255" />
</div> </div>
</div> </div>
<div class="form-actions">
<button class="btn btn-success" type="submit">{label_save}</button>
</div>
</fieldset>
</div>
<div id="config-pushover" class="tab-pane">
<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"> <div class="form-actions">
<button class="btn btn-success" type="submit">{label_save}</button> <button class="btn btn-success" type="submit">{label_save}</button>
</div> </div>
@ -156,6 +176,9 @@
<div class="control-group"> <div class="control-group">
<label class="checkbox"><input type="checkbox" id="log_sms" name="log_sms[]" {log_sms_checked} /> {label_log_sms}</label> <label class="checkbox"><input type="checkbox" id="log_sms" name="log_sms[]" {log_sms_checked} /> {label_log_sms}</label>
</div> </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"> <div class="form-actions">
<button class="btn btn-success" type="submit">{label_save}</button> <button class="btn btn-success" type="submit">{label_save}</button>
</div> </div>

View File

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

View File

@ -12,6 +12,7 @@
<th>{label_monitoring}</th> <th>{label_monitoring}</th>
<th>{label_send_email}</th> <th>{label_send_email}</th>
<th>{label_send_sms}</th> <th>{label_send_sms}</th>
<th>{label_send_pushover}</th>
<th>{label_action}</th> <th>{label_action}</th>
</tr> </tr>
</thead> </thead>
@ -32,6 +33,7 @@
<td>{active}</td> <td>{active}</td>
<td>{email}</td> <td>{email}</td>
<td>{sms}</td> <td>{sms}</td>
<td>{pushover}</td>
<td><a class="btn btn-small" href="index.php?mod=server&amp;action=view&amp;id={server_id}"><i class="icon-eye-open"></i></a> <td><a class="btn btn-small" href="index.php?mod=server&amp;action=view&amp;id={server_id}"><i class="icon-eye-open"></i></a>
{html_actions}</td> {html_actions}</td>
</tr> </tr>
@ -114,6 +116,15 @@
</select> </select>
</div> </div>
</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"> <div class="control-group">
<label class="control-label" for="warning_threshold">{label_warning_threshold}</label> <label class="control-label" for="warning_threshold">{label_warning_threshold}</label>
<div class="controls"> <div class="controls">

View File

@ -67,6 +67,10 @@
<td>{label_send_sms}:</td> <td>{label_send_sms}:</td>
<td>{sms}</td> <td>{sms}</td>
</tr> </tr>
<tr>
<td>{label_send_pushover}:</td>
<td>{pushover}</td>
</tr>
{html_actions} {html_actions}
</tbody> </tbody>
</table> </table>

View File

@ -35,6 +35,18 @@
<input type="text" id="mobile" name="mobile" value="{mobile}" maxlength="15" /> <input type="text" id="mobile" name="mobile" value="{mobile}" maxlength="15" />
</div> </div>
</div> </div>
<div class="control-group">
<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"> <div class="control-group">
<label class="control-label" for="email">{label_email}</label> <label class="control-label" for="email">{label_email}</label>
<div class="controls"> <div class="controls">

View File

@ -6,6 +6,7 @@
<th>{label_user_name}</th> <th>{label_user_name}</th>
<th>{label_level}</th> <th>{label_level}</th>
<th>{label_mobile}</th> <th>{label_mobile}</th>
<th>{label_pushover}</th>
<th>{label_email}</th> <th>{label_email}</th>
<th>{label_servers}</th> <th>{label_servers}</th>
<th width="75">{label_action}</th> <th width="75">{label_action}</th>
@ -18,6 +19,7 @@
<td>{user_name}</td> <td>{user_name}</td>
<td>{label_level_{level}}</td> <td>{label_level_{level}}</td>
<td>{mobile}</td> <td>{mobile}</td>
<td>{pushover_device}</td>
<td>{email}</td> <td>{email}</td>
<td>{emp_servers}</td> <td>{emp_servers}</td>
<td> <td>
@ -83,6 +85,18 @@
<input type="text" id="mobile" name="mobile" value="{edit_value_mobile}" maxlength="15" /> <input type="text" id="mobile" name="mobile" value="{edit_value_mobile}" maxlength="15" />
</div> </div>
</div> </div>
<div class="control-group">
<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"> <div class="control-group">
<label class="control-label" for="email">{label_email}</label> <label class="control-label" for="email">{label_email}</label>
<div class="controls"> <div class="controls">

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;
}
}
}
}
?>