diff options
author | Minteck <nekostarfan@gmail.com> | 2021-08-24 15:37:01 +0200 |
---|---|---|
committer | Minteck <nekostarfan@gmail.com> | 2021-08-24 15:37:01 +0200 |
commit | e3298dbeaae79bb1d384fa8cd78a67be89819720 (patch) | |
tree | 871560e330f6c7225fb50ae86e3586776d81356a /online | |
download | kartik-net-e3298dbeaae79bb1d384fa8cd78a67be89819720.tar.gz kartik-net-e3298dbeaae79bb1d384fa8cd78a67be89819720.tar.bz2 kartik-net-e3298dbeaae79bb1d384fa8cd78a67be89819720.zip |
Initial commit
Diffstat (limited to 'online')
-rw-r--r-- | online/callback/index.php | 44 | ||||
-rw-r--r-- | online/callback_ig/index.php | 44 | ||||
-rw-r--r-- | online/index.php | 184 | ||||
-rw-r--r-- | online/ingame/allow/index.php | 16 | ||||
-rw-r--r-- | online/ingame/api/profile.level.php | 15 | ||||
-rw-r--r-- | online/ingame/api/profile.logout.php | 15 | ||||
-rw-r--r-- | online/ingame/api/profile.name.php | 11 | ||||
-rw-r--r-- | online/ingame/api/profile.picture.php | 11 | ||||
-rw-r--r-- | online/ingame/api/profile.stats.php | 15 | ||||
-rw-r--r-- | online/ingame/api/profile.token.php | 13 | ||||
-rw-r--r-- | online/ingame/api/set.level.php | 13 | ||||
-rw-r--r-- | online/ingame/api/set.stats.php | 13 | ||||
-rw-r--r-- | online/ingame/index.php | 74 | ||||
-rw-r--r-- | online/logout/confirm/index.php | 28 | ||||
-rw-r--r-- | online/logout/index.php | 85 | ||||
-rw-r--r-- | online/private/.htaccess | 3 | ||||
-rw-r--r-- | online/private/app.json | 4 | ||||
-rw-r--r-- | online/private/statsnames.json | 38 | ||||
-rw-r--r-- | online/session/index.php | 6 |
19 files changed, 632 insertions, 0 deletions
diff --git a/online/callback/index.php b/online/callback/index.php new file mode 100644 index 0000000..113a681 --- /dev/null +++ b/online/callback/index.php @@ -0,0 +1,44 @@ +<?php
+
+// TODO: handle errors
+
+if (!isset($_GET['code'])) {
+ die();
+}
+
+$appdata = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/app.json"), true);
+
+$crl = curl_init('https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/token');
+curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
+curl_setopt($crl, CURLINFO_HEADER_OUT, true);
+curl_setopt($crl, CURLOPT_POST, true);
+curl_setopt($crl, CURLOPT_HTTPHEADER, [
+ "Authorization: Basic " . base64_encode($appdata["id"] . ":" . $appdata["secret"]),
+ "Content-Type: application/x-www-form-urlencoded",
+ "Accept: application/json"
+]);
+curl_setopt($crl, CURLOPT_POSTFIELDS, "grant_type=authorization_code&redirect_uri=" . urlencode("https://kartik.hopto.org/online/callback") . "&code=" . $_GET['code']);
+
+$result = curl_exec($crl);
+$result = json_decode($result, true);
+
+curl_close($crl);
+
+if (isset($result["access_token"])) {
+ $crl = curl_init('https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/users/me');
+ curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($crl, CURLINFO_HEADER_OUT, true);
+ curl_setopt($crl, CURLOPT_HTTPHEADER, [
+ "Authorization: Bearer " . $result["access_token"],
+ "Accept: application/json"
+ ]);
+
+ $result = curl_exec($crl);
+ $result = json_decode($result, true);
+
+ $token = bin2hex(random_bytes(32));
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $token, json_encode($result));
+ setcookie("kartik_online_token", $token, strtotime('+365 days'), "/online", "", true, true);
+
+ header("Location: /online");
+}
\ No newline at end of file diff --git a/online/callback_ig/index.php b/online/callback_ig/index.php new file mode 100644 index 0000000..ab9456a --- /dev/null +++ b/online/callback_ig/index.php @@ -0,0 +1,44 @@ +<?php
+
+// TODO: handle errors
+
+if (!isset($_GET['code'])) {
+ die();
+}
+
+$appdata = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/app.json"), true);
+
+$crl = curl_init('https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/token');
+curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
+curl_setopt($crl, CURLINFO_HEADER_OUT, true);
+curl_setopt($crl, CURLOPT_POST, true);
+curl_setopt($crl, CURLOPT_HTTPHEADER, [
+ "Authorization: Basic " . base64_encode($appdata["id"] . ":" . $appdata["secret"]),
+ "Content-Type: application/x-www-form-urlencoded",
+ "Accept: application/json"
+]);
+curl_setopt($crl, CURLOPT_POSTFIELDS, "grant_type=authorization_code&redirect_uri=" . urlencode("https://kartik.hopto.org/online/callback_ig") . "&code=" . $_GET['code']);
+
+$result = curl_exec($crl);
+$result = json_decode($result, true);
+
+curl_close($crl);
+
+if (isset($result["access_token"])) {
+ $crl = curl_init('https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/users/me');
+ curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($crl, CURLINFO_HEADER_OUT, true);
+ curl_setopt($crl, CURLOPT_HTTPHEADER, [
+ "Authorization: Bearer " . $result["access_token"],
+ "Accept: application/json"
+ ]);
+
+ $result = curl_exec($crl);
+ $result = json_decode($result, true);
+
+ $token = bin2hex(random_bytes(32));
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $token, json_encode($result));
+ setcookie("kartik_online_token", $token, strtotime('+365 days'), "/online", "", true, true);
+
+ header("Location: /online/ingame");
+}
\ No newline at end of file diff --git a/online/index.php b/online/index.php new file mode 100644 index 0000000..27c277f --- /dev/null +++ b/online/index.php @@ -0,0 +1,184 @@ +<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/telemetry/private/dom.php";
+
+if (!isset($_COOKIE["kartik_online_token"])) {
+ header("Location: https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/auth?client_id=2d3ca3a8-38b7-4193-990a-a9454bb8d44c&response_type=code&redirect_uri=https://kartik.hopto.org/online/callback&scope=hub&request_credentials=default&access_type=offline");
+ die();
+} else if (ctype_xdigit($_COOKIE["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $_COOKIE['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $_COOKIE['kartik_online_token']), true);
+} else {
+ header("Location: https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/auth?client_id=2d3ca3a8-38b7-4193-990a-a9454bb8d44c&response_type=code&redirect_uri=https://kartik.hopto.org/online/callback&scope=hub&request_credentials=default&access_type=offline");
+ die();
+}
+
+function secondsToTime($seconds) {
+ $dtF = new \DateTime('@0');
+ $dtT = new \DateTime("@$seconds");
+
+ $hours = $dtF->diff($dtT)->format('%h');
+ $rest = $dtF->diff($dtT)->format("%i " . l("min, ", "mn, ") . " %s " . l("secs", "sec"));
+ $hours = ($dtF->diff($dtT)->format('%a') * $hours) . " " . l("hrs, ", "hr, ");
+
+ return $hours . $rest;
+}
+
+function l($fr, $en) {
+ if (isset($_GET['lang'])) {
+ if ($_GET['lang'] == "en") {
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en";
+ } else if ($_GET['lang'] == "fr") {
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "fr";
+ }
+ }
+ if (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) == "fr") {
+ return $fr;
+ } else {
+ return $en;
+ }
+}
+
+?>
+<!DOCTYPE html>
+<html lang="en" style="height:100%;">
+<head>
+ <meta charset="UTF-8">
+ <title>Kartik Online</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="icon" href="/static/favicon.png">
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
+ <link rel="stylesheet" href="/appsicons.css">
+ <style>
+ .col-sm-4 {
+ padding: 15px;
+ }
+ </style>
+</head>
+<body style="height:100%;">
+
+<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
+
+ <a class="navbar-brand" href="/">
+ <img src="/static/logo.png" alt="Kartik" style="height:32px;"><span style="vertical-align: middle;font-size: 14px;">Online</span>
+ </a>
+
+ <div class="collapse navbar-collapse" id="collapsibleNavbar">
+ <ul class="navbar-nav">
+ <li class="nav-item">
+ <a class="nav-link" href="/">← <?= l("Retourner au site de Kartik", "Go back to Kartik website") ?></a>
+ </li>
+ <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/apps.php"; ?>
+ </ul>
+ </div>
+</nav>
+
+<div id="separator"></div>
+
+<div class="container" style="margin-top:25px;">
+ <br>
+ <div class="alert alert-warning">
+ <b><?= l("Note :", "Notice:") ?></b> <?= l("Assurez-vous que vous disposez de la version 21.08.2 ou suivant de Kartik pour pouvoir utiliser les nouvelles fonctionnalités en ligne.", "Make sure you have Kartik version 21.08.2 or later to use the new online features.") ?>
+ </div>
+ <h2 style="text-align: center;"><?= l("Vous revoilà", "Welcome back") ?> <?= $_DATA["name"] ?><?= l(" !", "!") ?></h2>
+ <h4 style="text-align: center;"><?= l("Connectez-vous à ce compte Minteck Hub sur votre copie de Kartik pour accéder à plus de fonctionnalités en ligne.", "Log in to this Minteck Hub account on your copy of Kartik to get access to more online features.") ?></h4>
+
+ <div class="row">
+ <div class="col-sm-4">
+ <div class="card">
+ <div class="card-body">
+ <h5><?= l("Connexions", "Logins"); ?></h5>
+ <ul class="list-group">
+ <?php $connected = false; foreach (scandir($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens") as $token): ?>
+ <?php if (trim($token) !== "." && trim($token) !== ".." && json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $token), true)["id"] === $_DATA["id"]): ?>
+ <?php $connected = true; ?>
+ <li class="list-group-item">
+ <code><?= substr($token, 0, 8) ?></code>
+ <a href="/online/logout/?_=<?= substr($token, 0, 20) ?>" style="float:right;"><?= l("Déconnecter", "Logout") ?></a>
+ </li>
+ <?php endif;endforeach; ?>
+ </ul>
+ <?php if (!$connected): ?>
+ <p style="text-align: center;"><i><?= l("Après vous être connecté à votre compte sur votre copie de Kartik, vous avez la possibilité de vous déconnecter à partir d'ici.", "After logging into your account from your copy of Kartik, you have the choice to log out from here.") ?></i></p>
+ <?php endif; ?>
+ </div>
+ </div>
+ </div>
+ <div class="col-sm-4">
+ <div class="card">
+ <div class="card-body">
+ <h5><?= l("Statistiques", "Statistics"); ?></h5>
+ <?php $prettynames = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/statsnames.json"), true); if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/stats/" . $_DATA["id"])): ?>
+ <?php
+
+ // Calculate insights
+ $stats = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/stats/" . $_DATA["id"]), true);
+ $totalTimes = $stats["times"]["single"] + $stats["times"]["local"] + $stats["times"]["online"];
+
+ $stats["results"]["total"] = $stats["results"]["wins"] + $stats["results"]["loses"];
+
+ ?>
+ <ul class="list-group">
+ <?php foreach($stats as $category => $items): ?>
+ <?php foreach($items as $item => $value): ?>
+ <li class="list-group-item">
+ <?php if ($value === 0 && $category !== "times"): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br>-
+ <?php else: ?>
+ <?php if ($category === "times"): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= secondsToTime($value); ?> (<?= round(($value / $totalTimes) * 100, 2) ?>%)
+ <?php else: ?>
+ <?php if ($category === "results" && ($item === "wins" || $item === "loses")): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= $value ?> (<?= round(($value / $stats["results"]["total"]) * 100, 2) ?>%)
+ <?php elseif ($category === "results" && $item === "total"): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= $value ?> (~<?= round(($totalTimes / $value) / 60, 2) ?> <?= l("min/partie", "mn/game") ?>)
+ <?php elseif ($category === "ingame" && $item === "walls"): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= $value ?>
+ <?php if ($stats["results"]["total"] !== 0): ?>
+ (~<?= round(($value / $stats["results"]["total"]), 2) ?> <?= l(" par partie", " per game") ?>)
+ <?php endif; ?>
+ <?php elseif ($category === "ingame" && $item === "laps"): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= $value ?>
+ <?php if ($stats["results"]["total"] !== 0): ?>
+ (~<?= round(($value / $stats["results"]["total"]), 2) ?> <?= l(" par partie", " per game") ?>)
+ <?php endif; ?>
+ <?php elseif ($category === "ingame" && $item === "turns"): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= $value ?> (~<?= round(($value / $stats["ingame"]["laps"]), 2) ?> <?= l(" par tour", " per lap") ?>)
+ <?php else: ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= $value ?>
+ <?php endif; ?>
+ <?php endif; ?>
+ <?php endif; ?>
+ </li>
+ <?php endforeach; ?>
+ <?php endforeach; ?>
+ </ul>
+ <?php else: ?>
+ <p style="text-align: center;"><i><?= l("Des statistiques sur votre niveau dans Kartik apparaîtront ici au fur et à mesure que vous jouez", "Stats about your level in Kartik will appear here as you play") ?></i></p>
+ <?php endif; ?>
+ </div>
+ </div>
+ </div>
+ <div class="col-sm-4">
+ <div class="card">
+ <div class="card-body">
+ <h5><?= l("Progression", "Progress"); ?></h5>
+ <?php if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"])): ?>
+ <p><b><?= l("Niveau", "Level") ?> <?= (int)file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"]) < 200 ? file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"]) : l("Dieu", "God") ?></b></p>
+ <div class="progress">
+ <div class="progress-bar bg-success" style="width:<?= (int)file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"]) < 200 ? file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"]) / 2 : "100" ?>%"></div>
+ </div>
+ <?php else: ?>
+ <p style="text-align: center;"><i><?= l("En progressant dans le jeu, vous passez des niveaux. Votre progression s'affichera ici au fur et à mesure que vous jouez.", "By progressing in the game, you pass levels. Your progress will show here as you play.") ?></i></p>
+ <?php endif; ?>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+
+</body>
+</html>
+
diff --git a/online/ingame/allow/index.php b/online/ingame/allow/index.php new file mode 100644 index 0000000..16171b6 --- /dev/null +++ b/online/ingame/allow/index.php @@ -0,0 +1,16 @@ +<?php
+
+if (!isset($_COOKIE["kartik_online_token"])) {
+ header("Location: https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/auth?client_id=2d3ca3a8-38b7-4193-990a-a9454bb8d44c&response_type=code&redirect_uri=https://kartik.hopto.org/online/callback_ig&scope=hub&request_credentials=default&access_type=offline");
+ die();
+} else if (ctype_xdigit($_COOKIE["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $_COOKIE['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $_COOKIE['kartik_online_token']), true);
+} else {
+ header("Location: https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/auth?client_id=2d3ca3a8-38b7-4193-990a-a9454bb8d44c&response_type=code&redirect_uri=https://kartik.hopto.org/online/callback_ig&scope=hub&request_credentials=default&access_type=offline");
+ die();
+}
+
+$token = bin2hex(random_bytes(96));
+file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $token, json_encode($_DATA));
+header("Location: http://localhost:14552/kartik-auth?_=" . $token);
+die();
\ No newline at end of file diff --git a/online/ingame/api/profile.level.php b/online/ingame/api/profile.level.php new file mode 100644 index 0000000..f7c8f8c --- /dev/null +++ b/online/ingame/api/profile.level.php @@ -0,0 +1,15 @@ +<?php
+
+if (!isset($_GET["kartik_online_token"])) {
+ die();
+} else if (ctype_xdigit($_GET["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token']), true);
+} else {
+ die();
+}
+
+if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"])) {
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"], "0");
+}
+
+echo(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"]));
\ No newline at end of file diff --git a/online/ingame/api/profile.logout.php b/online/ingame/api/profile.logout.php new file mode 100644 index 0000000..c3f2e88 --- /dev/null +++ b/online/ingame/api/profile.logout.php @@ -0,0 +1,15 @@ +<?php
+
+if (!isset($_GET["kartik_online_token"])) {
+ echo("false");
+ die();
+} else if (ctype_xdigit($_GET["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token']), true);
+} else {
+ echo("false");
+ die();
+}
+
+echo("true");
+unlink($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token']);
+die();
\ No newline at end of file diff --git a/online/ingame/api/profile.name.php b/online/ingame/api/profile.name.php new file mode 100644 index 0000000..b8d70fa --- /dev/null +++ b/online/ingame/api/profile.name.php @@ -0,0 +1,11 @@ +<?php
+
+if (!isset($_GET["kartik_online_token"])) {
+ die();
+} else if (ctype_xdigit($_GET["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token']), true);
+} else {
+ die();
+}
+
+echo($_DATA["name"]);
\ No newline at end of file diff --git a/online/ingame/api/profile.picture.php b/online/ingame/api/profile.picture.php new file mode 100644 index 0000000..2dab624 --- /dev/null +++ b/online/ingame/api/profile.picture.php @@ -0,0 +1,11 @@ +<?php
+
+if (!isset($_GET["kartik_online_token"])) {
+ die();
+} else if (ctype_xdigit($_GET["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token']), true);
+} else {
+ die();
+}
+
+echo("data:image/jpeg;base64," . base64_encode(file_get_contents($_DATA["avatar"]["url"])));
\ No newline at end of file diff --git a/online/ingame/api/profile.stats.php b/online/ingame/api/profile.stats.php new file mode 100644 index 0000000..338febe --- /dev/null +++ b/online/ingame/api/profile.stats.php @@ -0,0 +1,15 @@ +<?php
+
+if (!isset($_GET["kartik_online_token"])) {
+ die();
+} else if (ctype_xdigit($_GET["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token']), true);
+} else {
+ die();
+}
+
+if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/stats/" . $_DATA["id"])) {
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/stats/" . $_DATA["id"], "null");
+}
+
+echo(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/stats/" . $_DATA["id"]));
\ No newline at end of file diff --git a/online/ingame/api/profile.token.php b/online/ingame/api/profile.token.php new file mode 100644 index 0000000..32aaaff --- /dev/null +++ b/online/ingame/api/profile.token.php @@ -0,0 +1,13 @@ +<?php
+
+if (!isset($_GET["kartik_online_token"])) {
+ echo("false");
+ die();
+} else if (ctype_xdigit($_GET["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token']), true);
+} else {
+ echo("false");
+ die();
+}
+
+echo("true");
\ No newline at end of file diff --git a/online/ingame/api/set.level.php b/online/ingame/api/set.level.php new file mode 100644 index 0000000..032d048 --- /dev/null +++ b/online/ingame/api/set.level.php @@ -0,0 +1,13 @@ +<?php
+
+if (!isset($_GET["kartik_online_token"])) {
+ die();
+} else if (ctype_xdigit($_GET["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token']), true);
+} else {
+ die();
+}
+
+if (is_integer((int)$_GET['level'])) {
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"], $_GET['level']);
+}
\ No newline at end of file diff --git a/online/ingame/api/set.stats.php b/online/ingame/api/set.stats.php new file mode 100644 index 0000000..145cc30 --- /dev/null +++ b/online/ingame/api/set.stats.php @@ -0,0 +1,13 @@ +<?php
+
+if (!isset($_GET["kartik_online_token"])) {
+ die();
+} else if (ctype_xdigit($_GET["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $_GET['kartik_online_token']), true);
+} else {
+ die();
+}
+
+if (strlen(base64_decode($_GET['stats'])) < 256) {
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/stats/" . $_DATA["id"], base64_decode($_GET['stats']));
+}
\ No newline at end of file diff --git a/online/ingame/index.php b/online/ingame/index.php new file mode 100644 index 0000000..5a6c3c4 --- /dev/null +++ b/online/ingame/index.php @@ -0,0 +1,74 @@ +<?php
+
+if (!isset($_COOKIE["kartik_online_token"])) {
+ header("Location: https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/auth?client_id=2d3ca3a8-38b7-4193-990a-a9454bb8d44c&response_type=code&redirect_uri=https://kartik.hopto.org/online/callback_ig&scope=hub&request_credentials=default&access_type=offline");
+ die();
+} else if (ctype_xdigit($_COOKIE["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $_COOKIE['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $_COOKIE['kartik_online_token']), true);
+} else {
+ header("Location: https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/auth?client_id=2d3ca3a8-38b7-4193-990a-a9454bb8d44c&response_type=code&redirect_uri=https://kartik.hopto.org/online/callback_ig&scope=hub&request_credentials=default&access_type=offline");
+ die();
+}
+
+function l($fr, $en) {
+ if (isset($_GET['lang'])) {
+ if ($_GET['lang'] == "en") {
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en";
+ } else if ($_GET['lang'] == "fr") {
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "fr";
+ }
+ }
+ if (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) == "fr") {
+ return $fr;
+ } else {
+ return $en;
+ }
+}
+
+?>
+<!DOCTYPE html>
+<html lang="en" style="height:100%;">
+<head>
+ <meta charset="UTF-8">
+ <title>Kartik Online</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="icon" href="/static/favicon.png">
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
+ <link rel="stylesheet" href="/appsicons.css">
+</head>
+<body style="height:100%;">
+
+<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
+
+ <a class="navbar-brand" href="/">
+ <img src="/static/logo.png" alt="Kartik" style="height:32px;"><span style="vertical-align: middle;font-size: 14px;">Online</span>
+ </a>
+
+ <div class="collapse navbar-collapse" id="collapsibleNavbar">
+ <ul class="navbar-nav">
+ <li class="nav-item">
+ <a class="nav-link" href="/">← <?= l("Retourner au site de Kartik", "Go back to Kartik website") ?></a>
+ </li>
+ <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/apps.php"; ?>
+ </ul>
+ </div>
+</nav>
+
+<div id="separator" style="margin-top:90px;"></div>
+
+<div class="container" style="margin-top:25px;">
+ <h2 style="text-align: center;"><?= l("Jouer en tant que", "Play as") ?> <?= $_DATA["name"] ?> <?= l("sur Kartik", "on Kartik") ?></h2>
+ <h4 style="text-align: center;"><?= l("Vous serez connecté avec l'adresse email", "You will be logged in with the email") ?> <b><?= $_DATA["profile"]["email"]["email"] ?></b> <?= l("sur Kartik", "on Kartik") ?>. <u><?= l("N'autorisez que si cette page a été ouverte par une version non modifiée de Kartik", "Only allow if this page was opened from an unmodified version of Kartik.") ?></u></h4>
+ <br>
+ <p style="text-align:center;" class="btn-group container">
+ <a class="btn btn-success" href="/online/ingame/allow"><?= l("Autoriser", "Allow") ?></a>
+ <a class="btn btn-danger" href="/online"><?= l("Refuser", "Deny") ?></a>
+ </p>
+</div>
+
+</body>
+</html>
+
diff --git a/online/logout/confirm/index.php b/online/logout/confirm/index.php new file mode 100644 index 0000000..36ecda6 --- /dev/null +++ b/online/logout/confirm/index.php @@ -0,0 +1,28 @@ +<?php
+
+if (!isset($_GET['_'])) {
+ header("Location: /online");
+ die();
+} else if (!ctype_alnum($_GET['_'])) {
+ header("Location: /online");
+ die();
+}
+
+if (!isset($_COOKIE["kartik_online_token"])) {
+ header("Location: https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/auth?client_id=2d3ca3a8-38b7-4193-990a-a9454bb8d44c&response_type=code&redirect_uri=https://kartik.hopto.org/online/callback_ig&scope=hub&request_credentials=default&access_type=offline");
+ die();
+} else if (ctype_xdigit($_COOKIE["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $_COOKIE['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $_COOKIE['kartik_online_token']), true);
+} else {
+ header("Location: https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/auth?client_id=2d3ca3a8-38b7-4193-990a-a9454bb8d44c&response_type=code&redirect_uri=https://kartik.hopto.org/online/callback_ig&scope=hub&request_credentials=default&access_type=offline");
+ die();
+}
+
+foreach (scandir($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens") as $token) {
+ if (trim($token) !== "." && trim($token) !== ".." && json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $token), true)["id"] === $_DATA["id"] && substr($token, 0, strlen($_GET['_'])) === $_GET['_']) {
+ unlink($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $token);
+ }
+}
+
+header("Location: /online");
+die();
\ No newline at end of file diff --git a/online/logout/index.php b/online/logout/index.php new file mode 100644 index 0000000..294280a --- /dev/null +++ b/online/logout/index.php @@ -0,0 +1,85 @@ +<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/telemetry/private/dom.php";
+
+if (!isset($_GET['_'])) {
+ header("Location: /online");
+ die();
+} else if (!ctype_alnum($_GET['_'])) {
+ header("Location: /online");
+ die();
+}
+
+if (!isset($_COOKIE["kartik_online_token"])) {
+ header("Location: https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/auth?client_id=2d3ca3a8-38b7-4193-990a-a9454bb8d44c&response_type=code&redirect_uri=https://kartik.hopto.org/online/callback_ig&scope=hub&request_credentials=default&access_type=offline");
+ die();
+} else if (ctype_xdigit($_COOKIE["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $_COOKIE['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $_COOKIE['kartik_online_token']), true);
+} else {
+ header("Location: https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/auth?client_id=2d3ca3a8-38b7-4193-990a-a9454bb8d44c&response_type=code&redirect_uri=https://kartik.hopto.org/online/callback_ig&scope=hub&request_credentials=default&access_type=offline");
+ die();
+}
+
+function l($fr, $en) {
+ if (isset($_GET['lang'])) {
+ if ($_GET['lang'] == "en") {
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en";
+ } else if ($_GET['lang'] == "fr") {
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "fr";
+ }
+ }
+ if (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) == "fr") {
+ return $fr;
+ } else {
+ return $en;
+ }
+}
+
+?>
+<!DOCTYPE html>
+<html lang="en" style="height:100%;">
+<head>
+ <meta charset="UTF-8">
+ <title>Kartik Online</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="icon" href="/static/favicon.png">
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
+ <link rel="stylesheet" href="/appsicons.css">
+</head>
+<body style="height:100%;">
+
+<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
+
+ <a class="navbar-brand" href="/">
+ <img src="/static/logo.png" alt="Kartik" style="height:32px;"><span style="vertical-align: middle;font-size: 14px;">Online</span>
+ </a>
+
+ <div class="collapse navbar-collapse" id="collapsibleNavbar">
+ <ul class="navbar-nav">
+ <li class="nav-item">
+ <a class="nav-link" href="/">← <?= l("Retourner au site de Kartik", "Go back to Kartik website") ?></a>
+ </li>
+ <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/apps.php"; ?>
+ </ul>
+ </div>
+</nav>
+
+<div id="separator" style="margin-top:90px;"></div>
+
+<div class="container" style="margin-top:25px;">
+ <h2 style="text-align: center;"><?= l("Déconnecter la session", "Logout session") ?> <code><?= substr($_GET['_'], 0, 8) ?></code> <?= l("de Kartik", "from Kartik") ?></h2>
+ <h4 style="text-align: center;"><?= l("Vous êtes connecté à cette session dans votre copie locale de Kartik. Si vous pensez qu'elle a été compromise ou que vous n'en avez plus la nécessité, vous pouvez déconnecter cette session.", "You are logged into this session on your local copy of Kartik. If you think it has been compromised or you don't need it anymore, you can safely logout this session.") ?></h4>
+ <h4 style="text-align: center;"><?= l("Après vous être déconnecté, la copie de Kartik associée à cette session ne pourra plus utiliser les services Kartik Online.", "After being disconnected, the copy of Kartik associated to this session won't be able to use the Kartik Online services anymore.") ?></h4>
+ <br>
+ <p style="text-align:center;" class="btn-group container">
+ <a class="btn btn-success" href="/online/logout/confirm/?_=<?= $_GET['_'] ?>"><?= l("Continuer", "Continue") ?></a>
+ <a class="btn btn-danger" href="/online"><?= l("Annuler", "Cancel") ?></a>
+ </p>
+</div>
+
+</body>
+</html>
+
diff --git a/online/private/.htaccess b/online/private/.htaccess new file mode 100644 index 0000000..bf4912f --- /dev/null +++ b/online/private/.htaccess @@ -0,0 +1,3 @@ +Deny from All
+Require all denied
+Order deny,allow
\ No newline at end of file diff --git a/online/private/app.json b/online/private/app.json new file mode 100644 index 0000000..ae86a06 --- /dev/null +++ b/online/private/app.json @@ -0,0 +1,4 @@ +{
+ "id": "2d3ca3a8-38b7-4193-990a-a9454bb8d44c",
+ "secret": "8RAn6Ja2mj1V"
+}
\ No newline at end of file diff --git a/online/private/statsnames.json b/online/private/statsnames.json new file mode 100644 index 0000000..dda48b0 --- /dev/null +++ b/online/private/statsnames.json @@ -0,0 +1,38 @@ +{
+ "times.single": {
+ "fr": "Temps passé en mode solo",
+ "en": "Time spent in singleplayer"
+ },
+ "times.local": {
+ "fr": "Temps passé en multijoueur local",
+ "en": "Time spent in local multiplayer"
+ },
+ "times.online": {
+ "fr": "Temps passé en multijoueur en ligne",
+ "en": "Time spent in online multiplayer"
+ },
+ "results.wins": {
+ "fr": "Parties gagnées",
+ "en": "Games won"
+ },
+ "results.loses": {
+ "fr": "Parties perdues",
+ "en": "Games lost"
+ },
+ "results.total": {
+ "fr": "Parties jouées",
+ "en": "Games played"
+ },
+ "ingame.walls": {
+ "fr": "Nombre de collisions",
+ "en": "Collisions count"
+ },
+ "ingame.laps": {
+ "fr": "Nombre de tours",
+ "en": "Laps count"
+ },
+ "ingame.turns": {
+ "fr": "Nombre de rotations",
+ "en": "Turns count"
+ }
+}
\ No newline at end of file diff --git a/online/session/index.php b/online/session/index.php new file mode 100644 index 0000000..0f4ae89 --- /dev/null +++ b/online/session/index.php @@ -0,0 +1,6 @@ +<?php
+
+var_dump($_GET);
+var_dump($_POST);
+var_dump($_SERVER);
+die();
\ No newline at end of file |