diff options
Diffstat (limited to 'modules-available/statistics/page.inc.php')
-rw-r--r-- | modules-available/statistics/page.inc.php | 50 |
1 files changed, 5 insertions, 45 deletions
diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index 3e4aa9ce..d26649b6 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -264,60 +264,20 @@ class Page_Statistics extends Page $add = ''; if (preg_match('/^([a-f0-9]{4}):([a-f0-9]{4})$/', $param, $out)) { $cat = 'DEVICE'; - $host = $out[2] . '.' . $out[1]; $add = ' (' . $param . ')'; } elseif (preg_match('/^([a-f0-9]{4})$/', $param, $out)) { $cat = 'VENDOR'; - $host = $out[1]; } elseif (preg_match('/^c\.([a-f0-9]{2})([a-f0-9]{2})$/', $param, $out)) { $cat = 'CLASS'; - $host = $out[2] . '.' . $out[1] . '.c'; } else { die('Invalid format requested'); } - $cached = Page_Statistics::getPciId($cat, $param); - if ($cached !== false && $cached['dateline'] > time()) { - echo $cached['value'], $add; - exit; + $cached = PciId::getPciId($cat, $param, true); + if ($cached === false) { + $cached = 'Unknown'; } - $res = dns_get_record($host . '.pci.id.ucw.cz', DNS_TXT); - if (is_array($res)) { - foreach ($res as $entry) { - if (isset($entry['txt']) && substr($entry['txt'], 0, 2) === 'i=') { - $string = substr($entry['txt'], 2); - Page_Statistics::setPciId($cat, $param, $string); - echo $string, $add; - exit; - } - } - } - if ($cached !== false) { - echo $cached['value'], $add; - exit; - } - die('Not found'); - } - - public static function getPciId($cat, $id) - { - static $cache = []; - $key = $cat . '-' . $id; - if (isset($cache[$key])) - return $cache[$key]; - return $cache[$key] = Database::queryFirst('SELECT value, dateline FROM pciid WHERE category = :cat AND id = :id LIMIT 1', - array('cat' => $cat, 'id' => $id)); - } - - private static function setPciId($cat, $id, $value) - { - 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' => $value, - 'timeout' => time() + mt_rand(10, 30) * 86400, - ), true); + echo $cached, $add; + exit; } } |