iptables config example
*filter
:INPUT ACCEPT [284757:218570741]
:FORWARD ACCEPT [39841:24366908]
:OUTPUT ACCEPT [295372:221619506]
-A INPUT -s ! 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 3128 -j DROP
-A INPUT -i lo -j ACCEPT
-A FORWARD -i eth2 -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
COMMIT
# Completed on Thu Apr 10 20:09:49 2008
# Generated by iptables-save v1.3.5 on Thu Apr 10 20:09:49 2008
*nat
:PREROUTING ACCEPT [3356:298279]
:POSTROUTING ACCEPT [5:3398]
:OUTPUT ACCEPT [6455:393108]
-A PREROUTING -i eth1 -p tcp -m tcp --dport 22 -j REDIRECT --to-ports 3128
-A PREROUTING -i eth1 -p udp -m udp --dport 22 -j REDIRECT --to-ports 3128
-A PREROUTING -i eth2 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
-A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j DROP
-A PREROUTING -d 209.85.201.189 -i eth2 -p tcp -m tcp --dport 443 -j DROP
-A POSTROUTING -o eth1 -j MASQUERADE
COMMIT
# Completed on Thu Apr 10 20:09:49 2008
# Generated by webmin
*mangle
:FORWARD ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
# Completed
--
/usr/bin/ld: cannot find -lcrypto [ nagios ]
make all-recursive
make[1]: Entering directory `/usr/local/src/nagios-plugins-snmp'
Making all in src
make[2]: Entering directory `/usr/local/src/nagios-plugins-snmp/src'
gcc -DINET6 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -lcrypto -Dlinux -I/usr/include/rpm -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -I/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE -I. -I/usr/include/net-snmp -o check_snmp_int check_snmp_int.o nagios_common_snmp.o -L/usr/lib -lnetsnmp -lcrypto -lm -L/usr/lib/lib -lwrap
/usr/bin/ld: cannot find -lcrypto
make[2]: *** [check_snmp_int] Error 1
make[2]: Leaving directory `/usr/local/src/nagios-plugins-snmp/src'
--
How to vi text editor
The text editor vi, is supplied with all Linux distributions. It is a difficult editor to come to grips with initially, but once you do the rewards are vast. The editor is quite intuitive once you get the hang of it. The main thing to remember when using it is that the very last line on the screen (Or window that the editor is running in), is the status line, much like the status bar at the bottom of Netscape, or *cough* Internet Exlporer. It will tell you there what mode your in, and what operations have been completed - such as save or quit.
Lets start by firing up the editor with a blank text file. From the command line, type vi blah. Another cool thing about Linux is that you dont need to supply the legacy ".xxx" extensions given to us by DOS, and Windows. The editor will appear on-screen, with a tilde, ~, on evey line, and at the bottom of the screen it says "blah" [new file]. If you want to put anything into this file, you have to put vi into insert mode. Do this by typing the letter 'i' on its own. "-- INSERT --" appears on the bottom of the screen. Now you can type in anything you want. Try typing "Hello", and then on a new line "World". Now try going back up to the line above, using the cursor keys and try to delete Hello. You wont be able to. When you give a Carraige Return (Press Enter in other words), the text on that line becomes static. If you want to delete it, heres how.
Press your Esc button on the top left of the keyboard, and the "-- INSERT --" at the base dissapears. Vi is ready to accept a new command. The only thing here is that vi will only delete what is in front of the cursor, let me show you. Bring the cursor to the start of Hello, and press the x key once. Now only 'ello' remains. This doesnt really make any sense, so we'll delete the line altogether. Press 'd' twice in quick sucession. Now we have the word 'World' on its own. Press 'i' and insert "Hello" again. This time, leave the text in insert mode. Press the "Insert" key on your keyboard, its above the cursor keys. The "-- INSERT --" at the base of the screen has been replaced with "-- REPLACE --". Now type the word "Nurse" over the existing "World". Press Esc again to return to the ready mode.
Vi has a search tool too, which I find indispensable. From the ready mode, type in a slash, /, and input the text you want to look for. Remember, since Linux is case sensitive, looking for "money" is not the same as looking for "Money".
Well, what about saving the file, or quitting without saving? What about just quitting? Its easy. From the ready mode, type in ":w" to write the file ... you already supplied the file name when you typed 'vi blah' earlier. The editor will return this on the status line : "blah" [New File] 1 line, 12 characters written. Lets quit out of it altogether. Type in ":q". You have been returned to the command prompt. There was an easier way of doing that ... from the ready mode in the editor, you could have just typed in, in capitals, "ZZ" ... this saves the file and quits. If you had wanted to quit without saving the changes, you could have just typed in ":q!", and nothing would have saved ... blah wouldn't have existed.
Thats the basics of vi, but you could always 'man vi' from the command prompt ...
--
Linux commands
--
script to search only or search and replace exact pattern
clear
search_pattern ()
{
read -p " Enter the path where your text file is loscated: " p
read -p "Enter the pattern you want to serch: " pat
pattern=`sed -n "\|$pat|p" $p`
if [ -n "$pattern" ]; then
echo -e "$pattern"
else
echo -e "######### The pattern cannot be found #########"
fi
}
replace_pattern ()
{
read -p " Enter the path where your text file is loscated: " p
read -p "Enter the pattern you want to serch: " pat
read -p "Enter the pattern you want to replace: " reppat
pattern=`sed -n "\|$pat|p" $p`
if [ -f "$p" ]; then
if [ -n "$pattern" ]; then
sed -i "s|$pat|$reppat|" $p
else
echo -e "######### the pattern is not found ############# "
fi
else
echo -e "############ the file is not found #############"
fi
}
read -p " What do you ant to do: [ search or replace ]: " t
case $t in
search ) search_pattern
;;
replace ) replace_pattern
;;
* ) echo -e "please enter search or replace"
--
backup manager shell script
weekly=`date +%a`
monthly=`date +%d`
mark=`date +%C%a%B%Y`
clear
daily_backup ()
{
test_website=`sed -n /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ -z "$test_website" ]; then
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
else
sed -i /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
fi
else
echo -e "########## the backup dir does not exist #############"
fi
else
echo -e "########## the folder $web does not exist #############"
fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}
weekly_backup ()
{
test_website=`sed -n /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ -z "$test_website" ]; then
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ $weekly = "sun" ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e "######### today is not sunday ##########"
fi
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
else
sed -i /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ $weekly = "sun" ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e "######### today is not sunday ##########"
fi
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
fi
else
echo -e "########## the backup dir does not exist #############"
fi
else
echo -e "########## the folder $web does not exist #############"
fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}
monthly_backup ()
{
test_website=`sed -n /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ -z "$test_website" ]; then
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ $monthly = "31" ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e " Today is not the 31st of the months "
fi
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
else
sed -i /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
tar cvf /websites/$d/backup/$d.$mark.tar /websites/$d
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
fi
else
echo -e "########## the backup dir does not exist #############"
fi
else
echo -e "########## the folder $web does not exist #############"
fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}
delete_backup ()
{
test_website=`sed -n /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ -n "$test_website" ]; then
sed -i /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
else
echo -e "the scritp for $d does not exist"
fi
else
echo -e "########## the backup dir does not exist #############"
fi
else
echo -e "########## the folder $web does not exist #############"
fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}
read -p "read enter your domain name: " d
read -p "Back up to be done [ delete / daily / weekly / monthly ]: " p
read -p " Enter folder to be backed up " f
case $p in
delete ) delete_backup
;;
daily ) daily_backup
;;
weekly ) weekly_backup
;;
monthly ) monthly_backup
;;
* ) echo -e " Please enter daily , weekly or monthly "
esac
--
Database manager script
clear
add_DB ()
{
read -p " Enter your domain name: " d
read -p " Enter your choice of database name : " DB
read -p " Enter your user name: " u
read -p " Enter your paasword : " p
check_DB=$( mysql -u root -pagnello -e "show databases;" |grep "\<${DB}\>")
if [ -d /websites/"$d" ]; then
if [ -z $check_DB ]; then
mysql -u root -pagnello -e "create database ${DB};"
mysql -u root -pagnello -e "GRANT ALL ON ${DB}.* to '${u}'@'localhost' IDENTIFIED BY '${p}'"
else
echo -e "########## The database already exist ############"
fi
else
echo -e "########## The domain does not exist #############"
fi
}
del_DB ()
{
read -p " Enter your domain name: " d
read -p " Enter your database to be deleted : " DB
check_DB=$(mysql -u root -pagnello -e 'show databases;' |grep "\<${DB}\>")
check_mysql_db=$(mysql -u root -pagnello -e 'use mysql;' -e "select Db,User from db where Db='$DB';" |grep $DB |awk '{print $1}')
check_mysql_user=$(mysql -u root -pagnello -e 'use mysql;' -e "select Db,User from db where Db='$DB';" |grep $DB |awk '{print $2}')
if [ -d /websites/"$d" ]; then
if [ "$check_DB" = "$DB" ]; then
if [ "$DB" = "$check_mysql_db" ];then
mysql -u root -pagnello -e "drop database $DB;"
mysql -u root -pagnello -e 'use mysql;' -e "DELETE FROM db WHERE Db='${check_mysql_db}' AND Host='localhost'"
mysql -u root -pagnello -e 'use mysql;' -e "DELETE FROM user WHERE User='${check_mysql_user}' AND Host='localhost'"
else
echo -e "########## The database does not match in the mysql DB file ############"
fi
else
echo -e "########## The database does not exist #############"
fi
else
echo -e "############# The domani does not exist ##########"
fi
}
edit_DB ()
{
read -p " Enter your domain name: " d
read -p " Enter your choice of database name : " DB
read -p " Enter your user name: " u
read -p " Enter your paasword : " p
check_DB=$( mysql -u root -pagnello -e "show databases;" |grep "\<${DB}\>")
check_DB=$(mysql -u root -pagnello -e 'show databases;' |grep "\<${DB}\>")
check_mysql_db=$(mysql -u root -pagnello -e 'use mysql;' -e "select Db,User from db where Db='$DB';" |grep $DB |awk '{print $1}')
check_mysql_user=$(mysql -u root -pagnello -e 'use mysql;' -e "select Db,User from db where Db='$DB';" |grep $DB |awk '{print $2}')
if [ -d /websites/"$d" ]; then
if [ "$check_DB" = "$DB" ]; then
if [ "$DB" = "$check_mysql_db" ];then
if [ "$u" = "$check_mysql_user" ]; then
mysql -u root -pagnello -e 'use mysql;' -e "UPDATE user SET Password=PASSWORD('$p') WHERE user='$check_mysql_user';"
mysql -u root -pagnello -e 'use mysql;' -e "FLUSH PRIVILEGES;"
else
echo -e "################ the user that you enter does not exist #################"
fi
else
echo -e "########## The database does not match in the mysql DB file ############"
fi
else
echo -e "########## The database does not exist #############"
fi
else
echo -e "############# The domani does not exist ##########"
fi
}
read -p "Do you want to add / delete /edit database: " r
case $r in
add ) add_DB
;;
delete ) del_DB
;;
edit ) edit_DB
;;
* ) echo -e "Please enter add / delete /edit "
esac
Add IP aliases script
1) we need to enter the config file for the IP-aliases
2) we need to enter the ip number
#!/bin/bash
clear
read -p "Enter the IP number: [example eth0:1 eth0:2]: " ip
read -p "Enter the configuration file : " cf
path=/etc/sysconfig/network-scripts/ifcfg-$cf
check=`ifconfig |grep "\<$ip\>"`
if [ ! -f /etc/sysconfig/network-scripts/ifcfg-"$cf" ]; then
if [ -z "$check" ]; then
cat >> $path << _eof_
DEVICE=$cf
BOOTPROTO=static
BROADCAST=192.168.0.255
HWADDR=00:0C:29:9D:65:6F
IPADDR=$ip
NETMASK=255.255.255.0
NETWORK=192.168.0.0
ONBOOT=yes
_eof_
echo -e "######## Added the IP aliases ##############"
ifup $cf
else
echo -e "The Ip address already exist"
fi
else
echo -e "The ip aliases $cf exist"
fi
--
add custom error pages script
1) that you a domain set up and proper vhsot directive ( see add domin script )
#!/bin/bash
clear
url_custom_error_pages ()
{
read -p "Enter your domain name: " d
read -p "Enter the error number : " e
read -p "Enter the url you want the error page to redirect to " u
if [ -d /websites/"$d" ]; then
if [ -z "$(sed -n "/\#add_custom_error_page_${d}_from_${e}\#/,/\#add_custom_error_page_${d}_from_${e}\#/p" /usr/local/apache2/conf/extra/httpd_vhost.conf)" ]; then
sed -i "/\#FEATURES_${d}2631\#/a\#################add_custom_error_page_${d}_from_${e}\#################\n ErrorDocument ${e} http\:\/\/$u \n#################add_custom_error_page_${d}_from_${e}\##################" /usr/local/apache2/conf/extra/httpd_vhost.conf
/etc/init.d/httpd graceful
else
echo -e "The custom error page already exist "
fi
else
echo -e "the domain $d does not exist"
fi
}
folder_custom_error_pages ()
{
read -p "Enter your domain name: " d
read -p "Enter the error number : " e
read -p "Enter the foler you want the error page to redirect to " f
if [ -d /websites/"$d" ]; then
if [ -z "$(sed -n "/\#add_custom_error_page_${d}_from_${e}\#/,/\#add_custom_error_page_${d}_from_${e}\#/p" /usr/local/apache2/conf/extra/httpd_vhost.conf)" ]; then
sed -i "/\#FEATURES_${d}2631\#/a\#################add_custom_error_page_${d}_from_${e}\#################\n ErrorDocument ${e} ${f} \n#################add_custom_error_page_${d}_from_${e}\##################" /usr/local/apache2/conf/extra/httpd_vhost.conf
/etc/init.d/httpd graceful
else
echo -e "The custom erro page alread exist"
fi
else
echo -e "the domain $d does not exist"
fi
}
read -p " do you want your error page to redirect to url or to specific folder: [ url / folder ] " r
case $r in
url ) url_custom_error_pages
;;
folder ) folder_custom_error_pages
;;
* ) echo -e " please enter ur l or folder "
esac
--
generate awstats scripts
echo -e " enter the domain to generate webstats "
read d
domain_user=` echo $d |sed s/\.com/com2631/g `
tmp_name=` echo $d |sed s/\.com//g `
if [ -d /websites/"$d" -a -d /websites/"$d"/webstats ]; then
echo -e "awstats exist for this $d exist "
else
echo -e "generating awstats for $d "
mkdir /websites/"$d"/webstats
chown "$domain_user":"$domain_user" /websites/"$d"/webstats
cp -R /usr/local/src/awstats-6.7/* /websites/"$d"/webstats
echo -e "copying source dir to the webstats dir"
sleep 2
cp /websites/"$d"/webstats/wwwroot/cgi-bin/awstats.model.conf /websites/"$d"/webstats/wwwroot/cgi-bin/awstats."$tmp_name".sys.qualiproj.qualispace.com.conf
sleep 2
if [ -d /websites/"$d"/web/awstats ];then
echo -e "/web/awstats exist "
exist 1
else
echo -e "creating awstats"
sleep 2
mkdir /websites/"$d"/web/awstats
fi
chown "$domain_user":"$domain_user" /websites/$d/web/awstats
cp -R /websites/"$d"/webstats/wwwroot/icon /websites/"$d"/web/awstats/
config_file="/websites/$d/webstats/wwwroot/cgi-bin/awstats.$tmp_name.sys.qualiproj.qualispace.com.conf"
cat >> $config_file << _eof_
LogFile="/websites/"$d"/logs/$tmp_name.sys.qualiproj.access_log"
LogType=W
LogFormat=1
LogSeparator=" "
SiteDomain="$tmp_name.sys.qualiproj.qualispace.com"
HostAliases="www.$tmp_name.sys.qualiproj.qualispace.com agnello.sys.qualiproj.qualispace.com localhost 127.0.0.1 "
DNSLookup=1
DirData="/websites/$d/webstats"
DirCgi="/cgi-bin"
DirIcons="/web/awstats/icon"
AllowToUpdateStatsFromBrowser=0
AllowFullYearView=2
EnableLockForUpdate=0
DNSStaticCacheFile="dnscache.txt"
DNSLastUpdateCacheFile="dnscachelastupdate.txt"
SkipDNSLookupFor=""
AllowAccessFromWebToAuthenticatedUsersOnly=0
AllowAccessFromWebToFollowingAuthenticatedUsers=""
AllowAccessFromWebToFollowingIPAddresses=""
CreateDirDataIfNotExists=0
BuildHistoryFormat=text
BuildReportFormat=html
SaveDatabaseFilesWithPermissionsForEveryone=0
PurgeLogFile=0
KeepBackupOfHistoricFiles=0
DefaultFile="index.html"
SkipHosts=""
SkipUserAgents=""
SkipFiles=""
SkipReferrersBlackList=""
OnlyHosts=""
OnlyUserAgents=""
OnlyFiles=""
NotPageList="css js class gif jpg jpeg png bmp ico swf"
ValidHTTPCodes="200 304"
ValidSMTPCodes="1 250"
AuthenticatedUsersNotCaseSensitive=0
URLNotCaseSensitive=0
URLWithAnchor=0
URLQuerySeparators="?;"
URLWithQuery=0
URLWithQueryWithOnlyFollowingParameters=""
URLWithQueryWithoutFollowingParameters=""
URLReferrerWithQuery=0
WarningMessages=1
ErrorMessages=""
DebugMessages=0
NbOfLinesForCorruptedLog=50
WrapperScript=""
DecodeUA=0
LevelForBrowsersDetection=2
LevelForOSDetection=2
LevelForRefererAnalyze=2
LevelForRobotsDetection=2
LevelForSearchEnginesDetection=2
LevelForKeywordsDetection=2
LevelForFileTypesDetection=2
LevelForWormsDetection=0
_eof_
perl /websites/"$d"/webstats/tools/awstats_buildstaticpages.pl -awstatsprog=/websites/"$d"/webstats/wwwroot/cgi-bin/awstats.pl -update -config="$tmp_name".sys.qualiproj.qualispace.com -dir=/websites/"$d"/web/awstats/
mv /websites/"$d"/web/awstats/awstats.$tmp_name.sys.qualiproj.qualispace.com.html /websites/"$d"/web/awstats/index.html
cron_awstatsupdate="/etc/cron.daily/awstatsupdate"
cat >> $cron_awstatsupdate << _eof_
###################cron_upadte for domain $d#######################
perl /websites/"$d"/webstats/tools/awstats_buildstaticpages.pl -awstatsprog=/websites/"$d"/webstats/wwwroot/cgi-bin/awstats.pl -update -config="$tmp_name".sys.qualiproj.qualispace.com -dir=/websites/"$d"/web/awstats/
###############