View | Details | Raw Unified | Return to bug 233773 | Differences between
and this patch

Collapse All | Expand All

(-)pandorafms_console/Makefile (-4 / +2 lines)
Lines 10-17 Link Here
10
LICENSE=	${PANDORA_LICENSE}
10
LICENSE=	${PANDORA_LICENSE}
11
LICENSE_FILE=	${PANDORA_LICENSE_FILE}
11
LICENSE_FILE=	${PANDORA_LICENSE_FILE}
12
12
13
IGNORE_WITH_PHP=	70 71 72 73
14
15
RUN_DEPENDS=	${LOCALBASE}/bin/twopi:graphics/graphviz
13
RUN_DEPENDS=	${LOCALBASE}/bin/twopi:graphics/graphviz
16
14
17
USES=		apache:run,2.2+ php:web shebangfix
15
USES=		apache:run,2.2+ php:web shebangfix
Lines 29-35 Link Here
29
DOCS_DESC=	Install AUTHORS and ChangeLog
27
DOCS_DESC=	Install AUTHORS and ChangeLog
30
PGSQL_DESC=	Use PostgreSQL backend (experimental)
28
PGSQL_DESC=	Use PostgreSQL backend (experimental)
31
29
32
USE_PHP=	curl filter gd gettext hash json ldap mbstring mysql \
30
USE_PHP=	curl filter gd gettext hash json ldap mbstring mysqli \
33
		snmp session xml zip zlib
31
		snmp session xml zip zlib
34
32
35
SUB_FILES+=	pandora_console.conf pkg-message newsyslog.conf
33
SUB_FILES+=	pandora_console.conf pkg-message newsyslog.conf
Lines 39-45 Link Here
39
37
40
.include "${.CURDIR}/../pandorafms_server/bsd.pandora.mk"
38
.include "${.CURDIR}/../pandorafms_server/bsd.pandora.mk"
41
39
42
PORTREVISION=	2
40
PORTREVISION=	3
43
41
44
PANDORA_INSTALLER_ARGS+=	--destdir ${STAGEDIR}
42
PANDORA_INSTALLER_ARGS+=	--destdir ${STAGEDIR}
45
43
(-)pandorafms_console/files/patch-include_db_mysql.php (+192 lines)
Line 0 Link Here
1
--- include/db/mysql.php.orig	2016-04-08 09:50:59 UTC
2
+++ include/db/mysql.php
3
@@ -29,13 +29,13 @@ function mysql_connect_db($host = null, 
4
 		$port = $config["dbport"];
5
 	
6
 	// Non-persistent connection: This will help to avoid mysql errors like "has gone away" or locking problems
7
-	// If you want persistent connections change it to mysql_pconnect(). 
8
-	$connect_id = @mysql_connect($host . ":" . $port, $user, $pass, true);
9
+	// If you want persistent connections change it to mysqli_pconnect(). 
10
+	$connect_id = @mysqli_connect($host . ":" . $port,  $user,  $pass);
11
 	if (! $connect_id) {
12
 		return false;
13
 	}
14
 	
15
-	mysql_select_db($db, $connect_id);
16
+	mysqli_select_db($connect_id, $db);
17
 	return $connect_id;
18
 }
19
 
20
@@ -299,14 +299,14 @@ function mysql_db_process_sql($sql, $ret
21
 			$dbconnection = $config['dbconnection'];
22
 		}
23
 		
24
-		$result = mysql_query ($sql, $dbconnection);
25
+		$result = mysqli_query($dbconnection, $sql);
26
 		
27
 		$time = microtime (true) - $start;
28
 		if ($result === false) {
29
 			$backtrace = debug_backtrace ();
30
 			$error = sprintf ('%s (\'%s\') in <strong>%s</strong> on line %d',
31
-				mysql_error (), $sql, $backtrace[0]['file'], $backtrace[0]['line']);
32
-			db_add_database_debug_trace ($sql, mysql_error ($dbconnection));
33
+				mysqli_error($dbconnection), $sql, $backtrace[0]['file'], $backtrace[0]['line']);
34
+			db_add_database_debug_trace ($sql, mysqli_error($dbconnection));
35
 			set_error_handler ('db_sql_error_handler');
36
 			trigger_error ($error);
37
 			restore_error_handler ();
38
@@ -314,29 +314,29 @@ function mysql_db_process_sql($sql, $ret
39
 		}
40
 		elseif ($result === true) {
41
 			if ($rettype == "insert_id") {
42
-				$result = mysql_insert_id ($dbconnection);
43
+				$result = ((is_null($___mysqli_res = mysqli_insert_id($dbconnection))) ? false : $___mysqli_res);
44
 			}
45
 			elseif ($rettype == "info") {
46
-				$result = mysql_info ($dbconnection);
47
+				$result = mysqli_info($dbconnection);
48
 			}
49
 			else {
50
-				$result = mysql_affected_rows ($dbconnection);
51
+				$result = mysqli_affected_rows($dbconnection);
52
 			}
53
 			
54
-			db_add_database_debug_trace ($sql, $result, mysql_affected_rows ($dbconnection),
55
+			db_add_database_debug_trace ($sql, $result, mysqli_affected_rows($dbconnection),
56
 				array ('time' => $time));
57
 			return $result;
58
 		}
59
 		else {
60
-			db_add_database_debug_trace ($sql, 0, mysql_affected_rows ($dbconnection), 
61
+			db_add_database_debug_trace ($sql, 0, mysqli_affected_rows($dbconnection), 
62
 				array ('time' => $time));
63
-			while ($row = mysql_fetch_assoc ($result)) {
64
+			while ($row = mysqli_fetch_assoc($result)) {
65
 				array_push ($retval, $row);
66
 			}
67
 			
68
 			if ($cache === true)
69
 				$sql_cache[$sql] = $retval;
70
-			mysql_free_result ($result);
71
+			((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
72
 		}
73
 	}
74
 	
75
@@ -355,7 +355,8 @@ function mysql_db_process_sql($sql, $ret
76
  * @return string String cleaned.
77
  */
78
 function mysql_escape_string_sql($string) {
79
-	$str = mysql_real_escape_string($string);
80
+	global $config;
81
+	$str = mysqli_real_escape_string($config['dbconnection'], $string);
82
 	
83
 	return $str;
84
 }
85
@@ -754,10 +755,10 @@ function mysql_db_get_all_rows_filter ($
86
 function mysql_db_get_num_rows ($sql) {
87
 	global $config;
88
 	
89
-	$result = mysql_query($sql, $config['dbconnection']);
90
+	$result = mysqli_query($config['dbconnection'], $sql);
91
 	
92
 	if ($result) {
93
-		return mysql_num_rows($result);
94
+		return mysqli_num_rows($result);
95
 	}
96
 	else { 
97
 		return 0;
98
@@ -972,11 +973,12 @@ function mysql_db_process_sql_delete($ta
99
  * @return mixed The row or false in error.
100
  */
101
 function mysql_db_get_all_row_by_steps_sql($new = true, &$result, $sql = null) {
102
+	global $config;
103
 	if ($new == true)
104
-		$result = mysql_query($sql);
105
+		$result = mysqli_query($config['dbconnection'], $sql);
106
 	
107
 	if ($result) {
108
-		return mysql_fetch_assoc($result);
109
+		return mysqli_fetch_assoc($result);
110
 	}
111
 	else {
112
 		return array();
113
@@ -987,24 +989,27 @@ function mysql_db_get_all_row_by_steps_s
114
  * Starts a database transaction.
115
  */
116
 function mysql_db_process_sql_begin() {
117
-	mysql_query ('SET AUTOCOMMIT = 0');
118
-	mysql_query ('START TRANSACTION');
119
+	global $config;
120
+	mysqli_query($config['dbconnection'], 'SET AUTOCOMMIT = 0');
121
+	mysqli_query($config['dbconnection'], 'START TRANSACTION');
122
 }
123
 
124
 /**
125
  * Commits a database transaction.
126
  */
127
 function mysql_db_process_sql_commit() {
128
-	mysql_query ('COMMIT');
129
-	mysql_query ('SET AUTOCOMMIT = 1');
130
+	global $config;
131
+	mysqli_query($config['dbconnection'], 'COMMIT');
132
+	mysqli_query($config['dbconnection'], 'SET AUTOCOMMIT = 1');
133
 }
134
 
135
 /**
136
  * Rollbacks a database transaction.
137
  */
138
 function mysql_db_process_sql_rollback() {
139
-	mysql_query ('ROLLBACK ');
140
-	mysql_query ('SET AUTOCOMMIT = 1');
141
+	global $config;
142
+	mysqli_query($config['dbconnection'], 'ROLLBACK ');
143
+	mysqli_query($config['dbconnection'], 'SET AUTOCOMMIT = 1');
144
 }
145
 
146
 /**
147
@@ -1018,7 +1023,7 @@ function mysql_safe_sql_string($string) 
148
 	
149
 	global $config;
150
 	
151
-	return mysql_real_escape_string($string, $config['dbconnection']);
152
+	return mysqli_real_escape_string($config['dbconnection'], $string);
153
 }
154
 
155
 /**
156
@@ -1027,7 +1032,8 @@ function mysql_safe_sql_string($string) 
157
  * @return string Return the string error.
158
  */
159
 function mysql_db_get_last_error() {
160
-	return mysql_error();
161
+	global $config;
162
+	return mysqli_error($config['dbconnection']);
163
 }
164
 
165
 /**
166
@@ -1064,9 +1070,10 @@ function mysql_get_system_time() {
167
  * @return mixed Return the type name or False in error case.
168
  */
169
 function mysql_db_get_type_field_table($table, $field) {
170
-	$result = mysql_query('SELECT parameters FROM ' . $table);
171
+	global $config;
172
+	$result = mysqli_query($config['dbconnection'], 'SELECT parameters FROM ' . $table);
173
 	
174
-	return mysql_field_type($result, $field); 
175
+	return ((is_object($___mysqli_tmp = mysqli_fetch_field_direct($result, 0)) && !is_null($___mysqli_tmp = $___mysqli_tmp->type)) ? ((($___mysqli_tmp = (string)(substr(( (($___mysqli_tmp == MYSQLI_TYPE_STRING) || ($___mysqli_tmp == MYSQLI_TYPE_VAR_STRING) ) ? "string " : "" ) . ( (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24))) ? "int " : "" ) . ( (in_array($___mysqli_tmp, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, ((defined("MYSQLI_TYPE_NEWDECIMAL")) ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)))) ? "real " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_TIMESTAMP) ? "timestamp " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_YEAR) ? "year " : "" ) . ( (($___mysqli_tmp == MYSQLI_TYPE_DATE) || ($___mysqli_tmp == MYSQLI_TYPE_NEWDATE) ) ? "date " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_TIME) ? "time " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_SET) ? "set " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_ENUM) ? "enum " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_GEOMETRY) ? "geometry " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_DATETIME) ? "datetime " : "" ) . ( (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB))) ? "blob " : "" ) . ( ($___mysqli_tmp == MYSQLI_TYPE_NULL) ? "null " : "" ), 0, -1))) == "") ? "unknown" : $___mysqli_tmp) : false); 
176
 }
177
 
178
 /**
179
@@ -1136,11 +1143,11 @@ function mysql_db_process_file ($path, $
180
 				$query .= $sql_line;
181
 				
182
 				if (preg_match("/;[\040]*\$/", $sql_line)) {
183
-					if (!$result = mysql_query($query)) {
184
+					if (!$result = mysqli_query($config['dbconnection'], $query)) {
185
 						// Error. Rollback the transaction
186
 						mysql_db_process_sql_rollback();
187
 						
188
-						$error_message = mysql_error();
189
+						$error_message = mysqli_error($config['dbconnection']);
190
 						
191
 						// Handle the error
192
 						if ($handle_error) {
(-)pandorafms_console/files/patch-include_functions.php (+11 lines)
Line 0 Link Here
1
--- include/functions.php.orig	2016-04-08 09:50:59 UTC
2
+++ include/functions.php
3
@@ -2322,7 +2322,7 @@ function clear_pandora_error_for_header(
4
 	global $config;
5
 	
6
 	$config["alert_cnt"] = 0;
7
-	$_SESSION["alert_msg"] = "";
8
+	$_SESSION["alert_msg"] = array();
9
 }
10
 
11
 function set_pandora_error_for_header($message, $title = null) {
(-)pandorafms_console/files/patch-install.php (+121 lines)
Line 0 Link Here
1
--- install.php.orig	2016-04-08 09:51:58 UTC
2
+++ install.php
3
@@ -212,8 +212,8 @@ function parse_mysql_dump($url) {
4
 			if (trim($sql_line) != "" && strpos($sql_line, "--") === false) {
5
 				$query .= $sql_line;
6
 				if(preg_match("/;[\040]*\$/", $sql_line)) {
7
-					if (!$result = mysql_query($query)) {
8
-						echo mysql_error(); //Uncomment for debug
9
+					if (!$result = mysqli_query($GLOBALS["___mysqli_ston"], $query)) {
10
+						echo mysqli_error($GLOBALS["___mysqli_ston"]); //Uncomment for debug
11
 						echo "<i><br>$query<br></i>";
12
 						return 0;
13
 					}
14
@@ -426,7 +426,7 @@ function adjust_paths_for_freebsd($engin
15
 	for ($i = 0; $i < count ($adjust_sql); $i++) {
16
 		switch ($engine) {
17
 			case 'mysql':
18
-				$result = mysql_query($adjust_sql[$i]);
19
+				$result = mysqli_query($GLOBALS["___mysqli_ston"], $adjust_sql[$i]);
20
 				break;
21
 			case 'oracle':
22
 				//Delete the last semicolon from current query
23
@@ -575,7 +575,8 @@ function install_step2() {
24
 				font-size: 8.5pt;margin-top: 2px; font-weight: bolder;'>DB Engines</span>";
25
 			echo "</td><td>";
26
 			echo "</td></tr>";
27
-			check_extension("mysql", "PHP MySQL extension");
28
+			check_extension("mysql", "PHP mysql extension (deprecated)");
29
+			check_extension("mysqli", "PHP mysql extension");
30
 			check_extension("pgsql", "PHP PostgreSQL extension");
31
 			check_extension("oci8", "PHP Oracle extension");
32
 			echo "</table>";
33
@@ -617,8 +618,8 @@ function install_step2() {
34
 
35
 function install_step3() {
36
 	$options = '';
37
-	if (extension_loaded("mysql")) {
38
-		$options .= "<option value='mysql'>MySQL</option>";
39
+	if (extension_loaded("mysql") || extension_loaded("mysqli")) {
40
+		$options .= "<option value='mysql'>mysql</option>";
41
 	}
42
 	if (extension_loaded("pgsql")) {
43
 		$options .= "<option value='pgsql'>PostgreSQL</option>";
44
@@ -811,7 +812,7 @@ function install_step4() {
45
 			<table width='100%'>";
46
 			switch ($engine) {
47
 				case 'mysql':
48
-					if (! mysql_connect ($dbhost, $dbuser, $dbpassword)) {
49
+					if (! ($GLOBALS["___mysqli_ston"] = mysqli_connect($dbhost,  $dbuser,  $dbpassword))) {
50
 						check_generic ( 0, "Connection with Database");
51
 					}
52
 					else {
53
@@ -819,19 +820,19 @@ function install_step4() {
54
 						
55
 						// Drop database if needed and don't want to install over an existing DB
56
 						if ($dbdrop == 1) {
57
-							mysql_query ("DROP DATABASE IF EXISTS `$dbname`");
58
+							mysqli_query($GLOBALS["___mysqli_ston"], "DROP DATABASE IF EXISTS `$dbname`");
59
 						}
60
 						
61
 						// Create schema
62
 						if ($dbaction == 'db_new' || $dbdrop == 1) {
63
-							$step1 = mysql_query ("CREATE DATABASE `$dbname`");
64
+							$step1 = mysqli_query($GLOBALS["___mysqli_ston"], "CREATE DATABASE `$dbname`");
65
 							check_generic ($step1, "Creating database '$dbname'");
66
 						}
67
 						else {
68
 							$step1 = 1;
69
 						}
70
 						if ($step1 == 1) {
71
-							$step2 = mysql_select_db($dbname);
72
+							$step2 = mysqli_select_db($GLOBALS["___mysqli_ston"], $dbname);
73
 							check_generic ($step2, "Opening database '$dbname'");
74
 							
75
 							$step3 = parse_mysql_dump("pandoradb.sql");
76
@@ -848,9 +849,9 @@ function install_step4() {
77
 							$host = 'localhost';
78
 							if ($dbhost != 'localhost')
79
 								$host = $dbgrant;
80
-							$step5 = mysql_query ("GRANT ALL PRIVILEGES ON `$dbname`.* to pandora@$host 
81
+							$step5 = mysqli_query($GLOBALS["___mysqli_ston"], "GRANT ALL PRIVILEGES ON `$dbname`.* to pandora@$host 
82
 								IDENTIFIED BY '".$random_password."'");
83
-							mysql_query ("FLUSH PRIVILEGES");
84
+							mysqli_query($GLOBALS["___mysqli_ston"], "FLUSH PRIVILEGES");
85
 							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>");
86
 							
87
 							$step6 = is_writable("include");
88
@@ -863,7 +864,7 @@ function install_step4() {
89
 							$config_new = '<?php
90
 							// Begin of automatic config file
91
 							$config["dbtype"] = "' . $dbtype . '"; //DB type (mysql, postgresql...in future others)
92
-							$config["dbname"]="'.$dbname.'";			// MySQL DataBase name
93
+							$config["dbname"]="'.$dbname.'";			// mysql DataBase name
94
 							$config["dbuser"]="pandora";			// DB User
95
 							$config["dbpass"]="'.$random_password.'";	// DB Password
96
 							$config["dbhost"]="'.$dbhost.'";			// DB Host
97
@@ -1145,7 +1146,7 @@ function install_step4() {
98
 							$config_new = '<?php
99
 							// Begin of automatic config file
100
 							$config["dbtype"] = "' . $dbtype . '"; //DB type (mysql, postgresql...in future others)
101
-							$config["dbname"]="'.$dbname.'";			// MySQL DataBase name
102
+							$config["dbname"]="'.$dbname.'";			// mysql DataBase name
103
 							$config["dbuser"]="pandora";			// DB User
104
 							$config["dbpass"]="'.$random_password.'";	// DB Password
105
 							$config["dbhost"]="'.$dbhost.'";			// DB Host
106
@@ -1208,12 +1209,12 @@ function install_step4() {
107
 				
108
 				switch ($engine) {
109
 					case 'mysql':
110
-						if (mysql_error() != "") {
111
-							echo "<div class='err'> <b>ERROR:</b> ". mysql_error().".</div>";
112
+						if (mysqli_error($GLOBALS["___mysqli_ston"]) != "") {
113
+							echo "<div class='err'> <b>ERROR:</b> ". mysqli_error($GLOBALS["___mysqli_ston"]).".</div>";
114
 						}
115
 						
116
 						if ($step1 == 1) {
117
-							mysql_query ("DROP DATABASE $dbname");
118
+							mysqli_query($GLOBALS["___mysqli_ston"], "DROP DATABASE $dbname");
119
 						}
120
 						break;
121
 					case 'pgsql':

Return to bug 233773