json_encode($request))); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); $response = json_decode($response, true); print json_encode(true); die(); } // Check to see if we're being called from CLI mode, to check if we can run PHP scripts via cli if(isset($argv) && sizeof($argv) > 0) { // We need to make sure we can do the things we need in CLI mode. $results = array(); $results['mysql'] = extension_loaded("pdo_mysql"); $results['json'] = function_exists("json_encode"); $results['simplexml'] = function_exists("simplexml_load_file"); $results['pcntl'] = function_exists("pcntl_fork"); // memory limit check $memoryLimit = ini_get("memory_limit"); // Default to true $results['memorylimit'] = true; // It's in bytes, unless it's using some shorthand. if(preg_match("/^(\d+)([a-zA-Z])$/", $memoryLimit, $matches)) { // Using shorthand, convert to bytes if($matches[2] == 'm' || $matches[2] == 'M') { // Megabytes $memorySize = (1048576 * $matches[1]); } else if($matches[2] == 'K' || $matches[2] == 'k') { $memorySize = (1024 * $matches[1]); } else if($matches[2] == 'g' || $matches[2] == 'G') { $memorySize = (1073741824 * $matches[1]); } else { // Unknown shorthand $results['memorylimit'] = false; } } else if($memoryLimit != "-1") { $memorySize = $memoryLimit; } if($memoryLimit != "-1" && $memorySize < 67108864) { // Memory set is less than 64megs. This probably won't do. $results['memorylimit'] = false; } $results['memorysize'] = $memoryLimit; if(function_exists("json_encode")) { print(json_encode($results)); } else { print("fail"); } die(); } if(!isset($_POST['stage'])) { $stage = "1"; } else { $stage = $_POST['stage']; } if($stage == 2) { $error = false; if(!isset($_POST['mysqlRootUsername'])) { $mysqlRootUsername = 'root'; $mysqlRootPassword = ''; $mysqlHostname = 'localhost'; $mysqlUsername = ''; $mysqlPassword = ''; $mysqlDatabase = 'lilac'; $mysqlPopulate = true; $mysqlCreateUserDatabase = false; } else { $mysqlRootUsername = trim($_POST['mysqlRootUsername']); $mysqlRootPassword = trim($_POST['mysqlRootPassword']); $mysqlHostname = trim($_POST['mysqlHostname']); $mysqlUsername = trim($_POST['mysqlUsername']); $mysqlPassword = trim($_POST['mysqlPassword']); $mysqlDatabase = trim($_POST['mysqlDatabase']); $mysqlPopulate = trim($_POST['mysqlPopulate']); if(isset($_POST['mysqlCreateUserDatabase'])) { $mysqlCreateUserDatabase = true; } else { $mysqlCreateUserDatabase = false; } // Check for required parameters if($mysqlCreateUserDatabase) { if(empty($mysqlRootUsername)) { $error = "MySQL Administrator username cannot be blank if you want to create user and database."; } } if(!$error) { if(empty($mysqlHostname)) { $error = "MySQL Hostname cannot be blank."; } else if(empty($mysqlUsername)) { $error = "MySQL Username cannot be blank."; } else if(empty($mysqlDatabase)) { $error = "MySQL Database cannot be blank."; } } if(!$error) { // Okay, breathe, we're going to do the grunt of the work now. // Check to see if we need to create the user and database if($mysqlCreateUserDatabase) { // Attempt to connect as admin $dbConn = @mysql_connect($mysqlHostname, $mysqlRootUsername, $mysqlRootPassword); if(!$dbConn) { $error = "Failed to connect to MySQL server with Administrator login."; } else { if(!mysql_select_db("mysql", $dbConn)) { $error = "Failed creating user and database. Check your Admin credentials. Error was: " . mysql_error($dbConn) . ""; } else { // Create database if(!mysql_query("create database " . $mysqlDatabase, $dbConn)) { $error = "Failed to create database. Error was: " . mysql_error($dbConn) . ""; } else { // Okay, db is selected, let's grant privileges. // // NOTE TO SELF. TICKET #10 // // k if(in_array(strtolower($mysqlHostname), array('127.0.0.1', 'localhost'))) { // Assign rights to localhost if(!mysql_query("grant all privileges on " . $mysqlDatabase . ".* to '" . $mysqlUsername . "'@localhost identified by '" . $mysqlPassword . "'")) { $error = "Failed to create user. Error was: " . mysql_error($dbConn) . ""; } } else { // Assign rights via our hostname if(!mysql_query("grant all privileges on " . $mysqlDatabase . ".* to '" . $mysqlUsername . "'@'" . $_SERVER['SERVER_NAME'] . "' identified by '" . $mysqlPassword . "'")) { $error = "Failed to create user. Error was: " . mysql_error($dbConn) . ""; } } mysql_query("flush privileges"); } } } } if(!$error && $mysqlPopulate) { // Okay, we need to populate the database. Attempt to connect as our user. $dbConn = @mysql_connect($mysqlHostname, $mysqlUsername, $mysqlPassword); if(!$dbConn) { $error = "Failed to connect to MySQL server with " . $mysqlUsername . " user."; } else { // Select db. if(!mysql_select_db($mysqlDatabase, $dbConn)) { $error = "Failed to use " . $mysqlDatabase . " database. Check your User credentials. Error was: " . mysql_error($dbConn) . ""; } else { // Load the data exec("mysql -h " . $mysqlHostname . " -u " . $mysqlUsername . " -p" . $mysqlPassword . " " . $mysqlDatabase . " < " . dirname(__FILE__) . "/sqldata/schema.sql", $output, $retVal); if($retVal != 0) { $error = "Failed to import database schema. Make sure the mysql binary is in the search path for the web user."; } else { // Import labels exec("mysql -h " . $mysqlHostname . " -u " . $mysqlUsername . " -p" . $mysqlPassword . " " . $mysqlDatabase . " < " . dirname(__FILE__) . "/sqldata/lilac-nagios-en-label.sql", $output, $retVal); if($retVal != 0) { $error = "Failed to import Nagios labels. Error was:
" . str_replace("\n", "
", $output[count($output)]); } else { // Import Seed exec("mysql -h " . $mysqlHostname . " -u " . $mysqlUsername . " -p" . $mysqlPassword . " " . $mysqlDatabase . " < " . dirname(__FILE__) . "/sqldata/seed.sql", $output, $retVal); if($retVal != 0) { $error = "Failed to import seed data. Error was:
" . str_replace("\n", "
", $output[count($output)]); } } } } } } // Create PDO connection to perform upgrades try { $dbConn = new PDO("mysql:host=" . $mysqlHostname . ";dbname=" . $mysqlDatabase, $mysqlUsername, $mysqlPassword); } catch(PDOException $e) { $error = "Failed to connect to MySQL server with " . $mysqlUsername . " user:" . $e->getMessage(); } if(!$error) { if(!perform_upgrade($dbConn)) { $error = true; } } if(!$error) { // Okay, write to the configuration file! $conf = file_get_contents(dirname(__FILE__) . "/includes/lilac-conf.php.dist"); $conf = str_replace("%%DSN%%", "mysql:host=" . $mysqlHostname . ";dbname=" . $mysqlDatabase, $conf); $conf = str_replace("%%USERNAME%%",$mysqlUsername, $conf); $conf = str_replace("%%PASSWORD%%",$mysqlPassword, $conf); $conf = str_replace("%%DATABASE%%",$mysqlDatabase, $conf); // We have the new conf $ret = file_put_contents(dirname(__FILE__) . "/includes/lilac-conf.php", $conf); if($ret == false) { $error = "Failed to write to includes/lilac-conf.php. Check that the web user can write to the includes directory and try again."; } $success = "Completed Database Setup."; } } } } if(file_exists(dirname(__FILE__) . "/NOTICE")) { // Notice exists, we should display it here. $noticeContents = file_get_contents(dirname(__FILE__) . "/NOTICE"); $warning = $noticeContents; } print_header("Installer"); if($stage == 1) { $fatalErrors = false; // Dependency checking print_window_header("Dependency Checks"); ?>
Note: Lilac supports Nagios 3.x only. It is possible to import Nagios 2.x configuration files, but Lilac will only export to Nagios 3.x.
"> Configuration File Writable
The Lilac installer requires that it write to the configuration file at . It is recommended that you change the permissions of the includes directory so the web user can write to it.
"> PHP Version 5.2 or Better
PHP Version 5.2 or greater is required for Lilac. Download the latest at The PHP Group's Website or check with your operating system distribution. (Version 5.2 also provides the class DateTime, which is also required).
"> Magic Quotes GPC Set to Disabled
Magic Quotes GPC is set to enabled in your PHP configuration. Lilac will not work with Magic Quotes GPC set to enabled. Please disable it in your PHP configuration. Refer to Disabling Magic Quotes for more information.
"> PHP Pear Library Installed
PHP's PEAR library must be loaded. Please refer to PHP's PEAR Homepage for more information.
"> PHP PDO MySQL Extension Loaded
PHP's PDO MySQL extension must be loaded. This is not the same as the MySQLi extension. Please refer to PHP's PDO documentation for more information.
"> MySQL Client Executable
The Lilac installer needs the MySQL client binary to be installed and executable by the webserver if you need to populate the Lilac database. Install the MySQL command line utility.
"> NMAP Executable
Not a fatal error, Lilac needs the NMAP binary to be installed and executable by the webserver to perform auto-discovery tasks. Install the NMAP command line utility. If you are not going to perform auto-discovery tasks, you can ignore this and continue. If you choose to do auto-discovery tasks in the future, you must have NMAP installed.
"> PHP Curl Support
PHP's Curl support is not available. Curl is required for for Lilac to call internal webservices.. For more information, refer to PHP'S Curl Extension setup guide for more information on how to install it.
"> PHP SimpleXML Support
PHP's SimpleXML support is not available. SimpleXML is required for parsing XML documents and is used by Lilac's Autodiscovery system. For more information, refer to PHP'S SimpleXML Extension setup guide for more information on how to install it.
"> PHP POSIX Support
PHP's POSIX support is not available. POSIX support is required for the importer/exporter/autodiscovery to function. For instructions, refer to PHP's POSIX Extension setup guide for more information on how to install it.
"> PHP JSON Support
PHP's JSON support is not available. JSON support is automatically provided in PHP 5.2.0. For previous versions of PHP, refer to PHP's JSON Extension setup guide for more information on how to install it.
"> PHP Command Line Interface (CLI) Available
Lilac must be able to run command line PHP script to import and export configurations. Please make sure PHP's command line interface is installed and the PHP binary is in the search path for the web user. Refer to The PHP Group's Homepage for more information.
"> CLI JSON Support
JSON Support must be provided to PHP's command line interface. This is automatically provided in PHP 5.2.0 and above. For previous versions of PHP, refer to PHP's JSON Extension setup guide for more information on how to install it.
"> PHP Memory Limit For Scripts:
Not Really an Errror, but a note, PHP's Memory Limit for the command line scripts must be set to either -1 (Unlimited) or to a reasonable amount according to the size of your configuration. Suggested amount is 64M. Refer to php.ini directives for more information on how to change this value.
"> CLI Process Control Support
PHP must have Process control compiled in in order to properly import/export and auto-discover. For more information on how to install process control for PHP, refer to PHP's PCNTL Installation documentation.
"> CLI PDO MySQL Support
MySQL Support must be provided to PHP's command line interface. This is not the same as the MySQLi extension. Please refer to PHP's PDO documentation for more information.
"> PHP SimpleXML Support
PHP's SimpleXML support is not available for PHP's command line interface. SimpleXML is required for parsing XML documents and is used by Lilac's Autodiscovery system. For more information, refer to PHP'S SimpleXML Extension setup guide for more information on how to install it.
You must resolve the issues above before continuing the installation. Refresh The Page to perform the checks again.
Lilac needs credentials to connect to your MySQL server. The user should have all privileges on the Lilac database (except for grant). If you do not know how to create a MySQL user and database, you can provide your MySQL root credentials to create the user and database.

MySQL Connection Information

name="mysqlPopulate" id="populatedb">

Congratulations!

Your lilac installation is now complete. You should remove the install.php script as it is no longer needed. You can also remove the write privileges to the includes directory.

Want to help us improve Lilac?

We're very interested in knowing who is using Lilac and how they're using the tool. Fill out the completely optional form below to help us improve Lilac's future releases. Or you can choose to Launch Lilac Now.



Launch Lilac Now

<?php echo LILAC_NAME . " "; echo LILAC_VERSION;?><?php if($title) print(" - " . $title);?>
prepare("describe nagios_host"); $results = $stmt->execute(); $found = false; while($row = $stmt->fetch()) { if($row['Field'] == "parent_host") $found = true; } if($found) { $stmt = $dbConn->prepare("SELECT id, parent_host FROM nagios_host WHERE parent_host IS NOT NULL"); $insertStmt = $dbConn->prepare("INSERT INTO nagios_host_parent(child_host, parent_host) VALUES(?,?)"); $hosts = $stmt->execute(); while($host = $stmt->fetch()) { $insertStmt->execute(array($host['id'], $host['parent_host'])); } $dbConn->exec("ALTER TABLE nagios_host DROP COLUMN parent_host"); } // Check to see if column exists, parent_host in nagios_host_template $stmt = $dbConn->prepare("describe nagios_host_template"); $results = $stmt->execute(); $found = false; while($row = $stmt->fetch()) { if($row['Field'] == "parent_host") $found = true; } if($found) { $stmt = $dbConn->prepare("SELECT id, parent_host FROM nagios_host_template WHERE parent_host IS NOT NULL"); $insertStmt = $dbConn->prepare("INSERT INTO nagios_host_parent(child_host_template, parent_host) VALUES(?,?)"); $templates = $stmt->execute(); while($template = $stmt->fetch()) { $insertStmt->execute(array($template['id'], $template['parent_host'])); } $dbConn->exec("ALTER TABLE nagios_host_template DROP COLUMN parent_host"); } // Okay, check to see if columns exist in service and service templates // table $stmt = $dbConn->prepare("describe nagios_service"); $results = $stmt->execute(); $found = false; while($row = $stmt->fetch()) { if($row['Field'] == "retry_interval") $found = true; } if(!$found) { // Insert column definitions into service and service_templates $dbConn->exec("ALTER TABLE nagios_service CHANGE COLUMN retry_check_interval retry_interval INTEGER"); } $results = $stmt->execute(); $found = false; while($row = $stmt->fetch()) { if($row['Field'] == "first_notification_delay") $found = true; } if(!$found) { // Insert column definitions into service and service_templates $dbConn->exec("ALTER TABLE nagios_service ADD COLUMN first_notification_delay INTEGER"); } $stmt = $dbConn->prepare("describe nagios_service_template"); $results = $stmt->execute(); $found = false; while($row = $stmt->fetch()) { if($row['Field'] == "retry_interval") $found = true; } if(!$found) { // Insert column definitions into service and service_templates $dbConn->exec("ALTER TABLE nagios_service_template CHANGE COLUMN retry_check_interval retry_interval INTEGER"); } $results = $stmt->execute(); $found = false; while($row = $stmt->fetch()) { if($row['Field'] == "first_notification_delay") $found = true; } if(!$found) { // Insert column definitions into service and service_templates $dbConn->exec("ALTER TABLE nagios_service_template ADD COLUMN first_notification_delay INTEGER"); } // Modify nagios_contacts $dbConn->exec("ALTER TABLE nagios_contact MODIFY host_notification_period INTEGER"); $dbConn->exec("ALTER TABLE nagios_contact MODIFY service_notification_period INTEGER"); // Add p1_file to nagios_main_configuration $stmt = $dbConn->prepare("describe nagios_main_configuration"); $results = $stmt->execute(); $found = false; while($row = $stmt->fetch()) { if($row['Field'] == "p1_file") $found = true; } if(!$found) { $dbConn->exec("ALTER TABLE nagios_main_configuration ADD COLUMN p1_file VARCHAR(255)"); } // Okay, let's make sure our version is set! $dbConn->exec("DELETE FROM lilac_configuration"); $stmt = $dbConn->prepare("INSERT INTO lilac_configuration(version) VALUES(?)"); $stmt->execute(array(LILAC_VERSION)); return true; }