"; echo " $label "; echo ""; if (!extension_loaded($ext)){ echo ""; return 1; } else { echo ""; return 0; } echo ""; } function check_include ( $ext, $label ){ echo ""; echo " $label "; echo ""; if (!include($ext)){ echo ""; return 1; } else { echo ""; return 0; } echo ""; } function check_exists ( $file, $label ){ echo ""; echo " $label "; echo ""; if (!file_exists ($file)){ echo " "; return 1; } else { echo " "; return 0; } echo ""; } function check_generic ( $ok, $label ){ echo ""; echo " $label "; echo ""; if ($ok == 0 ){ echo " "; return 1; } else { echo " "; return 0; } echo ""; } function check_writable ( $fullpath, $label ){ echo ""; echo " $label "; echo ""; if (file_exists($fullpath)) if (is_writable($fullpath)){ echo " "; echo ""; return 0; } else { echo " "; echo ""; return 1; } else { echo " "; echo ""; return 1; } } function check_variable ( $var, $value, $label, $mode ){ echo ""; echo " $label "; echo ""; if ($mode == 1){ if ($var >= $value){ echo " "; return 0; } else { echo " "; return 1; } } elseif ($var == $value){ echo " "; return 0; } else { echo " "; return 1; } echo ""; } function parse_mysql_dump($url){ if (file_exists($url)){ $file_content = file($url); $query = ""; foreach($file_content as $sql_line){ if(trim($sql_line) != "" && strpos($sql_line, "--") === false){ $query .= $sql_line; if(preg_match("/;[\040]*\$/", $sql_line)){ if (!$result = mysql_query($query)) { echo mysql_error(); //Uncomment for debug echo "
$query
"; return 0; } $query = ""; } } } return 1; } else return 0; } function parse_postgresql_dump($connection, $url, $debug = false) { if (file_exists($url)) { $file_content = file($url); $query = ""; foreach($file_content as $sql_line){ $clean_line = trim($sql_line); $comment = preg_match("/^(\s|\t)*--.*$/", $clean_line); if ($comment) { continue; } if (empty($clean_line)) { continue; } $query .= $clean_line; //Check if the end of query with the the semicolon and any returns in the end of line if(preg_match("/;[\040]*\$/", $clean_line)) { //And execute and clean buffer pg_send_query($connection, $query); $result = pg_get_result($connection); if ($debug) { var_dump($query); var_dump(pg_result_error($result)); } if (pg_result_status($result) == PGSQL_FATAL_ERROR) { echo pg_result_error($result); echo "
$query
"; return 0; } $query = ""; } } return 1; } else { return 0; } } function random_name ($size){ $temp = ""; for ($a=0;$a< $size;$a++) $temp = $temp. chr(rand(122,97)); return $temp; } function print_logo_status ($step, $step_total){ global $banner; echo "

$banner

Install step $step of $step_total
"; } function install_step1() { global $banner; echo "

Pandora FMS installation wizard. Step #1 of 5

Welcome to Pandora FMS installation Wizard

This wizard helps you to quick install Pandora FMS console in your system.

In four steps checks all dependencies and make your configuration for a quick installation.

For more information, please refer to documentation.

Pandora FMS Development Team "; if (file_exists("include/config.php")){ echo "
Warning: You already have a config.php file. Configuration and database would be overwritten if you continued.
"; } echo ""; $writable = check_writable ( "include", "Checking if ./include is writable"); if (file_exists("include/config.php")) $writable += check_writable ( "include/config.php", "Checking if include/config.php is writable"); echo "
"; echo "
Warning: This installer will overwrite and destroy your existing Pandora FMS configuration and Database. Before continue, please be sure that you have no valuable Pandora FMS data in your Database.
"; echo "
Upgrade: If you want to upgrade from Pandora FMS 2.x to 3.0 version, please download the migration tool from our website at PandoraFMS.com web site.
"; echo "
"; print_logo_status (1, 5); echo "
"; if ($writable == 0) { echo "

"; } else echo "
ERROR:You need to setup permissions to be able to write in ./include directory
"; echo "
Pandora FMS is an OpenSource Software project registered at SourceForge
"; } function install_step1_licence() { echo "

Pandora FMS installation wizard. Step #2 of 5

GPL2 Licence terms agreement

Pandora FMS is an OpenSource software project licensed under the GPL2 licence. Pandora FMS includes, as well, another software also licensed under LGPL and BSD licenses. Before continue, you must accept the licence terms..

For more information, please refer to our website at http://pandorafms.org and contact us if you have any kind of question about the usage of Pandora FMS

If you dont accept the licence terms, please, close your browser and delete Pandora FMS files.

"; if (!file_exists("COPYING")){ echo "
Licence file 'COPYING' is not present in your distribution. This means you have some 'partial' Pandora FMS distribution. We cannot continue without accepting the licence file."; echo "
"; } else { echo "
"; echo ""; echo "

"; echo ""; } echo "

"; print_logo_status (2, 5); echo "
Pandora FMS is an OpenSource Software project registered at SourceForge
"; } function install_step2() { echo "

Pandora FMS console installation wizard. Step #3 of 5

"; echo "

Checking software dependencies

"; echo ""; $res = 0; $res += check_variable(phpversion(),"5.2","PHP version >= 5.2",1); $res += check_extension("gd","PHP GD extension"); $res += check_extension("ldap","PHP LDAP extension"); $res += check_extension("snmp","PHP SNMP extension"); $res += check_extension("session","PHP session extension"); $res += check_extension("gettext","PHP gettext extension"); $res += check_extension("mbstring","PHP Multibyte String"); $res += check_extension("zip","PHP Zip"); $res += check_extension("curl","CURL (Client URL Library)"); if (PHP_OS == "FreeBSD") { $res += check_exists ("/usr/local/bin/twopi","Graphviz Binary"); } else { $res += check_exists ("/usr/bin/twopi","Graphviz Binary"); } echo ""; check_extension("mysql", "PHP MySQL extension"); check_extension("pgsql", "PHP PostgreSQL extension"); echo "
"; echo "DB Engines"; echo ""; echo "
"; echo "
"; print_logo_status (3,5); echo "
"; if ($res > 0) { echo "
You have some incomplete dependencies. Please correct them or this installer will not be able to finish your installation.
Ignore it. Force install Step #3"; } else { echo "
"; } echo "
Pandora FMS is an OpenSource Software project registered at SourceForge
"; } function install_step3() { $options = ''; if (extension_loaded("mysql")) { $options .= ""; } if (extension_loaded("pgsql")) { $options .= ""; } $error = false; if (empty($options)) { $error = true; } echo "

Pandora FMS console installation wizard. Step #4 of 5

Environment and database setup

This wizard will create your Pandora FMS database, and populate it with all the data needed to run for the first time.

You need a privileged user to create database schema, this is usually root user. Information about root user will not be used or stored anymore.

Now, please, complete all details to configure your database and environment setup.

Warning: This installer will overwrite and destroy your existing Pandora FMS configuration and Database. Before continue, please be sure that you have no valuable Pandora FMS data in your Database.

"; if (!$error) { echo ""; } echo "
DB ENGINE
"; if ($error) { echo "
Warning: You haven't a any DB engine with PHP. Please check the previous step to DB engine dependencies.
"; } else { echo ""; } echo "
DB User with privileges on DB
DB Password for this user
DB Hostname
DB Name (pandora by default)
Drop Database if exists
Full path to HTTP publication directory
For example /var/www/pandora_console/. Needed for graphs and attachments.
URL path to Pandora FMS Console
For example '/pandora_console'
"; if (!$error) { echo "

"; } echo "
"; print_logo_status (4,5); echo "
Pandora FMS is an OpenSource Software project registered at SourceForge
"; } function install_step4() { $pandora_config = "include/config.php"; if ( (! isset($_POST["user"])) || (! isset($_POST["dbname"])) || (! isset($_POST["host"])) || (! isset($_POST["pass"])) || (!isset($_POST['engine'])) ) { $dbpassword = ""; $dbuser = ""; $dbhost = ""; $dbname = ""; $engine = ""; } else { $engine = $_POST['engine']; $dbpassword = $_POST["pass"]; $dbuser = $_POST["user"]; $dbhost = $_POST["host"]; if (isset($_POST["drop"])) $dbdrop = $_POST["drop"]; else $dbdrop = 0; $dbname = $_POST["dbname"]; if (isset($_POST["url"])) $url = $_POST["url"]; else $url = "http://localhost"; if (isset($_POST["path"])) $path = $_POST["path"]; else $path = "/var/www"; } $everything_ok = 0; $step1=0; $step2=0; $step3=0; $step4=0; $step5=0; $step6=0; $step7=0; echo "

Pandora FMS Console installation wizard. Step #5 of 5

Creating database and default configuration file

"; switch ($engine) { case 'mysql': if (! mysql_connect ($dbhost, $dbuser, $dbpassword)) { check_generic ( 0, "Connection with Database"); } else { check_generic ( 1, "Connection with Database"); // Drop database if needed if ($dbdrop == 1) { mysql_query ("DROP DATABASE IF EXISTS $dbname"); } // Create schema $step1 = mysql_query ("CREATE DATABASE $dbname"); check_generic ($step1, "Creating database '$dbname'"); if ($step1 == 1) { $step2 = mysql_select_db($dbname); check_generic ($step2, "Opening database '$dbname'"); $step3 = parse_mysql_dump("pandoradb.sql"); check_generic ($step3, "Creating schema"); $step4 = parse_mysql_dump("pandoradb_data.sql"); check_generic ($step4, "Populating database"); $random_password = random_name (8); $host = 'localhost'; if ($dbhost != 'localhost') $host = $_SERVER['SERVER_ADDR']; $step5 = mysql_query ("GRANT ALL PRIVILEGES ON $dbname.* to pandora@$host IDENTIFIED BY '".$random_password."'"); mysql_query ("FLUSH PRIVILEGES"); check_generic ($step5, "Established privileges for user pandora. A new random password has been generated: $random_password
Please write it down, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file
"); $step6 = is_writable("include"); check_generic ($step6, "Write permissions to save config file in './include'"); $cfgin = fopen ("include/config.inc.php","r"); $cfgout = fopen ($pandora_config,"w"); $config_contents = fread ($cfgin, filesize("include/config.inc.php")); $dbtype = 'mysql'; $config_new = ''; $step7 = fputs ($cfgout, $config_new); $step7 = $step7 + fputs ($cfgout, $config_contents); if ($step7 > 0) $step7 = 1; fclose ($cfgin); fclose ($cfgout); chmod ($pandora_config, 0600); check_generic ($step7, "Created new config file at '".$pandora_config."'"); } } if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) { $everything_ok = 1; } break; case 'pgsql': $step1 = $step2 = $step3 = $step4 = $step5 = $step6 = $step7 = 0; $connection = pg_connect("host='" . $dbhost . "' user='" . $dbuser . "' password='" . $dbpassword . "'"); if ($connection === false) { check_generic(0, "Connection with Database"); } else { check_generic(1, "Connection with Database"); // Drop database if needed if ($dbdrop == 1) { $result = pg_query($connection, "DROP DATABASE \"" . $dbname . "\";"); } pg_send_query($connection, "CREATE DATABASE \"" . $dbname . "\" WITH ENCODING 'utf8';"); $result = pg_get_result($connection); if (pg_result_status($result) != PGSQL_FATAL_ERROR) { $step1 = 1; } check_generic ($step1, "Creating database '$dbname'"); if ($step1 == 1) { //Reopen DB because I don't know how to use DB in PostgreSQL pg_close($connection); $connection = pg_connect("host='" . $dbhost . "' dbname='" . $dbname . "' user='" . $dbuser . "' password='" . $dbpassword . "'"); if ($connection !== false) { $step2 = 1; } } check_generic ($step2, "Opening database '$dbname'"); if ($step2) { $step3 = parse_postgresql_dump($connection, "pandoradb.postgreSQL.sql"); } check_generic($step3, "Creating schema"); if ($step3) { $step4 = parse_postgresql_dump($connection, "pandoradb.data.postgreSQL.sql"); } check_generic ($step4, "Populating database"); if ($step4) { $random_password = random_name (8); pg_query($connection, "DROP USER pandora"); pg_send_query($connection, "CREATE USER pandora WITH PASSWORD '" . $random_password . "'"); $result = pg_get_result($connection); if (pg_result_status($result) != PGSQL_FATAL_ERROR) { //Set the privileges for DB pg_send_query($connection, "GRANT ALL PRIVILEGES ON DATABASE pandora to pandora;"); $result = pg_get_result($connection); $setDBPrivileges = 0; if (pg_result_status($result) != PGSQL_FATAL_ERROR) { $setDBPrivileges = 1; } if ($setDBPrivileges) { //Set the privileges for each tables. pg_send_query($connection, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';"); $result = pg_get_result($connection); $tables = array(); while ($row = pg_fetch_assoc($result)) { $tables[] = $row['table_name']; } $correct = 1; foreach ($tables as $table) { pg_send_query($connection, "GRANT ALL PRIVILEGES ON TABLE " . $table . " to pandora;"); $result = pg_get_result($connection); if (pg_result_status($result) == PGSQL_FATAL_ERROR) { $correct = 0; break; } //INI ----- Grant for secuences pg_send_query($connection, "SELECT column_name FROM information_schema.columns WHERE table_name = '" . $table . "';"); $result2 = pg_get_result($connection); $columns = array(); while ($row = pg_fetch_assoc($result2)) { $columns[] = $row['column_name']; } //Check for each column if it have a sequence to grant foreach ($columns as $column) { pg_send_query($connection, "SELECT pg_get_serial_sequence('" . $table . "', '" . $column . "');"); $result3 = pg_get_result($connection); $sequence = pg_fetch_assoc($result3); if (!empty($sequence['pg_get_serial_sequence'])) { pg_send_query($connection, "GRANT ALL PRIVILEGES ON SEQUENCE " . $sequence['pg_get_serial_sequence'] . " to pandora;"); $result4 = pg_get_result($connection); if (pg_result_status($result4) == PGSQL_FATAL_ERROR) { $correct = 0; break; } } } //END ----- Grant for secuences } if ($correct) { $step5 = 1; } } } } check_generic ($step5, "Established privileges for user pandora. A new random password has been generated: $random_password
Please write it down, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file
"); if ($step5) { $step6 = is_writable("include"); } check_generic ($step6, "Write permissions to save config file in './include'"); if ($step6) { $cfgin = fopen ("include/config.inc.php","r"); $cfgout = fopen ($pandora_config,"w"); $config_contents = fread ($cfgin, filesize("include/config.inc.php")); $dbtype = 'postgresql'; $config_new = ''; $step7 = fputs ($cfgout, $config_new); $step7 = $step7 + fputs ($cfgout, $config_contents); if ($step7 > 0) $step7 = 1; fclose ($cfgin); fclose ($cfgout); chmod ($pandora_config, 0600); } check_generic ($step7, "Created new config file at '".$pandora_config."'"); if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) { $everything_ok = 1; } } break; } echo "
"; print_logo_status(4,5); echo "
"; if ($everything_ok == 1) { echo "

"; } else { echo "
There were some problems. Installation was not completed.

Please correct failures before trying again. All database schemes created in this step have been dropped.

"; switch ($engine) { case 'mysql': if (mysql_error() != "") { echo "
ERROR: ". mysql_error().".
"; } if ($step1 == 1) { mysql_query ("DROP DATABASE $dbname"); } break; case 'pgsql': break; } } echo "
Pandora FMS is an Open Source Software project registered at SourceForge
"; } function install_step5() { echo "

Pandora FMS console installation wizard. Finished

Installation complete

For security, you now must manually delete this installer ('install.php') file before trying to access to your Pandora FMS console.

You should also install Pandora FMS Servers before trying to monitor anything; please read documentation on how to install it.

Default user is 'admin' with password 'pandora', please change it both as soon as possible.

Don't forget to check http://pandorafms.com for updates.


Click here to access to your Pandora FMS console.

"; print_logo_status (5,5); echo "
Pandora FMS is an OpenSource Software project registered at SourceForge
"; } // --------------- // Main page code // --------------- if (! isset($_GET["step"])){ install_step1(); } else { $step = $_GET["step"]; switch ($step) { case 11: install_step1_licence(); break; case 2: install_step2(); break; case 3: install_step3(); break; case 4: install_step4(); break; case 5: install_step5(); break; } } ?>