<?php require_once "header.php"; ?>
<?php
if(isset($_GET['domain']) !== false) {
    $placeholder = htmlentities($_GET['domain']);
} else {
    $placeholder = 'domain';
}
?>
<h1>Subdo Finder</h1>
<form method="GET" action="" class="form-inline my-2 my-lg-0">
	Find : <input type="text" class="form-control mr-sm-2" name="domain" placeholder="<?php echo $placeholder ?>"> 
	<input type="submit" class="btn btn-primary my-2 my-sm-0" value="Search">
</form>
<?php
error_reporting(0);
header("X-Frame-Options: DENY");
header("Content-Security-Policy: frame-ancestors 'none'", false);
$domain = $_GET['domain'];
if (isset($_GET['domain'])) {
	$domain = $_GET['domain'];
	function http_request($url){
	    $ch = curl_init();
	    curl_setopt($ch, CURLOPT_URL, $url);
	    curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	    $output = curl_exec($ch); 
	    curl_close($ch);      
	    return $output;
	}

	$request = http_request("https://www.threatcrowd.org/searchApi/v2/domain/report/?domain=".$domain);
	$request = json_decode($request, TRUE);
	echo 'Total: '.count($request['subdomains']).' Subdomain<br/>
		<div style="color:#dbd9d9;"><table border="1" class="table">
		<tr>
			<th width=5><span style="color:black;">No</span></th>
			<th><span style="color:black;">Subdomain</span></th>	
		</tr>';
    $nomor = 1;
    
	foreach ($request['subdomains'] as $key => $value) {
        echo "<tr style='color:#dbd9d9;'>
                <td><span style='color:black;'>".$nomor++."</span></td>
                <td><a href='http://".htmlentities($value)."' target='_blank'>".htmlentities($value)."</a></td>
                </tr>";
	}
}
?>