<?php
/**
 * TightURL :: A blind redirection service
 *
 * Copyright (c) 2004, Ron Guerin <ron@vnetworx.net>
 * portions Copyright (c) 2002,2003 Free Software Foundation
 *
 * This file implements a blind redirection service named TightURL.
 * TightURL is Free Software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * TightURL is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * If you are not able to view the LICENSE, which should
 * always be possible within a valid and working TightURL release,
 * please write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * to get a copy of the GNU General Public License or to report a
 * possible license violation.
 *
 * @package TightURL
 * @author Ron Guerin <ron@vnetworx.net>
 * @license http://www.fsf.org/licenses/gpl.html GNU Public License
 * @copyright Copyright &copy; 2004 Ron Guerin
 * @filesource
 * @link http://tighturl.com TightURL
 * @version 0.1
 * 
 */
define("VERSION""0.1.2ex6");
define("REQUIRED_PHP_VERSION""4.3.0");

// System defaults,  DO NOT EDIT THIS FILE
// Edit tighturl.config.inc.php instead!

global $copyright$conn$db$os$svcname;

$dbhost "localhost";
$dbuser "dbuser";
$dbpass "dbpass";
$dbname "tighturl";
$dbtable "urls";

// You REALLY don't want to edit below here unless you know what you're doing.

// *************************************************************************

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

// ****** !All overridable configuration variables must go above this line! ******

  
(include("tighturl.lib.inc.php")) or die_HTML("$svcname Error: Can't include tighturl.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_HTML($svcname"Error: Cannot connect to database.");
  
$db mysql_select_db($dbname$conn) or die_HTML($svcname"Error: Cannot select database. "mysql_error());

  if (! 
mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$dbtable."'"))) {
    
// Query to create new table
    
$req  "CREATE TABLE IF NOT EXISTS `".$dbtable."` ( `id` int(11) unsigned NOT NULL auto_increment,";
    
$req .= " `status` tinyint(3) unsigned NOT NULL, `url` text NOT NULL,";
    
$req .= " `adddate` datetime NOT NULL default '0000-00-00 00:00:00',";
    
$req .= " `addip` text NOT NULL, `hits` int(11) NOT NULL default '0',";
    
$req .= " `lasthit` datetime NOT NULL default '0000-00-00 00:00:00',";
    
$req .= " `checkcount` tinyint(3) unsigned NOT NULL,";
    
$req .= " `lastcheck` datetime NOT NULL default '0000-00-00 00:00:00',";
    
$req .= " `complaints` int(10) unsigned NOT NULL,";
    
$req .= " `lastcomplaint` datetime NOT NULL default '0000-00-00 00:00:00',";
    
$req .= " PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
  }
  else {
    
// Query to modify table of previous release

    // First, check to see if this hasn't been done already by looking for the lastcomplaint field

    
$req  "ALTER TABLE `".$dbtable."`";
    
$req .= " ADD COLUMN `status` TINYINT UNSIGNED NOT NULL AFTER `id`,";
    
$req .= " CHANGE `url` `url` text NOT NULL AFTER `status`,";
    
$req .= " ADD COLUMN `adddate` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `url`;";
    
$req .= " ADD COLUMN `addip` TEXT NOT NULL AFTER `adddate`,";
    
$req .= " ADD COLUMN `hits` INT NOT NULL DEFAULT '' AFTER `addip`,";
    
$req .= " ADD COLUMN `lasthit` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `hits`,";
    
$req .= " ADD COLUMN `checkcount` TINYINT UNSIGNED NOT NULL AFTER `lasthit`,";
    
$req .= " ADD COLUMN `lastcheck` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `checkcount`,";
    
$req .= " ADD COLUMN `complaints` INT UNSIGNED NOT NULL AFTER `checkcount`,";
    
$req .= " ADD COLUMN `lastcomplaint` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `complaints`;";
  }
  
// Execute table query
  
$res mysql_query($req) or die(mysql_error());

  
$req  "CREATE TABLE IF NOT EXISTS `".$dbtable."-bb` (";
  
$req .= " `id` INT(11) NOT NULL auto_increment,";
  
$req .= " `ip` TEXT NOT NULL,";
  
$req .= " `date` DATETIME NOT NULL default '0000-00-00 00:00:00',";
  
$req .= " `request_method` TEXT NOT NULL,";
  
$req .= " `request_uri` TEXT NOT NULL,";
  
$req .= " `server_protocol` TEXT NOT NULL,";
  
$req .= " `http_headers` TEXT NOT NULL,";
  
$req .= " `user_agent` TEXT NOT NULL,";
  
$req .= " `request_entity` TEXT NOT NULL,";
  
$req .= " `key` TEXT NOT NULL,";
  
$req .= " INDEX (`ip`(15)),";
  
$req .= " INDEX (`user_agent`(10)),";
  
$req .= " PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;";

  
// Execute create new table query
  
$res mysql_query($req) or die(mysql_error());

  
// Now offer to convert template files by renaming them and add
  // the version header to squish.tmpl

  // <!-- "VERSION", "0.1.2-1" -->
  // <!-- Do not remove the template version comment below or you will break the version checker -->
  // <!-- Do not update the version number, but otherwise change the template as you require -->
  // <!-- "VERSION", "0.2.0.0" -->
  //    $SVCNAME is powered by Squish $SQUISHVER &amp; <a href="http://tighturl.com/project/">TightURL $TIGHTURLVER</a>,

  // Create an admin table.

  // Collect admin e-mail address, (store in table?) along with version of TightURL used on the database.
  // Start doing version checks on TightURL init.

  // Attempt to get user to subscribe administrator e-mail address to tighturl-announce@lists.sourceforge.net

  // Convert FOFMethod in config file to OperatingMode
  

  // Offer to perform killbot function (but only) after converting database (last, since this takes the most time)
  
TightURL_KillBot();  

  exit;

?>