X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/blobdiff_plain/92660e5c44d25cee93a7a9f531eb30f4ae9c061d..b27434d73cd12a4d80af33b27b77e7c9a4a8a8a3:/lib/functions.php diff --git a/lib/functions.php b/lib/functions.php index c2cad46..27e4fc3 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -1084,3 +1084,27 @@ function jirafeau_challenge_upload_password ($cfg, $password) return false; } +/** + * Test if visitor's IP is authorized to upload. + * @param $ip IP to be challenged + * @return true if IP is authorized, false otherwise. + */ +function jirafeau_challenge_upload_ip ($cfg, $ip) +{ + if (count ($cfg['upload_ip']) == 0) + return true; + forEach ($cfg['upload_ip'] as $i) + { + if ($i == $ip) + return true; + // CIDR test for IPv4 only. + if (strpos ($i, '/') !== false) + { + list ($subnet, $mask) = explode('/', $i); + if ((ip2long ($ip) & ~((1 << (32 - $mask)) - 1) ) == ip2long ($subnet)) + return true; + } + } + return false; +} +