diff --git a/CHANGELOG b/CHANGELOG index 06f2226f..41bffbce 100755 --- a/CHANGELOG +++ b/CHANGELOG @@ -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. \ No newline at end of file +resulting in a wrong list of log entries shown. diff --git a/CREDITS b/CREDITS new file mode 100755 index 00000000..f976ff9f --- /dev/null +++ b/CREDITS @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index f0c93957..48640a6d 100755 --- a/README.md +++ b/README.md @@ -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 ), it will use cURL to open the website and - check the HTTP status code (see 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 . +The latest version can be found at . You can also clone the git repo at 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 diff --git a/cron/status.cron.php b/cron/status.cron.php index c059304f..6a76ed41 100755 --- a/cron/status.cron.php +++ b/cron/status.cron.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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 diff --git a/index.php b/index.php index 39210539..baf1a361 100755 --- a/index.php +++ b/index.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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'; diff --git a/install.php b/install.php index 054283dc..50d0fb8b 100755 --- a/install.php +++ b/install.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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); diff --git a/src/bootstrap.php b/src/bootstrap.php index 754e0609..ec7c84db 100755 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -1,4 +1,30 @@ . + * + * @package phpservermon + * @author Pepijn Over + * @copyright Copyright (c) 2008-2014 Pepijn Over + * @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); -?> \ No newline at end of file +?> diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 2394db59..7bcc6724 100755 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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 diff --git a/src/lang/br.lang.php b/src/lang/br.lang.php index 2670cd4d..bd09e7e9 100755 --- a/src/lang/br.lang.php +++ b/src/lang/br.lang.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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', diff --git a/src/lang/de.lang.php b/src/lang/de.lang.php index ac8fe921..1c210746 100755 --- a/src/lang/de.lang.php +++ b/src/lang/de.lang.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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', diff --git a/src/lang/en.lang.php b/src/lang/en.lang.php index f54896ca..da57f02e 100755 --- a/src/lang/en.lang.php +++ b/src/lang/en.lang.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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', diff --git a/src/lang/fr.lang.php b/src/lang/fr.lang.php index 71915061..72be4ecc 100755 --- a/src/lang/fr.lang.php +++ b/src/lang/fr.lang.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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éditeur', 'email_from_name' => 'Nom de l expé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 à utiliser pour l envoi de SMS', 'sms_gateway_mosms' => 'Mosms', diff --git a/src/lang/kr.lang.php b/src/lang/kr.lang.php index 793a085c..bd0b1ad6 100755 --- a/src/lang/kr.lang.php +++ b/src/lang/kr.lang.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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', diff --git a/src/lang/nl.lang.php b/src/lang/nl.lang.php index 3c786697..c64c1004 100755 --- a/src/lang/nl.lang.php +++ b/src/lang/nl.lang.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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', diff --git a/src/psm/Module/AbstractModule.class.php b/src/psm/Module/AbstractModule.class.php index ef1a5aba..dddad3cf 100755 --- a/src/psm/Module/AbstractModule.class.php +++ b/src/psm/Module/AbstractModule.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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; diff --git a/src/psm/Module/Config.class.php b/src/psm/Module/Config.class.php index d8270848..327315f6 100755 --- a/src/psm/Module/Config.class.php +++ b/src/psm/Module/Config.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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'), ) ); diff --git a/src/psm/Module/Install.class.php b/src/psm/Module/Install.class.php old mode 100644 new mode 100755 index 679765df..9c39a45c --- a/src/psm/Module/Install.class.php +++ b/src/psm/Module/Install.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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!'); diff --git a/src/psm/Module/Log.class.php b/src/psm/Module/Log.class.php index 6e6db989..f5dc7885 100755 --- a/src/psm/Module/Log.class.php +++ b/src/psm/Module/Log.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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; diff --git a/src/psm/Module/ModuleInterface.class.php b/src/psm/Module/ModuleInterface.class.php index a9cadf6e..2f5930be 100644 --- a/src/psm/Module/ModuleInterface.class.php +++ b/src/psm/Module/ModuleInterface.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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 **/ diff --git a/src/psm/Module/Servers.class.php b/src/psm/Module/Servers.class.php index d19038f5..5b0976f9 100755 --- a/src/psm/Module/Servers.class.php +++ b/src/psm/Module/Servers.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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; diff --git a/src/psm/Module/Status.class.php b/src/psm/Module/Status.class.php index 844bbe0b..98a04bfe 100755 --- a/src/psm/Module/Status.class.php +++ b/src/psm/Module/Status.class.php @@ -23,7 +23,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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; diff --git a/src/psm/Module/Users.class.php b/src/psm/Module/Users.class.php index 71649266..4235bb4a 100755 --- a/src/psm/Module/Users.class.php +++ b/src/psm/Module/Users.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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; diff --git a/src/psm/Service/Database.class.php b/src/psm/Service/Database.class.php index 896eeaf7..4dc998af 100755 --- a/src/psm/Service/Database.class.php +++ b/src/psm/Service/Database.class.php @@ -22,123 +22,137 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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); } } diff --git a/src/psm/Service/Template.class.php b/src/psm/Service/Template.class.php index f67c9624..86d51e45 100755 --- a/src/psm/Service/Template.class.php +++ b/src/psm/Service/Template.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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]; diff --git a/src/psm/Txtmsg/Clickatell.class.php b/src/psm/Txtmsg/Clickatell.class.php index a8bd7538..7b25901e 100755 --- a/src/psm/Txtmsg/Clickatell.class.php +++ b/src/psm/Txtmsg/Clickatell.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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; diff --git a/src/psm/Txtmsg/Core.class.php b/src/psm/Txtmsg/Core.class.php index b6726684..36bf84c6 100755 --- a/src/psm/Txtmsg/Core.class.php +++ b/src/psm/Txtmsg/Core.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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; diff --git a/src/psm/Txtmsg/Inetworx.class.php b/src/psm/Txtmsg/Inetworx.class.php index a327e6b2..70de4032 100755 --- a/src/psm/Txtmsg/Inetworx.class.php +++ b/src/psm/Txtmsg/Inetworx.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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; diff --git a/src/psm/Txtmsg/Mollie.class.php b/src/psm/Txtmsg/Mollie.class.php index cfa3d7ed..2125ecbb 100755 --- a/src/psm/Txtmsg/Mollie.class.php +++ b/src/psm/Txtmsg/Mollie.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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; diff --git a/src/psm/Txtmsg/Mosms.class.php b/src/psm/Txtmsg/Mosms.class.php index 8757cf4a..3389636c 100755 --- a/src/psm/Txtmsg/Mosms.class.php +++ b/src/psm/Txtmsg/Mosms.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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 **/ diff --git a/src/psm/Txtmsg/Spryng.class.php b/src/psm/Txtmsg/Spryng.class.php index 3a81cfa0..015ad33d 100755 --- a/src/psm/Txtmsg/Spryng.class.php +++ b/src/psm/Txtmsg/Spryng.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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; diff --git a/src/psm/Txtmsg/Textmarketer.php b/src/psm/Txtmsg/Textmarketer.php index 9dc2d487..d89fecdf 100755 --- a/src/psm/Txtmsg/Textmarketer.php +++ b/src/psm/Txtmsg/Textmarketer.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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 **/ diff --git a/src/psm/Txtmsg/TxtmsgInterface.class.php b/src/psm/Txtmsg/TxtmsgInterface.class.php index c5f9399d..e679a6c5 100755 --- a/src/psm/Txtmsg/TxtmsgInterface.class.php +++ b/src/psm/Txtmsg/TxtmsgInterface.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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; diff --git a/src/psm/Util/Install/Queries.class.php b/src/psm/Util/Install/Queries.class.php index 2729b170..ab9254ce 100644 --- a/src/psm/Util/Install/Queries.class.php +++ b/src/psm/Util/Install/Queries.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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 **/ diff --git a/src/psm/Util/Mailer.class.php b/src/psm/Util/Mailer.class.php new file mode 100755 index 00000000..cd4931f9 --- /dev/null +++ b/src/psm/Util/Mailer.class.php @@ -0,0 +1,57 @@ +. + * + * @package phpservermon + * @author Pepijn Over + * @copyright Copyright (c) 2008-2014 Pepijn Over + * @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); + + } +} + +?> \ No newline at end of file diff --git a/src/psm/Util/Updater/Status.class.php b/src/psm/Util/Updater/Status.class.php index 0b6b0c94..dbd39cca 100755 --- a/src/psm/Util/Updater/Status.class.php +++ b/src/psm/Util/Updater/Status.class.php @@ -22,7 +22,7 @@ * @copyright Copyright (c) 2008-2014 Pepijn Over * @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; diff --git a/src/templates/config.tpl.html b/src/templates/config.tpl.html index 59d54d1a..7b574598 100755 --- a/src/templates/config.tpl.html +++ b/src/templates/config.tpl.html @@ -1,13 +1,21 @@ {config_update}
-
-
+ + +
+
+
{label_general}
- @@ -16,47 +24,100 @@
- +
- +
-  seconds +  seconds
+ {label_settings_notification} +
+ +
+ +

+ {label_alert_type_description} +

+
+
+
+ +
+
+
+
+
{label_settings_email}
- +
- +
- +
- {label_settings_sms} +
+ +
+ +
+
+
+ +
+ + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+ {label_settings_sms}
- +
- @@ -69,58 +130,53 @@
- +
- +
- +
- {label_settings_notification} -
- -
- -

- {label_alert_type_description} -

-
+
+
+
+
+
+
{label_settings_log}
- +
- +
- +
- +
- +
-
+
+
+ diff --git a/src/templates/install.tpl.html b/src/templates/install.tpl.html index 48842200..598a131f 100755 --- a/src/templates/install.tpl.html +++ b/src/templates/install.tpl.html @@ -3,7 +3,7 @@

 PHP Server Monitor

 

- PHP Server Monitor + PHP Server Monitor Twitter Bootstrap

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.

diff --git a/src/templates/main.tpl.html b/src/templates/main.tpl.html index dfa1fdfc..d8bd955c 100755 --- a/src/templates/main.tpl.html +++ b/src/templates/main.tpl.html @@ -87,7 +87,7 @@ {label_update} @@ -101,7 +101,7 @@