X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/blobdiff_plain/6667b979aa92be3489dae7c9e6fa5da9cae39116..364d1c4437c45eda91dd0b8c5e92a098578f8b39:/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; +} +