This repository was archived by the owner on Mar 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Updated LiveSync Security #494
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,83 +6,104 @@ class LiveSyncDataController extends DataController { | |
|
|
||
| public async function genGenerateData(): Awaitable<void> { | ||
| $data = array(); | ||
| await tr_start(); | ||
| $input_auth_key = idx(Utils::getGET(), 'auth', ''); | ||
| $livesync_enabled = await Configuration::gen('livesync'); | ||
| $livesync_auth_key = await Configuration::gen('livesync_auth_key'); | ||
| if ($livesync_enabled->getValue() === '1' && | ||
| strval($input_auth_key) === strval($livesync_auth_key->getValue())) { | ||
|
|
||
| $teams_array = array(); | ||
| $all_teams = await Team::genAllTeams(); | ||
| foreach ($all_teams as $team) { | ||
| $team_livesync_exists = | ||
| await Team::genLiveSyncExists($team->getId(), "fbctf"); | ||
| if ($team_livesync_exists === true) { | ||
| $team_livesync_key = | ||
| await Team::genGetLiveSyncKey($team->getId(), "fbctf"); | ||
| $teams_array[$team->getId()] = strval($team_livesync_key); | ||
| } | ||
| } | ||
| $data = array(); | ||
|
|
||
| $scores_array = array(); | ||
| $scored_teams = array(); | ||
| $all_scores = await ScoreLog::genAllScores(); | ||
| foreach ($all_scores as $score) { | ||
| if (in_array($score->getTeamId(), array_keys($teams_array)) === false) { | ||
| continue; | ||
| $teams_array = array(); | ||
| $all_teams = await Team::genAllTeams(); | ||
| foreach ($all_teams as $team) { | ||
| $team_livesync_exists = | ||
| await Team::genLiveSyncExists($team->getId(), "fbctf"); | ||
| if ($team_livesync_exists === true) { | ||
| $team_livesync_key = | ||
| await Team::genGetLiveSyncKey($team->getId(), "fbctf"); | ||
| $teams_array[$team->getId()] = strval($team_livesync_key); | ||
| } | ||
| } | ||
| $scores_array[$score->getLevelId()][$teams_array[$score->getTeamId()]]['timestamp'] = | ||
| $score->getTs(); | ||
| $scores_array[$score->getLevelId()][$teams_array[$score->getTeamId()]]['capture'] = | ||
| true; | ||
| $scores_array[$score->getLevelId()][$teams_array[$score->getTeamId()]]['hint'] = | ||
| false; | ||
| $scored_teams[$score->getLevelId()][] = $score->getTeamId(); | ||
| } | ||
| $all_hints = await HintLog::genAllHints(); | ||
| foreach ($all_hints as $hint) { | ||
| if ($hint->getPenalty()) { | ||
| if (in_array($hint->getTeamId(), array_keys($teams_array)) === | ||
|
|
||
| $scores_array = array(); | ||
| $scored_teams = array(); | ||
| $all_scores = await ScoreLog::genAllScores(); | ||
| foreach ($all_scores as $score) { | ||
| if (in_array($score->getTeamId(), array_keys($teams_array)) === | ||
| false) { | ||
| continue; | ||
| } | ||
| $scores_array[$hint->getLevelId()][$teams_array[$hint->getTeamId()]]['hint'] = | ||
| $scores_array[$score->getLevelId()][$teams_array[$score->getTeamId()]]['timestamp'] = | ||
| $score->getTs(); | ||
| $scores_array[$score->getLevelId()][$teams_array[$score->getTeamId()]]['capture'] = | ||
| true; | ||
| if (in_array( | ||
| $hint->getTeamId(), | ||
| $scored_teams[$hint->getLevelId()], | ||
| ) === | ||
| false) { | ||
| $scores_array[$hint->getLevelId()][$teams_array[$hint->getTeamId()]]['capture'] = | ||
| false; | ||
| $scores_array[$hint->getLevelId()][$teams_array[$hint->getTeamId()]]['timestamp'] = | ||
| $hint->getTs(); | ||
| $scores_array[$score->getLevelId()][$teams_array[$score->getTeamId()]]['hint'] = | ||
| false; | ||
| $scored_teams[$score->getLevelId()][] = $score->getTeamId(); | ||
| } | ||
| $all_hints = await HintLog::genAllHints(); | ||
| foreach ($all_hints as $hint) { | ||
| if ($hint->getPenalty()) { | ||
| if (in_array($hint->getTeamId(), array_keys($teams_array)) === | ||
| false) { | ||
| continue; | ||
| } | ||
| $scores_array[$hint->getLevelId()][$teams_array[$hint->getTeamId()]]['hint'] = | ||
| true; | ||
| if (in_array( | ||
| $hint->getTeamId(), | ||
| $scored_teams[$hint->getLevelId()], | ||
| ) === | ||
| false) { | ||
| $scores_array[$hint->getLevelId()][$teams_array[$hint->getTeamId()]]['capture'] = | ||
| false; | ||
| $scores_array[$hint->getLevelId()][$teams_array[$hint->getTeamId()]]['timestamp'] = | ||
| $hint->getTs(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $levels_array = array(); | ||
| $all_levels = await Level::genAllLevels(); | ||
| foreach ($all_levels as $level) { | ||
| $entity = await Country::gen($level->getEntityId()); | ||
| $category = await Category::genSingleCategory($level->getCategoryId()); | ||
| if (array_key_exists($level->getId(), $scores_array)) { | ||
| $score_level_array = $scores_array[$level->getId()]; | ||
| } else { | ||
| $score_level_array = array(); | ||
| $levels_array = array(); | ||
| $all_levels = await Level::genAllLevels(); | ||
| foreach ($all_levels as $level) { | ||
| $entity = await Country::gen($level->getEntityId()); | ||
| $category = | ||
|
||
| await Category::genSingleCategory($level->getCategoryId()); | ||
| if (array_key_exists($level->getId(), $scores_array)) { | ||
| $score_level_array = $scores_array[$level->getId()]; | ||
| } else { | ||
| $score_level_array = array(); | ||
| } | ||
| $one_level = array( | ||
| 'active' => $level->getActive(), | ||
| 'type' => $level->getType(), | ||
| 'title' => $level->getTitle(), | ||
| 'description' => $level->getDescription(), | ||
| 'entity_iso_code' => $entity->getIsoCode(), | ||
| 'category' => $category->getCategory(), | ||
| 'points' => $level->getPoints(), | ||
| 'bonus' => $level->getBonusFix(), | ||
| 'bonus_dec' => $level->getBonusDec(), | ||
| 'penalty' => $level->getPenalty(), | ||
| 'teams' => $score_level_array, | ||
| ); | ||
| $levels_array[] = $one_level; | ||
| } | ||
| $one_level = array( | ||
| 'active' => $level->getActive(), | ||
| 'type' => $level->getType(), | ||
| 'title' => $level->getTitle(), | ||
| 'description' => $level->getDescription(), | ||
| 'entity_iso_code' => $entity->getIsoCode(), | ||
| 'category' => $category->getCategory(), | ||
| 'points' => $level->getPoints(), | ||
| 'bonus' => $level->getBonusFix(), | ||
| 'bonus_dec' => $level->getBonusDec(), | ||
| 'penalty' => $level->getPenalty(), | ||
| 'teams' => $score_level_array, | ||
| ); | ||
| $levels_array[] = $one_level; | ||
| } | ||
|
|
||
| $data = $levels_array; | ||
| $data = $levels_array; | ||
| } else if ($livesync_enabled->getValue() === '0') { | ||
| $data['error'] = | ||
| tr('LiveSync is disabled, please contact the administrator for access.'); | ||
| } else if (strval($input_auth_key) !== | ||
| strval($livesync_auth_key->getValue())) { | ||
| $data['error'] = | ||
| tr('LiveSync auth key is invalid, please contact the administrator for access.'); | ||
| } else { | ||
| $data['error'] = | ||
| tr('LiveSync failed, please contact the administrator for assistance.'); | ||
| } | ||
| $this->jsonSend($data); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine these two awaits into one await with
https://docs.hhvm.com/hack/reference/function/HH.Asio.va/.Also, can you create a function in utils called
genvawhich calls\HH\Asio\va? This is what we use internally at FB and is easier to type.