Merge pull request #4 from phpservermon/develop

Pull from upstream
This commit is contained in:
Perri Vardy-Mason 2014-02-24 13:18:12 +00:00
commit c1797b93ec
41 changed files with 4787 additions and 1990 deletions

View File

@ -1,6 +1,18 @@
#########################
#
# Version 2.1
# Version 2.x
# ?, 2014
#
#########################
- Switched from mysql_* to PDO.
- Added SMTP support.
- Updated PHPMailer package to v5.2.6.
- When checking a website, the updater will now follow 302 Location headers.
#########################
#
# Version 2.1.0
# February 8, 2014
#
#########################
- Merged PHP Server Monitor Plus project by Luiz Alberto S. Ribeiro (https://github.com/madeinnordeste/PHP-Server-Monitor-Plus).
@ -53,4 +65,4 @@
- log.php
- tpl/log.tpl.html
- Select order by clause used datetime field after DATE_FORMAT had been performed,
resulting in a wrong list of log entries shown.
resulting in a wrong list of log entries shown.

12
CREDITS Executable file
View File

@ -0,0 +1,12 @@
Credits
=======
* Bugfixes & features - Perri Vardy-Mason
* PHP Mailer - Brent R. Matzelle
* German translation - Brunbaur Herbert
* French translation - David Ribeiro
* Korean translation - Ik-Jun
* Brazilian translation - Luiz Alberto S. Ribeiro
* Bootstrap implementation - Luiz Alberto S. Ribeiro
* Mosms implementation - Andreas Ek
* Status page - Michael Greenhill

View File

@ -2,12 +2,11 @@
## SUMMARY
PHP Server Monitor is a script that checks whether the servers on your list are up and running on the selected ports.
It comes with a web based user interface where you can add and remove servers or websites from the MySQL database,
PHP Server Monitor is a script that checks whether your websites and servers are up and running.
It comes with a web based user interface where you can add and remove servers and websites from the MySQL database,
and you can manage users for each server with a mobile number and email address.
With version 2 there's the support for websites as well. On the "Add server" page, you can choose
whether it is a "service" or a "website":
There are two different ways to monitor a server:
* Service
@ -17,10 +16,10 @@ whether it is a "service" or a "website":
* Website
You can enter a link to a website (for example <http://sourceforge.net/index.php>), it will use cURL to open the website and
check the HTTP status code (see <http://en.wikipedia.org/wiki/List_of_HTTP_status_codes> for details).
You can enter a link to a website, it will then use cURL to open the website and check the HTTP status code.
If the HTTP status code is in the 4xx range, it means an error occurred and the website is not accessible to the public.
You can also set a regular expression to match certain content on the page itself. If the regular expression returns no matches, the website is considered down.
You can also set a regular expression to match for content on the page itself.
If the regular expression returns no matches, the website is considered down.
In both cases the script will return a "status offline", and will start sending out notifications.
Each server has it's own settings regarding notification.
@ -46,15 +45,15 @@ project page (tracker), or send me an email (see top of file for link).
## DOWNLOAD
The latest version can be found at <http://phpservermon.neanderthal-technology.com/>.
The latest version can be found at <http://www.phpservermonitor.org/>.
You can also clone the git repo at <http://github.com/phpservermon/phpservermon> if you want to contribute.
## REQUIREMENTS
* PHP 5.3+
* PHP packages: cURL, MySQL
* MySQL Database
* PHP cURL package
* PHP PDO mysql driver
## INSTALL
@ -171,15 +170,7 @@ The second part is the actual message. There are a few variables you can use in
## CREDITS
* Bugfixes & features - Perri Vardy-Mason
* PHP Mailer - Brent R. Matzelle
* German translation - Brunbaur Herbert
* French translation - David Ribeiro
* Korean translation - Ik-Jun
* Brazilian translation - Luiz Alberto S. Ribeiro
* Bootstrap implementation - Luiz Alberto S. Ribeiro
* Mosms implementation - Andreas Ek
* Status page - Michael Greenhill
See CREDITS file.
## License

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
// include main configuration and functionality

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
require 'src/bootstrap.php';

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
define('PSM_INSTALL', true);

View File

@ -1,4 +1,30 @@
<?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: phpservermon 2.1.0
* @link http://www.phpservermonitor.org/
* @since phpservermon 2.1.0
**/
define('PSM_VERSION', '2.1.0');
// Include paths
@ -54,7 +80,7 @@ foreach($includes as $file) {
// init db connection
$db = new psm\Service\Database();
if($db->getLink() !== null) {
if($db->status()) {
psm_load_conf();
} else {
@ -67,4 +93,4 @@ if($db->getLink() !== null) {
$lang = psm_get_conf('language', 'en');
psm_load_lang($lang);
?>
?>

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
###############################################
@ -197,15 +197,25 @@ function psm_parse_msg($status, $type, $vars) {
* Shortcut to curl_init(), curl_exec and curl_close()
*
* @param string $href
* @param boolean $header return headers?
* @param boolean $body return body?
* @param int $timeout connection timeout in seconds
* @param boolean $add_agent add user agent?
* @return string cURL result
*/
function psm_curl_get($href) {
function psm_curl_get($href, $header = false, $body = true, $timeout = 10, $add_agent = true) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_NOBODY, (!$body));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_URL, $href);
if($add_agent) {
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11');
}
$result = curl_exec($ch);
curl_close($ch);
@ -259,7 +269,7 @@ function psm_check_updates() {
// been more than a week since update, lets go
// update "update-date"
$db->save(PSM_DB_PREFIX . 'config', array('value' => time()), array('key' => 'last_update_check'));
$latest = psm_curl_get('http://phpservermon.neanderthal-technology.com/version.php');
$latest = psm_curl_get('http://www.phpservermonitor.org/version.php');
$current = psm_get_conf('version');
return version_compare($latest, $current, '>');
@ -267,6 +277,46 @@ function psm_check_updates() {
return false;
}
/**
* Prepare a new Mailer util.
*
* If the from name and email are left blank they will be prefilled from the config.
* @param string $from_name
* @param string $from_email
* @return \psm\Util\Mailer
*/
function psm_build_mail($from_name = null, $from_email = null) {
$phpmailer = new \psm\Util\Mailer();
$phpmailer->Encoding = "base64";
$phpmailer->SMTPDebug = false;
if(psm_get_conf('email_smtp') == '1') {
$phpmailer->IsSMTP();
$phpmailer->Host = psm_get_conf('email_smtp_host');
$phpmailer->Port = psm_get_conf('email_smtp_port');
$smtp_user = psm_get_conf('email_smtp_username');
$smtp_pass = psm_get_conf('email_smtp_password');
if($smtp_user != '' && $smtp_pass != '') {
$phpmailer->SMTPAuth = true;
$phpmailer->Username = $smtp_user;
$phpmailer->Password = $smtp_pass;
}
} else {
$phpmailer->IsMail();
}
if($from_name == null) {
$from_name = psm_get_conf('email_from_name');
}
if($from_email == null) {
$from_email = psm_get_conf('email_from_email');
}
$phpmailer->SetFrom($from_email, $from_name);
return $phpmailer;
}
###############################################
#
# Debug functions

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
$sm_lang = array(
@ -95,6 +95,12 @@ $sm_lang = array(
'email_status' => 'Habilitar envio de email?',
'email_from_email' => 'Endereço do envio de email',
'email_from_name' => 'Nome do envio de email',
'email_smtp' => 'Enable SMTP',
'email_smtp_host' => 'SMTP host',
'email_smtp_port' => 'SMTP port',
'email_smtp_username' => 'SMTP username',
'email_smtp_password' => 'SMTP password',
'email_smtp_noauth' => 'Leave blank for no authentication',
'sms_status' => 'Habilitar o envio de mensagem de texto?',
'sms_gateway' => 'Gateway para o uso de envio de mensagens',
'sms_gateway_mosms' => 'Mosms',

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
$sm_lang = array(
@ -95,6 +95,12 @@ $sm_lang = array(
'email_status' => 'Email senden erlauben?',
'email_from_email' => 'Email from address',
'email_from_name' => 'Email from name',
'email_smtp' => 'Enable SMTP',
'email_smtp_host' => 'SMTP host',
'email_smtp_port' => 'SMTP port',
'email_smtp_username' => 'SMTP username',
'email_smtp_password' => 'SMTP password',
'email_smtp_noauth' => 'Leave blank for no authentication',
'sms_status' => 'SMS Nachricht senden erlauben?',
'sms_gateway' => 'SMS Gateway',
'sms_gateway_mosms' => 'Mosms',

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
$sm_lang = array(
@ -95,6 +95,12 @@ $sm_lang = array(
'email_status' => 'Allow sending email?',
'email_from_email' => 'Email from address',
'email_from_name' => 'Email from name',
'email_smtp' => 'Enable SMTP',
'email_smtp_host' => 'SMTP host',
'email_smtp_port' => 'SMTP port',
'email_smtp_username' => 'SMTP username',
'email_smtp_password' => 'SMTP password',
'email_smtp_noauth' => 'Leave blank for no authentication',
'sms_status' => 'Allow sending text messages?',
'sms_gateway' => 'Gateway to use for sending messages',
'sms_gateway_mosms' => 'Mosms',

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
$sm_lang = array(
@ -95,6 +95,12 @@ $sm_lang = array(
'email_status' => 'Autoriser l envoi de mail?',
'email_from_email' => 'Exp&eacute;diteur',
'email_from_name' => 'Nom de l exp&eacute;diteur',
'email_smtp' => 'Enable SMTP',
'email_smtp_host' => 'SMTP host',
'email_smtp_port' => 'SMTP port',
'email_smtp_username' => 'SMTP username',
'email_smtp_password' => 'SMTP password',
'email_smtp_noauth' => 'Leave blank for no authentication',
'sms_status' => 'Autoriser l envoi de SMS?',
'sms_gateway' => 'Passerelle &agrave; utiliser pour l envoi de SMS',
'sms_gateway_mosms' => 'Mosms',

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
* @since phpservermon 2.1
**/
@ -96,6 +96,12 @@ $sm_lang = array(
'email_status' => '메일전송 허용',
'email_from_email' => 'Email 주소',
'email_from_name' => 'Email 사용자',
'email_smtp' => 'Enable SMTP',
'email_smtp_host' => 'SMTP host',
'email_smtp_port' => 'SMTP port',
'email_smtp_username' => 'SMTP username',
'email_smtp_password' => 'SMTP password',
'email_smtp_noauth' => 'Leave blank for no authentication',
'sms_status' => 'SMS전송 허용',
'sms_gateway' => '메세지 전송을 위한 게이트웨이 허용',
'sms_gateway_mosms' => 'Mosms',

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
$sm_lang = array(
@ -95,6 +95,12 @@ $sm_lang = array(
'email_status' => 'Sta email berichten toe?',
'email_from_email' => 'Email van adres',
'email_from_name' => 'Email van naam',
'email_smtp' => 'SMTP gebruiken',
'email_smtp_host' => 'SMTP host',
'email_smtp_port' => 'SMTP poort',
'email_smtp_username' => 'SMTP gebruikersnaam',
'email_smtp_password' => 'SMTP wachtwoord',
'email_smtp_noauth' => 'Laat leeg voor geen authenticatie',
'sms_status' => 'Sta SMS berichten toe?',
'sms_gateway' => 'Gateway voor het sturen van SMS',
'sms_gateway_mosms' => 'Mosms',

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Module;

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Module;
@ -31,6 +31,36 @@ use psm\Service\Template;
class Config extends AbstractModule {
/**
* Checkboxes
* @var array $checkboxes
*/
protected $checkboxes = array(
'email_status',
'email_smtp',
'sms_status',
'log_status',
'log_email',
'log_sms',
'show_update',
);
/**
* Fields for saving
* @var array $fields
*/
protected $fields = array(
'email_from_name',
'email_from_email',
'email_smtp_host',
'email_smtp_port',
'email_smtp_username',
'email_smtp_password',
'sms_gateway_username',
'sms_gateway_password',
'sms_from',
);
function __construct(Database $db, Template $tpl) {
parent::__construct($db, $tpl);
@ -74,25 +104,23 @@ class Config extends AbstractModule {
}
$this->tpl->addTemplateDataRepeat($this->getTemplateId(), 'languages', $languages);
$this->tpl->addTemplateData(
$this->getTemplateId(),
array(
'email_status_checked' => ($config['email_status'] == '1') ? 'checked="checked"' : '',
'email_from_name' => $config['email_from_name'],
'email_from_email' => $config['email_from_email'],
'sms_status_checked' => ($config['sms_status'] == '1') ? 'checked="checked"' : '',
'sms_selected_' . $config['sms_gateway'] => 'selected="selected"',
'sms_gateway_username' => $config['sms_gateway_username'],
'sms_gateway_password' => $config['sms_gateway_password'],
'sms_from' => $config['sms_from'],
'alert_type_selected_' . $config['alert_type'] => 'selected="selected"',
'log_status_checked' => ($config['log_status'] == '1') ? 'checked="checked"' : '',
'log_email_checked' => ($config['log_email'] == '1') ? 'checked="checked"' : '',
'log_sms_checked' => ($config['log_sms'] == '1') ? 'checked="checked"' : '',
'show_update_checked' => ($config['show_update'] == '1') ? 'checked="checked"' : '',
'auto_refresh_servers' => (isset($config['auto_refresh_servers'])) ? $config['auto_refresh_servers'] : '0',
)
$tpl_data = array(
'sms_selected_' . $config['sms_gateway'] => 'selected="selected"',
'alert_type_selected_' . $config['alert_type'] => 'selected="selected"',
'auto_refresh_servers' => (isset($config['auto_refresh_servers'])) ? $config['auto_refresh_servers'] : '0',
);
foreach($this->checkboxes as $input_key) {
$tpl_data[$input_key . '_checked'] =
(isset($config[$input_key]) && (int) $config[$input_key] == 1)
? 'checked="checked"'
: '';
}
foreach($this->fields as $input_key) {
$tpl_data[$input_key] = (isset($config[$input_key])) ? $config[$input_key] : '';
}
$this->tpl->addTemplateData($this->getTemplateId(), $tpl_data);
}
/**
@ -104,21 +132,18 @@ class Config extends AbstractModule {
// save new config
$clean = array(
'language' => $_POST['language'],
'show_update' => (isset($_POST['show_update'])) ? '1' : '0',
'email_status' => (isset($_POST['email_status'])) ? '1' : '0',
'email_from_name' => $_POST['email_from_name'],
'email_from_email' => $_POST['email_from_email'],
'sms_status' => (isset($_POST['sms_status'])) ? '1' : '0',
'sms_gateway' => $_POST['sms_gateway'],
'sms_gateway_username' => $_POST['sms_gateway_username'],
'sms_gateway_password' => $_POST['sms_gateway_password'],
'sms_from' => $_POST['sms_from'],
'alert_type' => $_POST['alert_type'],
'log_status' => (isset($_POST['log_status'])) ? '1' : '0',
'log_email' => (isset($_POST['log_email'])) ? '1' : '0',
'log_sms' => (isset($_POST['log_sms'])) ? '1' : '0',
'auto_refresh_servers' => (isset($_POST['auto_refresh_servers'])) ? intval($_POST['auto_refresh_servers']) : '0',
);
foreach($this->checkboxes as $input_key) {
$clean[$input_key] = (isset($_POST[$input_key])) ? '1': '0';
}
foreach($this->fields as $input_key) {
if(isset($_POST[$input_key])) {
$clean[$input_key] = $_POST[$input_key];
}
}
// save all values to the database
foreach($clean as $key => $value) {
@ -167,6 +192,12 @@ class Config extends AbstractModule {
'label_email_status' => psm_get_lang('config', 'email_status'),
'label_email_from_email' => psm_get_lang('config', 'email_from_email'),
'label_email_from_name' => psm_get_lang('config', 'email_from_name'),
'label_email_smtp' => psm_get_lang('config', 'email_smtp'),
'label_email_smtp_host' => psm_get_lang('config', 'email_smtp_host'),
'label_email_smtp_port' => psm_get_lang('config', 'email_smtp_port'),
'label_email_smtp_username' => psm_get_lang('config', 'email_smtp_username'),
'label_email_smtp_password' => psm_get_lang('config', 'email_smtp_password'),
'label_email_smtp_noauth' => psm_get_lang('config', 'email_smtp_noauth'),
'label_sms_status' => psm_get_lang('config', 'sms_status'),
'label_sms_gateway' => psm_get_lang('config', 'sms_gateway'),
'label_sms_gateway_mosms' => psm_get_lang('config', 'sms_gateway_mosms'),
@ -187,6 +218,7 @@ class Config extends AbstractModule {
'label_log_email' => psm_get_lang('config', 'log_email'),
'label_log_sms' => psm_get_lang('config', 'log_sms'),
'label_auto_refresh_servers' => psm_get_lang('config', 'auto_refresh_servers'),
'label_save' => psm_get_lang('system', 'save'),
)
);

14
src/psm/Module/Install.class.php Normal file → Executable file
View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
* @since phpservermon 2.1.0
**/
@ -103,9 +103,9 @@ class Install extends AbstractModule {
} else {
$this->addResult('cURL installed');
}
if(!function_exists('mysql_connect')) {
if(!in_array('mysql', \PDO::getAvailableDrivers())) {
$errors++;
$this->addResult('php-mysql needs to be installed.', 'error');
$this->addResult('The PDO MySQL driver needs to be installed.', 'error');
}
if($errors > 0) {
@ -170,7 +170,7 @@ class Install extends AbstractModule {
$config['name']
);
if(is_resource($this->db->getLink())) {
if($this->db->status()) {
$this->addResult('Connection to MySQL successful.');
$config_php = $this->writeConfigFile($config);
if($config_php === true) {
@ -222,7 +222,7 @@ class Install extends AbstractModule {
$this->addResult('No valid configuration found.', 'error');
return $this->executeConfig();
}
if(!is_resource($this->db->getLink())) {
if(!$this->db->status()) {
$this->addResult('MySQL connection failed.', 'error');
return;
}
@ -234,7 +234,7 @@ class Install extends AbstractModule {
if(!empty($if_table_exists)) {
$this->addResult('Table ' . $name . ' already exists in your database!');
} else {
$this->db->query($sql);
$this->db->exec($sql);
$this->addResult('Table ' . $name . ' added.');
}
}
@ -256,7 +256,7 @@ class Install extends AbstractModule {
$install_queries = $queries->upgrade(PSM_VERSION, $version_from);
foreach($install_queries as $sql) {
$this->db->query($sql);
$this->db->exec($sql);
}
$this->addResult('Installation finished!');

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Module;

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
* @since phpservermon 2.1
**/

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Module;

View File

@ -23,7 +23,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Module;

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Module;

View File

@ -22,123 +22,137 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Service;
class Database {
protected $debug = array();
protected $last_inserted_id;
protected $link;
protected $num_rows_found;
protected $num_rows_returned;
function __construct($host = null, $user = null, $pass = null, $db = null) {
if($host != null && $user != null && $pass != null && $db != null) {
$this->connect($host, $user, $pass, $db);
} elseif(defined('PSM_DB_HOST') && defined('PSM_DB_USER') && defined('PSM_DB_PASS') && defined('PSM_DB_NAME')) {
$this->connect(PSM_DB_HOST, PSM_DB_USER, PSM_DB_PASS, PSM_DB_NAME);
}
}
/**
* DB hostname
* @var string $db_host
*/
protected $db_host;
/**
* Connect to the database
* DB name
* @var string $db_name
*/
protected $db_name;
/**
* DB user password
* @var string $db_pass
*/
protected $db_pass;
/**
* DB username
* @var string $db_user
*/
protected $db_user;
/**
* PDOStatement of last query
* @var \PDOStatement $last
*/
protected $last;
/**
* Mysql db connection identifer
* @var \PDO $pdo
* @see pdo()
*/
protected $pdo;
/**
* Connect status
* @var boolean
* @see connect()
*/
protected $status = false;
/**
* Constructor
*
* @param string $host
* @param string $db
* @param string $user
* @param string $pass
* @param string $db
* @return boolean
*/
protected function connect($host, $user, $pass, $db) {
$this->link = mysql_connect($host, $user, $pass);
if (!mysql_select_db($db, $this->link)) {
trigger_error(mysql_errno() . ": " . mysql_error());
return false;
function __construct($host = null, $user = null, $pass = null, $db = null) {
if($host != null && $user != null && $pass != null && $db != null) {
$this->db_host = $host;
$this->db_name = $db;
$this->db_user = $user;
$this->db_pass = $pass;
$this->connect();
} elseif(defined('PSM_DB_HOST') && defined('PSM_DB_USER') && defined('PSM_DB_PASS') && defined('PSM_DB_NAME')) {
$this->db_host = PSM_DB_HOST;
$this->db_name = PSM_DB_NAME;
$this->db_user = PSM_DB_USER;
$this->db_pass = PSM_DB_PASS;
$this->connect();
}
mysql_query("SET NAMES utf8;", $this->link);
mysql_query("SET CHARACTER SET 'utf8';", $this->link);
return true;
}
/**
* Executes a query
* Exectues query and fetches result.
*
* @param $sql string MySQL query
* @return resource mysql resource
* If you dont want to fetch a result, use exec().
* @param string $query SQL query
* @param boolean $fetch automatically fetch results, or return PDOStatement?
* @return array|\PDOStatement if $fetch = true, array, otherwise \PDOStatement
*/
public function executeQuery($sql) {
$result = mysql_query($sql, $this->getLink());
if (mysql_error($this->getLink())) {
trigger_error(mysql_errno($this->getLink()) . ': ' . mysql_error($this->getLink()));
return false;
}
if (is_resource($result) && mysql_num_rows($result) > 0) {
// Rows returned
$this->num_rows_returned = mysql_num_rows($result);
// Rows found
$result_num_rows_found = $this->fetchResults(mysql_query('SELECT FOUND_ROWS();'));
$this->num_rows_found = $result_num_rows_found[0]['FOUND_ROWS()'];
}
if (substr(strtolower(trim($sql)), 0, 6) == 'insert') {
// we have an insert
$this->last_inserted_id = mysql_insert_id($this->getLink());
$result = $this->last_inserted_id;
}
return $result;
}
/**
* Exectues query and fetches result
*
* @param $query string MySQL query
* @return $result array
*/
public function query($query) {
public function query($query, $fetch = true) {
// Execute query and process results
$result_resource = $this->executeQuery($query);
$result = $this->fetchResults($result_resource);
try {
$this->last = $this->pdo()->query($query);
} catch (\PDOException $e) {
$this->error($e);
}
if($fetch && $this->last != false) {
$cmd = strtolower(substr($query, 0, 6));
switch($cmd) {
case 'insert':
// insert query, return insert id
$result = $this->getLastInsertedId();
break;
case 'update':
case 'delete':
// update/delete, returns rowCount
$result = $this->getNumRows();
break;
default:
$result = $this->last->fetchAll(\PDO::FETCH_ASSOC);
break;
}
} else {
$result = $this->last;
}
return $result;
}
/**
* Fetch results from a query
*
* @param resource $result result from a mysql query
* @return array $array with results (multi-dimimensial) for more than one rows
* Execute SQL statement and return number of affected rows
* @param string $query
* @return int
*/
public function fetchResults($result_query){
if (!is_resource($result_query)) {
return array();
public function exec($query) {
try {
$this->last = $this->pdo()->exec($query);
} catch (\PDOException $e) {
$this->error($e);
}
$num_rows = mysql_num_rows($result_query);
$result = array();
while($record = mysql_fetch_assoc($result_query)) {
$result[] = $record;
}
return $result;
return $this->last;
}
/**
* Performs a select on the given table and returns an multi dimensional associative array with results
*
* @param string $table tablename
* @param mixed $where string or array with where data
* @param array $fields array with fields to be retrieved. if empty all fields will be retrieved
@ -147,7 +161,6 @@ class Database {
* @param string $direction ASC or DESC. Defaults to ASC
* @return array multi dimensional array with results
*/
public function select($table, $where = null, $fields = null, $limit = '', $orderby = null, $direction = 'ASC'){
// build query
$query_parts = array();
@ -164,16 +177,11 @@ class Database {
$query_parts[] = "FROM `{$table}`";
// Where clause
$query_parts[] = $this->buildWhereClause($table, $where);
$query_parts[] = $this->buildSQLClauseWhere($table, $where);
// Order by
if ($orderby !== null && !empty($orderby)) {
$orderby_clause = 'ORDER BY ';
foreach($orderby as $field) {
$orderby_clause .= "`{$field}`, ";
}
$query_parts[] = substr($orderby_clause, 0, -2) . ' ' . $direction;
if($orderby) {
$query_parts[] = $this->buildSQLClauseOrderBy($orderby, $direction);
}
// Limit
@ -183,203 +191,307 @@ class Database {
$query = implode(' ', $query_parts);
// Get results
$result = $this->query($query);
return $result;
return $this->query($query);
}
public function selectRow($table, $where = null, $fields = null, $limit = '', $orderby = null, $direction = 'ASC') {
$result = $this->select($table, $where, $fields, $limit, $orderby, $direction);
/**
* Alias to select() but uses limit = 1 to return only one row.
* @param string $table tablename
* @param mixed $where string or array with where data
* @param array $fields array with fields to be retrieved. if empty all fields will be retrieved
* @param array $orderby fields for the orderby clause
* @param string $direction ASC or DESC. Defaults to ASC
* @return array
*/
public function selectRow($table, $where = null, $fields = null, $orderby = null, $direction = 'ASC') {
$result = $this->select($table, $where, $fields, '1', $orderby, $direction);
if ($this->getNumRowsReturned() == '1') {
if(isset($result[0])) {
$result = $result[0];
}
return $result;
}
/**
* Remove a record from database
*
* @param string $table tablename
* @param mixed $where Where clause array or primary Id (string) or where clause (string)
* @return boolean
* @return int number of affected rows
*/
public function delete($table, $where = null){
$sql = 'DELETE FROM `'.$table.'` ' . $this->buildSQLClauseWhere($table, $where);
if ($table != '') {
$sql = 'DELETE FROM `'.$table.'` ' . $this->buildWhereClause($table, $where);
$this->query($sql);
}
return $this->exec($sql);
}
/**
* Insert or update data to the database
*
* @param array $table table name
* @param string $table table name
* @param array $data data to save or insert
* @param mixed $where either string ('user_id=2' or just '2' (works only with primary field)) or array with where clause (only when updating)
*/
public function save($table, $data, $where = null) {
public function save($table, array $data, $where = null) {
if ($where === null) {
// insert mode
$query = "INSERT INTO ";
$exec = false;
} else {
$query = "UPDATE ";
$exec = true;
}
$query .= "`{$table}` SET ";
foreach($data as $field => $value) {
$value = $this->escapeValue($value);
$query .= "`{$table}`.`{$field}`='{$value}', ";
if(is_null($value)) {
$value = 'NULL';
} else {
$value = $this->quote($value);
}
$query .= "`{$table}`.`{$field}`={$value}, ";
}
$query = substr($query, 0, -2) . ' ' . $this->buildWhereClause($table, $where);
$query = substr($query, 0, -2) . ' ' . $this->buildSQLClauseWhere($table, $where);
return $this->query($query);
if($exec) {
return $this->exec($query);
} else {
return $this->query($query);
}
}
/**
* Insert multiple rows into a single table
*
* This method is preferred over calling the insert() lots of times
* so it can be optimized to be inserted with 1 query.
* It can only be used if all inserts have the same fields, records
* that do not match the fields provided in the first record will be
* skipped.
*
* @param type $table
* @param array $data
* @return \PDOStatement
* @see insert()
*/
public function insertMultiple($table, array $data) {
if(empty($data)) return false;
// prepare first part
$query = "INSERT INTO `{$table}` ";
$fields = array_keys($data[0]);
$query .= "(`".implode('`,`', $fields)."`) VALUES ";
// prepare all rows to be inserted with placeholders for vars (\?)
$q_part = array_fill(0, count($fields), '?');
$q_part = "(".implode(',', $q_part).")";
$q_part = array_fill(0, count($data), $q_part);
$query .= implode(',', $q_part);
$pst = $this->pdo()->prepare($query);
$i = 1;
foreach($data as $row) {
// make sure the fields of this row are identical to first row
$diff_keys = array_diff_key($fields, array_keys($row));
if(!empty($diff_keys)) {
continue;
}
foreach($fields as $field) {
$pst->bindParam($i++, $row[$field]);
}
}
try {
$this->last = $pst->execute();
} catch (\PDOException $e) {
$this->error($e);
}
return $this->last;
}
/**
* Quote a string
* @param string $value
* @return string
*/
public function quote($value) {
return $this->pdo()->quote($value);
}
/**
* Get the PDO object
* @return \PDO
*/
public function pdo() {
return $this->pdo;
}
/**
* Get number of rows of last statement
* @return int number of rows
*/
public function getNumRows() {
return $this->last->rowCount();
}
/**
* Get the last inserted id after an insert
* @return int
*/
public function getLastInsertedId() {
return $this->pdo()->lastInsertId();
}
/**
* Build WHERE clause for query
*
* @param string $table table name
* @param mixed $where can be primary id (eg '2'), can be string (eg 'name=pepe') or can be array
* @return string sql where clause
* @see buildSQLClauseOrderBy()
*/
public function buildWhereClause($table, $where = null) {
public function buildSQLClauseWhere($table, $where = null) {
$query = '';
if ($where !== null) {
if (is_array($where)) {
$query .= " WHERE ";
if ($where !== null) {
if (is_array($where)) {
$query .= " WHERE ";
foreach($where as $field => $value) {
$value = $this->escapeValue($value);
$query .= "`{$table}`.`{$field}`='{$value}' AND ";
}
$query = substr($query, 0, -5);
} else {
if (strpos($where, '=') === false) {
// no field given, use primary field
$structure = $this->getTableStructure($table);
$where = $this->escapeValue($where);
$query .= " WHERE `{$table}`.`{$structure['primary']}`='{$where}'";
} elseif (strpos(strtolower(trim($where)), 'where') === false) {
$query .= " WHERE {$where}";
} else {
$query .= ' '.$where;
}
}
}
foreach($where as $field => $value) {
$query .= "`{$table}`.`{$field}`={$this->quote($value)} AND ";
}
$query = substr($query, 0, -5);
} else {
if (strpos($where, '=') === false) {
// no field given, use primary field
$primary = $this->getPrimary($table);
$query .= " WHERE `{$table}`.`{$primary}`={$this->quote($where)}";
} elseif (strpos(strtolower(trim($where)), 'where') === false) {
$query .= " WHERE {$where}";
} else {
$query .= ' '.$where;
}
}
}
return $query;
}
/**
* Get table structure and primary key
*
* @param string $table table name
* @return array primary key and database structure
*/
public function getTableStructure($table) {
if ($table == '') return false;
* Build ORDER BY clause for a query
* @param mixed $order_by can be string (with or without order by) or array
* @param string $direction
* @return string sql order by clause
* @see buildSQLClauseWhere()
*/
public function buildSQLClauseOrderBy($order_by, $direction) {
$query = '';
$structure = $this->query("DESCRIBE `{$table}`");
if ($order_by !== null) {
if (is_array($order_by)) {
$query .= " ORDER BY ";
if (empty($structure)) return false;
// use arrray search function to get primary key
$search_needle = array(
'key' => 'Key',
'value' => 'PRI'
);
$primary = pep_array_search_key_value(
$structure,
array(
'key' => 'Key',
'value' => 'PRI'
)
);
$primary_field = $structure[$primary[0]['path'][0]]['Field'];
return array(
'primary' => $primary_field,
'fields' => $structure
);
}
/**
* Get information about a field from the database
*
* @param string $table
* @param string $field
* @return array mysql field information
*/
public function getFieldInfo($table, $field) {
if ($table == '' || $field == '') return array();
$db_structure = $this->getTableStructure($table);
$field_info = pep_array_search_key_value(
$db_structure,
array(
'key' => 'Field',
'value' => $field
)
);
if (empty($field_info)) {
return array();
foreach($order_by as $field) {
$query .= "`{$field}`, ";
}
// remove trailing ", "
$query = substr($query, 0, -2);
} else {
if (strpos(strtolower(trim($order_by)), 'order by') === false) {
$query .= " ORDER BY {$order_by}";
} else {
$query .= ' '.$order_by;
}
}
}
if(strlen($query) > 0) {
// check if "ASC" or "DESC" is already in the order by clause
if(strpos(strtolower(trim($query)), 'asc') === false && strpos(strtolower(trim($query)), 'desc') === false) {
$query .= ' '.$direction;
}
}
// return field info
return $field_info[0]['result'];
return $query;
}
/**
* Formats the value for the SQL query to secure against injections
*
* @param string $value
* Get the host of the current connection
* @return string
*/
public function escapeValue($value) {
if(get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
$value = mysql_real_escape_string($value, $this->link);
return $value;
public function getDbHost() {
return $this->db_host;
}
/**
* Get number of rows found
*
* @return int number of rows found
*/
public function getNumRowsFound() {
return $this->num_rows_found;
}
/**
* Get number of rows returned
*
* @return int number of rows returned
*/
public function getNumRowsReturned() {
return $this->num_rows_returned;
}
/**
* Get the db name of the current connection
* @return string
*/
public function getDbName() {
return $this->db_name;
}
/**
* Get the database connection identifier
*
* @return object db connection
*/
public function getLink() {
return $this->link;
* Get the db user of the current connection
* @return string
*/
public function getDbUser() {
return $this->db_user;
}
/**
* Get status of the connection
* @return boolean
*/
public function status() {
return $this->status;
}
/**
* Connect to the database.
*
* @return resource mysql resource
*/
protected function connect() {
// Initizale connection
try {
$this->pdo = new \PDO(
'mysql:host='.$this->db_host.';dbname='.$this->db_name.';charset=utf8',
$this->db_user,
$this->db_pass
);
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->status = true;
} catch (\PDOException $e) {
$this->status = false;
return $this->onConnectFailure($e);
}
return $this->pdo;
}
/**
* Is called after connection failure
*/
protected function onConnectFailure(\PDOException $e) {
trigger_error('MySQL connection failed: '.$e->getMessage(), E_USER_WARNING);
return false;
}
/**
* Disconnect from current link
*/
protected function disconnect() {
$this->pdo = null;
}
/**
* Handle a PDOException
* @param \PDOException $e
*/
protected function error(\PDOException $e) {
trigger_error('SQL error: ' . $e->getMessage(), E_USER_WARNING);
}
}

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Service;
@ -93,9 +93,6 @@ class Template {
}
foreach($data as $key => $value) {
// check if $value is a file
$value = (file_exists($value)) ? $this->parseFile($value) : $value;
$this->templates[$id] = str_replace('{'.$key.'}', $value, $this->templates[$id]);
}
return $this->templates[$id];

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Txtmsg;

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Txtmsg;

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Txtmsg;

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Txtmsg;

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
* @since phpservermon 2.1
**/

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Txtmsg;

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
* @since phpservermon 2.1
**/

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Txtmsg;

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
* @since phpservermon 2.1.0
**/

57
src/psm/Util/Mailer.class.php Executable file
View File

@ -0,0 +1,57 @@
<?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 2.2.0
**/
namespace psm\Util;
/**
* PHPMailer is not using namespaces so unable to load files in autoloader.
*/
require_once(PSM_PATH_VENDOR . '/PHPMailer/class.phpmailer.php');
require_once(PSM_PATH_VENDOR . '/PHPMailer/class.smtp.php');
/**
* PSM Mailer utility
*
* The PHPMailer is an open source lib that can be found in vendor/PHPMailer.
*
* @see \PHPMailer
*/
class Mailer extends \PHPMailer {
/**
* Open new PHPMailer
*
* @param boolean $exceptions
*/
function __construct($exceptions = false) {
parent::__construct($exceptions);
}
}
?>

View File

@ -22,7 +22,7 @@
* @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://phpservermon.neanderthal-technology.com/
* @link http://www.phpservermonitor.org/
**/
namespace psm\Util\Updater;
@ -122,20 +122,13 @@ class Status {
$time = explode(' ', microtime());
$starttime = $time[1] + $time[0];
$ch = curl_init();
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, $this->server['ip']);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt ($ch, CURLOPT_TIMEOUT, 10);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11');
// We're only interested in the header, because that should tell us plenty!
// unless we have a pattern to search for!
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, ($this->server['pattern'] != '' ? false : true));
$curl_result = curl_exec ($ch);
curl_close ($ch);
$curl_result = psm_curl_get(
$this->server['ip'],
true,
($this->server['pattern'] == '' ? false : true)
);
$time = explode(" ", microtime());
$endtime = $time[1] + $time[0];
@ -260,10 +253,7 @@ class Status {
}
// build mail object with some default values
$mail = new \phpmailer();
$mail->From = psm_get_conf('email_from_email');
$mail->FromName = psm_get_conf('email_from_name');
$mail = psm_build_mail();
$mail->Subject = psm_parse_msg($this->status_new, 'email_subject', $this->server);
$mail->Priority = 1;

View File

@ -1,13 +1,21 @@
<!--%tpl_config-->
{config_update}
<div class="span12">
<form class="form-horizontal well" action="index.php?type=config&action=save" id="edit_config" method="post">
<fieldset>
<form class="form-horizontal well" action="index.php?type=config&action=save" id="edit_config" method="post">
<ul class="nav nav-tabs">
<li class="active"><a href="#config-general" data-toggle="tab">{label_general}</a></li>
<li><a href="#config-email" data-toggle="tab">{label_settings_email}</a></li>
<li><a href="#config-sms" data-toggle="tab">{label_settings_sms}</a></li>
<li><a href="#config-logging" data-toggle="tab">{label_settings_log}</a></li>
</ul>
<div class="tab-content">
<div id="config-general" class="tab-pane active">
<fieldset>
<legend>{label_general}</legend>
<div class="control-group">
<label class="control-label" for="language">{label_language}</label>
<div class="controls">
<select name="language">
<select id="language" name="language">
<!--%tpl_repeat_languages-->
<option value="{value}" {selected}>{label}</option>
<!--%%tpl_repeat_languages-->
@ -16,47 +24,100 @@
</div>
</div>
<div class="control-group">
<label class="control-label" for="auto_refresh_servers">{label_show_update}</label>
<label class="control-label" for="show_update">{label_show_update}</label>
<div class="controls">
<input type="checkbox" name="show_update[]" {show_update_checked} />
<input type="checkbox" id="show_update" name="show_update[]" {show_update_checked} />
</div>
</div>
<div class="control-group">
<label class="control-label" for="auto_refresh_servers">{label_auto_refresh_servers}</label>
<div class="controls">
<input type="text" name="auto_refresh_servers" value="{auto_refresh_servers}" maxlength="10" />&nbsp;seconds
<input type="text" id="auto_refresh_servers" name="auto_refresh_servers" value="{auto_refresh_servers}" maxlength="10" />&nbsp;seconds
</div>
</div>
<legend>{label_settings_notification}</legend>
<div class="control-group">
<label class="control-label" for="alert_type">{label_alert_type}</label>
<div class="controls">
<select id="alert_type" name="alert_type">
<option value="status" {alert_type_selected_status}>{label_alert_type_status}</option>
<option value="offline" {alert_type_selected_offline}>{label_alert_type_offline}</option>
<option value="always" {alert_type_selected_always}>{label_alert_type_always}</option>
</select>
<p class="help-block">
{label_alert_type_description}
</p>
</div>
</div>
<div class="form-actions">
<button class="btn btn-success" type="submit">{label_save}</button>
</div>
</fieldset>
</div>
<div id="config-email" class="tab-pane">
<fieldset>
<legend>{label_settings_email}</legend>
<div class="control-group">
<label class="control-label" for="email_status">{label_email_status}</label>
<div class="controls">
<input type="checkbox" name="email_status[]" {email_status_checked} />
<input type="checkbox" id="email_status" name="email_status[]" {email_status_checked} />
</div>
</div>
<div class="control-group">
<label class="control-label" for="email_from_name">{label_email_from_name}</label>
<div class="controls">
<input type="text" name="email_from_name" value="{email_from_name}" maxlength="255" />
<input type="text" id="email_from_name" name="email_from_name" value="{email_from_name}" maxlength="255" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="email_from_email">{label_email_from_email}</label>
<div class="controls">
<input type="text" name="email_from_email" value="{email_from_email}" maxlength="255" />
<input type="text" id="email_from_email" name="email_from_email" value="{email_from_email}" maxlength="255" />
</div>
</div>
<legend>{label_settings_sms}</legend>
<div class="control-group">
<label class="control-label" for="email_smtp">{label_email_smtp}</label>
<div class="controls">
<input type="checkbox" id="email_smtp" name="email_smtp[]" {email_smtp_checked} />
</div>
</div>
<div class="control-group">
<label class="control-label" for="email_smtp_host">{label_email_smtp_host}</label>
<div class="controls">
<input type="text" id="email_smtp_host" name="email_smtp_host" value="{email_smtp_host}" maxlength="100" placeholder="{label_email_smtp_host}" />
<input type="text" class="input-small" id="email_smtp_port" name="email_smtp_port" value="{email_smtp_port}" maxlength="10" placeholder="{label_email_smtp_port}" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="email_smtp_username">{label_email_smtp_username}</label>
<div class="controls">
<input type="text" id="email_smtp_username" name="email_smtp_username" value="{email_smtp_username}" maxlength="100" placeholder="{label_email_smtp_noauth}" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="email_smtp_password">{label_email_smtp_password}</label>
<div class="controls">
<input type="password" id="email_smtp_password" name="email_smtp_password" value="{email_smtp_password}" maxlength="100" placeholder="{label_email_smtp_noauth}" />
</div>
</div>
<div class="form-actions">
<button class="btn btn-success" type="submit">{label_save}</button>
</div>
</fieldset>
</div>
<div id="config-sms" class="tab-pane">
<fieldset>
<legend>{label_settings_sms}</legend>
<div class="control-group">
<label class="control-label" for="sms_status">{label_sms_status}</label>
<div class="controls">
<input type="checkbox" name="sms_status[]" {sms_status_checked} />
<input type="checkbox" id="sms_status" name="sms_status[]" {sms_status_checked} />
</div>
</div>
<div class="control-group">
<label class="control-label" for="sms_gateway">{label_sms_gateway}</label>
<div class="controls">
<select name="sms_gateway">
<select id="sms_gateway" name="sms_gateway">
<option value="mosms" {sms_selected_mosms}>{label_sms_gateway_mosms}</option>
<option value="mollie" {sms_selected_mollie}>{label_sms_gateway_mollie}</option>
<option value="spryng" {sms_selected_spryng}>{label_sms_gateway_spryng}</option>
@ -69,58 +130,53 @@
<div class="control-group">
<label class="control-label" for="sms_gateway_username">{label_sms_gateway_username}</label>
<div class="controls">
<input type="text" name="sms_gateway_username" value="{sms_gateway_username}" maxlength="255" />
<input type="text" id="sms_gateway_username" name="sms_gateway_username" value="{sms_gateway_username}" maxlength="255" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="sms_gateway_password">{label_sms_gateway_password}</label>
<div class="controls">
<input type="password" name="sms_gateway_password" value="{sms_gateway_password}" maxlength="255" />
<input type="password" id="sms_gateway_password" name="sms_gateway_password" value="{sms_gateway_password}" maxlength="255" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="sms_from">{label_sms_from}</label>
<div class="controls">
<input type="text" name="sms_from" value="{sms_from}" maxlength="255" />
<input type="text" id="sms_from" name="sms_from" value="{sms_from}" maxlength="255" />
</div>
</div>
<legend>{label_settings_notification}</legend>
<div class="control-group">
<label class="control-label" for="alert_type">{label_alert_type}</label>
<div class="controls">
<select name="alert_type">
<option value="status" {alert_type_selected_status}>{label_alert_type_status}</option>
<option value="offline" {alert_type_selected_offline}>{label_alert_type_offline}</option>
<option value="always" {alert_type_selected_always}>{label_alert_type_always}</option>
</select>
<p class="help-block">
{label_alert_type_description}
</p>
</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">
<label class="control-label" for="log_status">{label_log_status}</label>
<div class="controls">
<input type="checkbox" name="log_status[]" {log_status_checked} />
<input type="checkbox" id="log_status" name="log_status[]" {log_status_checked} />
</div>
</div>
<div class="control-group">
<label class="control-label" for="log_status">{label_log_email}</label>
<label class="control-label" for="log_email">{label_log_email}</label>
<div class="controls">
<input type="checkbox" name="log_email[]" {log_email_checked} />
<input type="checkbox" id="log_email" name="log_email[]" {log_email_checked} />
</div>
</div>
<div class="control-group">
<label class="control-label" for="log_sms">{label_log_sms}</label>
<div class="controls">
<input type="checkbox" name="log_sms[]" {log_sms_checked} />
<input type="checkbox" id="log_sms" name="log_sms[]" {log_sms_checked} />
</div>
</div>
<div class="form-actions">
<button class="btn btn-success" type="submit">Save</button>
<button class="btn btn-success" type="submit">{label_save}</button>
</div>
</fieldset>
</fieldset>
</div>
</div>
</form>
</div>
<!--%%tpl_config-->

View File

@ -3,7 +3,7 @@
<h1><img class="pull-right" src="static/opensource.png" width="100" alt="" /> &nbsp;PHP Server Monitor</h1>
<p>&nbsp;</p>
<p>
<a class="btn btn-primary btn-large" target="_blank" href="http://phpservermon.neanderthal-technology.com">PHP Server Monitor</a>
<a class="btn btn-primary btn-large" target="_blank" href="http://www.phpservermonitor.org/">PHP Server Monitor</a>
<a class="btn btn-large" target="_blank" href="http://twitter.github.com/bootstrap/">Twitter Bootstrap</a>
</p>
<p>PHP Server Monitor is a script that checks whether the servers on your list are up and running on the selected ports. It comes with a web based user interface where you can add and remove servers or websites from the MySQL database, and you can manage users for each server with a mobile number and email address.</p>

View File

@ -87,7 +87,7 @@
<a href="index.php?action=check">{label_update}</a>
</li>
<li id="nav_option_help">
<a href="http://phpservermon.sourceforge.net" target="_blank">{label_help}</a>
<a href="http://www.phpservermonitor.org/" target="_blank">{label_help}</a>
</li>
</ul>
</div>
@ -101,7 +101,7 @@
<footer class="footer">
<p class="pull-right"><a href="#">{label_back_to_top}</a></p>
<p>
Powered by <a href="http://phpservermon.neanderthal-technology.com" target="_blank">PHP Server Monitor</a> and
Powered by <a href="http://www.phpservermonitor.org/" target="_blank">PHP Server Monitor</a> and
<a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap</a>
<br/>
Copyright &copy; 2008-2014 <a href="mailto:pep@neanderthal-technology.com">Pepijn Over</a>

2949
vendor/PHPMailer/class.phpmailer.php vendored Executable file

File diff suppressed because it is too large Load Diff

1092
vendor/PHPMailer/class.smtp.php vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff