2021-11-12 15:23:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* index.php
|
|
|
|
*
|
|
|
|
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
|
|
|
*/
|
|
|
|
|
2021-11-12 16:01:04 +00:00
|
|
|
use wishthis\{Page, Database};
|
2021-11-12 15:23:48 +00:00
|
|
|
|
2022-01-14 13:15:23 +00:00
|
|
|
if ($options && $options->getOption('isInstalled')) {
|
2022-01-18 13:37:35 +00:00
|
|
|
header('Location: /?page=home');
|
2022-01-14 09:07:50 +00:00
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2021-11-15 13:52:11 +00:00
|
|
|
$page = new page(__FILE__, 'Install');
|
2021-11-12 15:23:48 +00:00
|
|
|
$page->header();
|
|
|
|
|
2021-11-14 08:12:49 +00:00
|
|
|
$step = isset($_POST['step']) ? $_POST['step'] : 1;
|
|
|
|
|
|
|
|
switch ($step) {
|
|
|
|
case 1:
|
2022-01-18 13:37:35 +00:00
|
|
|
session_destroy();
|
2021-11-14 08:12:49 +00:00
|
|
|
?>
|
|
|
|
<main>
|
2022-01-14 13:10:09 +00:00
|
|
|
<div class="ui hidden divider"></div>
|
|
|
|
<div class="ui container">
|
|
|
|
<div class="ui segment">
|
|
|
|
<h1 class="ui header">Install</h1>
|
|
|
|
<h2 class="ui header">Step <?= $step ?></h2>
|
|
|
|
<p>Welcome to the wishthis installer.</p>
|
|
|
|
<p>wishthis needs a database to function properly. Please enter your credentials.</p>
|
|
|
|
|
|
|
|
<form class="ui form" action="/?page=install" method="post">
|
|
|
|
<input type="hidden" name="step" value="<?= $step + 1; ?>" />
|
|
|
|
|
|
|
|
<div class="field">
|
|
|
|
<label>Host</label>
|
|
|
|
<input type="text" name="DATABASE_HOST" placeholder="localhost" value="localhost" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="field">
|
|
|
|
<label>Name</label>
|
|
|
|
<input type="text" name="DATABASE_NAME" placeholder="wishthis" value="wishthis" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="field">
|
|
|
|
<label>Username</label>
|
|
|
|
<input type="text" name="DATABASE_USER" placeholder="root" value="root" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="field">
|
|
|
|
<label>Password</label>
|
|
|
|
<input type="text" name="DATABASE_PASSWORD" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<input class="ui primary button" type="submit" value="Continue" />
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-14 08:12:49 +00:00
|
|
|
</main>
|
|
|
|
<?php
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
$configDirectory = 'includes/config';
|
|
|
|
$configPath = $configDirectory . '/config.php';
|
|
|
|
$configSamplePath = $configDirectory . '/config-sample.php';
|
|
|
|
$configContents = file_get_contents($configSamplePath);
|
|
|
|
|
|
|
|
foreach ($_POST as $key => $value) {
|
|
|
|
if ('DATABASE' === substr($key, 0, 8)) {
|
|
|
|
$configContents = preg_replace('/(' . $key . '.+?\').*?(\')/', '$1' . $value . '$2', $configContents);
|
|
|
|
}
|
2021-11-12 16:01:04 +00:00
|
|
|
}
|
2021-11-14 08:12:49 +00:00
|
|
|
|
|
|
|
file_put_contents($configPath, $configContents);
|
2021-11-15 08:45:36 +00:00
|
|
|
?>
|
|
|
|
<main>
|
2022-01-14 13:10:09 +00:00
|
|
|
<div class="ui hidden divider"></div>
|
|
|
|
<div class="ui container">
|
|
|
|
<div class="ui segment">
|
|
|
|
<h1 class="ui header">Install</h1>
|
|
|
|
<h2 class="ui header">Step <?= $step ?></h2>
|
|
|
|
<p>Click Continue to test the database connection.</p>
|
|
|
|
|
|
|
|
<form class="ui form" action="?page=install" method="post">
|
|
|
|
<input type="hidden" name="step" value="<?= $step + 1; ?>" />
|
|
|
|
|
|
|
|
<input class="ui primary button" type="submit" value="Continue" />
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-15 08:45:36 +00:00
|
|
|
</main>
|
|
|
|
<?php
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2021-11-15 11:20:55 +00:00
|
|
|
/**
|
|
|
|
* Users
|
|
|
|
*/
|
|
|
|
$database->query('CREATE TABLE `users` (
|
2022-01-18 13:37:35 +00:00
|
|
|
`id` int PRIMARY KEY AUTO_INCREMENT,
|
|
|
|
`email` varchar(64) NOT NULL UNIQUE,
|
|
|
|
`password` varchar(128) NOT NULL,
|
|
|
|
`last_login` datetime NOT NULL DEFAULT NOW(),
|
|
|
|
`power` int NOT NULL DEFAULT 0
|
2021-11-15 08:45:36 +00:00
|
|
|
);');
|
2022-01-18 13:20:35 +00:00
|
|
|
$database->query('CREATE INDEX `idx_password` ON `users` (`password`);');
|
2021-11-15 11:20:55 +00:00
|
|
|
|
2021-11-15 11:55:01 +00:00
|
|
|
/**
|
|
|
|
* Wishlists
|
|
|
|
*/
|
|
|
|
$database->query('CREATE TABLE `wishlists` (
|
2022-01-17 13:17:05 +00:00
|
|
|
`id` int PRIMARY KEY AUTO_INCREMENT,
|
2021-11-15 11:59:55 +00:00
|
|
|
`user` int NOT NULL,
|
2022-01-17 13:30:41 +00:00
|
|
|
`name` varchar(128) NOT NULL,
|
2022-01-18 13:20:35 +00:00
|
|
|
`hash` varchar(128) NOT NULL,
|
2022-01-17 13:30:41 +00:00
|
|
|
FOREIGN KEY (`user`)
|
|
|
|
REFERENCES `users` (`id`)
|
|
|
|
ON DELETE CASCADE
|
2021-11-15 11:55:01 +00:00
|
|
|
);');
|
2022-01-18 13:20:35 +00:00
|
|
|
$database->query('CREATE INDEX `idx_hash` ON `wishlists` (`hash`);');
|
2021-11-15 11:55:01 +00:00
|
|
|
|
2021-11-15 13:49:50 +00:00
|
|
|
/**
|
|
|
|
* Products
|
|
|
|
*/
|
|
|
|
$database->query('CREATE TABLE `products` (
|
2022-01-17 13:17:05 +00:00
|
|
|
`id` int NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
2021-11-15 13:49:50 +00:00
|
|
|
`wishlist` int NOT NULL,
|
2022-01-18 13:20:35 +00:00
|
|
|
`url` VARCHAR(255) NOT NULL,
|
2022-01-17 13:17:29 +00:00
|
|
|
FOREIGN KEY (`wishlist`)
|
2022-01-17 13:26:14 +00:00
|
|
|
REFERENCES `wishlists` (`id`)
|
2022-01-17 13:17:29 +00:00
|
|
|
ON DELETE CASCADE
|
2021-11-15 13:49:50 +00:00
|
|
|
);');
|
|
|
|
|
2021-11-15 11:20:55 +00:00
|
|
|
/**
|
|
|
|
* Options
|
|
|
|
*/
|
|
|
|
$database->query('CREATE TABLE `options` (
|
2022-01-17 13:17:05 +00:00
|
|
|
`id` int PRIMARY KEY AUTO_INCREMENT,
|
2021-11-15 11:20:55 +00:00
|
|
|
`key` varchar(64) NOT NULL UNIQUE,
|
2022-01-17 13:17:05 +00:00
|
|
|
`value` varchar(128) NOT NULL
|
2021-11-15 11:20:55 +00:00
|
|
|
);');
|
|
|
|
|
|
|
|
$database->query('INSERT INTO `options`
|
|
|
|
(`key`, `value`) VALUES
|
2022-01-18 13:42:50 +00:00
|
|
|
("isInstalled", true),
|
|
|
|
("version", "' . VERSION . '")
|
2021-11-15 11:20:55 +00:00
|
|
|
;');
|
2021-11-14 08:12:49 +00:00
|
|
|
?>
|
|
|
|
<main>
|
2022-01-14 15:18:33 +00:00
|
|
|
<div class="ui hidden divider"></div>
|
|
|
|
<div class="ui container">
|
|
|
|
<div class="ui segment">
|
|
|
|
<h1 class="ui header">Success</h1>
|
2022-01-18 13:37:35 +00:00
|
|
|
<p><a class="ui primary button" href="/?page=register">Register</a></p>
|
2022-01-14 15:18:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-14 08:12:49 +00:00
|
|
|
</main>
|
|
|
|
<?php
|
|
|
|
break;
|
2021-11-12 15:23:48 +00:00
|
|
|
}
|