You are here

function letsencrypt_challenge_challenge in Let's Encrypt Challenge 7

Page callback: Output the configured challenge.

1 string reference to 'letsencrypt_challenge_challenge'
letsencrypt_challenge_menu in ./letsencrypt_challenge.module
Implements hook_menu().

File

./letsencrypt_challenge.module, line 79
Main module file.

Code

function letsencrypt_challenge_challenge($filename = '') {

  // Let's make sure that this page is not cached.
  drupal_page_is_cacheable(FALSE);

  // If a file is found, that takes precedence.
  if (!empty($filename)) {
    $challenge_file = 'public://letsencrypt_challenge/' . $filename;
    if (file_exists($challenge_file)) {
      print file_get_contents($challenge_file);
      drupal_exit();
    }
  }
  $challenge = variable_get('letsencrypt_challenge', '');
  if (empty($challenge)) {
    print t("The URL is working, but the challenge is empty. Please configure.");
  }
  else {
    $challenge = trim($challenge);
    if (strpos($challenge, "\n") !== FALSE) {
      $challenges = explode("\n", $challenge);
      foreach ($challenges as $challenge) {
        if (strncmp($filename, $challenge, strlen($filename)) === 0) {
          break;
        }
      }
    }
    print $challenge;
  }
  drupal_exit();
}