Multiplay Labs

tech hits and tips from Multiplay

Archive for the ‘ultrastats’ tag

ultrastats mysql database port fix

without comments

Just been playing more with ultrastats and went to set it up on our test db which runs on a none standard port. After fighting with it for 1/2 an hour it telling me access denied I looked at to code to find the nice port option it asks you for in the installer was totally and utterly ignored 🙁

Here’s the patch

--- ./install.php.orig	Tue Feb 24 21:19:24 2009
+++ ./install.php	Tue Feb 24 21:21:38 2009
@@ -240,5 +240,5 @@
 
 	// Now Check database connect
-	$link_id = mysql_connect( $_SESSION['DB_HOST'], $_SESSION['DB_USER'], $_SESSION['DB_PASS']);
+	$link_id = mysql_connect( "{$_SESSION['DB_HOST']}:{$_SESSION['DB_PORT']}", $_SESSION['DB_USER'], $_SESSION['DB_PASS']);
 	if (!$link_id) 
 		RevertOneStep( $content['INSTALL_STEP']-1, GetAndReplaceLangStr( $content['LN_INSTALL_ERRORCONNECTFAILED'], $_SESSION['DB_HOST']) . "<br>" . DB_ReturnSimpleErrorMsg() );
--- ./include/functions_db.php.orig	Tue Feb 24 21:24:00 2009
+++ ./include/functions_db.php	Tue Feb 24 21:24:48 2009
@@ -43,5 +43,5 @@
 
 	//TODO: Check variables first
-	$link_id = @mysql_connect($CFG['DBServer'],$CFG['User'],$CFG['Pass']);
+	$link_id = @mysql_connect("{$CFG['DBServer']}:{$CFG['Port']}",$CFG['User'],$CFG['Pass']);
 	if (!$link_id) 
 		DB_PrintError("Link-ID == false, connect to ".$CFG['DBServer']." failed", true);

Written by Dilbert

February 24th, 2009 at 10:41 pm

Posted in Hackery,MySQL

Tagged with , , ,

ultrastats usernames with @ in them fix

without comments

The standard setup for ultrastats uses url parsing to create the DB entries for the monitored servers. This is far from optimum and when the username contains an ‘@’ falls down completely with their current code.

The fix for this is the following patch:

--- include/functions_common.php.orig	2009-02-23 17:33:29.000000000 +0000
+++ include/functions_common.php	2009-02-23 18:13:34.000000000 +0000
@@ -1135,10 +1135,9 @@
 	$ftpvalues['ftpfilename'] = "";
 
-	if ( strpos($ftpUrl, "@") !== false )
-	{	//Username and maybe password is given
-		$tmparray = explode("@", $ftpUrl);
-
+	$at_pos = strrpos( $ftpUrl, '@' );
+	if ( $at_pos !== false )
+	{	// Username and maybe password is given
 		// Set Username 
-		$ftpvalues['username'] = substr( $tmparray[0], 6 );
+		$ftpvalues['username'] = substr( $ftpUrl, 6, $at_pos - 6 );
 
 		// Check if Password is given
@@ -1149,13 +1148,16 @@
 			$ftpvalues['password'] = $tmparray2[1];
 		}
+		$server = substr( $ftpUrl, $at_pos + 1 );
 
 		// Get FTP Servername
-		$ftpvalues['ftpserver'] = substr( $tmparray[1], 0,  strpos($tmparray[1], "/") );
+		$first_slash = strpos( $server, '/' );
+		$last_slash = strrpos( $server, '/' );
+		$ftpvalues['ftpserver'] = substr( $server, 0,  $first_slash );
 
 		// Get FTP Path
-		$ftpvalues['ftppath'] = substr( $tmparray[1], strpos($tmparray[1], "/"), strrpos($tmparray[1], "/")-strpos($tmparray[1], "/")+1 );
+		$ftpvalues['ftppath'] = substr( $server, $first_slash, $last_slash - $first_slash + 1 );
 
 		// Get the Logfilename
-		$ftpvalues['ftpfilename'] = substr( $tmparray[1], strrpos($tmparray[1], "/")+1 );
+		$ftpvalues['ftpfilename'] = substr( $server, $last_slash + 1 );
 	}
 	else

Written by Dilbert

February 23rd, 2009 at 6:26 pm

Posted in Hackery

Tagged with , ,