<?php
/*
	$link = @mysqli_connect("localhost", "loginform", "HFDERHGUSDFgfd", "osup2020");
	$sql = "SELECT attempts FROM login_logs_hash
			WHERE ip = INET6_ATON('".$_SERVER['REMOTE_ADDR']."')";
	$result = @mysqli_query($link, $sql);
	$row = mysqli_fetch_assoc($result);
	if(isset($row['attempts']) && $row['attempts']>3){
		echo 'Your IP is blocked. Contact the admins';
		exit;
	}
	*/
if(isset($_POST['user'])){
	$link = @mysqli_connect("localhost", "loginform", "HFDERHGUSDFgfd", "osup2020");
	$sql = "SELECT 1 AS blocked
			FROM login_logs
			WHERE (		ip = INET6_ATON('".$_SERVER['REMOTE_ADDR']."')
							AND
						attempts > 3
							AND
						uid = (
								SELECT id FROM users
								WHERE user='".@mysqli_real_escape_string($link, $_POST['user'])."'
							)
							AND
						DATE_ADD(last_attempt, INTERVAL 1 MINUTE) > NOW()
					)
					OR
					(
						10 < ( SELECT SUM(attempts) FROM login_logs
							   WHERE ip = INET6_ATON('".$_SERVER['REMOTE_ADDR']."'))
					)
					OR
					(
						20 < (SELECT SUM(attempts) FROM login_logs
							  WHERE uid = (SELECT id FROM users WHERE user='".@mysqli_real_escape_string($link, $_POST['user'])."'
							  ))
							 AND
						ip = INET6_ATON('".$_SERVER['REMOTE_ADDR']."')
								 AND
						attempts > 1
					)
			";

	$result = @mysqli_query($link, $sql);
	$row = @mysqli_fetch_assoc($result);
	if(isset($row['blocked'])){
		echo 'Your IP is blocked.';
		exit;
	}
}
?>