Redirect image from the JPEG cam on the private network

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dren
Forum Newbie
Posts: 2
Joined: Sun Feb 01, 2009 1:16 pm

Redirect image from the JPEG cam on the private network

Post by dren »

Hi all.

My question is. how to redirect JPEG picture from a device on the private network to the internet network? So I have the following:


JPEG camera <= 172.3.2.1 => eth0 [Debian PC, Apache, PHP] eth1 <=internet user => Web client

Currently, PHP is save that picture to the WWW directory so that www clients can read that. Is there a better and faster way?n

Regards Dre
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: Redirect image from the JPEG cam on the private network

Post by infolock »

well, if you're just serving up the images on the web for users to view, yeah.. it would make sense to just post them to www. anywhere outside of www is restricted and cannot be accessed via web clients. if it is accessible, you're gonna have more problems than just images: you're gonna have security issues as well.

if this isn't what you mean, please explain a bit more. thanks
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Redirect image from the JPEG cam on the private network

Post by VladSun »

So, your JPEG camera has IP 172.3.2.1 in your private network, right?
If it's so then you need:
1. Enable IP packets forwarding:

Code: Select all

sysctl -w net.ipv4.ip_forward="1"

Code: Select all

iptables -P FORWARD DROP
iptables -A FORWARD -i eth0 -s 172.3.2.1 -j ACCEPT
iptables -A FORWARD -i eth1 -d 172.3.2.1 -j ACCEPT
2. Redirect traffic to JPEG camera (port forwarding):

Code: Select all

iptables -t nat -A PREROUTING -i eth1 -p tcp -d your_server_IP_on_eth1 --dport 8089 -j DNAT --to-destination 172.3.2.1
This way anybody who connects (TCP/IP) to your_server_IP_on_eth1:8089 will in fact connect to 172.3.2.1:8089
There are 10 types of people in this world, those who understand binary and those who don't
dren
Forum Newbie
Posts: 2
Joined: Sun Feb 01, 2009 1:16 pm

Re: Redirect image from the JPEG cam on the private network

Post by dren »

Hi.

Thanks for your ideas. I think that I have found the solution.

--test.php file
<?php
$cam= "http://172.31.x.x.x/image.esp?photo=1"; //this is the IP address of the JPEG webcam withc returns a JPEG picure each time it is called

$myJpeg = fopen($cam, 'rb');
if ($myJpeg) {
header('Content-Type: image/png');
fpassthru($myJpeg);
}

?>

---webclient.html file

//javascript autorefresh image here using
<img id='img' src='test.php'/>

So my design is so that I have a Debian PC with two network interfaces. One is connected to local network (172.31.x.x) and the other one is conneced to the public (internet) network.
Now the netork firewall can be configured to access only the www server. There is no access to the private network from the internet.
Post Reply