index.php

main 113 lines · 2.9 KB Raw
Alex Alex Commit Initial commit 01/10/2026 09:20
1<?php
2/**
3 * ZnoteX installer.
4 *
5 * Six steps, one router. Reachable at /install/ until the site is installed,
6 * after which it refuses to run - see install_locked_reason().
7 *
8 * Delete this folder once you are done. Nothing else depends on it.
9 */
10
11define('ZNOTE_INSTALL', true);
12
13if (PHP_VERSION_ID < 80100) {
14 die('ZnoteX needs PHP 8.1 or newer. You are on PHP ' . PHP_VERSION . '.');
15}
16
17require_once __DIR__ . '/../engine/session.php';
18require_once __DIR__ . '/../engine/security.php';
19znote_session_start();
20znote_security_boot();
21
22require_once __DIR__ . '/bootstrap.php';
23
24$locked = install_locked_reason();
25
26$step = (int)($_GET['step'] ?? 1);
27if ($step < 1 || $step > count(INSTALL_STEPS)) {
28 $step = 1;
29}
30
31// No jumping ahead: the later steps depend on what the earlier ones collected.
32if ($locked === '' && $step > install_max_step()) {
33 $step = install_max_step();
34}
35
36if ($locked === '' && ($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST' && !install_csrf_validate()) {
37 install_error('Invalid or expired form token. Please refresh the page and try again.');
38 header('Location: ' . install_url($step));
39 exit;
40}
41
42// A step handles its own POST and either advances or sets an error.
43$stepFile = __DIR__ . '/steps/' . $step . '.php';
44
45ob_start();
46if ($locked === '') {
47 if (is_file($stepFile)) {
48 include $stepFile;
49 } else {
50 echo '<p>Missing installer step file.</p>';
51 }
52}
53$content = ob_get_clean();
54if ($locked === '') {
55 $content = install_csrf_inject($content);
56}
57
58$error = install_take_error();
59?>
60<!DOCTYPE html>
61<html lang="en" dir="ltr">
62<head>
63 <meta charset="utf-8">
64 <meta name="viewport" content="width=device-width, initial-scale=1">
65 <meta name="robots" content="noindex, nofollow">
66 <title>Install ZnoteX</title>
67 <link rel="stylesheet" href="assets/install.css">
68</head>
69<body>
70
71<div class="wrap">
72
73 <header class="head">
74 <div class="brand"><span class="mark">ZX</span> Install ZnoteX</div>
75 <span class="version">2.0.1</span>
76 </header>
77
78 <?php if ($locked === ''): ?>
79 <ol class="steps">
80 <?php foreach (INSTALL_STEPS as $number => $label): ?>
81 <li class="<?= $number === $step ? 'is-current' : ($number < $step ? 'is-done' : '') ?>">
82 <span class="num"><?= $number < $step ? '&#10003;' : $number ?></span>
83 <span class="lbl"><?= ih($label) ?></span>
84 </li>
85 <?php endforeach; ?>
86 </ol>
87 <?php endif; ?>
88
89 <main class="card">
90 <?php if ($locked !== ''): ?>
91 <h1>Already installed</h1>
92 <p class="bad"><?= $locked ?></p>
93 <p>
94 <a class="btn" href="../index.php">Go to the site</a>
95 <a class="btn ghost" href="../admin/index.php">Admin panel</a>
96 </p>
97 <?php else: ?>
98 <?php if ($error !== ''): ?>
99 <p class="bad"><?= $error ?></p>
100 <?php endif; ?>
101 <?= $content ?>
102 <?php endif; ?>
103 </main>
104
105 <footer class="foot">
106 Step <?= (int)$step ?> of <?= count(INSTALL_STEPS) ?> &middot;
107 Delete the <code>install/</code> folder when you are finished.
108 </footer>
109</div>
110
111</body>
112</html>
113
Top