mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-19 19:15:22 +00:00
UI: auth.inc, use cached addresslist in referer check, for https://github.com/opnsense/core/issues/3567
This prevents ifconfig is executed on every request, which could take a long time when there are a lot of interfaces.
This commit is contained in:
parent
292358b9e5
commit
e6a228da20
@ -192,12 +192,6 @@ $userindex = index_users();
|
||||
function isAuthLocalIP($http_host)
|
||||
{
|
||||
global $config;
|
||||
$interface_list_ips = get_configured_ip_addresses();
|
||||
foreach ($interface_list_ips as $ilips => $ifname) {
|
||||
if (strcasecmp($http_host, $ilips) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (isset($config['virtualip']['vip'])) {
|
||||
foreach ($config['virtualip']['vip'] as $vip) {
|
||||
if ($vip['subnet'] == $http_host) {
|
||||
@ -205,7 +199,23 @@ function isAuthLocalIP($http_host)
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
$address_in_list = function($interface_list_ips, $http_host) {
|
||||
foreach ($interface_list_ips as $ilips => $ifname) {
|
||||
if (strcasecmp($http_host, $ilips) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
// try using cached addresses
|
||||
$interface_list_ips = get_cached_json_content("/tmp/isAuthLocalIP.cache.json");
|
||||
if (!empty($interface_list_ips) && $address_in_list($interface_list_ips, $http_host)) {
|
||||
return true;
|
||||
}
|
||||
// fetch addresses and store in cache
|
||||
$interface_list_ips = get_configured_ip_addresses();
|
||||
file_put_contents("/tmp/isAuthLocalIP.cache.json", json_encode($interface_list_ips));
|
||||
|
||||
return $address_in_list($interface_list_ips, $http_host);
|
||||
}
|
||||
|
||||
function index_groups()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user