aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/login/index.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/api/login/index.php b/api/login/index.php
new file mode 100644
index 0000000..e8a41ce
--- /dev/null
+++ b/api/login/index.php
@@ -0,0 +1,54 @@
+<?php
+
+if (isset($_POST['session'])) {
+ $ch = curl_init();
+
+ curl_setopt($ch, CURLOPT_URL,"https://familine.jetbrains.space/api/http/team-directory/profiles/me");
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ 'Authorization: Bearer ' . $_POST['session']
+ ));
+
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_VERBOSE, false);
+
+ $server_output = curl_exec($ch);
+ $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ curl_close($ch);
+
+ $data = json_decode($server_output, true);
+
+ if (isset($data["error"])) {
+ die("no");
+ }
+
+ if ($data["left"] != null) {
+ die("no");
+ }
+
+ if ($data["leftAt"] != null) {
+ die("no");
+ }
+
+ if ($data["archived"] != false) {
+ die("no");
+ }
+
+ if ($data["notAMember"] != false) {
+ die("no");
+ }
+
+ $token = openssl_random_pseudo_bytes(32);
+ $token = bin2hex($token);
+
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/private/tokens/" . str_replace(".", "", str_replace("/", "", $token)) . ".json", json_encode($data));
+ $exp = (new DateTime('tomorrow'))->format("U");
+ if (isset($_SERVER["HTTP_REFERER"]) && strpos($_SERVER["HTTP_REFERER"], "fl4-network-proxy.alwaysdata.net") !== false) {
+ setcookie("FL_SESSION_TOKEN", $token, $exp, "/", "fl4-network-proxy.alwaysdata.net", true, true);
+ } else {
+ setcookie("FL_SESSION_TOKEN", $token, $exp, "/", "famishare.ddns.net", true, true);
+ }
+
+ die("ok");
+} else {
+ die("no");
+}