MACC
"pass",
"dst_net" => "any",
"src_net" => $ip,
"service" => "8444"
]);
$ch = curl_init(API_URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Basic ' . API_TOKEN
]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
if (curl_errno($ch)) {
return 'Error: ' . curl_error($ch);
}
curl_close($ch);
return $result;
}
// Main logic with enhanced error handling and messaging
if ($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET["id"])) {
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_STRING);
$code = generateCode();
$_SESSION["code"] = $code;
$_SESSION["id"] = $id;
if (sendEmail($code)) {
echo '
Verification code sent to email. Please enter it below.
';
echo '
';
} else {
echo '
Failed to send verification code. Please try again later.
';
}
} elseif ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["entered_code"])) {
$entered_code = filter_input(INPUT_POST, 'entered_code', FILTER_SANITIZE_STRING);
if ($entered_code == $_SESSION["code"]) {
$ip = $_SERVER["REMOTE_ADDR"];
$result = addIPException($ip);
echo '
Verification successful. Your IP has been added to the exception list.
';
} else {
echo '
Invalid code. Please try again.
';
}
} else {
echo '
Invalid request.
';
}
?>