Multiplay Labs

tech hits and tips from Multiplay

Archive for February, 2009

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 , ,

Perl CGI.pm problems with query strings under Apache

without comments

Ever had a problem with query strings causing strange behaviour in apache when using the CGI module?
If you have the patch below might just save you some time and effort hunting down the problem.

--- CGI.pm.orig	Sat Mar  1 16:58:19 2008
+++ CGI.pm	Sat Mar  1 18:39:21 2008
@@ -2779,5 +2779,10 @@
    my $raw_script_name = $ENV{SCRIPT_NAME} || '';
    my $raw_path_info   = $ENV{PATH_INFO}   || '';
-   my $uri             = unescape($self->request_uri) || '';
+   my $uri             = $self->request_uri || '';
+
+   # ensure we dont get any query string as that can include escaped //
+   # e.g. a url parameter, which will break the apache bug fix
+   $uri =~ s/\?(.*)$//; 
+   $uri = unescape($uri);
 
    my $protected    = quotemeta($raw_path_info);

Written by Dilbert

February 21st, 2009 at 11:45 pm

Posted in Code,Hackery,Perl

Tagged with , , ,

Running perl scripts from rc.d under FreeBSD

without comments

If you have even tried to run a perl script under FreeBSD’s startup system rc.d then you’ll have hit upon a little problem where it doesnt correctly recognise the running process on shutdown. There’s a simple fix for this just apply the patch below and you’ll be good to go.

--- /etc/rc.subr.orig	Mon Oct  8 18:31:34 2007
+++ /etc/rc.subr	Mon Oct  8 18:32:31 2007
@@ -271,5 +271,5 @@
 		_fp_args='_argv'
 		_fp_match='case "$_argv" in
-		    ${_interp}|"${_interp} "*|"${_interpbn}: ${_procname}"*)'
+		    ${_interp}|"${_interp} "*|"[${_interpbn}]"|"${_interpbn}: ${_procname}"*)'
 	else					# a normal daemon
 		_procnamebn=${_procname##*/}

Written by Dilbert

February 21st, 2009 at 11:40 pm

Posted in Hackery,Perl

Tagged with , , ,

Halflife patches break query protocol

without comments

Always on of those things you love to get you install an update and it breaks things. Anyway some of the recent updates to valves old none source games updated to use the new a2s query, all good but this implementation doesn’t properly support the handshake in the challenge response. More specifically the server never responds to the request for a challenge.

In order to fix this in qstat I’ve had to make it do a bogus request which makes the server send a challenge and hence allows the handshake to complete correctly.

Anyone who uses qstat should update to the latest version in svn.

Written by Dilbert

February 21st, 2009 at 11:36 pm

Posted in Hackery

Tagged with , , , ,

YUI Treeview editComplete event

without comments

While using YUI‘s excellent little treeview library I needed the ability to hook into the completion of the edit node event. This isnt present in 2.6.0 so came up with this little patch to add it:

Index: docs/yui/treeview/treeview.js
===================================================================
--- docs/yui/treeview/treeview.js	(revision 214)
+++ docs/yui/treeview/treeview.js	(working copy)
@@ -306,6 +306,15 @@
         this.createEvent("enterKeyPressed", this);
 
     /**
+         * Fires when the edit of a node is complete
+         * @event editComplete
+         * @type CustomEvent
+         * @param {YAHOO.widget.Node} node the node that has the focus
+         * @param {Boolean} true if the editor saved, false otherwise
+         */
+        this.createEvent("editComplete", this);
+
+    /**
          * Fires when the label in a TextNode or MenuNode or content in an HTMLNode receives a Click.
 	* The listener may return false to cancel toggling and focusing on the node.
          * @event clickEvent
@@ -3052,9 +3061,11 @@
 		if (save) {
 			ed.node.saveEditorValue(ed);
 		}
+
 		Dom.setStyle(ed.editorPanel,'display','none');
 		ed.active = false;
 		node.focus();
+		this.fireEvent( 'editComplete', node, save );
 	};
 
 	/**

Written by Dilbert

February 21st, 2009 at 11:35 pm

Posted in Hackery

Tagged with , , ,