nagiosql/install/step3.php

291 lines
14 KiB
PHP
Raw Normal View History

2017-05-22 11:24:21 +02:00
<?php
///////////////////////////////////////////////////////////////////////////////
//
// NagiosQL
//
///////////////////////////////////////////////////////////////////////////////
//
2017-10-20 15:00:08 +02:00
// (c) 2005-2017 by Martin Willisegger
2017-05-22 11:24:21 +02:00
//
// Project : NagiosQL
// Component : Installer script - step 2
// Website : http://www.nagiosql.org
2017-10-20 15:00:08 +02:00
// Date : $LastChangedDate: 2017-06-22 09:29:35 +0200 (Thu, 22 Jun 2017) $
2017-05-22 11:24:21 +02:00
// Author : $LastChangedBy: martin $
2017-10-20 15:00:08 +02:00
// Version : 3.3.0
// Revision : $LastChangedRevision: 2 $
2017-05-22 11:24:21 +02:00
//
///////////////////////////////////////////////////////////////////////////////
//
// Prevent this file from direct access
// ====================================
if(preg_match('#' . basename(__FILE__) . '#', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'utf-8'))) {
exit;
}
//
// Define common variables
// =======================
$preIncludeContent = "templates/step3.tpl.htm";
$intError = 0;
if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) {
@date_default_timezone_set(@date_default_timezone_get());
}
//
// Build content
// =============
2017-10-20 15:00:08 +02:00
$arrTemplate['STEP1_BOX'] = $myInstClass->translate('Requirements');
$arrTemplate['STEP2_BOX'] = $myInstClass->translate($_SESSION['install']['mode']);
$arrTemplate['STEP3_BOX'] = $myInstClass->translate('Finish');
$arrTemplate['STEP3_TITLE'] = "NagiosQL ".$myInstClass->translate($_SESSION['install']['mode']).": ".$myInstClass->translate("Finishing Setup");
2017-05-22 11:24:21 +02:00
$arrTemplate['INST_VISIBLE'] = "showfield";
2017-10-20 15:00:08 +02:00
$arrTemplate['STEP4_SUB_TITLE'] = $myInstClass->translate("Deploy NagiosQL settings");
$arrTemplate['STEP3_TEXT_01'] = $myInstClass->translate("Database server connection (privileged user)");
$arrTemplate['STEP3_TEXT_03'] = $myInstClass->translate("Database server version");
$arrTemplate['STEP3_TEXT_05'] = $myInstClass->translate("Database server support");
$arrTemplate['STEP3_TEXT_07'] = $myInstClass->translate("Delete existing NagiosQL database");
$arrTemplate['STEP3_TEXT_09'] = $myInstClass->translate("Creating new database");
$arrTemplate['STEP3_TEXT_11'] = $myInstClass->translate("Installing NagiosQL database tables");
$arrTemplate['STEP3_TEXT_13'] = $myInstClass->translate("Create NagiosQL database user");
$arrTemplate['STEP3_TEXT_15'] = $myInstClass->translate("Set initial NagiosQL Administrator");
$arrTemplate['STEP3_TEXT_17'] = $myInstClass->translate("Database server connection (NagiosQL user)");
$arrTemplate['STEP4_TEXT_01'] = $myInstClass->translate("Writing global settings to database");
$arrTemplate['STEP4_TEXT_03'] = $myInstClass->translate("Writing database configuration to settings.php");
$arrTemplate['STEP4_TEXT_05'] = $myInstClass->translate("Import Nagios sample data");
$arrTemplate['STEP4_TEXT_07'] = $myInstClass->translate("Create and/or store NagiosQL path settings");
2017-05-22 11:24:21 +02:00
$arrTemplate['STEP4_VISIBLE'] = "hidefield";
2017-10-20 15:00:08 +02:00
$arrTemplate['STEP3_TEXT_02_SHOW'] = "hidefield";
2017-05-22 11:24:21 +02:00
$arrTemplate['STEP3_TEXT_03_SHOW'] = "hidefield";
$arrTemplate['STEP3_TEXT_05_SHOW'] = "hidefield";
$arrTemplate['STEP3_TEXT_07_SHOW'] = "hidefield";
$arrTemplate['STEP3_TEXT_09_SHOW'] = "hidefield";
$arrTemplate['STEP3_TEXT_11_SHOW'] = "hidefield";
$arrTemplate['STEP3_TEXT_13_SHOW'] = "hidefield";
$arrTemplate['STEP3_TEXT_15_SHOW'] = "hidefield";
$arrTemplate['STEP3_TEXT_17_SHOW'] = "hidefield";
$arrTemplate['STEP4_TEXT_03_SHOW'] = "hidefield";
$arrTemplate['STEP4_TEXT_05_SHOW'] = "hidefield";
$arrTemplate['STEP4_TEXT_07_SHOW'] = "hidefield";
//
2017-10-20 15:00:08 +02:00
// Check any data before installation
// ==================================
$intInstError = 0;
//
2017-05-22 11:24:21 +02:00
// Doing installation/upgrade
// ==========================
if ($_SESSION['install']['mode'] == "Update") {
2017-10-20 15:00:08 +02:00
$arrTemplate['STEP3_SUB_TITLE'] = $myInstClass->translate("Updating existing NagiosQL database");
//
// Include database class
// ======================
if ($_SESSION['install']['dbtype'] == "mysqli") {
// Include and initialize mysqli class
include("../functions/mysqli_class.php");
$myDBClass = new mysqlidb;
} else if ($_SESSION['install']['dbtype'] == "pgsql") {
// Include and initialize pgsql class
include("../functions/pgsql_class.php");
$myDBClass = new pgsqldb;
} else {
$strErrorMessage .= $myInstClass->translate("Database type not defined!")." (".$_SESSION['install']['dbtype'].")<br>\n";
$strStatusMessage = "<span class=\"red\">".$myInstClass->translate("failed")."</span>";
$intError = 1;
}
// Set DB parameters
$myDBClass->arrParams['server'] = $_SESSION['install']['dbserver'];
$myDBClass->arrParams['port'] = $_SESSION['install']['dbport'];
$myDBClass->arrParams['username'] = $_SESSION['install']['admuser'];
$myDBClass->arrParams['password'] = $_SESSION['install']['admpass'];
$myDBClass->arrParams['database'] = $_SESSION['install']['dbname'];
// Include classes
if ($intError == 0) $myInstClass->myDBClass =& $myDBClass;
// Check database connection
if ($intError == 0) $intError = $myInstClass->openAdmDBSrv($arrTemplate['STEP3_TEXT_02'],$strErrorMessage);
if ($intError == 0) $intError = $myInstClass->openDatabase($arrTemplate['STEP3_TEXT_02'],$strErrorMessage);
$arrTemplate['STEP3_TEXT_02_SHOW'] = "showfield";
// Check NagiosQL version
if ($intError == 0) {
$arrTemplate['STEP3_TEXT_03'] = $myInstClass->translate("Installed NagiosQL version");
$arrTemplate['STEP3_TEXT_03_SHOW'] = "showfield";
$intError = $myInstClass->checkQLVersion($arrTemplate['STEP3_TEXT_04'],$strErrorMessage,$arrUpdate,$setQLVersion);
}
// Upgrade NagiosQL DB
if ($intError == 0) {
$arrTemplate['STEP3_TEXT_05'] = $myInstClass->translate("Upgrading from version")." ".$setQLVersion." ".$myInstClass->translate("to")." ".$preNagiosQL_ver;
$arrTemplate['STEP3_TEXT_05_SHOW'] = "showfield";
$intError = $myInstClass->updateQLDB($arrTemplate['STEP3_TEXT_06'],$strErrorMessage,$arrUpdate);
}
if (($_SESSION['install']['dbtype'] == "mysql") && (version_compare($setQLVersion,"3.2.0") == -1)) {
2017-05-22 11:24:21 +02:00
// Converting database to UTF8
if ($intError == 0) {
2017-10-20 15:00:08 +02:00
$arrTemplate['STEP3_TEXT_07'] = $myInstClass->translate("Converting database to utf8 character set");
2017-05-22 11:24:21 +02:00
$arrTemplate['STEP3_TEXT_07_SHOW'] = "showfield";
$intError = $myInstClass->convQLDB($arrTemplate['STEP3_TEXT_08'],$strErrorMessage);
}
// Converting database tables to UTF8
if ($intError == 0) {
2017-10-20 15:00:08 +02:00
$arrTemplate['STEP3_TEXT_09'] = $myInstClass->translate("Converting database tables to utf8 character set");
2017-05-22 11:24:21 +02:00
$arrTemplate['STEP3_TEXT_09_SHOW'] = "showfield";
$intError = $myInstClass->convQLDBTables($arrTemplate['STEP3_TEXT_10'],$strErrorMessage);
}
// Converting database fields to UTF8
if ($intError == 0) {
2017-10-20 15:00:08 +02:00
$arrTemplate['STEP3_TEXT_11'] = $myInstClass->translate("Converting database fields to utf8 character set");
2017-05-22 11:24:21 +02:00
$arrTemplate['STEP3_TEXT_11_SHOW'] = "showfield";
$intError = $myInstClass->convQLDBFields($arrTemplate['STEP3_TEXT_12'],$strErrorMessage);
}
2017-10-20 15:00:08 +02:00
}
// Reconnect Database with new user
if ($intError == 0) {
$arrTemplate['STEP3_TEXT_17_SHOW'] = "showfield";
$intError = $myInstClass->openAdmDBSrv($arrTemplate['STEP3_TEXT_18'],$strErrorMessage,1);
$intError = $myInstClass->openDatabase($arrTemplate['STEP3_TEXT_18'],$strErrorMessage,1);
}
// Deploy NagiosQL database settings
if ($intError == 0) {
$arrTemplate['STEP4_VISIBLE'] = "showfield";
$intError = $myInstClass->updateSettingsDB($arrTemplate['STEP4_TEXT_02'],$strErrorMessage);
}
// Write database settings to file
if ($intError == 0) {
$arrTemplate['STEP4_TEXT_03_SHOW'] = "showfield";
$intError = $myInstClass->updateSettingsFile($arrTemplate['STEP4_TEXT_04'],$strErrorMessage);
2017-05-22 11:24:21 +02:00
}
} else {
2017-10-20 15:00:08 +02:00
$arrTemplate['STEP3_SUB_TITLE'] = $myInstClass->translate("Create new NagiosQL database");
//
// Include database class
// ======================
if ($_SESSION['install']['dbtype'] == "mysqli") {
// Include and initialize mysqli class
include("../functions/mysqli_class.php");
$myDBClass = new mysqlidb;
} else if ($_SESSION['install']['dbtype'] == "pgsql") {
// Include and initialize pgsql class
include("../functions/pgsql_class.php");
$myDBClass = new pgsqldb;
//} else if ($_SESSION['install']['dbtype'] == "sqlite3") {
// // Include sqlite3 and initialize class
// include("../functions/sqlite3_class.php");
// $myDBClass = new sqlite3db;
} else {
$strErrorMessage .= $myInstClass->translate("Database type not defined!")." (".$_SESSION['install']['dbtype'].")<br>\n";
$strStatusMessage = "<span class=\"red\">".$myInstClass->translate("failed")."</span>";
$intError = 1;
}
// Set DB parameters
$myDBClass->arrParams['server'] = $_SESSION['install']['dbserver'];
$myDBClass->arrParams['port'] = $_SESSION['install']['dbport'];
$myDBClass->arrParams['username'] = $_SESSION['install']['admuser'];
$myDBClass->arrParams['password'] = $_SESSION['install']['admpass'];
$myDBClass->arrParams['database'] = $_SESSION['install']['dbname'];
// Include classes
if ($intError == 0) $myInstClass->myDBClass =& $myDBClass;
2017-05-22 11:24:21 +02:00
// Check database connection
$intOldDBStatus = 0;
if ($intError == 0) $intError = $myInstClass->openAdmDBSrv($arrTemplate['STEP3_TEXT_02'],$strErrorMessage);
2017-10-20 15:00:08 +02:00
// Does the database already exist?
2017-05-22 11:24:21 +02:00
if ($intError == 0) {
2017-10-20 15:00:08 +02:00
$intOldDBStatus = $myInstClass->openDatabase($strTmpMessage,$strTmpError);
$myDBClass->strErrorMessage = "";
2017-05-22 11:24:21 +02:00
if (($intOldDBStatus == 0) && ($_SESSION['install']['dbdrop'] == 0)) {
2017-10-20 15:00:08 +02:00
$strErrorMessage .= $myInstClass->translate("Database already exists and drop database was not selected, please correct or manage manually")."<br>";
$arrTemplate['STEP3_TEXT_02'] = "<span class=\"red\">".$myInstClass->translate("failed")."</span>";
$intError = 1;
2017-05-22 11:24:21 +02:00
} else {
2017-10-20 15:00:08 +02:00
$myInstClass->openAdmDBSrv($arrTemplate['STEP3_TEXT_02'],$strErrorMessage);
2017-05-22 11:24:21 +02:00
}
}
2017-10-20 15:00:08 +02:00
$arrTemplate['STEP3_TEXT_02_SHOW'] = "showfield";
$arrTemplate['STEP3_TEXT_02'] .= " (".$_SESSION['install']['dbtype'].")";
2017-05-22 11:24:21 +02:00
// Check database version
if ($intError == 0) {
$arrTemplate['STEP3_TEXT_03_SHOW'] = "showfield";
$arrTemplate['STEP3_TEXT_05_SHOW'] = "showfield";
$intError = $myInstClass->checkDBVersion($arrTemplate['STEP3_TEXT_06'],$strErrorMessage,$strVersion);
if ($strVersion == "unknown") {
2017-10-20 15:00:08 +02:00
$arrTemplate['STEP3_TEXT_04'] = "<span class=\"red\">".$myInstClass->translate("unknown")."</span>";
2017-05-22 11:24:21 +02:00
} else {
$arrTemplate['STEP3_TEXT_04'] = "<span class=\"green\">".$strVersion."</span>";
}
}
// Drop existing database
if (($intError == 0) && ($_SESSION['install']['dbdrop'] == 1) && ($intOldDBStatus == 0)) {
$arrTemplate['STEP3_TEXT_07_SHOW'] = "showfield";
$intError = $myInstClass->dropDB($arrTemplate['STEP3_TEXT_08'],$strErrorMessage);
}
// Create new database
if ($intError == 0) {
$arrTemplate['STEP3_TEXT_09_SHOW'] = "showfield";
$intError = $myInstClass->createDB($arrTemplate['STEP3_TEXT_10'],$strErrorMessage);
2017-10-20 15:00:08 +02:00
echo $strErrorMessage;
2017-05-22 11:24:21 +02:00
}
2017-10-20 15:00:08 +02:00
// Write initial SQL data to database
if ($intError == 0) $intError = $myInstClass->openDatabase($strTmp,$strErrorMessage);
2017-05-22 11:24:21 +02:00
if ($intError == 0) {
$arrTemplate['STEP3_TEXT_11_SHOW'] = "showfield";
2017-10-20 15:00:08 +02:00
$arrInsert[] = $preSqlNewInstall;
$intError = $myInstClass->updateQLDB($arrTemplate['STEP3_TEXT_12'],$strErrorMessage,$arrInsert);
2017-05-22 11:24:21 +02:00
}
2017-10-20 15:00:08 +02:00
// Grant NagiosQL database user
2017-05-22 11:24:21 +02:00
if ($intError == 0) {
$arrTemplate['STEP3_TEXT_13_SHOW'] = "showfield";
2017-10-20 15:00:08 +02:00
$intError = $myInstClass->grantDBUser($arrTemplate['STEP3_TEXT_14'],$strErrorMessage);
2017-05-22 11:24:21 +02:00
}
// Create NagiosQL admin user
if ($intError == 0) {
$arrTemplate['STEP3_TEXT_15_SHOW'] = "showfield";
$intError = $myInstClass->createNQLAdmin($arrTemplate['STEP3_TEXT_16'],$strErrorMessage);
}
// Reconnect Database with new user
if ($intError == 0) {
2017-10-20 15:00:08 +02:00
$myDBClass->arrParams['username'] = $_SESSION['install']['dbuser'];
$myDBClass->arrParams['password'] = $_SESSION['install']['dbpass'];
2017-05-22 11:24:21 +02:00
$arrTemplate['STEP3_TEXT_17_SHOW'] = "showfield";
if ($intError == 0) $intError = $myInstClass->openAdmDBSrv($arrTemplate['STEP3_TEXT_18'],$strErrorMessage,1);
if ($intError == 0) $intError = $myInstClass->openDatabase($arrTemplate['STEP3_TEXT_18'],$strErrorMessage,1);
}
// Deploy NagiosQL settings
if ($intError == 0) {
$arrTemplate['STEP4_VISIBLE'] = "showfield";
$intError = $myInstClass->updateSettingsDB($arrTemplate['STEP4_TEXT_02'],$strErrorMessage);
2017-10-20 15:00:08 +02:00
}
2017-05-22 11:24:21 +02:00
// Write database settings to file
if ($intError == 0) {
$arrTemplate['STEP4_TEXT_03_SHOW'] = "showfield";
$intError = $myInstClass->updateSettingsFile($arrTemplate['STEP4_TEXT_04'],$strErrorMessage);
}
// Write sample data to database
if (($intError == 0) && ($_SESSION['install']['sample'] == 1)) {
$arrTemplate['STEP4_TEXT_05_SHOW'] = "showfield";
$arrSample[] = "sql/import_nagios_sample.sql";
$intError = $myInstClass->updateQLDB($arrTemplate['STEP4_TEXT_06'],$strErrorMessage,$arrSample);
}
// Create NagiosQL path and write path settings to the database
if ($intError == 0) {
$arrTemplate['STEP4_TEXT_07_SHOW'] = "showfield";
$intError = $myInstClass->updateQLpath($arrTemplate['STEP4_TEXT_08'],$strErrorMessage);
}
}
if ($intError != 0) {
$arrTemplate['ERRORMESSAGE'] = "<p style=\"color:#F00;margin-top:0px;font-weight:bold;\">".$strErrorMessage."</p>\n";
$arrTemplate['INFO_TEXT'] = "";
$arrTemplate['BUTTON'] = "<div id=\"install-back\">\n";
$arrTemplate['BUTTON'] .= "<input type='hidden' name='hidStep' id='hidStep' value='2' />\n";
2017-10-20 15:00:08 +02:00
$arrTemplate['BUTTON'] .= "<input type='image' src='images/previous.png' value='Submit' alt='Submit' /><br />".$myInstClass->translate("Back")."\n";
2017-05-22 11:24:21 +02:00
$arrTemplate['BUTTON'] .= "</div>\n";
} else {
$arrTemplate['ERRORMESSAGE'] = "";
$arrTemplate['INST_VISIBLE'] = "showfield";
2017-10-20 15:00:08 +02:00
$arrTemplate['INFO_TEXT'] = $myInstClass->translate("Please delete the install directory to continue!");
2017-05-22 11:24:21 +02:00
$arrTemplate['BUTTON'] = "<div id=\"install-next\">\n";
2017-10-20 15:00:08 +02:00
$arrTemplate['BUTTON'] .= "<a href='../index.php'><img src='images/next.png' alt='finish' title='finish' border='0' /></a><br />".$myInstClass->translate("Finish")."\n";
2017-05-22 11:24:21 +02:00
$arrTemplate['BUTTON'] .= "</div>\n";
}
//
// Write content
// =============
$strContent = $myInstClass->parseTemplate($arrTemplate,$preIncludeContent);
echo $strContent;
?>