четверг, 16 января 2014 г.

D-Link DCS-2210 as security cam and web-online translation on your website.

I had to install ip-cam in shop and configure it for online translation for manager and store video archive for one month on remote server.

Step 1: Configure ip-cam for sending snapshots to external FTP server.
Step 2: Show online translation on web page for shop manager(vlc+apache).
Step 3: Configure linux server to make video for previous day and store video file for one month(cron+mencoder).


Configure IP-cam:
1. Set static ip-address for IP-cam and check RTSP settings. RTSP settings must be: port 554 and Access names: live1.sdp and live2.sdp

2. In "Event Setup" - write ftp setting. (IP of remote ftp-server, login, pass and folder)

3. In "Event Setup"->"Media": Set name "Media1", than choose "Snapshot". In "Snapshot": Source "Profile2", Send 4 pre-event image(s), Send 7 post-event image(s) [0~7], File Name Prefix: shop

4. In "Event Setup"->"EVENT": Event name: Upload_FTP, in trigger set "Passive Infrared sensor" and choose days of EVENT SCHEDULE. In "ACTION" select your ftp-server and choose in "Attached media:" Media1

5.Forwarding RTSP ports and web-access to ip-cam.
In router that placed in my case in shop, set forwarding rules for RTSP and web-access. For RTSP: EXTERNAL_ROUTER_IP:20554 to LOCAL_IP_IPCAM:554 and web-access EXTERNAL_ROUTER_IP:20080 to LOCAL_IP_IPCAM:80

Online translation
1. Install vlc on remote server. In my case - "yum install vlc.x86_64" (I have fedora linux)
2. Create simple bash script and write this:

 cvlc --daemon rtsp://EXTERNAL_IP_OF_SHOP_ROUTER:20554/live1.sdp --rtsp-user=login_for_your_ip_cam --rtsp-pwd=pass_for_your_ip_cam --sout "#transcode{vcodec=FLV1,vb=2048,fps=25,scale=1,acodec=mp4a,deinterlace}:std{access=http{mime=video/x-flv},dst=0.0.0.0:8026/stream.flv}" --loop --color -I dummy  


Set external ip-address of your router instead EXTERNAL_IP_OF_SHOP_ROUTER and check login, password.
Run script and cvlc will be started as deamon and connected to your ip-cam. Video flow will be in stream.flv.
For future plans, you have to write script for checking if cvlc proccess is running.
Now you can be connected to stream.flv.
3. For web-online translation I used jwplayer. You can find it here http://www.jwplayer.com/download/. Download it and extract to your website folder. In your root folder of website create html page with this contents:

 <p>My IPcam</p>  
 <script type="text/javascript" src="mediaplayer/swfobject.js"></script>  
 <div id="cam3">My IPcam</div>  
 <script type="text/javascript">  
 var so = new SWFObject('mediaplayer/player.swf','mpl','480','270','8');  
 so.addParam('allowfullscreen','true');  
 so.addParam('flashvars','file=http://IP_OF_YOUR_SERVER_WHERE_VLC_IS_RUNNING:8026/stream.flv');  
 so.write('cam3');  
 </script>  


Check right path of jwplayer and set your ip-address instead IP_OF_YOUR_SERVER_WHERE_VLC_IS_RUNNING

Now you can open this html page in your browser.

Generating video file and storing it for one month

I had to store video files from camera one month.
Ip-cam sends snapshots to ftp-server, it allow you to make video file with snapshots. I created simple bash-script for generating video and added this script to cron that runs this script at the end of the day (mencoder must be installed).

 #!/bin/bash  
 current_date=`date +"%Y%m%d"`  
 output_file_name="$current_date.avi"  
 ### JPG folder. Path of folder where your camera sends shaphots ###  
 directory="FOLDER_WITH_SNAPSHOTS"  
 ### VIDEO folder where video files will be stored. My example /var/home/data/camera/video ###  
 save_directory="/var/home/data/camera/video"  
 ########## Generating video file ###########  
 mencoder "mf://$directory/shop$current_date*.jpg" -vf scale=640:-11 -oac copy -ovc lavc -lavcopts vcodec=msmpeg4:vbitrate=2000 -ffourcc MP43 -fps 24 -o "$save_directory/$output_file_name"  
 #### deleting jpg files and logs ######  
 rm -f $directory/shop$current_date*.jpg  
 rm -f $directory/*.log  
 #### if time of file more then 31 days, delete it###############  
 find /var/home/data/camera/video/ -atime +31|xargs rm -f  

RDP over iptables

RDP over iptables

IPTABLES='/usr/sbin/iptables'
IP_EXT="external server ip-address "
IP_INT="internal server ip-address "
SRDP_PORT="external RDP-port"
DRDP_PORT="real rdp port"
RDP_HOST_IP="real ip of RDP-host"

$IPTABLES -t nat -I PREROUTING --dst $IP_EXT -p tcp --dport $SRDP_PORT -j DNAT --to-destination $RDP_HOST_IP:$DRDP_PORT

$IPTABLES -t nat -I POSTROUTING -p tcp --dst $RDP_HOST_IP --dport $DRDP_PORT -j SNAT --to-source $IP_INT

$IPTABLES -t nat -I OUTPUT --dst $IP_EXT -p tcp --dport $SRDP_PORT -j DNAT --to-destination $RDP_HOST_IP:$DRDP_PORT

$IPTABLES -I FORWARD -i $IP_INT --dst $RDP_HOST_IP -j ACCEPT


Add samba user

1. useradd networkuser -M -G users -s /sbin/nologin
2. smbpasswd -a networkuser

delete:
1. smbpasswd -x user
2. userdel -r user  (-r if home directory)

Manage user group

Add user to secondary group:
useradd -G {group-name} username

Add NEW! user to primary group:
useradd -g {group-name} username

Add a EXISTING! user to existing group
usermod -a -G {group-name} username

среда, 15 января 2014 г.

Add openvpn user

Fedora 11 Add users to openvpn 1. Generate key for client
./build-key client