diff --git a/api.php b/api.php index 24459e7..d29e190 100644 --- a/api.php +++ b/api.php @@ -1227,10 +1227,21 @@ switch ($action) { if (!$exists) { $ip = getClientIp(); $hostname = @gethostbyaddr($ip) ?: ''; - if ($hostname === $ip) $hostname = ''; // gethostbyaddr palauttaa IP:n jos ei löydy + if ($hostname === $ip) $hostname = ''; + // Hae IP-osoitteen organisaatio/ISP ip-api.com:sta + $org = ''; + try { + $ipApiUrl = "http://ip-api.com/json/{$ip}?fields=org,isp,as"; + $ctx = stream_context_create(['http' => ['timeout' => 3]]); + $ipJson = @file_get_contents($ipApiUrl, false, $ctx); + if ($ipJson) { + $ipData = json_decode($ipJson, true); + $org = $ipData['org'] ?? $ipData['isp'] ?? ''; + } + } catch (\Throwable $e) { /* IP-haku ei saa kaataa API:a */ } _dbExecute( - "INSERT INTO availability_queries (company_id, osoite, postinumero, kaupunki, saatavilla, ip_address, hostname, user_agent, referer, created_at) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "INSERT INTO availability_queries (company_id, osoite, postinumero, kaupunki, saatavilla, ip_address, hostname, org, user_agent, referer, created_at) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [ $matchedCompany['id'], $rawOsoite, @@ -1239,6 +1250,7 @@ switch ($action) { $found ? 1 : 0, $ip, $hostname, + $org, substr($_SERVER['HTTP_USER_AGENT'] ?? '', 0, 500), substr($_SERVER['HTTP_REFERER'] ?? '', 0, 500), date('Y-m-d H:i:s'), @@ -1267,7 +1279,7 @@ switch ($action) { $total = (int)_dbFetchScalar("SELECT COUNT(*) FROM availability_queries WHERE company_id IN ($placeholders)", $userCompanyIds); $params = array_merge($userCompanyIds, [$limit, $offset]); $rows = _dbFetchAll( - "SELECT aq.id, aq.company_id, c.nimi as company_nimi, aq.osoite, aq.postinumero, aq.kaupunki, aq.saatavilla, aq.ip_address, aq.hostname, aq.referer, aq.created_at + "SELECT aq.id, aq.company_id, c.nimi as company_nimi, aq.osoite, aq.postinumero, aq.kaupunki, aq.saatavilla, aq.ip_address, aq.hostname, aq.org, aq.referer, aq.created_at FROM availability_queries aq LEFT JOIN companies c ON c.id = aq.company_id WHERE aq.company_id IN ($placeholders) ORDER BY aq.created_at DESC LIMIT ? OFFSET ?", $params @@ -5398,8 +5410,8 @@ switch ($action) { $to = !empty($input['to']) ? trim($input['to']) : ($ticket['from_email'] ?? ''); $cc = !empty($input['cc']) ? trim($input['cc']) : ''; - // Muunna uusi viesti HTML:ksi - $newMsgHtml = nl2br(htmlspecialchars($body, ENT_QUOTES, 'UTF-8')); + // Muunna uusi viesti HTML:ksi (säilytä rivinvaihdot ja välilyönnit) + $newMsgHtml = '
Nettisivujen kautta tehdyt saatavuustarkistukset
-| Aika | -Osoite | -Postinumero | -Kaupunki | -Tulos | -IP / Verkko | -Lähde | -Yritys | -
|---|
Nettisivujen kautta tehdyt saatavuustarkistukset
+ +| Aika | +Osoite | +Postinumero | +Kaupunki | +Tulos | +IP / Verkko | +Organisaatio | +Lähde | +Yritys | +
|---|