Monday, December 23, 2013

my first blog post via api!

Mr. Darcy has proposed marriage to me!
He is the last man on earth I would ever desire to marry.
Whatever shall I do?

Wednesday, March 28, 2012

CarDekho.com turns 4, comes out with a facelift

CarDekho.com, the No. 1 auto portal in India has completed four successful years since its inception in 2008. On the occasion, the company has launched a new and refreshing User Interface. As CarDekho.com enters its fifth year, the website has forayed into various other gamut of service for car buyers and dealers like new car buying, car finance, car insurance, used cars, exchange, etc.






Refreshing Look and highly usable functionality


The stylish new homepage with its increased usability and new features gives an in-depth knowledge about all new/used cars and their details. Currently, a user on an average spends over 8 minutes on CarDekho. The desired information required to finalize a car is just a click away using the intuitive features of the site.



CarDekho fact-sheet:

  • Over 3.5 million users reach out to
  • Fastest auto portal to achieve 3 crore unique visitor mark earlier this Jan
  • India’s largest stock of used cars with nearly 30,000 listings of active sellers
  • Hundreds of used and new car dealers across the country use CarDekho services
  • Used car dealers enrolled at CarDekho have increased their sales by 20%
  • 5000-6000 used cars listed in CarDekho’s section are sold  every month
  • Over 15,000 new car on-road price quotes are requested everyday
  • CarDekho facilitates car loans in over 25 cities
  • Offers loan disbursal with a turnaround time of less than two days


CarDekho solution for Car Buyers

CarDekho.com is the first step in the ladder for every user while buying a car. According to Amit Jain, the CEO, “It has been a tremendous run in the last 4 years. We stand committed to make car buying even simpler and friendly with best deals available in the market. I am very excited to see the growth in the price quotes generated for new cars as well as the huge increase in both sellers and buyers in used car section at CarDekho. This clearly indicates how the trends are clearly shifting to online research for buying both used and new cars. Our new UI bundled with array of services for car buying will ensure end to end solutions for car buyers. We want to touch each and every car buyer in India and help them choose the most suitable car. “

CarDekho future growth strategy

The website has seen enormous growth over last 4 years and looks forward to continue the winning streak. Speaking on the future endeavors Rohit Dangayach, Director Sales said, “We are spreading our services of new and used car buying, car finance and insurance, pan-India. We are aggressively reaching out to all channels in the car sales industry and offering them what they need to scale up their businesses multi-fold. Our success lies in success of all our partners and we will become the most important source of leads for everyone in the industry.”


Reducing the gap between Car Buyers and Car Makers

Not just the dealers but Car Makers have also benefited in selling cars through our site. For some Auto Manufacturers, CarDekho team is helping them sell their cars pan-India. Anurag Jain, the COO said, “Car manufacturers and dealers will focus on online channels like CarDekho to increase their sales. Online portals will play a crucial role in their marketing strategies. The number of people researching cars on portals and the effect on their car buying decision has increased significantly. With the increase in internet penetration in India, this will only grow bigger. CarDekho hand holds the customers right from their research stage till the delivery of their desired car at their doorsteps, thus helping car manufacturers sell more cars pan-India”.
 
About CarDekho.com

CarDekho is India’s most popular car portal and helps its users with car research, finance, insurance and any other aspect of car buying with the best possible deals through its exclusive tie-ups with car manufacturers, finance and insurance companies. CarDekho is owned by GirnarSoft Automobiles Pvt. Ltd., a subsidiary of Girnar Software Pvt. Ltd. Girnar Software is Rajasthan’s leading IT company and operates other popular portals like PriceDekho.com, BikeDekho.com and more. CarDekho was awarded the most popular website of 2011, and best automotive website of 2009 by online research agency MetrixLab. 



Source : CarDekho.com turns 4, comes out with a facelift

Monday, April 13, 2009

fcheck file system security

Download fcheck (see resources) and unpack it. fcheck is a cross-platform Perl script which runs on
UNIX and Windows systems (as long as they have Perl installed).
$mkdir /usr/local/fcheck
$cp fcheck /usr/local/fcheck
$cp fcheck.cfg /usr/local/fcheck
Edit /usr/local/fcheck/fcheck.cfg with your favorite editor and change the following values:
Directory, FileTyper, Database, Logger, TimeZone, and Signature.
# Directories that will be monitored
# if there is a trailing / it will be recursive
Directory = /etc/
Directory = /bin/
Directory = /sbin/
Directory = /lib/
Directory = /usr/bin/
Directory = /usr/sbin/
Directory = /usr/lib/
TimeZone = PST8PDT # For Pacific Standard
# Database of file signatures
DataBase = /usr/local/fcheck/sol.dbf
Logger = /usr/bin/logger -t fcheck
# Utility to determin file type
FileTyper = /bin/file
# What to use to create signatures Database of
# file signatures
$Signature = /usr/bin/md5sum#
DataBase = /usr/local/fcheck/sol.dbf
Logger = /usr/bin/logger -tfcheck
# Utility to determin file type
FileTyper = /bin/file
Also edit the fcheck script and change the path of the configuration file to
/usr/local/fcheck/fcheck.cfg
Then run fcheck for the first time to create the baseline database.
# Options explained:
# c create the database
# a is for all
# d is to monitor directory creation
# s is to create signatures for all files
# x is for extended permissions monitoring

$ ./fcheck -cadsx
To test that everything has been setup correctly run the following commands and fcheck should alert you to
the difference.
$ touch /etc/FOO
$ ./fcheck -adsx
fcheck should display some information about /etc/FOO. $rm /etc/FOO will prevent future messages.
Next, create a short shell script that will be run periodically by cron and check for changes. Open your
favorite editor and create /usr/local/bin/fcheck_script.
When using the `cron` utility lookout for _symlink attacks_
#!/bin/bash
# Use mktemp instead of $$ to prevent sym-link attacks
FCHECK_LOG=`mktemp`
# Grep for any changes
/usr/local/fcheck/fcheck -adsx \
| grep -Ev ^PROGRESS: |^STATUS:^$ > $FCHECK_LOG
# If there were any changes email the sys-admin
if [-s $FCHECK_LOG ] then
/usr/bin/mail -s fcheck \
`hostname` youremail@yourprovider.com < \
$FCHECK_LOG
/bin/rm $FCHECK_LOG
fi
The cron utility will be used to run periodic checks of the file-system and will compare it to the baseline
database. The following command will edit root’s crontab:
$ crontab -e
# Add this line to run the script every 15 minutes
# using nice lower priority when the system load
# is high.
*/15 * * * * nice /usr/local/bin/fcheck_script > \
/dev/null
Symlink Attacks
Side Note: Symlink Attacks running an IDS package usually involve running a script at a pre-configured time
using the cron utility. This opens up systems to symlink attacks. Symlink Attacks rely on the attacker knowing
that a certain file is going to be created at a certain time with a certain name. A common shell scripting
technique that generates some randomness is the use of $$, which is the PID of the running script. However,
this is vulnerable to Symlink Attacks because most PIDs are below 35K and most file systems can have 35K
files. The correct technique is the use of mktemp, which is a truly random file name.

Tuesday, February 24, 2009

Quartz Scheduling

Quartz scheduling

Quartz is a full-featured, open source job scheduling system that can beintegrated with, or used along side virtually any J2EE or J2SE application- from the smallest stand-alone application to the largest e-commercesystem. Quartz can be used to create simple or complex schedules forexecuting tens, hundreds, or even tens-of-thousands of jobs

Quartz is freely usable, licensed under the Apache 2.0 license.
Main elements-

1.Job 2.Trigger 3.Scheduler

Scheduler

Main part of the Quartz• Responsible for managing the runtime environment for all Quartz applications
• Based on a multithreaded architecture
– on startup a set of worker threads are initialized – a worker thread is used by the scheduler to schedule Jobs
• Many Jobs can be run concurrently

Scheduler keeps track of all Jobs and the times they are executed
Job execution needs to be very exact ant prompt


Job

A Job is a Java class that performs a task
example
– Use JavaMail to send emails
– Query and update persistent data
– Use FTP to move file

Only requirements:

– implement org.quartz.Job interface
– throw a JobExecutionExcpetion in the case of error

example code is here

public class HelloJob implements Job
{
public void execute(JobExecutionContext arg0) throws JobExecutionException{
System.out.println("Hello World Quartz Scheduler: " + new Date());
}
}


Jobs And Trigger

Quartz separates the Job from the schedule
Trigger are used to tell the Scheduler when a Job should be fired
Several triggers types are available, but the most important are:
– SimpleTrigger
– CronTrigger


Trigger

Simple Trigger
simple firing schedule: at given time, repeat nr of times, waiting between firings

CronTrigger
– calendar-like schedule: 0 15 10 ? MON-FRI

How to schedule a job

Create an Scheduler instance from the Factory
– Create a Job, JobDetail
– Create and setup the trigger
– Schedule Job and Trigger with the Scheduler
– Start the Scheduler


Crontrigger

cron is a UNIX tool that has been around for a long time, so its scheduling capabilities are powerful and proven. The CronTrigger class is based on the scheduling capabilities of cron.


CronTrigger uses "cron expressions", which are able to create firing schedules such as: "At 8:00am every Monday through Friday" or "At 1:30am every last Friday of the month".


A cron expression is a string comprised of 6 or 7 fields separated by white space. Fields can contain any of the allowed values, along with various combinations of the allowed special characters for that field. The fields are as follows:

fieldname(range)(allowed values)
1.seconds(0-59)(, - * / )‏
2.Minutes(0-59)(, - * / )‏
3.hours(0-23)(, - * / )‏
4.Day Of month( 1-31 )(, - * ? / L W)‏
5.month(1-12 or JAN-DEC )(, - * / )‏
6.day of week(1-7 or SUN-SAT )(, - * ? / L # )‏
7.year(empty, 1970-2099)(, - * / )‏

allowed value description

* ("all values") - used to select all values within a field. For example, "*" in the minute field means "every minute".

? ("no specific value") -useful when you need to specify something in one of the two fields in which the character is allowed, but not the other. For example, if I want my trigger to fire on a particular day of the month (say, the 10th), but don't care what day of the week that happens to be, I would put "10" in the day-of-month field, and "?" in the day-of-week field.

- used to specify ranges. For example, "10-12" in the hour field means "the hours 10, 11 and 12"., used to specify additional values. For example, "MON,WED,FRI" in the day-of-week field means "the days Monday, Wednesday, and Friday"./ - used to specify increments. For example, "0/15" in the seconds field means "the seconds 0, 15, 30, and 45".

L ("last") - has different meaning in each of the two fields in which it is allowed. the value "L" in the day-of-month field means "the last day of the month" if used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" means "the last friday of the month".

W ("weekday")‏

The 'L' and 'W' characters can also be combined in the day-of-month field to yield 'LW', which translates to "last weekday of the month".


# - used to specify "the nth" XXX day of the month
For example, the value of "6#3" in the day-of-week field means "the third Friday of the month" (day 6 = Friday and "#3" = the 3rd one in the month)‏

Cron expression example

1. Fire at 12pm (noon) every day
0 0 12 * * ?
2. Fire at 10:15am every day
0 15 10 ? * *
3. Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day
0 0/5 14,18 * * ?

4. Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day
0 10,44 14 ? 3 WED
5.Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday
0 15 10 ? * MON-FRI
FOR IMPEMENTING QUARTZ HAVE TO LOAD TO JAR FILES. name as follow.

1. quartz-1.6.4.jar()
2 .commons-collections-3.2.jar
u can load these jar using (http://www.opensymphony.com/quartz/|)

Sample Program is given below.


public class DailyReportGenerator {


public void run() throws Exception {

SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();

// jobs can be scheduled before sched.start() has been called

// job 1 will run every 20 seconds
JobDetail job = new JobDetail("job1", "group1", MailSender.class);
// All three Triggers will be scheduled to fire 5 minutes from now.
// Calendar cal = Calendar.getInstance();
// cal.add(Calendar.MINUTE, 5);

// Trigger trigger = new SimpleTrigger("T1", "MyGroup", cal.getTime());
// Trigger trig2 = new SimpleTrigger("T2", "MyGroup", cal.getTime());
// Trigger trig3 = new SimpleTrigger("T3", "MyGroup", cal.getTime());
//
// trig2.setJobName(jobDetail.getName());
// trig2.setPriority(10);
// sched.scheduleJob(trig2);
//
// // Trigger2 has its priority set to 1
// trig3.setJobName(jobDetail.getName());
// trig2.setPriority(1);
// sched.scheduleJob(trig3);
CronTrigger trigger = new CronTrigger("trigger1", "group1", "job1", "group1", "0 15 17 * * ?");
sched.addJob(job, true);
Date ft = sched.scheduleJob(trigger);

sched.start();

}
}

there are some lines are commented u can uncommented it and rum simple trigger .this one use cron trigger.which is really awesome .reduce overhead of threading.
MailSender is job implemented class.


public class MailSender implements Job{


public void execute(JobExecutionContext context)
throws JobExecutionException {
// send mail();
System.out.println("manu");

}

}


How To Load Property Files smartly

How To Load Property Files Smartly

What is the best strategy for loading property and configuration files in Java?

1.Absolute path for property files.
2.loading resources through classloaders.
3.Load file using Resourse bundle.


1>Absolute path for Property file


//property.properties
register.mail.file : usermail.html
invite.game.friend.mail.file : invitegamefriend.html
scrap.game.friend.mail.file : scrap.html

Public void loadpropertyfile{
Properties propertirs = new Properties();
propertirs.load(”/home/manu/property.properties”);
propertirs.list(System.out);
System.out.println("\nThe foo property: " + propertirs.getProperty("food"));
}

U can Load xml property file also
//sample.properties file (xml file)



Hi
struts
manu


Public void loadpropertyfileForXml{
Properties propertirs = new Properties();
propertirs.loadFromXml(”/home/manu/sample,properties”);
propertirs.list(System.out);
System.out.println("\nThe foo property:xml " + propertirs.getProperty("food"));
}


Loading Through class LoaderThis is one of the best methord to load property file
To load property file using class laoder the file must be put under the
class path(where the classes are resides).

1.ClassLoader.getResourceAsStream ("some/pkg/resource.properties");
2.Class.getResourceAsStream ("/some/pkg/resource.properties");
3.getClass().getClassLoader().getSystemResourceAsStream(”
/some/pkg/resource.properties”);




public class LoadSampleXml
{

public void initialize() throws InvalidPropertiesFormatException, IOException

{

//Properties propertirs=null;
Properties propertirs = new Properties();


// propertirs.loadFromXML(this.getClass().getResourceAsStream("samplexml.properties"));
// propertirs.loadFromXML(getClass().getClassLoader().getResourceAsStream("samplexml.properties"));
// propertirs.loadFromXML(getClass().getClassLoader().getSystemResourceAsStream("samplexml.properties"));
// propertirs.load(getClass().getClassLoader().getResourceAsStream("emailProperties.properties"));
propertirs.loadFromXML(getClass().getClassLoader().getResourceAsStream("res/samplexml.properties"));

propertirs.list(System.out);
System.out.println("\nThe java property:xml " + propertirs.getProperty("java"));

}



}


2>Using resource bundle

It must use when u requires locale specific property file. resource bundle is class u can see it anywhere in sun java
site.i m attaching a souce code to use resource bundle as to load property file.here also property file must be there in classpath.

getBundle is methord of ResourceBundle Class.

When the getBundle method locates the correct properties file, it returns a PropertyResourceBundle object containing the key-value pairs from the properties file.


code is here

public class PropertyTest {

public void initialize()
{
System.out.println(getClass().getClassLoader()+"dfsasdfasfasdfdasfasfas");
Properties config=loadProperties("emailProperties", getClass().getClassLoader());
System.out.println(config);

}

public Properties loadProperties(String name, ClassLoader loader)
{

System.out.println(ClassLoader.getSystemClassLoader().getResourceAsStream("samplexml.properties")+"system class loader");
if (name == null)
throw new IllegalArgumentException("Property file name : null");

Properties result = null;
try
{
if (loader == null)
loader = ClassLoader.getSystemClassLoader();

// Throws MissingResourceException on lookup failures:
final ResourceBundle rb = ResourceBundle.getBundle(name, Locale.ENGLISH,loader);
result = new Properties();
for(Enumeration keys = rb.getKeys(); keys.hasMoreElements();)
{
final String key = (String) keys.nextElement();
final String value = rb.getString(key);

result.put(key, value);
}


}
catch (Exception e)
{
result = null;
}

if (result == null)
{
throw new IllegalArgumentException("Could not load [" + name + "]" + " as a resource bundle");
}
return result;
}


}

Post Options

Friday, February 20, 2009

progn - A Special Form in Lisp

progn is a special form in lisp that causes each of its arguments to be evaluated in sequence and then returns the value of the last one.The preceding expressions are evaluated only for the side effects they perform .The values produced by them are discarded.

Syntax of PROGN:

progn form* => result*

Arguments and Values:

forms --> an implicit progn
results --> the values of the forms.

Description:

Progn evaluates forms in lisp, in the order in which they are given. The values of each form but the last are discarded. If progn appears as a top level form within that progn are considered by the compiler to be top level forms

Examples:

(progn) ==> NIL
(progn 1 2 3) ==> 3
(progn (values 2 3 4)) ==> 2, 3, 4
(setq b 1 ) ==> 1
(if b
(progn (setq b nil) 'here)
(progn (setq b t) 'there))==> HERE
a ==> NIL

Wednesday, February 18, 2009

SMTP Server Configuration

How To Install Postfix+Postfixadmin, MySQL, Cyrus-SASL, Courier-Authlib, Courier-Imap, Smtp-Auth, Squirellmail, MailScanner, ClamAV on CentOS 5.2

I will install this on CentOS 5.2 , please prepare Anything. Download All Software and packages and store it in /usr/local/src
Postfix : http://mirrors.rootservices.net/postfix/official/postfix-2.5.5.tar.gz
Postfix Admin : http://waix.dl.sourceforge.net/sourceforge/postfixadmin/postfixadmin-2.2.1.1.tar.gz
Cyrus-SASL : ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.22.tar.gz
Courier Authlib : http://prdownloads.sourceforge.net/courier/courier-authlib-0.61.0.tar.bz2
Courier-Imap : http://prdownloads.sourceforge.net/courier/courier-imap-4.4.1.tar.bz2
Squirellmail : http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fprdownloads.sourceforge.net%2Fsquirrelmail%2Fsquirrelmail-1.4.16.tar.gz
Downloading all packages :
#cd /usr/local/src
#wget http://mirrors.rootservices.net/postfix/official/postfix-2.5.5.tar.gz
#wget http://waix.dl.sourceforge.net/sourceforge/postfixadmin/postfixadmin-2.2.1.1.tar.gz
#wget ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.22.tar.gz
#wget http://prdownloads.sourceforge.net/courier/courier-authlib-0.61.0.tar.bz2
#wget http://prdownloads.sourceforge.net/courier/courier-imap-4.4.1.tar.bz2
#wget http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fprdownloads.sourceforge.net%2Fsquirrelmail%2Fsquirrelmail-1.4.16.tar.gz
Preparing All Server Dependency Packages
#yum install openldap-devel openldap-servers postgres-devel expect-devel postfix gamin-devel
Installing Apache,PHP,Mysql and rpm-build
#yum install httpd* php* mysql* rpm-build*
Remove All Cyrus-SASL & postfix/sendmail packages
We need to remove sendmail or previous postfix installation, and since we will compile the Cyrus-SASL manually from the sourcecode we need to remove the default Cyrus-SASL component first,
You can checked those package using rpm -qa|grep command
#rpm -qa|grep sendmail #rpm -qa|grep postfix #rpm -qa|grep cyrus
If you see any sendmail , postfix cyrus packages we can safely remove it, you can use rpm -e command
#rpm -e cyrus-sasl.1.x.x.x --nodeps #rpm -e sendmail.x.x.x --nodeps #rpm -e postfix.x.x.x --nodeps
Installation
Installing Cyrus-SASL
#cd /usr/local/src #tar -zxvf cyrus-sasl-2.1.22.tar.gz #cd cyrus-sasl-2.1.22
#export CPPFLAGS="-I/usr/include/mysql"
#export LDFLAGS="-L/usr/lib/mysql -lmysqlclient -lz -lm"
#./configure –enable-anon –enable-plain –enable-login –enable-sql \
–disable-krb4 –disable-otp –disable-cram –disable-digest \
–with-mysql=/usr/lib/mysql –without-pam –without-saslauthd \
–without-pwcheck –prefix=/usr –with-plugindir=/usr/lib/sasl2
#make -j2; make install
Installing Postfix :
Before we install the postfix we need to create postfix and postdrop id first, you can create it using this command:
#useradd postfix
#groupadd postdrop
#usermod -a -G postdrop postfix
now you can see the postfix id number
#id postfix uid=500(postfix) gid=500(postfix) groups=500(postfix),501(postdrop)
Start the installation :
# cd /usr/local/src
# tar -zxvf postfix-2.5.5.tar.gz
# cd postfix-2.5.5
# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_TLS -DUSE_CYRUS_SASL -I/usr/include/sasl' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib -lssl -lcrypto -lsasl2'
# make install
after some compilation process, you will be prompt for a lot of question, don’t worry just enter it till the end
Okay after you finish installing you need to edit Postfix main.cf :
We need to add few lines below in the end of main.cf, you have create a postfix user before right you can see the id (id postfix) then We’re going to punt and make all virtual mail users use the same UID:GID of Postfix. In my case the uid and gid is 500, 500 is postfix group id and user id
#id postfix uid=500(postfix) gid=500(postfix) groups=500(postfix),501(postdrop)
#cd /etc/postfix #vi main.cf
then paste this :
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:500
virtual_mailbox_base = /var/vmail/
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_limit = 112400000
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 500 virtual_transport = virtual
virtual_uid_maps = static:500
alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
#====================SASL========================
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,\ reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,\ reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination,permit
smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_sasl_security_options = noanonymous smtpd_sasl_application_name = smtpd
smtpd_banner=$myhostname ESMTP "mail.lineabsolute.com"
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

Then we need to create file mysql_virtual_alias_maps.cf
$cd /etc/postfix
$vi mysql_virtual_alias_maps.cf
user = postfix
password = password123
hosts = localhost
dbname = postfix query = SELECT goto FROM alias WHERE address='%s' AND active = '1'

Create file mysql_virtual_domains_maps.cf
$vi mysql_virtual_domains_maps.cf
user = postfix
password = password123
hosts = localhost
dbname = postfix query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'

Create file mysql_virtual_mailbox_maps.cf
$vi mysql_virtual_mailbox_maps.cf
user = postfix
password = password123
hosts = localhost
dbname = postfix
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'

Afterwards we create the certificates for TLS :
# mkdir /etc/postfix/ssl
# cd /etc/postfix/ssl/
# openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
# chmod 600 smtpd.key
# openssl req -new -key smtpd.key -out smtpd.csr
# openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
# openssl rsa -in smtpd.key -out smtpd.key.unencrypted
# mv -f smtpd.key.unencrypted smtpd.key
# openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
# chmod o= /etc/postfix/ssl/smtpd.key
Installing Courier Authlib :
# cd /usr/local/src
# rpmbuild -ta courier-authlib-0.61.0.tar.bz2
if you see this error:
# rpmbuild -ta courier-authlib-0.61.0.tar.bz2 error: Failed build dependencies: libtool is needed by courier-authlib-0.61.0-1.i386 postgresql-devel is needed by courier-authlib-0.61.0-1.i386 gdbm-devel is needed by courier-authlib-0.61.0-1.i386 pam-devel is needed by courier-authlib-0.61.0-1.i386 gcc-c++ is needed by courier-authlib-0.61.0-1.i386 redhat-rpm-config is needed by courier-authlib-0.61.0-1.i386 /usr/include/ltdl.h is needed by courier-authlib-0.61.0-1.i386

you need to install some dependencies first
# yum install libtool postgresql-devel gdbm-devel pam-devel gcc-c++ redhat-rpm-config libtool-ltdl-devel libtool-ltdl
then run the rpmbuild again
# rpmbuild -ta courier-authlib-0.61.0.tar.bz2
# cd /usr/src/redhat/RPMS/i386/
# rpm -ivh courier-authlib*
Installing Courier-Imap :
you need to be user beside root to build the rpm packet, you need to add the courier user first:
# useradd courier
# su courier
$ mkdir
$HOME/rpm
$ mkdir $HOME/rpm/SOURCES $ mkdir $HOME/rpm/SPECS
$ mkdir $HOME/rpm/BUILD
$ mkdir $HOME/rpm/SRPMS
$ mkdir $HOME/rpm/RPMS
$ mkdir $HOME/rpm/RPMS/i386
$ echo "%_topdir $HOME/rpm" >> $HOME/.rpmmacros
$ mkdir $HOME/downloads
$ cd $HOME/downloads
$ cd /usr/local/src
$ sudo mv courier-imap*$HOME/downloads
password: –> just type enter when you prompt by password
$ rpmbuild -ta courier-imap*
become root user again to compile the courier-imap
$ su
# cd /home/courier/rpm/RPMS/i386
# rpm -ivh courier-imap*
We need to edit the authmysqlrc file :
# cd /etc/authlib/
# mv authmysqlrc authmysqlrc.ori
# vi /etc/authlib/authmysqlrc
we need to add this line
MYSQL_SERVER localhost
MYSQL_USERNAME postfix
MYSQL_PASSWORD password123
MYSQL_PORT 0
MYSQL_OPT 0
MYSQL_DATABASE postfix
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_CLEAR_PWFIELD password
MYSQL_UID_FIELD '500'
MYSQL_GID_FIELD '500'
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD '/var/vmail/'
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD maildir

Edit authdaemonrc :
# mv authdaemonrc authdaemonrc.ori
# vi authdaemonrc
add this line :
authmodulelist="authmysql authpam"
DEBUG_LOGIN=1
Configuring SMTP-Auth :
# vi /usr/lib/sasl2/smtpd.conf
add this line:
pwcheck_method: authdaemond log_level: 3 mech_list: PLAIN LOGIN authdaemond_path:/var/spool/authdaemon/socket
# chmod o+x /var/spool/authdaemon
Create directory /var/vmail for save postfix user maildir data :
# mkdir /var/vmail
# chown -R postfix:postfix /var/vmail/
Starting Courier-authlib, Courier-Imap and Postfix :
# chkconfig --levels 235 courier-authlib on
# /etc/init.d/courier-authlib start
Starting Courier authentication services (authdaemond) :
# chkconfig --levels 235 courier-imap on
# /etc/init.d/courier-imap start Starting Courier-IMAP server: imap generating-SSL-certificate... imap-ssl pop3 generating-SSL-certificate... pop3-ssl
nb : it will automatically generate cert for imaps and pop3s
# chkconfig --levels 235 postfix on
# postfix start postfix/postfix-script: starting the Postfix mail system
Common error
when you start the postfix later ( # postfix start ) you will get this error
#postfix start
postfix: fatal: /etc/postfix/main.cf, line 687: missing ‘=’ after attribute name: "reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,\"
the error was cause on /etc/postfix/main.cf, i use \ to make the code fit to pages, it should be set to
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient, reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination,permit
Installing Postfixadmin :
# cd /usr/local/src
# tar -zxvf postfixadmin-2.2.1.1.tar.gz
# mv postfixadmin-2.2.1.1 postfixadmin
move the postfixadmin to your current virtual host domain(usually you the setting was on httpd.conf
# mv postfixadmin /var/www/html
Create Postfixadmin Mysql DB username and password :
i assume you have set your mysql service, root username and password if not you can run
#service mysqld start #mysqladmin -u root pasword rootpassword
go to mysql db as root
# mysql -u root -p mysql> create database postfix; mysql> grant all on postfix.* to postfix@'%' identified by 'password123'; mysql> exit
Configure Postfix config.inc.php :
# cd /var/www/html/postfixadmin
# vi config.inc.php
### modify few lines below ###
$CONF['configured'] = true;
$CONF['database_type'] = ‘mysql’;
$CONF['database_host'] = ‘localhost’;
$CONF['database_user'] = ‘postfix’;
$CONF['database_password'] = ‘password123';
$CONF['database_name'] = ‘postfix’;
$CONF['database_prefix'] = ”;
$CONF['encrypt'] = ‘md5crypt’;
Setup Postfix Admin from Web URL :
Example : http://192.168.0.1/postfixadmin/setup.php

there will be a script that checked the requirement for the script, there will be a warning such as php-mbstring is not available yet you need to install it first if youwant the script to worked (yum -y install php-mbstring), you suppose to see account creation box in the bottom, you can set your admin account to login. Don’t forget to delete the setup.php after you finished.

now you can login to the postfixadmin http://192.168.0.1/postfixadmin/login.php

now you need to create a virtual domain inside the postfixadmin

you also need to create a new mailbox so we can test the postfix

Installing Squirellmail Webmail :
# cd /usr/local/src
# tar -zxvf squirrelmail-1.4.16.tar.gz
# mv squirrelmail-1.4.16 webmail
# mv webmail /var/www/html
Configuring Squirellmail :
# cd /var/www/html/webmail
# ./configure
type option 2
type option A
type option 6 for auth type "login"
type option 8 and type courier
type option B
type option 7 for smtp auth "login"
type S to save
type Q to quit

Testing out Courier Authdaemon :
# authtest -s smtp test@lineabsolute.com pass123 Authentication succeeded. Authenticated: test@lineabsolute.com (uid 501, gid 501) Home Directory: /var/vmail/ Maildir: test@lineabsolute.com/ Quota: (none) Encrypted Password: $1$b6f3890b$IpwvW9Vh7bBvgbRm8CBw.0 Cleartext Password: pass123
Options: (none)
Testing the postfix smtp:
# telnet localhost 25 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'.
220 adityo.swiftco.com ESMTP "mail.lineabsolute.com"
ehlo localhost
250-adityo.swiftco.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
as you can see the postfix smtp are working and we can see postfix already support Auth with Login and Plain,
Postfix also support STARTTLS which is mean postfix support SSL for smtp. if you cannot see the 250-STARTTLS , please checked the maillog ( tail -f /var/log/maillog) if you get this error
Nov 18 03:40:20 adityo postfix/master[12007]: fatal: bind 0.0.0.0 port 25: Address already in use
it means that there are some other mailsystem on the server that using the port 25, please checked the ssl path on /etc/postfix/main.cf or regenerate the ssl on /etc/postfix/ssl/ if you still cannot see the 250-STARTTLS
Testing the postfix imap:
# telnet localhost 143 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. * OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2008 Double Precision, Inc. See COPYING for distribution information.
a login test@lineabsolute.com test123 a OK LOGIN Ok.
Testing the postfix pop3:
# telnet localhost 110 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. +OK Hello there. user test@lineabsolute.com +OK Password required. pass test123 +OK logged in. list +OK POP3 clients that break here, they violate STD53. 1 623 ###---> that was the email id that exist on your inbox 2 864 . quit +OK Bye-bye.

Testing Send and Receive email from webmail :
Open your web browser and type this url below
Example : http://192.168.0.1/webmail
Input your email : test@lineabsolute.com
Input your password : test123

Install ClamAV :
# yum -y install clamav clamd unrar
if your yum did not do anything it means that you basic repository did not found any clamav package, you need to add another repository first
# yum -y install yum-priorities # wget http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el
# rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
# rpm -K rpmforge-release-0.3.6-1.el5.rf.*.rpm # rpm -i rpmforge-release-0.3.6-1.el5.rf.*.rpm
then try it again
# yum -y install clamav clamd unrar

Installing MailScanner :
# wget http://www.mailscanner.info/files/4/rpm/MailScanner-4.72.5-1.rpm.tar.gz
# tar zxvf MailScanner-4.72.5-1.rpm.tar.gz
# ./install.sh This will take a while...
#################################################################
SpamAssassin site rules found in /etc/mail/spamassassin
To activate MailScanner run the following commands:
service sendmail stop
chkconfig sendmail off
chkconfig MailScanner on
service MailScanner start
##################################################################
Mailscanner Configuration :
# cd /etc/MailScanner/
# mv MailScanner.conf MailScanner.conf.orig
# cat MailScanner.conf.orig | egrep ^[^#] > MailScanner.conf
# vi /etc/MailScanner/MailScanner.conf
Change some parameters so that they look like this:
Run As User = postfix
Run As Group = postfix
Incoming Queue Dir = /var/spool/postfix/hold
Outgoing Queue Dir = /var/spool/postfix/incoming
MTA = postfix
Incoming Work Group = clamav
Incoming Work Permissions = 0640
Virus Scanners = clamd
Clamd Socket = /tmp/clamd.socket
Clamd Lock File = /var/lock/subsys/clamd
SpamAssassin User State Dir = /var/spool/MailScanner/spamassassin
Quarantine User = root
Quarantine Group = apache
Quarantine Permissions = 0660
Quarantine Whole Message = yes
Quarantine Whole Message As Queue Files = no
Detailed Spam Report = yes
Include Scores In SpamAssassin Report = yes
Spam Actions = store
High Scoring Spam Actions = store
Always Looked Up Last = &MailWatchLogging Is Definitely Not Spam = &SQLWhitelist Is Definitely Spam = &SQLBlacklist Filename Rules = %etc-dir%/filename.rules.conf Filetype Rules = %etc-dir%/filetype.rules.conf Dangerous Content Scanning = %rules-dir%/content.scanning.rules.conf
# mkdir /var/spool/MailScanner/spamassassin/
# chown -R postfix:postfix /var/spool/MailScanner/