This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/core/_install.php

231 lines
7.2 KiB
PHP
Raw Normal View History

<?php
2014-02-18 21:59:07 +00:00
/**
* Shimmie Installer
2014-02-22 20:36:52 +00:00
*
2014-02-18 21:59:07 +00:00
* @package Shimmie
2015-08-09 11:14:28 +00:00
* @copyright Copyright (c) 2007-2015, Shish et al.
* @author Shish [webmaster at shishnet.org], jgen [jeffgenovy at gmail.com]
2014-02-18 22:01:35 +00:00
* @link http://code.shishnet.org/shimmie2/
2014-02-18 21:59:07 +00:00
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
2015-08-09 11:14:28 +00:00
* Initialise the database, check that folder
* permissions are set properly.
*
* This file should be independent of the database
2015-08-09 11:14:28 +00:00
* and other such things that aren't ready yet
2014-02-18 21:59:07 +00:00
*/
// TODO: Rewrite the entire installer and make it more readable.
ob_start();
date_default_timezone_set('UTC');
2019-06-25 21:15:49 +00:00
define("DATABASE_TIMEOUT", 10000);
?>
2012-06-26 22:37:29 +00:00
<!DOCTYPE html>
<html>
<head>
<title>Shimmie Installation</title>
2018-11-11 17:38:32 +00:00
<link rel="shortcut icon" href="ext/handle_static/static/favicon.ico">
2018-11-07 00:08:26 +00:00
<link rel="stylesheet" href="lib/shimmie.css" type="text/css">
<script type="text/javascript" src="vendor/bower-asset/jquery/dist/jquery.min.js"></script>
</head>
<body>
<?php if (false) { ?>
2012-06-26 22:37:29 +00:00
<div id="installer">
<h1>Install Error</h1>
<div class="container">
<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 and doesn't know how to handle PHP files.</p>
<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>.<br/><br/>
</p>
</div>
</div>
<pre style="display:none">
<?php } elseif (!file_exists("vendor/")) { ?>
<div id="installer">
<h1>Install Error</h1>
<h3>Warning: Composer vendor folder does not exist!</h3>
<div class="container">
<p>Shimmie is unable to find the composer vendor directory.<br>
Have you followed the composer setup instructions found in the <a href="https://github.com/shish/shimmie2#installation-development">README</a>?</>
<p>If you are not intending to do any development with Shimmie, it is highly recommend you use one of the pre-packaged releases found on <a href="https://github.com/shish/shimmie2/releases">Github</a> instead.</p>
</div>
</div>
<pre style="display:none">
<?php }
// Pull in necessary files
require_once "vendor/autoload.php";
2019-07-07 14:57:06 +00:00
$_tracer = new EventTracer();
2018-11-07 00:08:26 +00:00
require_once "core/exceptions.php";
require_once "core/cacheengine.php";
require_once "core/dbengine.php";
require_once "core/database.php";
2020-01-27 17:47:28 +00:00
require_once "core/util.php";
if (is_readable("data/config/shimmie.conf.php")) {
die("Shimmie is already installed.");
}
do_install();
2019-11-03 16:22:59 +00:00
// TODO: Can some of these be pushed into "core/???.inc.php" ?
function do_install()
2019-11-03 16:22:59 +00:00
{
if (file_exists("data/config/auto_install.conf.php")) {
require_once "data/config/auto_install.conf.php";
} elseif (@$_POST["database_type"] == DatabaseDriver::SQLITE) {
$id = bin2hex(random_bytes(5));
define('DATABASE_DSN', "sqlite:data/shimmie.{$id}.sqlite");
} elseif (isset($_POST['database_type']) && isset($_POST['database_host']) && isset($_POST['database_user']) && isset($_POST['database_name'])) {
define('DATABASE_DSN', "{$_POST['database_type']}:user={$_POST['database_user']};password={$_POST['database_password']};host={$_POST['database_host']};dbname={$_POST['database_name']}");
} else {
ask_questions();
return;
}
define("CACHE_DSN", null);
define("DATABASE_KA", true);
2020-01-27 17:47:28 +00:00
try {
create_dirs();
create_tables(new Database());
write_config();
} catch (InstallerException $e) {
print <<<EOD
<div id="installer">
<h1>Shimmie Installer</h1>
<h3>{$e->title}</h3>
<div class="container">
{$e->body}
<br/><br/>
</div>
</div>
EOD;
exit($e->code);
}
2019-11-03 16:22:59 +00:00
}
function ask_questions()
2019-11-03 16:22:59 +00:00
{
$warnings = [];
$errors = [];
2009-07-15 21:17:53 +00:00
if (check_gd_version() == 0 && check_im_version() == 0) {
$errors[] = "
2016-05-19 16:49:35 +00:00
No thumbnailers could be found - install the imagemagick
tools (or the PHP-GD library, if imagemagick is unavailable).
2012-03-09 22:27:12 +00:00
";
} elseif (check_im_version() == 0) {
$warnings[] = "
2012-06-26 22:37:29 +00:00
The 'convert' command (from the imagemagick package)
could not be found - PHP-GD can be used instead, but
the size of thumbnails will be limited.
2012-03-09 22:27:12 +00:00
";
}
2009-07-15 21:17:53 +00:00
if (!function_exists('mb_strlen')) {
$errors[] = "
The mbstring PHP extension is missing - multibyte languages
(eg non-english languages) may not work right.
";
}
$drivers = PDO::getAvailableDrivers();
if (
!in_array(DatabaseDriver::MYSQL, $drivers) &&
!in_array(DatabaseDriver::PGSQL, $drivers) &&
!in_array(DatabaseDriver::SQLITE, $drivers)
) {
$errors[] = "
2012-06-26 22:37:29 +00:00
No database connection library could be found; shimmie needs
2012-06-26 22:51:05 +00:00
PDO with either Postgres, MySQL, or SQLite drivers
2012-06-26 22:37:29 +00:00
";
}
$db_m = in_array(DatabaseDriver::MYSQL, $drivers) ? '<option value="'. DatabaseDriver::MYSQL .'">MySQL</option>' : "";
$db_p = in_array(DatabaseDriver::PGSQL, $drivers) ? '<option value="'. DatabaseDriver::PGSQL .'">PostgreSQL</option>' : "";
$db_s = in_array(DatabaseDriver::SQLITE, $drivers) ? '<option value="'. DatabaseDriver::SQLITE .'">SQLite</option>' : "";
2012-06-26 22:37:29 +00:00
$warn_msg = $warnings ? "<h3>Warnings</h3>".implode("\n<p>", $warnings) : "";
$err_msg = $errors ? "<h3>Errors</h3>".implode("\n<p>", $errors) : "";
2012-06-26 22:37:29 +00:00
print <<<EOD
2012-06-26 22:37:29 +00:00
<div id="installer">
<h1>Shimmie Installer</h1>
<div class="container">
$warn_msg
$err_msg
<h3>Database Install</h3>
2018-11-07 00:08:26 +00:00
<form action="index.php" method="POST">
<center>
<table class='form'>
<tr>
<th>Type:</th>
<td><select name="database_type" id="database_type" onchange="update_qs();">
$db_m
$db_p
$db_s
</select></td>
</tr>
<tr class="dbconf mysql pgsql">
<th>Host:</th>
<td><input type="text" name="database_host" size="40" value="localhost"></td>
</tr>
<tr class="dbconf mysql pgsql">
<th>Username:</th>
<td><input type="text" name="database_user" size="40"></td>
</tr>
<tr class="dbconf mysql pgsql">
<th>Password:</th>
<td><input type="password" name="database_password" size="40"></td>
</tr>
2018-11-07 16:48:07 +00:00
<tr class="dbconf mysql pgsql">
<th>DB&nbsp;Name:</th>
<td><input type="text" name="database_name" size="40" value="shimmie"></td>
</tr>
<tr><td colspan="2"><input type="submit" value="Go!"></td></tr>
</table>
</center>
<script>
$(function() {
update_qs();
});
function update_qs() {
$(".dbconf").hide();
var seldb = $("#database_type").val() || "none";
$("."+seldb).show();
}
</script>
</form>
<h3>Help</h3>
<p class="dbconf mysql pgsql">
Please make sure the database you have chosen exists and is empty.<br>
The username provided must have access to create tables within the database.
</p>
<p class="dbconf sqlite">
For SQLite the database name will be a filename on disk, relative to
where shimmie was installed.
</p>
<p class="dbconf none">
Drivers can generally be downloaded with your OS package manager;
2018-11-07 00:08:26 +00:00
for Debian / Ubuntu you want php-pgsql, php-mysql, or php-sqlite.
</p>
</div>
</div>
EOD;
2019-11-03 16:22:59 +00:00
}
?>
</body>
</html>