aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2021-12-23 19:41:28 +0100
committerMinteck <contact@minteck.org>2021-12-23 19:41:28 +0100
commitc451cbe0b6de0707d891937d7f61596491e81565 (patch)
tree4c564a930af36980be2f345f68306aca0a967269 /api
parent4692b0866fb0051b8647f77f1f5a8ee74f48e89e (diff)
downloadshare-c451cbe0b6de0707d891937d7f61596491e81565.tar.gz
share-c451cbe0b6de0707d891937d7f61596491e81565.tar.bz2
share-c451cbe0b6de0707d891937d7f61596491e81565.zip
Commit
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");
+}