Jump to content

Coders unite? Need a little help - Adding IP Address and Time checks


mmclaughlin

Recommended Posts

So we have been working on coming up with a way to limit information shown on a page either by IP (does not seem easily feasible) or by date and time.  

I have been working using this code

<DOCTYPE html>
<header>
    
 
</header>
<body>
    <input 
           id="btthider" 
           class="bttnhider"
           type="submit"
           onclick="showHidden(); showbtthidden();" value="Add a new notice here"
           >
 
    <script>
        var h = new Date().getHours();
        var d = new Date(). getDay();
        var butn = document.getElementById('btthider');
        if (h <= 7 && h >= 11).btn.disabled=true;
        if (d = 0 && d = 6). btn.disable=true
        
    </script>
    
    
    
</body>
 
</DOCTYPE>
 
To hide a button based on time and thought that I may be able to show and hide a .pdf or a widget.  
 
The reason for this need is that we have some activities that can ONLY be seen during the day which could then disappear during the evening and weekends.  This is not a rules function ability or I would have used that.  So any thoughts if this would work on a Frog page?
 
Matt
Link to comment
Share on other sites

This shows a particular widget depending on the day of the week

$("div[data-content-uuid='"+widget_to_hide+"']").hide();
// automatically show by day of week
var dayOfWeek = moment().day()
//0=sunday, 1=monday, 6=saturday etc
//show a specific widget if it is the weekend
if (dayOfWeek === 6 || dayOfWeek === 0) {
  $("div[data-content-uuid='"+widget_to_hide+"']").show();
}

What exactly do you want to do? Hide a pdf/widget except for a few hours of each day mon-fri?

Link to comment
Share on other sites

9 hours ago, pconkie said:

This shows a particular widget depending on the day of the week


$("div[data-content-uuid='"+widget_to_hide+"']").hide();
// automatically show by day of week
var dayOfWeek = moment().day()
//0=sunday, 1=monday, 6=saturday etc
//show a specific widget if it is the weekend
if (dayOfWeek === 6 || dayOfWeek === 0) {
  $("div[data-content-uuid='"+widget_to_hide+"']").show();
}

What exactly do you want to do? Hide a pdf/widget except for a few hours of each day mon-fri?

I was after something like this to hide our Home Drive network widget so the GCSE Computer Science kids couldn't access their network spaces during the controlled assessment.............  weekdays 9am - 4pm...... not that we need it now but i'd still like to get it working in case we need it in the future!!  

 

Granted they could still access it via Frogdrive but not sure how many kids have actually looked to closely at that!! :D

Link to comment
Share on other sites

2 minutes ago, mmclaughlin said:

@pconkie So it is a file or widget  that we would like to hide except during school hours for students who are in the school.  This would then prevent them from accessing it at home.  

@ADT  Thanks!

 

 

 

Not sure what ive done.....  @pconkie has done all the work!! :D

Link to comment
Share on other sites

@mmclaughlin

Just to check I understand...

You have a file.widget that should be hidden unless the student is IN school AND it is between 8am-4pm

 

A student who is "off sick" at home on a school day between 8am-4pm should NOT be able to see it.

A student who is in school on a Saturday (!) between 8am-4pm should NOT be able to see it.

Please confirm that 64.26.100.114 the ip address you see when you go to this website https://whatismyipaddress.com at school

Edited by pconkie
Link to comment
Share on other sites

64.26.100.114 is our IP address for the school.  It is static.

Yes, We would like those conditions to be met.  That 1.  The student is physically present on our servers in the school. 2.  The student is here during the school day and 3. That it is not on the weekend.  This would be a widget assigned to a for a site that prevents a pdf or text widget to be available to a student.

 

Matt

 

 

Link to comment
Share on other sites

So this should do it

<script>
    ///////////////////////////////////////
    //logic:
    /////Always hide widget.. 
    ////Show widget if all criteria met
    ///////////////////////////////////////
    
    //declare and set vars
    //change these values as required
    var widget_to_hide = "8E78A5802002886228C14F5F7A52E20F74E7BD2C79D5CFCA";
    var school_ip = "64.26.100.114";
    var format = 'hh:mm:ss';
    var time = moment();
    var beforeTime = moment('08:30:00', format);
    var afterTime = moment('15:30:00', format);
    var currentuser = FrogOS.getUser();
    var dayOfWeek = moment().day()
    
    //hide widget
    $("div[data-content-uuid='"+widget_to_hide+"']").hide();
    
    if (currentuser.profile.type !== "student") {
        //they are not a student - show the widget
        $("div[data-content-uuid='"+widget_to_hide+"']").show();
    } else {
        //async load of users external ip address...waits for response...
        $.get( "../ipaddress.php", function( data ) {
            var r = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
            var ip = data.match(r);
            if (ip[0] == school_ip) {
                //they are at school
                if (dayOfWeek === 1 || dayOfWeek === 2 || dayOfWeek === 3 || dayOfWeek === 4 || dayOfWeek === 5) {
                    //0=sunday, 1=monday etc BUT perhaps this isn't correct for US?
                    //it should be Mon-Fri
                    if (time.isBetween(beforeTime, afterTime)) {
                        //it's within school hours
                        //finally show the widget!
                        $("div[data-content-uuid='"+widget_to_hide+"']").show();
                    }
                }
            }
        });
    } 
</script>

You will need a student account to test as this will not hide the widget if the user is staff / admin.

Code also attached for easy copy/paste - code.txt

Paul

Link to comment
Share on other sites

9 hours ago, pconkie said:

So this should do it


<script>
    ///////////////////////////////////////
    //logic:
    /////Always hide widget.. 
    ////Show widget if all criteria met
    ///////////////////////////////////////
    
    //declare and set vars
    //change these values as required
    var widget_to_hide = "8E78A5802002886228C14F5F7A52E20F74E7BD2C79D5CFCA";
    var school_ip = "64.26.100.114";
    var format = 'hh:mm:ss';
    var time = moment();
    var beforeTime = moment('08:30:00', format);
    var afterTime = moment('15:30:00', format);
    var currentuser = FrogOS.getUser();
    var dayOfWeek = moment().day()
    
    //hide widget
    $("div[data-content-uuid='"+widget_to_hide+"']").hide();
    
    if (currentuser.profile.type !== "student") {
        //they are not a student - show the widget
        $("div[data-content-uuid='"+widget_to_hide+"']").show();
    } else {
        //async load of users external ip address...waits for response...
        $.get( "../ipaddress.php", function( data ) {
            var r = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
            var ip = data.match(r);
            if (ip[0] == school_ip) {
                //they are at school
                if (dayOfWeek === 1 || dayOfWeek === 2 || dayOfWeek === 3 || dayOfWeek === 4 || dayOfWeek === 5) {
                    //0=sunday, 1=monday etc BUT perhaps this isn't correct for US?
                    //it should be Mon-Fri
                    if (time.isBetween(beforeTime, afterTime)) {
                        //it's within school hours
                        //finally show the widget!
                        $("div[data-content-uuid='"+widget_to_hide+"']").show();
                    }
                }
            }
        });
    } 
</script>

You will need a student account to test as this will not hide the widget if the user is staff / admin.

Code also attached for easy copy/paste - code.txt

Paul

Another Conkie Special!!!!

You should be getting consultancy money from Frog!!! :P

Link to comment
Share on other sites

  • 1 month later...

So this worked, but it turns out that we have a range of IP addresses that we use in county and since we happen to have an internal server, these are what is used by Frog not the external IP address.  So I need to adjust this to be an IP range instead of a static IP.  Any suggestions?

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...