IP Address Restrictor

Description

This is code so that you can change the page based on the incoming IP Address - for example, we use it to:

A) Make certain information only available to those on campus (a staff directory)

B) We have various online databases through our library that access easily on site, but if you are offsite, you need to go through a proxy. This allows one page to have the 'correct' links either way. 

 

Code

${esc.hash}${esc.hash}${esc.hash}IP ACCESS Restrictor
${esc.hash}${esc.hash}MP 2012 June
${esc.hash}${esc.hash}NOTE extra information left in comments so you can see if it you like


${esc.hash}set (${esc.dollar}ip=${esc.dollar}request.getRemoteAddr())
${esc.hash}set (${esc.dollar}fp=${esc.dollar}ip.substring(0,${esc.dollar}ip.indexOf('.',0)))

${esc.hash}set (${esc.dollar}fd=${esc.dollar}ip.indexOf('.',0))
${esc.hash}set (${esc.dollar}fdp=${esc.dollar}fd + 1)
${esc.hash}set (${esc.dollar}sd=${esc.dollar}ip.indexOf('.',${esc.dollar}fdp))
${esc.hash}set (${esc.dollar}sd=${esc.dollar}sd + 1)

${esc.hash}set (${esc.dollar}sp=${esc.dollar}ip.substring(${esc.dollar}fdp,${esc.dollar}ip.indexOf('.',${esc.dollar}fdp)))
${esc.hash}set (${esc.dollar}tp=${esc.dollar}ip.substring(${esc.dollar}sd,${esc.dollar}ip.indexOf('.',${esc.dollar}sd)))


${esc.hash}${esc.hash}<p> IP : ${esc.dollar}ip </p>
${esc.hash}${esc.hash}<p> FD : ${esc.dollar}fd </p>
${esc.hash}${esc.hash}<p> FD : ${esc.dollar}fdp </p>
${esc.hash}${esc.hash}<p> Firstpair : ${esc.dollar}fp </p>
${esc.hash}${esc.hash}<p> Secondpair : ${esc.dollar}sp </p>
${esc.hash}${esc.hash}<p> Thirdpair : ${esc.dollar}tp </p>

${esc.hash}set (${esc.dollar}pass = "FALSE")


${esc.hash}${esc.hash}allow all 10. x. x .x addresses
${esc.hash}if (${esc.dollar}fp == 10)
${esc.hash}set (${esc.dollar}pass = "TRUE")
${esc.hash}end

${esc.hash}${esc.hash}allow all 192.159.104. x addresses
${esc.hash}if (${esc.dollar}fp == 192 && ${esc.dollar}sp == 159 && ${esc.dollar}tp == 104)
${esc.hash}set (${esc.dollar}pass = "TRUE")
${esc.hash}end

${esc.hash}${esc.hash}allow all 64.9.76. x addresses
${esc.hash}if (${esc.dollar}fp == 64 && ${esc.dollar}sp == 9 && ${esc.dollar}tp == 76 )
${esc.hash}set (${esc.dollar}pass = "TRUE")
${esc.hash}end


${esc.hash}if (${esc.dollar}pass == "TRUE")
You are on campus.
${esc.hash}end

${esc.hash}if (${esc.dollar}pass == "FALSE")
You are off campus. 
${esc.hash}end