0) return $number_licenses; else return 0; } function number_samples($sample) { $sql_number_samples = mysql_query("SELECT sample FROM compescor_sample WHERE sample = '$sample'"); $number_samples = mysql_num_rows($sql_number_samples); if ($number_samples >0) return $number_samples; else return 0; } function breach($number_samples) { //$sql_number_samples = mysql_query("SELECT sample FROM compescor_sample WHERE sample = '$sample'"); //$number_samples = mysql_num_rows($sql_number_samples); if ($number_samples > number_licenses()) return true; else return false; } function existing_breach($sample) { $sql_number_breaches = mysql_query("SELECT sample FROM compescor_breaches WHERE sample = '$sample'"); $number_breaches = mysql_num_rows($sql_number_breaches); if ($number_breaches >0) return true; else return false; } function log_breach($sample, $number_samples) { if (existing_breach($sample)) { // update $sql_update_breach = mysql_query("UPDATE compescor_breaches SET number_samples = '$number_samples' WHERE sample = '$sample'"); } else { // insert $sql_insert_breach = mysql_query("INSERT INTO compescor_breaches (sample, number_samples, number_licences) VALUES ('$sample', '$number_samples', '".number_licenses()."')"); } } function new_sample($ip) { // use this if mysql_insert_id() proves not to work // have to check for new sample in order to test breach but this does not // necessarily have to be used if mysql_insert_id() works $sql_number_samples = mysql_query("SELECT ip FROM compescor_samples WHERE ip = '$ip'"); $number_samples = mysql_num_rows($sql_number_samples); if ($number_samples == 0) return true; else return false; } function validip($ip) { if (!empty($ip) && ip2long($ip)!=-1) { $reserved_ips = array ( array('0.0.0.0','2.255.255.255'), array('10.0.0.0','10.255.255.255'), array('127.0.0.0','127.255.255.255'), array('169.254.0.0','169.254.255.255'), array('172.16.0.0','172.31.255.255'), array('192.0.2.0','192.0.2.255'), array('192.168.0.0','192.168.255.255'), array('255.255.255.0','255.255.255.255') ); foreach ($reserved_ips as $r) { $min = ip2long($r[0]); $max = ip2long($r[1]); if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false; } return true; } else { return false; } } function getip() { if (validip($_SERVER["HTTP_CLIENT_IP"])) { return $_SERVER["HTTP_CLIENT_IP"]; } foreach (explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]) as $ip) { if (validip(trim($ip))) { return $ip; } } if (validip($_SERVER["HTTP_X_FORWARDED"])) { return $_SERVER["HTTP_X_FORWARDED"]; } elseif (validip($_SERVER["HTTP_FORWARDED_FOR"])) { return $_SERVER["HTTP_FORWARDED_FOR"]; } elseif (validip($_SERVER["HTTP_FORWARDED"])) { return $_SERVER["HTTP_FORWARDED"]; } elseif (validip($_SERVER["HTTP_X_FORWARDED"])) { return $_SERVER["HTTP_X_FORWARDED"]; } else { return $_SERVER["REMOTE_ADDR"]; } } function login_log() { // Logs who has logged on and when $sql = mysql_query("INSERT INTO mya_logins (account_id, datestamp, host_ip, host_addr) VALUES ('".$_SESSION["account_id"]."', '".time()."', '".getip()."', '".gethostbyaddr(getip())."')"); $result = mysql_query($sql); } ?>