Example #1
0
 public function Start()
 {
     $request = jf::$BaseRequest;
     if (jf::CurrentUser()) {
         // User is logged in, check if the user is authorized
         if (jf::Check("view_contest_chal")) {
             if (($activeContest = \webgoat\ContestDetails::getActive()) !== null) {
                 $this->ContestName = $activeContest[0]['ContestName'];
                 $startTime = $activeContest[0]['StartTimestamp'];
                 $currentTime = time();
                 if ($currentTime < $startTime) {
                     $this->TimeRemaining = $startTime - $currentTime;
                 } else {
                     $challenges = \webgoat\ContestChallenges::getByContestID();
                     if (count($challenges) == 0) {
                         $this->Error = "Currently there are no challenges in this contest";
                     } else {
                         $this->Challenges = $challenges;
                     }
                 }
             } else {
                 $this->Error = "Currently there is no active contest. Check back later!!";
             }
             return $this->Present();
         } else {
             // User is not authorized
             $this->Redirect(SiteRoot);
         }
     } else {
         // User is not logged in
         $this->Redirect(jf::url() . "/user/login?return=/{$request}");
     }
 }
Example #2
0
 private function insertNewChallenges()
 {
     $allChallenges = \webgoat\ContestChallengeScanner::run();
     $result = array();
     foreach ($allChallenges as $challenge) {
         if (($details = \webgoat\ContestChallenges::getByName($challenge)) === null) {
             array_push($result, $challenge);
         }
     }
     $this->newChallenges = $result;
 }
Example #3
0
 public function Start()
 {
     if (jf::CurrentUser()) {
         if (jf::Check("contest")) {
             if (isset($_POST['challenge']) && isset($_POST['name']) && isset($_POST['points']) && isset($_POST['flag'])) {
                 $hashedFlag = md5($_POST['flag']);
                 $activeContest = \webgoat\ContestDetails::getActive();
                 $activeContestID = $activeContest[0]['ID'];
                 $data = array('ContestID' => $activeContestID, 'ChallengeName' => $_POST['challenge'], 'NameToDisplay' => $_POST['name'], 'Points' => $_POST['points'], 'CorrectFlag' => $hashedFlag);
                 \webgoat\ContestChallenges::add($data);
                 echo json_encode(array('status' => true, 'message' => 'Challenge successfully added'));
                 return true;
             }
         }
     }
 }
Example #4
0
 private function addSubmission($challenge)
 {
     $challengeDetails = \webgoat\ContestChallenges::getByName($challenge);
     $flag = $_POST['flag'];
     $ip = \jf\HttpRequest::IP();
     $challengeID = $challengeDetails[0]['ID'];
     $userID = jf::CurrentUser();
     $data = array('UserID' => $userID, 'ChallengeID' => $challengeID, 'Flag' => $flag, 'IP' => $ip, 'timestamp' => time());
     \webgoat\ContestSubmissions::add($data);
     \webgoat\ContestChallenges::incrementTotalAttempts($challenge);
     if (\webgoat\ContestSubmissions::evaluate($challengeID, $flag)) {
         $this->Submission = 1;
         // Increment complete count
         \webgoat\ContestChallenges::incrementCompletedCount($challenge);
     } else {
         $this->Submission = 0;
     }
 }