Pastoid

Habari http:Bl Plugin

The page you are looking at now is at this URL: http://pastoid.com/ami

This paste was last updated on February 5, 2009 at 11:39 pm.

httpbl.plugin.phpraw

<?php
 
class httpblPlugin extends Plugin
{
	/**
	 * function info
	 * Returns information about this plugin
	 * @return array Plugin info array
	 **/
	function info()
	{
		return array (
			'name' => 'http:Bl',
			'url' => 'http://habariproject.org/',
			'author' => 'Owen Winkler',
			'authorurl' => 'http://asymptomatic.net/',
			'version' => '1.0',
			'description' => 'Uses the http:Bl to prevent spam',
			'license' => 'Apache License 2.0',
		);
	}
 
	function get_status($op = null)
	{
		if(Options::get('httpbl__apikey') == '') {
			$status = array('ok'=>127,'age'=>0,'threat'=>0,'type'=>-1);
		}
		elseif(isset($_SESSION['httpbl_status'])) {
			$status = $_SESSION['httpbl_status'];
		}
		else {
			$request = Options::get('httpbl__apikey') . '.' . implode('.', array_reverse(explode(".", $_SERVER["REMOTE_ADDR"]))) . '.dnsbl.httpbl.org';
			$response = explode('.', gethostbyname($request));
 
			if(reset($response) == '127') {
				$result = array_combine(array('ok', 'age', 'threat', 'type'), $response);
				$status = $result;
			}
			else {
				$status = array('ok'=>127,'age'=>0,'threat'=>0,'type'=>-1);
			}
		}
		if(!isset($status['valid'])) {
			if($status['type'] != -1) {
				$age_th = intval(Options::get('httpbl__age_th'));
				$threat_th = intval(Options::get('httpbl__threat_th'));
				$types = array_sum(Options::get('httpbl__types'));
 
				$valid = true;
				if($status['threat'] >= $threat_th) {
					$valid = false;
				}
 
				if($status['age'] >= $age_th ) {
					$valid = true;
				}
 
				if(intval($status['type']) && $types == 0) {
					$valid = true;
				}
 
				$status['valid'] = $valid;
			}
			else {
				$status['valid'] = true;
			}
			$_SESSION['httpbl_status'] = $status;
		}
 
 
		if(isset($op)) {
			return $status[$op];
		}
		else {
			return $status;
		}
	}
 
	function action_init()
	{
		// Should check against criteria to see if this post submission should be denied
		if($_SERVER['REQUEST_METHOD'] != 'GET' && !$this->get_status('valid')) {
			$caught = Options::get('httpbl__caught');
			Options::set('httpbl__caught', intval($caught) + 1);
			header('HTTP/1.1 403 Forbidden');
			die();
		}
	}
 
	function filter_dashboard_status($statuses)
	{
		if(Options::get('httpbl__apikey') == '') {
			$statuses['http:Bl'] = '<a href="http://www.projecthoneypot.org/httpbl_configure.php">Needs API Key</a>';
		}
		else {
			$statuses[_t('http:Bl rejected')] = _t('%d spammers', array(intval(Options::get('httpbl__caught'))));
		}
		return $statuses;
	}
 
	public function configure()
	{
		$form = new FormUI('httpbl');
 
		$form->append( 'text', 'apikey', 'httpbl__apikey', _t( 'API Key' ) );
 
		$form->append( 'static', 'threatths', _t('Visitors with a threat level higher than this are determined to be spammers:'));
		$form->append( 'text', 'threatth', 'httpbl__threat_th', _t( 'Threat Threshhold' ) );
		$form->threatth->add_validator('validate_range', 0, 255);
 
		$form->append( 'static', 'ageths', _t('Ignore IP records that are older than this number of days:'));
		$form->append( 'text', 'ageth', 'httpbl__age_th', _t( 'Age Threshhold' ) );
		$form->ageth->add_validator('validate_range', 0, 255);
 
		$form->append( 'static', 'typess', _t('Block comments from threats listed as:'));
		$types = $form->append( 'checkboxes', 'httpbl__types', _t('Threat Types'));
		$types->options = array(1=>_t('Suspicious'),2=>_t('Harvester'),4=>_t('Spammer'));
 
		$form->append( 'submit', 'submit', 'Submit' );
 
		return $form;
	}
 
	public function help()
	{
		return <<< END_HELP
<p>This is the help text for the test plugin.</p>
END_HELP;
	}
 
}
?>

Toggle wordwrap

Referring DomainHits
Unknown Referer 127
pastoid.com 19
Is this paste spam?
<Hide