6.php

main 158 lines · 5.9 KB Raw
Alex Alex Commit Initial commit 01/10/2026 09:20
1<?php
2/**
3 * Step 6 - write the configuration and lock the installer.
4 *
5 * The generated values go to config.local.php, which config.php includes at
6 * the end. config.php is never rewritten: it stays the documented default file
7 * you can update with a new ZnoteX release without losing your settings, and
8 * a 1000-line file edited by regular expression is a file waiting to break.
9 */
10
11if (!defined('ZNOTE_INSTALL')) { http_response_code(403); die('Direct access denied.'); }
12
13/**
14 * The file we are about to write, also shown for manual copying.
15 */
16function install_config_contents(): string {
17 $quote = static function (string $value): string {
18 return "'" . str_replace(array('\\', "'"), array('\\\\', "\\'"), $value) . "'";
19 };
20
21 $admin = (string)install_get('admin_account');
22 $nl = "\n";
23
24 $out = '<?php' . $nl;
25 $out .= '/**' . $nl;
26 $out .= ' * Written by the ZnoteX installer.' . $nl;
27 $out .= ' *' . $nl;
28 $out .= ' * config.php is included first and holds every default; this file overrides the' . $nl;
29 $out .= ' * handful of values specific to this install. Updating ZnoteX therefore means' . $nl;
30 $out .= ' * replacing config.php and leaving this file alone.' . $nl;
31 $out .= ' *' . $nl;
32 $out .= ' * Most other settings are editable from Admin Panel > Settings.' . $nl;
33 $out .= ' */' . $nl . $nl;
34
35 $out .= '$config[\'sqlHost\'] = ' . $quote((string)install_get('sqlHost')) . ';' . $nl;
36 $out .= '$config[\'sqlUser\'] = ' . $quote((string)install_get('sqlUser')) . ';' . $nl;
37 $out .= '$config[\'sqlPassword\'] = ' . $quote((string)install_get('sqlPassword')) . ';' . $nl;
38 $out .= '$config[\'sqlDatabase\'] = ' . $quote((string)install_get('sqlDatabase')) . ';' . $nl . $nl;
39
40 $out .= '$config[\'ServerEngine\'] = ' . $quote((string)install_get('ServerEngine', 'TFS_10')) . ';' . $nl;
41 $out .= '$config[\'site_title\'] = ' . $quote((string)install_get('site_title')) . ';' . $nl;
42 $out .= '$config[\'site_url\'] = ' . $quote((string)install_get('site_url')) . ';' . $nl;
43
44 $path = (string)install_get('server_path');
45 if ($path !== '') {
46 $out .= '$config[\'server_path\'] = ' . $quote($path) . ';' . $nl;
47 }
48
49 $out .= $nl . '// Admin access is granted by account name.' . $nl;
50 $out .= '$config[\'page_admin_access\'] = array(' . $nl;
51 $out .= "\t" . $quote($admin) . ',' . $nl;
52 $out .= ');' . $nl;
53
54 return $out;
55}
56
57$written = false;
58$writeErr = '';
59
60$contents = install_config_contents();
61
62if ($_SERVER['REQUEST_METHOD'] === 'POST') {
63 $target = install_config_file();
64
65 if (@file_put_contents($target, $contents) === false) {
66 $writeErr = 'Could not write ' . $target . '. Create it by hand with the contents below.';
67 } else {
68 $written = true;
69
70 // The lock. Written last, so a failed write above does not lock a site
71 // that is not actually configured.
72 @file_put_contents(install_lock_file(),
73 "Installed on " . date('Y-m-d H:i:s') . "\n"
74 . "Delete this file only if you mean to run the installer again.\n");
75
76 install_reset();
77 }
78}
79?>
80<h1><?= $written ? 'Installed' : 'Finish' ?></h1>
81
82<?php if ($written): ?>
83
84 <p class="good">
85 ZnoteX is installed. <code>config.local.php</code> is written and the installer is locked.
86 </p>
87
88 <h2>Before you open the site</h2>
89 <p class="lead">
90 Vocations, starting towns and starting skills come pre-filled with generic defaults.
91 Most servers change at least some of this before letting anyone create a character -
92 it is much less painful to set it now than after players have already made characters.
93 </p>
94 <ul class="checks">
95 <li>
96 <span class="state opt">1</span>
97 <span class="what">
98 Configure vocations, towns &amp; starting skills
99 <span class="detail">Admin Panel &rarr; Settings &rarr; Character creation. Each one is an editable table now, no JSON to hand-edit.</span>
100 </span>
101 </li>
102 <li>
103 <span class="state opt">2</span>
104 <span class="what">
105 Delete the <code>install/</code> folder
106 <span class="detail">It refuses to run now, but there is no reason to leave it on a public server.</span>
107 </span>
108 </li>
109 <li>
110 <span class="state opt">3</span>
111 <span class="what">
112 Look around the rest of the panel
113 <span class="detail">Admin Panel &rarr; Settings covers almost everything else you would otherwise edit by hand.</span>
114 </span>
115 </li>
116 </ul>
117
118 <div class="actions">
119 <a class="btn green" href="../admin/index.php?p=settings#character-creation">Configure vocations &amp; towns</a>
120 <a class="btn ghost" href="../admin/index.php">Admin panel</a>
121 <a class="btn ghost" href="../index.php">Open the site</a>
122 </div>
123
124<?php else: ?>
125
126 <p class="lead">Review what will be written, then finish.</p>
127
128 <table>
129 <tr><th>Setting</th><th>Value</th></tr>
130 <tr><td>Database</td><td><code><?= ih(install_get('sqlUser')) ?>@<?= ih(install_get('sqlHost')) ?> / <?= ih(install_get('sqlDatabase')) ?></code></td></tr>
131 <tr><td>Server engine</td><td><code><?= ih(install_get('ServerEngine')) ?></code></td></tr>
132 <tr><td>Site name</td><td><?= ih(install_get('site_title')) ?></td></tr>
133 <tr><td>Site URL</td><td><?= ih(install_get('site_url')) ?></td></tr>
134 <tr><td>Administrator</td><td><?= ih(install_get('admin_account')) ?> <span class="detail">(account name &mdash; this is what grants panel access)</span></td></tr>
135 <tr><td>Character</td><td><?= ih(install_get('admin_character')) ?></td></tr>
136 </table>
137
138 <?php if ($writeErr !== ''): ?>
139 <p class="bad"><?= ih($writeErr) ?></p>
140 <h2>Create config.local.php yourself</h2>
141 <p>Put this in the ZnoteX root, next to <code>config.php</code>:</p>
142 <pre><code><?= ih($contents) ?></code></pre>
143 <?php endif; ?>
144
145 <div class="info">
146 These go to <code>config.local.php</code>. Your <code>config.php</code> is left untouched,
147 so a future ZnoteX update can replace it without losing anything.
148 </div>
149
150 <form method="post">
151 <div class="actions">
152 <button class="btn green" type="submit">Write the config and finish</button>
153 <a class="btn ghost" href="<?= install_url(5) ?>">Back</a>
154 </div>
155 </form>
156
157<?php endif; ?>
158
Top