Jump to content
Sign in to follow this  
mmclaughlin

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

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

Share this post


Link to post
Share on other sites

@mmclaughlin I had a think about the first part (ip address). IF your school has a static IP then the following should work....

ip.PNG.455629331be033d782b811d7a278ebdd.PNG

Edited by pconkie
  • Thanks 2

Share this post


Link to post
Share on other sites

Actually I've just seen @Graham Quince suggestion in the other thread regarding IP addresses in frog...

So this is a 100% frog based solution for getting ip address of current user

Capture.PNG.d559b0639843d86e8d0980d253a769ce.PNG

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
18 hours ago, pconkie said:

And some initial thoughts on hide/show based on time of day....

time.PNG.c908ad1050633c361050d48a17b2ce18.PNG

Could we add day of week as well to this?

Share this post


Link to post
Share on other sites

On this one...

5DCC217B-107C-482C-832E-8931142C6270.png.a759517acf0746aa48ebc68245cd1785.png

There is a rouge semicolon on the end of line 4 - it should be a {

You should also delete line 5

Edited by pconkie

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@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!

 

 

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

 

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

PS: A word of warning: This only hides the widget.  It is still on the page in the site.  It would still be possible for an inventive student to get to it.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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?

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...