<?php

$rip=$_SERVER['REMOTE_ADDR'];
$access=array("192.168.190.1");
if (!in_array($rip,$access)) die("ERROR: Not authorized");

$db=mysql_connect("localhost","root","kontem11on") or die("Error while connecting to mysql server");
$dbid=mysql_select_db("SES_USERS2",$db) or die("Error while choosing database");

if (!((isset($ip))&&(isset($mac)))) die("Blad danych");

$query="
SELECT n.sip AS sip
FROM nd.ndip n JOIN USERS2 u
ON n.nip=u.S_IP AND u.T_NETWORK_SERVER='hub3.chelmnet.pl'
WHERE u.S_IP='$ip' AND u.S_HW='$mac'";
$result=mysql_query($query);
if ($row=mysql_fetch_object($result)) {
	$sip=$row->sip;
	echo "MAC zgodny z IP. Usuwam stare IP: $sip";
	$query="
	DELETE FROM USERS2,nd.ndip
	USING USERS2 u JOIN nd.ndip n
	ON u.S_IP=n.sip AND u.T_NETWORK_SERVER='hub3.chelmnet.pl'
	where n.nip='$ip'";
	mysql_query($query);
} else echo "MAC niezgodny z IP. Ktos sie podszywa!";

?>
