LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-26-2003, 05:36 PM   #1
lockejr
Member
 
Registered: Jan 2003
Location: Wichita, KS
Distribution: Slack, Gentoo, CPUBuilders
Posts: 37

Rep: Reputation: 15
Help with webpage


Alright here's the deal, I have a network of ip camera's that dump images into an ftp server. each camera has it's own folder so it's all nice and organized, I made a cron script that goes through every day and archives old stuff. Now I need to build a webpage that will automatically pull the most recent picture and display it. I very little web experience but enough that I can build a page. My question is how or what command can i put into the code that will only pull the most recent picture. The jpeg's are named in sequence so it just needs to look for the higest number. any idea's out there?
 
Old 03-26-2003, 05:46 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
A simple perl script that reads the desired directory - sorts the files by name then prints an html page that displays that image.
 
Old 03-26-2003, 06:23 PM   #3
lockejr
Member
 
Registered: Jan 2003
Location: Wichita, KS
Distribution: Slack, Gentoo, CPUBuilders
Posts: 37

Original Poster
Rep: Reputation: 15
yeah that's what i need it to do but how? I know nothing about perl. Do you know of a good tutorial to look at for this? I'm not looking for someone to walk me through it but just to point me too a good starting point. I have done several searches on google but it's such a broad topic that nothing really matches.
 
Old 03-26-2003, 06:35 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
I got bored so I wrote you a little script that should do the job.

1) Set camroot to the path where all your cams files are stored
2) Set webroot to the coresponding relative path to the root of of your site
3) Upload it to your cgi-bin (call it img.cgi or something) give it executeable permissions.

Code:
#!/usr/bin/perl

$camroot = "/home/www/test/cams";
$webroot = "/cams";

##################################################################################
# Do not edit anything below here (except the HTML - but do it after this works) #
##################################################################################

$camroot .= $ENV{'QUERY_STRING'};
$webroot .= $ENV{'QUERY_STRING'};

opendir(DIR, "$camroot");
@files = readdir(DIR);
close(DIR);

$last = $files[@files-1];
$time = localtime(time());

print <<"EOF";
Content-type:text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>My Web Cams</TITLE>
</HEAD>
<BODY>
<IMG alt="$time" src="$webroot/$last">
</BODY>
</HTML>

EOF

exit;
I have made the assumptions that all cameras store their pictures in one directory and beneath that is a directoy for each camera so to view the last img of cam1 (/home/www/mysite/cams/cam1/1234.jpg). you would access http://yoursite/cgi-bin/img.cgi?/cam1

This reads the "/home/www/mysite/cams/cam1/" directory and gets the name of the last file. It then prints an html page with an img link pointing to the appropriate file on your server http://yoursite/cams/cam1/1234.jpg

I have only tested this quickly but it should work. Let me know if you run into problems I will be about for the next half hour.

oh - to make it conform to W3C standards it creates an alt value containing the time.

Last edited by david_ross; 03-26-2003 at 06:38 PM.
 
Old 03-26-2003, 06:49 PM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
You may also want to put a meta refresh tag there too.

Put the line:
<META HTTP-EQUIV="refresh" content="HOWOFTEN;URL=$ENV{'REQUEST_URI'}">

Above the title and change HOWOFTEN to the number of second between each refresh.
 
Old 03-26-2003, 06:53 PM   #6
lockejr
Member
 
Registered: Jan 2003
Location: Wichita, KS
Distribution: Slack, Gentoo, CPUBuilders
Posts: 37

Original Poster
Rep: Reputation: 15
Cool man, you assumed right for the camera pathing, it's /home/camera/images/cameraname so it should work with a little tweaking. I will give it a try when I get to work in the morning.

Thanks again
 
Old 03-26-2003, 06:56 PM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
I'll check in if I have time during my lunch break tomorrow. Stick another post up if you ahve any problems - you may need to change the path to perl (first line) it is sometimes /usr/local/bin/perl (somtimes they are link so both work).
"whereis perl" should give you the exact location.
 
Old 03-27-2003, 10:05 AM   #8
lockejr
Member
 
Registered: Jan 2003
Location: Wichita, KS
Distribution: Slack, Gentoo, CPUBuilders
Posts: 37

Original Poster
Rep: Reputation: 15
Well I got in and updated the pathing. I get a really coll screen that tells me the date and time but unfortunately no images. i've got the camroot set to /home/camera/images which is correct and webroot set to /var/www/html which is also correct. is there anything I'm missing?
 
Old 03-27-2003, 10:38 AM   #9
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Yes web root is the bit after http://yoursite.com and before the cam dir. Also the images must be visible bay accessing yoursite.com/images/cam1/1234.jpg etc

To do this you could add a an aliased directoy in httpd.conf to alias "/home/camera/images" to "/camimages/" then set webroot to "/camimages"

The fact that it displays the time means that it can't display the image (it does prove that the script is runnig though )
 
Old 03-27-2003, 11:39 AM   #10
lockejr
Member
 
Registered: Jan 2003
Location: Wichita, KS
Distribution: Slack, Gentoo, CPUBuilders
Posts: 37

Original Poster
Rep: Reputation: 15
Cool setting up that alias did it. Now one more question, is there a line I can enter that will make it display all the camera's on one page?
 
Old 03-27-2003, 02:39 PM   #11
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Do you have an SSI enabled site?
 
Old 03-27-2003, 02:42 PM   #12
lockejr
Member
 
Registered: Jan 2003
Location: Wichita, KS
Distribution: Slack, Gentoo, CPUBuilders
Posts: 37

Original Poster
Rep: Reputation: 15
no i don't, it's really basic, internal for the company.
 
Old 03-27-2003, 02:45 PM   #13
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
I have one idea - I have never tried it though - give me half an hour.
 
Old 03-27-2003, 03:14 PM   #14
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
I can't beleive it worked!

1) Remove the line that gets the time "$time = localtime(time());"
2) Replace the print command, all the HTML and the EOF line with:
Code:
print "Location:$webroot/$last\n\n";
3) Create an HTML page like:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Cams 1 &amp; 2</TITLE>
</HEAD>
<BODY>
This is cam 1 <IMG alt="Camera 1" src="/cgi-bin/img.cgi?/cam1">
<BR clear="all">
This is cam 2 <IMG alt="Camera 2" src="/cgi-bin/img.cgi?/cam2">
</BODY>
</HTML>
Then access the HTML page - that's it!

You can now insert a camera picture into an existing page with just an img link.

As an extension you could modify a Javascript rollover script to download the next image then swap them - this would save downloading the whole page to get an update on the image and would also be more transparent to the user.
 
Old 03-27-2003, 04:06 PM   #15
lockejr
Member
 
Registered: Jan 2003
Location: Wichita, KS
Distribution: Slack, Gentoo, CPUBuilders
Posts: 37

Original Poster
Rep: Reputation: 15
awesome man it is perfect
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Webpage How-To Linux~Powered Programming 5 03-19-2007 06:20 PM
Webpage troycus Linux - Software 4 06-16-2005 01:26 PM
webpage sanjibgupta Linux - Newbie 3 10-11-2004 04:09 AM
no one can see my webpage! killjoyce Linux - Networking 7 04-06-2004 03:53 PM
How can I browse webpage clearly? bin_shell Linux - Software 1 03-03-2004 05:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration