#!/usr/bin/php
<?php
define
("VERSION""0.2.0.0");
define("REQUIRED_PHP_VERSION""4.3.0");
error_reporting (E_ALL);

  if (
version_compare(phpversion(), REQUIRED_PHP_VERSION)<0) {
    die(
"Error: TightURL ".VERSION." needs PHP >= ".REQUIRED_PHP_VERSION." (you are using ".phpversion().")");
  }

  if (
file_exists("tighturl.tltpattern.inc.php")) include("tighturl.tltpattern.inc.php");
  if (
file_exists("tighturl.urlpattern.inc.php")) include("tighturl.urlpattern.inc.php");
#  (include("tighturl.lib.inc.php")) or die("Error: cannot load tighturl.lib.inc.php");
  
(include("tighturl.killbot.lib.inc.php")) or die("Error: cannot load tighturl.killbot.lib.inc.php");
  if (
file_exists("tighturl.config.inc.php")) include("tighturl.config.inc.php");

  
// Connect to MySQL, open database.
  
$conn = @mysql_connect($dbhost$dbuser$dbpass) or die("Error: Cannot connect to database.");
  
$db mysql_select_db($dbname$conn) or die("Error: Cannot select database. "mysql_error());

  if ((isset(
$BotNewFirst)) && ($BotNewFirst TRUE)) {
    
// Report only non-flagged new records, that have been checked 1 time.
    
TightURL_NewReport("SELECT * FROM $dbtable where (status=0) && (checkcount=0) ORDER BY id;");
  }

  
// Query records with status normal and either added within last 24 hours, or the last hit is more recent than the last check
  
TightURL_KillBot("SELECT * FROM $dbtable where (status=0) && ((SUBTIME(NOW(), '23:59:59.999999') <= adddate) || (lasthit > lastcheck));");

  if ((! isset(
$BotNewFirst)) || ( $BotNewFirst FALSE)) {
    
// Report only non-flagged new records, that have been checked 1 time.
    
TightURL_NewReport("SELECT * FROM $dbtable where (status=0) && (checkcount = 1) ORDER BY id;");
  }

  exit;

?>