+function checkKey($key, $host)
+{
+ $fh = @fopen('/etc/nagios3/nagcollect.keys', 'r');
+ if (!$fh) {
+ error_log("NagCollect: can't open \"/etc/nagios3/nagcollect.keys\"!");
+ return false;
+ }
+ while ($str = fgets($fh, 1024)) {
+ $str = trim($str);
+ if (!$str || $str[0] == '#' || $str[0] == '/')
+ continue;
+ $p = strpos($str, ':');
+ if ($p)
+ $str = trim(substr($str, 0, $p));
+ if ($str == $key) {
+ fclose($fh);
+ return true;
+ }
+ }
+ fclose($fh);
+ error_log("NagCollect: received invalid key \"$key\"!");
+ return false;
+}
+