<?xml version="1.0" encoding="ISO-8859-1"?>

<product productid="_inferno_csrf_autoprotect" active="1">
	<title>Inferno CSRF Auto Protection</title>
	<description>Automatically applies CSRF Protection to all custom modifications</description>
	<version>1.0.0</version>
	<url>http://infernotechnologies.net</url>
	<versioncheckurl />
	<dependencies>
	</dependencies>
	<codes>
	</codes>
	<templates>
	</templates>
	<plugins>
		<plugin active="1" executionorder="5">
			<title><![CDATA[[I.CSRF] Include Security Token]]></title>
			<hookname>global_complete</hookname>
			<phpcode><![CDATA[preg_match_all("#<form(.*?)>(.*?)</form>#is", $output, $_icsrf_forms);
$_icsrf_fixed = 0;
$_icsrf_norm = 0;

if (is_array($_icsrf_forms[0]))
{
	$_icsrf_form_security_token = '<input type="hidden" value="' . $vbulletin->userinfo['securitytoken'] . '" name="securitytoken" />';
	foreach ($_icsrf_forms[0] as $_icsrf_key => $_icsrf_form_html)
	{
		if (
			preg_match("#method=('|\")?post('|\")?#i", $_icsrf_form_html)
			&&
			!preg_match("#name=('|\")?securitytoken('|\")?#i", $_icsrf_form_html)
		)
		{
			$_icsrf_new_form_html = str_replace('</form>', $_icsrf_form_security_token . '</form>', $_icsrf_form_html);
			$_icsrf_fixed++;

			$output = str_replace($_icsrf_form_html, $_icsrf_new_form_html, $output);
		}
		else
		{
			$_icsrf_norm++;
		}
	}

	if ($vbulletin->debug)
	{
		$newdebughtml = str_replace(
			"<div style=\"margin-bottom:6px\"><strong>Template Usage:</strong></div>",
			trim("
				<div style=\"margin-bottom:6px\"><strong>Inferno CSRF Auto Protection:</strong></div>
				<ul style=\"list-style:none; margin:0px; padding:0px\">
					<li class=\"smallfont\"><span style=\"float: right;\" class=\"shade\">($_icsrf_norm)</span> CSRF Protected Forms</li>
					<li class=\"smallfont\"><span style=\"float: right;\" class=\"shade\">(<strong>$_icsrf_fixed</strong>)</span> CSRF Auto Protected Forms</li>
				</ul>
				<hr style=\"margin:10px 0px 10px 0px\" />
				<div style=\"margin-bottom:6px\"><strong>Template Usage:</strong></div>
			"),
			$debughtml
		);

		$output = str_replace($debughtml, $newdebughtml, $output);
	}
}

unset($_icsrf_forms, $_icsrf_form_html, $_icsrf_new_form_html, $_icsrf_form_security_token, $_icsrf_key, $newdebughtml);]]></phpcode>
		</plugin>
		<plugin active="1" executionorder="5">
			<title><![CDATA[[I.CSRF] Set CSRF Flag]]></title>
			<hookname>init_startup</hookname>
			<phpcode><![CDATA[$_icsrf_exclude = array();
// Add exempt scripts below
// Eg: $_icsrf_exclude[] = 'SCRIPT_NAME';

if (!DEFINED('CSRF_PROTECTION') && !in_array(THIS_SCRIPT, $_icsrf_exclude))
{
	define('CSRF_PROTECTION', true);
}

unset($_icsrf_exclude);]]></phpcode>
		</plugin>
	</plugins>
	<phrases>
	</phrases>
	<options>
	</options>
	<helptopics>
	</helptopics>
	<cronentries>
	</cronentries>
	<faqentries>
	</faqentries>
</product>
