|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
requester Smarty n00b
Joined: 20 Jul 2018 Posts: 2
|
Posted: Fri Jul 20, 2018 11:25 am Post subject: Clearpass comparing requester ip |
|
|
Hi all,
i am trying to compare the requester ip to some criteria in a subnet:
{if strpos($smarty.request.ip, '192.168.1.') !== false && intval(explode('.',$smarty.request.ip)[3]) <= 0 && intval(explode('.',$smarty.request.ip)[3]) >= 63}
{ assign var=redirectpage value='some_page.php' }
{/if}
the first part with strpos works great but it seems to fail on the intval, explode or Array part in it...
Do you have any idea on how to write the needed code?
Regards
Jannis |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jul 20, 2018 11:28 am Post subject: |
|
|
Code: | function inet_private($addrString)
{
$addr = inet_pton($addrString);
if(strlen($addr) !== 4)
throw new Exception('Only valid IPv4 addresses are currently supported.');
$ta = unpack('n*', $addr);
$addr = reset($ta);
return $addr === 49320 // 192.168.0.0/16
|| ($addr &~ 15) === 44048 // 172.16.0.0/12
|| ($addr &~ 255) === 32512 // 127.0.0.0/8
|| ($addr &~ 255) === 2560; // 10.0.0.0/8
}
|
|
|
Back to top |
|
requester Smarty n00b
Joined: 20 Jul 2018 Posts: 2
|
Posted: Fri Jul 20, 2018 11:56 am Post subject: |
|
|
nevermind.. we made it
{assign var="ipArray" value="."|explode:$smarty.request.ip}
{if strpos($smarty.request.ip, '192.168.1.') !== false && ($ipArray[3]|intval) >= 0 && ($ipArray[3]|intval) <= 63}
{ assign var=redirectpage value='some_page.php' }
{/if} |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|