X-Git-Url: https://git.p6c8.net/jirafeau_project.git/blobdiff_plain/92660e5c44d25cee93a7a9f531eb30f4ae9c061d..3e29f7cbb6cd46c2629b2e7193dbbbbf5967bfc3:/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; +} +