mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-24 06:15:16 +02:00
2011-02-24 Miguel de Dios <miguel.dedios@artica.es>
* include/db/postgresql.php: in function "postgresql_connect_db" added quotes for special names in user or password or host. Fixed in function "postgresql_process_sql" the output errors. * install.php: begin to make a source code to install Pandora in DB schema on PostgreSQL. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4019 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
170fb63d3c
commit
b73a6f05e2
@ -1,3 +1,12 @@
|
|||||||
|
2011-02-24 Miguel de Dios <miguel.dedios@artica.es>
|
||||||
|
|
||||||
|
* include/db/postgresql.php: in function "postgresql_connect_db" added
|
||||||
|
quotes for special names in user or password or host. Fixed in function
|
||||||
|
"postgresql_process_sql" the output errors.
|
||||||
|
|
||||||
|
* install.php: begin to make a source code to install Pandora in DB schema
|
||||||
|
on PostgreSQL.
|
||||||
|
|
||||||
2011-02-24 Sergio Martin <sergio.martin@artica.es>
|
2011-02-24 Sergio Martin <sergio.martin@artica.es>
|
||||||
|
|
||||||
* install.php: Remove the cheching dependences
|
* install.php: Remove the cheching dependences
|
||||||
|
@ -26,10 +26,10 @@ function postgresql_connect_db($host = null, $db = null, $user = null, $pass = n
|
|||||||
if ($pass === null)
|
if ($pass === null)
|
||||||
$pass = $config["dbpass"];
|
$pass = $config["dbpass"];
|
||||||
|
|
||||||
$config['dbconnection'] = pg_connect("host=" . $host .
|
$config['dbconnection'] = pg_connect("host='" . $host . "'" .
|
||||||
" dbname=" . $db .
|
" dbname='" . $db . "'" .
|
||||||
" user=" . $user .
|
" user='" . $user . "'" .
|
||||||
" password=" . $pass);
|
" password='" . $pass . "'");
|
||||||
|
|
||||||
if (! $config['dbconnection']) {
|
if (! $config['dbconnection']) {
|
||||||
include ($config["homedir"]."/general/error_authconfig.php");
|
include ($config["homedir"]."/general/error_authconfig.php");
|
||||||
@ -208,8 +208,8 @@ function postgresql_process_sql($sql, $rettype = "affected_rows", $dbconnection
|
|||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
$backtrace = debug_backtrace ();
|
$backtrace = debug_backtrace ();
|
||||||
$error = sprintf ('%s (\'%s\') in <strong>%s</strong> on line %d',
|
$error = sprintf ('%s (\'%s\') in <strong>%s</strong> on line %d',
|
||||||
mysql_error (), $sql, $backtrace[0]['file'], $backtrace[0]['line']);
|
pg_result_error($result), $sql, $backtrace[0]['file'], $backtrace[0]['line']);
|
||||||
add_database_debug_trace ($sql, mysql_error ());
|
add_database_debug_trace ($sql, pg_result_error($result));
|
||||||
set_error_handler ('sql_error_handler');
|
set_error_handler ('sql_error_handler');
|
||||||
trigger_error ($error);
|
trigger_error ($error);
|
||||||
restore_error_handler ();
|
restore_error_handler ();
|
||||||
|
@ -170,6 +170,29 @@ function parse_mysql_dump($url){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parse_postgresql_dump($url) {
|
||||||
|
if (file_exists($url)) {
|
||||||
|
$file_content = file($url);
|
||||||
|
|
||||||
|
$query = "";
|
||||||
|
|
||||||
|
foreach($file_content as $sql_line){
|
||||||
|
$comment = preg_match("/^(\s|\t)*--.*$/", $line);
|
||||||
|
if ($comment) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$clean_line = $sql_line;
|
||||||
|
var_dump($clean_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function random_name ($size){
|
function random_name ($size){
|
||||||
$temp = "";
|
$temp = "";
|
||||||
for ($a=0;$a< $size;$a++)
|
for ($a=0;$a< $size;$a++)
|
||||||
@ -297,7 +320,6 @@ function install_step2() {
|
|||||||
echo "<table border=0 width=230>";
|
echo "<table border=0 width=230>";
|
||||||
$res = 0;
|
$res = 0;
|
||||||
$res += check_variable(phpversion(),"5.2","PHP version >= 5.2",1);
|
$res += check_variable(phpversion(),"5.2","PHP version >= 5.2",1);
|
||||||
$res += check_extension("mysql","PHP MySQL extension");
|
|
||||||
$res += check_extension("gd","PHP GD extension");
|
$res += check_extension("gd","PHP GD extension");
|
||||||
$res += check_extension("ldap","PHP LDAP extension");
|
$res += check_extension("ldap","PHP LDAP extension");
|
||||||
$res += check_extension("snmp","PHP SNMP extension");
|
$res += check_extension("snmp","PHP SNMP extension");
|
||||||
@ -312,7 +334,14 @@ function install_step2() {
|
|||||||
else {
|
else {
|
||||||
$res += check_exists ("/usr/bin/twopi","Graphviz Binary");
|
$res += check_exists ("/usr/bin/twopi","Graphviz Binary");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
echo "<tr><td>";
|
||||||
|
echo "<span style='display: block; font-family: verdana,arial,sans;
|
||||||
|
font-size: 8.5pt;margin-top: 2px; font-weight: bolder;'>DB Engines</span>";
|
||||||
|
echo "</td><td>";
|
||||||
|
echo "</td></tr>";
|
||||||
|
check_extension("mysql", "PHP MySQL extension");
|
||||||
|
check_extension("pgsql", "PHP PostgreSQL extension");
|
||||||
echo "</table>";
|
echo "</table>";
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
print_logo_status (3,5);
|
print_logo_status (3,5);
|
||||||
@ -343,6 +372,19 @@ function install_step2() {
|
|||||||
|
|
||||||
|
|
||||||
function install_step3() {
|
function install_step3() {
|
||||||
|
$options = '';
|
||||||
|
if (extension_loaded("mysql")) {
|
||||||
|
$options .= "<option value='mysql'>MySQL</option>";
|
||||||
|
}
|
||||||
|
if (extension_loaded("pgsql")) {
|
||||||
|
$options .= "<option value='pgsql'>PostgreSQL</option>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$error = false;
|
||||||
|
if (empty($options)) {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
|
||||||
echo "
|
echo "
|
||||||
<div id='install_container'>
|
<div id='install_container'>
|
||||||
<h1>Pandora FMS console installation wizard. Step #4 of 5 </h1>
|
<h1>Pandora FMS console installation wizard. Step #4 of 5 </h1>
|
||||||
@ -365,15 +407,31 @@ function install_step3() {
|
|||||||
Pandora FMS configuration and <b>Database</b>. Before continue,
|
Pandora FMS configuration and <b>Database</b>. Before continue,
|
||||||
please <b>be sure that you have no valuable Pandora FMS data in your Database.</b>
|
please <b>be sure that you have no valuable Pandora FMS data in your Database.</b>
|
||||||
<br><br>
|
<br><br>
|
||||||
</div>
|
</div>";
|
||||||
<form method='post' action='install.php?step=4'>
|
if (!$error) {
|
||||||
<div>DB User with privileges on MySQL</div>
|
echo "<form method='post' action='install.php?step=4'>";
|
||||||
|
}
|
||||||
|
echo "<div>DB ENGINE</div>";
|
||||||
|
|
||||||
|
|
||||||
|
if ($error) {
|
||||||
|
echo "
|
||||||
|
<div class='warn'>
|
||||||
|
<b>Warning:</b> You haven't a any DB engine with PHP. Please check the previous step to DB engine dependencies.
|
||||||
|
</div>";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo "<select name='engine'>";
|
||||||
|
echo $options;
|
||||||
|
echo "</select>";
|
||||||
|
}
|
||||||
|
echo " <div>DB User with privileges on DB</div>
|
||||||
<input class='login' type='text' name='user' value='root'>
|
<input class='login' type='text' name='user' value='root'>
|
||||||
|
|
||||||
<div>DB Password for this user</div>
|
<div>DB Password for this user</div>
|
||||||
<input class='login' type='password' name='pass' value=''>
|
<input class='login' type='password' name='pass' value=''>
|
||||||
|
|
||||||
<div>DB Hostname of MySQL</div>
|
<div>DB Hostname</div>
|
||||||
<input class='login' type='text' name='host' value='localhost'>
|
<input class='login' type='text' name='host' value='localhost'>
|
||||||
|
|
||||||
<div>DB Name (pandora by default)</div>
|
<div>DB Name (pandora by default)</div>
|
||||||
@ -395,16 +453,20 @@ function install_step3() {
|
|||||||
</div>
|
</div>
|
||||||
<input class='login' type='text' name='url' style='width: 250px;'
|
<input class='login' type='text' name='url' style='width: 250px;'
|
||||||
value='".dirname ($_SERVER["SCRIPT_NAME"])."'>
|
value='".dirname ($_SERVER["SCRIPT_NAME"])."'>
|
||||||
|
";
|
||||||
<div align='right'><br>
|
|
||||||
|
if (!$error) {
|
||||||
|
echo " <div align='right'><br>
|
||||||
<input type='image' src='images/arrow_next.png' value='Step #4' id='step4'>
|
<input type='image' src='images/arrow_next.png' value='Step #4' id='step4'>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
";
|
||||||
|
}
|
||||||
|
echo " </form>
|
||||||
</div>";
|
</div>";
|
||||||
|
|
||||||
print_logo_status (4,5);
|
print_logo_status (4,5);
|
||||||
|
|
||||||
echo "</div>
|
echo "</div>
|
||||||
<div id='foot_install'>
|
<div id='foot_install'>
|
||||||
<i>Pandora FMS is an OpenSource Software project registered at
|
<i>Pandora FMS is an OpenSource Software project registered at
|
||||||
<a target='_new' href='http://pandora.sourceforge.net'>SourceForge</a></i>
|
<a target='_new' href='http://pandora.sourceforge.net'>SourceForge</a></i>
|
||||||
@ -416,13 +478,15 @@ function install_step4() {
|
|||||||
$pandora_config = "include/config.php";
|
$pandora_config = "include/config.php";
|
||||||
|
|
||||||
if ( (! isset($_POST["user"])) || (! isset($_POST["dbname"])) || (! isset($_POST["host"])) ||
|
if ( (! isset($_POST["user"])) || (! isset($_POST["dbname"])) || (! isset($_POST["host"])) ||
|
||||||
(! isset($_POST["pass"])) ) {
|
(! isset($_POST["pass"])) || (!isset($_POST['engine'])) ) {
|
||||||
$dbpassword = "";
|
$dbpassword = "";
|
||||||
$dbuser = "";
|
$dbuser = "";
|
||||||
$dbhost = "";
|
$dbhost = "";
|
||||||
$dbname = "";
|
$dbname = "";
|
||||||
|
$engine = "";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
$engine = $_POST['engine'];
|
||||||
$dbpassword = $_POST["pass"];
|
$dbpassword = $_POST["pass"];
|
||||||
$dbuser = $_POST["user"];
|
$dbuser = $_POST["user"];
|
||||||
$dbhost = $_POST["host"];
|
$dbhost = $_POST["host"];
|
||||||
@ -454,72 +518,120 @@ function install_step4() {
|
|||||||
<div id='install_box'>
|
<div id='install_box'>
|
||||||
<h2>Creating database and default configuration file</h2>
|
<h2>Creating database and default configuration file</h2>
|
||||||
<table>";
|
<table>";
|
||||||
if (! mysql_connect ($dbhost,$dbuser,$dbpassword)) {
|
switch ($engine) {
|
||||||
check_generic ( 0, "Connection with Database");
|
case 'mysql':
|
||||||
}
|
if (! mysql_connect ($dbhost, $dbuser, $dbpassword)) {
|
||||||
else {
|
check_generic ( 0, "Connection with Database");
|
||||||
check_generic ( 1, "Connection with Database");
|
}
|
||||||
|
else {
|
||||||
// Drop database if needed
|
check_generic ( 1, "Connection with Database");
|
||||||
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: <b>$random_password</b><div class='warn'>Please write it down, you will need to setup your Pandora FMS server, editing the </i>/etc/pandora/pandora_server.conf</i> file</div>");
|
|
||||||
|
|
||||||
$step6 = is_writable("include");
|
|
||||||
check_generic ($step6, "Write permissions to save config file in './include'");
|
|
||||||
|
|
||||||
$cfgin = fopen ("include/config.inc.php","r");
|
// Drop database if needed
|
||||||
$cfgout = fopen ($pandora_config,"w");
|
if ($dbdrop == 1)
|
||||||
$config_contents = fread ($cfgin, filesize("include/config.inc.php"));
|
mysql_query ("DROP DATABASE IF EXISTS $dbname");
|
||||||
$dbtype = 'mysql'; //TODO set other types
|
|
||||||
$config_new = '<?php
|
// Create schema
|
||||||
// Begin of automatic config file
|
$step1 = mysql_query ("CREATE DATABASE $dbname");
|
||||||
$config["dbtype"] = "' . $dbtype . '"; //DB type (mysql, postgres)
|
check_generic ($step1, "Creating database '$dbname'");
|
||||||
$config["dbname"]="'.$dbname.'"; // MySQL DataBase name
|
if ($step1 == 1) {
|
||||||
$config["dbuser"]="pandora"; // DB User
|
$step2 = mysql_select_db($dbname);
|
||||||
$config["dbpass"]="'.$random_password.'"; // DB Password
|
check_generic ($step2, "Opening database '$dbname'");
|
||||||
$config["dbhost"]="'.$dbhost.'"; // DB Host
|
|
||||||
$config["homedir"]="'.$path.'"; // Config homedir
|
$step3 = parse_mysql_dump("pandoradb.sql");
|
||||||
$config["homeurl"]="'.$url.'"; // Base URL
|
check_generic ($step3, "Creating schema");
|
||||||
// End of automatic config file
|
|
||||||
?>';
|
$step4 = parse_mysql_dump("pandoradb_data.sql");
|
||||||
$step7 = fputs ($cfgout, $config_new);
|
check_generic ($step4, "Populating database");
|
||||||
$step7 = $step7 + fputs ($cfgout, $config_contents);
|
|
||||||
if ($step7 > 0)
|
$random_password = random_name (8);
|
||||||
$step7 = 1;
|
$host = 'localhost';
|
||||||
fclose ($cfgin);
|
if ($dbhost != 'localhost')
|
||||||
fclose ($cfgout);
|
$host = $_SERVER['SERVER_ADDR'];
|
||||||
chmod ($pandora_config, 0600);
|
$step5 = mysql_query ("GRANT ALL PRIVILEGES ON $dbname.* to pandora@$host
|
||||||
check_generic ($step7, "Created new config file at '".$pandora_config."'");
|
IDENTIFIED BY '".$random_password."'");
|
||||||
}
|
mysql_query ("FLUSH PRIVILEGES");
|
||||||
}
|
check_generic ($step5, "Established privileges for user pandora. A new random password has been generated: <b>$random_password</b><div class='warn'>Please write it down, you will need to setup your Pandora FMS server, editing the </i>/etc/pandora/pandora_server.conf</i> file</div>");
|
||||||
if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) {
|
|
||||||
$everything_ok = 1;
|
$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'; //TODO set other types
|
||||||
|
$config_new = '<?php
|
||||||
|
// Begin of automatic config file
|
||||||
|
$config["dbtype"] = "' . $dbtype . '"; //DB type (mysql, postgres)
|
||||||
|
$config["dbname"]="'.$dbname.'"; // MySQL DataBase name
|
||||||
|
$config["dbuser"]="pandora"; // DB User
|
||||||
|
$config["dbpass"]="'.$random_password.'"; // DB Password
|
||||||
|
$config["dbhost"]="'.$dbhost.'"; // DB Host
|
||||||
|
$config["homedir"]="'.$path.'"; // Config homedir
|
||||||
|
$config["homeurl"]="'.$url.'"; // Base URL
|
||||||
|
// End of automatic config file
|
||||||
|
?>';
|
||||||
|
$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) {
|
||||||
|
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("pandoradb.postgreSQL.sql");
|
||||||
|
check_generic ($step3, "Creating schema");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
echo "</table></div>";
|
echo "</table></div>";
|
||||||
|
|
||||||
print_logo_status (4,5);
|
print_logo_status(4,5);
|
||||||
|
|
||||||
echo "<div id='install_img'>";
|
echo "<div id='install_img'>";
|
||||||
if ($everything_ok == 1) {
|
if ($everything_ok == 1) {
|
||||||
@ -533,11 +645,19 @@ function install_step4() {
|
|||||||
All database schemes created in this step have been dropped. </p>
|
All database schemes created in this step have been dropped. </p>
|
||||||
</div>";
|
</div>";
|
||||||
|
|
||||||
if (mysql_error() != "")
|
switch ($engine) {
|
||||||
echo "<div class='warn'> <b>ERROR:</b> ". mysql_error().".</div>";
|
case 'mysql':
|
||||||
|
if (mysql_error() != "") {
|
||||||
if ($step1 == 1)
|
echo "<div class='warn'> <b>ERROR:</b> ". mysql_error().".</div>";
|
||||||
mysql_query ("DROP DATABASE $dbname");
|
}
|
||||||
|
|
||||||
|
if ($step1 == 1) {
|
||||||
|
mysql_query ("DROP DATABASE $dbname");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'pgsql':
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
echo "
|
echo "
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user