<commit_before><?php
  include(__DIR__.'/config.php');
  header('Content-type: text/html');
  header('X-Backend-Hints: "ClientIP.loadIndex"');
?><!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="shortcut icon" href="<?= $config->faviconfile ?>" />
<title data-i18n="general_page_title"></title>
<?php
  script_tag('/bower_components/jquery/jquery.min.js');
?>
<script type="text/javascript">
  window.contestsRoot = <?= json_encode(upgrade_url($config->teacherInterface->sAbsoluteStaticPath.'/contests')) ?>;
  window.sAbsoluteStaticPath = <?= json_encode(upgrade_url($config->teacherInterface->sAbsoluteStaticPath.'/')) ?>;
  window.sAssetsStaticPath = <?= json_encode(upgrade_url($config->teacherInterface->sAssetsStaticPath.'/')) ?>;
  window.timestamp = <?= $config->timestamp ?>;
  window.config = <?= json_encode([
    "httpsTestUrl" => $config->contestInterface->httpsTestUrl,
    "imagesURLReplacements" => $config->imagesURLReplacements,
    "imagesURLReplacementsNonStatic" => $config->imagesURLReplacementsNonStatic,
    "redirectToHTTPS" => !!$config->contestInterface->redirectToHTTPS,
    "redirectToHTTPSIfError" => !!$config->redirectToHTTPSIfError,
    "upgradeToHTTPS" => $config->upgradeToHTTPS,
    "logActivity" => $config->contestInterface->logActivity
    ]) ?>;

  function checkHttps() {
    // Test HTTPS connectivity, downgrade to HTTP if HTTPS doesn't work
    if(!window.config.httpsTestUrl) {
      return;
    }
    $.ajax({
      url: window.config.httpsTestUrl,
      timeout: 10000
      })
      .success(function() {
        if(window.config.redirectToHTTPS && window.location.protocol != 'https:') {
          window.location.href = 'https:' + window.location.href.substring(window.location.protocol.length);
        }
      })
      .fail(function() {
        window.config.downgradeToHTTP = true;
      });
  }
  checkHttps();
</script>
</head>
<?php
  flush();
  stylesheet_tag('/style.css');
?>
<body>
<div id="divHeader">
  <div id="leftTitle" data-i18n="[html]left_title"></div>
  <div id="headerGroup">
    <h1 id="headerH1" data-i18n="general_title"></h1>
    <h2 id="headerH2" data-i18n="general_subtitle"></h2><commit_msg>contestInterface: Hide body while testing HTTPS<commit_after><?php
  include(__DIR__.'/config.php');
  header('Content-type: text/html');
  header('X-Backend-Hints: "ClientIP.loadIndex"');
?><!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="shortcut icon" href="<?= $config->faviconfile ?>" />
<title data-i18n="general_page_title"></title>
<?php
  script_tag('/bower_components/jquery/jquery.min.js');
?>
<script type="text/javascript">
  window.contestsRoot = <?= json_encode(upgrade_url($config->teacherInterface->sAbsoluteStaticPath.'/contests')) ?>;
  window.sAbsoluteStaticPath = <?= json_encode(upgrade_url($config->teacherInterface->sAbsoluteStaticPath.'/')) ?>;
  window.sAssetsStaticPath = <?= json_encode(upgrade_url($config->teacherInterface->sAssetsStaticPath.'/')) ?>;
  window.timestamp = <?= $config->timestamp ?>;
  window.config = <?= json_encode([
    "httpsTestUrl" => $config->contestInterface->httpsTestUrl,
    "imagesURLReplacements" => $config->imagesURLReplacements,
    "imagesURLReplacementsNonStatic" => $config->imagesURLReplacementsNonStatic,
    "redirectToHTTPS" => !!$config->contestInterface->redirectToHTTPS,
    "redirectToHTTPSIfError" => !!$config->redirectToHTTPSIfError,
    "upgradeToHTTPS" => $config->upgradeToHTTPS,
    "logActivity" => $config->contestInterface->logActivity
    ]) ?>;

  function displayBody() {
    // Display the page
    var body = document.getElementsByTagName("body");
    if(body && body[0]) {
      body[0].style.display = "block";
    } else {
      setTimeout(displayBody, 100);
    }
  }
  function checkHttps() {
    // Test HTTPS connectivity, downgrade to HTTP if HTTPS doesn't work
    try {
      if(!window.config.httpsTestUrl) {
        displayBody();
        return;
      }
      if(!window.config.redirectToHTTPS || window.location.protocol == 'https:') {
        displayBody();
      }
      $.ajax({
        url: window.config.httpsTestUrl,
        timeout: 2000
        })
        .success(function() {
          if(window.config.redirectToHTTPS && window.location.protocol != 'https:') {
            window.location.href = 'https:' + window.location.href.substring(window.location.protocol.length);
          }
        })
        .fail(function() {
          window.config.downgradeToHTTP = true;
          displayBody();
        });
    } catch(e) {
      displayBody();
    }
  }
  checkHttps();

  // Failsafe to display the body after 2 seconds even if checkHttps somehow
  // had an error
  setTimeout(displayBody, 2000);
</script>
</head>
<?php
  flush();
  stylesheet_tag('/style.css');
?>
<body style="display: none;">
<div id="divHeader">
  <div id="leftTitle" data-i18n="[html]left_title"></div>
  <div id="headerGroup">
    <h1 id="headerH1" data-i18n="general_title"></h1>
    <h2 id="headerH2" data-i18n="general_subtitle"></h2>
{'fraction_non_alphanumeric': 0.17432800934943513, 'fraction_numerical': 0.009544215037008181, 'mean_word_length': 4.119641076769691, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 111, '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': '783695', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1658, 'n_words': 245}