mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-02 17:13:20 +02:00
Preparation for better IP whitelisting
This commit is contained in:
parent
b3113da4f4
commit
bb5d34e0f0
3 changed files with 57 additions and 0 deletions
|
@ -46,4 +46,23 @@ function isIpWhitelisted($ip, $pdo) {
|
|||
$stmt->execute([$ip]);
|
||||
$count = $stmt->fetchColumn();
|
||||
return $count > 0;
|
||||
}
|
||||
|
||||
// Function to update the permitted IPs from the database
|
||||
function updatePermittedIPs($pool, $permittedIPsTable) {
|
||||
$pdo = $pool->get();
|
||||
$query = "SELECT addr FROM registrar_whitelist";
|
||||
$stmt = $pdo->query($query);
|
||||
$permittedIPs = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
$pool->put($pdo);
|
||||
|
||||
// Manually clear the table by removing each entry
|
||||
foreach ($permittedIPsTable as $key => $value) {
|
||||
$permittedIPsTable->del($key);
|
||||
}
|
||||
|
||||
// Insert new values
|
||||
foreach ($permittedIPs as $ip) {
|
||||
$permittedIPsTable->set($ip, ['addr' => $ip]);
|
||||
}
|
||||
}
|
|
@ -98,4 +98,23 @@ function isIpWhitelisted($ip, $pdo) {
|
|||
$stmt->execute([$ip]);
|
||||
$count = $stmt->fetchColumn();
|
||||
return $count > 0;
|
||||
}
|
||||
|
||||
// Function to update the permitted IPs from the database
|
||||
function updatePermittedIPs($pool, $permittedIPsTable) {
|
||||
$pdo = $pool->get();
|
||||
$query = "SELECT addr FROM registrar_whitelist";
|
||||
$stmt = $pdo->query($query);
|
||||
$permittedIPs = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
$pool->put($pdo);
|
||||
|
||||
// Manually clear the table by removing each entry
|
||||
foreach ($permittedIPsTable as $key => $value) {
|
||||
$permittedIPsTable->del($key);
|
||||
}
|
||||
|
||||
// Insert new values
|
||||
foreach ($permittedIPs as $ip) {
|
||||
$permittedIPsTable->set($ip, ['addr' => $ip]);
|
||||
}
|
||||
}
|
|
@ -58,4 +58,23 @@ function isIpWhitelisted($ip, $pdo) {
|
|||
$stmt->execute([$ip]);
|
||||
$count = $stmt->fetchColumn();
|
||||
return $count > 0;
|
||||
}
|
||||
|
||||
// Function to update the permitted IPs from the database
|
||||
function updatePermittedIPs($pool, $permittedIPsTable) {
|
||||
$pdo = $pool->get();
|
||||
$query = "SELECT addr FROM registrar_whitelist";
|
||||
$stmt = $pdo->query($query);
|
||||
$permittedIPs = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
$pool->put($pdo);
|
||||
|
||||
// Manually clear the table by removing each entry
|
||||
foreach ($permittedIPsTable as $key => $value) {
|
||||
$permittedIPsTable->del($key);
|
||||
}
|
||||
|
||||
// Insert new values
|
||||
foreach ($permittedIPs as $ip) {
|
||||
$permittedIPsTable->set($ip, ['addr' => $ip]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue