FileZ/FileZ — pull request #134 by rdir (2013-02-11 20:13:41+00:00)
Title: Adding general purpose filters to FileZ

The class Fz_Filter implements a general purpose filter for FileZ. Filters have a syntax very similar to their counterparts in LDAP. The main difference is that expressions are PERL non-anchored, case insensitive regular expressions whereas LDAP uses shell-like wildcards.

The primary goal for filters is to grant or deny access to authenticated users if a set of criteria is satisfied of not. For example, consider a FileZ site which uses its own authentication handler MyAuth and requires that users can only deposit files from hosts satisfying one or both of these conditions: the IP address belong to the network 192.168.1.0/24 or the hostname contains the string mydomain. To configure this requirement, add the following line in config/filez.ini:
[auth_options]
filter = "(|(REMOTE_ADDR=^192\.168\.1\.\d+)(HTTP_HOST=mydomain))"

Add the following code in lib/Fz/Controller/Security/MyAuth.php
protected function _doSecure() {
...
$filter = new Fz_Filter($this->getOption ("filter", null));
if (! $filter->applyTo($_SERVER)) {
throw new Exception("Sorry, you are not allowed to use this server");
}
...
}