<?php

$directory = $_SERVER['HOME'] . '/htdocs' . dirname($_SERVER['PHP_SELF']);
if (!isset($_POST['password']) &&
    empty($_POST['password'])) {
	header('HTTP/1.0 200 OK');
	readfile($directory.'/password-form.html');
	exit;
} // if
$password = strtoupper(trim($_POST['password']));

$exit = null;
foreach (glob('secret*.html.gpg') as $file) {

	$command = "echo '{$password}' | /usr/bin/gpg ".
		"--batch ".
		"--passphrase-fd 0 ".
		"--decrypt ".
		$file;

	exec($command, $html, $exit);

	if ($exit !== 0) {
		continue;
	} else {
		break;
	} // if
} // foreach

if ($exit !== 0) {
	header('HTTP/1.0 403 Forbidden');
	readfile(__DIR__.'/error.html');
	exit;
} // if

echo join("\n", $html);

?>
