TightURL

TightURL Git Source Tree

Root/tighturl-install.php

1<?php
2// Very crude installer thrown together so there can be a
3// new TightURL 0.1.4 release. It is ugly but will do the job.
4
5if (isset($_REQUEST['Action']) && $_REQUEST['Action'])
6{
7
8// Install TightURL by setting up the database. This will create tables if needed.
9// It will also upgrade previous versions of the database to be 0.1.4 compliant
10
11  (require_once("tighturl.config.inc.php")) or die_HTML("Error: Cannot locate tighturl.config.inc.php.");
12
13  // Connect to MySQL, open database.
14  $conn = @mysql_connect($dbhost, $dbuser, $dbpass) or die_HTML("Error: Cannot connect to database.");
15  $db = mysql_select_db($dbname, $conn) or die_HTML("Error: Cannot select database. ". mysql_error());
16
17  $new = mysql_query("CREATE TABLE `".$dbtable."` ( `id` int(11) unsigned NOT NULL auto_increment, `status` tinyint(3) unsigned NOT NULL, `hits` int(11) NOT NULL default '0', `lasthit` datetime NOT NULL default '0000-00-00 00:00:00', `url` text NOT NULL, `adddate` datetime NOT NULL default '0000-00-00 00:00:00', `addip` text NOT NULL, `lastcheck` datetime NOT NULL default '0000-00-00 00:00:00', `checkcount` int(10) unsigned NOT NULL, `complaints` int(10) unsigned NOT NULL, `lastcomplaint` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
18  mysql_query("CREATE TABLE IF NOT EXISTS `".$dbtable."_bb2` ( `id` int(11) NOT NULL auto_increment, `ip` text NOT NULL, `date` datetime NOT NULL default '0000-00-00 00:00:00', `request_method` text NOT NULL, `request_uri` text NOT NULL, `server_protocol` text NOT NULL, `http_headers` text NOT NULL, `user_agent` text NOT NULL, `request_entity` text NOT NULL, `key` text NOT NULL, PRIMARY KEY (`id`), KEY `ip` (`ip`(15)), KEY `user_agent` (`user_agent`(10))) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
19
20  if (! $new) {
21    $fields = mysql_list_fields('$dbname', '$dbtable');
22    $result = mysql_query("SHOW COLUMNS FROM $dbtable");
23
24    $columnnames = array();
25    while ($row = mysql_fetch_array($result)) {
26      $columnnames[]=$row[0];
27    }
28
29    $hits = FALSE; $lasthit = FALSE;
30    if (in_array('hits', $columnnames)) $hits = TRUE;
31    if (in_array('lasthit', $columnnames)) $lasthit = TRUE;
32    if (in_array('status', $columnnames)) $status = TRUE;
33
34    if (! $status) { // If there's a status field, then this DB has already been upgraded, do nothing.
35      $maker = "ALTER TABLE `tighturl` DROP PRIMARY KEY, CHANGE `id` `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD `status` tinyint(3) UNSIGNED NOT NULL DEFAULT '0' AFTER `id`";
36      if ($hits) {
37        $maker .= ", CHANGE `hits` `hits` int(11) NOT NULL DEFAULT '0' AFTER `status`";
38      }
39      else {
40        $maker .= ", ADD `hits` int(11) NOT NULL DEFAULT '0' AFTER `status`";
41      }
42      if ($lasthit) {
43        $maker .= ", CHANGE `lasthit` `lasthit` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `hits`";
44      }
45      else {
46        $maker .= ", ADD `lasthit` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `hits`";
47      }
48      $maker .= ", CHANGE `url` `url` text NOT NULL AFTER `lasthit`"
49       . ", ADD `adddate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `url`"
50       . ", ADD `addip` text NOT NULL AFTER `adddate`"
51       . ", ADD `checkcount` int(10) NOT NULL DEFAULT '0' AFTER `addip`"
52       . ", ADD `lastcheck` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `checkcount`"
53       . ", ADD `complaints` int(10) NOT NULL DEFAULT '0' AFTER `lastcheck`"
54       . ", ADD `lastcomplaint` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `complaints`"
55       . ", ADD PRIMARY KEY (`id`), TYPE=MyISAM;";
56
57      mysql_query($maker) or die_HTML("Error: Database error. ". mysql_error());
58    }
59  }
60
61?>
62<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
63<html>
64<head>
65   <title>TightURL Installer</title>
66</head>
67<body>
68
69<h1>Finished.</h1>
70
71<p>Your TightURL database has been installed or upgraded as appropriate.</p>
72
73<p><font color="red">You must delete (or at least rename) tighturl-install.php in order to run TightURL.</font></p>
74
75</body>
76</html>
77
78<?php
79exit;
80
81} else {
82// start else clause
83
84?>
85<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
86<html>
87<head>
88   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
89   <TITLE>TightURL Install/Upgrade</TITLE>
90</head>
91<body>
92<h1>Welcome to the TightURL Installer and Upgrader</h1>
93
94<P>This script will either set up a newly created TightURL database, or upgrade an existing TightURL database
95to work with the version of TightURL you just installed. This process will happen automatically once you click
96the "install/upgrade now!" button below.</P>
97
98<P>Before starting, please make sure you've completed the following steps below:<br />
99<ol>
100  <li>BACK UP your TightURL database!!!!</li>
101  <li>Make sure <FONT FACE="FIXED"><CODE>tighturl.config.inc.php</CODE></FONT> has the proper settings for
102      <FONT FACE="FIXED"><CODE>$dbhost</CODE></FONT>, <FONT FACE="FIXED"><CODE>$dbname</CODE></FONT>, <FONT FACE="FIXED"><CODE>$dbtable</CODE></FONT>,
103      <FONT FACE="FIXED"><CODE>$dbuser</CODE></FONT>, and <FONT FACE="FIXED"><CODE>$dbpass</CODE></FONT>.</li>
104</ol>
105
106<form action="tighturl-install.php" method="post">
107  <table border="0">
108    <tr>
109      <td width="100%">
110        <p align="center">
111          <input type="submit" name="Action" value="Install/Upgrade Now!">
112        </p>
113      </td>
114    </tr>
115  </table>
116</form>
117</P>
118
119<P><HR NOSHADE></P>
120</BODY>
121</HTML>
122<?php
123} // end else clause
124
125function die_HTML($errmsg) {
126
127  echo "<html>\n <head>\n <title>TightURL Installer/Upgrader</title>\n </head>\n <body>\n";
128  echo " " . $errmsg . "<br />\n";
129  echo " </body>\n</html>";
130  die;
131}
132
133?>
134

Archive Download this file

Branches