Sunday, December 25, 2011

Setup and Configure Sendmail Server

Hello Everyone,
After verifying connectivity, DNS, and telnet to smtp, it is right time to configure your Sendmail server. To enable masquerading and binding your domain for sendmail, you should change the sendmail configuration file which is located in /etc/mail/sendmail.mc. Open this file with vi and change the following lines:
change:
LOCAL_DOMAIN(`localhost.localdomain')dnl     to     LOCAL_DOMAIN(khosro.org)dnl
dnl MASQUERADE_AS(`mydomain.com')dnl      to   MASQUERADE_AS(khosro.org)dnl
dnl FEATURE(masquerade_envelope)dnl            to   FEATURE(masquerade_envelope)dnl
dnl FEATURE(masquerade_entire_domain)   to FEATURE(masquerade_entire_domain)dnl
dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl   to MASQUERADE_DOMAIN(khosro.org)dnl

Replace khosro.org with your domain name.
Now, you should run the following command in order to take effect your change in configuration file. You should use m4 command like this:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Now, restart your sendmail with this command:    service sendmail restart
If everything is fine, you should able to send an email. Create a file and put some text on this file. Name this file to message_file. Run this command in order to send an email to your friend.

mail -v -s "Test from Khosro" root@mymachine.khosro.org < message_file

Change mymachine.khosro.org to your machine name and domain name. Use mail command to check the inbox and verify your email that you already sent it.  
Please leave your comments or questions. I will try to answer as soon as possible.
Thanks,
Khosro Taraghi

Exporting all Email Accounts from Zimbra Server for Microsoft Transporter Suite

Hello Everyone,

In order to move all email accounts and data from IMAP or POP3 Zimbra Server in Linux box machine to Exchange Server 2007, we need to create a .CSV file with the following columns:
  • SourceIdentity: The e-mail account that the user has in the IMAP/POP3 Server
  • SourceServer: The name or IP of the IMAP/POP3 Server
  • SourceLoginID: the account user name used to connect on the IMAP/POP3 server
  • SourcePassword: the user’s password
  • TargetIdentity: the Exchange Server 2007 identity will receive the data from the previous IMAP/POP3 Server settings  
To make life easier, I made a script that export all users from Zimbra to a CSV file. 
Here is the script:

#!/bin/bash
clear
echo "Processing account, please wait.............................."
USERS=`su - zimbra -c 'zmprov -l gaa'`
#Assume that domain name is test.com
exchange="@test.com"
echo "SourceIdentity,SourceServer,SourceLoginID,SourcePassword,TargetIdentity" > export_users.csv
for ACCOUNT in $USERS
 do
  SourceIdentity=`echo $ACCOUNT`
  #Assume that domain name is xyz.com for Linux box and Zimbra
  SourceServer=`echo "xyz.com"`
  SourceLoginID=`echo $ACCOUNT | awk -F@ '{print $1}'`
  SourcePassword=`echo "P@ssw0rd"`
  TargetIdentity=`echo -n $ACCOUNT | awk -F@ '{print $1}'`
  TargetIdentity=${TargetIdentity}${exchange}
  if [ $SourceLoginID == "admin" ] || [ $SourceLoginID == "spam" ] || [ $SourceLoginID == "ham" ] || [ $SourceLoginID == "virus-quarantine" ]
  then
   echo "Skipping system account, $ACCOUNT..."
  else
   echo "$SourceIdentity,$SourceServer,$SourceLoginID,$SourcePassword,$TargetIdentity" >> export_users.csv
  fi
 done



Now, we can use this CSV file in Microsoft Transporter Suite to import users to Exchange 2007.
Hope enjoy using this script. Please leave your comments or questions. I will try to answer as soon as possible.
Thanks,
Khosro Taraghi

Wednesday, November 23, 2011

Apache Module mod_vhost_alias


Hello everybody,
mod_vhost_alias provides for dynamically configured mass virtual hosting. According to Apache website, http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html, this module creates dynamically configured virtual hosts, by allowing the IP address and/or the Host: header of the HTTP request to be used as part of the pathname to determine what files to serve. This allows for easy use of a huge number of virtual hosts with similar configurations.

The following explanation shows how to configure apache with this module. Then, I wrote a script to automate creation of mass virtual hosting.

  • Untar the installation file of apache and change your directory to apache directory
  • Run this command: ./configure –prefix=$HOME/apache –enable-modules=mod_vhost_alias
  • make
  • make install

Here is the script:

#!/bin/bash
clear
echo "******************************************************"
echo "This is a script for making multiple virtual hosts."
echo "Scripted by: Khosro Taraghi"
echo "Modified date: Nov-23-2011"
echo "******************************************************"
echo ""
echo ""
reset_server=0
end_of_script=""
while ([ "$end_of_script" != "n" ] && [ "$end_of_script" != "y" ])
do
echo -n "Press y to continue or press n to exit (y/n): "
read end_of_script
if ([ "$end_of_script" != "n" ] && [ "$end_of_script" != "y" ])
then
echo "The input is incorrect!!!"
fi
done
if [ "$end_of_script" == "y" ]
then
echo -n "Please enter the path to your Server Root (Absolute path): "
read sroot
sroot=$(echo $sroot | sed 's/\/$//')
while ([ ! -d "$sroot" ])
do
echo -n "Directory $sroot does not exist!! Please try again: "
read sroot
sroot=$(echo $sroot | sed 's/\/$//')
done
echo -n "Please enter the path to your Document Root (Absolute path): "
read droot
droot=$(echo $droot | sed 's/\/$//')
while ([ ! -d "$droot" ])
do
echo -n "Directory $droot does not exist!! Please try again: "
read droot
droot=$(echo $droot | sed 's/\/$//')
done
sed -i 's/^#.*NameVirtualHost/NameVirtualHost/' $sroot/conf/httpd.conf
fi
while [ "$end_of_script" != "n" ]
do
echo -n "Please enter the name of your Server Name (for example, www.example.com): "
read sname
echo "<VirtualHost *:80>" >> $sroot/conf/httpd.conf
echo "ServerAdmin khosro@example.com" >> $sroot/conf/httpd.conf
mkdir -p $droot/$sname
echo "VirtualDocumentRoot \"$droot/%0\"" >> $sroot/conf/httpd.conf
echo "DirectoryIndex index.html" >> $sroot/conf/httpd.conf
echo "ServerName $sname" >> $sroot/conf/httpd.conf
echo "ErrorLog logs/$sname-error_log" >> $sroot/conf/httpd.conf
echo "CustomLog logs/$sname-access_log common" >> $sroot/conf/httpd.conf
alias_vhost=""
while ([ "$alias_vhost" != "n" ] && [ "$alias_vhost" != "y" ])
do
echo -n "Do you want to add an alias to another virtual host (y/n): "
read alias_vhost
if ([ "$end_of_script" != "n" ] && [ "$end_of_script" != "y" ])
then
echo "The input is incorrect!!! Enter y for yes or n for no!"
fi
done
if [ "$alias_vhost" == "y" ]
then
echo -n "Please enter the name of Server Name that you want to make an alias to $sname, (for example, www.example2.com) : "
read alias_name
echo "AliasMatch ^/(.*)$ $droot/$alias_name/index.html" >> $sroot/conf/httpd.conf
fi
redirect=""
while ([ "$redirect" != "n" ] && [ "$redirect" != "y" ])
do
echo -n "Do you want to make a redirect to another virtual host (y/n): "
read redirect
if ([ "$redirect" != "n" ] && [ "$redirect" != "y" ])
then
echo "The input is incorrect!!! Enter y for yes or n for no!"
fi
done
if [ "$redirect" == "y" ]
then
echo -n "Please enter the name of Server Name that you want to make a Redirect to $sname, (for example, www.example2.com) : "
read redirect_name
echo "RedirectMatch permanent ^/$ http://$redirect_name" >> $sroot/conf/httpd.conf
fi
echo "</VirtualHost>" >> $sroot/conf/httpd.conf
echo "<html><title>$sname</title>This is a webpage that belongs to $sname.</html>" >> $droot/$sname/index.html
echo ""
echo "The Virtual Host <$sname> was added successfully."
echo "Press any key to continue..."
read
echo "127.0.0.1 $sname" >> /etc/hosts
service NetworkManager restart
clear
reset_server=1
end_of_script=""
while ([ "$end_of_script" != "n" ] && [ "$end_of_script" != "y" ])
do
echo -n "Press y to continue or press n to exit (y/n): "
read end_of_script
if ([ "$end_of_script" != "n" ] && [ "$end_of_script" != "y" ])
then
echo "The input is incorrect!!!"
fi
done
done
if [ $reset_server -eq 1 ]
then
sed -i '/combined/s/^LogFormat "/LogFormat "%V /' $sroot/conf/httpd.conf
sed -i '/common/s/^LogFormat "/LogFormat "%V /' $sroot/conf/httpd.conf
$sroot/bin/apachectl stop 1>/dev/null
$sroot/bin/apachectl start 1>/dev/null
fi


Regards,
Khosro Taraghi

Thursday, September 29, 2011

How To Install And Run Webalizer From Source Code And How To Configure Apache For Webalizer

Hello Everybody,
Today, I will explain, briefly, how to install and run Webalizer and how to configure apache for webalizer at the same machine box. First download the source code from following address: http://www.webalizer.org/download.html (Download .tgz file). Then go to the location of this file (.tgz)and run following commands:

1. yum install gcc libpng libpng-devel gd gd-devel zlib zlib-devel
2. tar xvzf webalizer-2.23-05-src.tgz
3. cd webalizer-2.23-05
4. ./configure --prefix=/webalizer ------> Here you can specify the destination of installation. You change to somewhere else.
5. make
6. make install
7. cp /webalizer/etc/webalizer.conf.sample /webalizer/etc/webalizer.conf ----> Change to your path if you already changed it.
8. vi /webalizer/etc/webalizer.conf ------>  Uncomment and change the following lines(don't forget to change the path to your path):
    LogFile        /apa2/logs/access_log
    OutputDir      /apa2/usage
    HistoryName     /webalizer/webalizer.hist
    Incremental     yes
    IncrementalName /webalizer/webalizer.current
    Quiet           yes
    FoldSeqErr      yes
    HideURL         *.gif
    HideURL         *.GIF
    HideURL         *.jpg
    HideURL         *.JPG
    HideURL         *.png

    HideURL         *.PNG
    HideURL         *.ra


9. mkdir /apa2/usage   ------> change the /apa2 to the location of your Server root.
10. vi /apa2/conf/httpd.conf ------> change the path to the location of your httpd.conf
11. Add the following lines to your httpd.conf ------> change the /apa2 to the location of your Server root.

    <IfModule mod_alias.c>

      Alias /usage/ "/apa2/usage/"
          <Directory "/apa2/usage">
          Options None
          AllowOverride None
          Order deny,allow
          Deny from all
          Allow from 127.0.0.1
          </Directory>

    </IfModule>


12. Restart apache:  ------> change the /apa2 to the location of your Server root.
    
    /apa2/bin/apachectl restart

13. To run Webalizer manually, to generate reports, use the following command:

    /webalizer/bin/webalizer   ------> Change /webalizer/ to the location of your Webalizer. For example, if you installed Webalizer in /abc, just change it to /abc/bin/webalizer

Now, whenever you want to get the new report, you should do the step 13 manually. To run this command automatically, use cron job.

14. To see the result, open the browser and enter the following url:

     http://127.0.0.1/usage/

Now, you should see the result on the browser. For any question, please leave a comment. I will try to answer as soon as possible.

Regards,
Khosro Taraghi

Saturday, September 24, 2011

How To Start sshd Service in CYGWIN

Hello All,

Today, I want to explain that how you can start the sshd service in cygwin. First, You should download the installation file from www.cygwin.com for windows. During the installation, you must expand the Admin folder and select cygrunsrv. Also, you must expand Net and select openssh. After installation, open cygwin shell, and run the following commands:
  1. ssh-host-config -y     --------> This command will create necessary configuration files.
  2. cygrunsrv -S sshd     --------> This command will run the sshd service. This is equal to "service sshd start" command.
Now your sshd service is ready. Try by doing ssh to somewhere or someone ssh to you.
Don't forget to configure your firewall in Windows.

Regards,
Khosro Taraghi

Monday, August 29, 2011

How To Install Broadcom BCM4311, BCM4312, BCM4313, BCM4321, BCM4322, BCM43224, BCM43225, BCM43227 and BCM43228 Wireless NICs On CentOS 6

Hello Everybody,

Today, I am going to explain how to install Broadcom wireless NIC cards on CentOS 6.0. First, you should determine which Wlan chip or Wlan controller do you have. Login as root and run the following command:

[root@Centos6 ~]# lspci | grep Broadcom
02:00.0 Network controller: Broadcom Corporation BCM43224 802.11a/b/g/n (rev 01) 

As you see, my computer has BCM43224 Wlan chip. So, if your computer has one of the following Wlan chips or Wlan Network Controllers (BCM4311, BCM4312, BCM4313, BCM4321, BCM4322, BCM43224, BCM43225, BCM43227 and BCM43228), your computer will install the wireless after running the instructions below:

  1. yum install kernel-headers kernel-devel gcc 
  2. Go to this link **Click Here** and download the Broadcom Linux Driver (64 or 32 bits)
  3. mkdir -p /usr/local/khosro/taraghi-wl 
  4. cd /usr/local/khosro/taraghi-wl 
  5. tar xvfz /home/khosro/Download/hybrid-portsrc_x86_64-v5_100_82_38.tar.gz (You should change the path to the actual path of your tarball that you downloaded)
  6. make -C /lib/modules/`uname -r`/build/ M=`pwd`           ====>Your output should look something like this:
    make: Entering directory `/usr/src/kernels/2.6.32-71.29.1.el6.x86_64'
     LD      /usr/local/khosro/taraghi-wl/built-in.o
     CC [M]  /usr/local/
    khosro/taraghi-wl/src/shared/linux_osl.o
     CC [M]  /usr/local/
    khosro/taraghi-wl/src/wl/sys/wl_linux.o
     CC [M]  /usr/local/
    khosro/taraghi-wl/src/wl/sys/wl_iw.o
     LD [M]  /usr/local/
    khosro/taraghi-wl/wl.o
     Building modules, stage 2.
     MODPOST 1 modules
     CC      /usr/local/
    khosro/taraghi-wl/wl.mod.o
     LD [M]  /usr/local/
    khosro/taraghi-wl/wl.ko.unsigned
     NO SIGN [M] /usr/local/
    khosro/taraghi-wl/wl.ko
    make: Leaving directory `/usr/src/kernels/2.6.32-71.29.1.el6.x86_64'
  7. rmmod bcm43xx 
  8. rmmod b43 
  9. insmod wl.ko  ====> Load the driver module 
  10. cp -vi /usr/local/khosro/taraghi-wl/wl.ko /lib/modules/`uname -r`/extra/  
  11. depmod $(uname -r) ===> To create module dependencies
  12. vim /etc/modprobe.d/blacklist.conf     ===>And add the following lines under "# framebuffer drivers" to prevent these modules from being loaded into kernel at boot time:
blacklist bcm43xx
blacklist b43

Save the file. Now, you should see the available wirelesses under Wireless Network if you click on Wired Network icon ,usually, on top right.

Regards,
Khosro Taraghi

Friday, August 19, 2011

Monitoring Network Printers

This is a quick instructions about how to monitor the network printers in Nagios monitoring system. First important things that you should know is SNMP. Your printer should support the SNMP and also enabled on printer. HP printers that support internal/external JetDirect or other printers that support JetDirect protocol are good for this purpose.
Fisrt, we should install check_hpjd plugin.  To install this plugin, we should install net-snmp and net-snmp-utils packages.
yum install net-snmp
yum install net-snmp-utils
Next step, edit the main Nagios Configuration file:
vi /usr/local/nagios/etc/nagios.cfg
and uncomment this line:
#cfg_file=/usr/local/nagios/etc/objects/printer.cfg
and then save it. Now edit the printer configuration file and add new host definition for the networked printer that you want to monitor.
vi /usr/local/nagios/etc/objects/printer.cfg
This is the output of this file which is a sample and modify it according to your needs
# HOST DEFINITIONS
# Define a host for the printer we'll be monitoring
# Change the host_name, alias, and address to fit your situation

define host{
        use             generic-printer         ; Inherit default values from a template
        host_name       hplj2605dn              ; The name we're giving to this printer
        alias           HP LaserJet 2605dn      ; A longer name associated with the printer
        address         192.168.1.30            ; IP address of the printer
        hostgroups      network-printers        ; Host groups this printer is associated with
        }

# HOST GROUP DEFINITIONS
# A hostgroup for network printers

define hostgroup{
        hostgroup_name  network-printers        ; The name of the hostgroup
        alias           Network Printers        ; Long name of the group
        }
# SERVICE DEFINITIONS
# Create a service for monitoring the status of the printer
# Change the host_name to match the name of the host you defined above
# If the printer has an SNMP community string other than "public", change the check_command #directive to reflect that

define service{
        use                     generic-service         ; Inherit values from a template
        host_name               hplj2605dn              ; The name of the host the service is associated with
        service_description     Printer Status          ; The service description
        check_command           check_hpjd!-C public    ; The command used to monitor the service
        normal_check_interval   10      ; Check the service every 10 minutes under normal conditions
        retry_check_interval    1       ; Re-check the service every minute until its final/hard state is determined
        }

# Create a service for "pinging" the printer occassionally.  Useful for monitoring RTA, packet loss, etc.

define service{
        use                     generic-service
        host_name               hplj2605dn
        service_description     PING
        check_command           check_ping!3000.0,80%!5000.0,100%
        normal_check_interval   10
        retry_check_interval    1
        }

After editing this file, run the following command to make sure everything is fine, especially for spelling errors:
/usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg
It supposes to show 0 and 0 errors if these is no error.
And finally restart the service:
service nagios restart

All the best,
Khosro Taraghi

Thursday, June 9, 2011

Adding Windows machines to Nagios

Adding Windows machines to Nagios
Nagios is an open source powerful monitoring system that enables you to monitor your servers, services, application and so on. It has also ability to monitor Windows based servers, but in order to communicate with Windows servers, you should install Nagios agent on each machine. I am going to explain that how to configure the Nagios for Windows machine and also how to install Nagios Client agent on the Windows machine.
Here is the general idea:
Nagios(Monitoring Server(Linux)) -----àcheck_nt ---------------àNSClient++ ----àCPU
Nagios(Monitoring Server(Linux))  -----àcheck_nt --------------àNSClient++ ----àMemory
Nagios (Monitoring Server(Linux)) ----àcheck_nt ---------------àNSClient++ ----àDisk Space
Nagios(Monitoring Server(Linux))  -----àcheck_nt --------------àNSClient++ ----àProcesses
Nagios(Monitoring Server(Linux))  -----àcheck_nt --------------àNSClient++ ----àServices

Configure Nagios:
1.       Login as su (Super User)
2.       vi /usr/local/nagios/etc/nagios.cfg
3.       remove (#) sign from the following line:
#cfg_file=/usr/local/nagios/etc/objects/windows.cfg
Save the file and exit.
4.       Go to /usr/local/nagios/etc/objects/ directory.(cd /usr/local/nagios/etc/objects)
5.       Edit windows.cfg (vi windows.cfg)
6.       Under Host Group Definitions, define a hostgroup for windows machines. An example can be like this:
define hostgroup{
                hostgroup_name             myWindows
                alias                                       Windows Machines
                }
7.       Under Service Definitions, create services for Uptime of the server, CPU load, Memory Usage, and C:\ disk usage like this:
define service{
                use                                        generic-service
                hostgroup_name             myWindows
                service_description        Uptime
                check_command             check_nt!UPTIME
                }
define service{
                use                                        generic-service
                hostgroup_name             myWindows
                service_description        CPU Load
                check_command             check_nt!CPULOAD!-l 5,85,95
                }
define service{
                use                                        generic-service
                hostgroup_name             myWindows
                service_description        Memory Usage
                check_command             check_nt!MEMUSE!-w 90 –c 95
                }
define service{
                use                                        generic-service
                hostgroup_name             myWindows
                service_description        C:\ Drive Space
                check_command             check_nt!USEDDISKSPACE!-l c -w 85 –c 95
                }

which –w means Warning and –c means Critical.
8.       Now, you should define your hosts for windows machines that we are going to monitor, something like this for each host:

Define host{
                use                         myWindows
                host_name         xxxxxxxx
                alias                       yyyyyyy
                address                                xxxxxxxx.xxx.xxx
                }
Replace  xxxxxxxx with actual hostname and yyyyyyy with a longer name associated with the host and xxxxxxx.xxx.xxx with fully qualified name of host.

9.       Test nagios configuration   with this command:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
You should see these lines from the output:
Total Warnings: 0
Total Errors:   0
If you see any error, check your configuration file.
10.   Restart Nagios:  restart nagios service

Nagios agent for Windows OS(NSCLIENT++):
Nsclient++ is a secure monitoring daemon for Windows OS. Nsclient++ has to install in Windows machine in order to talk with Linux machine and nagios. You can download the latest version(msi) of nsclinet++ from this link:  http://nsclient.org/nscp/downloads
Run installation and put the fully qualified name of the Windows machine into the Allowed Hosts and then check all options and don’t check the NSCA if you are not sure. At the end, check Start Services.
Regards,
Khosro Taraghi