1<?php
2/**
3 * Title: Config values
4 * Icon: fa-wrench
5 * Group: Server Info
6 * Order: 11
7 * Description: Edit a single config.lua value without re-uploading the whole file.
8 * Hidden: true
9 */
10
11if (!defined('ACP_ROOT')) {
12 http_response_code(403);
13 die('Direct access denied.');
14}
15
16$whitelist = serverdata_config_whitelist();
17$current = serverdata_load('config');
18$current = is_array($current) ? $current : array();
19
20if (!$current) {
21 acp_flash_error(t_default('acp.cfged.no_data', 'Upload a config.lua on Server Info first - there is nothing published to edit yet.'));
22 acp_redirect('serverinfo');
23}
24
25if ($_SERVER['REQUEST_METHOD'] === 'POST') {
26 $adminName = (string)($GLOBALS['user_data']['name'] ?? '');
27 $changed = array();
28 $failed = false;
29
30 foreach ($whitelist as $key) {
31 if (!array_key_exists($key, $current)) {
32 continue;
33 }
34
35 $existing = $current[$key];
36 $posted = $_POST['cfg'][$key] ?? null;
37
38 if (is_bool($existing)) {
39 $value = !empty($posted);
40 } elseif (is_int($existing)) {
41 $value = intv($posted ?? 0);
42 } elseif (is_float($existing)) {
43 $value = (float)str_replace(',', '.', (string)($posted ?? 0));
44 } else {
45 $value = trim((string)($posted ?? ''));
46 }
47
48 if ($value !== $existing) {
49 if (serverdata_override_set('config', $key, ['value' => $value], $adminName)) {
50 $changed[] = $key;
51 } else {
52 $failed = true;
53 }
54 }
55 }
56
57 if ($changed) {
58 acp_log('serverdata.config_edit', implode(', ', $changed), ['keys' => $changed]);
59 acp_flash_success(t_default('acp.cfged.saved', '{n} value(s) updated.', ['n' => count($changed)]));
60 } elseif (!$failed) {
61 acp_flash_info(t_default('acp.cfged.nothing_changed', 'Nothing changed.'));
62 }
63
64 if ($failed) {
65 acp_flash_error(t_default('acp.cfged.save_failed', 'Some values could not be saved - run the pending database migration first (Admin Panel > Migrations).'));
66 }
67
68 acp_redirect('config_editor');
69}
70?>
71
72<?php acp_card_open(t_default('acp.cfged.title', 'Config values'), t_default('acp.cfged.sub', 'These change what is shown on the public server info page. Your OT server\'s own config.lua is never touched.')); ?>
73
74 <form method="post">
75 <?= acp_csrf_field() ?>
76 <div class="acp-table-wrap">
77 <table class="acp-table">
78 <thead>
79 <tr>
80 <th><?= t_default('acp.cfged.col_key', 'Key') ?></th>
81 <th><?= t_default('acp.cfged.col_value', 'Value') ?></th>
82 </tr>
83 </thead>
84 <tbody>
85 <?php foreach ($whitelist as $key): ?>
86 <?php if (!array_key_exists($key, $current)) continue; ?>
87 <?php $value = $current[$key]; ?>
88 <tr>
89 <td><code><?= h($key) ?></code></td>
90 <td>
91 <?php if (is_bool($value)): ?>
92 <label style="display:flex;align-items:center;gap:8px;font-weight:400;">
93 <input type="checkbox" name="cfg[<?= h($key) ?>]" value="1" <?= $value ? 'checked' : '' ?>>
94 <span class="is-muted"><?= t_default('acp.cfged.enabled', 'Enabled') ?></span>
95 </label>
96 <?php elseif (is_int($value) || is_float($value)): ?>
97 <input class="acp-input" type="number" step="<?= is_float($value) ? 'any' : '1' ?>" name="cfg[<?= h($key) ?>]" value="<?= h((string)$value) ?>">
98 <?php else: ?>
99 <input class="acp-input" type="text" name="cfg[<?= h($key) ?>]" value="<?= h((string)$value) ?>">
100 <?php endif; ?>
101 </td>
102 </tr>
103 <?php endforeach; ?>
104 </tbody>
105 </table>
106 </div>
107 <div class="acp-actions">
108 <button class="acp-btn acp-btn--green" type="submit"><i class="fa fa-check"></i> <?= t_default('acp.cfged.save_btn', 'Save') ?></button>
109 <a class="acp-btn acp-btn--ghost" href="<?= h(acp_url('serverinfo')) ?>"><?= t_default('acp.cfged.back', 'Back to Server Info') ?></a>
110 </div>
111 </form>
112
113<?php acp_card_close(); ?>
114