Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Campaign Classic - Restrict WebApp Access to internal IP without login

patrickm2478362
Level 1
Level 1

Hi,

 

I have created a WebApp in Campaign Classic which is currently accessible to anyone. I would like to restrict it to internal use only (either manually via IP ranges or using the whitelisted IPs setup via the control panel) but not have users need to log in.

 

Data will be captured on the WebApp and stored in the Campaign Classic DB.

 

Any help would be appreciated.

 

Thanks,

 

Patrick

1 Accepted Solution
David__Garcia
Correct answer by
Level 8
Level 8

Use the following example as a basis to get started, should be enough.

 

 

 

<%
//step 1: get remote ip and store it in webapp variable
ctx.vars.myip = request.getRemoteAddr();
%> 
<html>
  <head></head>
  <body>
    <p>This is a test</p>
    <script type="text/javascript">
      // 
      < ![CDATA[window.addEventListener('load', function() {
            //step 2: assign ip to local variable or sessionstorage for validation
            var ip = document.controller.getValue('/ctx/vars/myip'); 
            sessionStorage.setItem("myip", ip); // stores ip to browser sessionStorage
            alert(ip);
          })
          // ]]>
    </script>
  </body>
</html>

 

 

 

Below you can see we have stored the ip in ctx.vars.myip as well as sessionStorage so that you can do whatever validation you may require.

 

David__Garcia_0-1628827664039.png

 

You may also add `ctx.vars.myip = request.getRemoteAddr();` inside a js activity in your webapp (must be first activity) then add a test activity to check for ranges such as if myip begins with xxx.xx. range then send them to another page or whatever.

 

View solution in original post

1 Reply
David__Garcia
Correct answer by
Level 8
Level 8

Use the following example as a basis to get started, should be enough.

 

 

 

<%
//step 1: get remote ip and store it in webapp variable
ctx.vars.myip = request.getRemoteAddr();
%> 
<html>
  <head></head>
  <body>
    <p>This is a test</p>
    <script type="text/javascript">
      // 
      < ![CDATA[window.addEventListener('load', function() {
            //step 2: assign ip to local variable or sessionstorage for validation
            var ip = document.controller.getValue('/ctx/vars/myip'); 
            sessionStorage.setItem("myip", ip); // stores ip to browser sessionStorage
            alert(ip);
          })
          // ]]>
    </script>
  </body>
</html>

 

 

 

Below you can see we have stored the ip in ctx.vars.myip as well as sessionStorage so that you can do whatever validation you may require.

 

David__Garcia_0-1628827664039.png

 

You may also add `ctx.vars.myip = request.getRemoteAddr();` inside a js activity in your webapp (must be first activity) then add a test activity to check for ranges such as if myip begins with xxx.xx. range then send them to another page or whatever.

 

View solution in original post