Restrict saatavuus API to return only true/false
Requires exact match of osoite + postinumero + kaupunki. No longer exposes addresses, speeds, or any customer data. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
64
api.php
64
api.php
@@ -287,70 +287,40 @@ switch ($action) {
|
||||
break;
|
||||
}
|
||||
|
||||
$query = normalizeAddress($_GET['osoite'] ?? '');
|
||||
$postinumero = trim($_GET['postinumero'] ?? '');
|
||||
// Parametrit: osoite (kadunnimi + numero), postinumero, kaupunki
|
||||
$queryOsoite = normalizeAddress($_GET['osoite'] ?? '');
|
||||
$queryPostinumero = trim($_GET['postinumero'] ?? '');
|
||||
$queryKaupunki = strtolower(trim($_GET['kaupunki'] ?? ''));
|
||||
|
||||
if (empty($query) && empty($postinumero)) {
|
||||
if (empty($queryOsoite) || empty($queryPostinumero) || empty($queryKaupunki)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'Anna osoite tai postinumero']);
|
||||
echo json_encode(['error' => 'Anna osoite, postinumero ja kaupunki']);
|
||||
break;
|
||||
}
|
||||
|
||||
$customers = loadCustomers();
|
||||
$matches = [];
|
||||
$found = false;
|
||||
foreach ($customers as $c) {
|
||||
foreach ($c['liittymat'] ?? [] as $l) {
|
||||
$addr = normalizeAddress($l['asennusosoite'] ?? '');
|
||||
$zip = trim($l['postinumero'] ?? '');
|
||||
$city = strtolower(trim($l['kaupunki'] ?? ''));
|
||||
$hit = false;
|
||||
|
||||
// Postinumero-haku
|
||||
if (!empty($postinumero) && $zip === $postinumero) {
|
||||
$hit = true;
|
||||
}
|
||||
|
||||
// Osoitehaku (sisältää haun)
|
||||
if (!empty($query) && !empty($addr)) {
|
||||
if (strpos($addr, $query) !== false || strpos($query, $addr) !== false) {
|
||||
$hit = true;
|
||||
// Kaikki kolme pitää mätsätä: osoite, postinumero, kaupunki
|
||||
if ($zip === $queryPostinumero && $city === $queryKaupunki) {
|
||||
// Osoite-match: tarkka sisältö-match
|
||||
if (!empty($addr) && !empty($queryOsoite)) {
|
||||
if (strpos($addr, $queryOsoite) !== false || strpos($queryOsoite, $addr) !== false) {
|
||||
$found = true;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
// Kadunnimi-match (ilman numeroa)
|
||||
$queryStreet = trim(preg_replace('/\d+.*$/', '', $query));
|
||||
$addrStreet = trim(preg_replace('/\d+.*$/', '', $addr));
|
||||
if (!empty($queryStreet) && !empty($addrStreet) && strpos($addrStreet, $queryStreet) !== false) {
|
||||
$hit = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($hit) {
|
||||
// Palauta VAIN osoitetieto ja nopeus - ei asiakastietoja
|
||||
$matches[] = [
|
||||
'osoite' => $l['asennusosoite'] ?? '',
|
||||
'postinumero' => $zip,
|
||||
'kaupunki' => $l['kaupunki'] ?? '',
|
||||
'nopeus' => $l['liittymanopeus'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Poista duplikaatit (sama osoite eri asiakkailla)
|
||||
$unique = [];
|
||||
$seen = [];
|
||||
foreach ($matches as $m) {
|
||||
$key = normalizeAddress($m['osoite'] . $m['postinumero']);
|
||||
if (!isset($seen[$key])) {
|
||||
$unique[] = $m;
|
||||
$seen[$key] = true;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'saatavilla' => count($unique) > 0,
|
||||
'kohteet' => $unique,
|
||||
'maara' => count($unique),
|
||||
]);
|
||||
// Palauta VAIN true/false - ei osoitteita, nopeuksia tai muuta dataa
|
||||
echo json_encode(['saatavilla' => $found]);
|
||||
break;
|
||||
|
||||
// ---------- CONFIG (admin) ----------
|
||||
|
||||
Reference in New Issue
Block a user