<?php
/* daCode http://www.dacode.org/
 * src/phplib/nospider.php3
 * $Id: nospider.php3,v 1.19 2001/07/12 09:48:15 penso Exp $
 */

Class nospider {
	var $REMOTE_ADDR,$db;

	Function Nospider() {
		global $REMOTE_ADDR,$HTTP_X_FORWARDED_FOR;
//echo '<br>Nospider';
		$this->REMOTE_ADDR=$HTTP_X_FORWARDED_FOR?
				$HTTP_X_FORWARDED_FOR:$REMOTE_ADDR;

		$this->db = LoadClass('Db');
	}

	/* Check how many hits a remote address has made.*/
	Function check() {
		global $config;

		$date = $this->getdate();

		$sqlc_q = "SELECT count(host) FROM ".$config->tables['nospider'].
			" WHERE timestamp > ".(addslashes($date) - 60)." AND host='".addslashes($this->REMOTE_ADDR)."'";
		$ret = $this->db->query($sqlc_q);
		if (!$ret) {
			echo lecho("SQL Failed: ").$this->db->error();
			return -1;
		}
		$row = $this->db->fetch_array();

		if ($row[0] > $config->numberofhits) {
			echo lecho("you bad boy...")."\n";
			exit;
		} else {
			$sqlc_q = "INSERT INTO ".$config->tables['nospider'].
				" (host) VALUES ('".addslashes($this->REMOTE_ADDR)."')";
			$ret = $this->db->query($sqlc_q);
			if (!$ret) {
				echo lecho("SQL Failed: ").$this->db->error();
				return -1;
			}
		}
	}

	/* Return the actual date in timestamp(14) format */
	Function getdate() {
		$date = getdate();
		$yea = $date['year'];
		$mon = $date['mon'];
		if ($mon < 10) $mon = "0$mon";
		$mday = $date['mday'];
		if ($mday < 10) $mday = "0$mday";
		$hrs = $date['hours'];
		if ($hrs < 10)
			$hrs = "0$hrs";
		$min = $date['minutes'];
		if ($min < 10) $min = "0$min";
		$sec = $date['secondes'];
		if ($seconds < 10) $sec = "0$sec";

		return "$yea$mon$mday$hrs$min$sec";
	}

}

?>
