<commit_before><commit_msg>Initial Commit<commit_after><?php
session_start();
$headers = getallheaders();
$server_token = substr(hash('md5', $_SESSION['username'].'<PASSWORD>'), 4, 8);

// Validation routine

if (isset($_COOKIE['PHPSESSID']) && isset($_SESSION['username'])) {
  
  if ($_COOKIE['PHPSESSID'] === $_SESSION['username']) {

    if (isset($headers['X-CSRF-Token']) && $headers['X-CSRF-Token'] === $server_token) {
       echo print_response($_SERVER['REQUEST_METHOD']);

    } elseif (isset($_POST['_csrf']) && $_POST['_csrf'] === $server_token) {
      echo print_response($_SERVER['REQUEST_METHOD']);

    } elseif (isset($_GET['_csrf']) && $_GET['_csrf'] === $server_token) {
      echo print_response($_SERVER['REQUEST_METHOD']);

    } else {
      echo print_error($_SERVER['REQUEST_METHOD']);   
    }
  } else {
      $response = array('error' => 'true', 'error_msg' => 'not logged in');
      echo json_encode($response);
  }

} else {
    $response = array('error' => 'true', 'error_msg' => 'not logged in');
    echo json_encode($response);
  }

// Function to return a JSON reponse if validation is successful.
function print_response ($method) {
  if ($method === 'GET') {
    $name = htmlentities(isset($_GET['name'])) ? htmlentities($_GET['name']) : "default_name";
    $msg = htmlentities(isset($_GET['msg'])) ? htmlentities($_GET['msg']) : "default_message";
    $response = array('greet' => 'Hello, '.$name, 'msg' => $msg);
    header('Content-Type: application/json');
    return json_encode($response);
  } elseif ($method === 'POST') {
    $name = htmlentities(isset($_POST['name'])) ? htmlentities($_POST['name']) : "default_name";
    $msg = htmlentities(isset($_POST['msg'])) ? htmlentities($_POST['msg']) : "default_message";
    $response = array('greet' => 'Hello, '.$name, 'msg' => $msg);
    header('Content-Type: application/json');
    return json_encode($response);
  }
}

// Function to return a JSON error if validation is unsuccessful.
function print_error ($method) {
  $headers = getallheaders();
  $client_token = isset($headers['X-CSRF-Token']) ? $headers['X-CSRF-Token'] : "null";
  $client_token = isset($_POST['_csrf']) ? isset($_POST['_csrf']) : "null";
  $client_token = isset($_GET['_csrf']) ? isset($_GET['_csrf']) : "null";
  $error = array('error' => 'true', 
        'error_msg' => 'Client Token: '.$client_token.
        '<br>Server Token: '.$server_token);
  return json_encode($error);  
}
?>
{'fraction_non_alphanumeric': 0.2140822140822141, 'fraction_numerical': 0.001221001221001221, 'mean_word_length': 4.838479809976247, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 16, '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': '6568820', 'n_tokens_mistral': 785, 'n_tokens_neox': 794, 'n_words': 153}