Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions www/htdocs/central/common/inc_ip_check.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Modifications
2026-03-11 Created fho4abcd
2026-03-12 fho4abcd Moved code to functions to avoid undesired interactions
2026-03-17 fho4abcd Added loopback to local network + remove message (now in caller)
** Description
This file contains functions intended to allow only access to a database from allowed client IP addresses.

Expand Down Expand Up @@ -54,16 +55,18 @@ function getClientIP() {
** Used to isolate the used variables from the including file
** Returns true if IP check is not configured
** Returns true if IP is valid
** Returns fals if IP is invalid
** Returns false if IP is invalid
*/
function checkClientIP($clientIP, $database) {
global $db_path, $msgstr;
//debug: echo "Client IP: " . $clientIP."<br>";
/*
** In IPv4, link-local addresses fall within the range of 169.254.0.0 to 169.254.255.255.
** In IPv6, link-local addresses have the prefix FE80::
** Loopback (127.0.0.1/::1) are of a standalone host.
*/
if ( strpos($clientIP, "fe80::") === 0 || strpos($clientIP, "169.254.") === 0 ) {
if ( strpos($clientIP, "fe80::") === 0 || strpos($clientIP, "169.254.") === 0 ||
strcmp($clientIP, "127.0.0.1") ==1 || strcmp($clientIP, "::1") == 0 ) {
//debug: echo "Link-Local Address<br>";
} else {
$dr_path_file = $db_path . $database . "/dr_path.def";
Expand All @@ -79,12 +82,7 @@ function checkClientIP($clientIP, $database) {
break;
}
}
if ( $allowed === false ) {?>
<div id="ip_not_allowed" style="width: 100%; background-color: #ffc107; text-align: center;">
<?php
echo $msgstr["clientip"]." (".$clientIP.") ".$msgstr["invalidfordb"]." ".$database."<br>";
?>
</div><?php
if ( $allowed === false ) {
// Next value should force inhibiting actions in the calling code
return false;
}
Expand Down
10 changes: 8 additions & 2 deletions www/htdocs/central/common/inicio.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
2025-10-15 fho4abcd Improve switch to error page in case of expired/lost session
2026-03-11 fho4abcd Added ip check
2026-03-12 fho4abcd Improved ip check
2026-03-17 fho4abcd IP check shows message (was in function)
*/
global $Permiso, $arrHttp,$valortag,$nombre;
$arrHttp=Array();
Expand Down Expand Up @@ -333,9 +334,14 @@ function VerificarUsuarioLDAP(){
if ( isset($arrHttp['base'])) {
include ("inc_ip_check.php");
$clientIP = getClientIP();
if ( checkClientIP( $clientIP, $arrHttp['base'] ) === false ) {
if ( checkClientIP( $clientIP, $arrHttp['base'] ) === false ) {?>
<div id="ip_not_allowed" style="width: 100%; background-color: #ffc107; text-align: center;">
<?php
echo $msgstr["clientip"]." (".$clientIP.") ".$msgstr["invalidfordb"]." ".$arrHttp['base'] ."<br>";
?>
</div><?php
unset( $arrHttp['base'] );
}
}
include("homepage.php");
?>
?>