public function postModified() { $this->load->helper('app_log'); $results = $this->threat_model->getModified(); $urltopost = 'http://avapincus.cloudapp.net/update'; $datatopost = json_encode($results); //print_r($datatopost);die(); //set curl options $ch = curl_init($urltopost); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $datatopost); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $returndata = curl_exec($ch); if ($returndata !== '[]') { app_log('<br />ERROR:<br />' . $returndata . '<br />Posted: ' . date('m-d-Y H:i:s')); return false; } else { $this->threat_model->resetModified(); return true; } }
function process_specified_user() { global $_GET; global $people; //?global $specified_user; global $show_submission_result; // 0: no, 1: message, 2: message & compile log global $submission_result; global $compile_log; if (!array_key_exists("id", $_GET) || $_GET["id"] == "") { // Not showing anyone's submission status $show_submission_result = 0; return; } if (!array_key_exists($_GET["id"], $people)) { $show_submission_result = 1; $submission_result = "You are trying to display the status for an invalid user."; app_log('A user at ' . get_ip() . ' tried to display the status of user ' . $_GET['id'] . ' which is an invalid user.'); return; } $specified_user = $people[$_GET['id']]; $show_submission_result = 1; $last_processed = "Your most recent submission processed is the one submitted around {$specified_user->time_of_last_submission}. <br />"; //$submission_result = "Your most recent submission's status is: "; switch ($specified_user->last_status_code) { case "-1": $submission_result = "You haven't submitted anything yet or your submission hasn't been processed."; break; case "0": $submission_result = $last_processed . "Submission ok!"; break; case "1": $submission_result = $last_processed . "Compile failure."; $show_submission_result = 2; $compile_log = file($specified_user->last_compile_log_filename, 1); if ($compile_log === false) { $submission_msg = "Compile failure but compile log could not be read. Notify a proctor."; // $submission_result = "Compile failure but compile log could not be read. Notify a proctor."; $show_submission_result = 1; // TODO log } break; case "2": $submission_msg = "Program failed test"; // $submission_result = $last_processed . "Program failed test."; break; case "3": $submission_msg = "Program timed out while running"; // $submission_result = $last_processed . "Program timed out while running."; break; case "4": $submission_msg = "Program crashed while running."; // $submission_result = $last_processed . "Program crashed while running."; break; case "5": $submission_msg = "Unknown error while running program."; // $submission_result = "Unknown error while running program."; // TODO log break; default: $submission_result = "Unknown error."; app_log(sprintf("ERROR: User %d has a last_status_code of %d which is invalid. (scoreboard status display)", $specified_user->user_id, $specified_user->last_status_code)); break; } $submission_result = $last_processed . "<br /><b>" . $submission_msg . "</b>"; $submission_result = "<span>" . $submission_result . "</span>"; }
<?php $type = _post('type'); $data = _post('data'); app_log('recieve type %s with %s', $type, json_encode($data)); $entry = ORM::forTable($type)->findOne($data['id']); if ($entry) { $code = 1; $message = 'has entry'; } else { $entry = ORM::forTable('entry')->create(); $code = 0; $message = 'ok'; } $entry->set($data); $entry->save(); echo json_encode(array('code' => $code, 'message' => $message)); app_log('recieve type %s with %s', $type, json_encode($data));
require __DIR__ . '/vendor/autoload.php'; $map = ['answer', 'question', 'user']; $n = count($map) - 1; $url = 'http://3.xctest.sinaapp.com/upload'; while (1) { $i = rand(0, $n); $type = $map[$i]; $entry = ORM::forTable($type)->where('is_upload', 0)->findOne(); $data = ['type' => $type, 'data' => $entry->toArray()]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $content = curl_exec($ch); $response = json_decode($content, true); if (json_last_error()) { app_log('error: json decode error %s', json_last_error()); throw new Exception("json decode error", 1); } if (empty($response)) { app_log('error: response empty'); throw new Exception("response empty", 1); } if ($response['code'] !== 0) { app_log('error: response code %s message %s', $response['code'], $response['message']); throw new Exception("response code " . $response['code'], 1); } $entry->is_upload = 1; $entry->save(); app_log('curl %s of type %s with %s', $url, $type, json_encode($entry->toArray())); sleep(2); }
$random_chars = ''; for ($i = 0; $i < 15; $i++) { $random_chars .= $chars[mt_rand(0, strlen($chars) - 1)]; } $tempfile = $upload["tmp_name"]; $filename = 'submission-' . $user_id . '-' . $submission_time . '-' . $_POST['progno'] . '-' . $random_chars . $extension; $filename_with_path = $contest_root . '/temp_web/' . $filename; $result = copy($tempfile, $filename_with_path); if ($result === false) { $message = "ERROR: Could not copy submitted file to temp_web/."; return; } $message = "The program was successfully uploaded. Thanks!"; } process_submission(); app_log(sprintf("User %d submitted a file. IP address: %s. Language: %s. Problem: %s. Result: %s", $user_id, get_ip(), $_POST['lang'], $_POST['progno'], $message)); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>ACM Coding Contest Submission</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <p> <?php
/** * Efetando log de acesso do sistema, atualizado a cada acesso na página. * * @return <void> */ static function access_log() { app_log('access', json(array('accessed_in' => date('d/m/Y H:i:s'), 'ip' => ip(), 'url' => URL_CURRENT, 'get' => $_GET, 'post' => $_POST))); }
$message = "You have been successfully registered. Your user id is {$user_id}. Write this number down now! You may need it later to log in again."; $success = true; } else { $message = 'ERROR: Registration error. Code ' . $status . ': ' . $status_message; $success = false; } // Acknowledge to backend that we saw the information if possible so it can clean up $ack = fopen($contest_root . '/temp_web/registration_done-' . $random_chars, 'w'); if ($ack === false) { // TODO log this } else { fclose($ack); } } process_submission(); app_log(get_ip() . ' attemped to register with name "' . $_GET['name'] . '". Result: ' . $message); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>ACM Coding Contest Submission</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <p> <?php