$cat, 'id' => $id)); if ($row !== false && $row['dateline'] >= time()) { return $cache[$key] = $row['value']; } if (!$dnsQuery) return false; // Unknown, query if ($cat === self::DEVICE && preg_match('/^([a-f0-9]{4}):([a-f0-9]{4})$/', $id, $out)) { $host = $out[2] . '.' . $out[1]; } elseif ($cat === self::VENDOR && preg_match('/^([a-f0-9]{4})$/', $id, $out)) { $host = $out[1]; } elseif ($cat === self::DEVCLASS && preg_match('/^c\.([a-f0-9]{2})([a-f0-9]{2})$/', $id, $out)) { $host = $out[2] . '.' . $out[1] . '.c'; } else { error_log("getPciId called with unknown format: ($cat) ($id)"); return false; } $res = dns_get_record($host . '.pci.id.ucw.cz', DNS_TXT); if (!is_array($res)) return false; foreach ($res as $entry) { if (isset($entry['txt']) && substr($entry['txt'], 0, 2) === 'i=') { $string = substr($entry['txt'], 2); Database::exec('INSERT INTO pciid (category, id, value, dateline) VALUES (:cat, :id, :value, :timeout)' . ' ON DUPLICATE KEY UPDATE value = VALUES(value), dateline = VALUES(dateline)', array( 'cat' => $cat, 'id' => $id, 'value' => $string, 'timeout' => time() + mt_rand(10, 30) * 86400, ), true); return $cache[$key] = $string; } } return $cache[$key] = ($row['value'] ?? false); } }