update install file
This commit is contained in:
parent
9a5d45c4c5
commit
f49527d7c4
44
install.php
44
install.php
@ -44,7 +44,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
|
||||||
$pdo->exec("CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
|
$pdo->exec("CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
|
||||||
$pdo->exec("USE `$name` text");
|
$pdo->exec("USE `$name` ");
|
||||||
|
|
||||||
// Read existing helpers from current config if it exists
|
// Read existing helpers from current config if it exists
|
||||||
$helpers = '';
|
$helpers = '';
|
||||||
@ -60,23 +60,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
if (empty($helpers)) {
|
if (empty($helpers)) {
|
||||||
$helpers = "
|
$helpers = "
|
||||||
function check_permission(\$page = null, \$user_id = null) {
|
function check_permission(\$page = null, \$user_id = null) {
|
||||||
if (!\$user_id) \$user_id = \$_SESSION['user_id'] ?? null;
|
if (!\$user_id) \$user_id =
eg_SESSION['user_id'] ?? null;
|
||||||
if (!\$page) \$page = basename(\$_SERVER['PHP_SELF']);
|
if (!\$page) \$page = basename(
eg_SERVER['PHP_SELF']);
|
||||||
if (!\$user_id) return ['view' => 0, 'add' => 0, 'edit' => 0, 'delete' => 0];
|
if (!\$user_id) return ['view' => 0, 'add' => 0, 'edit' => 0, 'delete' => 0];
|
||||||
static \$permissions_cache = [];
|
static \$permissions_cache = [];
|
||||||
\$cache_key = \$user_id . '_' . \$page;
|
\$cache_key = \$user_id . '_' . \$page;
|
||||||
if (isset(\$permissions_cache[\$cache_key])) return \$permissions_cache[\$cache_key];
|
if (isset(
eg_permissions_cache[\$cache_key])) return \$permissions_cache[\$cache_key];
|
||||||
\$stmt = db()->prepare(\"SELECT can_view as view, can_add as `add`, can_edit as edit, can_delete as `delete` FROM user_permissions WHERE user_id = ? AND page = ?\");
|
\$stmt = db()->prepare(\"SELECT can_view as view, can_add as `add`, can_edit as edit, can_delete as `delete` FROM user_permissions WHERE user_id = ? AND page = ?\");
|
||||||
\$stmt->execute([\$user_id, \$page]);
|
\$stmt->execute([\$user_id, \$page]);
|
||||||
\$perms = \$stmt->fetch();
|
\$perms = \$stmt->fetch();
|
||||||
if (!\$perms) return ['view' => 0, 'add' => 0, 'edit' => 0, 'delete' => 0];
|
if (!\$perms) return ['view' => 0, 'add' => 0, 'edit' => 0, 'delete' => 0];
|
||||||
\$result = ['view' => (int)\$perms['view'], 'add' => (int)\$perms['add'], 'edit' => (int)\$perms['edit'], 'delete' => (int)\$perms['delete']];
|
\$result = ['view' => (int)
eg_perms['view'], 'add' => (int)
eg_perms['add'], 'edit' => (int)
eg_perms['edit'], 'delete' => (int)
eg_perms['delete']];
|
||||||
\$permissions_cache[\$cache_key] = \$result;
|
\$permissions_cache[\$cache_key] = \$result;
|
||||||
return \$result;
|
return \$result;
|
||||||
}
|
}
|
||||||
function has_permission(\$action, \$page = null, \$user_id = null) {
|
function has_permission(\$action, \$page = null, \$user_id = null) {
|
||||||
\$perms = check_permission(\$page, \$user_id);
|
\$perms = check_permission(
eg_page, \$user_id);
|
||||||
return !empty(\$perms[\$action]);
|
return !empty(
eg_perms[\$action]);
|
||||||
}";
|
}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,8 @@ function has_permission(\$action, \$page = null, \$user_id = null) {
|
|||||||
. "define('DB_USER', '$user');\n"
|
. "define('DB_USER', '$user');\n"
|
||||||
. "define('DB_PASS', '$pass');\n\n"
|
. "define('DB_PASS', '$pass');\n\n"
|
||||||
. "function db() {\n"
|
. "function db() {\n"
|
||||||
. " static \$pdo;\n"
|
. " static \$pdo;
|
||||||
|
"
|
||||||
. " if (!\$pdo) {\n"
|
. " if (!\$pdo) {\n"
|
||||||
. " \$pdo = new PDO(\"mysql:host=\" . DB_HOST . \";dbname=\" . DB_NAME . \";charset=utf8mb4\", DB_USER, DB_PASS, [\n"
|
. " \$pdo = new PDO(\"mysql:host=\" . DB_HOST . \";dbname=\" . DB_NAME . \";charset=utf8mb4\", DB_USER, DB_PASS, [\n"
|
||||||
. " PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,\n"
|
. " PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,\n"
|
||||||
@ -199,22 +200,28 @@ $envReady = !in_array(false, $checks, true);
|
|||||||
<?php if ($step === 1): ?>
|
<?php if ($step === 1): ?>
|
||||||
<h5>Checking Environment</h5>
|
<h5>Checking Environment</h5>
|
||||||
<div class="list-group list-group-flush mb-4 border rounded-3 overflow-hidden">
|
<div class="list-group list-group-flush mb-4 border rounded-3 overflow-hidden">
|
||||||
<?php foreach ($checks as $label => $pass): ?>
|
<?php foreach ($checks as $label => $pass):
|
||||||
|
?>
|
||||||
<div class="list-group-item d-flex justify-content-between align-items-center py-3">
|
<div class="list-group-item d-flex justify-content-between align-items-center py-3">
|
||||||
<span class="text-secondary"><?php echo $label; ?></span>
|
<span class="text-secondary"><?php echo $label; ?></span>
|
||||||
<?php if ($pass): ?>
|
<?php if ($pass):
|
||||||
|
?>
|
||||||
<span class="badge bg-success-subtle text-success px-3 py-2 rounded-pill">Passed</span>
|
<span class="badge bg-success-subtle text-success px-3 py-2 rounded-pill">Passed</span>
|
||||||
<?php else: ?>
|
<?php else:
|
||||||
|
?>
|
||||||
<span class="badge bg-danger-subtle text-danger px-3 py-2 rounded-pill">Failed</span>
|
<span class="badge bg-danger-subtle text-danger px-3 py-2 rounded-pill">Failed</span>
|
||||||
<?php endif; ?>
|
<?php endif;
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach;
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-grid">
|
<div class="d-grid">
|
||||||
<a href="?step=2" class="btn btn-primary <?php echo !$envReady ? 'disabled' : ''; ?>">Continue to Database</a>
|
<a href="?step=2" class="btn btn-primary <?php echo !$envReady ? 'disabled' : ''; ?>">Continue to Database</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php elseif ($step === 2): ?>
|
<?php elseif ($step === 2):
|
||||||
|
?>
|
||||||
<h5>Database Configuration</h5>
|
<h5>Database Configuration</h5>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
@ -240,7 +247,8 @@ $envReady = !in_array(false, $checks, true);
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php elseif ($step === 3): ?>
|
<?php elseif ($step === 3):
|
||||||
|
?>
|
||||||
<h5>Administrator Account</h5>
|
<h5>Administrator Account</h5>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
@ -260,7 +268,8 @@ $envReady = !in_array(false, $checks, true);
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php elseif ($step === 4): ?>
|
<?php elseif ($step === 4):
|
||||||
|
?>
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<div class="bg-success-subtle text-success d-inline-flex align-items-center justify-content-center rounded-circle" style="width: 80px; height: 80px;">
|
<div class="bg-success-subtle text-success d-inline-flex align-items-center justify-content-center rounded-circle" style="width: 80px; height: 80px;">
|
||||||
@ -277,7 +286,8 @@ $envReady = !in_array(false, $checks, true);
|
|||||||
<p class="small text-danger mt-3">Warning: Delete install.php for production security.</p>
|
<p class="small text-danger mt-3">Warning: Delete install.php for production security.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif;
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user