diff options
author | Marvin Borner | 2018-05-06 13:28:36 +0200 |
---|---|---|
committer | Marvin Borner | 2018-05-06 13:28:36 +0200 |
commit | 9be672cd85682c865bdeb4463945d1362049d871 (patch) | |
tree | fdb128558d211ba3bdbb53a1738e2b023dce5f5b /main/app/sprinkles/core/assets | |
parent | af049eeb0d2b442656cc1f7a6246bcdab22cf535 (diff) |
Extended wormhole and began chat verification
Diffstat (limited to 'main/app/sprinkles/core/assets')
-rw-r--r-- | main/app/sprinkles/core/assets/SiteAssets/js/chat.js | 2 | ||||
-rw-r--r-- | main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php | 48 |
2 files changed, 34 insertions, 16 deletions
diff --git a/main/app/sprinkles/core/assets/SiteAssets/js/chat.js b/main/app/sprinkles/core/assets/SiteAssets/js/chat.js index ebf549b..f131db1 100644 --- a/main/app/sprinkles/core/assets/SiteAssets/js/chat.js +++ b/main/app/sprinkles/core/assets/SiteAssets/js/chat.js @@ -15,7 +15,7 @@ function InitializeChatServer() { }, 5000); }; ChatSocket.onopen = function () { - ChatSocket.send(JSON.stringify({ClientMessageType: "Verify", Cookie: document.cookie})); + ChatSocket.send(JSON.stringify({ClientMessageType: "Verify", Cookie: document.cookie, UserID: current_user_id})); // CONNECTION SUCCESSFUL! console.log("[WEBSOCKET LOGGER] Chat connection established!"); // GOT MESSAGE diff --git a/main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php b/main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php index 1385f19..17e85b9 100644 --- a/main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php +++ b/main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php @@ -37,16 +37,16 @@ class ChatProcessor implements MessageComponentInterface foreach ($this->subscriptions as $id => $channel) { if ($this->subscriptions[$conn->resourceId] == $channel) { $MessageObject = new \stdClass(); - $MessageObject->ServerMessage = true; + $MessageObject->ServerMessage = TRUE; $MessageObject->ServerMessageType = "GroupJoin"; $MessageObject->GroupName = $channel; $MessageObject->Username = $this->connectedUsersNames[$conn->resourceId]; if ($id === $conn->resourceId) { - $MessageObject->WasHimself = true; + $MessageObject->WasHimself = TRUE; } else { - $MessageObject->WasHimself = false; + $MessageObject->WasHimself = FALSE; } - $MessageJson = json_encode($MessageObject, true); + $MessageJson = json_encode($MessageObject, TRUE); $this->users[$id]->send($MessageJson); } } @@ -57,16 +57,16 @@ class ChatProcessor implements MessageComponentInterface foreach ($this->subscriptions as $id => $channel) { if ($channel == $target) { $MessageObject = new \stdClass(); - $MessageObject->ServerMessage = false; + $MessageObject->ServerMessage = FALSE; $MessageObject->GroupName = $channel; $MessageObject->Username = $this->connectedUsersNames[$conn->resourceId]; $MessageObject->Message = htmlspecialchars($data->Message); if ($id === $conn->resourceId) { - $MessageObject->WasHimself = true; + $MessageObject->WasHimself = TRUE; } else { - $MessageObject->WasHimself = false; + $MessageObject->WasHimself = FALSE; } - $MessageJson = json_encode($MessageObject, true); + $MessageJson = json_encode($MessageObject, TRUE); $this->users[$id]->send($MessageJson); } } @@ -78,24 +78,37 @@ class ChatProcessor implements MessageComponentInterface foreach ($this->subscriptions as $id => $channel) { if ($channel == $target) { $MessageObject = new \stdClass(); - $MessageObject->ServerMessage = true; + $MessageObject->ServerMessage = TRUE; $MessageObject->ServerMessageType = "TypingState"; $MessageObject->GroupName = $channel; $MessageObject->Username = $this->connectedUsersNames[$conn->resourceId]; $MessageObject->State = $data->State; if ($id === $conn->resourceId) { - $MessageObject->WasHimself = true; + $MessageObject->WasHimself = TRUE; } else { - $MessageObject->WasHimself = false; + $MessageObject->WasHimself = FALSE; } - $MessageJson = json_encode($MessageObject, true); + $MessageJson = json_encode($MessageObject, TRUE); $this->users[$id]->send($MessageJson); } } } break; case "Verify": - print_r($data); + $headerCookies = explode('; ', $data->Cookie); + $cookies = array(); + foreach ($headerCookies as $headerCookie) { + list($key, $val) = explode('=', $headerCookie, 2); + $cookies[$key] = $val; + } + $UserSessionKey = $cookies["uf4"]; + $AccessToken = file_get_contents("/AccessToken.txt"); // SECRET + $KeyVerifierCode = $this->getHttpCode("https://beam-messenger.de/wormhole/" . $AccessToken . "/verify/" . $data->UserID . "/" . $UserSessionKey); + if ($KeyVerifierCode === 200) { + echo "Access granted"; + } else { + echo "Access denied"; + } break; } } @@ -108,10 +121,10 @@ class ChatProcessor implements MessageComponentInterface foreach ($this->subscriptions as $id => $channel) { if ($channel == $target) { $MessageObject = new \stdClass(); - $MessageObject->ServerMessage = true; + $MessageObject->ServerMessage = TRUE; $MessageObject->ServerMessageType = "UserDisconnect"; $MessageObject->Username = $this->connectedUsersNames[$conn->resourceId]; - $MessageJson = json_encode($MessageObject, true); + $MessageJson = json_encode($MessageObject, TRUE); $this->users[$id]->send($MessageJson); } } @@ -127,4 +140,9 @@ class ChatProcessor implements MessageComponentInterface $conn->close(); } + + public function getHttpCode($domain) { + $headers = get_headers($domain); + return substr($headers[0], 9, 3); + } }
\ No newline at end of file |