Re: [Phplib-users] preauth using cidr
Brought to you by:
nhruby,
richardarcher
|
From: Paul W. <pa...@zz...> - 2001-11-08 20:07:35
|
I fixed my own problem. I forgot to convert the remote host ip. This
code appears to work for anyone interested:
$cidr = $valid_client; /* db value 192.55.192.0/24 */
list ($quad, $nbits) = split ("/", $cidr, 2);
$byte = explode (".", $quad);
$address_required = ($byte[0] << 24) | ($byte[1] << 16) | ($byte[2] <<
8) | $byte[3];
/* remote host info */
$byte = explode(".", $ip); /* ip from $HTTP_SERVER_VARS['REMOTE_ADDR']
*/
$address_client = ($byte[0] << 24) | ($byte[1] << 16) | ($byte[2] << 8)
| $byte[3];
$bitmask = 0xffffffff << (32 - $nbits);
if (($address_client & $bitmask) == ($address_required & $bitmask)) {
$this->auth['uname'] = $this->dbAuth->f('ID');
$this->auth['perm'][$this->dbAuth->f('Service')] = 1;
$success = 1;
}
Paul Wolstenholme wrote:
>
> Hi,
>
> I am trying to do a preauth using cidr to allow some institutional
> subscribers to access info that is normally password protected. I found
> some Perl code that does this but it does not work in php. Does anyone
> know how one could accomplish this?
>
> $cidr = $valid_client; /* eg 192.55.192.0/24 */
> list ($quad, $nbits) = split ("/", $cidr, 2);
> $byte = explode (".", $quad);
>
> $address = ($byte[0] << 24) | ($byte[1] << 16) | ($byte[2] << 8) |
> $byte[3];
> $bitmask = 0xffffffff << (32 - $nbits);
>
> if ($ip & $bitmask == $address & $bitmask) {
> $this->auth['uname'] = $this->dbAuth->f('ID');
> $this->auth['perm'][$this->dbAuth->f('Service')] = 1;
> }
>
> --
> ________________________________________________________________
> Paul Wolstenholme
> SMA Webware
> http://www.zzube.com/
> What do you know?
> http://make.zzube.com/
> Vancouver, BC Canada
--
________________________________________________________________
Paul Wolstenholme
SMA Webware
http://www.zzube.com/
What do you know?
http://make.zzube.com/
Vancouver, BC Canada |