Imported Upstream version 3.3.0

This commit is contained in:
Mario Fetka
2017-10-20 15:00:08 +02:00
parent c4f4701ef1
commit 8b51dbf723
150 changed files with 4395 additions and 4065 deletions

View File

@@ -5,15 +5,15 @@
//
///////////////////////////////////////////////////////////////////////////////
//
// (c) 2005-2012 by Martin Willisegger
// (c) 2005-2017 by Martin Willisegger
//
// Project : NagiosQL
// Component : Configuration Class
// Website : http://www.nagiosql.org
// Date : $LastChangedDate: 2013-01-10 09:46:11 +0100 (Thu, 10 Jan 2013) $
// Date : $LastChangedDate: 2017-06-22 09:29:35 +0200 (Thu, 22 Jun 2017) $
// Author : $LastChangedBy: martin $
// Version : 3.2.0
// Revision : $LastChangedRevision: 1351 $
// Version : 3.3.0
// Revision : $LastChangedRevision: 2 $
//
///////////////////////////////////////////////////////////////////////////////////////////////
//
@@ -50,7 +50,7 @@ class nagconfig {
// Activities during initialisation
//
///////////////////////////////////////////////////////////////////////////////////////////
function nagconfig() {
function __construct() {
if (isset($_SESSION) && isset($_SESSION['SETS'])) {
// Read global settings
$this->arrSettings = $_SESSION['SETS'];
@@ -123,7 +123,7 @@ class nagconfig {
if ($arrConfigId != 1) {
// Define variables
$strTimeFile = "unknown";
$intFileStamp = mktime();
$intFileStamp = time();
foreach($arrConfigId AS $intConfigId) {
// Get configuration file data
$this->getConfigData($intConfigId,"target",$strTarget);
@@ -226,7 +226,7 @@ class nagconfig {
if ($arrConfigId != 1) {
// Define variables
$strTimeFile = "unknown";
$intFileStamp = mktime();
$intFileStamp = time();
foreach($arrConfigId AS $intConfigId) {
// Get configuration file data
$this->getConfigData($intConfigId,"target",$strTarget);
@@ -333,7 +333,7 @@ class nagconfig {
if ($strMethod == 1) {
// Save configuration file
if (file_exists($strConfigDir."/".$strName) && is_writable($strBackupDir) && is_writable($strConfigDir)) {
$strOldDate = date("YmdHis",mktime());
$strOldDate = date("YmdHis",time());
copy($strConfigDir."/".$strName,$strBackupDir."/".$strName."_old_".$strOldDate);
unlink($strConfigDir."/".$strName);
} else if (!is_writable($strBackupDir)) {
@@ -350,7 +350,7 @@ class nagconfig {
// Save configuration file
$intFileStamp = ftp_mdtm($this->resConnectId, $strConfigDir."/".$strName);
if ($intFileStamp > -1) {
$strOldDate = date("YmdHis",mktime());
$strOldDate = date("YmdHis",time());
$intErrorReporting = error_reporting();
error_reporting(0);
$intReturn = ftp_rename($this->resConnectId,$strConfigDir."/".$strName,$strBackupDir."/".$strName."_old_".$strOldDate);
@@ -374,7 +374,7 @@ class nagconfig {
$intFileStamp = $arrInfo['mtime'];
if ($intFileStamp > -1) {
$strOldDate = date("YmdHis",mktime());
$strOldDate = date("YmdHis",time());
$intReturn = ssh2_sftp_rename($this->resSFTP,$strConfigDir."/".$strName,$strBackupDir."/".$strName."_old_".$strOldDate);
if (!$intReturn) {
$this->processClassMessage(translate('Cannot backup the old configuration file because the permissions are wrong (remote SFTP)!')."::",$this->strErrorMessage);
@@ -583,7 +583,7 @@ class nagconfig {
$configtp = new HTML_Template_IT($this->arrSettings['path']['base_path']."/templates/files/");
$configtp->loadTemplatefile($setTemplate, true, true);
$configtp->setOptions($arrTplOptions);
$configtp->setVariable("CREATE_DATE",date("Y-m-d H:i:s",mktime()));
$configtp->setVariable("CREATE_DATE",date("Y-m-d H:i:s",time()));
$this->getConfigData($intConfigID,"version",$this->intNagVersion);
$configtp->setVariable("NAGIOS_QL_VERSION",$this->arrSettings['db']['version']);
if ($this->intNagVersion == 3) $strVersion = "Nagios 3.x config file";
@@ -812,7 +812,7 @@ class nagconfig {
$configtp = new HTML_Template_IT($this->arrSettings['path']['base_path']."/templates/files/");
$configtp->loadTemplatefile($setTemplate, true, true);
$configtp->setOptions($arrTplOptions);
$configtp->setVariable("CREATE_DATE",date("Y-m-d H:i:s",mktime()));
$configtp->setVariable("CREATE_DATE",date("Y-m-d H:i:s",time()));
if ($this->intNagVersion == 0) {
$this->getConfigData($intConfigID,"version",$this->intNagVersion);
}

10
functions/content_class.php Executable file → Normal file
View File

@@ -5,15 +5,15 @@
//
///////////////////////////////////////////////////////////////////////////////
//
// (c) 2005-2012 by Martin Willisegger
// (c) 2005-2017 by Martin Willisegger
//
// Project : NagiosQL
// Component : Content Class
// Website : http://www.nagiosql.org
// Date : $LastChangedDate: 2011-12-08 07:35:31 +0100 (Do, 08. Dez 2011) $
// Date : $LastChangedDate: 2017-06-22 09:29:35 +0200 (Thu, 22 Jun 2017) $
// Author : $LastChangedBy: martin $
// Version : 3.2.0
// Revision : $LastChangedRevision: 1141 $
// Version : 3.3.0
// Revision : $LastChangedRevision: 2 $
//
///////////////////////////////////////////////////////////////////////////////////////////////
//
@@ -55,7 +55,7 @@ class nagcontent {
// Activities during class initialization
//
///////////////////////////////////////////////////////////////////////////////////////////
function nagcontent() {
function __construct() {
// Read global settings
$this->arrSettings = $_SESSION['SETS'];
if (isset($_SESSION['domain'])) $this->intDomainId = $_SESSION['domain'];

View File

@@ -5,15 +5,15 @@
//
///////////////////////////////////////////////////////////////////////////////
//
// (c) 2005-2012 by Martin Willisegger
// (c) 2005-2017 by Martin Willisegger
//
// Project : NagiosQL
// Component : NagiosQL data processing class
// Website : http://www.nagiosql.org
// Date : $LastChangedDate: 2012-03-05 07:55:49 +0100 (Mon, 05 Mar 2012) $
// Date : $LastChangedDate: 2017-06-22 09:29:35 +0200 (Thu, 22 Jun 2017) $
// Author : $LastChangedBy: martin $
// Version : 3.2.0
// Revision : $LastChangedRevision: 1271 $
// Version : 3.3.0
// Revision : $LastChangedRevision: 2 $
//
///////////////////////////////////////////////////////////////////////////////////////////////
//
@@ -44,7 +44,7 @@ class nagdata {
// Activities during initialisation
//
///////////////////////////////////////////////////////////////////////////////////////////
function nagdata() {
function __construct() {
if (isset($_SESSION) && isset($_SESSION['SETS'])) {
// Read global settings
$this->arrSettings = $_SESSION['SETS'];
@@ -113,7 +113,7 @@ class nagdata {
$strSQL = "DELETE FROM `".$strTableName."` WHERE `id` = $intDataId $strNoDelete";
$booReturn = $this->myDBClass->insertData($strSQL);
if ($booReturn == false) {
$this->processClassMessage(translate('Delete failed because a database error:')."::".mysql_error()."::",$this->strInfoMessage);
$this->processClassMessage(translate('Delete failed because a database error:')."::".$this->myDBClass->strErrorMessage."::",$this->strInfoMessage);
return(1);
} else if ($this->myDBClass->intAffectedRows == 0) {
$this->processClassMessage(translate('No data deleted. Probably the dataset does not exist or it is protected from delete.')."::",$this->strErrorMessage);
@@ -137,7 +137,7 @@ class nagdata {
$strSQL = "DELETE FROM `".$strTableName."` WHERE `id` = ".$elem['id'];
$booReturn = $this->myDBClass->insertData($strSQL);
if ($booReturn == false) {
$this->processClassMessage(translate('Delete failed because a database error:')."::".mysql_error()."::",$this->strInfoMessage);
$this->processClassMessage(translate('Delete failed because a database error:')."::".$this->myDBClass->strErrorMessage."::",$this->strInfoMessage);
return(1);
} else {
$intDeleteCount = $intDeleteCount + $this->myDBClass->intAffectedRows;

View File

@@ -5,15 +5,15 @@
//
///////////////////////////////////////////////////////////////////////////////
//
// (c) 2005-2012 by Martin Willisegger
// (c) 2005-2017 by Martin Willisegger
//
// Project : NagiosQL
// Component : Import Class
// Website : http://www.nagiosql.org
// Date : $LastChangedDate: 2012-09-18 10:44:22 +0200 (Tue, 18 Sep 2012) $
// Date : $LastChangedDate: 2017-06-22 13:39:15 +0200 (Thu, 22 Jun 2017) $
// Author : $LastChangedBy: martin $
// Version : 3.2.0
// Revision : $LastChangedRevision: 1346 $
// Version : 3.3.0
// Revision : $LastChangedRevision: 7 $
//
///////////////////////////////////////////////////////////////////////////////////////////////
//
@@ -45,7 +45,7 @@ class nagimport {
// Activities during initialisation
//
///////////////////////////////////////////////////////////////////////////////////////////
function nagimport() {
function __construct() {
if (isset($_SESSION) && isset($_SESSION['SETS'])) {
// Read global settings
$this->arrSettings = $_SESSION['SETS'];
@@ -632,8 +632,8 @@ class nagimport {
if ($strKeyField == "") {$strKey = $strConfigName;} else {$strKey = $strKeyField;}
if ($booResult != true) {
$this->strErrorMessage .= $this->myDBClass->strErrorMessage;
if ($strKeyField != "") $this->strErrorMessage .= translate('Entry')." <b class=\"blackmessage\">".$strKey." -> ".$arrImportData[$strKeyField]['value']."</b> ".translate('inside')." <b class=\"blackmessage\">".$strTable."</b> ".translate('could not be inserted:')." ".mysql_error()."::";
if ($strKeyField == "") $this->strErrorMessage .= translate('Entry')." <b class=\"blackmessage\">".$strTemp1." -> ".$strTemp2.translate('inside')."</b> ".$strTable." <b class=\"blackmessage\">".$strTable."</b> ".translate('could not be inserted:')." ".mysql_error()."::";
if ($strKeyField != "") $this->strErrorMessage .= translate('Entry')." <b class=\"blackmessage\">".$strKey." -> ".$arrImportData[$strKeyField]['value']."</b> ".translate('inside')." <b class=\"blackmessage\">".$strTable."</b> ".translate('could not be inserted:')." ".$this->myDBClass->strErrorMessage."::";
if ($strKeyField == "") $this->strErrorMessage .= translate('Entry')." <b class=\"blackmessage\">".$strTemp1." -> ".$strTemp2.translate('inside')."</b> ".$strTable." <b class=\"blackmessage\">".$strTable."</b> ".translate('could not be inserted:')." ".$this->myDBClass->strErrorMessage."::";
return(1);
} else {
if ($strKeyField != "") $this->strInfoMessage .= translate('Entry')." <b class=\"blackmessage\">".$strKey." -> ".$arrImportData[$strKeyField]['value']."</b> ".translate('inside')." <b class=\"blackmessage\">".$strTable."</b> ".translate('successfully inserted')."::";
@@ -1236,7 +1236,7 @@ class nagimport {
// Update data in master table
$arrCommand[0] = $intSlaveId;
$strValue = implode("!",$arrCommand);
$strSQL = "UPDATE `".$strDataTable."` SET `".$arrRelData['fieldName']."` = '".mysql_real_escape_string($strValue)."' WHERE `id` = ".$intDataId;
$strSQL = "UPDATE `".$strDataTable."` SET `".$arrRelData['fieldName']."` = '".$this->myDBClass->real_escape($strValue)."' WHERE `id` = ".$intDataId;
$booResult = $this->myDBClass->insertData($strSQL);
if ($booResult == false) $this->strErrorMessage .= $this->myDBClass->strErrorMessage;
}

View File

@@ -1,331 +0,0 @@
<?php
///////////////////////////////////////////////////////////////////////////////
//
// NagiosQL
//
///////////////////////////////////////////////////////////////////////////////
//
// (c) 2005-2012 by Martin Willisegger
//
// Project : NagiosQL
// Component : Mysql data processing class
// Website : http://www.nagiosql.org
// Date : $LastChangedDate: 2012-02-21 14:10:41 +0100 (Tue, 21 Feb 2012) $
// Author : $LastChangedBy: martin $
// Version : 3.2.0
// Revision : $LastChangedRevision: 1229 $
//
///////////////////////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////////////////////
//
// Class: Common database functions for MySQL
//
///////////////////////////////////////////////////////////////////////////////////////////////
//
// Includes any functions to communicate with an MySQL database server
//
// Name: mysqldb
//
// Class variables: $arrSettings Includes all global settings ($SETS)
// $strErrorMessage Includes database error messages
// $error Boolean - error occurred (true/false)
// $strDBId Database connection ID
// $intLastId Last insert ID
// $intAffectedRows Counter for affected data rows (INSERT/DELETE/UPDATE)
//
///////////////////////////////////////////////////////////////////////////////////////////////
class mysqldb {
// Define class variables
var $arrSettings; // Will be filled in class constructor
var $error = false; // Will be filled in functions
var $strDBId = ""; // Will be filled in functions
var $intLastId = 0; // Will be filled in functions
var $intAffectedRows = 0; // Will be filled in functions
var $strErrorMessage = ""; // Will be filled in functions
///////////////////////////////////////////////////////////////////////////////////////////
// Class constructor
///////////////////////////////////////////////////////////////////////////////////////////
//
// Activities during initialisation
//
///////////////////////////////////////////////////////////////////////////////////////////
function mysqldb() {
if (isset($_SESSION) && isset($_SESSION['SETS'])) {
// Read global settings
$this->arrSettings = $_SESSION['SETS'];
// Connect to Database
if (isset($this->arrSettings['db'])) $this->getDatabase($this->arrSettings['db']);
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Connect to a database
///////////////////////////////////////////////////////////////////////////////////////////
//
// Opens a connection to the database server and select a database
//
// Parameters: $arrSettings Connection parameter
// -> Key server = Servername
// -> Key username = Benutzername
// -> Key password = Passwort
// -> Key database = Datenbank
//
// Return value: true = successful
// false = error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function getdatabase($arrSettings) {
$this->dbconnect($arrSettings['server'],$arrSettings['port'],$arrSettings['username'],$arrSettings['password']);
if ($this->error == true) {
return false;
}
$this->dbselect($arrSettings['database']);
if ($this->error == true) {
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Get a singe data field
///////////////////////////////////////////////////////////////////////////////////////////
//
// Sends an SQL statement to the server and returns the result of the first data field
//
// Parameters: $strSQL SQL Statement
//
// Return value: <data> = successful
// <empty> = error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function getFieldData($strSQL) {
// Send an SQL Statement to the server
$resQuery = mysql_query($strSQL);
// Error processing
if ($resQuery && (mysql_num_rows($resQuery) != 0) && (mysql_error() == "")) {
// return the field value at postition 0/0
return mysql_result($resQuery,0,0);
} else if (mysql_error() != "") {
$this->strErrorMessage .= mysql_error()."::";
$this->error = true;
return("");
}
return("");
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Get a single dataset
///////////////////////////////////////////////////////////////////////////////////////////
//
// Sends an SQL statement to the server and returns the result of the first data set
//
// Parameters: $strSQL SQL Statement
// $arrDataset Return value including the data set
//
// Return value: true = successful
// false = error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function getSingleDataset($strSQL,&$arrDataset) {
$arrDataset = "";
// Send an SQL Statement to the server
$resQuery = mysql_query($strSQL);
// Error processing
if ($resQuery && (mysql_num_rows($resQuery) != 0) && (mysql_error() == "")) {
// Fill the data to the array
$arrDataset = mysql_fetch_array($resQuery,MYSQL_ASSOC);
return true;
} else if (mysql_error() != "") {
$this->strErrorMessage .= mysql_error()."::";
$this->error = true;
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Get a full data part
///////////////////////////////////////////////////////////////////////////////////////////
//
// Sends an SQL statement to the server and returns the result inside a data array
//
// Parameters: $strSQL SQL Statement
// $arrDataset Return value including the data records
// $intDataCount Return value including the number of the records
//
// Return value: true = successful
// false = error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function getDataArray($strSQL,&$arrDataset,&$intDataCount) {
$arrDataset = "";
$intDataCount = 0;
// Send an SQL Statement to the server
$resQuery = mysql_query($strSQL);
// Error processing
if ($resQuery && (mysql_num_rows($resQuery) != 0) && (mysql_error() == "")) {
$intDataCount = mysql_num_rows($resQuery);
$i = 0;
// Fill array
while ($arrDataTemp = mysql_fetch_array($resQuery, MYSQL_ASSOC)) {
foreach ($arrDataTemp AS $key => $value) {
$arrDataset[$i][$key] = $value;
}
$i++;
}
return true;
} else if (mysql_error() != "") {
$this->strErrorMessage .= mysql_error()."::";
$this->error = true;
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Insert data
///////////////////////////////////////////////////////////////////////////////////////////
//
// Inserts data to the database server
//
// Parameters: $strSQL SQL Statement
//
// $this->intLastId Dataset insert ID
// $this->intAffectedRows The number of the affected records
//
// Return value: true = successful
// false = error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function insertData($strSQL) {
// Send an SQL Statement to the server
$resQuery = mysql_query($strSQL);
// Error processing
if (mysql_error() == "") {
$this->intLastId = mysql_insert_id();
$this->intAffectedRows = mysql_affected_rows();
return true;
} else {
$this->strErrorMessage .= mysql_error()."::";
$this->error = true;
return false;
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Count records
///////////////////////////////////////////////////////////////////////////////////////////
//
// Counts the number of records
//
// Parameters: $strSQL SQL Statement
//
// Return value: <number> = successful
// 0 = no datasets or error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function countRows($strSQL) {
// Send an SQL Statement to the server
$resQuery = mysql_query($strSQL);
// Error processing
if ($resQuery && (mysql_error() == "")) {
return mysql_num_rows($resQuery);
} else {
$this->strErrorMessage .= mysql_error()."::";
$this->error = true;
return 0;
}
}
///////////////////////////////////////////////////////////////////////////////////////////
//
// help functions
//
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Connet to the database server
///////////////////////////////////////////////////////////////////////////////////////////
//
// Parameters: $dbserver Server name
// $dbport Server port
// $dbuser Database user
// $dbpasswd Database password
//
// Return value: true = successful
// false = error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function dbconnect($dbserver,$dbport,$dbuser,$dbpasswd) {
// Not all parameters available
if (($dbserver == "") || ($dbuser == "")) {
$this->strErrorMessage .= translate("Missing server connection parameter!")."::";
$this->error = true;
return false;
}
$this->strDBId = @mysql_connect($dbserver.":".$dbport,$dbuser,$dbpasswd);
// Session cannot be etablished
if(!$this->strDBId) {
$this->strErrorMessage .= "[".$this->arrSettings['db']['server']."] ".translate("Connection to the database server has failed by reason:")."::";
$this->strErrorMessage .= mysql_error()."::";
$this->error = true;
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: select database
///////////////////////////////////////////////////////////////////////////////////////////
//
// Parameters: $database Database name
//
// Return value: true = successful
// false = error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function dbselect($database) {
// Not all parameters available
if ($database == "") {
$this->strErrorMessage .= translate("Missing database connection parameter!")."::";
$this->error = true;
return false;
}
$bolConnect = @mysql_select_db($database);
// Session cannot be etablished
if(!$bolConnect) {
$this->strErrorMessage .= "[".$this->arrSettings['db']['server']."] ".translate("Connection to the database server has failed by reason:")."::";
$this->strErrorMessage .= mysql_error()."::";
$this->error = true;
return false;
}
$resQuery = mysql_query("set names 'utf8'");
if (mysql_error() != "") {
$this->strErrorMessage .= mysql_error()."::";
$this->error = true;
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Close database connection
///////////////////////////////////////////////////////////////////////////////////////////
//
// Return value: true = successful
//
///////////////////////////////////////////////////////////////////////////////////////////
function dbdisconnect() {
@mysql_close($this->strDBId);
return true;
}
}
?>

440
functions/mysqli_class.php Normal file
View File

@@ -0,0 +1,440 @@
<?php
///////////////////////////////////////////////////////////////////////////////
//
// Common utilities
//
///////////////////////////////////////////////////////////////////////////////
//
// (c) 2005-2017 by Martin Willisegger
//
// Project : Common scripts
// Component : MySQLi data processing class
// Date : $LastChangedDate: 2017-06-22 13:39:15 +0200 (Thu, 22 Jun 2017) $
// Author : $LastChangedBy: martin $
// Version : 3.3.0
// Revision : $LastChangedRevision: 7 $
// SVN-ID : $Id: mysqli_class.php 7 2017-06-22 11:39:15Z martin $
//
///////////////////////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////////////////////
//
// Class: Common database functions for MySQL (mysqli database module)
//
///////////////////////////////////////////////////////////////////////////////////////////////
//
// Includes any functions to communicate with an MySQL database server
//
// Name: mysqlidb
//
// Class variables: $arrParams Array including the server settings
// ---------------- $strErrorMessage Database error string
// $error Boolean - Error true/false
// $strDBId Database connection id
// $intLastId ID of last dataset
// $intAffectedRows Counter variable of all affected data dows
// $booSSLuse Use SSL connection
// (INSERT/DELETE/UPDATE)
//
// Parameters: $arrParams['server'] -> DB server name
// ----------- $arrParams['port'] -> DB server port
// $arrParams['user'] -> DB server username
// $arrParams['password'] -> DB server password
// $arrParams['database'] -> DB server database name
//
///////////////////////////////////////////////////////////////////////////////////////////////
class mysqlidb {
// Define class variables
var $error = false; // Will be filled in functions
var $strDBId = ""; // Will be filled in functions
var $intLastId = 0; // Will be filled in functions
var $intAffectedRows = 0; // Will be filled in functions
var $strErrorMessage = ""; // Will be filled in functions
var $booSSLuse = false; // Defines if SSL is used or not
var $arrParams = ""; // Must be filled in while initialization
var $arrSQLdef = ""; // Must be filled in while initialization
var $strSQLQuote1 = "`"; // Quote char for table or row names
var $strSQLQuote2 = "'"; // Quote char for table or row names
///////////////////////////////////////////////////////////////////////////////////////////
// Class constructor
///////////////////////////////////////////////////////////////////////////////////////////
//
// Activities during initialisation
//
///////////////////////////////////////////////////////////////////////////////////////////
function __construct() {
$this->arrParams['server'] = "";
$this->arrParams['port'] = 0;
$this->arrParams['username'] = "";
$this->arrParams['password'] = "";
$this->arrParams['database'] = "";
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Connect to database
///////////////////////////////////////////////////////////////////////////////////////////
//
// Opens a connection to the database server and select a database
//
//
// Return value: true successful
// false error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function getdatabase() {
$this->dbconnect();
if ($this->error == true) {
return false;
}
$this->dbselect();
if ($this->error == true) {
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Get a single dataset field value
///////////////////////////////////////////////////////////////////////////////////////////
//
// Sends an SQL statement to the server and returns the result of the first data field
//
// Parameters: $strSQL SQL Statement
//
// Return value: <data> = successful
// <empty> = error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function getFieldData($strSQL) {
// Reset error variables
$this->strErrorMessage = "";
$this->error = false;
// Send the SQL statement to the server
$resQuery = mysqli_query($this->strDBId,$strSQL);
// Error processing
if ($resQuery && (mysqli_num_rows($resQuery) != 0) && (mysqli_error($this->strDBId) == "")) {
// Return the field value from position 0/0
$arrDataset = mysqli_fetch_array($resQuery,MYSQLI_NUM);
return $arrDataset[0];
} else if (mysqli_error($this->strDBId) != "") {
$this->strErrorMessage .= mysqli_error($this->strDBId)."::";
$this->error = true;
return("");
}
return("");
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Get a single dataset
///////////////////////////////////////////////////////////////////////////////////////////
//
// Sends an SQL statement to the server and returns the result of the first data set
//
// Parameters: $strSQL SQL Statement
// $arrDataset Return value including the data set
//
// Return value: true = successful
// false = error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function getSingleDataset($strSQL,&$arrDataset) {
$arrDataset = "";
// Reset error variables
$this->strErrorMessage = "";
$this->error = false;
// Send the SQL statement to the server
$resQuery = mysqli_query($this->strDBId,$strSQL);
// Error processing
if ($resQuery && (mysqli_num_rows($resQuery) != 0) && (mysqli_error($this->strDBId) == "")) {
// Put the values into the array
$arrDataset = mysqli_fetch_array($resQuery,MYSQLI_ASSOC);
return true;
} else if (mysqli_error($this->strDBId) != "") {
$this->strErrorMessage .= mysqli_error($this->strDBId)."::";
$this->error = true;
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Get a full data part
///////////////////////////////////////////////////////////////////////////////////////////
//
// Sends an SQL statement to the server and returns the result inside a data array
//
// Parameters: $strSQL SQL Statement
// $arrDataset Return value including the data records
// $intDataCount Return value including the number of the records
//
// Return value: true = successful
// false = error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function getDataArray($strSQL,&$arrDataset,&$intDataCount) {
$arrDataset = "";
$intDataCount = 0;
// Reset error variables
$this->strErrorMessage = "";
$this->error = false;
// Send the SQL statement to the server
$resQuery = mysqli_query($this->strDBId,$strSQL);
// Error processing
if ($resQuery && (mysqli_num_rows($resQuery) != 0) && (mysqli_error($this->strDBId) == "")) {
$intDataCount = mysqli_num_rows($resQuery);
$i = 0;
// Put the values into the array
while ($arrDataTemp = mysqli_fetch_array($resQuery,MYSQLI_ASSOC)) {
foreach ($arrDataTemp AS $key => $value) {
$arrDataset[$i][$key] = $value;
}
$i++;
}
return true;
} else if (mysqli_error($this->strDBId) != "") {
$this->strErrorMessage .= mysqli_error($this->strDBId)."::";
$this->error = true;
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Insert/update/delete data
///////////////////////////////////////////////////////////////////////////////////////////
//
// Insert/update or delete data
//
// Parameters: $strSQL SQL Statement
// $this->intLastId Dataset insert ID
// $this->intAffectedRows The number of the affected records
//
// Return value: true = successful
// false = error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function insertData($strSQL) {
// Reset error variables
$this->strErrorMessage = "";
$this->error = false;
// Send the SQL statement to the server
$resQuery = mysqli_query($this->strDBId,$strSQL);
// Error processing
if (mysqli_error($this->strDBId) == "") {
$this->intLastId = mysqli_insert_id($this->strDBId);
$this->intAffectedRows = mysqli_affected_rows($this->strDBId);
return true;
} else {
$this->strErrorMessage .= mysqli_error($this->strDBId)."::";
$this->error = true;
return false;
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Counts data rows
///////////////////////////////////////////////////////////////////////////////////////////
//
// Counts the number of records
//
// Parameters: $strSQL SQL Statement
//
// Return value: <number> = successful
// 0 = no datasets or error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function countRows($strSQL) {
// Reset error variables
$this->strErrorMessage = "";
$this->error = false;
// Send the SQL statement to the server
$resQuery = mysqli_query($this->strDBId,$strSQL);
// Error processing
if ($resQuery && (mysqli_error($this->strDBId) == "")) {
return mysqli_num_rows($resQuery);
} else {
$this->strErrorMessage .= mysqli_error($this->strDBId);
$this->error = true;
return 0;
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Use mysqli_real_escape_string
///////////////////////////////////////////////////////////////////////////////////////////
//
// Returns a safe insert string for database manipulations
//
// Value: $strInput Input String
//
// Return value: $strOutput Output String
//
///////////////////////////////////////////////////////////////////////////////////////////
function real_escape($strInput) {
return mysqli_real_escape_string($this->strDBId,$strInput);
}
///////////////////////////////////////////////////////////////////////////////////////////
//
// Assistant functions
//
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Initialize a mysql database connection
///////////////////////////////////////////////////////////////////////////////////////////
//
// Return value: true
//
///////////////////////////////////////////////////////////////////////////////////////////
function dbinit() {
$this->strDBId = mysqli_init();
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Connect to database server
///////////////////////////////////////////////////////////////////////////////////////////
//
// Parameters: $dbserver Server name
// $dbuser Database user
// $dbpasswd Database password
// $dbname Database name
// $dbport TCP port
//
// Return value: true successful
// false error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function dbconnect($dbserver=NULL,$dbport=NULL,$dbuser=NULL,$dbpasswd=NULL) {
// Reset error variables
$this->strErrorMessage = "";
$this->error = false;
// Get parameters
if ($dbserver == NULL) $dbserver = $this->arrParams['server'];
if ($dbport == NULL) $dbport = $this->arrParams['port'];
if ($dbuser == NULL) $dbuser = $this->arrParams['username'];
if ($dbpasswd == NULL) $dbpasswd = $this->arrParams['password'];
// Not all parameters available
if (($dbserver == "") || ($dbuser == "") || ($dbpasswd == "")) {
$this->strErrorMessage .= gettext("Missing server connection parameter!")."::";
$this->error = true;
return false;
}
$this->dbinit();
if ($this->booSSLuse == true) {
// TO BE DEFINED
}
$intErrorReporting = error_reporting();
error_reporting(0);
if ($dbport == 0) {
$booReturn = mysqli_real_connect($this->strDBId,$dbserver,$dbuser,$dbpasswd);
} else {
$booReturn = mysqli_real_connect($this->strDBId,$dbserver,$dbuser,$dbpasswd,NULL,$dbport);
}
$arrError = error_get_last();
error_reporting($intErrorReporting);
// Connection fails
if($booReturn == false) {
$this->strErrorMessage = "[".$dbserver."] ".gettext("Connection to the database server has failed by reason:")." ::";
if (mysqli_connect_error($this->strDBId) != "") $this->strErrorMessage .= mysqli_connect_error($this->strDBId)."::";
$this->error = true;
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: select database
///////////////////////////////////////////////////////////////////////////////////////////
//
// Parameters: $database Database name
//
// Return value: true = successful
// false = error
// Status message is stored in class variable $this->strErrorMessage
//
///////////////////////////////////////////////////////////////////////////////////////////
function dbselect($database=NULL) {
// Reset error variables
$this->strErrorMessage = "";
$this->error = false;
// Get parameters
if ($database == NULL) $database = $this->arrParams['database'];
// Not all parameters available
if ($database == "") {
$this->strErrorMessage .= gettext("Missing database connection parameter!")."::";
$this->error = true;
return false;
}
$bolConnect = mysqli_select_db($this->strDBId,$database);
// Session cannot be etablished
if(!$bolConnect) {
$this->strErrorMessage .= "[".$database."] ".gettext("Connection to the database has failed by reason:")." ::";
$this->strErrorMessage .= mysqli_error($this->strDBId)."::";
$this->error = true;
return false;
}
$resQuery = mysqli_query($this->strDBId,"set names 'utf8'");
if (mysqli_error($this->strDBId) != "") {
$this->strErrorMessage .= mysqli_error($this->strDBId)."::";
$this->error = true;
return false;
}
$resQuery = mysqli_query($this->strDBId,"set session sql_mode = 'NO_ENGINE_SUBSTITUTION'");
if (mysqli_error($this->strDBId) != "") {
$this->strErrorMessage .= mysqli_error($this->strDBId)."::";
$this->error = true;
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Set SSL parameters
///////////////////////////////////////////////////////////////////////////////////////////
//
// Parameters: $sslkey SSL key
// $sslcert SSL certificate
// $sslca SSL CA file (optional)
// $sslpath SSL certificate path (optional)
// $sslcypher SSL cypher (optional)
//
// Return value: true successful
// The mysqli_ssl_set function always returns TRUE!
//
///////////////////////////////////////////////////////////////////////////////////////////
function dbsetssl($sslkey,$sslcert,$sslca=NULL,$sslpath=NULL,$sslcypher=NULL) {
// Reset error variables
$this->strErrorMessage = "";
$this->error = false;
// Values are missing
if (($sslkey == "") || ($sslcert == "")) {
$this->strErrorMessage = gettext("Missing MySQL SSL parameter!")."::";
$this->error = true;
return false;
}
mysqli_ssl_set($this->strDBId,$sslkey,$sslcert,$sslca,$sslpath,$sslcypher);
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Function: Close database server connectuon
///////////////////////////////////////////////////////////////////////////////////////////
//
// Value: none
//
// Return value: true if successful, false if failed
//
///////////////////////////////////////////////////////////////////////////////////////////
function dbdisconnect() {
mysqli_close($this->strDBId);
return true;
}
}
?>

View File

@@ -5,15 +5,15 @@
//
///////////////////////////////////////////////////////////////////////////////
//
// (c) 2005-2012 by Martin Willisegger
// (c) 2005-2017 by Martin Willisegger
//
// Project : NagiosQL
// Component : Visualization Class
// Website : http://www.nagiosql.org
// Date : $LastChangedDate: 2012-10-03 10:00:02 +0200 (Wed, 03 Oct 2012) $
// Date : $LastChangedDate: 2017-06-22 09:29:35 +0200 (Thu, 22 Jun 2017) $
// Author : $LastChangedBy: martin $
// Version : 3.2.0
// Revision : $LastChangedRevision: 1349 $
// Version : 3.3.0
// Revision : $LastChangedRevision: 2 $
//
///////////////////////////////////////////////////////////////////////////////////////////////
//
@@ -46,7 +46,7 @@ class nagvisual {
// Activities during initialisation
//
///////////////////////////////////////////////////////////////////////////////////////////
function nagvisual() {
function __construct() {
// Read global settings
$this->arrSettings = $_SESSION['SETS'];
if (isset($_SESSION['domain'])) $this->intDomainId = $_SESSION['domain'];
@@ -229,7 +229,7 @@ class nagvisual {
///////////////////////////////////////////////////////////////////////////////////////////
function tfSecure($strKey) {
$strKey = stripslashes($strKey);
$strKey = mysql_real_escape_string($strKey);
$strKey = $this->myDBClass->real_escape($strKey);
return($strKey);
}

View File

@@ -4,15 +4,15 @@
// NagiosQL
///////////////////////////////////////////////////////////////////////////////
//
// (c) 2005-2012 by Martin Willisegger
// (c) 2005-2017 by Martin Willisegger
//
// Project : NagiosQL
// Component : Preprocessing script
// Website : http://www.nagiosql.org
// Date : $LastChangedDate: 2013-01-10 09:46:11 +0100 (Thu, 10 Jan 2013) $
// Date : $LastChangedDate: 2017-06-22 09:29:35 +0200 (Thu, 22 Jun 2017) $
// Author : $LastChangedBy: martin $
// Version : 3.2.0
// Revision : $LastChangedRevision: 1351 $
// Version : 3.3.0
// Revision : $LastChangedRevision: 2 $
//
///////////////////////////////////////////////////////////////////////////////
//error_reporting(E_ALL);
@@ -46,7 +46,7 @@ $chkDomainId = 0;
$chkGroupAdm = 0;
$intError = 0;
$setDBVersion = "unknown";
$setFileVersion = "3.2.0";
$setFileVersion = "3.3.0";
//
// Start PHP session
// =================
@@ -91,15 +91,17 @@ if (!isset($_SESSION['SETS']['db'])) $_SESSION['SETS']['db'] = $SETS['db'];
//
// Include external function/class files - part 1
// ==============================================
include("mysql_class.php");
include("mysqli_class.php");
require("translator.php");
//
// Initialize classes - part 1
// ===========================
$myDBClass = new mysqldb;
$myDBClass = new mysqlidb;
$myDBClass->arrParams = $SETS['db'];
$myDBClass->getDatabase();
if ($myDBClass->error == true) {
$strErrorMessage .= translate('Error while connecting to database:')."::".$myDBClass->strErrorMessage;
$intError = 1;
$strDBMessage = $myDBClass->strErrorMessage;
$booError = $myDBClass->error;
}
//
// Get additional configuration from the table tbl_settings
@@ -264,7 +266,7 @@ if (isset($_SERVER['REMOTE_USER']) && ($_SERVER['REMOTE_USER'] != "") && ($_SESS
$SETS['data']['locale'] = $strUserLocale;
}
// Update last login time
$strSQLUpdate = "UPDATE `tbl_user` SET `last_login`=NOW() WHERE `username`='".mysql_real_escape_string($chkInsName)."'";
$strSQLUpdate = "UPDATE `tbl_user` SET `last_login`=NOW() WHERE `username`='".$myDBClass->real_escape($chkInsName)."'";
$booReturn = $myDBClass->insertData($strSQLUpdate);
$myDataClass->writeLog(translate('Webserver login successfull'));
$_SESSION['strLoginMessage'] = "";
@@ -273,8 +275,8 @@ if (isset($_SERVER['REMOTE_USER']) && ($_SERVER['REMOTE_USER'] != "") && ($_SESS
}
}
if (($_SESSION['logged_in'] == 0) && isset($chkInsName) && ($chkInsName != "") && ($intError == 0)) {
$chkInsName = mysql_real_escape_string($chkInsName);
$chkInsPasswd = mysql_real_escape_string($chkInsPasswd);
$chkInsName = $myDBClass->real_escape($chkInsName);
$chkInsPasswd = $myDBClass->real_escape($chkInsPasswd);
$strSQL = "SELECT * FROM `tbl_user` WHERE `username`='".$chkInsName."'
AND `password`=MD5('".$chkInsPasswd."') AND `active`='1'";
$booReturn = $myDBClass->getDataArray($strSQL,$arrDataUser,$intDataCount);
@@ -299,7 +301,7 @@ if (($_SESSION['logged_in'] == 0) && isset($chkInsName) && ($chkInsName != "") &
$SETS['data']['locale'] = $strUserLocale;
}
// Update last login time
$strSQLUpdate = "UPDATE `tbl_user` SET `last_login`=NOW() WHERE `username`='".mysql_real_escape_string($chkInsName)."'";
$strSQLUpdate = "UPDATE `tbl_user` SET `last_login`=NOW() WHERE `username`='".$myDBClass->real_escape($chkInsName)."'";
$booReturn = $myDBClass->insertData($strSQLUpdate);
$myDataClass->writeLog(translate('Login successfull'));
$_SESSION['strLoginMessage'] = "";
@@ -322,7 +324,7 @@ if (!isset($_SESSION['userid']) && ($_SESSION['logged_in'] == 1)) {
// Review and update login
// =======================
if (($_SESSION['logged_in'] == 1) && ($intError == 0)) {
$strSQL = "SELECT * FROM `tbl_user` WHERE `username`='".mysql_real_escape_string($_SESSION['username'])."'";
$strSQL = "SELECT * FROM `tbl_user` WHERE `username`='".$myDBClass->real_escape($_SESSION['username'])."'";
$booReturn = $myDBClass->getDataArray($strSQL,$arrDataUser,$intDataCount);
if ($booReturn == false) {
$myVisClass->processMessage(translate('Error while selecting data from database:'),$strErrorMessage);

10
functions/prepend_content.php Executable file → Normal file
View File

@@ -4,15 +4,15 @@
// NagiosQL
///////////////////////////////////////////////////////////////////////////////
//
// (c) 2005-2012 by Martin Willisegger
// (c) 2005-2017 by Martin Willisegger
//
// Project : NagiosQL
// Component : Preprocessing script for content pages
// Website : http://www.nagiosql.org
// Date : $LastChangedDate: 2011-12-08 07:35:31 +0100 (Do, 08. Dez 2011) $
// Date : $LastChangedDate: 2017-06-22 09:53:38 +0200 (Thu, 22 Jun 2017) $
// Author : $LastChangedBy: martin $
// Version : 3.2.0
// Revision : $LastChangedRevision: 1141 $
// Version : 3.3.0
// Revision : $LastChangedRevision: 5 $
//
///////////////////////////////////////////////////////////////////////////////
//
@@ -321,7 +321,7 @@ if (($chkModus == "make") && ($intGlobalWriteAccess == 0)) {
if ($intSuccess != 0) $myVisClass->processMessage(translate('Configuration files successfully written!'),$strInfoMessage);
if ($intError != 0) $myVisClass->processMessage(translate('Some configuration files were not written. Dataset not activated, not found or you do not have write permission!'),$strErrorMessage);
} else if ($preTableName == 'tbl_service') {
$strSQL = "SELECT `id`, `$preKeyField` FROM `$preTableName` WHERE $strDomainWhere AND `access_group` IN ($strAccess) AND `active`='1' GROUP BY `$preKeyField`";
$strSQL = "SELECT `id`, `$preKeyField` FROM `$preTableName` WHERE $strDomainWhere AND `access_group` IN ($strAccess) AND `active`='1' GROUP BY `$preKeyField`, `id`";
$myDBClass->getDataArray($strSQL,$arrData,$intDataCount);
if ($booReturn == false) $myVisClass->processMessage($myDBClass->strErrorMessage,$strErrorMessage);
if ($booReturn && ($intDataCount != 0)) {

View File

@@ -2,17 +2,18 @@
///////////////////////////////////////////////////////////////////////////////
//
// NagiosQL
//
///////////////////////////////////////////////////////////////////////////////
//
// (c) 2005-2012 by Martin Willisegger
// (c) 2005-2017 by Martin Willisegger
//
// Project : NagiosQL
// Component : Preprocessing script for scripting files
// Website : http://www.nagiosql.org
// Date : $LastChangedDate: 2012-02-29 09:54:45 +0100 (Wed, 29 Feb 2012) $
// Date : $LastChangedDate: 2017-06-22 09:48:25 +0200 (Thu, 22 Jun 2017) $
// Author : $LastChangedBy: martin $
// Version : 3.2.0
// Revision : $LastChangedRevision: 1262 $
// Version : 3.3.0
// Revision : $LastChangedRevision: 4 $
//
///////////////////////////////////////////////////////////////////////////////
error_reporting(E_ALL);
@@ -41,7 +42,7 @@ define('BASE_PATH', str_replace("functions","",dirname(__FILE__)));
//
// Read settings file
// ==================
$preBasePath = str_replace("scripts","",getcwd());
$preBasePath = str_replace("functions","",dirname(__FILE__));
$preIniFile = $preBasePath.'config/settings.php';
//
// Read file settings
@@ -50,16 +51,16 @@ $SETS = parse_ini_file($preIniFile,true);
//
// Include external function/class files - part 1
// ==============================================
include("mysql_class.php");
include("mysqli_class.php");
//
// Initialize classes - part 1
// ===========================
$myDBClass = new mysqldb;
$myDBClass->arrSettings = $SETS;
$myDBClass->getDatabase($SETS['db']);
$myDBClass = new mysqlidb;
$myDBClass->arrParams = $SETS['db'];
$myDBClass->getDatabase();
if ($myDBClass->error == true) {
echo str_replace("::","\n","Error while connecting to database: ".$myDBClass->strErrorMessage);
$intError = 1;
$strDBMessage = $myDBClass->strErrorMessage;
$booError = $myDBClass->error;
}
//
// Get additional configuration from the table tbl_settings

View File

@@ -5,13 +5,15 @@
//
///////////////////////////////////////////////////////////////////////////////
//
// (c) 2005-2017 by Martin Willisegger
//
// Project : NagiosQL
// Component : Translation Functions
// Website : http://www.nagiosql.org
// Date : $LastChangedDate: 2012-02-23 08:02:21 +0100 (Thu, 23 Feb 2012) $
// Date : $LastChangedDate: 2017-06-22 09:29:35 +0200 (Thu, 22 Jun 2017) $
// Author : $LastChangedBy: martin $
// Version : 3.2.0
// Revision : $LastChangedRevision: 1238 $
// Version : 3.3.0
// Revision : $LastChangedRevision: 2 $
//
///////////////////////////////////////////////////////////////////////////////
//