<?PHP
header("content-type: text/plain");
include "pplib.inc.php";
if (!isset($_REQUEST["mand"]) || !isset($_REQUEST["auth"])) {
	die (time()." [FAILURE] - mand and auth paramenter needed!");
}
$sqlcmd = "SELECT * FROM $dbname.pplant WHERE PPLANT_Caption='".ppaddslashes($_REQUEST["mand"])."' AND PPLANT_HostPWD='".ppaddslashes($_REQUEST["auth"])."' LIMIT 1";
$result = mysqli_query($ppconf["mysqli_linkid"], $sqlcmd);
if ($myrow = mysqli_fetch_array($result)) {
	$host = "unknown";
    /* update for PHP5.4+
	if (isset($_ENV["REMOTE_ADDR"])) $host=$_ENV["REMOTE_ADDR"];
    if (isset($HTTP_ENV_VARS["REMOTE_ADDR"])) $host=$HTTP_ENV_VARS["REMOTE_ADDR"];
    if (isset($HTTP_SERVER_VARS["REMOTE_ADDR"])) $host=$HTTP_SERVER_VARS["REMOTE_ADDR"];
	*/
	$host = $_SERVER['HTTP_HOST'];
    if ($host == "unknown") {
    	echo time()." [FAILURE] Authorization failed - could not resolve your host address.";
    } else {
    	$sqlcmd = "UPDATE $dbname.pplant SET PPLANT_CurrentHost='".ppaddslashes($host)."' WHERE PPLANT_ID='".ppaddslashes($myrow["PPLANT_ID"])."' LIMIT 1";
    	mysqli_query($ppconf["mysqli_linkid"], $sqlcmd);
    	echo time()." [SUCCESS] Authorized host updated from '".htmlspecialchars($myrow["PPLANT_CurrentHost"])."' to '".htmlspecialchars($host)."'.";
    }
} else {
	echo time()." [FAILURE]Authorization failed: Invalid mand or auth argument.";
}
mysqli_free_result($result);


