Skip to content

Commit aff1c87

Browse files
committed
10 Feb 2024
Updated installer - Added settings to append company information.
1 parent a426093 commit aff1c87

File tree

2 files changed

+72
-32
lines changed

2 files changed

+72
-32
lines changed

core/lib/CORE-Install-HTML.php

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,25 +151,31 @@
151151
</div>
152152
</div>
153153

154-
<!-- (C3-5) JWT -->
155-
<h4 class="text-danger mb-3">JSON WEB TOKEN</h4>
154+
<!-- (C3-5) COMPANY -->
155+
<?php if (I_CO) { ?>
156+
<h4 class="text-danger mb-3">COMPANY</h4>
156157
<div class="bg-light border p-3 mb-3">
157158
<div class="form-floating mb-2">
158-
<input type="text" name="jwtkey" class="form-control" required>
159-
<label>Secret Key</label>
159+
<input type="text" name="coname" class="form-control" required>
160+
<label>Company Name</label>
160161
</div>
161-
<div class="text-secondary mb-2" onclick="install.rnd()">
162-
* Click here to generate random key.
162+
163+
<div class="form-floating mb-2">
164+
<input type="text" name="coemail" class="form-control" required>
165+
<label>Company Email</label>
163166
</div>
164167

165168
<div class="form-floating mb-2">
166-
<input type="text" name="jwyiss" class="form-control" required value="<?=$_SERVER["HTTP_HOST"]?>">
167-
<label>Issuer</label>
169+
<input type="text" name="cotel" class="form-control" required>
170+
<label>Company Tel</label>
168171
</div>
169-
<div class="text-secondary">
170-
* Your company name or domain name.
172+
173+
<div class="form-floating mb-2">
174+
<textarea name="coaddr" class="form-control" required></textarea>
175+
<label>Company Address</label>
171176
</div>
172177
</div>
178+
<?php } ?>
173179

174180
<!-- (C3-6) ADMIN USER -->
175181
<?php if (I_USER) { ?>
@@ -181,7 +187,7 @@
181187
</div>
182188

183189
<div class="form-floating mb-2">
184-
<input type="text" name="aemail" class="form-control" required value="admin@site.com">
190+
<input type="text" name="aemail" class="form-control" required>
185191
<label>Email</label>
186192
</div>
187193

@@ -198,7 +204,27 @@
198204
</div>
199205
<?php } ?>
200206

201-
<!-- (C3-7) PUSH NOTIFICATION -->
207+
<!-- (C3-7) JWT -->
208+
<h4 class="text-danger mb-3">JSON WEB TOKEN</h4>
209+
<div class="bg-light border p-3 mb-3">
210+
<div class="form-floating mb-2">
211+
<input type="text" name="jwtkey" class="form-control" required>
212+
<label>Secret Key</label>
213+
</div>
214+
<div class="text-secondary mb-2" onclick="install.rnd()">
215+
* Click here to regenerate a random key.
216+
</div>
217+
218+
<div class="form-floating mb-2">
219+
<input type="text" name="jwyiss" class="form-control" required value="<?=$_SERVER["HTTP_HOST"]?>">
220+
<label>Issuer</label>
221+
</div>
222+
<div class="text-secondary">
223+
* Your company name or domain name.
224+
</div>
225+
</div>
226+
227+
<!-- (C3-8) PUSH NOTIFICATION -->
202228
<?php if (I_PUSH) { ?>
203229
<h4 class="text-danger mb-3">WEB PUSH VAPID KEYS</h4>
204230
<div class="bg-light border p-3 mb-3">
@@ -219,7 +245,7 @@
219245
</div>
220246
<?php } ?>
221247

222-
<!-- (C3-8) GO! -->
248+
<!-- (C3-9) GO! -->
223249
<input id="gobtn" type="submit" class="btn btn-primary" value="Go!" disabled>
224250
</form>
225251
</div></body>

core/lib/LIB-Install.php

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
<?php
22
// (PHASE A) BASE SETTINGS
3-
// (A1) MODULES
4-
define("I_USER", defined("USR_LVL")); // user module
5-
define("I_PUSH", defined("PUSH_PUBLIC")); // push notifications module
3+
// @TODO - ADD FILES, SQL, PHP VERSION, REQUIRED MODULES AS YOUR PROJECT NEEDS
64

7-
// (A2) FILES & FOLDERS THAT REQUIRE READ/WRITE PERMISSION
5+
// (A1) FILES & FOLDERS THAT REQUIRE READ/WRITE PERMISSION
86
define("I_ALL", [
9-
// @TODO - ADD AS REQUIRED
107
PATH_BASE, PATH_ASSETS, PATH_LIB, PATH_PAGES, // PATH_UPLOADS,
118
PATH_LIB . "CORE-Config.php",
129
PATH_BASE . "index.php",
1310
PATH_BASE . "CB-manifest.json"
1411
]);
1512

16-
// (A3) SQL FILES - FROM OLDEST TO NEWEST VERSIONS
17-
// @TODO - SET AS REQUIRED
13+
// (A2) SQL FILES - FROM OLDEST TO NEWEST VERSIONS
1814
define("I_SQL", ["SQL-CoreBoxx-1.sql"]);
1915

20-
// (A4) MINIMUM APACHE VERSION + PHP VERSION + EXTENSIONS
21-
define("I_MIN_PHP", "8.0.0");
22-
define("I_PDO", extension_loaded("pdo_mysql"));
23-
define("I_OPENSSL", extension_loaded("openssl"));
16+
// (A3) APACHE + PHP + EXTENSIONS
2417
define("I_APACHE", strpos(strtolower($_SERVER["SERVER_SOFTWARE"]), "apache")!==false);
18+
define("I_MIN_PHP", "8.0.0");
2519
define("I_REWRITE", I_APACHE && function_exists("apache_get_version")
2620
? in_array("mod_rewrite", apache_get_modules()) : false
2721
);
22+
define("I_PDO", extension_loaded("pdo_mysql"));
23+
define("I_OPENSSL", extension_loaded("openssl"));
24+
25+
// (A4) CORE BOXX MODULES & SETTINGS
26+
define("I_USER", defined("USR_LVL")); // user module
27+
define("I_PUSH", defined("PUSH_PUBLIC")); // push notifications module
28+
define("I_CO", false); // include company name, address, tel, email
2829

2930
class Install extends Core {
3031
// (PHASE B) BASE REQUIREMENTS & SYSTEM CHECK
@@ -108,7 +109,7 @@ function E2 () {
108109
exit($check=="installer/test/" ? "OK" : "INVALID HOST URL");
109110
}
110111

111-
// (PHASE F) VERIFY HTACCESS FILE + INSTALL
112+
// (PHASE F) INSTALL
112113
function F () {
113114
// (F1) ALLOWED API CORS DOMAINS
114115
if ($_POST["apicors"]==1 && $_POST["corsallow"]!="") {
@@ -166,7 +167,20 @@ function F () {
166167
exit("Error setting email from - " . $ex->getMessage());
167168
}
168169

169-
// (F6) CREATE ADMIN USER
170+
// (F6) COMPANY INFO
171+
if (I_CO) { try {
172+
$stmt = $pdo->prepare("REPLACE INTO `settings` (`setting_name`, `setting_description`, `setting_value`, `setting_group`) VALUES (?,?,?,?), (?,?,?,?), (?,?,?,?), (?,?,?,?)");
173+
$stmt->execute([
174+
"CO_NAME", "Company Name", $_POST["coname"], 1,
175+
"CO_EMAIL", "Company Email", $_POST["coemail"], 1,
176+
"CO_TEL", "Company Telephone", $_POST["cotel"], 1,
177+
"CO_ADDRESS", "Company Address", $_POST["coaddr"], 1
178+
]);
179+
} catch (Exception $ex) {
180+
exit("Error updating company info - " . $ex->getMessage());
181+
}}
182+
183+
// (F7) CREATE ADMIN USER
170184
if (I_USER) { try {
171185
$stmt = $pdo->prepare("REPLACE INTO `users` (`user_name`, `user_email`, `user_level`, `user_password`) VALUES (?,?,?,?)");
172186
$stmt->execute([$_POST["aname"], $_POST["aemail"], "A", password_hash($_POST["apass"], PASSWORD_DEFAULT)]);
@@ -175,13 +189,13 @@ function F () {
175189
}}
176190
$stmt = null; $pdo = null;
177191

178-
// (F7) TIMEZONE
192+
// (F8) TIMEZONE
179193
date_default_timezone_set($_POST["timezone"]);
180194
$now = ["o" => (new DateTime())->getOffset()];
181195
$now["h"] = floor(abs($now["o"]) / 3600);
182196
$now["m"] = floor((abs($now["o"]) - ($now["h"] * 3600)) / 60);
183197

184-
// (F8) CORE_CONFIG.PHP SETTINGS TO UPDATE
198+
// (F9) CORE_CONFIG.PHP SETTINGS TO UPDATE
185199
$hbase = ($_POST["https"]=="1" ? "https://" : "http://") . $_POST["host"];
186200
$hbase = rtrim($hbase, "/\\") . "/";
187201
$replace = [
@@ -205,12 +219,12 @@ function F () {
205219
}
206220
unset($_POST); unset($now); unset($hbase);
207221

208-
// (F9) BACKUP LIB/CORE-CONFIG.PHP
222+
// (F10) BACKUP LIB/CORE-CONFIG.PHP
209223
if (!copy(PATH_LIB . "CORE-Config.php", PATH_LIB . "CORE-Config.old")) {
210224
exit("Failed to backup config file - " . PATH_LIB . "CORE-Config.old");
211225
}
212226

213-
// (F10) UPDATE LIB/CORE-CONFIG.PHP
227+
// (F11) UPDATE LIB/CORE-CONFIG.PHP
214228
$cfg = file(PATH_LIB . "CORE-Config.php") or exit("Cannot read". PATH_LIB ."CORE-Config.php");
215229
foreach ($cfg as $j=>$line) { foreach ($replace as $k=>$v) { if (strpos($line, "\"$k\"") !== false) {
216230
if ($k!="API_HTTPS" && $k!="API_CORS") { $v = "\"$v\""; }
@@ -221,7 +235,7 @@ function F () {
221235
try { file_put_contents(PATH_LIB . "CORE-Config.php", implode("", $cfg)); }
222236
catch (Exception $ex) { exit("Error writing to ". PATH_LIB ."CORE-Config.php"); }
223237

224-
// (F11) ALMOST DONE...
238+
// (F12) ALMOST DONE...
225239
return "G";
226240
}
227241

@@ -243,4 +257,4 @@ function G () {
243257
if (defined("I_RELOAD")) { $this->Core->redirect(); }
244258
exit("OK");
245259
}
246-
}
260+
}

0 commit comments

Comments
 (0)