View Full Version : Controlling Hours of Access to Embedded Network Camera
kblaw
11-25-2012, 10:43 PM
I have an Axis network (IP) camera that I would like to embed in my website. Axis provides the code (see below), and it works. However, I would like to limit the hours during the day when people have access to view the camera (or, alternatively, the web page where the camera appears). I would like to limit the hours to Monday through Friday, 9 a.m. to 7 p.m. E.S.T.
If you have any suggestions, please let me know. I have only rudimentary knowledge of code, so if you have any suggestions, it would be helpful if you could provided any suggested changes or additions to the existing code below.
I am also open to other suggestions for accomplishing the same goal. Thanks in advance.
<SCRIPT LANGUAGE="JavaScript">
// Set the BaseURL to the URL of your camera
var BaseURL = "http://98.242.185.88:4956/";
// DisplayWidth & DisplayHeight specifies the displayed width & height of the image.
// You may change these numbers, the effect will be a stretched or a shrunk image
var DisplayWidth = "640";
var DisplayHeight = "480";
// This is the path to the image generating file inside the camera itself
var File = "axis-cgi/mjpg/video.cgi?resolution=640x480";
// No changes required below this point
var output = "";
if ((navigator.appName == "Microsoft Internet Explorer") &&
(navigator.platform != "MacPPC") && (navigator.platform != "Mac68k"))
{
// If Internet Explorer under Windows then use ActiveX
output = '<OBJECT ID="Player" width='
output += DisplayWidth;
output += ' height=';
output += DisplayHeight;
output += ' CLASSID="CLSID:DE625294-70E6-45ED-B895-CFFA13AEB044" ';
output += 'CODEBASE="';
output += BaseURL;
output += 'activex/AMC.cab#version=5,6,2,2">';
output += '<PARAM NAME="MediaURL" VALUE="';
output += BaseURL;
output += File + '">';
output += '<param name="MediaType" value="mjpeg">';
output += '<param name="ShowStatusBar" value="0">';
output += '<param name="ShowToolbar" value="0">';
output += '<param name="AutoStart" value="1">';
output += '<param name="StretchToFit" value="1">';
// Remove the // for the ptz settings below to use the code for click-in-image.
// output += '<param name="PTZControlURL" value="';
// output += BaseURL;
// output += '/axis-cgi/com/ptz.cgi?camera=1">';
// output += '<param name="UIMode" value="ptz-relative">'; // or "ptz-absolute"
output += '<BR><B>Axis Media Control</B><BR>';
output += 'The AXIS Media Control, which enables you ';
output += 'to view live image streams in Microsoft Internet';
output += ' Explorer, could not be registered on your computer.';
output += '<BR></OBJECT>';
} else {
// If not IE for Windows use the browser itself to display
theDate = new Date();
output = '<IMG SRC="';
output += BaseURL;
output += File;
output += '&dummy=' + theDate.getTime().toString(10);
output += '" HEIGHT="';
output += DisplayHeight;
output += '" WIDTH="';
output += DisplayWidth;
output += '" ALT="Camera Image">';
}
document.write(output);
document.Player.ToolbarConfiguration = "play,+snapshot,+fullscreen"
// Remove the // below to use the code for Motion Detection.
// document.Player.UIMode = "MDConfig";
// document.Player.MotionConfigURL = "/axis-cgi/operator/param.cgi?ImageSource=0"
// document.Player.MotionDataURL = "/axis-cgi/motion/motiondata.cgi";
</SCRIPT>
Beverleyh
11-25-2012, 11:55 PM
Something like this;
<?php
$day = date('l'); // get day of week
$hr = date('G'); // get hour of day
$wkend = array('Saturday', 'Sunday');
// check if day is not Saturday or Sunday, and between the hours of 9am and 7pm inclusive
if ( (!in_array($day, $wkend)) && ($hr >= 9 && $hr <= 19) ) {
?>
<!-- Put your page code here -->
<?php } else { ?>
<p>Sorry, come back between 9am and 7pm, Monday to Friday, to see something interesting.</p>
<?php } ?>
You might also need to calculate an hour offset depending on your server time/location
djr33
11-26-2012, 01:22 AM
There's a significant problem with this: if someone is already on the page, you can't force them to leave. So you can decide when you want to show them the page and when you don't, but once it is loaded there's nothing to stop them from keeping the page open.
I'm not sure exactly what you are doing this for, but if it's for privacy and it's very important that the page is never viewable outside of those hours, this is not going to be solved by PHP.
Javascript can do this easily enough, but it's not guaranteed because Javascript can be disabled-- it's like a request to the browser to reload the page (or hide the camera, or whatever) but not a guaranteed command-- because the browser can ignore Javascript. It'll work for 95%+ of your visitors, but for that 5%, they may know how to disable it and intentionally view longer.
The best solution I can think of is requiring that the page refreshes every 5-15 minutes so that the PHP code (which will always work) will block them from using the page at the wrong times (or within 5-15 minutes of the wrong times, at least). However, it's also very hard to force a page to refresh. A meta refresh tag or a refresh header sent from PHP would be possible, but I do believe that can be overridden by the browser/user settings as well, although it's a lot harder to get around than Javascript (which usually has a simple "off" button).
So.... there's NO way to do this effectively if you need 100% reliability. The solution would be to actually stop the video feed at those times, which is technically possible but might be difficult (or even effectively impossible) depending on what kind of software you're using for it. I'd suggest contacting technical support for the camera and/or software.
Additionally, if the camera feed is available on the website then I imagine that with a bit of creativity and knowledge, users could extract that from the site (for example, embed it on their own page, personal or public) and watch any time they'd like. Therefore, it's really not about the webpage at all, but about the camera feed itself.
One thing you could explore would be using Flash or another plugin to load the camera feed, and those could disable it at the times you indicated. They're also much harder to reverse engineer. But someone who knows what they're doing could probably extract the camera feed from them as well, as mentioned above. Check with a Flash programmer to see if there's a good solution to this. But I still think dealing with it at the source is the best idea.
kblaw
11-26-2012, 01:42 AM
Many thanks. I'm already in over my head here. I use Godaddy, and tried including the entire code in one of Godaddy's "script" boxes. It came back with a message that only Javascript may be entered. I then tried to open up the HTML editor. However, I ended up with only the following appearing
= 9 && $hr <= 19) ) { ?>
That also appears as text on the previewed page. Any suggestions?
Something like this;
<?php
$day = date('l'); // get day of week
$hr = date('G'); // get hour of day
$wkend = array('Saturday', 'Sunday');
// check if day is not Saturday or Sunday, and between the hours of 9am and 7pm inclusive
if ( (!in_array($day, $wkend)) && ($hr >= 9 && $hr <= 19) ) {
?>
<!-- Put your page code here -->
<?php } else { ?>
<p>Sorry, come back between 9am and 7pm, Monday to Friday, to see something interesting.</p>
<?php } ?>
You might also need to calculate an hour offset depending on your server time/location
kblaw
11-26-2012, 01:50 AM
Thanks. As I said in the previous response, I can see that I'm already in over my head. The reason for limiting the hours is indeed for privacy. The network camera is to show my dog during weekdays when I'm not at home. I'm not overly concerned (though maybe I should be) if someone manages to stay on past the deadline, as it would probably get very boring after a while. I also doubt that anyone would really want to go through the effort to embed the video on another page, though I do understand the concern. My main concern is that someone will simply stumble onto the camera at a time when I don't want to give access.
The difficulty here is that I want to have access to the camera (through sources other than my website) at all times, so I can't shut off the camera. I was using a hosting service that re-streamed the video, and that worked very well, but it has raised its rates by a huge amount. That makes it no longer feasible to use this service.
There's a significant problem with this: if someone is already on the page, you can't force them to leave. So you can decide when you want to show them the page and when you don't, but once it is loaded there's nothing to stop them from keeping the page open.
I'm not sure exactly what you are doing this for, but if it's for privacy and it's very important that the page is never viewable outside of those hours, this is not going to be solved by PHP.
Javascript can do this easily enough, but it's not guaranteed because Javascript can be disabled-- it's like a request to the browser to reload the page (or hide the camera, or whatever) but not a guaranteed command-- because the browser can ignore Javascript. It'll work for 95%+ of your visitors, but for that 5%, they may know how to disable it and intentionally view longer.
The best solution I can think of is requiring that the page refreshes every 5-15 minutes so that the PHP code (which will always work) will block them from using the page at the wrong times (or within 5-15 minutes of the wrong times, at least). However, it's also very hard to force a page to refresh. A meta refresh tag or a refresh header sent from PHP would be possible, but I do believe that can be overridden by the browser/user settings as well, although it's a lot harder to get around than Javascript (which usually has a simple "off" button).
So.... there's NO way to do this effectively if you need 100% reliability. The solution would be to actually stop the video feed at those times, which is technically possible but might be difficult (or even effectively impossible) depending on what kind of software you're using for it. I'd suggest contacting technical support for the camera and/or software.
Additionally, if the camera feed is available on the website then I imagine that with a bit of creativity and knowledge, users could extract that from the site (for example, embed it on their own page, personal or public) and watch any time they'd like. Therefore, it's really not about the webpage at all, but about the camera feed itself.
One thing you could explore would be using Flash or another plugin to load the camera feed, and those could disable it at the times you indicated. They're also much harder to reverse engineer. But someone who knows what they're doing could probably extract the camera feed from them as well, as mentioned above. Check with a Flash programmer to see if there's a good solution to this. But I still think dealing with it at the source is the best idea.
Deadweight
11-26-2012, 02:35 AM
Couldnt the person just grab their ip and then locate them using their ip and change the timestamp according to their ip?
djr33
11-26-2012, 03:24 AM
kblaw, please note that your recent posts were caught by our automatic spam filter-- they're approved now (and you did nothing wrong) but in case you can't see something you post, that's why-- and a moderator will approve it as soon as possible.
For PHP, you will need to use a .php page and have access to the plain-text source code. I'm not sure what you mean by "using GoDaddy", but if you're referring to some preview-based ("WYSIWYG") editor, then you will need to start using FTP with access to the code directly. GoDaddy has PHP enabled by default, so that shouldn't be a problem.
And note that Beverley's script is just fine for access to the page, if that's part of what you want to do. Combined with some other methods to actually block the camera feed at those times, Beverley's method will allow you to put a friendly message up for users.
Thanks. As I said in the previous response, I can see that I'm already in over my head. The reason for limiting the hours is indeed for privacy. The network camera is to show my dog during weekdays when I'm not at home. I'm not overly concerned (though maybe I should be) if someone manages to stay on past the deadline, as it would probably get very boring after a while. I also doubt that anyone would really want to go through the effort to embed the video on another page, though I do understand the concern. My main concern is that someone will simply stumble onto the camera at a time when I don't want to give access.
The difficulty here is that I want to have access to the camera (through sources other than my website) at all times, so I can't shut off the camera. I was using a hosting service that re-streamed the video, and that worked very well, but it has raised its rates by a huge amount. That makes it no longer feasible to use this service.I understand. The bottom line is that if you put it on the internet, it's public. One option would be to put all of this behind a password system so that no one else can view it. But still they'd end up being able to get access to the camera feed without a password, if they knew where to look.
What's in your favor at the moment is that others don't know where to look. That's what I'd suggest using-- put it on an obscure page on your website that only you know about (don't ever link to it) and just use it yourself. If the public knows about it, they can view it at other times.
If you only want to discourage people from viewing at other times, you can use Beverley's method. But if you want to actually prevent them for privacy reasons (and that's a good idea), then you will need to do something more than that.
Couldnt the person just grab their ip and then locate them using their ip and change the timestamp according to their ip? I'm not sure what you mean exactly. But, yes, someone could find the IP. That would potentially allow them to view the camera at other times and actually also allow them to locate where the camera is geographically, although it probably wouldn't let them know the exact address, just the city and the internet provider. (On the other hand, that information may already be available based on the registration of the domain name.)
----
There are three things that I suggest:
1. Put this in some weird place on your website where no one will find it. Maybe add a password-- look into .htaccess passwords for something easy and secure. Never link to this or make it public.
2. Contact the company that does the streaming. Ask them for help.
3. Look into alternatives. Surely there must be some company out there that requires a password to view the stream. And I don't think it would be all that expensive, at least if you look around for various options. Even if it is expensive, that might be what you need to deal with to make this private.
It's all up to you, but you need to decide how important privacy is and what you'd be willing to do about it-- turn off the camera? pay more? switch services? deal with the privacy risk?
Finally, you can also consider dealing with this at the other end. For example, you could try to:
--manually turn off the camera at those times
--set it to automatically turn off at those times if that's an option
--even try something like buying a switch that's on a timer for that circuit-- there are consumer devices out there for that so that you can have certain lights on at certain times of the day, and I don't think they're expensive or hard to use-- but for that you'd need to be sure that it wouldn't disrupt the stream. If you can simply switch the power to the camera on and off without disabling the streaming and allowing it to start up the next time the camera is turned on, that sounds like a great idea to me. Cheap, easy and reliable. But that might only work with certain streaming software (or maybe none-- I'm not sure).
kblaw
11-26-2012, 12:40 PM
Thanks for the enlightening responses. A few notes:
1. The ideal solution continues to be using a service that restreams the video. I am still exploring alternative services that might not be so expensive. I actually have several cameras. The original cost for my current restreaming service was less than $10 per month, but it will be increasing to about $75 per month. I cannot justify that cost for a non-commercial website.
2. Over the weekend, I sent a service inquiry to Axis Cameras asking about any solution it might offer. I am waiting for its response.
3. In the meantime, I am willing to live with a system that is not completely secure, as long as it discourages the average person from logging in at off-hours. I do need to keep the cameras on during off-hours, so that I have my own access to the cameras through other applications, but I want anyone to have access at other hours through my website. Thus, concealing links or using password protection on the website won't work for me.
4. I use Godaddy's Website Tonight. Apparently, based on some research I did, it does not support PHP. Is there an alternative using Javascript?
Thanks again.
4.
djr33
11-27-2012, 10:23 AM
1-2. This is a fairly specialized service, so while that is obviously expensive, you may end up needing to choose between the cost and the quality of service. There just isn't going to be any alternative to manipulating the streaming itself.
3. The PHP solution will work for this in that they can only START viewing the camera at certain times.
4. No, not really. There are 2 problems:
1) Javascript time would be based on the user's computer, not the server (which would be at a constant geographical location) or the camera. So if someone in China or someone in Italy or someone in Canada were looking at tis, they'd have access at completely different times due to time zones. You could TRY to figure this out, but it would probably require referring to the server's time and finding the offset. That's possible. But it means using PHP again.
2) You can completely control the browser using Javascript-- force the page to reload, navigate to a different page, hide the camera, etc. The problem, as I said earlier, is that it's not actually all that powerful-- if Javascript is disabled (or someone wants to go through the trough the trouble of manipulating the commands, which is all possible because it's all on the user's computer), then it's useless. Javascript NEVER works for security. Javascript ONLY works to enhance the user's experience by helping them with additional OPTIONAL features. It's a one-way relationship-- the code MAY help the user, but it cannot be relied upon for anything beyond that. (One option would be to require Javascript to load the page in the first place; that kind of script can be somewhat effective. But if you know what you're doing, you could allow JS to load the page then disable it, or simply reverse engineer the code to find the raw code and work from there.)
You should not be using Godaddy's "Website Tonight" if you want ANY kind of control over your website, especially at this level. It's just not designed for that. It's basically a template with a bit of flexibility, but nothing like what you'd need here. As a metaphor, it's sort of like the difference between being a painter and using making "color-by-number" pictures-- the second is certainly easier and faster, but at some point you'll find yourself asking "wait, I want to make a picture of something else." So, it's time to consider upgrading. Code is relatively accessible if you're willing to take the time to figure it out.
However, as I said before, this is properly solved at the level of the camera feed anyway. So you don't necessarily need PHP. In that case you can just keep your current website and not change a thing-- but then find some way to deal with the camera.
My best suggestion is still to make this private. Why should anyone else be able to see it anyway? I'm confused. Or, here's an idea, why not create two cameras, one that is disabled at those times, but available to the public, and another one that is password protected (or just hidden from the public on an unknown page) that only you can view? Low-tech, but maybe that would work for you.
kblaw
12-28-2012, 07:09 PM
Just an update on this, and a further question. I purchased a separate web hosting service and domain from Godaddy for the purpose of running the cameras with the code suggested above. I am using Drupal for now, and it appears to work fine.
So as avoid rebuilding any of the main website, I would like to embed the video from the new site on the main website. I realize that this is less than ideal. I am able to embed the entire web page, but would like to embed only the video itself. Is there a way to do this (understandng that I am restricted to using HTML)? Again, please bear in mind that I have only a rudimentary knowledge of code. Thanks in advance.
djr33
12-28-2012, 08:20 PM
It depends on how it is set up. If allowed (by the hosts) you could simply go into the source code of your new site, grab the code that embeds the video, and put that on the new site. Might work, might not (based on whether anything more complex is going on there).
Alternatively, you could use an iframe, perhaps with some Javascript to align the video in the right place, and frame the other page well.
I'd suggest contacting the hosts for support, since this is a service they provide, right? Or is it something you worked out yourself?
kblaw
12-29-2012, 01:17 AM
It depends on how it is set up. If allowed (by the hosts) you could simply go into the source code of your new site, grab the code that embeds the video, and put that on the new site. Might work, might not (based on whether anything more complex is going on there).
Alternatively, you could use an iframe, perhaps with some Javascript to align the video in the right place, and frame the other page well.
I'd suggest contacting the hosts for support, since this is a service they provide, right? Or is it something you worked out yourself?
Thanks. If I'm not mistaken, I think the source code would get me back to where I started, and then I would still have the issue of Website Tonight not supporting php. I'm using an iframe to embed, but I'm getting more than the video. I have gotten it down to only a couple of items appearing above the video, so if someone could point me in the right direction for Javascript to align the video to some degree, that would be very helpful.
kblaw
01-02-2013, 06:25 PM
Just another quick note:
This is now up and running, and pretty much the way I wanted it. Thanks for all your help! A link to one of the cameras (there are eight) is below:
http://www.mywheatenterrier.com/Channel_One.html
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.