<?php
// add more IP addresses if you are running the cron jobs from another host
$allowip = array();
//$allowip[] = '127.0.0.1';											// acceptable ip address - Loop back IP
//$allowip[] = (string)$_SERVER['SERVER_ADDR'];						// acceptable ip address - Server own IP
//$allowip[] = 'ADD MORE IP';										// acceptable ip address - Secured Host (Optional to setup)
//$allowip[] = 'ADD MORE IP';										// acceptable ip address - Secured Host (Optional to setup)

$tabs = array();
$tabs[] = 'route=product/auction/auctionglobalvalidateactive';		// 1 = global validate active auctions
$tabs[] = 'route=product/auction/auctionglobalvalidatewon';			// 2 = global validate ended auctions (won / buyout)
$tabs[] = 'route=product/auction/auctionglobalvalidateintegrity';	// 3 = global validate active auctions integrity
$tabs[] = 'route=product/auction/auctionglobalsendnotification';	// 4 = global send auction email notifications

if (!$allowip || ($allowip && in_array((string)$_SERVER['REMOTE_ADDR'], $allowip))) {
	foreach ($tabs as $tab) {
		$auth = '&auth=' . urlencode(sha1(time()));
		file_get_contents(getLocalhostURL('') . "?" . $tab . $auth);
	}
}

function accessPublicFunctionBySocket($url, $params) {
	$parts = parse_url($url);
	$fsock = fsockopen($parts['host'], $parts['port'], $errno, $errstr, 15);
	stream_set_blocking($fsock, false);
	stream_set_timeout($fsock, 15);
	if ($fsock) {
		$out = "GET " . $parts['path'] . "?" . $params . " HTTP/1.1\r\n";
		$out .= "Host: " . $parts['host'] . "\r\n";
		$out .= "Connection: Close\r\n\r\n";
		fwrite($fsock, $out);
		fclose($fsock);
	}
}

function getLocalhostURL($server_path) {
	$server_prefix = !empty($_SERVER['HTTPS']) ? "https://" : "http://";
	$server_name = $_SERVER['SERVER_NAME'];
	$server_port = ":" . $_SERVER['SERVER_PORT'];
	$server_path = dirname($_SERVER['SCRIPT_NAME']) == "/" ? "" : dirname($_SERVER['SCRIPT_NAME']);
	$server_root = "/index.php";
	return $server_prefix . $server_name . $server_port . $server_path . $server_root;
}

exit();
?>