Admins eHow SysAdmin Tips & Tricks

July 30, 2009

Disable submit button on click

Filed under: HTML,JavaScript — Tags: , , , , — admin @ 10:50 am

Are you looking for a JavaScript code to disable your HTML form submit button on first click to prevent double clicks ?
so here is the code 🙂 , it has been tested on IE 8 , Firefox 3.5 and Chrome. I am pretty sure it works on all browsers which support JavaScript.
Put the following code into <head> section of your page :

<script language="javascript" type="text/javascript">
function dis(){
frm=document.forms[0];
frm.submit.disabled=true;
}
</script>

and the following code into <form> section :

onsubmit="dis();"

for example :

<form method="post" action="/index.php" onsubmit="dis();">

July 24, 2009

Delete Files Older Than x Days on Linux

Filed under: CentOS,Debian,General — Tags: , , , — admin @ 1:40 pm

The find utility on linux allows you to pass in a bunch of interesting arguments, including one to execute another command on each file. We’ll use this in order to figure out what files are older than a certain number of days, and then use the rm command to delete them.

Command Syntax

find /path/to/files* -mtime +5 -exec rm {} \;

Note that there are spaces between rm, {}, and \;

Explanation

  • The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
  • The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.
  • The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.

or you can use the following command :

find /path/to/files* -mtime +5 | xargs rm -f

This should work on Ubuntu, Suse, Redhat, or pretty much any version of linux.

July 19, 2009

How to enable mod_rewrite on Apache2

Filed under: Apache,Debian,General — Tags: , — admin @ 12:51 pm
a2enmod rewrite
/etc/init.d/apache2 restart

July 15, 2009

How to install ffmpeg on Debian Lenny from SVN

Filed under: Debian,General — Tags: , , , — admin @ 11:36 am

From ffmpeg.org :

FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec – the leading audio/video codec library.

Installation Guide :
download the following debian package and install it :

wget http://www.debian-multimedia.org/pool/main/d/debian-multimedia-keyring/debian-multimedia-keyring_2008.10.16_all.deb
dpkg -i debian-multimedia-keyring_2008.10.16_all.deb 

Add the following lines to your /etc/apt/source.list :

nano /etc/apt/nano sources.list
deb http://www.debian-multimedia.org lenny main
deb-src http://www.debian-multimedia.org lenny main

update your apt cache :

apt-get update

install needed utils :

apt-get install checkinstall yasm git-core subversion

install ffmpeg dependencies :

apt-get build-dep ffmpeg

Install x264 :

git clone git://git.videolan.org/x264.git
cd x264
./configure
make
checkinstall --pkgname=x264 --pkgversion "1:0.svn`date +%Y%m%d`" --backup=no --default

Install libtheora :

wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz
tar xzvf libtheora-1.1.1.tar.gz
cd libtheora-1.1.1
./configure
make
checkinstall --pkgname=libtheora --pkgversion "1.1.1" --backup=no --default

remove old libx264-dev :

apt-get remove libx264-dev

download the latest release of ffmpeg using subversion :

svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

configure and make ffmpeg :

cd ffmpeg/
./configure --enable-version3 --enable-libmp3lame --enable-libtheora --enable-libx264 --enable-libgsm --enable-postproc --enable-libxvid --enable-libfaac --enable-pthreads --enable-libvorbis --enable-gpl --enable-x11grab --enable-nonfree
make
checkinstall --pkgname=ffmpeg --pkgversion "4:0.5+svn`date +%Y%m%d`" --backup=no --default

and we are all set 🙂
just one more note , if you are going to convert flv files to 3gp files like me 😀 use the following command :

ffmpeg -i input.flv -s 176x144 -vcodec h263 -acodec aac output.3gp

July 14, 2009

Limit Connections per IP using mod_limitipconn on cPanel

Filed under: Apache,CentOS,cPanel,General,Security — Tags: , , , , , , — admin @ 9:41 am

one of the problems I had on one of my cPanel servers was that some people were using download managers to download files from server , so hundreds of connections were being ESTABLISHED to Apache and it was becoming like a dos attack and causing Apache to become non responsive.
so here is what I did to limit connections per IP in a cPanel hosting server :
there is an Apache module named mod_limitipconn which will take care of it for us.
first download the latest version of mod_limitipconn from this site : http://dominia.org/djao/limitipconn2.html
decompress and install it.
at current time the latest version is 0.23.

wget http://dominia.org/djao/limit/mod_limitipconn-0.23.tar.bz2
tar jxvf mod_limitipconn-0.23.tar.bz2
cd mod_limitipconn-0.23
/usr/local/apache/bin/apxs -cia mod_limitipconn.c

next step is to add the required configuration to the Apache config file , we can add this directly to the end of httpd.conf file but the problem is that if we do this , the httpd.conf will be overwritten by easyapache so we will use include files to add our config.
login into your WHM panel , and follow the following menu items :
Main >> Service Configuration >> Apache Configuration >> Include Editor
on the Post VirtualHost Include section , choose All Versions from drop down menu and add the following config into it :

<IfModule mod_limitipconn.c>
<Location />
MaxConnPerIP 10
NoIPLimit images/*
</Location>
</IfModule>

then click on update and restart Apache server.
now We are all set 🙂

July 12, 2009

Backup Your Data in Linux by sending them to your GMail

Filed under: CentOS,Debian,General,Security — Tags: , , , — admin @ 8:33 am

A very effective way for backing up your data on a Linux server is to set a cron job on your box to mail your data to your GMail account. GMail servers are very reliable and give you a huge amount of space for free. so they are pretty suitable for backing up sensitive data.
In order to accomplish this , first create a directory named “backup” in the root directory of your box :

cd / && mkdir backup

then you need to create a script to do the backup and mail it for you.

nano /usr/bin/backup

copy and paste the following into the file :

cd /backup
rm -rf /backup/*
cp LIST_OF_FILES .
tar jcf backup.tar.bz2 *
echo | mutt -a backup.tar.bz2 -s "my daily backup" -- adminsehow@gmail.com

you have to change LIST_OF_FILES string to the list of the files you want to be backed up separated by space , and change adminsehow@gmail.com to your own gmail account.
as you can see in the script we are compressing the data files to make them as small as possible.
also we are using “mutt” to send emails so you need to install it , in Debian you can install it by following command :

apt-get install mutt

make the script executable :

chmod +x /usr/bin/backup

lastly you need to set a cron job , so open the cron file by following command :

crontab -e

and copy and paste the following command into it :

0 0 * * * /usr/bin/backup

it will run your backup script once daily 🙂
also don’t forget you need to have a working smtp server on your Linux box.

Powered by WordPress