diff options
| author | ilotterytea <iltsu@alright.party> | 2025-12-09 01:43:12 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-12-09 01:43:12 +0500 |
| commit | 29477e67ede12347b153e2255325327374e1b073 (patch) | |
| tree | be9170a20d332eab1fcc8b380f70f231921aac45 /system | |
| parent | 28bb4f3618e2e947d14a05a24e99d826c26c0ce3 (diff) | |
feat: new configuration
Diffstat (limited to 'system')
| -rw-r--r-- | system/config.php | 430 | ||||
| -rw-r--r-- | system/emotes/index.php | 10 | ||||
| -rw-r--r-- | system/emotes/verdict.php | 4 | ||||
| -rw-r--r-- | system/index.php | 10 |
4 files changed, 442 insertions, 12 deletions
diff --git a/system/config.php b/system/config.php new file mode 100644 index 0000000..4144b93 --- /dev/null +++ b/system/config.php @@ -0,0 +1,430 @@ +<?php +include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/config.php"; +include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/partials.php"; +include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/alert.php"; +include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/accounts.php"; + +if (file_exists(CFG_PATH) && !authorize_user(true) && !isset($_SESSION['user_role']['permission_admin'])) { + generate_alert('/', 'Unauthorized', 401); + exit(); +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $c = CONFIG; + $c['rating']['names'] = $c['rating']['names_string']; + unset($c['rating']['names_string']); + + // setting all checkboxes to false + foreach ($c as $sk => $sv) { + foreach ($sv as $k => &$v) { + if (is_bool($v) && !array_key_exists("{$sk}_$k", $_POST)) { + $c[$sk][$k] = false; + } + } + unset($v); + } + + foreach ($_POST as $k => $v) { + $parts = explode('_', $k); + $part_count = count($parts); + if ($part_count != 2) { + continue; + } + $section = $parts[0]; + $key = $parts[1]; + + if (!array_key_exists($section, $c)) { + $c[$section] = []; + } + + if ($v === 'on') { + $v = true; + } + + if (is_numeric($v)) { + $v += 0; + } + + $c[$section][$key] = $v; + } + + if (!file_put_contents(CFG_PATH, json_encode($c, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT))) { + http_response_code(500); + exit("Failed to write the configuration file."); + } + + generate_alert('/system/config.php', 'Saved!', 200); + exit(); +} + +?> +<html> + +<head> + <title>Configuration - <?= CONFIG['instance']['name'] ?></title> + <link rel="stylesheet" href="/static/style.css"> + <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"> +</head> + +<body> + <div class="container"> + <div class="wrapper"> + <?php html_navigation_bar() ?> + <section class="content"> + <h1>Instance configuration</h1> + <?php if (!file_exists(CFG_PATH)): ?> + <div class="box"> + <p>This message confirms the instance is nearly ready. The configuration below shows the default + settings. Enter your database credentials to complete the setup.</p> + </div> + <?php endif; ?> + <form action="/system/config.php" method="post"> + <div class="box"> + <div class="box navtab"> + <p>Instance</p> + </div> + <div class="box content"> + <table class="vertical left"> + <tr> + <th>Name</th> + <td><input type="text" name="instance_name" + value="<?= CONFIG['instance']['name'] ?>"></td> + </tr> + </table> + </div> + </div> + + <div class="box"> + <div class="box navtab"> + <p>Database</p> + </div> + <div class="box content"> + <table class="vertical left"> + <tr> + <th>Name</th> + <td><input type="text" name="database_name" + value="<?= CONFIG['database']['name'] ?>" required></td> + </tr> + <tr> + <th>User</th> + <td><input type="text" name="database_user" + value="<?= CONFIG['database']['user'] ?>" required></td> + </tr> + <tr> + <th>Password</th> + <td><input type="password" name="database_pass" + value="<?= CONFIG['database']['pass'] ?>" required></td> + </tr> + <tr> + <th>Host</th> + <td><input type="text" name="database_host" + value="<?= CONFIG['database']['host'] ?>" required></td> + </tr> + </table> + </div> + </div> + + <div class="box"> + <div class="box navtab"> + <p>Emotes</p> + </div> + <div class="box content"> + <table class="vertical left"> + <tr> + <th>Allow emote upload</th> + <td><input type="checkbox" name="emote_upload" value="on" + <?= CONFIG['emote']['upload'] ? 'checked' : '' ?>></td> + </tr> + <tr> + <th>Allow anonymous emote upload</th> + <td><input type="checkbox" name="anonymous_upload" value="on" + <?= CONFIG['anonymous']['upload'] ? 'checked' : '' ?>></td> + </tr> + <tr> + <th>Default uploader name</th> + <td><input type="text" name="anonymous_defaultname" + value="<?= CONFIG['anonymous']['defaultname'] ?>"></td> + </tr> + <tr> + <th>RegEx filter for names</th> + <td><input type="text" name="emote_nameregex" + value="<?= CONFIG['emote']['nameregex'] ?>"></td> + </tr> + <tr> + <th>Default visibility</th> + <td> + <select name="emote_defaultvisibility"> + <option value="0" <?= CONFIG['emote']['defaultvisibility'] == 0 ? 'selected' : '' ?>>Unlisted</option> + <option value="on" <?= CONFIG['emote']['defaultvisibility'] == 1 ? 'selected' : '' ?>>Public</option> + <option value="2" <?= CONFIG['emote']['defaultvisibility'] == 2 ? 'selected' : '' ?>>Pending approval</option> + </select> + </td> + </tr> + <tr> + <th>Max name length</th> + <td><input type="number" name="emote_maxnamelength" + value="<?= CONFIG['emote']['maxnamelength'] ?>"></td> + </tr> + <tr> + <th>Max comment length</th> + <td><input type="number" name="emote_maxcommentlength" + value="<?= CONFIG['emote']['maxcommentlength'] ?>"></td> + </tr> + <tr> + <th>Max size</th> + <td>X: <input type="number" name="emote_maxsizex" + value="<?= CONFIG['emote']['maxsizex'] ?>"> Y: + <input type="number" name="emote_maxsizey" + value="<?= CONFIG['emote']['maxsizey'] ?>"> + </td> + </tr> + <tr> + <th>Store original uploaded file</th> + <td><input type="checkbox" name="emote_storeoriginal" value="on" + <?= CONFIG['emote']['storeoriginal'] ? 'checked' : '' ?>></td> + </tr> + </table> + </div> + </div> + + <div class="box"> + <div class="box navtab"> + <p>Accounts</p> + </div> + <div class="box content"> + <table class="vertical left"> + <tr> + <th>Enable account registration</th> + <td><input type="checkbox" name="account_registration" value="on" + <?= CONFIG['account']['registration'] ? 'checked' : '' ?>></td> + </tr> + <tr> + <th>Max. cookie lifetime <i>(in seconds)</i></th> + <td><input type="number" name="account_maxcookielifetime" + value="<?= CONFIG['account']['maxcookielifetime'] ?>"></td> + </tr> + <tr> + <th>RegEx filter for usernames</th> + <td><input type="text" name="account_regex" + value="<?= CONFIG['account']['regex'] ?>"></td> + </tr> + <tr> + <th>Username length</th> + <td>Min: <input type="number" name="account_minusernamelength" + value="<?= CONFIG['account']['minusernamelength'] ?>"> + Max: <input type="number" name="account_maxusernamelength" + value="<?= CONFIG['account']['maxusernamelength'] ?>"></td> + </tr> + <tr> + <th>Min. password length</th> + <td><input type="number" name="account_minpasswordlength" + value="<?= CONFIG['account']['minpasswordlength'] ?>"></td> + </tr> + <tr> + <th>Secret key length</th> + <td><input type="number" name="account_secretkeylength" + value="<?= CONFIG['account']['secretkeylength'] ?>"></td> + </tr> + <tr> + <th>Profile picture size</th> + <td>X: <input type="number" name="account_pfpsizex" + value="<?= CONFIG['account']['pfpsizex'] ?>"> + Y: <input type="number" name="account_pfpsizey" + value="<?= CONFIG['account']['pfpsizey'] ?>"></td> + </tr> + <tr> + <th>Profile banner size</th> + <td>X: <input type="number" name="account_bannersizex" + value="<?= CONFIG['account']['bannersizex'] ?>"> + Y: <input type="number" name="account_bannersizey" + value="<?= CONFIG['account']['bannersizey'] ?>"></td> + </tr> + <tr> + <th>Badge size</th> + <td>X: <input type="number" name="account_badgesizex" + value="<?= CONFIG['account']['badgesizex'] ?>"> + Y: <input type="number" name="account_badgesizey" + value="<?= CONFIG['account']['badgesizey'] ?>"></td> + </tr> + <tr> + <th>Enable public list</th> + <td><input type="checkbox" name="account_publiclist" value="on" + <?= CONFIG['account']['publiclist'] ? 'checked' : '' ?>></td> + </tr> + <tr> + <th>Log actions</th> + <td><input type="checkbox" name="account_log" value="on" <?= CONFIG['account']['log'] ? 'checked' : '' ?>></td> + </tr> + </table> + </div> + </div> + + <div class="box"> + <div class="box navtab"> + <p>Twitch</p> + </div> + <div class="box content"> + <table class="vertical left"> + <tr> + <th>Enable account registration via Twitch</th> + <td><input type="checkbox" name="twitch_registration" + <?= CONFIG['twitch']['registration'] ? 'checked' : '' ?> value="on"> + </td> + </tr> + <tr> + <th>Client ID</th> + <td><input type="text" name="twitch_clientid" + value="<?= CONFIG['twitch']['clientid'] ?>"> + </td> + </tr> + <tr> + <th>Client secret</th> + <td><input type="password" name="twitch_clientsecret" + value="<?= CONFIG['twitch']['clientsecret'] ?>"> + </td> + </tr> + <tr> + <th>Redirect URI</th> + <td><input type="url" name="twitch_redirecturi" + value="<?= CONFIG['twitch']['redirecturi'] ?>"> + </td> + </tr> + </table> + </div> + </div> + + <div class="box"> + <div class="box navtab"> + <p>CAPTCHA</p> + </div> + <div class="box content"> + <table class="vertical left"> + <tr> + <th>Enable CAPTCHA</th> + <td><input type="checkbox" name="captcha_enable" <?= CONFIG['captcha']['enable'] ? 'checked' : '' ?> value="on"> + </td> + </tr> + <tr> + <th>Force authorized users to solve CAPTCHA</th> + <td><input type="checkbox" name="captcha_force" <?= CONFIG['captcha']['force'] ? 'checked' : '' ?> value="on"> + </td> + </tr> + <tr> + <th>Size</th> + <td>Min: <input type="number" name="captcha_x" + value="<?= CONFIG['captcha']['x'] ?>"> + Max: <input type="number" name="captcha_y" + value="<?= CONFIG['captcha']['y'] ?>"></td> + </tr> + </table> + </div> + </div> + + <div class="box"> + <div class="box navtab"> + <p>Rating</p> + </div> + <div class="box content"> + <table class="vertical left"> + <tr> + <th>Enable rating</th> + <td><input type="checkbox" name="rating_enable" <?= CONFIG['rating']['enable'] ? 'checked' : '' ?> value="on"> + </td> + </tr> + <tr> + <th>Names<sup title="The schema is ['id/rating_point' => 'name']">[?]</sup></th> + <td><textarea name="rating_names"><?= CONFIG['rating']['names_string'] ?></textarea> + </td> + </tr> + <tr> + <th>Minimal amount of votes</th> + <td><input type="number" name="rating_minvotes" + value="<?= CONFIG['rating']['minvotes'] ?>"></td> + </tr> + </table> + </div> + </div> + + <div class="box"> + <div class="box navtab"> + <p>Tags</p> + </div> + <div class="box content"> + <table class="vertical left"> + <tr> + <th>Enable tags</th> + <td><input type="checkbox" name="tags_enable" <?= CONFIG['tags']['enable'] ? 'checked' : '' ?> value="on"> + </td> + </tr> + <tr> + <th>RegEx filter</th> + <td><input type="text" name="tags_regex" value="<?= CONFIG['tags']['regex'] ?>"> + </td> + </tr> + <tr> + <th>Maximum amount of tags per emote.</th> + <td><input type="number" name="tags_maxcount" + value="<?= CONFIG['tags']['maxcount'] ?>"></td> + </tr> + </table> + </div> + </div> + + <div class="box"> + <div class="box navtab"> + <p>Emotesets</p> + </div> + <div class="box content"> + <table class="vertical left"> + <tr> + <th>Show emotesets public</th> + <td><input type="checkbox" name="emoteset_public" <?= CONFIG['emoteset']['public'] ? 'checked' : '' ?> value="on"> + </td> + </tr> + </table> + </div> + </div> + + <div class="box"> + <div class="box navtab"> + <p>Moderation</p> + </div> + <div class="box content"> + <table class="vertical left"> + <tr> + <th>Enable system dashboard for moderators</th> + <td><input type="checkbox" name="mod_dashboard" <?= CONFIG['mod']['dashboard'] ? 'checked' : '' ?> value="on"> + </td> + </tr> + <tr> + <th>Enable manual emote approval</th> + <td><input type="checkbox" name="mod_approve" <?= CONFIG['mod']['approve'] ? 'checked' : '' ?> value="on"> + </td> + </tr> + </table> + </div> + </div> + + <div class="box"> + <div class="box navtab"> + <p>Reports</p> + </div> + <div class="box content"> + <table class="vertical left"> + <tr> + <th>Enable reports</th> + <td><input type="checkbox" name="reports_enable" <?= CONFIG['reports']['enable'] ? 'checked' : '' ?> value="on"> + </td> + </tr> + </table> + </div> + </div> + + <button type="submit">Save</button> + </form> + </section> + </div> + </div> +</body> + +</html>
\ No newline at end of file diff --git a/system/emotes/index.php b/system/emotes/index.php index d172482..79be71f 100644 --- a/system/emotes/index.php +++ b/system/emotes/index.php @@ -5,7 +5,7 @@ include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/alert.php"; include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/config.php"; include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/utils.php"; -if (!MOD_EMOTES_APPROVE) { +if (!CONFIG['mod']['approve']) { generate_alert("/404.php", "Manual emote approval is disabled", 405); exit; } @@ -17,7 +17,7 @@ if (!authorize_user(true) || !$_SESSION["user_role"]["permission_approve_emotes" $current_user_id = $_SESSION["user_id"] ?? ""; -$db = new PDO(DB_URL, DB_USER, DB_PASS); +$db = new PDO(CONFIG['database']['url'], CONFIG['database']['user'], CONFIG['database']['pass']); $emote_results = $db->prepare("SELECT e.*, CASE WHEN up.private_profile = FALSE OR up.id = ? THEN e.uploaded_by ELSE NULL END AS uploaded_by, CASE WHEN up.private_profile = FALSE OR up.id = ? THEN u.username ELSE NULL END AS uploader_name, @@ -65,7 +65,7 @@ if (isset($_GET["id"])) { <html> <head> - <title>System panel - <?php echo INSTANCE_NAME ?></title> + <title>System panel - <?php echo CONFIG['instance']['name'] ?></title> <link rel="stylesheet" href="/static/style.css"> <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"> </head> @@ -87,7 +87,7 @@ if (isset($_GET["id"])) { echo '<span style="font-size:10px;"> by '; if ($row["uploader_name"] == null) { - echo ANONYMOUS_DEFAULT_NAME . '*'; + echo CONFIG['anonymous']['defaultname'] . '*'; } else { echo $row["uploader_name"]; } @@ -174,7 +174,7 @@ if (isset($_GET["id"])) { <tr> <th>Uploader</th> <td><?php - $username = ANONYMOUS_DEFAULT_NAME; + $username = CONFIG['anonymous']['defaultname']; $link = "#"; if ($emote["uploader_name"] != null) { diff --git a/system/emotes/verdict.php b/system/emotes/verdict.php index 07e1300..2c53fd0 100644 --- a/system/emotes/verdict.php +++ b/system/emotes/verdict.php @@ -4,7 +4,7 @@ include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/accounts.php"; include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/config.php"; include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/utils.php"; -if (!MOD_EMOTES_APPROVE) { +if (!CONFIG['mod']['approve']) { generate_alert("/404.php", "Manual emote approval is disabled", 405); exit; } @@ -22,7 +22,7 @@ if (!isset($_POST["id"], $_POST["action"])) { $id = str_safe($_POST["id"], 32); $action = $_POST["action"]; -$db = new PDO(DB_URL, DB_USER, DB_PASS); +$db = new PDO(CONFIG['database']['url'], CONFIG['database']['user'], CONFIG['database']['pass']); $stmt = $db->prepare("SELECT id, code, uploaded_by FROM emotes WHERE id = ? AND visibility = 2 LIMIT 1"); $stmt->execute([$id]); diff --git a/system/index.php b/system/index.php index f5c1677..31291be 100644 --- a/system/index.php +++ b/system/index.php @@ -4,7 +4,7 @@ include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/accounts.php"; include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/alert.php"; include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/config.php"; -if (!MOD_SYSTEM_DASHBOARD) { +if (!CONFIG['mod']['dashboard']) { generate_alert("/404.php", "System dashboard is disabled", 405); exit; } @@ -14,14 +14,14 @@ if (!authorize_user(true) || (!$_SESSION["user_role"]["permission_approve_emotes exit; } -$db = new PDO(DB_URL, DB_USER, DB_PASS); +$db = new PDO(CONFIG['database']['url'], CONFIG['database']['user'], CONFIG['database']['pass']); ?> <html> <head> - <title>System panel - <?php echo INSTANCE_NAME ?></title> + <title>System panel - <?php echo CONFIG['instance']['name'] ?></title> <link rel="stylesheet" href="/static/style.css"> <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"> </head> @@ -35,7 +35,7 @@ $db = new PDO(DB_URL, DB_USER, DB_PASS); <div class="box navtab">System panel</div> <div class="box content"> <?php - if (MOD_EMOTES_APPROVE && $_SESSION["user_role"]["permission_approve_emotes"]) { + if (CONFIG['mod']['approve'] && $_SESSION["user_role"]["permission_approve_emotes"]) { echo '<a href="/system/emotes">Emotes'; $results = $db->query("SELECT COUNT(*) FROM emotes WHERE visibility = 2")->fetch()[0]; @@ -47,7 +47,7 @@ $db = new PDO(DB_URL, DB_USER, DB_PASS); echo '</a>'; } - if (REPORTS_ENABLE && $_SESSION["user_role"]["permission_report_review"]) { + if (CONFIG['reports']['enable'] && $_SESSION["user_role"]["permission_report_review"]) { echo '<a href="/system/reports">Reports'; $results = $db->query("SELECT COUNT(*) FROM reports WHERE resolved_by IS NULL")->fetch()[0]; |
