Repositories | Polyback | Log in to see private repositories
3,363 bytes | parent directory
<?php require $_SERVER['DOCUMENT_ROOT'].'/api/private/core.php';
// The ROBLOX token (.ROBLOSECURITY) the site fetches item details with. Super admins store or
// remove it; it's never shown again. /admin/roblox-token
use pizzaboxer\ProjectPolygon\Archive;
use pizzaboxer\ProjectPolygon\Database;
use pizzaboxer\ProjectPolygon\PageBuilder;
use pizzaboxer\ProjectPolygon\Users;
Users::RequireAdmin(Users::STAFF_SUPERADMIN);
$Error = $Success = false;
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (!is_string($_POST["polygon_csrf"] ?? null) || !hash_equals((string) SESSION["csrfToken"], $_POST["polygon_csrf"])) die(http_response_code(403));
if (isset($_POST["remove"]))
{
Database::singleton()->run("DELETE FROM SiteSecrets WHERE Name = 'RobloxToken'");
Users::LogStaffAction("[ Roblox token ] Removed the stored ROBLOX token");
$Success = "Removed";
}
else
{
$token = trim((string) ($_POST["token"] ?? ""));
if (str_starts_with($token, ".ROBLOSECURITY=")) $token = substr($token, strlen(".ROBLOSECURITY="));
if (strlen($token) < 100 || strlen($token) > 4096 || !preg_match('/^[\x21-\x7e]+$/', $token)) $Error = "That doesn't look like a .ROBLOSECURITY token";
else
{
Database::singleton()->run(
"INSERT INTO SiteSecrets (Name, Value, SetBy, SetAt) VALUES ('RobloxToken', :v, :u, UNIX_TIMESTAMP())
ON DUPLICATE KEY UPDATE Value = VALUES(Value), SetBy = VALUES(SetBy), SetAt = VALUES(SetAt)",
[":v" => $token, ":u" => SESSION["user"]["id"]]
);
Users::LogStaffAction("[ Roblox token ] Stored a ROBLOX token");
$Success = "Stored";
}
}
}
$Info = Archive::RobloxTokenInfo();
$csrf = '<input type="hidden" name="polygon_csrf" value="' . htmlspecialchars(SESSION["csrfToken"]) . '">';
$pageBuilder = new PageBuilder(["title" => "ROBLOX token"]);
$pageBuilder->buildHeader();
?>
<h2 class="font-weight-normal">ROBLOX token</h2>
<p>The .ROBLOSECURITY token the site uses to fetch items' names and descriptions from ROBLOX (the <b>Fetch from ROBLOX</b> button when selling from the archive). Every administrator's fetches use it; only super admins can store or remove it, and it's never shown again. Use an account made for this, not your own.</p>
<?php if ($Error) { ?><div class="alert alert-danger px-2 py-1" role="alert"><?=htmlspecialchars($Error)?></div><?php } ?>
<?php if ($Success) { ?><div class="alert alert-success px-2 py-1" role="alert"><?=htmlspecialchars($Success)?></div><?php } ?>
<p><?php if ($Info) { ?>A token is stored, set <?=date("j M Y H:i", (int) $Info->SetAt)?> by <?=htmlspecialchars((string) $Info->username)?>.<?php } else { ?>No token is stored: fetching works for public items only.<?php } ?></p>
<form method="post" autocomplete="off" class="mb-3" style="max-width:40rem">
<?=$csrf?>
<div class="form-group"><label for="token"><?=$Info ? "Replace it with" : "Token"?>:</label>
<input type="password" class="form-control form-control-sm" id="token" name="token" autocomplete="new-password" placeholder="_|WARNING:-DO-NOT-SHARE-THIS..."></div>
<button class="btn btn-primary">Store</button>
</form>
<?php if ($Info) { ?>
<form method="post" onsubmit="return confirm('Remove the stored ROBLOX token?')"><?=$csrf?><input type="hidden" name="remove" value="1"><button class="btn btn-outline-danger btn-sm">Remove it</button></form>
<?php } ?>
<?php $pageBuilder->buildFooter(); ?>