<commit_before><?php
include_once('auth.php');

global $WS_AUTHINFO;
if ($WS_AUTHINFO["error_span"] != "") {
   echo json_encode($WS_AUTHINFO);
   die();
}

if (//!array_key_exists('stdin', $_REQUEST) ||
     !array_key_exists('problem', $_REQUEST))
  {
    echo "Internal error, malformed request to load.php";
    die;
  }
//$stdin = $_REQUEST["stdin"];
$problem = $_REQUEST["problem"];
$preview = $_REQUEST["preview"]=='True' ? 'True' : 'False';

// only accept characters that cannot cause problems
$regex = "[_0-9a-zA-Z/-]+";
if (!preg_match("@^$regex\$@", $problem)) {
  echo "Internal error, problem name \"$problem\" doesn't match $regex";
  die;
 }

$descriptorspec = array(
                        0 => array("pipe", "r"),  // stdin
                        1 => array("pipe", "w"),  // stdout
                        2 => array("pipe", "w"),  // stderr
                        );

$process = proc_open("python3 ./load.py " . $problem . " " . $WS_AUTHINFO['username'] . " " . $preview, $descriptorspec, $pipes);

if (!is_resource($process)) {
  echo "Internal error, could not run Websheet program";
  die;
 }

fwrite($pipes[0], json_encode($WS_AUTHINFO));
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$return_value = proc_close($process);

if ($stderr != "" || $return_value != 0) {
  echo "Internal error: <pre>";
  echo $stdout . $stderr . "\nReturned $return_value</pre>";
  die;
 }

echo $stdout;<commit_msg>checks for student ID in query string<commit_after><?php
include_once('auth.php');

global $WS_AUTHINFO;
if ($WS_AUTHINFO["error_span"] != "") {
   echo json_encode($WS_AUTHINFO);
   die();
}

if (//!array_key_exists('stdin', $_REQUEST) ||
     !array_key_exists('problem', $_REQUEST))
  {
    echo "Internal error, malformed request to load.php";
    die;
  }
//$stdin = $_REQUEST["stdin"];
$problem = $_REQUEST["problem"];
$preview = $_REQUEST["preview"]=='True' ? 'True' : 'False';

$student = $WS_AUTHINFO['username']; 
// for code review by instructor
if (array_key_exists('student', $_REQUEST) && $_REQUEST["student"]!="undefined"){
    $student = $_REQUEST["student"];
}

// only accept characters that cannot cause problems
$regex = "[_0-9a-zA-Z/-]+";
if (!preg_match("@^$regex\$@", $problem)) {
  echo "Internal error, problem name \"$problem\" doesn't match $regex";
  die;
 }

$descriptorspec = array(
                        0 => array("pipe", "r"),  // stdin
                        1 => array("pipe", "w"),  // stdout
                        2 => array("pipe", "w"),  // stderr
                        );

$process = proc_open("python3 ./load.py " . $problem . " " . $student . " " . $preview, $descriptorspec, $pipes);

if (!is_resource($process)) {
  echo "Internal error, could not run Websheet program";
  die;
 }

fwrite($pipes[0], json_encode($WS_AUTHINFO));
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$return_value = proc_close($process);

if ($stderr != "" || $return_value != 0) {
  echo "Internal error: <pre>";
  echo $stdout . $stderr . "\nReturned $return_value</pre>";
  die;
 }

echo $stdout;
{'fraction_non_alphanumeric': 0.20234785295026259, 'fraction_numerical': 0.008032128514056224, 'mean_word_length': 3.5286713286713285, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6084603', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1084, 'n_words': 244}