Spam Karma 2, Dreamhost and cURL

This blog is protected by the most excellent Spam Karma plugin and is hosted on the most excellent host, Dreamhost.

There’s one small problem with this set-up, though. Spam Karma uses the allow_url_fopen() functionality of PHP, which Dreamhost has disabled for security reasons.

What follows is a replacement function that rewrites one function using cURL to achieve the same goals, thus allowing full SK2 functionality on Dreamhost.

In the file sk2_functions.php, replace function sk2_get_url_content with this:

function sk2_get_url_content($url, $level = 0, $convert_case = false)
{
	if ($level > 8)
		return "";

	$buffer = "";

	$curl_handle=curl_init();
	curl_setopt($curl_handle,CURLOPT_URL, $url);
	curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
	curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
	$buffer = curl_exec($curl_handle);
	curl_close($curl_handle);

	if ($level >= 0)
		if (preg_match_all("/< (script|iframe) [^>]*src=”([^”]*)”[^>]*>/”, $buffer, $matches))
		{
			foreach ($matches[2] as $match)
			{
				$buffer .= “**embedded:$match**”;
				$new_url = $match;
				if (! strncmp($new_url, “http”, 7))
					$new_url = $url . “/” . $new_url;

				$buffer .= “***\n” . sk2_get_url_content($new_url, $level+1);
			}
		}

	return $buffer;
}

Note that the timeout is pretty tight, I don’t like waiting. So, if you have a slower connection (or more patience) you might want to increase the value of CURLOPT_CONNECTTIMEOUT.

Also, in the file sk2_referrer_check_plugin.php there are checks for allow_url_fopen(), which we can now safely comment out:

function filter_this(&$cmt_object)
	{
		if (! $cmt_object->is_trackback())
			return;

		/*
		jason [at] ushmitsudoki [dot] com - 20050427
		won't be needing to check this anymore

		if( ! ini_get('allow_url_fopen'))
		{
			$this->log_msg("allow_url_fopen is disabled on this PHP install: sk2_referrer_check_plugin cannot run.” , 5);
			return;
		}
		*/

and one more edit in the same file:

function output_plugin_UI()
	{
		echo "
“; parent::output_plugin_UI(false); // call default constructor /* jason [at] ushmitsudoki [dot] com - 20050427 won’t be needing to check this anymore if(! ini_get(’allow_url_fopen’)) echo “

allow_url_fopen is disabled on this PHP install: TB Referrer Check plugin cannot run. You should disable it.

“; */ echo “
“; }

Finally, I’m not a WordPress, PHP, or SpamKarma developer, so use this at your own peril. Corrections and comments welcome.

5 Responses to Spam Karma 2, Dreamhost and cURL »»


Comments

  1. Comment by dr Dave | 2005/05/10 at 16:53:01

    Hey Jason!

    Thanks a lot for the awesome work…

    I finally got around to integrate your code and tighten the few remaining loose ends into the new release of SK2 (was mostly waiting for 1.5.1 to be around).
    It’s now all there for download, along with a shiny new Wiki documentation: http://unknowngenius.com/blog/wordpress/spam-karma

  2. Comment by Jason | 2005/05/10 at 21:50:12

    dr Dave,

    Not at all! Glad to add my very minor contribution!

  3. Comment by Jason | 2005/05/10 at 22:02:14

    Also, you should remove the check in sk2_referrer_check_plugin.php. If the cURL changes are implemented, there’s no need for that check any longer.

  4. Comment by dr Dave | 2005/05/12 at 18:22:34

    Hi,

    I think that’s been done (I just checked the source and the check appears to be commented)… Make sure you got the last ‘beta 1′ release… if I missed it, definitely let me know…

    Cheers,

  5. Comment by Jason | 2005/05/12 at 23:56:35

    You got the first one, but check out line 67 in the same plugin.

    Although it appears to only be a comment to the user, and doesn’t affect the workings, I’d still comment it out.


Leave a Reply »»