Install Qmail by copy/paste

Install Qmail by copy/paste

Install qmail by copy/paste… I suggest in small blocks at a time

Code:

#!/bin/sh

SERVERNAME=`hostname`

cd /usr/local/src/

wget http://qmail.linocomm.net/netqmail-1.06.tar.gz
wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
wget http://qmail.org/moni.csi.hu/pub/glibc-2.3.1/daemontools-0.76.errno.patch
wget http://qmail.org/moni.csi.hu/pub/glibc-2.3.1/ucspi-tcp-0.88.errno.patch

# install qmail:
umask 022
mkdir -p /package
cp daemontools-0.76.tar.gz /package

chmod 1755 /package
tar -xzf netqmail-1.06.tar.gz
tar -xzf ucspi-tcp-0.88.tar.gz
cd /package
tar -xzf daemontools-0.76.tar.gz

mkdir /var/qmail
cd /usr/local/src/netqmail-1.06
echo " /usr/sbin/groupadd nofiles
/usr/sbin/useradd -g nofiles -d /var/qmail/alias alias
/usr/sbin/useradd -g nofiles -d /var/qmail qmaild
/usr/sbin/useradd -g nofiles -d /var/qmail qmaill
/usr/sbin/useradd -g nofiles -d /var/qmail qmailp
/usr/sbin/groupadd qmail
/usr/sbin/useradd -g qmail -d /var/qmail qmailq
/usr/sbin/useradd -g qmail -d /var/qmail qmailr
/usr/sbin/useradd -g qmail -d /var/qmail qmails" > IDS

/bin/sh IDS

make setup check

./config-fast $SERVERNAME
cd /usr/local/src/ucspi-tcp-0.88
patch -p1 < ../ucspi-tcp-0.88.errno.patch
make
make setup check
cd /package/admin/daemontools-0.76
patch -p1 < /usr/local/src/daemontools-0.76.errno.patch
package/install

echo "./Maildir/" > /var/qmail/control/defaultdelivery
echo 120 > /var/qmail/control/concurrencyincoming
echo 120 > /var/qmail/control/concurrencyremote
echo 120 > /var/qmail/control/concurrencylocal

chmod 644 /var/qmail/control/concurrencyincoming
chmod 644 /var/qmail/control/concurrencyremote
chmod 644 /var/qmail/control/concurrencylocal

echo '#!/bin/sh
# Using stdout for logging
# Using control/defaultdelivery from qmail-local to deliver messages by default
' > /var/qmail/rc

echo "exec env – PATH="/var/qmail/bin:$PATH" \
qmail-start "`cat /var/qmail/control/defaultdelivery`"
" >> /var/qmail/rc

chmod 755 /var/qmail/rc
mkdir /var/log/qmail

# the qmailctl script­:
echo '#!/bin/sh

# For Red Hat chkconfig
# chkconfig: – 80 30
# description: the qmail MTA
' > /var/qmail/bin/qmailctl

echo 'PATH=/var/qmail/bin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
export PATH

QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`

case "$1' in
start)
echo "Starting qmail"
if svok /service/qmail-send ; then
svc -u /service/qmail-send
else
echo qmail-send supervise not running
fi
if svok /service/qmail-smtpd ; then
svc -u /service/qmail-smtpd
else
echo qmail-smtpd supervise not running
fi
if [ -d /var/lock/subsys ]; then
touch /var/lock/subsys/qmail
fi
;;
stop)
echo "Stopping qmail…"
echo " qmail-smtpd"
svc -d /service/qmail-smtpd
echo " qmail-send"
svc -d /service/qmail-send
if [ -f /var/lock/subsys/qmail ]; then
rm /var/lock/subsys/qmail
fi
;;
stat)
svstat /service/qmail-send
svstat /service/qmail-send/log
svstat /service/qmail-smtpd
svstat /service/qmail-smtpd/log
qmail-qstat
;;
doqueue|alrm|flush)
echo "Flushing timeout table and sending ALRM signal to qmail-send."
/var/qmail/bin/qmail-tcpok
svc -a /service/qmail-send
;;
queue)
qmail-qstat
qmail-qread
;;
reload|hup)
echo "Sending HUP signal to qmail-send."
svc -h /service/qmail-send
;;
pause)
echo "Pausing qmail-send"
svc -p /service/qmail-send
echo "Pausing qmail-smtpd"
svc -p /service/qmail-smtpd
;;
cont)
echo "Continuing qmail-send"
svc -c /service/qmail-send
echo "Continuing qmail-smtpd"
svc -c /service/qmail-smtpd
;;
restart)
echo "Restarting qmail:"
echo "* Stopping qmail-smtpd."
svc -d /service/qmail-smtpd
echo "* Sending qmail-send SIGTERM and restarting."
svc -t /service/qmail-send
echo "* Restarting qmail-smtpd."
svc -u /service/qmail-smtpd
;;
cdb)
tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
chmod 644 /etc/tcp.smtp.cdb
echo "Reloaded /etc/tcp.smtp."
;;
help)
cat << HELP
stop — stops mail service (smtp connections refused, nothing goes out)
start — starts mail service (smtp connection accepted, mail can go out)
pause — temporarily stops mail service (connections accepted, nothing leaves)
cont — continues paused mail service
stat — displays status of mail service
cdb — rebuild the tcpserver cdb file for smtp
restart — stops and restarts smtp, sends qmail-send a TERM & restarts it
doqueue — schedules queued messages for immediate delivery
reload — sends qmail-send HUP, rereading locals and virtualdomains
queue — shows status of queue
alrm — same as doqueue
flush — same as doqueue
hup — same as reload
HELP
;;
*)
echo "Usage: $0 {start|stop|restart|doqueue|flush|reload|stat|pause|cont|cdb|queue|help}"
exit 1
;;
esac

exit 0
' >> /var/qmail/bin/qmailctl

ln -s /var/qmail/bin/qmailctl /etc/rc.d/init.d/qmail
ln -s ../init.d/qmail /etc/rc.d/rc0.d/K30qmail
ln -s ../init.d/qmail /etc/rc.d/rc1.d/K30qmail
ln -s ../init.d/qmail /etc/rc.d/rc2.d/S80qmail
ln -s ../init.d/qmail /etc/rc.d/rc3.d/S80qmail
ln -s ../init.d/qmail /etc/rc.d/rc4.d/S80qmail
ln -s ../init.d/qmail /etc/rc.d/rc5.d/S80qmail
ln -s ../init.d/qmail /etc/rc.d/rc6.d/K30qmail

chmod 755 /var/qmail/bin/qmailctl
ln -s /var/qmail/bin/qmailctl /usr/bin

mkdir -p /var/qmail/supervise/qmail-send/log
mkdir -p /var/qmail/supervise/qmail-smtpd/log

echo '#!/bin/sh' > /var/qmail/supervise/qmail-send/run
echo "exec /var/qmail/rc
" >> /var/qmail/supervise/qmail-send/run

echo '#!/bin/sh' > /var/qmail/supervise/qmail-send/log/run
echo "exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t n40 s5242880 /var/log/qmail
" >> /var/qmail/supervise/qmail-send/log/run

cd /var/qmail/control
ln -s ../outgoingip outgoingip

echo '#!/bin/sh' > /var/qmail/supervise/qmail-smtpd/run
echo 'QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`
LOCAL=`head -1 /var/qmail/control/me`
if [ -z "$QMAILDUID" -o -z "$NOFILESGID" -o -z "$MAXSMTPD" -o -z "$LOCAL" ]; then
echo QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in
echo /var/qmail/supervise/qmail-smtpd/run
exit 1
fi
exec /usr/local/bin/softlimit -m 2000000 \
/usr/local/bin/tcpserver -v -H -R -l "$LOCAL" -x /etc/tcp.smtp.cdb -c "$MAXSMTPD" \
-u "$QMAILDUID" -g "$NOFILESGID" 0 smtp \
/var/qmail/bin/qmail-smtpd 2>&1' >> /var/qmail/supervise/qmail-smtpd/run

echo '#!/bin/sh' > /var/qmail/supervise/qmail-smtpd/log/run
echo "exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t n40 s5242880 /var/log/qmail/smtpd
" >> /var/qmail/supervise/qmail-smtpd/log/run

mkdir -p /var/log/qmail/smtpd
chown qmaill /var/log/qmail /var/log/qmail/smtpd

chmod 755 /var/qmail/supervise/qmail-send/run
chmod 755 /var/qmail/supervise/qmail-send/log/run
chmod 755 /var/qmail/supervise/qmail-smtpd/run
chmod 755 /var/qmail/supervise/qmail-smtpd/log/run

ln -s /var/qmail/supervise/qmail-send /var/qmail/supervise/qmail-smtpd /service
sleep 10
qmailctl stop

#create system aliases:
echo postmaster > /var/qmail/alias/.qmail-root
echo postmaster > /var/qmail/alias/.qmail-postmaster
ln -s .qmail-postmaster /var/qmail/alias/.qmail-mailer-daemon
chmod 644 /var/qmail/alias/.qmail-root /var/qmail/alias/.qmail-postmaster

echo '127.:allow,RELAYCLIENT=""' >>/etc/tcp.smtp
qmailctl cdb

/etc/rc.d/init.d/sendmail stop
rpm -e --nodeps sendmail

# link qmail version of sendmail:
rm /usr/lib/sendmail
rm /usr/sbin/sendmail
ln -s /var/qmail/bin/sendmail /usr/lib
ln -s /var/qmail/bin/sendmail /usr/sbin

qmailctl start

Creating an SSL key, CSR and self-signed cert


cd /etc/pki/tls
cd private
openssl genrsa -des3 -out `hostname`.key 1024
  # password: whatever you want


# TO MAKE IT HAVE NO PASSPHRASE (optional):
cp `hostname`.key `hostname`.key.orig
openssl rsa -in `hostname`.key.orig -out `hostname`.key

# MAKE THE CSR
cd ../csr
openssl req -new -key ../private/`hostname`.key -out `hostname`.csr
  # answer the questions

# MAKE THE SELF-SIGNED CERT:
cd ../certs
openssl x509 -req -days 1800 -in ../csr/`hostname`.csr -signkey ../private/`hostname`.key -out `hostname`.crt

Perl, Extended Find and Replace

Use with caution, this will not make backups:

search="searchRegExp"
replace="replaceStr"
egrep -lri --exclude="Entries" --exclude="*.gif" --exclude="*.WAV" --exclude="*.wav" --exclude="*.zip"  "$search" * | xargs perl -pi -e "s/$search/$replace/gi"

the “gi” option means globally, case-insensitive, so take the “i” off if you want it to be case-sensative.

If you want to make backup files, replace “perl -pi” with “perl -pi.bak”

Read more

Using XAJAX to autocomplete emails from address book

PostPosted: Sat Sep 10, 2005 6:00 pm Post subject: Reply with quote

Imagine that you are supposed to type in an email address into a form. You would typically type an email address that may be stored in your address book from a MySQL database. There are too many emails in your address book to pre-populate into a list on the page. Instead you want to start typing and have addresses that match what you’ve typed so far appear in a drop down. We will fetch the emails to populate the drop down from the server, on the fly, in the background.

Read more

nusoap WSDL service return array of complex data

I’m just getting the code in the post for now… hopefully I’ll have time to come back and document it for you. I am excluding my config.php on purpose, you’ll need to define you’re own constants in there.

<?php

require_once(“config.php”);
require_once(“nusoap.php”);

/*
* This function takes an $email address and returns an array of email addresses
* that are the given email address’s recent contacts from their address book.
*
* @param string $email (the email address of the user)
* @param string $token (a password that is used for authentication for use of this function, it is NOT the email users password.)
*/
function getAutocompleteContacts( $email, $num, $token ) {
  if ($token != SOAP_TOKEN)
    return new soap_fault(‘Server’, ”, “Supplied token does not match our records”,”);

$email = strtolower(trim($email));

if ( ! ereg( ‘^’.email_reg.’$', $email) )
return new soap_fault(‘Client’, ”, “Must supply a valid email address: $email not valid”,”);

$aDB = DB::connect( ADDR_DSN );
if ( DB::isError($aDB) ) {
return new soap_fault(‘Server’, ”, ‘Service temporarily unavailable: could not connect to ADDR_DSN DB’,”);
}
$aDB->setFetchMode( DB_FETCHMODE_ASSOC );

// REALLY YOU SHOULD DO YOU’RE OWN QUERY, BUT FOR THE SAKE
// OF THIS EXAMPLE, I’M JUST GOING TO INJECT A COUPLE RESULTS:
$result = array();
$result[] = array( ‘contact’ => ‘Chaos Captain’, ‘email’ => ‘choas@sdfusidfousdf.com’);
$result[] = array( ‘contact’ => ‘Joe Joe’, ‘email’ => ‘choas@sdf768sdf798s7df987.com’);

return $result;

#return new soap_fault(‘Server’, ”, ‘Fallthrough error, should have faulted on invalid type above’,”);

}

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ”;
$server = new soap_server;
$server->configureWSDL(‘addressbook1′, ‘urn:’.$_SERVER['SCRIPT_URI']);
$server->wsdl->addComplexType(
‘Contact’,
‘complexType’,
‘struct’,
‘all’,
”,
array(
‘contact’ => array(‘name’ => ‘contact’, ‘type’ => ‘xsd:string’),
‘email’ => array(‘name’ => ‘email’, ‘type’ => ‘xsd:string’),
)
);

$server->wsdl->addComplexType(
‘ContactArray’,
‘complexType’,
‘array’,
”,
‘SOAP-ENC:Array’,
array(),
array(
array(‘ref’=>’SOAP-ENC:arrayType’,'wsdl:arrayType’=>’tns:Contact[]‘)
),
‘tns:Contact’
);

$server->register(‘getAutocompleteContacts’,
array(‘email’ => ‘xsd:string’, ‘num’ => ‘xsd:int’, ‘token’ => ‘xsd:string’), // input parameters
array(‘return’ => ‘tns:ContactArray’),
‘urn:’.$_SERVER['SCRIPT_URI'], // namespace
‘urn:’.$_SERVER['SCRIPT_URI'].”#getAutocompleteContacts”, // soapaction
‘rpc’, // style
‘encoded’, // use
‘Fetch array of address book contacts for use in autocomplete’); // documentation

#$server->wsdl->schemaTargetNamespace = $_SERVER['SCRIPT_URI'];
$server->service($HTTP_RAW_POST_DATA);
exit();
?>

Client Code:

<?php
require_once(‘config.php’);
require_once(‘nusoap.php’);

$client = new soapclient(SOAP_SERVER_WSDL_URL, true);

// Check for an error
$err = $client->getError();
if ($err) {
// Display the error
echo ‘<h2>Constructor error</h2><pre>’ . $err . ‘</pre>’;
// At this point, you know the call that follows will fail
}

$result = $client->call(‘getAutocompleteContacts’, array(‘email’=>’something@asdf97s9d8f7sdf.com’, ‘num’=>5, ‘token’=>SOAP_TOKEN) );

print_r($result);
?>

Will production something like this::

Array
(
[0] => Array
(
[contact] => Chaos Captain
[email] => choas@sdfusidfousdf.com
)

[1] => Array
(
[contact] => Joe Joe
[email] => choas@sdf768sdf798s7df987.com
)

)