function validate_from_regex($conf, $items, $checker) { $regexes = $conf['regexes_for_check']; $items_final = $items; $source_found = ""; if (count($regexes) > 0) { $i = 0; while ($i < count($regexes) && $source_found == "") { $regex = $regexes[$i]; if (count($regex) > 0 && count($regex) == 2) { $network_source = explode("/", $regex[0]); $ip = $network_source[0]; $netmask = $network_source[1]; if (preg_match("/" . $conf['ipV4v6_regex'] . "/", $ip) === 1 && 0 <= $netmask && $netmask < 33) { if (netmask($ip, $netmask) == netmask($checker, $netmask)) { $source_found = $regex[1]; } } else { $checker_host = getHostFromAddrWithDNS($conf, $checker); if ($checker_host != -1) { if (preg_match($regex[0], $checker_host) == 1) { $source_found = $regex[1]; } } else { $checker_host = gethostbyaddr($checker); if (preg_match($regex[0], $checker_host) == 1) { $source_found = $regex[1]; } } } } $i++; } if ($source_found != "") { foreach ($items as $item) { $regex_ip = explode("/", $source_found); $ip = $regex_ip[0]; $netmask = $regex_ip[1]; $item_explode = explode(":", $item['item']); if (preg_match("/" . $conf['ipV4v6_regex'] . "/", $ip) == 1 && 0 <= $netmask && $netmask < 33) { if (preg_match("/" . $conf['ipV4v6_regex'] . "/", $item_explode[0]) == 0) { $item_ip = gethostbyname($item_explode[0]); } else { $item_ip = $item_explode[0]; } if (netmask($ip, $netmask) != netmask($item_ip, $netmask)) { array_splice($items_final, array_search($item, $items_final), 1); } } else { if (preg_match("/" . $conf['ipV4v6_regex'] . "/", $item_explode[0]) === 1) { $item_host = gethostbyaddr($item_explode[0]); } else { $item_host = $item_explode[0]; } if (preg_match($source_found, $item_host) === 0 || preg_match($source_found, $item_host) === false) { array_splice($items_final, array_search($item, $items_final), 1); } } } } else { $items_final = array(); } } if (count($items_final) == 0) { if ($conf['concordance'] == "inclusive") { return $items; } else { if ($conf['concordance'] == "exclusive") { return $items_final; } else { error_log("Configuration error for the variable 'concordance'. Possible values are exclusive or inclusive."); } } } else { return $items_final; } }
$host_line = $result[count($result) - 1]; $host_line_explode = explode("domain name pointer", $host_line); $host = $host_line_explode[1]; return $host; } else { return -1; } } $host = trim(htmlspecialchars($_POST['host'])); $protocole = trim(htmlspecialchars($_POST['protocole'])); $port = trim(htmlspecialchars($_POST['port'])); $string = trim(htmlspecialchars($_POST['string'])); $result_app = trim(htmlspecialchars($_POST['result'])); $id = trim(htmlspecialchars($_POST['id'])); $ip = $_SERVER['REMOTE_ADDR']; $hostname = getHostFromAddrWithDNS($conf, $ip); if ($hostname == -1) { $hostname = gethostbyaddr($ip); } $version = trim(htmlspecialchars($_POST['version'])); $item = $host . ":" . $protocole . ":" . $port . ":" . $string; $latency = trim(htmlspecialchars($_POST['date'])); $checktimestamp = date('Y/m/d H:i:s', time()); $checktimestamp_log = time(); $clean = $conf['check_lifetime']; /* * Function to connect to db */ function connexionbdd($conf) { try {