<?php
/**
 * BIND Zone File Recovery - LucasIT Standard
 */

function sanitize_network_input($input) {
 $input = preg_replace('/\s+/', '', $input);
 $input = preg_replace('/[^a-zA-Z0-9\.\-\:]/', '', $input);
 return (!empty($input)) ? $input : false;
}

$target = isset($_POST['target']) ? sanitize_network_input($_POST['target']) : '';
$info_lines = [];
$results = "";

if ($target) {
 $safe_target = escapeshellarg($target);
 $raw_output = [];
 // Execution of the recovery script
 exec("dns-zone-recovery.py $safe_target", $raw_output);

 if (!empty($raw_output)) {
     // Join array into a single string for the pre block
     $results = implode("\n", $raw_output);
 }
}
?>
<html>
    <head>
        <title>Lucas IT Services - BIND Zone File Recovery</title>
        <link rel="icon" href="../images/favicon.ico" sizes="16x16 24x24 32x32 48x48 64x64" type="image/vnd.microsoft.icon"/>
        <link href="../css/tools.css?v=2.1" rel="stylesheet" type="text/css">
        <meta charset="UTF-8" />
        <meta name="google" content="notranslate" />
        <meta http-equiv="Content-Language" content="en_US" />
    </head>
    <body>
        <img src="../images/Logo.png" width="96" height="96"/>
        <p><font size="+4">BIND Zone File Recovery</font></p>

        <form method="POST">
            <div style="margin-bottom: 10px; display: flex; align-items: center;">
                Domain: &nbsp;
                <input type="text" name="target" class="input-field" style="width: 260px;" placeholder="Domain Name" value="<?= htmlspecialchars($target) ?>" autocomplete="off">
                &nbsp;
                <a href="javascript:void(0)" onclick="this.closest('form').submit();"><div class="button">Generate</div></a>
                &nbsp;
                <a href="./"><div class="button">Reset</div></a>
            </div>
        </form>

        <?php if ($target): ?>
            <br/>
            
            <?php if (!empty($results)): ?>
                <div class="boxed">
                    <pre style="white-space: pre-wrap; font-family: monospace; padding: 10px;"><?php echo htmlspecialchars($results); ?></pre>
                </div>
            <?php else: ?>
                <p>No results returned from the generator.</p>
            <?php endif; ?>
        <?php endif; ?>

        <p><a href="index.phps">View Source</a> |  <a href="../">Back to Tools</a></p>
    </body>
</html>