Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Clearpass comparing requester ip

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
requester
Smarty n00b


Joined: 20 Jul 2018
Posts: 2

PostPosted: Fri Jul 20, 2018 11:25 am    Post subject: Clearpass comparing requester ip Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Jul 20, 2018 11:28 am    Post subject: Reply with quote

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
View user's profile Send private message
requester
Smarty n00b


Joined: 20 Jul 2018
Posts: 2

PostPosted: Fri Jul 20, 2018 11:56 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP