среда, 19 марта 2014 г.

zimbra CRITICAL DATABASE ALERT LDAP primary MDB database is 90% full


I moved zimbra folder to another partition and created symlink from /opt/zimbra to /home/zimbra. After that, all services started without problems, but every 30 minutes I am receiving on my email "CRITICAL DATABASE ALERT" from zimbra server. The solution finded in zimbra support forum: Login as zimbra user and:
 # update database size  
 zmlocalconfig -e ldap_db_maxsize=67108864  
 # update log size  
 zmlocalconfig -e ldap_accesslog_maxsize=536870912  
 # allow time for zmconfigd to apply new setting (as suggested by Quanah)  
 sleep 90  
 # stop slapd  
 ldap stop  
 # change to database directory  
 cd /opt/zimbra/data/ldap/mdb/db  
 # backup database  
 /opt/zimbra/libexec/zmslapcat /opt/zimbra/data/ldap/mdb/db  
 # move to .old  
 mv data.mdb data.mdb.old  
 # recreate database with new size and restore from backup  
 /opt/zimbra/openldap/sbin/slapadd -q -b "" -F /opt/zimbra/data/ldap/config -l /opt/zimbra/data/ldap/mdb/db/ldap.bak  
 # start slapd  
 ldap start  
 # archive original  
 gzip data.mdb.old  

вторник, 4 февраля 2014 г.

Remote reboot D-Link 524UP


Frozen usb-modems in old routers such as D-Link 524UP makes me crazy. I had to collect stat info from four places and often d-link routers were offline. I found that D-Link has http request to reboot. And I added to PC with Linux, placed at the same place, simple script to check internet connection and reboot router if no internet connection.
 #!/bin/bash  
   
 ### google DNS ip ######  
 ip="8.8.8.8"  
   
 ping $ip -c 1 > /dev/null  
   
 #### 192.168.0.1 - local ip of wifi router #########  
   
 if [ $? -ne 0 ]  
 then  
 wget -q http://login:pass@192.168.0.1/Tools/reboot.xgi &>/dev/null  
 fi  
   

Create mail list in Zimbra mail server. Simple shell script.


 #!/bin/sh  
   
 # get all users list of mydomain.com   
 /opt/zimbra/bin/zmprov -l gaa mydomain.com > /opt/zimbra/scripts/users_mailbox.txt  
   
 # add users to mail list all@mydomain.com  
   
 for mbox in `cat /opt/zimbra/scripts/users_mailbox.txt`  
 do  
 echo "$mbox";  
 /opt/zimbra/bin/zmprov -l adlm all@maydomain.com $mbox  
 done  

четверг, 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