2008-04-19 18:57:43 +00:00
|
|
|
<?php ob_start(); ?>
|
2008-01-26 13:14:30 +00:00
|
|
|
<html>
|
2008-01-27 15:33:59 +00:00
|
|
|
<!--
|
|
|
|
- install.php (c) Shish 2007
|
|
|
|
-
|
|
|
|
- Initialise the database, check that folder
|
|
|
|
- permissions are set properly, set an admin
|
|
|
|
- account.
|
|
|
|
-
|
|
|
|
- This file should be independant of the database
|
|
|
|
- and other such things that aren't ready yet
|
|
|
|
-->
|
2008-01-26 13:14:30 +00:00
|
|
|
<head>
|
2008-01-27 15:33:59 +00:00
|
|
|
<title>Shimmie Installation</title>
|
2008-01-26 13:14:30 +00:00
|
|
|
<style>
|
|
|
|
BODY {background: #EEE;font-family: "Arial", sans-serif;font-size: 14px;}
|
|
|
|
H1, H3 {border: 1px solid black;background: #DDD;text-align: center;}
|
|
|
|
H1 {margin-top: 0px;margin-bottom: 0px;padding: 2px;}
|
|
|
|
H3 {margin-top: 32px;padding: 1px;}
|
|
|
|
FORM {margin: 0px;}
|
|
|
|
A {text-decoration: none;}
|
|
|
|
A:hover {text-decoration: underline;}
|
|
|
|
#block {width: 512px; margin: auto; margin-top: 64px;}
|
2008-01-27 15:33:59 +00:00
|
|
|
#iblock {width: 512px; margin: auto; margin-top: 16px;}
|
|
|
|
TD INPUT {width: 350px;}
|
2008-01-26 13:14:30 +00:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
2008-01-27 15:33:59 +00:00
|
|
|
<?php if(false) { ?>
|
2008-01-26 13:14:30 +00:00
|
|
|
<div id="block">
|
|
|
|
<h1>Install Error</h1>
|
|
|
|
<p>Shimmie needs to be run via a web server with PHP support -- you
|
|
|
|
appear to be either opening the file from your hard disk, or your
|
|
|
|
web server is mis-configured.
|
|
|
|
<p>If you've installed a web server on your desktop PC, you probably
|
|
|
|
want to visit <a href="http://localhost/">the local web server</a>.
|
|
|
|
</div>
|
|
|
|
<div style="display: none;">
|
2008-01-27 15:33:59 +00:00
|
|
|
<PLAINTEXT>
|
2008-01-26 13:14:30 +00:00
|
|
|
<?php }
|
2008-01-27 15:33:59 +00:00
|
|
|
assert_options(ASSERT_ACTIVE, 1);
|
|
|
|
assert_options(ASSERT_BAIL, 1);
|
|
|
|
|
2007-04-16 11:58:25 +00:00
|
|
|
/*
|
2008-01-27 15:33:59 +00:00
|
|
|
* This file lets anyone destroy the database -- disable it
|
|
|
|
* as soon as the admin is done installing for the first time
|
2007-04-16 11:58:25 +00:00
|
|
|
*/
|
2008-01-27 15:33:59 +00:00
|
|
|
if(is_readable("config.php")) {
|
2010-03-15 05:30:37 +00:00
|
|
|
session_start();
|
|
|
|
?>
|
|
|
|
<div id="iblock">
|
|
|
|
<h1>Shimmie Repair Console</h1>
|
|
|
|
<?php
|
|
|
|
include "config.php";
|
|
|
|
if($_SESSION['dsn'] == $database_dsn || $_POST['dsn'] == $database_dsn) {
|
|
|
|
if($_POST['dsn']) {$_SESSION['dsn'] = $_POST['dsn'];}
|
|
|
|
|
|
|
|
if(empty($_GET["action"])) {
|
|
|
|
echo "<h3>Basic Checks</h3>";
|
|
|
|
echo "If these checks fail, something is broken; if they all pass, ";
|
|
|
|
echo "something <i>might</i> be broken, just not checked for...";
|
|
|
|
eok("Images writable", is_writable("images"));
|
|
|
|
eok("Thumbs writable", is_writable("thumbs"));
|
|
|
|
eok("Data writable", is_writable("data"));
|
|
|
|
|
|
|
|
/*
|
|
|
|
echo "<h3>New Database DSN</h3>";
|
|
|
|
echo "
|
|
|
|
<form action='install.php?action=newdsn' method='POST'>
|
|
|
|
<center>
|
|
|
|
<table>
|
|
|
|
<tr><td>Database:</td><td><input type='text' name='new_dsn' size='40'></td></tr>
|
|
|
|
<tr><td colspan='2'><center><input type='submit' value='Go!'></center></td></tr>
|
|
|
|
</table>
|
|
|
|
</center>
|
|
|
|
</form>
|
|
|
|
";
|
|
|
|
*/
|
|
|
|
|
|
|
|
echo "<h3>Log Out</h3>";
|
|
|
|
echo "
|
|
|
|
<form action='install.php?action=logout' method='POST'>
|
|
|
|
<input type='submit' value='Leave'>
|
|
|
|
</form>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
else if($_GET["action"] == "logout") {
|
|
|
|
session_destroy();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo "
|
|
|
|
<h3>Login</h3>
|
|
|
|
Enter the database DSN exactly as in config.php (ie, as originally
|
|
|
|
installed) to access advanced recovery tools:
|
|
|
|
|
|
|
|
<form action='install.php' method='POST'>
|
|
|
|
<center>
|
|
|
|
<table>
|
|
|
|
<tr><td>Database:</td><td><input type='text' name='dsn' size='40'></td></tr>
|
|
|
|
<tr><td colspan='2'><center><input type='submit' value='Go!'></center></td></tr>
|
|
|
|
</table>
|
|
|
|
</center>
|
|
|
|
</form>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
echo "\t\t</div>";
|
2008-01-27 15:33:59 +00:00
|
|
|
exit;
|
|
|
|
}
|
2008-04-08 16:02:43 +00:00
|
|
|
require_once "core/compat.inc.php";
|
2009-01-22 12:05:55 +00:00
|
|
|
require_once "core/database.class.php";
|
2007-04-16 11:58:25 +00:00
|
|
|
|
|
|
|
do_install();
|
|
|
|
|
|
|
|
// utilities {{{
|
|
|
|
function check_gd_version() {
|
|
|
|
$gdversion = 0;
|
|
|
|
|
|
|
|
if (function_exists('gd_info')){
|
|
|
|
$gd_info = gd_info();
|
|
|
|
if (substr_count($gd_info['GD Version'], '2.')) {
|
|
|
|
$gdversion = 2;
|
|
|
|
} else if (substr_count($gd_info['GD Version'], '1.')) {
|
|
|
|
$gdversion = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $gdversion;
|
|
|
|
}
|
2008-01-27 15:33:59 +00:00
|
|
|
|
|
|
|
function check_im_version() {
|
|
|
|
if(!ini_get('safe_mode')) {
|
|
|
|
$convert_check = exec("convert");
|
|
|
|
}
|
|
|
|
return (empty($convert_check) ? 0 : 1);
|
|
|
|
}
|
2010-03-15 05:30:37 +00:00
|
|
|
|
|
|
|
function eok($name, $value) {
|
|
|
|
echo "<br>$name ... ";
|
|
|
|
if($value) {
|
|
|
|
echo "<font color='green'>ok</font>\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo "<font color='red'>failed</font>\n";
|
|
|
|
}
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
// }}}
|
2008-01-27 16:25:17 +00:00
|
|
|
function do_install() { // {{{
|
2009-01-22 13:02:22 +00:00
|
|
|
if(isset($_POST['database_dsn'])) {
|
|
|
|
install_process($_POST['database_dsn']);
|
|
|
|
}
|
|
|
|
else if(file_exists("auto_install.conf")) {
|
|
|
|
install_process(trim(file_get_contents("auto_install.conf")));
|
2009-07-15 21:20:10 +00:00
|
|
|
unlink("auto_install.conf");
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2008-01-27 16:25:17 +00:00
|
|
|
else {
|
2009-01-22 13:02:22 +00:00
|
|
|
begin();
|
2008-01-27 16:25:17 +00:00
|
|
|
}
|
|
|
|
} // }}}
|
|
|
|
function begin() { // {{{
|
2009-07-15 21:17:53 +00:00
|
|
|
$err = "";
|
|
|
|
$thumberr = "";
|
|
|
|
$dberr = "";
|
|
|
|
|
2008-01-27 15:33:59 +00:00
|
|
|
if(check_gd_version() == 0 && check_im_version() == 0) {
|
2009-07-15 21:17:53 +00:00
|
|
|
$thumberr = "<p>PHP's GD extension seems to be missing, ".
|
2008-01-27 15:33:59 +00:00
|
|
|
"and imagemagick's \"convert\" command cannot be found - ".
|
|
|
|
"no thumbnailing engines are available.";
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2009-07-15 21:17:53 +00:00
|
|
|
|
|
|
|
if(!function_exists("mysql_connect")) {
|
|
|
|
$dberr = "<p>PHP's MySQL extension seems to be missing; you may ".
|
|
|
|
"be able to use an unofficial alternative, checking ".
|
|
|
|
"for libraries...";
|
|
|
|
if(!function_exists("pg_connect")) {
|
|
|
|
$dberr .= "<br>PgSQL is missing";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$dberr .= "<br>PgSQL is available";
|
|
|
|
}
|
|
|
|
if(!function_exists("sqlite_open")) {
|
|
|
|
$dberr .= "<br>SQLite is missing";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$dberr .= "<br>SQLite is available";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($thumberr || $dberr) {
|
|
|
|
$err = "<h3>Error</h3>";
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print <<<EOD
|
2008-01-26 13:14:30 +00:00
|
|
|
<div id="iblock">
|
|
|
|
<h1>Shimmie Installer</h1>
|
|
|
|
|
2009-07-15 21:17:53 +00:00
|
|
|
$err
|
|
|
|
$thumberr
|
|
|
|
$dberr
|
2007-04-16 11:58:25 +00:00
|
|
|
|
2008-01-26 13:14:30 +00:00
|
|
|
<h3>Install</h3>
|
2008-01-27 16:25:17 +00:00
|
|
|
<form action="install.php" method="POST">
|
2008-01-26 13:14:30 +00:00
|
|
|
<center>
|
|
|
|
<table>
|
|
|
|
<tr><td>Database:</td><td><input type="text" name="database_dsn" size="40"></td></tr>
|
2008-01-26 14:38:32 +00:00
|
|
|
<tr><td colspan="2"><center><input type="submit" value="Go!"></center></td></tr>
|
2008-01-26 13:14:30 +00:00
|
|
|
</table>
|
|
|
|
</center>
|
|
|
|
</form>
|
2007-04-16 11:58:25 +00:00
|
|
|
|
2008-01-26 13:14:30 +00:00
|
|
|
<h3>Help</h3>
|
|
|
|
|
|
|
|
<p>Databases should be specified like so:
|
|
|
|
<br>ie: <code>protocol://username:password@host/database?options</code>
|
|
|
|
<br>eg: <code>mysql://shimmie:pw123@localhost/shimmie?persist</code>
|
|
|
|
</div>
|
2007-04-16 11:58:25 +00:00
|
|
|
EOD;
|
2008-01-27 16:25:17 +00:00
|
|
|
} // }}}
|
2009-01-22 13:02:22 +00:00
|
|
|
function install_process($database_dsn) { // {{{
|
2010-03-15 04:31:28 +00:00
|
|
|
build_dirs();
|
2008-01-27 16:25:17 +00:00
|
|
|
create_tables($database_dsn);
|
2009-01-22 09:39:44 +00:00
|
|
|
insert_defaults($database_dsn);
|
2008-01-27 16:25:17 +00:00
|
|
|
write_config($database_dsn);
|
|
|
|
|
2009-01-22 09:39:44 +00:00
|
|
|
header("Location: index.php");
|
2007-04-16 11:58:25 +00:00
|
|
|
} // }}}
|
|
|
|
function create_tables($dsn) { // {{{
|
2010-01-17 09:43:49 +00:00
|
|
|
if(substr($dsn, 0, 5) == "mysql") {
|
|
|
|
$engine = new MySQL();
|
|
|
|
}
|
|
|
|
else if(substr($dsn, 0, 5) == "pgsql") {
|
|
|
|
$engine = new PostgreSQL();
|
|
|
|
}
|
|
|
|
else if(substr($dsn, 0, 6) == "sqlite") {
|
|
|
|
$engine = new SQLite();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
die("Unknown database engine; Shimmie currently officially supports MySQL
|
|
|
|
(mysql://), with hacks for Postgres (pgsql://) and SQLite (sqlite://)");
|
|
|
|
}
|
|
|
|
|
2007-04-16 11:58:25 +00:00
|
|
|
$db = NewADOConnection($dsn);
|
|
|
|
if(!$db) {
|
|
|
|
die("Couldn't connect to \"$dsn\"");
|
|
|
|
}
|
|
|
|
else {
|
2009-01-22 12:05:55 +00:00
|
|
|
$engine->init($db);
|
|
|
|
|
|
|
|
$db->execute($engine->create_table_sql("aliases", "
|
|
|
|
oldtag VARCHAR(128) NOT NULL PRIMARY KEY,
|
|
|
|
newtag VARCHAR(128) NOT NULL,
|
2009-01-22 13:42:44 +00:00
|
|
|
INDEX(newtag)
|
2009-01-22 12:05:55 +00:00
|
|
|
"));
|
|
|
|
$db->execute($engine->create_table_sql("config", "
|
|
|
|
name VARCHAR(128) NOT NULL PRIMARY KEY,
|
|
|
|
value TEXT
|
|
|
|
"));
|
2009-01-22 13:03:51 +00:00
|
|
|
$db->execute($engine->create_table_sql("users", "
|
|
|
|
id SCORE_AIPK,
|
2009-01-22 13:42:44 +00:00
|
|
|
name VARCHAR(32) UNIQUE NOT NULL,
|
2009-01-22 13:03:51 +00:00
|
|
|
pass CHAR(32),
|
2009-07-15 22:29:14 +00:00
|
|
|
joindate SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,
|
2009-01-22 13:03:51 +00:00
|
|
|
admin SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
|
2009-01-22 13:42:44 +00:00
|
|
|
email VARCHAR(128)
|
2009-01-22 13:03:51 +00:00
|
|
|
"));
|
2009-01-22 12:05:55 +00:00
|
|
|
$db->execute($engine->create_table_sql("images", "
|
|
|
|
id SCORE_AIPK,
|
2009-01-22 13:03:51 +00:00
|
|
|
owner_id INTEGER NOT NULL,
|
2009-01-22 12:05:55 +00:00
|
|
|
owner_ip SCORE_INET NOT NULL,
|
|
|
|
filename VARCHAR(64) NOT NULL,
|
|
|
|
filesize INTEGER NOT NULL,
|
2009-01-22 13:42:44 +00:00
|
|
|
hash CHAR(32) UNIQUE NOT NULL,
|
2009-01-22 12:05:55 +00:00
|
|
|
ext CHAR(4) NOT NULL,
|
|
|
|
source VARCHAR(255),
|
|
|
|
width INTEGER NOT NULL,
|
|
|
|
height INTEGER NOT NULL,
|
2009-07-15 22:29:14 +00:00
|
|
|
posted SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,
|
2009-01-24 11:59:51 +00:00
|
|
|
locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
|
2009-01-22 12:05:55 +00:00
|
|
|
INDEX(owner_id),
|
|
|
|
INDEX(width),
|
2009-01-22 13:03:51 +00:00
|
|
|
INDEX(height),
|
|
|
|
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
|
2009-01-22 12:05:55 +00:00
|
|
|
"));
|
|
|
|
$db->execute($engine->create_table_sql("tags", "
|
|
|
|
id SCORE_AIPK,
|
2009-01-22 13:42:44 +00:00
|
|
|
tag VARCHAR(64) UNIQUE NOT NULL,
|
|
|
|
count INTEGER NOT NULL DEFAULT 0
|
2009-01-22 12:05:55 +00:00
|
|
|
"));
|
|
|
|
$db->execute($engine->create_table_sql("image_tags", "
|
2009-01-22 13:03:51 +00:00
|
|
|
image_id INTEGER NOT NULL,
|
|
|
|
tag_id INTEGER NOT NULL,
|
2009-01-22 12:05:55 +00:00
|
|
|
INDEX(image_id),
|
|
|
|
INDEX(tag_id),
|
2009-01-22 13:42:44 +00:00
|
|
|
UNIQUE(image_id, tag_id),
|
2009-01-22 13:03:51 +00:00
|
|
|
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
|
2009-01-22 12:05:55 +00:00
|
|
|
"));
|
2009-12-30 08:54:04 +00:00
|
|
|
$db->execute("INSERT INTO config(name, value) VALUES('db_version', 8)");
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
$db->Close();
|
|
|
|
} // }}}
|
2009-01-22 09:39:44 +00:00
|
|
|
function insert_defaults($dsn) { // {{{
|
2008-01-27 16:25:17 +00:00
|
|
|
$db = NewADOConnection($dsn);
|
|
|
|
if(!$db) {
|
|
|
|
die("Couldn't connect to \"$dsn\"");
|
|
|
|
}
|
|
|
|
else {
|
2009-07-16 19:44:04 +00:00
|
|
|
if(substr($dsn, 0, 5) == "mysql") {
|
|
|
|
$engine = new MySQL();
|
|
|
|
}
|
|
|
|
else if(substr($dsn, 0, 5) == "pgsql") {
|
|
|
|
$engine = new PostgreSQL();
|
|
|
|
}
|
|
|
|
else if(substr($dsn, 0, 6) == "sqlite") {
|
|
|
|
$engine = new SQLite();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
die("Unknown database engine; Shimmie currently officially supports MySQL
|
|
|
|
(mysql://), with hacks for Postgres (pgsql://) and SQLite (sqlite://)");
|
|
|
|
}
|
|
|
|
$engine->init($db);
|
|
|
|
|
2008-01-27 16:25:17 +00:00
|
|
|
$config_insert = $db->Prepare("INSERT INTO config(name, value) VALUES(?, ?)");
|
|
|
|
$user_insert = $db->Prepare("INSERT INTO users(name, pass, joindate, admin) VALUES(?, ?, now(), ?)");
|
|
|
|
|
|
|
|
$db->Execute($user_insert, Array('Anonymous', null, 'N'));
|
|
|
|
$db->Execute($config_insert, Array('anon_id', $db->Insert_ID()));
|
|
|
|
|
|
|
|
if(check_im_version() > 0) {
|
|
|
|
$db->Execute($config_insert, Array('thumb_engine', 'convert'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->Close();
|
|
|
|
}
|
|
|
|
} // }}}
|
2007-04-16 11:58:25 +00:00
|
|
|
function build_dirs() { // {{{
|
2010-03-15 04:31:28 +00:00
|
|
|
// *try* and make default dirs. Ignore any errors --
|
|
|
|
// if something is amiss, we'll tell the user later
|
|
|
|
if(!file_exists("images")) @mkdir("images");
|
|
|
|
if(!file_exists("thumbs")) @mkdir("thumbs");
|
|
|
|
if(!file_exists("data") ) @mkdir("data");
|
|
|
|
if(!is_writable("images")) @chmod("images", 0755);
|
|
|
|
if(!is_writable("thumbs")) @chmod("thumbs", 0755);
|
|
|
|
if(!is_writable("data") ) @chmod("data", 0755);
|
2007-04-16 11:58:25 +00:00
|
|
|
|
|
|
|
if(
|
2010-03-15 04:31:28 +00:00
|
|
|
!file_exists("images") || !file_exists("thumbs") || !file_exists("data") ||
|
|
|
|
!is_writable("images") || !is_writable("thumbs") || !is_writable("data")
|
2007-04-16 11:58:25 +00:00
|
|
|
) {
|
2007-08-08 04:53:55 +00:00
|
|
|
print "Shimmie needs three folders in it's directory, 'images', 'thumbs', and 'data',
|
2007-04-16 11:58:25 +00:00
|
|
|
and they need to be writable by the PHP user (if you see this error,
|
|
|
|
if probably means the folders are owned by you, and they need to be
|
|
|
|
writable by the web server).
|
|
|
|
<p>Once you have created these folders, hit 'refresh' to continue.";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
} // }}}
|
|
|
|
function write_config($dsn) { // {{{
|
2007-12-19 10:39:44 +00:00
|
|
|
$file_content = "<?php \$database_dsn='$dsn'; ?>";
|
2007-04-16 11:58:25 +00:00
|
|
|
|
2009-01-22 09:39:44 +00:00
|
|
|
if(is_writable("./") && file_put_contents("config.php", $file_content)) {
|
2007-04-16 11:58:25 +00:00
|
|
|
assert(file_exists("config.php"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$h_file_content = htmlentities($file_content);
|
|
|
|
print <<<EOD
|
|
|
|
The web server isn't allowed to write to the config file; please copy
|
|
|
|
the text below, save it as 'config.php', and upload it into the shimmie
|
|
|
|
folder manually. Make sure that when you save it, there is no whitespace
|
|
|
|
before the "<?php" or after the "?>"
|
|
|
|
|
|
|
|
<p><textarea cols="80" rows="2">$file_content</textarea>
|
|
|
|
|
2009-01-22 12:05:55 +00:00
|
|
|
<p>One done, <a href='index.php'>Continue</a>
|
2007-04-16 11:58:25 +00:00
|
|
|
EOD;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
} // }}}
|
|
|
|
?>
|
2008-01-27 15:33:59 +00:00
|
|
|
</body>
|
|
|
|
</html>
|