<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Denie&#039;s Tech Blog &#187; Tutorials</title>
	<atom:link href="http://blog.nataprawira.com/tech/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nataprawira.com/tech</link>
	<description>Information Technology for Life!</description>
	<lastBuildDate>Tue, 13 Dec 2011 05:17:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sendmail Multiple Queues</title>
		<link>http://blog.nataprawira.com/tech/2011/01/13/sendmail-multiple-queues/</link>
		<comments>http://blog.nataprawira.com/tech/2011/01/13/sendmail-multiple-queues/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 09:32:42 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Sendmail]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[multiple]]></category>
		<category><![CDATA[queue]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=200</guid>
		<description><![CDATA[

Source:
http://www.ducea.com/2008/08/19/sendmail-multiple-queues/
Sendmail will use by default a single mail queue. This is what most users will need, and if you don’t have any special requirement you will not care about this. Still for high traffic mail servers it might be useful to split the queue over several directories, as thousands of files in a single directory [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2011%2F01%2F13%2Fsendmail-multiple-queues%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2011%2F01%2F13%2Fsendmail-multiple-queues%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>Source:<br />
<a href="http://www.ducea.com/2008/08/19/sendmail-multiple-queues/">http://www.ducea.com/2008/08/19/sendmail-multiple-queues/</a></p>
<p>Sendmail will use by default a single mail queue. This is what most users will need, and if you don’t have any special requirement you will not care about this. Still for high traffic mail servers it might be useful to split the queue over several directories, as thousands of files in a single directory will become a performance penalty at some point and also processing the queue sequentially will become very slow.</p>
<p>This post will show how we can implement multiple mail queues with modern sendmail versions.<br />
Let’s start by assuming we want to use 8 mail queues. First thing is to create the actual directories as sendmail will not do this by default:</p>
<p><code>mkdir /var/spool/mqueue/q{1,2,3,4,5,6,7,8}</code></p>
<p>And fix the permissions to the ones of the original folder /var/spool/mqueue. For ex. this might look like:</p>
<p><code>chown -R root:smmsp /var/spool/mqueue/q*</code></p>
<p>using a default sendmail install running on debian. Fix the users to the specific ones found on your system (ls -al /var/spool/mqueue if you are uncertain of this).</p>
<p>Next, we need to enable the multiple queues in the sendmail configuration. For this we will edit sendmail.mc (normally found under /etc/mail) and append one line:</p>
<p><code>define(`QUEUE_DIR', `/var/spool/mqueue/q*')dnl</code></p>
<p>and now regenerate sendmail.cf; this is done normally running:</p>
<p><code>m4 sendmail.mc &gt; /etc/mail/sendmail.cf</code></p>
<p>(fix your paths appropriately), or if you are using debian sendmail you can just run make all in /etc/mail.</p>
<p>After restarting sendmail, it will start using the multiple queues we defined. Running mailq will output each of the queues:</p>
<p><code>#mailq<br />
/var/spool/mqueue/q6 is empty<br />
/var/spool/mqueue/q4 is empty<br />
/var/spool/mqueue/q3 is empty<br />
/var/spool/mqueue/q2 is empty<br />
/var/spool/mqueue/q5 is empty<br />
/var/spool/mqueue/q1 is empty<br />
/var/spool/mqueue/q7 is empty<br />
/var/spool/mqueue/q8 is empty<br />
Total requests: 0</code></p>
<p>Note: if you want to add more folders to the configuration all you have to do is to create the respective folders, set the appropriate permissions and restart sendmail.</p>
<p>If you had existing mails in the queue (most likely if you were looking for this solution), if you want them still processed, move them from /var/spool/mqueue in one of the newly created queues (q1 for ex).</p>
<p>Individual queue directories can be symbolic links to other partitions to spreads load among multiple disks. Queue IDs are unique across queues so you can move the items among queues if you have to.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2011/01/13/sendmail-multiple-queues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fully Optimized Sendmail.mc</title>
		<link>http://blog.nataprawira.com/tech/2010/12/24/fully-optimized-sendmail-mc/</link>
		<comments>http://blog.nataprawira.com/tech/2010/12/24/fully-optimized-sendmail-mc/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 17:54:13 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Sendmail]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[optimize]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=185</guid>
		<description><![CDATA[

This is what I&#8217;m currently using on &#8220;sendmail.mc&#8221;. So far quite good and I can blast around 100K emails within few hours. Enjoy!
divert(-1)dnl
include(`/usr/share/sendmail-cf/m4/cf.m4&#8242;)dnl
VERSIONID(`setup for linux&#8217;)dnl
OSTYPE(`linux&#8217;)dnl
define(`confDEF_USER_ID&#8217;, &#8220;8:12&#8221;)dnl
dnl define(`confAUTO_REBUILD&#8217;)dnl
define(`confTO_CONNECT&#8217;, `1m&#8217;)dnl
define(`confTRY_NULL_MX_LIST&#8217;, `True&#8217;)dnl
define(`confDONT_PROBE_INTERFACES&#8217;, `True&#8217;)dnl
define(`PROCMAIL_MAILER_PATH&#8217;, `/usr/bin/procmail&#8217;)dnl
define(`ALIAS_FILE&#8217;, `/etc/aliases&#8217;)dnl
define(`STATUS_FILE&#8217;, `/var/log/mail/statistics&#8217;)dnl
define(`UUCP_MAILER_MAX&#8217;, `2000000&#8242;)dnl
define(`confUSERDB_SPEC&#8217;, `/etc/mail/userdb.db&#8217;)dnl
define(`confPRIVACY_FLAGS&#8217;, `authwarnings,novrfy,noexpn,restrictqrun&#8217;)dnl
define(`confAUTH_OPTIONS&#8217;, `A&#8217;)dnl
define(`confCHECKPOINTINTERVAL&#8217;,`0&#8242;)dnl
define(`confCONNECTION_RATE_THROTTLE&#8217;,`0&#8242;)dnl
define(`confDF_BUFFER_SIZE&#8217;,`16384&#8242;)dnl
define(`confMAX_DAEMON_CHILDREN&#8217;,`0&#8242;)dnl
define(`confMAX_QUEUE_RUN_SIZE&#8217;,`0&#8242;)dnl
define(`confMCI_CACHE_SIZE&#8217;,`4&#8242;)dnl
define(`confMCI_CACHE_TIMEOUT&#8217;,`120s&#8217;)dnl
define(`confMIN_QUEUE_AGE&#8217;,`0&#8242;)dnl
define(`confSAFE_QUEUE&#8217;,`false&#8217;)dnl
define(`confTO_IDENT&#8217;,`0&#8242;)dnl
define(`confXF_BUFFER_SIZE&#8217;,`16384&#8242;)dnl
define(`confQUEUE_LA&#8217;,`1000&#8242;)dnl
define(`confREFUSE_LA&#8217;,`500&#8242;)dnl
FEATURE(`nocanonify&#8217;, `canonify_hosts&#8217;)dnl
FEATURE(`no_default_msa&#8217;, `dnl&#8217;)dnl
FEATURE(`mailertable&#8217;, `hash -o /etc/mail/mailertable.db&#8217;)dnl
FEATURE(`virtusertable&#8217;, `hash -o /etc/mail/virtusertable.db&#8217;)dnl
FEATURE(redirect)dnl
dnl # FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl
FEATURE(use_ct_file)dnl
FEATURE(local_procmail, `&#8217;, `procmail -t -Y -a $h -d $u&#8217;)dnl
FEATURE(`access_db&#8217;, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F12%2F24%2Ffully-optimized-sendmail-mc%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F12%2F24%2Ffully-optimized-sendmail-mc%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><strong>This is what I&#8217;m currently using on &#8220;sendmail.mc&#8221;. So far quite good and I can blast around 100K emails within few hours. Enjoy!<span id="more-185"></span></strong></p>
<p>divert(-1)dnl<br />
include(`/usr/share/sendmail-cf/m4/cf.m4&#8242;)dnl<br />
VERSIONID(`setup for linux&#8217;)dnl<br />
OSTYPE(`linux&#8217;)dnl<br />
define(`confDEF_USER_ID&#8217;, &#8220;8:12&#8221;)dnl<br />
dnl define(`confAUTO_REBUILD&#8217;)dnl<br />
define(`confTO_CONNECT&#8217;, `1m&#8217;)dnl<br />
define(`confTRY_NULL_MX_LIST&#8217;, `True&#8217;)dnl<br />
define(`confDONT_PROBE_INTERFACES&#8217;, `True&#8217;)dnl<br />
define(`PROCMAIL_MAILER_PATH&#8217;, `/usr/bin/procmail&#8217;)dnl<br />
define(`ALIAS_FILE&#8217;, `/etc/aliases&#8217;)dnl<br />
define(`STATUS_FILE&#8217;, `/var/log/mail/statistics&#8217;)dnl<br />
define(`UUCP_MAILER_MAX&#8217;, `2000000&#8242;)dnl<br />
define(`confUSERDB_SPEC&#8217;, `/etc/mail/userdb.db&#8217;)dnl<br />
define(`confPRIVACY_FLAGS&#8217;, `authwarnings,novrfy,noexpn,restrictqrun&#8217;)dnl<br />
define(`confAUTH_OPTIONS&#8217;, `A&#8217;)dnl<br />
define(`confCHECKPOINTINTERVAL&#8217;,`0&#8242;)dnl<br />
define(`confCONNECTION_RATE_THROTTLE&#8217;,`0&#8242;)dnl<br />
define(`confDF_BUFFER_SIZE&#8217;,`16384&#8242;)dnl<br />
define(`confMAX_DAEMON_CHILDREN&#8217;,`0&#8242;)dnl<br />
define(`confMAX_QUEUE_RUN_SIZE&#8217;,`0&#8242;)dnl<br />
define(`confMCI_CACHE_SIZE&#8217;,`4&#8242;)dnl<br />
define(`confMCI_CACHE_TIMEOUT&#8217;,`120s&#8217;)dnl<br />
define(`confMIN_QUEUE_AGE&#8217;,`0&#8242;)dnl<br />
define(`confSAFE_QUEUE&#8217;,`false&#8217;)dnl<br />
define(`confTO_IDENT&#8217;,`0&#8242;)dnl<br />
define(`confXF_BUFFER_SIZE&#8217;,`16384&#8242;)dnl<br />
define(`confQUEUE_LA&#8217;,`1000&#8242;)dnl<br />
define(`confREFUSE_LA&#8217;,`500&#8242;)dnl<br />
FEATURE(`nocanonify&#8217;, `canonify_hosts&#8217;)dnl<br />
FEATURE(`no_default_msa&#8217;, `dnl&#8217;)dnl<br />
FEATURE(`mailertable&#8217;, `hash -o /etc/mail/mailertable.db&#8217;)dnl<br />
FEATURE(`virtusertable&#8217;, `hash -o /etc/mail/virtusertable.db&#8217;)dnl<br />
FEATURE(redirect)dnl<br />
dnl # FEATURE(always_add_domain)dnl<br />
FEATURE(use_cw_file)dnl<br />
FEATURE(use_ct_file)dnl<br />
FEATURE(local_procmail, `&#8217;, `procmail -t -Y -a $h -d $u&#8217;)dnl<br />
FEATURE(`access_db&#8217;, `hash -T&lt;TMPF&gt; -o /etc/mail/access.db&#8217;)dnl<br />
EXPOSED_USER(`root&#8217;)dnl<br />
DAEMON_OPTIONS(`Name=MTA-v4, Family=inet&#8217;)<br />
LOCAL_DOMAIN(`localhost.localdomain&#8217;)dnl<br />
MODIFY_MAILER_FLAGS(`PROCMAIL&#8217;, `+m&#8217;)dnl<br />
dnl # INPUT_MAIL_FILTER(`dk-filter&#8217;, `S=inet:8891@localhost&#8217;)dnl<br />
FEATURE(`dnsbl&#8217;,`bl.spamcop.net&#8217;,`554 Mail from $&amp;{client_addr} rejected by bl.spamcop.net&#8217;)dnl<br />
FEATURE(`dnsbl&#8217;,`rbl-plus.mail-abuse.org&#8217;,`&#8221;MAPS-listed host: http://mail-abuse.org/cgi-bin/lookup?&#8221;$&amp;{client_addr}&#8217;)dnl<br />
FEATURE(`dnsbl&#8217;,`sbl-xbl.spamhaus.org&#8217;,`554 Mail from $&amp;{client_addr} has been rejected by the Spamhaus Blackhole List&#8217;)dnl<br />
FEATURE(`dnsbl&#8217;,`dnsbl.sorbs.net&#8217;,`554 Mail from $&amp;{client_addr} has been rejected by the SORBS&#8217;)dnl<br />
MAILER(smtp)dnl<br />
MAILER(procmail)dnl</p>
<hr />[root@edm mail]# cat /proc/meminfo<br />
MemTotal:        8455500 kB</p>
<hr />[root@edm mail]# cat /proc/cpuinfo<br />
processor       : 0<br />
vendor_id       : AuthenticAMD<br />
cpu family      : 16<br />
model           : 2<br />
model name      : Quad-Core AMD Opteron(tm) Processor 2350 HE<br />
stepping        : 3<br />
cpu MHz         : 1995.000<br />
cache size      : 512 KB<br />
fpu             : yes<br />
fpu_exception   : yes<br />
cpuid level     : 5<br />
wp              : yes<br />
flags           : fpu de tsc msr pae cx8 apic cmov pat clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt lm 3dnowext 3dnow constant_tsc rep_good nonstop_tsc pni cx16 popcnt lahf_lm cmp_legacy extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch<br />
bogomips        : 3999.51<br />
TLB size        : 1024 4K pages<br />
clflush size    : 64<br />
cache_alignment : 64<br />
address sizes   : 48 bits physical, 48 bits virtual<br />
power management: ts ttp tm stc 100mhzsteps hwpstate</p>
<p>processor       : 1<br />
vendor_id       : AuthenticAMD<br />
cpu family      : 16<br />
model           : 2<br />
model name      : Quad-Core AMD Opteron(tm) Processor 2350 HE<br />
stepping        : 3<br />
cpu MHz         : 1995.000<br />
cache size      : 512 KB</p>
<p>processor       : 2<br />
vendor_id       : AuthenticAMD<br />
cpu family      : 16<br />
model           : 2<br />
model name      : Quad-Core AMD Opteron(tm) Processor 2350 HE<br />
stepping        : 3<br />
cpu MHz         : 1995.000<br />
cache size      : 512 KB</p>
<p>processor       : 3<br />
vendor_id       : AuthenticAMD<br />
cpu family      : 16<br />
model           : 2<br />
model name      : Quad-Core AMD Opteron(tm) Processor 2350 HE<br />
stepping        : 3<br />
cpu MHz         : 1995.000<br />
cache size      : 512 KB</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2010/12/24/fully-optimized-sendmail-mc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tuning Sendmail</title>
		<link>http://blog.nataprawira.com/tech/2010/12/24/tuning-sendmail/</link>
		<comments>http://blog.nataprawira.com/tech/2010/12/24/tuning-sendmail/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 17:20:01 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Sendmail]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Tuning]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=183</guid>
		<description><![CDATA[

# Copyright (c) 2001 Sendmail, Inc. and its suppliers.
#	All rights reserved.
#
# By using this file, you agree to the terms and conditions set
# forth in the LICENSE file which can be found at the top level of
# the sendmail distribution.
#
#	$Id: TUNING,v 1.16 2001/08/19 21:03:38 gshapiro Exp $
#
********************************************
** This is a DRAFT, comments are welcome! **
********************************************
If [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F12%2F24%2Ftuning-sendmail%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F12%2F24%2Ftuning-sendmail%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p># Copyright (c) 2001 Sendmail, Inc. and its suppliers.<br />
#	All rights reserved.<br />
#<br />
# By using this file, you agree to the terms and conditions set<br />
# forth in the LICENSE file which can be found at the top level of<br />
# the sendmail distribution.<br />
#<br />
#	$Id: TUNING,v 1.16 2001/08/19 21:03:38 gshapiro Exp $<br />
#<span id="more-183"></span></p>
<p>********************************************<br />
** This is a DRAFT, comments are welcome! **<br />
********************************************</p>
<p>If the default configuration of sendmail does not achieve the<br />
required performance, there are several configuration options that<br />
can be changed to accomplish higher performance.  However, before<br />
those options are changed it is necessary to understand why the<br />
performance is not as good as desired.  This may also involve hardware<br />
and software (OS) configurations which are not extensively explored<br />
in this document.  We assume that your system is not limited by<br />
network bandwidth because optimizing for this situation is beyond<br />
the scope of this guide.  In almost all other cases performance will<br />
be limited by disk I/O.</p>
<p>This text assumes that all options which are mentioned here are<br />
familiar to the reader, they are explained in the Sendmail Installation<br />
and Operations Guide; doc/op/op.txt.</p>
<p>There are basically three different scenarios which are treated<br />
in the following:<br />
* Mailing Lists and Large Aliases (1-n Mailing)<br />
* 1-1 Mass Mailing<br />
* High Volume Mail</p>
<p>Depending on your requirements, these may need different options<br />
to optimize sendmail for the particular purpose.  It is also possible<br />
to configure sendmail to achieve good performance in all cases, but<br />
it will not be optimal for any specific purpose.  For example, it<br />
is non-trivival to combine low latency (fast delivery of incoming<br />
mail) with high overall throughput.</p>
<p>Before we explore the different scenarios, a basic discussion about<br />
disk I/O, delivery modes, and queue control is required.</p>
<p>* Disk I/O<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>In general mail will be written to disk up before a delivery attempt<br />
is made.  This is required for reliability and should only be changed<br />
in a few specific cases that are mentioned later on.  To achieve<br />
better disk I/O performance the queue directories can be spread<br />
over several disks to distribute the load.  This is some basic tuning<br />
that should be done in all cases where the I/O speed of a single<br />
disk is exceeded, which is true for almost every high-volume<br />
situation except if a special disk subsystem with large (NV)RAM<br />
buffer is used.</p>
<p>Depending on your OS there might be ways to speed up I/O, e.g.,<br />
using softupdates or turning on the noatime mount option.  If this<br />
is done make sure the filesystem is still reliable, i.e., if fsync()<br />
returns without an error, the file has really been committed to<br />
disk.</p>
<p>* Queueing Strategies and DeliveryMode<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>There are basically three delivery modes:</p>
<p>background: incoming mail will be immediately delivered by a new process<br />
interactive: incoming mail will be immediately delivered by the same process<br />
queue: incoming mail will be queued and delivered by a queue runner later on</p>
<p>The first offers the lowest latency without the disadvantage of the<br />
second, which keep the connection from the sender open until the<br />
delivery to the next hop succeeded or failed.  However, it does not<br />
allow for a good control over the number of delivery processes other<br />
than limiting the total number of direct children of the daemon<br />
processes (MaxChildren) or by load control options (RefuseLA,<br />
DelayLA).  Moreover, it can&#8217;t make as good use as &#8216;queue&#8217; mode can<br />
for connection caching.</p>
<p>Interactive DeliveryMode should only be used in rare cases, e.g.,<br />
if the delivery time to the next hop is a known quantity or if the<br />
sender is under local control and it does not matter if it has to<br />
wait for delivery.</p>
<p>Queueing up e-mail before delivery is done by a queue runner allows<br />
the best load control but does not achieve as low latency as the<br />
other two modes.  However, this mode is probably also best for<br />
concurrent delivery since the number of queue runners can be specified<br />
on a queue group basis.  Persistent queue runners (-qp) can be used<br />
to minimize the overhead for creating processes because they just<br />
sleep for the specified interval (which shold be short) instead of<br />
exiting after a queue run.</p>
<p>* Queue Groups<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>In most situations disk I/O is a bottleneck which can be mitigated<br />
by spreading the load over several disks.  This can easily be achieved<br />
with different queue directories.  sendmail 8.12 introduces queue<br />
groups which are collections of queue directories with similar<br />
properties, i.e., number of processes to run the queues in the<br />
group, maximum number of recipients within an e-mail (envelope),<br />
etc.  Queue groups allow control over the behaviour of different<br />
queues.  Depending on the setup, it is usually possible to have<br />
several queue runners delivering mails concurrently which should<br />
increase throughput.  The number of queue runners can be controlled<br />
per queue group (Runner=) and overall (MaxQueueChildren).</p>
<p>* DNS Lookups<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>sendmail performs by default host name canonifications by using<br />
host name lookups.  This process is meant to replace unqualified<br />
host name with qualified host names, and CNAMEs with the non-aliased<br />
name.  However, these lookups can take a while for large address<br />
lists, e.g., mailing lists.  If you can assure by other means that<br />
host names are canonical, you should use</p>
<p>FEATURE(`nocanonify&#8217;, `canonify_hosts&#8217;)</p>
<p>in your .mc file.  For further information on this feature and<br />
additional options see cf/README.  If sendmail is invoked directly<br />
to send e-mail then either the -G option should be used or</p>
<p>define(`confDIRECT_SUBMISSION_MODIFIERS&#8217;, `C&#8217;)</p>
<p>should be added to the .mc file.</p>
<p>* Mailing Lists and Large Aliases (1-n Mailing)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Before 8.12 sendmail delivers an e-mail sequentially to all its<br />
recipients.  For mailing lists or large aliases the overall delivery<br />
time can be substantial, especially if some of the recipients are located<br />
at hosts that are slow to accept e-mail.  Some mailing list software<br />
therefore &#8220;split&#8221; up e-mails into smaller pieces with fewer recipients.<br />
sendmail 8.12 can do this itself, either across queue groups or<br />
within a queue directory.  For the former the option SplitAcrossQueueGroups<br />
option must be set, the latter is controlled by the &#8216;r=&#8217; field of<br />
a queue group declaration.</p>
<p>Let&#8217;s assume a simple example: a mailing lists where most of<br />
the recipients are at three domains: the local one (local.domain)<br />
and two remotes (one.domain, two.domain) and the rest is splittered<br />
over several other domains.  For this case it is useful to specify<br />
three queue groups:</p>
<p>QUEUE_GROUP(`local&#8217;, `P=/var/spool/mqueue/local, F=f, R=2, I=1m&#8217;)dnl<br />
QUEUE_GROUP(`one&#8217;, `P=/var/spool/mqueue/one, F=f, r=50, R=3&#8242;)dnl<br />
QUEUE_GROUP(`two&#8217;, `P=/var/spool/mqueue/two, F=f, r=30, R=4&#8242;)dnl<br />
QUEUE_GROUP(`remote&#8217;, `P=/var/spool/mqueue/remote, F=f, r=5, R=8, I=2m&#8217;)dnl<br />
define(`ESMTP_MAILER_QGRP&#8217;, `remote&#8217;)dnl<br />
define(`confSPLIT_ACROSS_QUEUEGROUPS&#8217;, `True&#8217;)dnl<br />
define(`confDELIVERY_MODE&#8217;, `q&#8217;)dnl<br />
define(`confMAX_QUEUE_CHILDREN&#8217;, `50&#8242;)dnl<br />
define(`confMIN_QUEUE_AGE&#8217;, `27m&#8217;)dnl</p>
<p>and specify the queuegroup ruleset as follows:</p>
<p>LOCAL_RULESETS<br />
Squeuegroup<br />
R$* @ local.domain	$# local<br />
R$* @ $* one.domain	$# one<br />
R$* @ $* two.domain	$# two<br />
R$* @ $*		$# remote<br />
R$*			$# mqueue</p>
<p>Now it is necessary to control the number of queue runners, which<br />
is done by MaxQueueChildren.  Starting the daemon with the option<br />
-q5m assures that the first delivery attempt for each e-mail is<br />
done within 5 minutes, however, there are also individual queue<br />
intervals for the queue groups as specified above.  MinQueueAge<br />
is set to 27 minutes to avoid that entries are run too often.</p>
<p>Notice: if envelope splitting happens due to alias expansion, and<br />
DeliveryMode is not &#8216;i&#8217;nteractive, then only one envelope is sent<br />
immediately.  The rest (after splitting) are queued up and queue<br />
runners must come along and take care of them.  Hence it is essential<br />
that the queue interval is very short.</p>
<p>* 1-1 Mass Mailing<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>In this case some program generates e-mails which are sent to<br />
individual recipients (or at most very few per e-mail).  A simple<br />
way to achieve high throughput is to set the delivery mode to<br />
&#8216;interactive&#8217;, turn off the SuperSafe option and make sure that the<br />
program that generates the mails can deal with mail losses if the<br />
server loses power.  In no other case should SuperSafe be set to<br />
&#8216;false&#8217;.  If these conditions are met, sendmail does not need to<br />
commit mails to disk but can buffer them in memory which will greatly<br />
enhance performance, especially compared to normal disk subsystems, e.g.,<br />
non solid-state disks.</p>
<p>* High Volume Mail<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>For high volume mail it is necessary to be able to control the load<br />
on the system.  Therefore the &#8216;queue&#8217; delivery mode should be used,<br />
and all options related to number of processes and the load should<br />
be set to reasonable values.  It is important not to accept mail<br />
faster than it can be delivered otherwise the system will be<br />
overwhelmed.  Hence RefuseLA should be lower than QueueLA, the number<br />
of daemon children should probably be lower than the number of queue<br />
runnners (MaxChildren vs. MaxQueueChildren).  DelayLA is a new option<br />
in 8.12 which allows delaying connections instead of rejecting them.<br />
This may result in a smoother load distribution depending on how<br />
the mails are submitted to sendmail.</p>
<p>* Miscellaneous<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Other options that are interesting to tweak performance are<br />
(in no particular order):</p>
<p>SuperSafe: if interactive DeliveryMode is used, then this can<br />
be set to the new value &#8220;interactive&#8221; in 8.12 to save some disk<br />
synchronizations which are not really necessary in that mode.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Source:<br />
http://luxio.us/gXwyLu</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2010/12/24/tuning-sendmail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTAccess Tricks</title>
		<link>http://blog.nataprawira.com/tech/2010/12/06/htaccess-tricks/</link>
		<comments>http://blog.nataprawira.com/tech/2010/12/06/htaccess-tricks/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 02:19:37 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[HTaccess]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=176</guid>
		<description><![CDATA[


Source: Stupid HTAccess Tricks
GENERAL INFORMATION [ ^ ]
.htaccess Definition 1 ^
Apache server software provides distributed (i.e., directory-level) configuration via Hypertext Access files. These .htaccess files enable the localized fine-tuning of Apache’s universal system-configuration directives, which are defined in Apache’s main configuration file. The localized .htaccess directives must operate from within a file named .htaccess. The user must have appropriate file permissions to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F12%2F06%2Fhtaccess-tricks%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F12%2F06%2Fhtaccess-tricks%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><a name="top"></a><span style="color: #000000"><br />
<em>Source: <a title="Stupid HTAccess Tricks" href="http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/" target="_blank">Stupid HTAccess Tricks</a></em></span></p>
<h3 id="general"><span style="color: #000000">GENERAL INFORMATION [ <a href="#top">^</a> ]</span></h3>
<h4 id="gen1"><span style="color: #000000">.htaccess Definition <sup>1</sup> <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Apache server software provides distributed (i.e., directory-level) configuration via <em>Hypertext Access</em> files. These <a title="htaccess at Wikipedia" rel="nofollow" href="http://en.wikipedia.org/wiki/Htaccess"><code>.</code><code>htaccess</code></a> files enable the localized fine-tuning of Apache’s universal system-configuration directives, which are defined in Apache’s main configuration file. The localized <code>.</code><code>htaccess</code> directives must operate from within a file named <code>.</code><code>htaccess</code>. The user must have appropriate file permissions to access and/or edit the <code>.</code><code>htaccess</code> file. Further,<code>.</code><code>htaccess</code> file permissions should never allow world write access — a secure permissions setting is “644”, which allows universal read access and user-only write access. Finally,<code>.</code><code>htaccess</code> rules apply to the parent directory and all subdirectories. Thus to apply configuration rules to an entire website, place the <code>.</code><code>htaccess</code> file in the root directory of the site.<span id="more-176"></span></span></p>
<h4 id="gen2"><span style="color: #000000">Commenting .htaccess Code <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Comments are essential to maintaining control over any involved portion of code. Comments in<code>.</code><code>htaccess</code> code are fashioned on a per-line basis, with each line of comments beginning with a pound sign <code>#</code>. Thus, comments spanning multiple lines in the <code>.</code><code>htaccess</code> file require multiple pound signs. Further, due to the extremely volatile nature of htaccess voodoo, it is wise to include only alphanumeric characters (and perhaps a few dashes and underscores) in any<code>.</code><code>htaccess</code> comments.</span></p>
<h4 id="gen3"><span style="color: #000000">Important Notes for .htaccess Noobs <a href="#top">^</a></span></h4>
<p><span style="color: #000000">As a configuration file, <code>.</code><code>htaccess</code> is very powerful. Even the slightest syntax error (like a missing space) can result in severe server malfunction. Thus it is crucial to make backup copies of <em>everything</em> related to your site (including any original <code>.</code><code>htaccess</code> files) <em>before</em> working with your Hypertext Access file(s). It is also important to check your entire website thoroughly after making any changes to your <code>.</code><code>htaccess</code> file. If any errors or other problems are encountered, employ your backups immediately to restore original functionality.</span></p>
<h4 id="gen4"><span style="color: #000000">Performance Issues <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000">.</span></code><code><span style="color: #000000">htaccess</span></code><span style="color: #000000"> directives provide directory-level configuration without requiring access to Apache’s main server cofiguration file (httpd.conf). However, due to performance and security concerns, the main configuration file should always be used for server directives whenever possible. For example, when a server is configured to process <code>.</code><code>htaccess</code> directives, Apache must search every directory within the domain and load any and all <code>.</code><code>htaccess</code> files upon every document request. This results in increased page processing time and thus decreases performance. Such a performance hit may be unnoticeable for sites with light traffic, but becomes a more serious issue for more popular websites. Therefore, <code>.</code><code>htaccess</code> files should only be used when the main server configuration file is inaccessible. See the “<a href="#performance">Performance Tricks</a>” section of this article for more information.</span></p>
<h4 id="gen5"><span style="color: #000000">Regex Character Definitions for htaccess <sup>2</sup> <a href="#top">^</a></span></h4>
<dl>
<dt><code><span style="color: #000000">#</span></code></dt>
<dd><span style="color: #000000">the <code>#</code> instructs the server to ignore the line. used for including comments. each line of comments requires it’s own <code>#</code>. when including comments, it is good practice to use only letters, numbers, dashes, and underscores. this practice will help eliminate/avoid potential server parsing errors. </span></dd>
<dt><code><span style="color: #000000">[F]</span></code></dt>
<dd><span style="color: #000000">Forbidden: instructs the server to return a <code>403 Forbidden</code> to the client. </span></dd>
<dt><code><span style="color: #000000">[L]</span></code></dt>
<dd><span style="color: #000000">Last rule: instructs the server to stop rewriting after the preceding directive is processed. </span></dd>
<dt><code><span style="color: #000000">[N]</span></code></dt>
<dd><span style="color: #000000">Next: instructs Apache to rerun the rewrite rule until all rewriting directives have been achieved. </span></dd>
<dt><code><span style="color: #000000">[G]</span></code></dt>
<dd><span style="color: #000000">Gone: instructs the server to deliver <code>Gone (no longer exists)</code> status message. </span></dd>
<dt><code><span style="color: #000000">[P]</span></code></dt>
<dd><span style="color: #000000">Proxy: instructs server to handle requests by <code>mod_proxy</code> </span></dd>
<dt><code><span style="color: #000000">[C]</span></code></dt>
<dd><span style="color: #000000">Chain: instructs server to chain the current rule with the previous rule. </span></dd>
<dt><code><span style="color: #000000">[R]</span></code></dt>
<dd><span style="color: #000000">Redirect: instructs Apache to issue a redirect, causing the browser to request the rewritten/modified URL. </span></dd>
<dt><code><span style="color: #000000">[NC]</span></code></dt>
<dd><span style="color: #000000">No Case: defines any associated argument as case-<em>in</em>sensitive. i.e., &#8220;NC&#8221; = &#8220;No Case&#8221;. </span></dd>
<dt><code><span style="color: #000000">[PT]</span></code></dt>
<dd><span style="color: #000000">Pass Through: instructs <code>mod_rewrite</code> to pass the rewritten URL back to Apache for further processing. </span></dd>
<dt><code><span style="color: #000000">[OR]</span></code></dt>
<dd><span style="color: #000000">Or: specifies a logical &#8220;or&#8221; that ties two expressions together such that either one proving true will cause the associated rule to be applied. </span></dd>
<dt><code><span style="color: #000000">[NE]</span></code></dt>
<dd><span style="color: #000000">No Escape: instructs the server to parse output without escaping characters. </span></dd>
<dt><code><span style="color: #000000">[NS]</span></code></dt>
<dd><span style="color: #000000">No Subrequest: instructs the server to skip the directive if internal sub-request. </span></dd>
<dt><code><span style="color: #000000">[QSA]</span></code></dt>
<dd><span style="color: #000000">Append Query String: directs server to add the query string to the end of the expression (URL). </span></dd>
<dt><code><span style="color: #000000">[S=x]</span></code></dt>
<dd><span style="color: #000000">Skip: instructs the server to skip the next &#8220;x&#8221; number of rules if a match is detected. </span></dd>
<dt><code><span style="color: #000000">[E=variable:value]</span></code></dt>
<dd><span style="color: #000000">Environmental Variable: instructs the server to set the environmental variable &#8220;variable&#8221; to &#8220;value&#8221;. </span></dd>
<dt><code><span style="color: #000000">[T=MIME-type]</span></code></dt>
<dd><span style="color: #000000">Mime Type: declares the mime type of the target resource. </span></dd>
<dt><code><span style="color: #000000">[]</span></code></dt>
<dd><span style="color: #000000">specifies a character class, in which any character within the brackets will be a match. e.g., [xyz] will match either an x, y, or z. </span></dd>
<dt><code><span style="color: #000000">[]+</span></code></dt>
<dd><span style="color: #000000">character class in which any combination of items within the brackets will be a match. e.g., [xyz]+ will match any number of x’s, y’s, z’s, or any combination of these characters. </span></dd>
<dt><code><span style="color: #000000">[^]</span></code></dt>
<dd><span style="color: #000000">specifies <em>not</em> within a character class. e.g., [^xyz] will match any character that is neither x, y, nor z. </span></dd>
<dt><code><span style="color: #000000">[a-z]</span></code></dt>
<dd><span style="color: #000000">a dash (-) between two characters within a character class ([]) denotes the range of characters between them. e.g., [a-zA-Z] matches all lowercase and uppercase letters from a to z. </span></dd>
<dt><code><span style="color: #000000">a{n}</span></code></dt>
<dd><span style="color: #000000">specifies an exact number, <code>n</code>, of the preceding character. e.g., x{3} matches exactly three<code>x</code>’s. </span></dd>
<dt><code><span style="color: #000000">a{n,}</span></code></dt>
<dd><span style="color: #000000">specifies <code>n</code> or more of the preceding character. e.g., x{3,} matches three or more <code>x</code>’s. </span></dd>
<dt><code><span style="color: #000000">a{n,m}</span></code></dt>
<dd><span style="color: #000000">specifies a range of numbers, between <code>n</code> and <code>m</code>, of the preceding character. e.g., x{3,7} matches three, four, five, six, or seven <code>x</code>’s. </span></dd>
<dt><code><span style="color: #000000">()</span></code></dt>
<dd><span style="color: #000000">used to group characters together, thereby considering them as a single unit. e.g., (perishable)?press will match press, with or without the perishable prefix. </span></dd>
<dt><code><span style="color: #000000">^</span></code></dt>
<dd><span style="color: #000000">denotes the beginning of a regex (regex = regular expression) test string. i.e., begin argument with the proceeding character. </span></dd>
<dt><code><span style="color: #000000">$</span></code></dt>
<dd><span style="color: #000000">denotes the end of a regex (regex = regular expression) test string. i.e., end argument with the previous character. </span></dd>
<dt><code><span style="color: #000000">?</span></code></dt>
<dd><span style="color: #000000">declares as optional the preceding character. e.g., <code>monzas?</code> will match monza or monzas, while <code>mon(za)?</code> will match either mon or monza. i.e., <code>x?</code> matches zero or one of <code>x</code>. </span></dd>
<dt><code><span style="color: #000000">!</span></code></dt>
<dd><span style="color: #000000">declares negation. e.g., “<code>!string</code>” matches everything except “<code>string</code>”. </span></dd>
<dt><code><span style="color: #000000">.</span></code></dt>
<dd><span style="color: #000000">a dot (or period) indicates any single arbitrary character. </span></dd>
<dt><code><span style="color: #000000">-</span></code></dt>
<dd><span style="color: #000000">instructs “not to” rewrite the URL, as in “<code>...domain.com.* - [F]</code>”. </span></dd>
<dt><code><span style="color: #000000">+</span></code></dt>
<dd><span style="color: #000000">matches one or more of the preceding character. e.g., <code>G+</code> matches one or more G’s, while &#8220;+&#8221; will match one or more characters of any kind. </span></dd>
<dt><code><span style="color: #000000">*</span></code></dt>
<dd><span style="color: #000000">matches zero or more of the preceding character. e.g., use “<code>.*</code>” as a wildcard. </span></dd>
<dt><code><span style="color: #000000">|</span></code></dt>
<dd><span style="color: #000000">declares a logical “or” operator. for example, <code>(x|y)</code> matches <code>x</code> or <code>y</code>. </span></dd>
<dt><code><span style="color: #000000">\</span></code></dt>
<dd><span style="color: #000000">escapes special characters ( <code>^ $ ! . * |</code> ). e.g., use “<code>\.</code>” to indicate/escape a literal dot. </span></dd>
<dt><code><span style="color: #000000">\.</span></code></dt>
<dd><span style="color: #000000">indicates a literal dot (escaped). </span></dd>
<dt><code><span style="color: #000000">/*</span></code></dt>
<dd><span style="color: #000000">zero or more slashes. </span></dd>
<dt><code><span style="color: #000000">.*</span></code></dt>
<dd><span style="color: #000000">zero or more arbitrary characters. </span></dd>
<dt><code><span style="color: #000000">^$</span></code></dt>
<dd><span style="color: #000000">defines an empty string. </span></dd>
<dt><code><span style="color: #000000">^.*$</span></code></dt>
<dd><span style="color: #000000">the standard pattern for matching everything. </span></dd>
<dt><code><span style="color: #000000">[^/.]</span></code></dt>
<dd><span style="color: #000000">defines one character that is neither a slash nor a dot. </span></dd>
<dt><code><span style="color: #000000">[^/.]+</span></code></dt>
<dd><span style="color: #000000">defines any number of characters which contains neither slash nor dot. </span></dd>
<dt><code><span style="color: #000000">http://</span></code></dt>
<dd><span style="color: #000000">this is a literal statement — in this case, the literal character string, “http://”. </span></dd>
<dt><code><span style="color: #000000">^domain.*</span></code></dt>
<dd><span style="color: #000000">defines a string that begins with the term “<code>domain</code>”, which then may be proceeded by any number of any characters. </span></dd>
<dt><code><span style="color: #000000">^domain\.com$</span></code></dt>
<dd><span style="color: #000000">defines the exact string “<code>domain.com</code>”. </span></dd>
<dt><code><span style="color: #000000">-d</span></code></dt>
<dd><span style="color: #000000">tests if string is an existing directory </span></dd>
<dt><code><span style="color: #000000">-f</span></code></dt>
<dd><span style="color: #000000">tests if string is an existing file </span></dd>
<dt><code><span style="color: #000000">-s</span></code></dt>
<dd><span style="color: #000000">tests if file in test string has a non-zero value </span></dd>
</dl>
<h4 id="gen6"><span style="color: #000000">Redirection Header Codes <a href="#top">^</a></span></h4>
<ul style="margin-top: 25px;margin-right: 0px;margin-bottom: 25px;margin-left: 0px;line-height: 18px;padding: 0px"> <span style="color: #000000"></p>
<li>301 &#8211; Moved Permanently</li>
<li>302 &#8211; Moved Temporarily</li>
<li>403 &#8211; Forbidden</li>
<li>404 &#8211; Not Found</li>
<li>410 &#8211; Gone</li>
<p></span></ul>
<h3 id="essentials"><span style="color: #000000">ESSENTIALS [ <a href="#top">^</a> ]</span></h3>
<h4 id="ess1"><span style="color: #000000">Commenting your htaccess Files <a href="#top">^</a></span></h4>
<p><span style="color: #000000">It is an excellent idea to consistenly and logically comment your htaccess files. Any line in an htaccess file that begins with the pound sign ( # ) tells the server to ignore it. Multiple lines require multiple pounds and use letters/numbers/dash/underscore only:</span></p>
<p><code><span style="color: #000000"># this is a comment</span></code><span style="color: #000000"><br />
<code># each line must have its own pound sign</code><br />
<code># use only alphanumeric characters along with dashes - and underscores _</code></span></p>
<h4 id="ess2"><span style="color: #000000">Enable Basic Rewriting <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Certain servers may not have “<code>mod_rewrite</code>” enabled by default. To ensure <code>mod_rewrite</code>(basic rewriting) is enabled throughout your site, add the following line once to your site’s root htaccess file:</span></p>
<p><code><span style="color: #000000"># enable basic rewriting</span></code><span style="color: #000000"><br />
<code>RewriteEngine on</code></span></p>
<h4 id="ess3"><span style="color: #000000">Enable Symbolic Links <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Enable symbolic links (symlinks) by adding the following directive to the target directory’s htaccess file. Note: for the <code>FollowSymLinks</code> directive to function, <code>AllowOverride Options</code>privileges must be enabled from within the server configuration file (<a href="#ess4">see proceeding paragraph for more information</a>):</span></p>
<p><code><span style="color: #000000"># enable symbolic links</span></code><span style="color: #000000"><br />
<code>Options +FollowSymLinks</code></span></p>
<h4 id="ess4"><span style="color: #000000">Enable AllowOverride <a href="#top">^</a></span></h4>
<p><span style="color: #000000">For directives that require <code>AllowOverride</code> in order to function, such as <code>FollowSymLinks</code> (see above paragraph), the following directive must be added to the server configuration file. For performance considerations, it is important to only enable <code>AllowOverride</code> in the specific directory or directories in which it is required. In the following code chunk, we are enabling the<code>AllowOverride</code> privs only in the specified directory (/www/replace/this/with/actual/directory). Refer to <a href="#per1">this section</a> for more information about <code>AllowOverride</code> and performance enhancement:</span></p>
<p><code><span style="color: #000000"># enable allowoverride privileges</span></code><span style="color: #000000"><br />
<code>&lt;Directory /www/replace/this/with/actual/directory&gt;</code><br />
<code>AllowOverride Options</code><br />
<code>&lt;/Directory&gt;</code></span></p>
<h4 id="ess5"><span style="color: #000000">Rename the htaccess File <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Not every system enjoys the extension-only format of htaccess files. Fortunately, you can rename them to whatever you wish, granted the name is valid on your system. Note: This directive must be placed in the server-wide configuration file or it will not work:</span></p>
<p><code><span style="color: #000000"># rename htaccess files</span></code><span style="color: #000000"><br />
<code>AccessFileName ht.access</code></span></p>
<p><span style="color: #000000">Note: If you rename your htaccess files, remember to update any associated configuration settings. For example, if you are protecting your htaccess file via <code>FilesMatch</code>, remember to inform it of the renamed files:</span></p>
<p><code><span style="color: #000000"># protect renamed htaccess files</span></code><span style="color: #000000"><br />
<code>&lt;FilesMatch "^ht\."&gt;</code><br />
<code>Order deny,allow</code><br />
<code>Deny from all</code><br />
<code>&lt;/FilesMatch&gt;</code></span></p>
<h4 id="ess6"><span style="color: #000000">Retain Rules Defined in httpd.conf <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Save yourself time and effort by defining replicate rules for multiple virtual hosts once and only once via your httpd.conf file. Then, simply instruct your target htaccess file(s) to inherit the httpd.conf rules by including this directive:</span></p>
<p><code><span style="color: #000000">RewriteOptions Inherit</span></code></p>
<h3 id="performance"><span style="color: #000000">PERFORMANCE [ <a href="#top">^</a> ]</span></h3>
<h4 id="per1"><span style="color: #000000">Improving Performance via AllowOverride <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Limit the extent to which htaccess files decrease performance by enabling <code>AllowOverride</code> only in required directories. For example, if <code>AllowOverride</code> is enabled throughout the entire site, the server must dig through every directory, searching for htaccess files that may not even exist. To prevent this, we disable the <code>AllowOverride</code> in the site’s root htaccess file and then enable<code>AllowOverride</code> only in required directories via the server config file (refer to <a href="#ess4">this section</a> for more information). Note: if you do not have access to your site’s server config file and also need <code>AllowOverride</code> privileges, do not use this directive:</span></p>
<p><code><span style="color: #000000"># increase performance by disabling allowoverride</span></code><span style="color: #000000"><br />
<code>AllowOverride None</code></span></p>
<h4 id="per2"><span style="color: #000000">Improving Performance by Passing the Character Set <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Prevent certain 500 error displays by passing the default character set parameter before you get there. Note: replace the “utf-8” below with the charset that your site is using:</span></p>
<p><code><span style="color: #000000"># pass the default character set</span></code><span style="color: #000000"><br />
<code>AddDefaultCharset utf-8</code></span></p>
<h4 id="per3"><span style="color: #000000">Improving Performance by Preserving Bandwidth <a href="#top">^</a></span></h4>
<p><span style="color: #000000">To increase performance on PHP enabled servers, add the following directive:</span></p>
<p><code><span style="color: #000000"># preserve bandwidth for PHP enabled servers</span></code><span style="color: #000000"><br />
<code>&lt;ifmodule mod_php4.c&gt;</code><br />
<code>php_value zlib.output_compression 16386</code><br />
<code>&lt;/ifmodule&gt;</code></span></p>
<h4 id="per4"><span style="color: #000000">Disable the Server Signature <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Here we are disabling the digital signature that would otherwise identify the server:</span></p>
<p><code><span style="color: #000000"># disable the server signature</span></code><span style="color: #000000"><br />
<code>ServerSignature Off</code></span></p>
<h4 id="per5"><span style="color: #000000">Set the Server Timezone <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Here we are instructing the server to synchronize chronologically according to the time zone of some specified state:</span></p>
<p><code><span style="color: #000000"># set the server timezone</span></code><span style="color: #000000"><br />
<code>SetEnv TZ America/Washington</code></span></p>
<h4 id="per6"><span style="color: #000000">Set the Email Address for the Server Administrator <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Here we are specifying the default email address for the server administrator:</span></p>
<p><code><span style="color: #000000"># set the server administrator email</span></code><span style="color: #000000"><br />
<code>SetEnv SERVER_ADMIN default@domain.com</code></span></p>
<h4 id="per7"><span style="color: #000000">Improve Site Transfer Speed by Enabling File Caching <a href="#top">^</a></span></h4>
<p><span style="color: #000000">The htaccess genius over at askapache.com explains how to dramatically improve your site’s transfer speed by enabling file caching <sup>3</sup>. Using time in seconds* to indicate the duration for which cached content should endure, we may generalize the htaccess rules as such (edit file types and time value to suit your needs):</span></p>
<p><code><span style="color: #000000"># cache images and flash content for one month</span></code><span style="color: #000000"><br />
<code>&lt;FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf)$"&gt;</code><br />
<code>Header set Cache-Control "max-age=2592000"</code><br />
<code>&lt;/FilesMatch&gt;</code></span></p>
<p><code><span style="color: #000000"># cache text, css, and javascript files for one week</span></code><span style="color: #000000"><br />
<code>&lt;FilesMatch ".(js|css|pdf|txt)$"&gt;</code><br />
<code>Header set Cache-Control "max-age=604800"</code><br />
<code>&lt;/FilesMatch&gt;</code></span></p>
<p><code><span style="color: #000000"># cache html and htm files for one day</span></code><span style="color: #000000"><br />
<code>&lt;FilesMatch ".(html|htm)$"&gt;</code><br />
<code>Header set Cache-Control "max-age=43200"</code><br />
<code>&lt;/FilesMatch&gt;</code></span></p>
<p><code><span style="color: #000000"># implement minimal caching during site development</span></code><span style="color: #000000"><br />
<code>&lt;FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|js|css|pdf|swf|html|htm|txt)$"&gt;</code><br />
<code>Header set Cache-Control "max-age=5"</code><br />
<code>&lt;/FilesMatch&gt;</code></span></p>
<p><code><span style="color: #000000"># explicitly disable caching for scripts and other dynamic files</span></code><span style="color: #000000"><br />
<code>&lt;FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"&gt;</code><br />
<code>Header unset Cache-Control</code><br />
<code>&lt;/FilesMatch&gt;</code></span></p>
<p><code><span style="color: #000000"># alternate method for file caching</span></code><span style="color: #000000"><br />
<code>ExpiresActive On</code><br />
<code>ExpiresDefault A604800 # 1 week</code><br />
<code>ExpiresByType image/x-icon A2419200 # 1 month</code><br />
<code>ExpiresByType application/x-javascript A2419200 # 1 month</code><br />
<code>ExpiresByType text/css A2419200 # 1 month</code><br />
<code>ExpiresByType text/html A300 # 5 minutes</code><br />
<code># disable caching for scripts and other dynamic files</code><br />
<code>&lt;FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"&gt;</code><br />
<code>ExpiresActive Off</code><br />
<code>&lt;/FilesMatch&gt;</code></span></p>
<ul style="margin-top: 25px;margin-right: 0px;margin-bottom: 25px;margin-left: 0px;line-height: 18px;padding: 0px"> <span style="color: #000000"></p>
<li>* <strong>Convert common time intervals into seconds:</strong></li>
<li>300 = 5 minutes</li>
<li>2700 = 45 minutes</li>
<li>3600 = 1 hour</li>
<li>54000 = 15 hours</li>
<li>86400 = 1 day</li>
<li>518400 = 6 days</li>
<li>604800 = 1 week</li>
<li>1814400 = 3 weeks</li>
<li>2419200 = 1 month</li>
<li>26611200 = 11 months</li>
<li>29030400 = 1 year = never expires</li>
<p></span></ul>
<h4 id="per8"><span style="color: #000000">Set the default language and character set <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Here is an easy way to set the default language for pages served by your server (edit the language to suit your needs):</span></p>
<p><code><span style="color: #000000"># set the default language</span></code><span style="color: #000000"><br />
<code>DefaultLanguage en-US</code></span></p>
<p><span style="color: #000000">Likewise, here we are setting the default character set (edit to taste):</span></p>
<p><code><span style="color: #000000"># set the default character set</span></code><span style="color: #000000"><br />
<code>AddDefaultCharset UTF-8</code></span></p>
<h4 id="per9"><span style="color: #000000">Declare specific/additional MIME types <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000"># add various mime types</span></code><span style="color: #000000"><br />
<code>AddType application/x-shockwave-flash .swf</code><br />
<code>AddType video/x-flv .flv</code><br />
<code>AddType image/x-icon .ico</code></span></p>
<h4 id="per10"><span style="color: #000000">Send character set and other headers without meta tags <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000"># send the language tag and default character set</span></code><span style="color: #000000"><br />
<code># AddType 'text/html; charset=UTF-8' html</code><br />
<code>AddDefaultCharset UTF-8</code><br />
<code>DefaultLanguage en-US</code></span></p>
<h4 id="per11"><span style="color: #000000">Limit server request methods to GET and PUT <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000"># limit server request methods to GET and PUT</span></code><span style="color: #000000"><br />
<code>Options -ExecCGI -Indexes -All</code><br />
<code>RewriteEngine on</code><br />
<code>RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS|HEAD) RewriteRule .* - [F]</code></span></p>
<h4 id="per12"><span style="color: #000000">Selectively process files according to server request method <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000"># process files according to server request method</span></code><span style="color: #000000"><br />
<code>Script PUT /cgi-bin/upload.cgi</code><br />
<code>Script GET /cgi-bin/download.cgi</code></span></p>
<h4 id="per13"><span style="color: #000000">Execute various file types through a cgi script <a href="#top">^</a></span></h4>
<p><span style="color: #000000">For those special occasions where certain file types need to be processed with some specific cgi script, let em know who sent ya:</span></p>
<p><code><span style="color: #000000"># execute all png files via png-script.cgi</span></code><span style="color: #000000"><br />
<code>Action image/png /cgi-bin/png-script.cgi</code></span></p>
<h3 id="security"><span style="color: #000000">SECURITY [ <a href="#top">^</a> ]</span></h3>
<h4 id="sec1"><span style="color: #000000">Prevent Access to .htaccess <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Add the following code block to your htaccess file to add an extra layer of security. Any attempts to access the htaccess file will result in a 403 error message. Of course, your first layer of defense to protect htaccess files involves setting htaccess file permissions via CHMOD to 644:</span></p>
<p><code><span style="color: #000000"># secure htaccess file</span></code><span style="color: #000000"><br />
<code>&lt;Files .</code><code>htaccess&gt;</code><br />
<code>order allow,deny</code><br />
<code>deny from all</code><br />
<code>&lt;/Files&gt;</code></span></p>
<h4 id="sec2"><span style="color: #000000">Prevent Acess to a Specific File <a href="#top">^</a></span></h4>
<p><span style="color: #000000">To restrict access to a specific file, add the following code block and edit the file name, “secretfile.jpg”, with the name of the file that you wish to protect:</span></p>
<p><code><span style="color: #000000"># prevent viewing of a specific file</span></code><span style="color: #000000"><br />
<code>&lt;files secretfile.jpg&gt;</code><br />
<code>order allow,deny</code><br />
<code>deny from all</code><br />
<code>&lt;/files&gt;</code></span></p>
<h4 id="sec2a"><span style="color: #000000">Prevent acess to multiple file types <a href="#top">^</a></span></h4>
<p><span style="color: #000000">To restrict access to a variety of file types, add the following code block and edit the file types within parentheses to match the extensions of any files that you wish to protect:</span></p>
<p><code><span style="color: #000000">&lt;FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$"&gt;</span></code><span style="color: #000000"><br />
<code>Order Allow,Deny</code><br />
<code>Deny from all</code><br />
<code>&lt;/FilesMatch&gt;</code></span></p>
<h4 id="sec3"><span style="color: #000000">Prevent Unauthorized Directory Browsing <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Prevent unauthorized directory browsing by instructing the server to serve a “xxx Forbidden &#8211; Authorization Required” message for any request to view a directory. For example, if your site is missing it’s default index page, everything within the root of your site will be accessible to all visitors. To prevent this, include the following htaccess rule:</span></p>
<p><code><span style="color: #000000"># disable directory browsing</span></code><span style="color: #000000"><br />
<code>Options All -Indexes</code></span></p>
<p><span style="color: #000000">Conversely, to enable directory browsing, use the following directive:</span></p>
<p><code><span style="color: #000000"># enable directory browsing</span></code><span style="color: #000000"><br />
<code>Options All +Indexes</code></span></p>
<p><span style="color: #000000">Likewise, this rule will prevent the server from listing directory contents:</span></p>
<p><code><span style="color: #000000"># prevent folder listing</span></code><span style="color: #000000"><br />
<code>IndexIgnore *</code></span></p>
<p><span style="color: #000000">And, finally, the <code>IndexIgnore</code> directive may be used to prevent the display of select file types:</span></p>
<p><code><span style="color: #000000"># prevent display of select file types</span></code><span style="color: #000000"><br />
<code>IndexIgnore *.wmv *.mp4 *.avi *.etc</code></span></p>
<h4 id="sec4"><span style="color: #000000">Change Default Index Page <a href="#top">^</a></span></h4>
<p><span style="color: #000000">This rule tells the server to search for and serve “business.html” as the default directory index. This rule must exist in the htaccess files of the root directory for which you wish to replace the default index file (e.g., “index.html”):</span></p>
<p><code><span style="color: #000000"># serve alternate default index page</span></code><span style="color: #000000"><br />
<code>DirectoryIndex business.html</code></span></p>
<p><span style="color: #000000">This rule is similar, only in this case, the server will scan the root directory for the listed files and serve the first match it encounters. The list is read from left to right:</span></p>
<p><code><span style="color: #000000"># serve first available alternate default index page from series</span></code><span style="color: #000000"><br />
<code>DirectoryIndex filename.html index.cgi index.pl default.htm</code></span></p>
<h4 id="sec5"><span style="color: #000000">Disguise Script Extensions <a href="#top">^</a></span></h4>
<p><span style="color: #000000">To enhance security, disguise scripting languages by replacing actual script extensions with dummy extensions of your choosing. For example, to change the “<code>.foo</code>” extension to “<code>.php</code>”, add the following line to your htaccess file and rename all affected files accordingly:</span></p>
<p><code><span style="color: #000000"># serve foo files as php files</span></code><span style="color: #000000"><br />
<code>AddType application/x-httpd-php .foo</code></span></p>
<p><code><span style="color: #000000"># serve foo files as cgi files</span></code><span style="color: #000000"><br />
<code>AddType application/x-httpd-cgi .foo</code></span></p>
<h4 id="sec6"><span style="color: #000000">Limit Access to the Local Area Network (LAN) <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000"># limit access to local area network</span></code><span style="color: #000000"><br />
<code>&lt;Limit GET POST PUT&gt;</code><br />
<code>order deny,allow</code><br />
<code>deny from all</code><br />
<code>allow from 192.168.0.0/33</code><br />
<code>&lt;/Limit&gt;</code></span></p>
<h4 id="sec7"><span style="color: #000000">Secure Directories by IP Address and/or Domain <a href="#top">^</a></span></h4>
<p><span style="color: #000000">In the following example, all IP addresses are <em>allowed access</em> except for 12.345.67.890 and domain.com:</span></p>
<p><code><span style="color: #000000"># allow all except those indicated here</span></code><span style="color: #000000"><br />
<code>&lt;Limit GET POST PUT&gt;</code><br />
<code>order allow,deny</code><br />
<code>allow from all</code><br />
<code>deny from 12.345.67.890</code><br />
<code>deny from .*domain\.com.*</code><br />
<code>&lt;/Limit&gt;</code></span></p>
<p><span style="color: #000000">In the following example, all IP addresses are <em>denied access</em> except for 12.345.67.890 and domain.com:</span></p>
<p><code><span style="color: #000000"># deny all except those indicated here</span></code><span style="color: #000000"><br />
<code>&lt;Limit GET POST PUT&gt;</code><br />
<code>order deny,allow</code><br />
<code>deny from all</code><br />
<code>allow from 12.345.67.890</code><br />
<code>allow from .*domain\.com.*</code><br />
<code>&lt;/Limit&gt;</code></span></p>
<p><span style="color: #000000">This is how to block unwanted visitors based on the referring domain. You can also save bandwidth by <a href="#types">blocking specific file types</a> — such as <code>.jpg, .zip, .mp3, .mpg</code> — from specific referring domains. Simply replace “scumbag” and “wormhole” with the offending domains of your choice:</span></p>
<p><code><span style="color: #000000"># block visitors referred from indicated domains</span></code><span style="color: #000000"><br />
<code>&lt;IfModule mod_rewrite.c&gt;</code><br />
<code>RewriteEngine on</code><br />
<code>RewriteCond %{HTTP_REFERER} scumbag\.com [NC,OR]</code><br />
<code>RewriteCond %{HTTP_REFERER} wormhole\.com [NC,OR]</code><br />
<code>RewriteRule .* - [F]</code><br />
<code>&lt;/ifModule&gt;</code></span></p>
<h4 id="sec7a"><span style="color: #000000">Prevent or allow domain access for a specified range of IP addresses <a href="#top">^</a></span></h4>
<p><span style="color: #000000">There are several effective ways to block a range of IP addresses via htaccess. This first method blocks an IP range specified by their <acronym title="Classless Inter-Domain Routing">CIDR</acronym> (Classless Inter-Domain Routing) number. This method is useful for blocking mega-spammers such as RIPE, Optinet, and others. If, for example, you find yourself adding line after line of Apache <code>deny</code> directives for addresses beginning with the same first few numbers, choose one of them and try a <a title="whois lookup" href="http://www.whois.net/">whois lookup</a>. Listed within the whois results will be the CIDR value representing every IP address associated with that particular network. Thus, blocking via CIDR is an effective way to eloquently prevent all IP instances of the offender from accessing your site. Here is a generalized example for blocking by CIDR (edit values to suit your needs):</span></p>
<p><code><span style="color: #000000"># block IP range by CIDR number</span></code><span style="color: #000000"><br />
<code>&lt;Limit GET POST PUT&gt;</code><br />
<code>order allow,deny</code><br />
<code>allow from all</code><br />
<code>deny from 10.1.0.0/16</code><br />
<code>deny from 80.0.0/8</code><br />
<code>&lt;/Limit&gt;</code></span></p>
<p><span style="color: #000000">Likewise, to allow an IP range by CIDR number:</span></p>
<p><code><span style="color: #000000"># allow IP range by CIDR number</span></code><span style="color: #000000"><br />
<code>&lt;Limit GET POST PUT&gt;</code><br />
<code>order deny,allow</code><br />
<code>deny from all</code><br />
<code>allow from 10.1.0.0/16</code><br />
<code>allow from 80.0.0/8</code><br />
<code>&lt;/Limit&gt;</code></span></p>
<p><span style="color: #000000">Another effective way to block an entire range of IP addresses involves truncating digits until the desired range is represented. As an IP address is read from left to right, its value represents an increasingly specific address. For example, a fictitious IP address of 99.88.77.66 would designate some uniquely specific IP address. Now, if we remove the last two digits (66) from the address, it would represent <em>any</em> address beginning with the remaining digits. That is, 99.88.77 represents 99.88.77.1, 99.88.77.2, … 99.88.77.99, …etc. Likewise, if we then remove another pair of digits from the address, its range suddenly widens to represent every IP address 99.88.x.y, where x and y represent any valid set of IP address values (i.e., you would block 256*256 = 65,536 unique IP addresses). Following this logic, it is possible to block an entire range of IP addresses to varying degrees of specificity. Here are few generalized lines exemplifying proper htaccess syntax (edit values to suit your needs):</span></p>
<p><code><span style="color: #000000"># block IP range by address truncation</span></code><span style="color: #000000"><br />
<code>&lt;Limit GET POST PUT&gt;</code><br />
<code>order allow,deny</code><br />
<code>allow from all</code><br />
<code>deny from 99.88.77.66</code><br />
<code>deny from 99.88.77.*</code><br />
<code>deny from 99.88.*.*</code><br />
<code>deny from 99.*.*.*</code><br />
<code>&lt;/Limit&gt;</code></span></p>
<p><span style="color: #000000">Likewise, to allow an IP range by address truncation:</span></p>
<p><code><span style="color: #000000"># allow IP range by address truncation</span></code><span style="color: #000000"><br />
<code>&lt;Limit GET POST PUT&gt;</code><br />
<code>order deny,allow</code><br />
<code>deny from all</code><br />
<code>allow from 99.88.77.66</code><br />
<code>allow from 99.88.77.*</code><br />
<code>allow from 99.88.*.*</code><br />
<code>allow from 99.*.*.*</code><br />
<code>&lt;/Limit&gt;</code></span></p>
<h4 id="sec7b"><span style="color: #000000">Block or allow multiple IP addresses on one line <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Save a little space by blocking multiple IP addresses or ranges on one line. Here are few examples (edit values to suit your needs):</span></p>
<p><code><span style="color: #000000"># block two unique IP addresses</span></code><span style="color: #000000"><br />
<code>deny from 99.88.77.66 11.22.33.44</code><br />
<code># block three ranges of IP addresses</code><br />
<code>deny from 99.88 99.88.77 11.22.33</code></span></p>
<p><span style="color: #000000">Likewise, to allow multiple IP addresses or ranges on one line:</span></p>
<p><code><span style="color: #000000"># allow two unique IP addresses</span></code><span style="color: #000000"><br />
<code>allow from 99.88.77.66 11.22.33.44</code><br />
<code># allow three ranges of IP addresses</code><br />
<code>allow from 99.88 99.88.77 11.22.33</code></span></p>
<h4 id="sec7c"><span style="color: #000000">Miscellaneous rules for blocking and allowing IP addresses <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Here are few miscellaneous rules for blocking various types of IP addresses. These rules may be adapted to <em>allow</em> the specified IP values by simply changing the <code>deny</code> directive to <code>allow</code>. Check ’em out (edit values to suit your needs):</span></p>
<p><code><span style="color: #000000"># block a partial domain via network/netmask values</span></code><span style="color: #000000"><br />
<code>deny from 99.1.0.0/255.255.0.0</code></span></p>
<p><code><span style="color: #000000"># block a single domain</span></code><span style="color: #000000"><br />
<code>deny from 99.88.77.66</code></span></p>
<p><code><span style="color: #000000"># block domain.com but allow sub.domain.com</span></code><span style="color: #000000"><br />
<code>order deny,allow</code><br />
<code>deny from domain.com</code><br />
<code>allow from sub.domain.com</code></span></p>
<h4 id="sec8"><span style="color: #000000">Stop Hotlinking, Serve Alternate Content <a href="#top">^</a></span></h4>
<p><span style="color: #000000">To serve ‘em some unexpected alternate content when hotlinking is detected, employ the following code, which will protect all files of the types included in the last line (add more types as needed). Remember to replace the dummy path names with real ones. Also, the name of the nasty image being served in this case is “eatme.jpe”, as indicated in the line containing the<code>RewriteRule</code>. Please advise that this method will also block services such as FeedBurner from accessing your images.</span></p>
<p><code><span style="color: #000000"># stop hotlinking and serve alternate content</span></code><span style="color: #000000"><br />
<code>&lt;IfModule mod_rewrite.c&gt;</code><br />
<code>RewriteEngine on</code><br />
<code>RewriteCond %{HTTP_REFERER} !^$</code><br />
<code>RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.com/.*$ [NC]</code><br />
<code>RewriteRule .*\.(gif|jpg)$ http://www.domain.com/eatme.jpe [R,NC,L]</code><br />
<code>&lt;/ifModule&gt;</code></span></p>
<p><span style="color: #000000">Note: To deliver a standard (or custom, if configured) error page instead of some nasty image of the Fonz, replace the line containing the <code>RewriteRule</code> in the above htaccess directive with the following line:</span></p>
<p><code><span style="color: #000000"># serve a standard 403 forbidden error page</span></code><span style="color: #000000"><br />
<code>RewriteRule .*\.(gif|jpg)$ - [F,L]</code></span></p>
<p><span style="color: #000000">Note: To grant linking permission to a site other than yours, insert this code block after the line containing the “domain.com” string. Remember to replace “goodsite.com” with the actual site domain:</span></p>
<p><code><span style="color: #000000"># allow linking from the following site</span></code><span style="color: #000000"><br />
<code>RewriteCond %{HTTP_REFERER} !^http://(www\.)?goodsite\.com/.*$ [NC]</code></span></p>
<h4 id="sec9"><span style="color: #000000">Block Evil Robots, Site Rippers, and Offline Browsers <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Eliminate some of the unwanted scum from your userspace by injecting this handy block of code. After such, any listed agents will be denied access and receive an error message instead. Please advise that there are much more comprehensive lists available this example has been truncated for business purposes. Note: DO NOT include the “[OR]” on the very last <code>RewriteCond</code>or your server will crash, delivering “500 Errors” to all page requests.</span></p>
<p><code><span style="color: #000000"># deny access to evil robots site rippers offline browsers and other nasty scum</span></code><span style="color: #000000"><br />
<code>RewriteBase /</code><br />
<code>RewriteCond %{HTTP_USER_AGENT} ^Anarchie [OR]</code><br />
<code>RewriteCond %{HTTP_USER_AGENT} ^ASPSeek [OR]</code><br />
<code>RewriteCond %{HTTP_USER_AGENT} ^attach [OR]</code><br />
<code>RewriteCond %{HTTP_USER_AGENT} ^autoemailspider [OR]</code><br />
<code>RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]</code><br />
<code>RewriteCond %{HTTP_USER_AGENT} ^Xenu [OR]</code><br />
<code>RewriteCond %{HTTP_USER_AGENT} ^Zeus.*Webster [OR]</code><br />
<code>RewriteCond %{HTTP_USER_AGENT} ^Zeus</code><br />
<code>RewriteRule ^.* - [F,L]</code></span></p>
<p><span style="color: #000000">Or, instead of delivering a friendly error message (i.e., the last line), send these bad boys to the hellish website of your choice by replacing the <code>RewriteRule</code> in the last line with one of the following two examples:</span></p>
<p><code><span style="color: #000000"># send em to a hellish website of your choice</span></code><span style="color: #000000"><br />
<code>RewriteRule ^.*$ http://www.hellish-website.com [R,L]</code></span></p>
<p><span style="color: #000000">Or, to send em to a virtual blackhole of fake email addresses:</span></p>
<p><code><span style="color: #000000"># send em to a virtual blackhole of fake email addresses</span></code><span style="color: #000000"><br />
<code>RewriteRule ^.*$ http://english-61925045732.spampoison.com [R,L]</code></span></p>
<p><span style="color: #000000">You may also include specific referrers to your blacklist by using <code>HTTP_REFERER</code>. Here, we use the infamously scummy domain, “iaea.org” as our blocked example, and we use “yourdomain” as your domain (the domain to which you are blocking iaea.org):</span></p>
<p><code><span style="color: #000000">RewriteCond %{HTTP_REFERER} ^http://www.iaea.org$</span></code><span style="color: #000000"><br />
<code>RewriteRule !^http://[^/.]\.yourdomain\.com.* - [F,L]</code></span></p>
<h4 id="sec10"><span style="color: #000000">More Stupid Blocking Tricks <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Note: Although these redirect techniques are aimed at blocking and redirecting nasty scumsites, the directives may also be employed for friendly redirection purposes:</span></p>
<p><code><span style="color: #000000"># redirect any request for anything from spamsite to differentspamsite</span></code><span style="color: #000000"><br />
<code>RewriteCond %{HTTP_REFERER} ^http://.*spamsite.*$ [NC]</code><br />
<code>RewriteRule .* http://www.differentspamsite.com [R]</code></span></p>
<p><code><span style="color: #000000"># redirect all requests from spamsite to an image of something at differentspamsite</span></code><span style="color: #000000"><br />
<code>RewriteCond %{HTTP_REFERER} ^http://.*spamsite.*$ [NC]</code><br />
<code>RewriteRule .* http://www.differentspamsite/something.jpg [R]</code></span></p>
<p><code><span style="color: #000000"># redirect traffic from a certain address or range of addresses to another site</span></code><span style="color: #000000"><br />
<code>RewriteCond %{REMOTE_ADDR} 192.168.10.*</code><br />
<code>RewriteRule .* http://www.differentspamsite.com/index.html [R]</code></span></p>
<h4 id="sec11"><span style="color: #000000">Even More Scum-Blocking Tricks <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Here is a step-by-step series of code blocks that should equip you with enough knowledge to block any/all necessary entities. Read through the set of code blocks, observe the patterns, and then copy, combine and customize to suit your specific scum-blocking needs:</span></p>
<p><code><span style="color: #000000"># set variables for user agents and referers and ip addresses</span></code><span style="color: #000000"><br />
<code>SetEnvIfNoCase User-Agent ".*(user-agent-you-want-to-block|php/perl).*" BlockedAgent</code><br />
<code>SetEnvIfNoCase Referer ".*(block-this-referrer|and-this-referrer|and-this-referrer).*" BlockedReferer</code><br />
<code>SetEnvIfNoCase REMOTE_ADDR ".*(666.666.66.0|22.22.22.222|999.999.99.999).*" BlockedAddress</code></span></p>
<p><code><span style="color: #000000"># set variable for any class B network coming from a given netblock</span></code><span style="color: #000000"><br />
<code>SetEnvIfNoCase REMOTE_ADDR "66.154.*" BlockedAddress</code></span></p>
<p><code><span style="color: #000000"># set variable for two class B networks 198.25.0.0 and 198.26.0.0</span></code><span style="color: #000000"><br />
<code>SetEnvIfNoCase REMOTE_ADDR "198.2(5|6)\..*" BlockedAddress</code></span></p>
<p><code><span style="color: #000000"># deny any matches from above and send a 403 denied</span></code><span style="color: #000000"><br />
<code>&lt;Limit GET POST PUT&gt;</code><br />
<code>order deny,allow</code><br />
<code>deny from env=BlockedAgent</code><br />
<code>deny from env=BlockedReferer</code><br />
<code>deny from env=BlockedAddress</code><br />
<code>allow from all</code><br />
<code>&lt;/Limit&gt;</code></span></p>
<h4 id="sec12"><span style="color: #000000">Password-Protect Directories <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Here is an excellent online tool for generating the necessary elements for a password-protected directory:</span></p>
<p><code><span style="color: #000000"># password protect directories</span></code><span style="color: #000000"><br />
<a title="htaccess Password Generator" rel="nofollow" href="http://www.thejackol.com/scripts/htpasswdgen.php">htaccess Password Generator</a></span></p>
<h4 id="sec12a"><span style="color: #000000">Password-protect Files, Directories, and More.. <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Secure site contents by requiring user authentication for specified files and/or directories. The first example shows how to password-protect any single file type that is present beneath the directory which houses the htaccess rule. The second rule employs the <code>FilesMatch</code> directive to protect any/all files which match any of the specified character strings. The third rule demonstrates how to protect an entire directory. The fourth set of rules provides password-protection for all IP’s except those specified. Remember to edit these rules according to your specific needs.</span></p>
<p><code><span style="color: #000000"># password-protect single file</span></code><span style="color: #000000"><br />
<code>&lt;Files secure.php&gt;</code><br />
<code>AuthType Basic</code><br />
<code>AuthName "Prompt"</code><br />
<code>AuthUserFile /home/path/.</code><code>htpasswd</code><br />
<code>Require valid-user</code><br />
<code>&lt;/Files&gt;</code></span></p>
<p><code><span style="color: #000000"># password-protect multiple files</span></code><span style="color: #000000"><br />
<code>&lt;FilesMatch "^(execute|index|secure|insanity|biscuit)*$"&gt;</code><br />
<code>AuthType basic</code><br />
<code>AuthName "Development"</code><br />
<code>AuthUserFile /home/path/.</code><code>htpasswd</code><br />
<code>Require valid-user</code><br />
<code>&lt;/FilesMatch&gt;</code></span></p>
<p><code><span style="color: #000000"># password-protect the directory in which this htaccess rule resides</span></code><span style="color: #000000"><br />
<code>AuthType basic</code><br />
<code>AuthName "This directory is protected"</code><br />
<code>AuthUserFile /home/path/.</code><code>htpasswd</code><br />
<code>AuthGroupFile /dev/null</code><br />
<code>Require valid-user</code></span></p>
<p><code><span style="color: #000000"># password-protect directory for every IP except the one specified</span></code><span style="color: #000000"><br />
<code># place in htaccess file of a directory to protect that entire directory</code><br />
<code>AuthType Basic</code><br />
<code>AuthName "Personal"</code><br />
<code>AuthUserFile /home/path/.</code><code>htpasswd</code><br />
<code>Require valid-user</code><br />
<code>Allow from 99.88.77.66</code><br />
<code>Satisfy Any</code></span></p>
<h4 id="sec13"><span style="color: #000000">Require SSL (Secure Sockets Layer) <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Here is an excellent method for requiring SSL (via askapache.com <sup>3</sup>):</span></p>
<p><code><span style="color: #000000"># require SSL</span></code><span style="color: #000000"><br />
<code>SSLOptions +StrictRequire</code><br />
<code>SSLRequireSSL</code><br />
<code>SSLRequire %{HTTP_HOST} eq "domain.tld"</code><br />
<code>ErrorDocument 403 https://domain.tld</code></span></p>
<p><code><span style="color: #000000"># require SSL without mod_ssl</span></code><span style="color: #000000"><br />
<code>RewriteCond %{HTTPS} !=on [NC]</code><br />
<code>RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]</code></span></p>
<h4 id="sec14"><span style="color: #000000">Automatically CHMOD Various File Types <a href="#top">^</a></span></h4>
<p><span style="color: #000000">This method is great for ensuring the CHMOD settings for various file types. Employ the following rules in the root htaccess file to affect <em>all</em> specified file types, or place in a specific directory to affect only those files (edit file types according to your needs):</span></p>
<p><code><span style="color: #000000"># ensure CHMOD settings for specified file types</span></code><span style="color: #000000"><br />
<code># remember to never set CHMOD 777 unless you know what you are doing</code><br />
<code># files requiring write access should use CHMOD 766 rather than 777</code><br />
<code># keep specific file types private by setting their CHMOD to 400</code><br />
<code>chmod .</code><code>htpasswd files 640</code><br />
<code>chmod .</code><code>htaccess files 644</code><br />
<code>chmod php files 600</code></span></p>
<h4 id="sec15"><span style="color: #000000">Disguise all file extensions <a href="#top">^</a></span></h4>
<p><span style="color: #000000">This method will disguise all file types (i.e., any file extension) and present them as .<code>php</code> files (or whichever extension you choose):</span></p>
<p><code><span style="color: #000000"># diguise all file extensions as php</span></code><span style="color: #000000"><br />
<code>ForceType application/x-httpd-php</code></span></p>
<h4 id="sec16"><span style="color: #000000">Protect against denial-of-service (DOS) attacks by limiting file upload size <a href="#top">^</a></span></h4>
<p><span style="color: #000000">One method to help protect your server against DOS attacks involves limiting the maximum allowable size for file uploads. Here, we are limiting file upload size to 10240000 bytes, which is equivalent to around 10 megabytes. For this rule, file sizes are expressed in bytes. Check<a title="File Size Conversion Table" rel="nofollow" href="http://www.webopedia.com/quick_ref/FileSizeConversionTable.asp">here</a> for help with various file size conversions. Note: this code is only useful if you actually allow users to upload files to your site.</span></p>
<p><code><span style="color: #000000"># protect against DOS attacks by limiting file upload size</span></code><span style="color: #000000"><br />
<code>LimitRequestBody 10240000</code></span></p>
<h4 id="sec17"><span style="color: #000000">Secure directories by disabling execution of scripts <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Prevent malicious brainiacs from actively scripting secure directories by adding the following rules to the representative htaccess file (edit file types to suit your needs):</span></p>
<p><code><span style="color: #000000"># secure directory by disabling script execution</span></code><span style="color: #000000"><br />
<code>AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi</code><br />
<code>Options -ExecCGI</code></span></p>
<h3 id="usability"><span style="color: #000000">USABILITY TRICKS [ <a href="#top">^</a> ]</span></h3>
<h4 id="usa1"><span style="color: #000000">Minimize CSS Image Flicker in IE6 <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Add the following htaccess rules to minimize or even eliminate CSS background-image “flickering” in MSIE6:</span></p>
<p><code><span style="color: #000000"># minimize image flicker in IE6</span></code><span style="color: #000000"><br />
<code>ExpiresActive On</code><br />
<code>ExpiresByType image/gif A2592000</code><br />
<code>ExpiresByType image/jpg A2592000</code><br />
<code>ExpiresByType image/png A2592000</code></span></p>
<h4 id="usa2"><span style="color: #000000">Deploy Custom Error Pages <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Replicate the following patterns to serve your own set of custom error pages. Simply replace the “<code>/errors/###.html</code>” with the correct path and file name. Also change the “###” preceding the path to summon pages for other errors. Note: your custom error pages must be larger than 512 bytes in size or they will be completely ignored by Internet Explorer:</span></p>
<p><code><span style="color: #000000"># serve custom error pages</span></code><span style="color: #000000"><br />
<code>ErrorDocument 400 /errors/400.html</code><br />
<code>ErrorDocument 401 /errors/401.html</code><br />
<code>ErrorDocument 403 /errors/403.html</code><br />
<code>ErrorDocument 404 /errors/404.html</code><br />
<code>ErrorDocument 500 /errors/500.html</code></span></p>
<h4 id="usa2a"><span style="color: #000000">Provide a Universal Error Document <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000"># provide a universal error document</span></code><span style="color: #000000"><br />
<code>RewriteCond %{REQUEST_FILENAME} !-f</code><br />
<code>RewriteCond %{REQUEST_FILENAME} !-d</code><br />
<code>RewriteRule ^.*$ /dir/error.php [L]</code></span></p>
<h4 id="usa3"><span style="color: #000000">Employ Basic URL Spelling Check <a href="#top">^</a></span></h4>
<p><span style="color: #000000">This bit of voodoo will auto-correct simple spelling errors in the URL:</span></p>
<p><code><span style="color: #000000"># automatically corect simple speling erors</span></code><span style="color: #000000"><br />
<code>&lt;IfModule mod_speling.c&gt;</code><br />
<code>CheckSpelling On</code><br />
<code>&lt;/IfModule&gt;</code></span></p>
<h4 id="usa4"><span style="color: #000000">Instruct browser to download multimedia files rather than display them <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Here is a useful method for delivering multimedia file downloads to your users. Typically, browsers will attempt to play or stream such files when direct links are clicked. With this method, provide a link to a multimedia file and a dialogue box will provide users the choice of saving the file or opening it. Here are a few htaccess rules demonstrating the technique (edit file types according to your specific needs):</span></p>
<p><code><span style="color: #000000"># instruct browser to download multimedia files</span></code><span style="color: #000000"><br />
<code>AddType application/octet-stream .avi</code><br />
<code>AddType application/octet-stream .mpg</code><br />
<code>AddType application/octet-stream .wmv</code><br />
<code>AddType application/octet-stream .mp3</code></span></p>
<h4 id="usa5"><span style="color: #000000">Instruct server to display source code for dynamic file types <a href="#top">^</a></span></h4>
<p><span style="color: #000000">There are many situations where site owners may wish to display the contents of a dynamic file rather than executing it as a script. To exercise this useful technique, create a directory in which to place dynamic files that should be displayed rather than executed, and add the following line of code to the htaccess file belonging to that directory. This method is known to work for <code>.pl</code>,<code>.py</code>, and <code>.cgi</code> file-types. Here it is:</span></p>
<p><code><span style="color: #000000">RemoveHandler cgi-script .pl .py .cgi</span></code></p>
<h4 id="usa6"><span style="color: #000000">Redirect visitors to a temporary site during site development <a href="#top">^</a></span></h4>
<p><span style="color: #000000">During web development, maintenance, or repair, send your visitors to an alternate site while retaining full access for yourself. This is a very useful technique for preventing visitor confusion or dismay during those awkward, web-development moments. Here are the generalized htaccess rules to do it (edit values to suit your needs):</span></p>
<p><code><span style="color: #000000"># redirect all visitors to alternate site but retain full access for you</span></code><span style="color: #000000"><br />
<code>ErrorDocument 403 http://www.alternate-site.com</code><br />
<code>Order deny,allow</code><br />
<code>Deny from all</code><br />
<code>Allow from 99.88.77.66</code></span></p>
<h4 id="usa7"><span style="color: #000000">Provide a password prompt for visitors during site development <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Here is another possible solution for &#8220;hiding&#8221; your site during those private, site-under-construction moments. Here we are instructing Apache to provide visitors with a password prompt while providing open access to any specifically indicated IP addresses or URL’s. Edit the following code according to your IP address and other development requirements (thanks to Caleb at askapache.com for sharing this trick <sup>3</sup>):</span></p>
<p><code><span style="color: #000000"># password prompt for visitors</span></code><span style="color: #000000"><br />
<code>AuthType basic</code><br />
<code>AuthName "This site is currently under construction"</code><br />
<code>AuthUserFile /home/path/.</code><code>htpasswd</code><br />
<code>AuthGroupFile /dev/null</code><br />
<code>Require valid-user</code><br />
<code># allow webmaster and any others open access</code><br />
<code>Order Deny,Allow</code><br />
<code>Deny from all</code><br />
<code>Allow from 111.222.33.4</code><br />
<code>Allow from favorite.validation/services/</code><br />
<code>Allow from googlebot.com</code><br />
<code>Satisfy Any</code></span></p>
<h4 id="usa8"><span style="color: #000000">Prevent file or directory access according to specified time periods <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Prevent viewing of all pictures of Fonzi during the midnight hour — or <em>any</em> files during <em>any</em> time period — by using this handy htaccess ruleset:</span></p>
<p><code><span style="color: #000000"># prevent access during the midnight hour</span></code><span style="color: #000000"><br />
<code>RewriteCond %{TIME_HOUR} ^12$</code><br />
<code>RewriteRule ^.*$ - [F,L]</code></span></p>
<p><code><span style="color: #000000"># prevent access throughout the afternoon</span></code><span style="color: #000000"><br />
<code>RewriteCond %{TIME_HOUR} ^(12|13|14|15)$</code><br />
<code>RewriteRule ^.*$ - [F,L]</code></span></p>
<h3 id="redirects"><span style="color: #000000">REDIRECT TRICKS [ <a href="#top">^</a> ]</span></h3>
<h4 id="red1"><span style="color: #000000">Important Note About Redirecting via mod_rewrite <a href="#top">^</a></span></h4>
<p><span style="color: #000000">For all redirects using the <code>mod_rewrite</code> directive, it is necessary to have the <code>RewriteEngine</code>enabled. It is common practice to enable the <code>mod_rewrite</code> directive in either the server configuration file or at the top of the site’s root htaccess file. If the <code>mod_rewrite</code> directive is not included in either of these two places, it should be included as the first line in any code block that utilizes a rewrite function (i.e., <code>mod_rewrite</code>), but only needs to be included once for each htaccess file. The proper <code>mod_rewrite</code> directive is included here for your convenience, but may or may not also be included within some of the code blocks provided in this article:</span></p>
<p><code><span style="color: #000000"># initialize and enable rewrite engine</span></code><span style="color: #000000"><br />
<code>RewriteEngine on</code></span></p>
<h4 id="red2"><span style="color: #000000">Redirect from http://www.domain.com to http://domain.com <a href="#top">^</a></span></h4>
<p><span style="color: #000000">This method uses a “301 redirect” to establish a permanent redirect from the “www-version” of a domain to its respectively corresponding “non-www version”. Be sure to test <em>immediately</em> after preparing 301 redirects and remove it immediately if any errors occur. Use a “<a title="Server Header Checker" href="http://www.seoconsultants.com/tools/headers.asp">server header checker</a>” to confirm a positive 301 response. Further, always include a trailing slash “/” when linking directories. Finally, be consistent with the “www” in all links (either use it always or never).</span></p>
<p><code><span style="color: #000000"># permanently redirect from www domain to non-www domain</span></code><span style="color: #000000"><br />
<code>RewriteEngine on</code><br />
<code>Options +FollowSymLinks</code><br />
<code>RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ [NC]</code><br />
<code>RewriteRule ^(.*)$ http://domain.tld/$1 [R=301,L]</code></span></p>
<h4 id="red3"><span style="color: #000000">Redirect from http://old-domain.com to http://new-domain.com <a href="#top">^</a></span></h4>
<p><span style="color: #000000">For a basic domain change from “old-domain.com” to “new-domain.com” (and folder/file names have <em>not</em> been changed), use the <code>Rewrite</code> rule to remap the old domain to the new domain. When checking the redirect live, the old domain may appear in the browser’s address bar. Simply check an image path (right-click an image and select “properties”) to verify proper redirection. Remember to check your site thoroughly after implementing this redirect.</span></p>
<p><code><span style="color: #000000"># redirect from old domain to new domain</span></code><span style="color: #000000"><br />
<code>RewriteEngine On</code><br />
<code>RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L]</code></span></p>
<h4 id="red4"><span style="color: #000000">Redirect String Variations to a Specific Address <a href="#top">^</a></span></h4>
<p><span style="color: #000000">For example, if we wanted to redirect any requests containing the character string, “perish”, to our main page at http://perishablepress.com/, we would replace “some-string” with “perish” in the following code block:</span></p>
<p><code><span style="color: #000000"># redirect any variations of a specific character string to a specific address</span></code><span style="color: #000000"><br />
<code>RewriteRule ^some-string http://www.domain.com/index.php/blog/target [R]</code></span></p>
<p><span style="color: #000000">Here are two other methods for accomplishing string-related mapping tasks:</span></p>
<p><code><span style="color: #000000"># map URL variations to the same directory on the same server</span></code><span style="color: #000000"><br />
<code>AliasMatch ^/director(y|ies) /www/docs/target</code></span></p>
<p><code><span style="color: #000000"># map URL variations to the same directory on a different server</span></code><span style="color: #000000"><br />
<code>RedirectMatch ^/[dD]irector(y|ies) http://domain.com</code></span></p>
<h4 id="red5"><span style="color: #000000">Other Fantastic Redirect Tricks <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Redirect an entire site via 301:</span></p>
<p><code><span style="color: #000000"># redirect an entire site via 301</span></code><span style="color: #000000"><br />
<code>redirect 301 / http://www.domain.com/</code></span></p>
<p><span style="color: #000000">Redirect a specific file via 301:</span></p>
<p><code><span style="color: #000000"># redirect a specific file via 301</span></code><span style="color: #000000"><br />
<code>redirect 301 /current/currentfile.html http://www.newdomain.com/new/newfile.html</code></span></p>
<p><span style="color: #000000">Redirect an entire site via permanent redirect:</span></p>
<p><code><span style="color: #000000"># redirect an entire site via permanent redirect</span></code><span style="color: #000000"><br />
<code>Redirect permanent / http://www.domain.com/</code></span></p>
<p><span style="color: #000000">Redirect a page or directory via permanent redirect:</span></p>
<p><code><span style="color: #000000"># redirect a page or directory</span></code><span style="color: #000000"><br />
<code>Redirect permanent old_file.html http://www.new-domain.com/new_file.html</code><br />
<code>Redirect permanent /old_directory/ http://www.new-domain.com/new_directory/</code></span></p>
<p><span style="color: #000000">Redirect a file using RedirectMatch:</span></p>
<p><code><span style="color: #000000"># redirect a file using RedirectMatch</span></code><span style="color: #000000"><br />
<code>RedirectMatch 301 ^.*$ http://www.domain.com/index.html</code></span></p>
<p><span style="color: #000000">Note: When redirecting specific files, use Apache‘s <code>Redirect</code> rule for files within the same domain. Use Apache‘s <code>RewriteRule</code> for <em>any</em> domains, especially if they are different. The<code>RewriteRule</code> is more powerful than the <code>Redirect</code> rule, and thus should serve you more effectively.</span></p>
<p><span style="color: #000000">Thus, use the following for a stronger, harder page redirection (first line redirects a file, second line a directory, and third a domain):</span></p>
<p><code><span style="color: #000000"># redirect files directories and domains via RewriteRule</span></code><span style="color: #000000"><br />
<code>RewriteRule http://old-domain.com/old-file.html http://new-domain.com/new-file.html</code><br />
<code>RewriteRule http://old-domain.com/old-dir/ http://new-domain.com/new-dir/</code><br />
<code>RewriteRule http://old-domain.com/ http://new-domain.com/</code></span></p>
<h4 id="red6"><span style="color: #000000">Send visitors to a subdomain <a href="#top">^</a></span></h4>
<p><span style="color: #000000">This rule will ensure that all visitors are viewing pages via the subdomain of your choice. Edit the &#8220;subdomain&#8221;, &#8220;domain&#8221;, and &#8220;tld&#8221; to match your subdomain, domain, and top-level domain respectively:</span></p>
<p><code><span style="color: #000000"># send visitors to a subdomain</span></code><span style="color: #000000"><br />
<code>RewriteCond %{HTTP_HOST} !^$</code><br />
<code>RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC]</code><br />
<code>RewriteRule ^/(.*)$ http://subdomain.domain.tld/$1 [L,R=301]</code></span></p>
<h4 id="red7"><span style="color: #000000">More fun with RewriteCond and RewriteRule <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000"># rewrite only if the file is not found</span></code><span style="color: #000000"><br />
<code>RewriteCond %{REQUEST_FILENAME} !-f</code><br />
<code>RewriteRule ^(.+)special\.html?$ cgi-bin/special/special-html/$1</code></span></p>
<p><code><span style="color: #000000"># rewrite only if an image is not found</span></code><span style="color: #000000"><br />
<code>RewriteCond %{REQUEST_FILENAME} !-f</code><br />
<code>RewriteRule images/special/(.*).gif cgi-bin/special/mkgif?$1</code></span></p>
<p><code><span style="color: #000000"># seo-friendly rewrite rules for various directories</span></code><span style="color: #000000"><br />
<code>RewriteRule ^(.*)/aud/(.*)$ $1/audio-files/$2 [L,R=301]</code><br />
<code>RewriteRule ^(.*)/img/(.*)$ $1/image-files/$2 [L,R=301]</code><br />
<code>RewriteRule ^(.*)/fla/(.*)$ $1/flash-files/$2 [L,R=301]</code><br />
<code>RewriteRule ^(.*)/vid/(.*)$ $1/video-files/$2 [L,R=301]</code></span></p>
<p><code><span style="color: #000000"># broswer sniffing via htaccess environmental variables</span></code><span style="color: #000000"><br />
<code>RewriteCond %{HTTP_USER_AGENT} ^Mozilla.*</code><br />
<code>RewriteRule ^/$ /index-for-mozilla.html [L]</code><br />
<code>RewriteCond %{HTTP_USER_AGENT} ^Lynx.*</code><br />
<code>RewriteRule ^/$ /index-for-lynx.html [L]</code><br />
<code>RewriteRule ^/$ /index-for-all-others.html [L]</code></span></p>
<p><code><span style="color: #000000"># redirect query to Google search</span></code><span style="color: #000000"><br />
<code>Options +FollowSymlinks</code><br />
<code>RewriteEngine On</code><br />
<code>RewriteCond %{REQUEST_URI} .google\.php*</code><br />
<code>RewriteRule ^(.*)$ ^http://www.google.com/search?q=$1 [R,NC,L]</code></span></p>
<p><code><span style="color: #000000"># deny request according to the request method</span></code><span style="color: #000000"><br />
<code>RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS|HEAD)$ [NC]</code><br />
<code>RewriteRule ^.*$ - [F]</code></span></p>
<p><code><span style="color: #000000"># redirect uploads to a better place</span></code><span style="color: #000000"><br />
<code>RewriteCond %{REQUEST_METHOD} ^(PUT|POST)$ [NC]</code><br />
<code>RewriteRule ^(.*)$ /cgi-bin/upload-processor.cgi?p=$1 [L,QSA]</code></span></p>
<h4 id="red8"><span style="color: #000000">More fun with Redirect 301 and RedirectMatch 301 <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000"># seo friendly redirect for a single file</span></code><span style="color: #000000"><br />
<code>Redirect 301 /old-dir/old-file.html http://domain.com/new-dir/new-file.html</code></span></p>
<p><code><span style="color: #000000"># seo friendly redirect for multiple files</span></code><span style="color: #000000"><br />
<code># redirects all files in dir directory with first letters xyz</code><br />
<code>RedirectMatch 301 /dir/xyz(.*) http://domain.com/$1</code></span></p>
<p><code><span style="color: #000000"># seo friendly redirect entire site to a different domain</span></code><span style="color: #000000"><br />
<code>Redirect 301 / http://different-domain.com</code></span></p>
<h3 id="wordpress"><span style="color: #000000">WORDPRESS TRICKS [ <a href="#top">^</a> ]</span></h3>
<h4 id="wor1"><span style="color: #000000">Secure WordPress Contact Forms <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Protect your insecure WordPress contact forms against online unrighteousness by verifying the domain from whence the form is called. Remember to replace the “domain.com” and “contact.php” with <em>your</em> domain and contact-form file names, respectively.</span></p>
<p><code><span style="color: #000000"># secure wordpress contact forms via referrer check</span></code><span style="color: #000000"><br />
<code>RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]</code><br />
<code>RewriteCond %{REQUEST_POST} .*contact.php$</code><br />
<code>RewriteRule .* - [F]</code></span></p>
<h4 id="wor2"><span style="color: #000000">WordPress Permalinks <a href="#top">^</a></span></h4>
<p><span style="color: #000000">In our article, <a title="In depth: htaccess rules for WordPress" href="http://perishablepress.com/press/2006/06/14/the-htaccess-rules-for-all-wordpress-permalinks/">The htaccess rules for all WordPress Permalinks</a>, we revealed the precise htaccess directives used by the WordPress blogging platform for permalink functionality. Here, for the sake of completeness, we repeat the directives only. For more details please refer to the original article:</span></p>
<p><span style="color: #000000">If WordPress is installed in the site’s root directory, WordPress creates and uses the following htaccess directives:</span></p>
<p><code><span style="color: #000000"># BEGIN WordPress</span></code><span style="color: #000000"><br />
<code>&lt;IfModule mod_rewrite.c&gt;</code><br />
<code>RewriteEngine On</code><br />
<code>RewriteBase /</code><br />
<code>RewriteCond %{REQUEST_FILENAME} !-f</code><br />
<code>RewriteCond %{REQUEST_FILENAME} !-d</code><br />
<code>RewriteRule . /index.php [L]</code><br />
<code>&lt;/IfModule&gt;</code><br />
<code># END WordPress</code></span></p>
<p><span style="color: #000000">If WordPress is installed in some subdirectory “foo”, WordPress creates and uses the following htaccess directives:</span></p>
<p><code><span style="color: #000000"># BEGIN WordPress</span></code><span style="color: #000000"><br />
<code>&lt;IfModule mod_rewrite.c&gt;</code><br />
<code>RewriteEngine On</code><br />
<code>RewriteBase /foo/</code><br />
<code>RewriteCond %{REQUEST_FILENAME} !-f</code><br />
<code>RewriteCond %{REQUEST_FILENAME} !-d</code><br />
<code>RewriteRule . /foo/index.php [L]</code><br />
<code>&lt;/IfModule&gt;</code><br />
<code># END WordPress</code></span></p>
<h3 id="random"><span style="color: #000000">RANDOM TRICKS [ <a href="#top">^</a> ]</span></h3>
<h4 id="ran1"><span style="color: #000000">Activate SSI for HTML/SHTML file types: <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000"># activate SSI for HTML and or SHTML file types</span></code><span style="color: #000000"><br />
<code>AddType text/html .html</code><br />
<code>AddType text/html .shtml</code><br />
<code>AddHandler server-parsed .html</code><br />
<code>AddHandler server-parsed .shtml</code><br />
<code>AddHandler server-parsed .htm</code></span></p>
<h4 id="ran2"><span style="color: #000000">Grant CGI access in a specific directory: <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000"># grant CGI access in a specific directory</span></code><span style="color: #000000"><br />
<code>Options +ExecCGI</code><br />
<code>AddHandler cgi-script cgi pl</code><br />
<code># to enable all scripts in a directory use the following</code><br />
<code>SetHandler cgi-script</code></span></p>
<h4 id="ran3"><span style="color: #000000">Disable magic_quotes_gpc for PHP enabled servers: <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000"># turn off magic_quotes_gpc for PHP enabled servers</span></code><span style="color: #000000"><br />
<code>&lt;ifmodule mod_php4.c&gt;</code><br />
<code>php_flag magic_quotes_gpc off</code><br />
<code>&lt;/ifmodule&gt;</code></span></p>
<h4 id="ran4"><span style="color: #000000">Enable MD5 digests: <a href="#top">^</a></span></h4>
<p><span style="color: #000000">Note: enabling this option may result in a relative decrease in server performance.</span></p>
<p><code><span style="color: #000000"># enable MD5 digests via ContentDigest</span></code><span style="color: #000000"><br />
<code>ContentDigest On</code></span></p>
<h4 id="ran5"><span style="color: #000000">Expression Engine Tricks: <a href="#top">^</a></span></h4>
<p><code><span style="color: #000000"># send Atom and RSS requests to the site docroot to be rewritten for ExpressionEngine</span></code><span style="color: #000000"><br />
<code>RewriteRule .*atom.xml$ http://www.yoursite.com/index.php/weblog/rss_atom/ [R]</code><br />
<code>RewriteRule .*rss.xml$ http://www.yoursite.com/index.php/weblog/rss_2.0/ [R]</code></span></p>
<p><code><span style="color: #000000"># cause all requests for index.html to be rewritten for ExpressionEngine</span></code><span style="color: #000000"><br />
<code>RewriteRule /.*index.html$ http://www.domain.com/index.php [R]</code></span></p>
<h3><span style="color: #000000">REFERENCES</span></h3>
<ul style="margin-top: 25px;margin-right: 0px;margin-bottom: 25px;margin-left: 0px;line-height: 18px;padding: 0px"> <span style="color: #000000"></p>
<li><sup>1</sup> <a title="Original Wikipedia htaccess article archived at WebGeek" rel="nofollow" href="http://www.hybrid6.com/webgeek/2007/02/htaccess-reference.php">Wikipedia htaccess Resource</a></li>
<li><sup>2</sup> <a title="Apache Cookbook" rel="nofollow" href="http://www.oreilly.com/catalog/apacheckbk/">Apache Cookbook</a></li>
<li><sup>3</sup> <a title="Ultimate htaccess Article" rel="nofollow" href="http://www.askapache.com/2006/htaccess/htaccesselite-ultimate-htaccess-article.html">Ultimate htaccess Article</a></li>
<li><a title="Regular-Expressions.info" rel="nofollow" href="http://www.regular-expressions.info/">More on regular expressions</a></li>
<li><a title="Apache Reference" rel="nofollow" href="http://httpd.apache.org/docs/1.3/howto/htaccess.html">Apache htaccess Reference</a></li>
<li><a title="Apache Tutorial" rel="nofollow" href="http://httpd.apache.org/docs/trunk/howto/htaccess.html">Apache htaccess Tutorial</a></li>
<li><a title="Apache mod_rewrite" rel="nofollow" href="http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html">Apache mod_rewrite</a></li>
<li><a title="htaccess Forum" rel="nofollow" href="http://www.webmasterworld.com/forum13/687.htm">htaccess Forum</a></li>
<li><a title="Behind the Scenes with htaccess" rel="nofollow" href="http://brainstormsandraves.com/archives/2005/10/09/htaccess/">Behind the Scenes with htaccess</a></li>
<li><a title="Automatic htaccess file generator" rel="nofollow" href="http://cooletips.de/htaccess/">Automatic htaccess file generator</a></li>
<p></span></ul>
<p><span style="color: #000000"> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2010/12/06/htaccess-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advanced MRTG Configurations</title>
		<link>http://blog.nataprawira.com/tech/2010/12/02/advanced-mrtg-configurations/</link>
		<comments>http://blog.nataprawira.com/tech/2010/12/02/advanced-mrtg-configurations/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 16:40:30 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[MRTG]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=174</guid>
		<description><![CDATA[

Introduction
In many cases using MRTG in a basic configuration to monitor the volume of network traffic to your server isn&#8217;t enough. You may also want to see graphs of CPU, disk, and memory usage. This chapter explains how to find the values you want to monitor in the SNMP MIB files and then how to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F12%2F02%2Fadvanced-mrtg-configurations%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F12%2F02%2Fadvanced-mrtg-configurations%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<h1 style="color: green;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: #048444;font-size: 24px"><span>Introduction</span></h1>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">In many cases using MRTG in a basic configuration to monitor the volume of network traffic to your server isn&#8217;t enough. You may also want to see graphs of CPU, disk, and memory usage. This chapter explains how to find the values you want to monitor in the SNMP MIB files and then how to use this information to configure MRTG.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">All the chapter&#8217;s examples assume that the SNMP Read Only string is craz33guy and that the net-snmp-utils RPM package is installed (see Chapter 22, &#8220;<a title="Quick HOWTO : Ch22 : Monitoring Server Performance" href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch22_:_Monitoring_Server_Performance"> Monitoring Server Performance</a>&#8220;).<span id="more-174"></span></p>
<h1 style="color: green;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: #048444;font-size: 24px"><span>Locating And Viewing The Contents Of Linux MIBs</span></h1>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Residing in memory, MIBs are data structures that are constantly updated via the SNMP daemon. The MIB configuration text files are located on your hard disk and loaded into memory each time SNMP restarts.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">You can easily find your Fedora Linux MIBs by using the locate command and filtering the output to include only values with the word &#8220;snmp&#8221; in them. As you can see in this case, the MIBs are located in the /usr/share/snmp/mibs directory:</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# locate mib | grep snmp
/usr/share/doc/net-snmp-5.0.6/README.mib2c
/usr/share/snmp/mibs
/usr/share/snmp/mibs/DISMAN-SCHEDULE-MIB.txt
...
...
[root@bigboy tmp]#</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">As the MIB configurations are text files you can search for keywords in them using the grep command. This examples searches for the MIBs that keep track of TCP connections and returns the RFC1213 and TCP MIBs as the result.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@silent mibs]# grep -i tcp /usr/share/snmp/mibs/*.txt | grep connections
...
RFC1213-MIB.txt: "The limit on the total number of TCP connections
RFC1213-MIB.txt: "The number of times TCP connections have made a
...
TCP-MIB.txt:     "The number of times TCP connections have made a
...
...
[root@silent mibs]#</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">You can use the vi editor to look at the MIBs. Don&#8217;t change them, because doing so could cause SNMP to fail. MIBs are very complicated, but fortunately the key sections are commented.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Each value tracked in a MIB is called an object and is often referred to by its object ID or OID. In this snippet of the RFC1213-MIB.txt file, you can see that querying the tcpActiveOpens object returns the number of active open TCP connections to the server. The SYNTAX field shows that this is a counter value.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">MIBs usually track two types of values. Counter values are used for items that continuously increase as time passes, such as the amount of packets passing through a NIC or amount of time CPU been busy since boot time. Integer values change instant by instant and are useful for tracking such statistics as the amount of memory currently being used.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">tcpActiveOpens OBJECT-TYPE
    SYNTAX  Counter
    ACCESS  read-only
    STATUS  mandatory
    DESCRIPTION
            "The number of times TCP connections have made a
            direct transition to the SYN-SENT state from the
            CLOSED state."
    ::= { tcp 5 }</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">You&#8217;ll explore the differences between SNMP and MRTG terminologies in more detail later. Understanding them will be important in understanding how to use MRTG to track MIB values.</p>
<h1 style="color: green;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: #048444;font-size: 24px"><span>Testing Your MIB Value</span></h1>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Once you have identified an interesting MIB value for your Linux system you can then use the snmpwalk command to poll it. Many times the text aliases in a MIB only reference the OID branch and not the OID the data located in a leaf ending in an additional number like a &#8220;.0&#8243; or &#8220;.1&#8243;. The snmpget command doesn&#8217;t work with branches giving an error stating that the MIB variable couldn&#8217;t be found.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">In the example below, the ssCpuRawUser OID alias was found to be interesting, but the snmpget command fails to get a value. Follow up with the snmpwalk command shows that the value is located in ssCpuRawUser.0 instead. The snmpget is then successful in retrieving the &#8220;counter32&#8243; type data with a current value of 396271.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# snmpget -v1 -c craz33guy localhost ssCpuRawUser
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: UCD-SNMP-MIB::ssCpuRawUser
[root@bigboy tmp]#

[root@bigboy tmp]# snmpwalk -v1 -c craz33guy localhost ssCpuRawUser
UCD-SNMP-MIB::ssCpuRawUser.0 = Counter32: 396241
[root@bigboy tmp]# snmpget -v1 -c craz33guy localhost ssCpuRawUser.0
UCD-SNMP-MIB::ssCpuRawUser.0 = Counter32: 396271
[root@bigboy tmp]#</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The MIB values that work successfully with snmpget are the ones you should use with MRTG.</p>
<h1 style="color: green;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: #048444;font-size: 24px"><span>Differences In MIB And MRTG Terminology</span></h1>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Always keep in mind that MRTG refers to MIB counter values as counter values. It refers to MIB integer and gauge values as gauge. By default, MRTG considers all values to be counters.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">MRTG doesn&#8217;t plot counter values as a constantly increasing graph, it plots only how much the value has changed since the last polling cycle. CPU usage is typically tracked by MIBs as a counter value; fortunately, you can edit your MRTG configuration file to make it graph this information in a percentage use format (more on this later).</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The syntax type, the MIB object name, and the description of what it does are the most important things you need to know when configuring MRTG; I&#8217;ll come back to these later.</p>
<h1 style="color: green;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: #048444;font-size: 24px"><span>The CPU And Memory Monitoring MIB</span></h1>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The UCD-SNMP-MIB MIB keeps track of a number of key performance MIB objects, including the commonly used ones in Table 23-1.</p>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Table 23-1 Important Objects In The UCD-SNMP-MIB MIB</span></h2>
<table style="font-size: 13px;color: black;background-color: white" border="1" cellspacing="0" cellpadding="5" align="center">
<tbody>
<tr>
<th>UCD-SNMP-MIB Object Variable</th>
<th>MIB Type</th>
<th>MRTG Type</th>
<th>Description</th>
</tr>
<tr valign="top">
<td>ssCpuRawUser</td>
<td>Counter</td>
<td>Counter</td>
<td>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Total CPU usage by applications run by nonprivileged users since the system booted. Adding the user, system, and nice values can give a good approximation of total CPU usage..</p>
</td>
</tr>
<tr valign="top">
<td>ssCpuRawSystem</td>
<td>Counter</td>
<td>Counter</td>
<td>Total CPU usage by applications run by privileged system processes since the system booted.</td>
</tr>
<tr valign="top">
<td>ssCpuRawNice</td>
<td>Counter</td>
<td>Counter</td>
<td>Total CPU usage by applications running at a nondefault priority level.</td>
</tr>
<tr valign="top">
<td>ssCpuRawIdle</td>
<td>Counter</td>
<td>Counter</td>
<td>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The percentage of the time the CPU is running idle. Subtracting this value from 100 can give a good approximation of total CPU usage.</p>
</td>
</tr>
<tr valign="top">
<td>memAvailReal</td>
<td>Integer</td>
<td>Gauge</td>
<td>Available Physical Memory Space On The Host</td>
</tr>
</tbody>
</table>
<h1 style="color: green;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: #048444;font-size: 24px"><span>The TCP/IP Monitoring MIB</span></h1>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The TCP-MIB MIB keeps track of data connection information and contains the very useful tcpActiveOpens and tcpCurrEstab objects. Table 23.2 details the most important objects in TCP-MIB.</p>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Table 23-2 Important Objects In The TCP-MIB MIB</span></h2>
<table style="font-size: 13px;color: black;background-color: white" border="1" cellspacing="0" cellpadding="5" align="center">
<tbody>
<tr>
<th>UCD-SNMP-MIB Object Variable</th>
<th>MIB Type</th>
<th>MRTG Type</th>
<th>Description</th>
</tr>
<tr valign="top">
<td>tcpActiveOpens</td>
<td>Counter</td>
<td>Counter</td>
<td>Measures the number of completed TCP connections.</td>
</tr>
<tr valign="top">
<td>tcpCurrEstab</td>
<td>Gauge</td>
<td>Gauge</td>
<td>Measures the number of TCP connections in the established state</td>
</tr>
<tr valign="top">
<td>tcpInErrs</td>
<td>Counter</td>
<td>Counter</td>
<td>Total number of TCP segments with bad checksum errors</td>
</tr>
</tbody>
</table>
<h1 style="color: green;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: #048444;font-size: 24px"><span>Manually Configuring Your MRTG File</span></h1>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The MRTG cfgmaker program creates configuration files for network interfaces only, simultaneously tracking two OIDs: the NIC&#8217;s input and output data statistics. The mrtg program then uses these configuration files to determine the type of data to record in its data directory. The indexmaker program also uses this information to create the overview, or Summary View Web page for the MIB OIDs you&#8217;re monitoring.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">This Summary View page shows daily statistics only. You have to click on the Summary View graphs to get the Detailed View page behind it with the daily, weekly, monthly, and annual graphs. Some of the parameters in the configuration file refer to the Detailed View, others refer to the Summary View.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">If you want to monitor any other pairs of OIDs, you have to manually create the configuration files, because cfgmaker isn&#8217;t aware of any OIDs other than those related to a NIC. The mrtg and indexmaker program can be fed individual OIDs from a customized configuration file and will function as expected if you edit the file correctly.</p>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Parameter Formats</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">MRTG configuration parameters are always followed by a graph name surrounded by square brackets and a colon. The format looks like this:</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Parameter[graph name]: value</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">For ease of editing, the parameters for a particular graph are usually grouped together. Each graph can track two OIDS listed in the Target parameter, which is usually placed at the very top of the graph name list. The two OID values are separated by an &amp; symbol; the first one can be is the input OID, and the second one is the output OID.</p>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Legend Parameters</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">On the Detailed View Web page, each graph has a legend that shows the max, average, and current values of the graph&#8217;s OID statistics. You can use the legendI parameter for the description of the input graph (first graph OID) and the legendO for the output graph (second graph OID).</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The space available under each graph&#8217;s legend is tiny so MRTG also has legend1 and legend2 parameters that are placed at the very bottom of the page to provide more details. Parameter legend1 is the expansion of legendI, and legend2 is the expansion of legendO.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The Ylegend is the legend for the Y axis, the value you are trying to compare. In the case of a default MRTG configuration this would be the data flow through the interface in bits or bytes per second. Here is an example of the legends of a default MRTG configuration:</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">YLegend[graph1]: Bits per second
Legend1[graph1]: Incoming Traffic in Bits per Second
Legend2[graph1]: Outgoing Traffic in Bits per Second
LegendI[graph1]: In
LegendO[graph1]: Out</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">You can prevent MRTG from printing the legend at the bottom of the graph by leaving the value of the legend blank like this:</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">LegendI[graph1]:</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Later you&#8217;ll learn how to match the legends to the OIDs for a variety of situations.</p>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Options Parameters</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Options parameters provide MRTG with graph formatting information. The growright option makes sure the data at the right of the screen is for the most current graph values. This usually makes the graphs more intuitively easy to read. MRTG defaults to growing from the left.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The nopercent option prevents MRTG from printing percentage style statistics in the legends at the bottom of the graph. The gauge option alerts MRTG to the fact that the graphed values are of the gauge type. If the value you are monitoring is in bytes, then you can convert the output to bits using the bits option. Likewise, you can convert per second values to per minute graphs using the perminute option. Here are some examples for two different graphs:</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">options[graph1]: growright,nopercent,perminute

options[graph2]: gauge,bits</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">If you place this parameter at the top with a label of [_] it gets applied to all the graphs defined in the file. Here&#8217;s an example.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">options[_]: growright</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Title Parameters</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The title on the Summary Page is provided by the Title parameter, the PageTop parameter tells the title for the Detailed View page. The PageTop string must start with &lt; H1 &gt; and end with &lt; H1 &gt;.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Title[graph1]: Interface eth0

PageTop[graph1]: &lt; H1 &gt;Detailed Statistics For Interface eth0 &lt; H1 &gt;</pre>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Scaling Parameters</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The MaxBytes parameter is the maximum amount of data MRTG will plot on a graph. Anything more than this seems to disappear over the edge of the graph.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">MRTG also tries to adjust its graphs so that the largest value plotted on the graph is always close to the top. This is so even if you set the MaxBytes parameter.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">When you are plotting a value that has a known maximum and you always want to have this value at the top of the vertical legend, you may want to turn off MRTG&#8217;s auto scaling. If you are plotting percentage CPU usage, and the server reaches a maximum of 60%, with scaling, MRTG will have a vertical plot of 0% to 60%, so that the vertical peak is near the top of the graph image.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">When scaling is off, and MaxBytes is set to 100, then the peak will be only 60% of the way up as the graph plots from 0% to 100%. The example removes scaling from the yearly, monthly, weekly, and daily views on the Detailed View page and gives them a maximum value of 100.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Unscaled[graph1]: ymwd
MaxBytes[graph1]: 100</pre>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Defining The MIB Target Parameters</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">As stated before, MRTG always tries to compare two MIB OID values that are defined by the Target parameter. You have to specify the two MIB OID objects, the SNMP password and the IP address of the device you are querying in this parameter, and separate them with an &amp; character:</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Target[graph1]: mib-object-1.0&amp;mib-object-2.0:&lt;SNMP-password&gt;@&lt;IP-address&gt;</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The numeric value, in this case .0, at the end of the MIB is required. The next example uses the SNMP command to return the user mode CPU utilization of a Linux server. Notice how the .0 is tagged onto the end of the output.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@silent mibs]# snmpwalk -v 1 -c craz33guy localhost ssCpuRawUser
UCD-SNMP-MIB::ssCpuRawUser.0 = Counter32: 926739
[root@silent mibs]#</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The MRTG legends map to the MIBs listed in the target as shown in Table 23-3.</p>
<h3 style="color: black;background-color: initial;font-weight: bold;margin-top: 0px;margin-right: 0px;margin-bottom: 0.3em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: initial;border-bottom-style: none;border-bottom-color: initial;font-size: 17px"><span>Table 23-3 Mapping MIBs To The Graph Legends</span></h3>
<table style="font-size: 13px;color: black;background-color: white" border="1" cellspacing="0" cellpadding="5" align="center">
<tbody>
<tr>
<th>Legend</th>
<th>Maps To Target MIB</th>
</tr>
<tr valign="top">
<td>Legend1</td>
<td>#1</td>
</tr>
<tr valign="top">
<td>Legend2</td>
<td>#2</td>
</tr>
<tr valign="top">
<td>LegendI</td>
<td>#1</td>
</tr>
<tr valign="top">
<td>LegendO</td>
<td>#2</td>
</tr>
</tbody>
</table>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">So in the example below, legend1 and legendI describe mib-object-1.0 and legend2 and legendO describe mib-object-2.0.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Target[graph1]: mib-object-1.0&amp;mib-object-2.0:&lt;SNMP-password&gt;@&lt;IP-address&gt;</pre>
<h3 style="color: black;background-color: initial;font-weight: bold;margin-top: 0px;margin-right: 0px;margin-bottom: 0.3em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: initial;border-bottom-style: none;border-bottom-color: initial;font-size: 17px"><span>Plotting Only One MIB Value</span></h3>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">If you want to plot only one MIB value, you can just repeat the target MIB in the definition as in the next example, which plots only mib-object-1. The resulting MRTG graph actually superimposes the input and output graphs one on top of the other.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Target[graph1]: mib-object-1.0&amp;mib-object-1.0:&lt;SNMP-password&gt;@&lt;IP-address&gt;</pre>
<h3 style="color: black;background-color: initial;font-weight: bold;margin-top: 0px;margin-right: 0px;margin-bottom: 0.3em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: initial;border-bottom-style: none;border-bottom-color: initial;font-size: 17px"><span>Adding MIB Values Together For a Graph</span></h3>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">You can use the plus sign between the pairs of MIB object values to add them together. The next example adds mib-object-1.0 and mib-object-3.0 for one graph and adds mib-object-2.0 and mib-object-4.0 for the other.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Target[graph1]: mib-object-1.0&amp;mib-object-2.0:&lt;SNMP-password&gt;@&lt;IP-address&gt; + mib-object-3.0&amp;mib-object-4.0:&lt;SNMP-password&gt;@&lt;IP-address&gt;</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">You can use other mathematical operators, such as subtract (-), multiply (*), and divide (%). Left and right parentheses are also valid. There must be white spaces before and after all these operators for MRTG to work correctly. If not, you&#8217;ll get oddly shaded graphs.</p>
<h3 style="color: black;background-color: initial;font-weight: bold;margin-top: 0px;margin-right: 0px;margin-bottom: 0.3em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: initial;border-bottom-style: none;border-bottom-color: initial;font-size: 17px"><span>Sample Target: Total CPU Usage</span></h3>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Linux CPU usage is occupied by system processes, user mode processes, and a few processes running in nice mode. This example adds them all together in a single plot.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Target[graph1]:ssCpuRawUser.0&amp;ssCpuRawUser.0:&lt;SNMP-password&gt;@&lt;IP-address&gt; + ssCpuRawSystem.0&amp;ssCpuRawSystem.0:&lt;SNMP-password&gt;@&lt;IP-address&gt; + ssCpuRawNice.0&amp;ssCpuRawNice.0:&lt;SNMP-password&gt;@&lt;IP-address&gt;</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Be sure to place this command on a single line</p>
<h3 style="color: black;background-color: initial;font-weight: bold;margin-top: 0px;margin-right: 0px;margin-bottom: 0.3em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: initial;border-bottom-style: none;border-bottom-color: initial;font-size: 17px"><span>Sample Target: Memory Usage</span></h3>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Here is an example for the plotting the amount of free memory versus the total RAM installed in the server. Notice that this is a gauge type variable.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Target[graph1]: memAvailReal.0&amp;memTotalReal.0:&lt;SNMP-password&gt;@&lt;IP-address&gt;
options[graph1]: nopercent,growright,gauge</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Next, plot the percentage of available memory. Notice how the mandatory white spaces separate the mathematical operators from the next target element.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Target[graph1]: ( memAvailReal.0&amp; memAvailReal.0:&lt;SNMP-password&gt;@&lt;IP-Address&gt; ) * 100 / ( memTotalReal.0&amp;memTotalReal.0:&lt;SNMP-password&gt;@&lt;IP-Address&gt; )
options[graph1]: nopercent,growright,gauge</pre>
<h3 style="color: black;background-color: initial;font-weight: bold;margin-top: 0px;margin-right: 0px;margin-bottom: 0.3em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: initial;border-bottom-style: none;border-bottom-color: initial;font-size: 17px"><span>Sample Target: Newly Created Connections</span></h3>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">HTTP traffic caused by Web browsing usually consists of many very short lived connections. The tcpPassiveOpens MIB object tracks newly created connections and is suited for this type of data transfer. The tcpActiveOpens MIB object monitors new connections originating from the server. On smaller Web sites you may want to use the perminute option to make the graphs more meaningful.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Target[graph1]: tcpPassiveOpens.0&amp; tcpPassiveOpens.0:&lt;SNMP-password&gt;@&lt;IP-address&gt;
MaxBytes[graph1]: 1000000
Options[graph1]: perminute</pre>
<h3 style="color: black;background-color: initial;font-weight: bold;margin-top: 0px;margin-right: 0px;margin-bottom: 0.3em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: initial;border-bottom-style: none;border-bottom-color: initial;font-size: 17px"><span>Sample Target: Total TCP Established Connections</span></h3>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Other protocols such as FTP and SSH create longer established connections while people download large files or stay logged into the server. The tcpCurrEstab MIB object measures the total number of connections in the established state and is a gauge value.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Target[graph1]: tcpCurrEstab.0&amp;tcpCurrEstab.0:&lt;SNMP-password&gt;@&lt;IP-address&gt;
MaxBytes[graph1]: 1000000
Options[graph1]: gauge</pre>
<h3 style="color: black;background-color: initial;font-weight: bold;margin-top: 0px;margin-right: 0px;margin-bottom: 0.3em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: initial;border-bottom-style: none;border-bottom-color: initial;font-size: 17px"><span>Sample Target: Disk Partition Usage</span></h3>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">In this example, you&#8217;ll monitor the /var and /home disk partitions on the system.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">1) First use the df -k command to get a list of the partitions in use.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda8               505605    128199    351302  27% /
/dev/hda1               101089     19178     76692  21% /boot
/dev/hda5              1035660    122864    860188  13% /home
/dev/hda6               505605      8229    471272   2% /tmp
/dev/hda3              3921436    890092   2832140  24% /usr
/dev/hda2              1510060    171832   1261520  73% /var
[root@bigboy tmp]#</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">2) Add two entries to your snmpd.conf file.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">disk  /home
disk  /var</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">3) Restart the SNMP daemon to reload the values.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# service snmpd restart</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">4) Use the snmpwalk command to query the the dskPercent MIB. Object dskPercent.1 refers to the first disk entry in snmpd.conf (/home), and dskPercent.2 refers to the second (/var).</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# snmpwalk -v 1 -c craz33guy localhost dskPercent.1
UCD-SNMP-MIB::dskPercent.1 = INTEGER: 13
[root@bigboy tmp]# snmpwalk -v 1 -c craz33guy localhost dskPercent.2
UCD-SNMP-MIB::dskPercent.2 = INTEGER: 73
[root@bigboy tmp]#</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Your MRTG target for these gauge MIB objects should look like this:</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Target[graph1]: dskPercent.1&amp; dskPercent.1:&lt;SNMP-password&gt;@&lt;IP-address&gt;
options[graph1]: growright,gauge</pre>
<h3 style="color: black;background-color: initial;font-weight: bold;margin-top: 0px;margin-right: 0px;margin-bottom: 0.3em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: initial;border-bottom-style: none;border-bottom-color: initial;font-size: 17px"><span>Defining Global Variables</span></h3>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">You have to make sure MRTG knows where the MIBs you&#8217;re using are located. The default location MRTG uses may not be valid. Specify their locations with the global LoadMIBs parameter. You must also define where the HTML files will be located; the example specifies the default Fedora MRTG HTML directory.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt, /usr/share/snmp/mibs/TCP-MIB.txt
workdir: /var/www/mrtg/</pre>
<h1 style="color: green;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: #048444;font-size: 24px"><span>Implementing Advanced Server Monitoring</span></h1>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">You now can combine all you have learned to create a configuration file that monitors all these variables, and then you can integrate it into the existing MRTG configuration.</p>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>A Complete Sample Configuration</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Here is a sample configuration file that is used to query server localhost for CPU, memory, disk, and TCP connection information.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">#
# File: /etc/mrtg/server-info.cfg
#
# Configuration file for non bandwidth server statistics
#

#
# Define global options
#

LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt,/usr/share/snmp/mibs/TCP-MIB.txt
workdir: /var/www/mrtg/

#
# CPU Monitoring
# (Scaled so that the sum of all three values doesn't exceed 100)
#

Target[server.cpu]:ssCpuRawUser.0&amp;ssCpuRawUser.0:craz33guy@localhost + ssCpuRawSystem.0&amp;ssCpuRawSystem.0:craz33guy@localhost + ssCpuRawNice.0&amp;ssCpuRawNice.0:craz33guy@localhost
Title[server.cpu]: Server CPU Load
PageTop[server.cpu]: &lt; H1 &gt;CPU Load - System, User and Nice Processes&lt; /H1 &gt;
MaxBytes[server.cpu]: 100
ShortLegend[server.cpu]: %
YLegend[server.cpu]: CPU Utilization
Legend1[server.cpu]: Current CPU percentage load
LegendI[server.cpu]: Used
LegendO[server.cpu]:
Options[server.cpu]: growright,nopercent
Unscaled[server.cpu]: ymwd

#
# Memory Monitoring (Total Versus Available Memory)
#

Target[server.memory]: memAvailReal.0&amp;memTotalReal.0:craz33guy@localhost
Title[server.memory]: Free Memory
PageTop[server.memory]: &lt; H1 &gt;Free Memory&lt; /H1 &gt;
MaxBytes[server.memory]: 100000000000
ShortLegend[server.memory]: B
YLegend[server.memory]: Bytes
LegendI[server.memory]: Free
LegendO[server.memory]: Total
Legend1[server.memory]: Free memory, not including swap, in bytes
Legend2[server.memory]: Total memory
Options[server.memory]: gauge,growright,nopercent
kMG[server.memory]: k,M,G,T,P,X

#
# Memory Monitoring (Percentage usage)
#
Title[server.mempercent]: Percentage Free Memory
PageTop[server.mempercent]: &lt; H1 &gt;Percentage Free Memory&lt; /H1 &gt;
Target[server.mempercent]: ( memAvailReal.0&amp;memAvailReal.0:craz33guy@localhost ) * 100 / ( memTotalReal.0&amp;memTotalReal.0:craz33guy@localhost )
options[server.mempercent]: growright,gauge,transparent,nopercent
Unscaled[server.mempercent]: ymwd
MaxBytes[server.mempercent]: 100
YLegend[server.mempercent]: Memory %
ShortLegend[server.mempercent]: Percent
LegendI[server.mempercent]: Free
LegendO[server.mempercent]: Free
Legend1[server.mempercent]: Percentage Free Memory
Legend2[server.mempercent]: Percentage Free Memory

#
# New TCP Connection Monitoring (per minute)
#

Target[server.newconns]: tcpPassiveOpens.0&amp;tcpActiveOpens.0:craz33guy@localhost
Title[server.newconns]: Newly Created TCP Connections
PageTop[server.newconns]: &lt; H1 &gt;New TCP Connections&lt; /H1 &gt;
MaxBytes[server.newconns]: 10000000000
ShortLegend[server.newconns]: c/s
YLegend[server.newconns]: Conns / Min
LegendI[server.newconns]: In
LegendO[server.newconns]: Out
Legend1[server.newconns]: New inbound connections
Legend2[server.newconns]: New outbound connections
Options[server.newconns]: growright,nopercent,perminute

#
# Established TCP Connections
#

Target[server.estabcons]: tcpCurrEstab.0&amp;tcpCurrEstab.0:craz33guy@localhost
Title[server.estabcons]: Currently Established TCP Connections
PageTop[server.estabcons]: &lt; H1 &gt;Established TCP Connections&lt; /H1 &gt;
MaxBytes[server.estabcons]: 10000000000
ShortLegend[server.estabcons]:
YLegend[server.estabcons]: Connections
LegendI[server.estabcons]: In
LegendO[server.estabcons]:
Legend1[server.estabcons]: Established connections
Legend2[server.estabcons]:
Options[server.estabcons]: growright,nopercent,gauge

#
# Disk Usage Monitoring
#

Target[server.disk]: dskPercent.1&amp;dskPercent.2:craz33guy@localhost
Title[server.disk]: Disk Partition Usage
PageTop[server.disk]: &lt; H1 &gt;Disk Partition Usage /home and /var&lt; /H1 &gt;
MaxBytes[server.disk]: 100
ShortLegend[server.disk]: %
YLegend[server.disk]: Utilization
LegendI[server.disk]: /home
LegendO[server.disk]: /var
Options[server.disk]: gauge,growright,nopercent
Unscaled[server.disk]: ymwd</pre>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Testing The Configuration</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The next step is to test that MRTG can load the configuration file correctly.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Restart SNMP to make sure the disk monitoring commands in the snmpd.conf file are activated. Run the /usr/bin/mrtg command followed by the name of the configuration file three times. If all goes well, MRTG will complain only about the fact that certain database files don&#8217;t exist. MRTG then creates the files. By the third run, all the files are created and MRTG should operate smoothly.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# service snmpd restart
[root@bigboy tmp]# env LANG=C /usr/bin/mrtg /etc/mrtg/server-stats.cfg</pre>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Creating A New MRTG Index Page To Include This File</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Use the indexmaker command and include your original MRTG configuration file from Chapter 22, &#8220;<a title="Quick HOWTO : Ch22 : Monitoring Server Performance" href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch22_:_Monitoring_Server_Performance">Monitoring Server Performance</a>&#8220;, (/etc/mrtg/mrtg.cfg) plus the new one you created (/etc/mrtg/server-stats.cfg).</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# indexmaker --output=/var/www/mrtg/index.html \
/etc/mrtg/mrtg.cfg /etc/mrtg/server-stats.cfg</pre>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Configuring cron To Use The New MRTG File</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The final step is to make sure that MRTG is configured to poll your server every five minutes using this new configuration file. To do so, add this line to your /etc/cron.d/mrtg file.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">0-59/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/server-stats.cfg</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Some versions of Linux require you to edit your /etc/crontab file instead. See Chapter 22, &#8220;<a title="Quick HOWTO : Ch22 : Monitoring Server Performance" href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch22_:_Monitoring_Server_Performance"> Monitoring Server Performance</a>&#8220;, for more details. You will also have to restart cron with the service crond restart for it to read its new configuration file that tells it to additionally run MRTG every five minutes using the new MRTG configuration file.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# service crond restart</pre>
<h1 style="color: green;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: #048444;font-size: 24px"><span>Monitoring Non Linux MIB Values</span></h1>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">All the MIBs mentioned so far are for Linux systems; other types of systems will need additional MIBs whose correct installation may be unclear in user guides or just not available. In such cases, you&#8217;ll need to know the exact value of the OID.</p>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Scenario</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Imagine that your small company has purchased a second-hand Cisco switch to connect its Web site servers to the Internet. The basic MRTG configuration shown in Chapter 22, &#8220;<a title="Quick HOWTO : Ch22 : Monitoring Server Performance" href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch22_:_Monitoring_Server_Performance"> Monitoring Server Performance</a>&#8220;, provides the data bandwidth statistics, but you want to measure the CPU load the traffic is having on the device, as well. Downloading MIBs from Cisco and using them with the snmpget command was not a success. You do not know what to do next. Find The OIDs</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">When MIB values fail, it is best to try to find the exact OID value. Like most network equipment manufacturers, Cisco has an FTP site from which you can download both MIBs and OIDs. The SNMP files for Cisco&#8217;s devices can be found at ftp.cisco.com in the /pub/mibs directory; OIDs are in the oid directory beneath that.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">After looking at all the OID files, you decide that the file CISCO-PROCESS-MIB.oid will contain the necessary values and find these entries inside it.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">"cpmCPUTotalPhysicalIndex"  "1.3.6.1.4.1.9.9.109.1.1.1.1.2"
"cpmCPUTotal5sec"           "1.3.6.1.4.1.9.9.109.1.1.1.1.3"
"cpmCPUTotal1min"           "1.3.6.1.4.1.9.9.109.1.1.1.1.4"
"cpmCPUTotal5min"           "1.3.6.1.4.1.9.9.109.1.1.1.1.5"
"cpmCPUTotal5secRev"        "1.3.6.1.4.1.9.9.109.1.1.1.1.6"
"cpmCPUTotal1minRev"        "1.3.6.1.4.1.9.9.109.1.1.1.1.7"
"cpmCPUTotal5minRev"        "1.3.6.1.4.1.9.9.109.1.1.1.1.8"</pre>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Testing The OIDs</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">As you can see, all the OIDs are a part of the same tree starting with 1.3.6.1.4.1.9.9.109.1.1.1.1. The OIDs provided may be incomplete, so it is best to use the snmpwalk command to try to get all the values below this root first.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# snmpwalk -v1 -c craz33guy cisco-switch 1.3.6.1.4.1..9.9.109.1.1.1.1
SNMPv2-SMI::enterprises.9.9.109.1.1.1.1.2.1 = INTEGER: 0
SNMPv2-SMI::enterprises.9.9.109.1.1.1.1.3.1 = Gauge32: 32
SNMPv2-SMI::enterprises.9.9.109.1.1.1.1.4.1 = Gauge32: 32
SNMPv2-SMI::enterprises.9.9.109.1.1.1.1.5.1 = Gauge32: 32
[root@bigboy tmp]#</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Although listed in the OID file, 1.1.1.1.6, 1.1.1.1.7, and 1.1.1.1.8 are not supported. Notice also how SNMP has determined that the first part of the OID value (1.3.6.1.4.1) in the original OID file maps to the word &#8220;enterprise&#8221;.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Next, you can use one the snmpget command to set only one of the OID values returned by snmpwalk.</p>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# snmpget -v1 -c craz33guy cisco-switch \
enterprises.9.9.109.1.1.1.1.5.1
SNMPv2-SMI::enterprises.9.9.109.1.1.1.1.5.1 = Gauge32: 33
[root@bigboy tmp]#</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Success! Now you can use this OID value, enterprises.9.9.109.1.1.1.1.5.1, for your MRTG queries.</p>
<h1 style="color: green;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: #048444;font-size: 24px"><span>Speeding up MRTG with RRDtool</span></h1>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">MRTG is a very useful program but it has a limitation. All the graphs and web pages are recreated each time a device is polled. This can potentially overload your MRTG server especially if you have a large number of monitored devices and the graphs take more than five minutes to generate. RRDtool is an application written by the creator of MRTG that can store general purpose data, but generates graphs on demand. Integrating MRTG with RRDtool can have very noticeable performance benefits. The example that follows will show you how to quickly implement a general purpose solution.</p>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Scenario</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The use of RRDtool is needed to reduce the load on a monitoring server that has been experiencing very sluggish performance due to the amount of MRTG graphs it has to regenerate every polling cycle.</p>
<ul>
<li>Due to space constraints, the RRD database needs to be located in the /var partition.</li>
<li>The server has a default Apache configuration with the CGI files needed for dynamically generated content being located in the /var/www/cgi-bin directory.</li>
<li>A CGI script is required that will read the new MRTG data in RRDtool format.</li>
<li>The MRTG configuration file is /etc/mrtg/mrtg.cfg.</li>
</ul>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Here&#8217;s how to proceed.</p>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Installing RRDtool</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The RRDtool and RRDtool PERL module file can be downloaded from its website at<a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/">http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/</a>, but installation can be tricky as the installation program may look for certain supporting libraries in the wrong directories.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Fortunately the prerequisite rrdtool and rrdtool-perl packages now come as part of most Linux distributions. For more details on installing packages, see Chapter 6, &#8220;<a title="Quick HOWTO : Ch06 : Installing Linux Software" href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch06_:_Installing_Linux_Software">Installing Linux Software</a>&#8220;).</p>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>Storing the MRTG Data in RRDtool Format</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">This phase of the integration process can be done in a few minutes, but the steps can be tricky:</p>
<ul>
<li>The first step is to add some new options to your cfgmaker command. The first indicates that MRTG should only store rrdtool formatted data, and the second defines the /var/mrtg directory in which it should be stored. For added security, the directory should be external to your web server&#8217;s document root.</li>
</ul>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">--global 'LogFormat: rrdtool' --global "workdir: /var/mrtg"  --global 'IconDir: /mrtg'</pre>
<dl>
<dd>Finally, you should also specify an icon directory which specifies the location of all miscellaneous MRTG web page icons. The RRD web interface script we&#8217;ll install later uses an incorrect location. The icon directory /mrtg is actually a partial URL location. In this Fedora scenario we are using the default Apache configuration which locates the MRTG icon files in the /var/www/mrtg directory. If you are using a non default Apache MRTG configuration or are using other Linux distributions or versions you may have to copy the icons to the custom directory in which the MRTG PNG format icon files are located.</dd>
</dl>
<dl>
<dd>The cfgmaker program is simple to use and is covered in in Chapter 22, &#8220;<a title="Quick HOWTO : Ch22 : Monitoring Server Performance" href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch22_:_Monitoring_Server_Performance">Monitoring Server Performance</a>&#8220;.</dd>
</dl>
<ul>
<li>The next step is to create the data repository directory /var/mrtg and make it be owned by the apache user and process that runs the default Linux web server application.</li>
</ul>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# mkdir /var/mrtg
[root@bigboy tmp]# chown apache /var/mrtg
[root@bigboy tmp]#</pre>
<dl>
<dd><strong>Note:</strong> If you are using SELinux you&#8217;ll have to change the context of this directory to match that of the /var/www/html directory so that the apache process will be able to read the database files when your CGI script needs them. These commands compare the contexts of the both directories and apply the correct set to /var/mrtg.</dd>
</dl>
<dl>
<dd>Please refer to Chapter 20, &#8220;<a title="Quick HOWTO : Ch20 : The Apache Web Server" href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch20_:_The_Apache_Web_Server"> The Apache Web Server</a>&#8221; for more details on file contexts with Apache.</dd>
</dl>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# ls -alZ /var/www | grep html
drwxr-xr-x  root     root     system_u:object_r:httpd_sys_content_t html
[root@bigboy tmp]# ls -alZ /var | grep mrtg
drwxr-xr-x  apache   root     root:object_r:var_t              mrtg
[root@bigboy tmp]# chcon -R -u system_u -r object_r -t httpd_sys_content_t /var/mrtg
[root@bigboy tmp]#</pre>
<ul>
<li>We now need to test that the RRD files are being created correctly. Run MRTG using the /etc/mrtg/mrtg.cfg file as the source configuration file then test to see if the contents of the /var/mrtg directory have changed. Success!</li>
</ul>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# ls /var/mrtg/
localhost_192.168.1.100.rrd
[root@bigboy tmp]#</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The files are being created properly. Now we need to find a script to read the new data format and present it in a web format. This will be discussed next.</p>
<h2 style="color: teal;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #aaaaaa;font-size: 19px"><span>The MRTG / RRDtool Integration Script</span></h2>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The MRTG website recommends the script located on the mrtg-rrd website (<a href="http://www.fi.muni.cz/~kas/mrtg-rrd/">http://www.fi.muni.cz/~kas/mrtg-rrd/</a>) as being a good one to use. Let&#8217;s go ahead and install it.</p>
<ul>
<li>Download the script using wget. The site lists several versions; make sure you get the latest one.</li>
</ul>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# wget <a href="ftp://ftp.linux.cz/pub/linux/people/jan_kasprzak/mrtg-rrd/mrtg-rrd-0.7.tar.gz">ftp://ftp.linux.cz/pub/linux/people/jan_kasprzak/mrtg-rrd/mrtg-rrd-0.7.tar.gz</a>
--12:42:12--  <a href="ftp://ftp.linux.cz/pub/linux/people/jan_kasprzak/mrtg-rrd/mrtg-rrd-0.7.tar.gz">ftp://ftp.linux.cz/pub/linux/people/jan_kasprzak/mrtg-rrd/mrtg-rrd-0.7.tar.gz</a>
           =&gt; `mrtg-rrd-0.7.tar.gz'
Resolving ftp.linux.cz... 147.251.48.205
Connecting to ftp.linux.cz|147.251.48.205|:21... connected.
Logging in as anonymous ... Logged in!
...
...
...
15:24:50 (53.53 KB/s) - `mrtg-rrd-0.7.tar.gz' saved [20863]
[root@bigboy tmp]# ls
mrtg-rrd-0.7.tar.gz
[root@bigboy tmp]#</pre>
<ul>
<li>Extract the contents of the tar file.</li>
</ul>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# tar -xzvf mrtg-rrd-0.7.tar.gz
mrtg-rrd-0.7/
mrtg-rrd-0.7/COPYING
mrtg-rrd-0.7/FAQ
mrtg-rrd-0.7/TODO
mrtg-rrd-0.7/Makefile
mrtg-rrd-0.7/mrtg-rrd.cgi
mrtg-rrd-0.7/ChangeLog
[root@bigboy tmp]#</pre>
<ul>
<li>Create the /var/www/cgi-bin/mrtg directory and copy the mrtg-rrd.cgi file to it.</li>
</ul>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[root@bigboy tmp]# mkdir -p /var/www/cgi-bin/mrtg
[root@bigboy tmp]# cp mrtg-rrd-0.7/mrtg-rrd.cgi /var/www/cgi-bin/mrtg/
[root@bigboy tmp]#</pre>
<ul>
<li>Edit the mrtg-rrd.cgi file and make it refer to the /etc/mrtg/mrtg.cfg file for its configuration details, or you can specify all the .cfg files in your /etc/mrtg directory.</li>
</ul>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">#
# File: mrtg-rrd.cgi (Single File)
#

# EDIT THIS to reflect all your MRTG config files
BEGIN { @config_files = qw(/etc/mrtg/mrtg.cfg); }</pre>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">#
# File: mrtg-rrd.cgi (multipl .cfg files)
#

# EDIT THIS to reflect all your MRTG config files
BEGIN { @config_files = &lt;/etc/mrtg/*.cfg&gt;; }</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">
<ul>
<li>You should now be able to access your MRTG RRD graphs by visiting this URL:</li>
</ul>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab"><a href="http://www.my-web-site.org/cgi-bin/mrtg/mrtg-rrd.cgi">http://www.my-web-site.org/cgi-bin/mrtg/mrtg-rrd.cgi</a></pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Once installed, RRDtool operates transparently with MRTG. You&#8217;ll have to remember to add the RRD statements to any new MRTG configurations and also add the configuration file to the CGI script. Our monitoring server can now breathe a little easier.</p>
<h1 style="color: green;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: #048444;font-size: 24px"><span>Troubleshooting</span></h1>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">The troubleshooting techniques for advanced MRTG are similar to those mentioned in Chapter 22, &#8220;<a title="Quick HOWTO : Ch22 : Monitoring Server Performance" href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch22_:_Monitoring_Server_Performance">Monitoring Server Performance</a>&#8220;, but because you have done some customizations you&#8217;ll have to go the extra mile.</p>
<ul>
<li>Verify the IP address and community string of the target device you intend to poll.</li>
<li>Make sure you can do an SNMP walk of the target device. If not, revise your access controls on the target device and any firewall rules that may impede SNMP traffic.</li>
<li>Ensure you can do an SNMP get of the specific OID value listed in your MRTG configuration file.</li>
<li>Check your MRTG parameters to make sure they are correct. Gauge values defined as counter and vice versa will cause your graphs to have continuous zero values. Graph results that are eight times what you expect may have the bits parameter set.</li>
<li>There are a few errors common to initial RRDtool integration.</li>
</ul>
<dl>
<dd>Web messages like this where the reference to the MRTG configuration file in the CGI script was incorrect</dd>
</dl>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Error: Cannot open config file: No such file or directory</pre>
<dl>
<dd>&#8220;Permission Denied&#8221; web messages are usually caused by incorrect file permissions and / or SELinux contexts</dd>
</dl>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">Error: RRDs::graph failed, opening '/var/mrtg/localhost_192.168.1.100.rrd': Permission denied</pre>
<dl>
<dd>Errors in the /var/log/httpd/errorlog file referring to files or directories that don&#8217;t exist can be caused by an incorrect IconDir statement in the MRTG configuration file.</dd>
</dl>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">[Wed Jan 04 15:42:13 2006] [error] [client 192.168.1.102] File does not exist: /var/www/html/var,
referer: <a href="http://bigboy/cgi-bin/mrtg/mrtg-rrd.cgi/">http://bigboy/cgi-bin/mrtg/mrtg-rrd.cgi/</a> 

[Wed Jan 04 15:45:46 2006] [error] [client 192.168.1.102] script not found or unable to stat:
 /var/www/cgi-bin/mrtg/mrtg-l.png, referer: <a href="http://bigboy/cgi-bin/mrtg/mrtg-rrd.cgi/">http://bigboy/cgi-bin/mrtg/mrtg-rrd.cgi/</a></pre>
<dl>
<dd>Errors caused by not installing the pre-requisite RRD RPM modules rrdtool, perl-RRD-Simple and rrdtool-perl.</dd>
</dl>
<pre style="color: black;background-color: #f9f9f9;line-height: 1.1em;padding: 1em;border: 1px dashed #2f6fab">ERROR: could not find RRDs.pm. Use LibAdd: in mrtg.cfg to help mrtg find RRDs.pm</pre>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">These quick steps should be sufficient in most cases and will reward you with a more manageable network.</p>
<h1 style="color: green;background-color: initial;font-weight: normal;margin-top: 0px;margin-right: 0px;margin-bottom: 0.6em;margin-left: 0px;padding-top: 0.5em;padding-bottom: 0.17em;border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: #048444;font-size: 24px"><span>Conclusion</span></h1>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">Using the guidelines in this chapter you should be able to graph most SNMP MIB values available on any type of device. MRTG is an excellent, flexible monitoring tool and should be considered as a part of any systems administrator&#8217;s server management plans.</p>
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">
<p style="margin-top: 0.4em;margin-right: 0px;margin-bottom: 0.5em;margin-left: 0px;line-height: 1.5em">SOURCE: <a href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch23_:_Advanced_MRTG_for_Linux">http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch23_:_Advanced_MRTG_for_Linux</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2010/12/02/advanced-mrtg-configurations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to DISABLE ipv6 in CentOS5 System</title>
		<link>http://blog.nataprawira.com/tech/2010/07/19/how-to-disable-ipv6-in-centos5-system/</link>
		<comments>http://blog.nataprawira.com/tech/2010/07/19/how-to-disable-ipv6-in-centos5-system/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 09:20:32 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[disable]]></category>
		<category><![CDATA[ipv6]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=163</guid>
		<description><![CDATA[

echo &#8220;NETWORKING_IPV6=no&#8221; &#62;&#62; /etc/sysconfig/network
echo &#8220;alias ipv6 off&#8221; &#62;&#62; /etc/modprobe.conf
echo &#8220;alias net-pf-10 off&#8221; &#62;&#62; /etc/modprobe.conf
reboot
# ifconfig
eth1      Link encap:Ethernet  HWaddr 00:1C:F0:BB:A7:28
inet addr:10.10.10.11  Bcast:10.10.10.255  Mask:255.255.255.0
 inet6 addr: fe80::21c:f0ff:febb:a728/64 Scope:Link
 UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:470449435 errors:1 dropped:0 overruns:0 frame:0
TX packets:464084402 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2563674692 (2.3 GiB)  TX bytes:2243518951 (2.0 GiB)
Interrupt:225 Base address:0&#215;2800
Don&#8217;t really [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F07%2F19%2Fhow-to-disable-ipv6-in-centos5-system%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F07%2F19%2Fhow-to-disable-ipv6-in-centos5-system%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<div id="_mcePaste" style="width: 1px;height: 1px">echo &#8220;NETWORKING_IPV6=no&#8221; &gt;&gt; /etc/sysconfig/network</div>
<div id="_mcePaste" style="width: 1px;height: 1px">echo &#8220;alias ipv6 off&#8221; &gt;&gt; /etc/modprobe.conf</div>
<div id="_mcePaste" style="width: 1px;height: 1px">echo &#8220;alias net-pf-10 off&#8221; &gt;&gt; /etc/modprobe.conf</div>
<div id="_mcePaste" style="width: 1px;height: 1px">reboot</div>
<p><strong># ifconfig</strong></p>
<blockquote><p>eth1      Link encap:Ethernet  HWaddr 00:1C:F0:BB:A7:28<br />
inet addr:10.10.10.11  Bcast:10.10.10.255  Mask:255.255.255.0<br />
<strong> inet6 addr: fe80::21c:f0ff:febb:a728/64 Scope:Link<br />
</strong> UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1<br />
RX packets:470449435 errors:1 dropped:0 overruns:0 frame:0<br />
TX packets:464084402 errors:0 dropped:0 overruns:0 carrier:0<br />
collisions:0 txqueuelen:1000<br />
RX bytes:2563674692 (2.3 GiB)  TX bytes:2243518951 (2.0 GiB)<br />
Interrupt:225 Base address:0&#215;2800</p></blockquote>
<div>Don&#8217;t really need of ipv6 to be run on your server. Want to disable it ?</div>
<p><span id="more-163"></span>Just run the following syntax&#8230;</p>
<p><em><span style="color: #993300">Make sure no such entries inside: </span></em><strong><em><span style="color: #333300">/etc/sysconfig/network</span></em></strong><em><span style="color: #993300"> and </span></em><strong><em><span style="color: #333300">/etc/modprobe.conf</span></em></strong><em><span style="color: #993300"> file <img src='http://blog.nataprawira.com/tech/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></em></p>
<blockquote><p># echo &#8220;NETWORKING_IPV6=no&#8221; &gt;&gt; /etc/sysconfig/network<br />
# echo &#8220;alias ipv6 off&#8221; &gt;&gt; /etc/modprobe.conf<br />
# echo &#8220;alias net-pf-10 off&#8221; &gt;&gt; /etc/modprobe.conf<br />
# reboot <span style="color: #0000ff"> </span><em><span style="color: #0000ff">(your server to make affect)</span></em></p></blockquote>
<p>Once reboot-ed, do :</p>
<p># ifconfig</p>
<blockquote><p>eth1      Link encap:Ethernet  HWaddr 00:1C:F0:BB:A7:28<br />
inet addr:10.10.10.11  Bcast:10.10.10.255  Mask:255.255.255.0<br />
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1<br />
RX packets:470471884 errors:1 dropped:0 overruns:0 frame:0<br />
TX packets:464109169 errors:0 dropped:0 overruns:0 carrier:0<br />
collisions:0 txqueuelen:1000<br />
RX bytes:2574513731 (2.3 GiB)  TX bytes:2255015395 (2.1 GiB)<br />
Interrupt:225 Base address:0&#215;2800</p></blockquote>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2010/07/19/how-to-disable-ipv6-in-centos5-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting a MySQL InnoDB Engine Conversion</title>
		<link>http://blog.nataprawira.com/tech/2010/07/11/scripting-a-mysql-innodb-engine-conversion/</link>
		<comments>http://blog.nataprawira.com/tech/2010/07/11/scripting-a-mysql-innodb-engine-conversion/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 19:50:08 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Conversion]]></category>
		<category><![CDATA[InnoDB]]></category>
		<category><![CDATA[MyISAM]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=161</guid>
		<description><![CDATA[

0) Backup your database.
You should probably be doing this already.  Now’s a good time to make sure that your backups ran.
 
1) Create the script.
You’ll need the correct permissions to query the database. Here’s the command.  Be sure to change &#60;DATABASE_NAME&#62; as it fits.
# mysql -p -e "show tables in &#60;DATABASE_NAME&#62;;" &#124; \
tail --lines=+2 &#124; [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F07%2F11%2Fscripting-a-mysql-innodb-engine-conversion%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F07%2F11%2Fscripting-a-mysql-innodb-engine-conversion%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<h3 style="font-family: 'Trebuchet MS', 'Lucida Grande', Verdana, Arial, sans-serif;font-weight: bold;font-size: 1.3em;color: #333333;text-decoration: none;margin-top: 30px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;padding: 0px"><span style="color: #000000;font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-weight: normal;font-size: 13px"><strong>0) Backup your database.<br />
</strong>You should probably be doing this already.  Now’s a good time to make sure that your backups ran.</span></h3>
<p><span style="color: #000000;font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-weight: normal;font-size: 13px"> </span></p>
<p><strong>1) Create the script.<br />
</strong>You’ll need the correct permissions to query the database. Here’s the command.  Be sure to change &lt;DATABASE_NAME&gt; as it fits.</p>
<p><code style="font: normal normal normal 1.1em/normal 'Courier New', Courier, Fixed"><strong><span style="color: #0000ff"># mysql -p -e "show tables in &lt;DATABASE_NAME&gt;;" | \<br />
tail --lines=+2 | \<br />
xargs -i echo "ALTER TABLE {} ENGINE=INNODB;" &gt; alter_table.sql</span></strong></code></p>
<p><strong>2) Run the script</strong>.</p>
<p><code style="font: normal normal normal 1.1em/normal 'Courier New', Courier, Fixed"><strong><span style="color: #0000ff"># mysql --database=&lt;DATABASE_NAME&gt; -p &lt; alter_table.sql</span></strong></code></p>
<p><strong>3) Verify</strong> it by running this command in mysql:</p>
<p><code style="font: normal normal normal 1.1em/normal 'Courier New', Courier, Fixed"><strong><span style="color: #0000ff">mysql&gt; show table status;</span></strong></code></p>
<p><span id="more-161"></span></p>
<p><strong><a title="http://technotes.twosmallcoins.com/?cat=268" href="http://technotes.twosmallcoins.com/?cat=268" target="_blank">SOURCE</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2010/07/11/scripting-a-mysql-innodb-engine-conversion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How To Getting Yesterdays or Tomorrows day with shell date command</title>
		<link>http://blog.nataprawira.com/tech/2010/06/29/how-to-getting-yesterdays-or-tomorrows-day-with-shell-date-command/</link>
		<comments>http://blog.nataprawira.com/tech/2010/06/29/how-to-getting-yesterdays-or-tomorrows-day-with-shell-date-command/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 18:37:22 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=146</guid>
		<description><![CDATA[

When invoked without arguments, the date command displays the current date and time. Depending on the options specified, date will set the date and time or print it in a user defined way. I’ve seen many people writing a perl script for calculating yesterday or tomorrow. Computer loves numbers but we love relative terms like [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F06%2F29%2Fhow-to-getting-yesterdays-or-tomorrows-day-with-shell-date-command%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F06%2F29%2Fhow-to-getting-yesterdays-or-tomorrows-day-with-shell-date-command%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">When invoked without arguments, the date command displays the current date and time. Depending on the options specified, date will set the date and time or print it in a user defined way. I’ve seen many people writing a perl script for calculating yesterday or tomorrow. Computer loves numbers but we love relative terms like 2 days ago. Luckily GNU date command is designed to handle relative date calculation.<span id="more-146"></span></p>
<h3 style="margin-top: 1.833em;margin-right: 0px;margin-bottom: 0.611em;margin-left: 0px;font-weight: normal;font-size: 1.286em;line-height: 1.222em;padding: 0px">Why use relative date formats?</h3>
<ul style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 1.571em;padding: 0px">
<li>Ease of use</li>
<li>To write your own scripts</li>
<li>Automate task using cron (example run a job on last day of the month or Nth day of the month or 3rd Friday and so on)</li>
</ul>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">First, print today&#8217;s date:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ <strong>date</strong></code><br />
Sun Jun 17 12:17:24 CDT 2007</p>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">Now display Yesterday&#8217;s date:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date --date="1 days ago"</code><br />
OR try:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date --date="yesterday"</code><br />
Sat Jun 16 12:17:20 CDT 2007</p>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">Now display Tomorrow&#8217;s date:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date --date="-1 days ago"</code><br />
Or better try:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date --date="next day"</code><br />
Sat Jun 16 12:17:20 CDT 2007</p>
<h3 style="margin-top: 1.833em;margin-right: 0px;margin-bottom: 0.611em;margin-left: 0px;font-weight: normal;font-size: 1.286em;line-height: 1.222em;padding: 0px">Getting date in the future</h3>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">To get tomorrow and day after tomorrow (tomorrow+N) use <strong>day</strong> word to get date in the future.</p>
<h3 style="margin-top: 1.833em;margin-right: 0px;margin-bottom: 0.611em;margin-left: 0px;font-weight: normal;font-size: 1.286em;line-height: 1.222em;padding: 0px">Getting date in the past</h3>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">To get yesterday and earlier day in the past use string <strong>day ago</strong>:</p>
<h3 style="margin-top: 1.833em;margin-right: 0px;margin-bottom: 0.611em;margin-left: 0px;font-weight: normal;font-size: 1.286em;line-height: 1.222em;padding: 0px">Moving by whole years or months</h3>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">You can add year and months keywords to get more accurate date:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date --date='2 year ago' # past<br />
$ date --date='3 years' # go into future<br />
$ date --date='2 days' # future<br />
$ date --date='1 month ago' # past<br />
$ date --date='2 months' # future</code></p>
<h3 style="margin-top: 1.833em;margin-right: 0px;margin-bottom: 0.611em;margin-left: 0px;font-weight: normal;font-size: 1.286em;line-height: 1.222em;padding: 0px">Moving date using more precise units</h3>
<ul style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 1.571em;padding: 0px">
<li>You can use fortnight for 14 day</li>
<li>Week for 7 days</li>
<li>hour for 60 minutes</li>
<li>minute for 60 seconds</li>
<li>second for one second</li>
<li>You can also use this / now / today keywords to stress the meaning</li>
</ul>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">To print the date of this Friday:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date --date='this Friday'</code><br />
To print the date of the day six months and 15 day<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date --date='6 months 15 day'</code><br />
To print the date of the day two months and 5 days ago:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date --date='2 months 5 day ago'</code></p>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">You can also use relative format to setup date and time. For example to set the system clock forward by 30 minutes, enter:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd"># date --set='+30 minutes'</code></p>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">To display date in <a href="http://en.wikipedia.org/wiki/Unix_time">epoch time</a>:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date --date='1970-01-01 00:00:01 UTC +5 hours' +%s</code></p>
<h4 style="font-weight: bold;font-size: 1em;padding: 0px;margin: 0px"><a href="http://www.cyberciti.biz/tips/linux-unix-get-yesterdays-tomorrows-date.html" target="_blank">SOURCE</a></h4>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2010/06/29/how-to-getting-yesterdays-or-tomorrows-day-with-shell-date-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to format date for display or to use in a shell script</title>
		<link>http://blog.nataprawira.com/tech/2010/06/29/how-to-format-date-for-display-or-to-use-in-a-shell-script/</link>
		<comments>http://blog.nataprawira.com/tech/2010/06/29/how-to-format-date-for-display-or-to-use-in-a-shell-script/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 18:35:12 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=144</guid>
		<description><![CDATA[

Q. How do I format date to display on screen on for my scripts as per my requirements?
A. You need to use standard date command to format date or time for output or to use in a shell script.
Syntax to specify format
date +FORMAT

Task: Display date in mm-dd-yy format
Type the command as follows:
$ date +"%m-%d-%y"
Output:
02-27-07
Turn on 4 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F06%2F29%2Fhow-to-format-date-for-display-or-to-use-in-a-shell-script%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F06%2F29%2Fhow-to-format-date-for-display-or-to-use-in-a-shell-script%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">Q. How do I format date to display on screen on for my scripts as per my requirements?</p>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">A. You need to use standard date command to format date or time for output or to use in a shell script.</p>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">Syntax to specify format<br />
<strong>date <span style="color: #ff0000;padding: 0px;margin: 0px">+FORMAT<span id="more-144"></span><br />
</span></strong></p>
<h3 style="margin-top: 1.833em;margin-right: 0px;margin-bottom: 0.611em;margin-left: 0px;font-weight: normal;font-size: 1.286em;line-height: 1.222em;padding: 0px">Task: Display date in mm-dd-yy format</h3>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">Type the command as follows:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date +"%m-%d-%y"</code><br />
Output:</p>
<pre style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;background-color: #eeeeee;clear: both;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;line-height: 1.5em;border: 1px solid #dddddd">02-27-07</pre>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">Turn on 4 digit year display:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date +"%m-%d-%Y"</code><br />
Just display date as mm/dd/yy format:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date +"%D"</code></p>
<h3 style="margin-top: 1.833em;margin-right: 0px;margin-bottom: 0.611em;margin-left: 0px;font-weight: normal;font-size: 1.286em;line-height: 1.222em;padding: 0px">Task: Display time only</h3>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">Type the command as follows:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date +"%T"</code><br />
Output:</p>
<pre style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;background-color: #eeeeee;clear: both;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;line-height: 1.5em;border: 1px solid #dddddd">19:55:04</pre>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">Display locale’s 12-hour clock time<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date +"%r"</code><br />
Output:</p>
<pre style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;background-color: #eeeeee;clear: both;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;line-height: 1.5em;border: 1px solid #dddddd">07:56:05 PM</pre>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">Display time in HH:MM format:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ date +"%H-%M"</code></p>
<h3 style="margin-top: 1.833em;margin-right: 0px;margin-bottom: 0.611em;margin-left: 0px;font-weight: normal;font-size: 1.286em;line-height: 1.222em;padding: 0px">How do I save time/date format to a variable?</h3>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">Simply type command as follows at a shell prompt:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ NOW=$(date +"%m-%d-%Y")</code><br />
To display a variable use <a href="http://www.cyberciti.biz/faq/how-to-write-output-to-terminal/" target="_blank">echo / printf command</a>:<br />
<code style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;line-height: 1.5em;background-color: #eeeeee;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;border: 1px solid #dddddd">$ echo $NOW</code><br />
Sample shell script:</p>
<pre style="padding-top: 0.667em;padding-right: 0.917em;padding-bottom: 0.667em;padding-left: 0.917em;margin-top: 0px;margin-right: 0px;margin-bottom: 1.833em;margin-left: 0px;background-color: #eeeeee;clear: both;font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif;font-size: 0.857em;line-height: 1.5em;border: 1px solid #dddddd">#!/bin/bash
NOW=$(date +"%m-%d-%Y")
FILE="backup.$NOW.tar.gz"
# rest of script</pre>
<h3 style="margin-top: 1.833em;margin-right: 0px;margin-bottom: 0.611em;margin-left: 0px;font-weight: normal;font-size: 1.286em;line-height: 1.222em;padding: 0px">Complete list of FORMAT control characters supported by date command</h3>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">FORMAT controls the output.It can be the combination of any one of the following:</p>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">
<dl>
<dt>%%</dt>
<dd>a literal %</dd>
<dt>%a</dt>
<dd>locale&#8217;s abbreviated weekday name (e.g., Sun)</dd>
<dt>%A</dt>
<dd>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">locale&#8217;s full weekday name (e.g., Sunday)</p>
</dd>
<dt>%b</dt>
<dd>locale&#8217;s abbreviated month name (e.g., Jan)</dd>
<dt>%B</dt>
<dd>locale&#8217;s full month name (e.g., January)</dd>
<dt>%c</dt>
<dd>locale&#8217;s date and time (e.g., Thu Mar 3 23:05:25 2005)</dd>
<dt>%C</dt>
<dd>century; like %Y, except omit last two digits (e.g., 21)</dd>
<dt>%d</dt>
<dd>day of month (e.g, 01)</dd>
<dt>%D</dt>
<dd>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">date; same as %m/%d/%y</p>
</dd>
<dt>%e</dt>
<dd>day of month, space padded; same as %_d</dd>
<dt>%F</dt>
<dd>full date; same as %Y-%m-%d</dd>
<dt>%g</dt>
<dd>last two digits of year of ISO week number (see %G)</dd>
<dt>%G</dt>
<dd>year of ISO week number (see %V); normally useful only with %V</dd>
<dt>%h</dt>
<dd>same as %b</dd>
<dt>%H</dt>
<dd>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">hour (00..23)</p>
</dd>
<dt>%I</dt>
<dd>hour (01..12)</dd>
<dt>%j</dt>
<dd>day of year (001..366)</dd>
<dt>%k</dt>
<dd>hour ( 0..23)</dd>
<dt>%l</dt>
<dd>hour ( 1..12)</dd>
<dt>%m</dt>
<dd>month (01..12)</dd>
<dt>%M</dt>
<dd>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">minute (00..59)</p>
</dd>
<dt>%n</dt>
<dd>a newline</dd>
<dt>%N</dt>
<dd>nanoseconds (000000000..999999999)</dd>
<dt>%p</dt>
<dd>locale&#8217;s equivalent of either AM or PM; blank if not known</dd>
<dt>%P</dt>
<dd>like %p, but lower case</dd>
<dt>%r</dt>
<dd>locale&#8217;s 12-hour clock time (e.g., 11:11:04 PM)</dd>
<dt>%R</dt>
<dd>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">24-hour hour and minute; same as %H:%M</p>
</dd>
<dt>%s</dt>
<dd>seconds since 1970-01-01 00:00:00 UTC</dd>
<dt>%S</dt>
<dd>second (00..60)</dd>
<dt>%t</dt>
<dd>a tab</dd>
<dt>%T</dt>
<dd>time; same as %H:%M:%S</dd>
<dt>%u</dt>
<dd>day of week (1..7); 1 is Monday</dd>
<dt>%U</dt>
<dd>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">week number of year, with Sunday as first day of week (00..53)</p>
</dd>
<dt>%V</dt>
<dd>ISO week number, with Monday as first day of week (01..53)</dd>
<dt>%w</dt>
<dd>day of week (0..6); 0 is Sunday</dd>
<dt>%W</dt>
<dd>week number of year, with Monday as first day of week (00..53)</dd>
<dt>%x</dt>
<dd>locale&#8217;s date representation (e.g., 12/31/99)</dd>
<dt>%X</dt>
<dd>locale&#8217;s time representation (e.g., 23:13:48)</dd>
<dt>%y</dt>
<dd>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">last two digits of year (00..99)</p>
</dd>
<dt>%Y</dt>
<dd>year</dd>
<dt>%z</dt>
<dd>+hhmm numeric timezone (e.g., <strong>-0400</strong>)</dd>
<dt>%:z</dt>
<dd>+hh:mm numeric timezone (e.g., <strong>-04</strong>:00)</dd>
<dt>%::z</dt>
<dd>+hh:mm:ss numeric time zone (e.g., <strong>-04</strong>:00:00)</p>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px">
</dd>
<dt>%:::z</dt>
<dd>numeric time zone with : to necessary precision (e.g., <strong>-04</strong>, +05:30)</dd>
<dt>%Z</dt>
<dd>alphabetic time zone abbreviation (e.g., EDT)</dd>
</dl>
<p style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 0px;padding: 0px"><a href="http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/" target="_blank"><strong> SOURCE</strong></a></p>
<h3 style="margin-top: 1.833em;margin-right: 0px;margin-bottom: 0.611em;margin-left: 0px;font-weight: normal;font-size: 1.286em;line-height: 1.222em;padding: 0px">See also:</h3>
<ul style="margin-top: 0px;margin-right: 0px;margin-bottom: 1.571em;margin-left: 1.571em;padding: 0px">
<li><a href="http://www.cyberciti.biz/tips/shell-scripting-creating-reportlog-file-names-with-date-in-filename.html" target="_blank">Shell Scripting: Creating report/log file names with date in filename</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2010/06/29/how-to-format-date-for-display-or-to-use-in-a-shell-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up DomainKeys on Centos</title>
		<link>http://blog.nataprawira.com/tech/2010/03/09/setting-up-domainkeys-on-centos/</link>
		<comments>http://blog.nataprawira.com/tech/2010/03/09/setting-up-domainkeys-on-centos/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 14:30:22 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Sendmail]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[DKIM]]></category>
		<category><![CDATA[DomainKeys]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=140</guid>
		<description><![CDATA[

This is a quick walk through on how to set up domain keys on Centos 5 using sendmail. It should also be very similar for Redhat or Fedora.

Domainkeys is a method mostly used by yahoo to verify that the sender of an email is valid. I did notice that gmail changes the domainkeys header line [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F03%2F09%2Fsetting-up-domainkeys-on-centos%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2010%2F03%2F09%2Fsetting-up-domainkeys-on-centos%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<h2><span style="font-weight: normal;font-size: 13px">This is a quick walk through on how to set up domain keys on Centos 5 using sendmail. It should also be very similar for Redhat or Fedora.</span></h2>
<div>
<p>Domainkeys is a method mostly used by yahoo to verify that the sender of an email is valid. I did notice that gmail changes the domainkeys header line to a pass value but I don’t know if they block/accept mail based on that.<span id="more-140"></span></p>
<p>First install some dependencies.</p>
<blockquote><p><strong>yum install sendmail-devel openssl-devel</strong></p></blockquote>
<p>First download the latest version of dk-milter by going to http://sourceforge.net/projects/dk-milter/</p>
<blockquote><p><strong>cd /usr/src/<br />
wget http://downloads.sourceforge.net/dk-milter/dk-milter-1.0.0.tar.gz</strong></p></blockquote>
<p>Then extract it using the command</p>
<blockquote><p><strong>tar xzf dk-milter-1.0.0.tar.gz<br />
cd dk-milter-2.6.0</strong></p></blockquote>
<p>Start by copying the sample config file to the proper directory and the make/make installing</p>
<blockquote><p><strong>cp site.config.m4.dist devtools/Site/site.config.m4<br />
make; make install</strong></p>
<p><span> </span></p></blockquote>
<p>You may see a few errors during the install, as long as they are just about creating the man pages you should be alright. Now change back to a good working directory and create your new keys.</p>
<blockquote><p><strong>cd ~/ssl-gen<br />
openssl genrsa -out rsa.private 768<br />
openssl rsa -in rsa.private -out rsa.public -pubout -outform PEM</strong></p></blockquote>
<p>Make the directory and move the private key into it.</p>
<blockquote><p><strong>mkdir -p /var/db/domainkeys/<br />
cp rsa.private /var/db/domainkeys/mail.key.pem</strong></p></blockquote>
<p>Now we should set up our DNS TXT records with our public key. This is how it should look in a bind zone file. Put the public key only and not the “BEGIN RSA PRIVATE…” or “END RSA…” parts of the key with out parenthesis.</p>
<blockquote><p><strong>mail._domainkey.jkurtzman.com.         IN TXT  “k=rsa; t=y; p=(Paste the public key here)”<br />
_domainkey.jkurtzman.com.                 IN TXT  “t=y; o=~”</strong></p></blockquote>
<p>You can use the following command to verify that your TXT record was set up correctly.</p>
<blockquote><p><strong>dig +short mail._domainkey.jkurtzman.com TXT</strong></p></blockquote>
<p>Now we will need to make the init script so the it starts when the computer reboots. Put the following into a file called <strong>/etc/init.d/domainkeys</strong>. Of course be sure to change the domain to your own domain. Remember to fix any lines that have wrapped when copying. Especially the COMMAND line.</p>
<blockquote><p><strong>#!/bin/sh<br />
#<br />
# “/etc/rc.d/init.d/dk-filter”<br />
# Start/stop script for the dk-filter daemon on RedHat Linux<br />
#<br />
# chkconfig: – 79 31<br />
# description: Acts as the “dk-filter” InputMailFilter (milter) for the \<br />
# Sendmail MTA to provide DomainKeys service</strong></p>
<p><strong>############################################################<br />
#<br />
# Be sure to edit these values:<br />
#<br />
KEYFILE=”/var/db/domainkeys/mail.key.pem”<br />
DOMAIN=”jkurtzman.com”<br />
SELECTOR=”mail”<br />
USER=”domainkeys”<br />
#<br />
############################################################</strong></p>
<p><strong>PIDFILE=”/var/run/dk-milter/pid”<br />
SUBMISSION_DAEMON=”smtp”<br />
PORT=8891</strong></p>
<p><strong># Source function library. Provides the “status” option<br />
. /etc/init.d/functions</strong></p>
<p><strong>test -x `which dk-filter` || exit 0</strong></p>
<p><strong>RETVAL=0</strong></p>
<p><strong>start() {<br />
echo -n $”Starting dk-filter: ”<br />
COMMAND=”dk-filter -u $USER -b s -p inet:$PORT@localhost -l -P $PIDFILE -s $KEYFILE -d $DOMAIN -S $SELECTOR -m$SUBMISSION_DAEMON -c nofws”<br />
# echo -e “Now executing\n”$COMMAND”&#8221;<br />
daemon $COMMAND<br />
RETVAL=$?<br />
echo<br />
[ $RETVAL -eq 0 ] &amp;&amp; touch /var/lock/subsys/dk-filter<br />
return $RETVAL<br />
}</strong></p>
<p><strong>stop() {<br />
echo -n $”Stopping dk-filter: ”<br />
killproc dk-filter<br />
RETVAL=$?<br />
echo<br />
[ $RETVAL -eq 0 ] &amp;&amp; rm -f $PIDFILE /var/lock/subsys/dk-filter<br />
return $RETVAL<br />
}</strong></p>
<p><strong>restart() {<br />
stop<br />
start<br />
}</strong></p>
<p><strong>case “$1″ in<br />
start)<br />
start<br />
;;<br />
stop)<br />
stop<br />
;;<br />
status)<br />
status dk-filter<br />
;;<br />
restart)<br />
restart<br />
;;<br />
*)<br />
echo $”Usage: $0 {start|stop|status|restart}”<br />
exit 1<br />
esac</strong></p>
<p><strong>exit $?</strong></p></blockquote>
<p>Give your new file execute permisions, create a user for domain keys to run as, and start it</p>
<blockquote><p><strong>chmod +x /etc/init.d/domainkeys<br />
useradd domainkeys<br />
service domainkeys start</strong></p></blockquote>
<p>If everything work you should see that the dk-filter has started.<br />
Now run chkconfig so the service starts when you reboot.</p>
<blockquote><p><strong>chkconfig domainkeys on</strong></p></blockquote>
<p>Now add this to your /etc/mail/sendmail.mc file.</p>
<blockquote><p><strong>INPUT_MAIL_FILTER(`dk-filter’, `S=inet:8891@localhost’)</strong></p></blockquote>
<p>And make and restart sendmail.</p>
<blockquote><p><strong>cd /etc/mail<br />
make<br />
service sendmail restart</strong></p></blockquote>
<p>You should now be able to send email and be domainkey verified. If you are relaying mail through the mail server you will need to make sure you are using SMTP Authentication otherwise the  dk-filter will not add the header information.</p>
<p>Try sending an email to a yahoo account and see if you get secure icon.</p>
<p><span style="font-family: 'Trebuchet MS';font-size: x-small"> </span></p>
<h1><span style="font-family: 'Trebuchet MS'">Source:</span></h1>
<h1><span style="font-family: 'Trebuchet MS'"><a href="http://luxio.us/cMZ11e" target="_blank">http://luxio.us/cMZ11e </a></span></h1>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2010/03/09/setting-up-domainkeys-on-centos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setup a transparent proxy with 3 easy steps</title>
		<link>http://blog.nataprawira.com/tech/2009/12/18/setup-a-transparent-proxy-with-3-easy-steps/</link>
		<comments>http://blog.nataprawira.com/tech/2009/12/18/setup-a-transparent-proxy-with-3-easy-steps/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 14:57:30 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[Transparent Proxy]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=127</guid>
		<description><![CDATA[

First, Squid server installed (use up2date squid) and configured by adding following directives to file:
# vi /etc/squid/squid.conf


Modify or add following squid directives:
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
acl lan src 192.168.1.1 192.168.2.0/24
http_access allow localhost
http_access allow lan
Where,

httpd_accel_host virtual: Squid as an httpd accelerator
httpd_accel_port 80: 80 is port you want to act as a proxy
httpd_accel_with_proxy on: Squid act as [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F12%2F18%2Fsetup-a-transparent-proxy-with-3-easy-steps%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F12%2F18%2Fsetup-a-transparent-proxy-with-3-easy-steps%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>First, Squid server installed (use up2date squid) and configured by adding following directives to file:<br />
<strong><code># vi /etc/squid/squid.conf</code></strong></p>
<p><strong><span id="more-127"></span><br />
</strong></p>
<p>Modify or add following squid directives:<br />
<strong><code>httpd_accel_host <span style="color: #ff0000">virtual</span><br />
httpd_accel_port <span style="color: #ff0000">80</span><br />
httpd_accel_with_proxy <span style="color: #ff0000">on</span><br />
httpd_accel_uses_host_header <span style="color: #ff0000">on</span><br />
acl lan src <span style="color: #ff0000">192.168.1.1 192.168.2.0/24</span><br />
http_access allow <span style="color: #ff0000">localhost</span><br />
http_access allow <span style="color: #ff0000">lan</span></code></strong></p>
<p>Where,</p>
<ul>
<li>httpd_accel_host <span style="color: #ff0000">virtual</span>: Squid as an httpd accelerator</li>
<li>httpd_accel_port <span style="color: #ff0000">80</span>: 80 is port you want to act as a proxy</li>
<li>httpd_accel_with_proxy <span style="color: #ff0000">on</span>: Squid act as both a local httpd accelerator and as a proxy.</li>
<li>httpd_accel_uses_host_header <span style="color: #ff0000">on</span>: Header is turned on which is the hostname from the URL.</li>
<li>acl lan src <span style="color: #ff0000">192.168.1.1 192.168.2.0/24</span>: Access control list, only allow LAN computers to use squid</li>
<li>http_access allow <span style="color: #ff0000">localhost</span>: Squid access to LAN and localhost ACL only</li>
<li>http_access allow <span style="color: #ff0000">lan</span>: &#8212; same as above &#8211;</li>
</ul>
<p>Here is the complete listing of squid.conf for your reference (grep will remove all comments and sed will remove all empty lines, thanks to David Klein for quick hint ):<br />
<strong><code># grep -v "^#" /etc/squid/squid.conf | sed -e '/^$/d'</code></strong></p>
<p>OR, try out sed (thanks to <a href="http://www.cyberciti.biz/tips/linux-setup-transparent-proxy-squid-howto.html#comment-144">kotnik</a> for small sed trick)<br />
<strong><code># cat /etc/squid/squid.conf | sed '/ *#/d; /^ *$/d'</code></strong></p>
<p>Output:<br />
<strong><code>hierarchy_stoplist cgi-bin ?<br />
acl QUERY urlpath_regex cgi-bin \?<br />
no_cache deny QUERY<br />
hosts_file /etc/hosts<br />
refresh_pattern ^ftp:           1440    20%     10080<br />
refresh_pattern ^gopher:        1440    0%      1440<br />
refresh_pattern .               0       20%     4320<br />
acl all src 0.0.0.0/0.0.0.0<br />
acl manager proto cache_object<br />
acl localhost src 127.0.0.1/255.255.255.255<br />
acl to_localhost dst 127.0.0.0/8<br />
acl purge method PURGE<br />
acl CONNECT method CONNECT<br />
cache_mem 1024 MB<br />
http_access allow manager localhost<br />
http_access deny manager<br />
http_access allow purge localhost<br />
http_access deny purge<br />
http_access deny !Safe_ports<br />
http_access deny CONNECT !SSL_ports<br />
acl lan src 192.168.1.1  192.168.2.0/24<br />
http_access allow localhost<br />
http_access allow lan<br />
http_access deny all<br />
http_reply_access allow all<br />
icp_access allow all<br />
visible_hostname myclient.hostname.com<br />
httpd_accel_host virtual<br />
httpd_accel_port 80<br />
httpd_accel_with_proxy on<br />
httpd_accel_uses_host_header on<br />
coredump_dir /var/spool/squid</code></strong></p>
<h3>Iptables configuration</h3>
<p>Next, I had added following rules to forward all http requests (coming to port 80) to the Squid server port 3128 :<br />
<strong><code>iptables -t nat -A PREROUTING -i  <span style="color: #ff0000">eth1</span> -p tcp --dport <span style="color: #ff0000">80</span> -j DNAT --to 192.168.1.1:3128<br />
iptables -t nat -A PREROUTING -i  <span style="color: #ff0000">eth0</span> -p tcp --dport  <span style="color: #ff0000">80 -j REDIRECT --to-port 3128</span></code></strong></p>
<p>Here is complete shell script. Script first configure Linux system as router and forwards all http request to port 3128 (Download the <a href="http://www.cyberciti.biz/tips/wp-content/uploads/2006/06/fw.proxy.txt">fw.proxy</a> shell script):<br />
<strong><code><em><span style="color: #9a1900">#!/bin/sh</span></em><br />
<em><span style="color: #9a1900"># squid server IP</span></em><br />
SQUID_SERVER<span style="color: #990000">=</span><span style="color: #ff0000">"192.168.1.1"</span><br />
<em><span style="color: #9a1900"># Interface connected to Internet</span></em><br />
INTERNET<span style="color: #990000">=</span><span style="color: #ff0000">"eth0"</span><br />
<em><span style="color: #9a1900"># Interface connected to LAN</span></em><br />
LAN_IN<span style="color: #990000">=</span><span style="color: #ff0000">"eth1"</span><br />
<em><span style="color: #9a1900"># Squid port</span></em><br />
SQUID_PORT<span style="color: #990000">=</span><span style="color: #ff0000">"3128"</span><br />
<em><span style="color: #9a1900"># DO NOT MODIFY BELOW</span></em><br />
<em><span style="color: #9a1900"># Clean old firewall</span></em><br />
iptables <span style="color: #990000">-</span>F<br />
iptables <span style="color: #990000">-</span>X<br />
iptables <span style="color: #990000">-</span>t nat <span style="color: #990000">-</span>F<br />
iptables <span style="color: #990000">-</span>t nat <span style="color: #990000">-</span>X<br />
iptables <span style="color: #990000">-</span>t mangle <span style="color: #990000">-</span>F<br />
iptables <span style="color: #990000">-</span>t mangle <span style="color: #990000">-</span>X<br />
<em><span style="color: #9a1900"># Load IPTABLES modules for NAT and IP conntrack support</span></em><br />
modprobe ip_conntrack<br />
modprobe ip_conntrack_ftp<br />
<em><span style="color: #9a1900"># For win xp ftp client</span></em><br />
<em><span style="color: #9a1900">#modprobe ip_nat_ftp</span></em><br />
echo <span style="color: #993399">1</span> <span style="color: #990000">&gt;</span> /proc/sys/net/ipv4/<span style="color: #0000ff">ip_forward</span><br />
<em><span style="color: #9a1900"># Setting default filter policy</span></em><br />
iptables <span style="color: #990000">-</span>P INPUT DROP<br />
iptables <span style="color: #990000">-</span>P OUTPUT ACCEPT<br />
<em><span style="color: #9a1900"># Unlimited access to loop back</span></em><br />
iptables <span style="color: #990000">-</span>A INPUT <span style="color: #990000">-</span>i lo <span style="color: #990000">-</span>j ACCEPT<br />
iptables <span style="color: #990000">-</span>A OUTPUT <span style="color: #990000">-</span>o lo <span style="color: #990000">-</span>j ACCEPT<br />
<em><span style="color: #9a1900"># Allow UDP, DNS and Passive FTP</span></em><br />
iptables <span style="color: #990000">-</span>A INPUT <span style="color: #990000">-</span>i <span style="color: #009900">$INTERNET</span> <span style="color: #990000">-</span><span style="color: #0000ff">m</span> state <span style="color: #990000">-</span><span style="color: #990000">-</span>state ESTABLISHED<span style="color: #990000">,</span>RELATED <span style="color: #990000">-</span>j ACCEPT<br />
<em><span style="color: #9a1900"># set this system as a router for Rest of LAN</span></em><br />
iptables <span style="color: #990000">-</span><span style="color: #990000">-</span>table nat <span style="color: #990000">-</span><span style="color: #990000">-</span>append POSTROUTING <span style="color: #990000">-</span><span style="color: #990000">-</span>out<span style="color: #990000">-</span>interface <span style="color: #009900">$INTERNET</span> <span style="color: #990000">-</span>j MASQUERADE<br />
iptables <span style="color: #990000">-</span><span style="color: #990000">-</span>append FORWARD <span style="color: #990000">-</span><span style="color: #990000">-</span>in<span style="color: #990000">-</span>interface <span style="color: #009900">$LAN_IN</span> <span style="color: #990000">-</span>j ACCEPT<br />
<em><span style="color: #9a1900"># unlimited access to LAN</span></em><br />
iptables <span style="color: #990000">-</span>A INPUT <span style="color: #990000">-</span>i <span style="color: #009900">$LAN_IN</span> <span style="color: #990000">-</span>j ACCEPT<br />
iptables <span style="color: #990000">-</span>A OUTPUT <span style="color: #990000">-</span>o <span style="color: #009900">$LAN_IN</span> <span style="color: #990000">-</span>j ACCEPT<br />
<em><span style="color: #9a1900"># DNAT port 80 request comming from LAN systems to squid 3128 ($SQUID_PORT) aka transparent proxy</span></em><br />
iptables <span style="color: #990000">-</span>t nat <span style="color: #990000">-</span>A PREROUTING <span style="color: #990000">-</span>i <span style="color: #009900">$LAN_IN</span> <span style="color: #990000">-</span>p tcp <span style="color: #990000">-</span><span style="color: #990000">-</span>dport <span style="color: #993399">80</span> <span style="color: #990000">-</span>j DNAT <span style="color: #990000">-</span><span style="color: #990000">-</span>to <span style="color: #009900">$SQUID_SERVER</span><span style="color: #990000">:</span><span style="color: #009900">$SQUID_PORT</span><br />
<em><span style="color: #9a1900"># if it is same system</span></em><br />
iptables <span style="color: #990000">-</span>t nat <span style="color: #990000">-</span>A PREROUTING <span style="color: #990000">-</span>i <span style="color: #009900">$INTERNET</span> <span style="color: #990000">-</span>p tcp <span style="color: #990000">-</span><span style="color: #990000">-</span>dport <span style="color: #993399">80</span> <span style="color: #990000">-</span>j REDIRECT <span style="color: #990000">-</span><span style="color: #990000">-</span>to<span style="color: #990000">-</span>port <span style="color: #009900">$SQUID_PORT</span><br />
<em><span style="color: #9a1900"># DROP everything and Log it</span></em><br />
iptables <span style="color: #990000">-</span>A INPUT <span style="color: #990000">-</span>j LOG<br />
iptables <span style="color: #990000">-</span>A INPUT <span style="color: #990000">-</span>j DROP</code></strong></p>
<p>Save shell script. Execute script so that system will act as a router and forward the ports:<br />
<strong><code># chmod +x /etc/fw.proxy<br />
# /etc/fw.proxy<br />
# service iptables save<br />
# chkconfig iptables on</code></strong></p>
<p>Start or Restart the squid:<br />
<strong><code># /etc/init.d/squid restart<br />
# chkconfig squid on</code></strong></p>
<h3>Desktop / Client computer configuration</h3>
<p>Point all desktop clients to your eth1 IP address (192.168.2.1) as Router/Gateway (use DHCP to distribute this information). You do not have to setup up individual browsers to work with proxies.</p>
<h3>How do I test my squid proxy is working correctly?</h3>
<p>See access log file /var/log/squid/access.log:<br />
<strong><code># tail -f /var/log/squid/access.log</code></strong></p>
<p>Above command will monitor all incoming request and log them to /var/log/squid/access_log file. Now if somebody accessing a website through browser, squid will log information.</p>
<h3>Problems and solutions</h3>
<h4>(a) Windows XP FTP Client</h4>
<p>All Desktop client FTP session request ended with an error:<br />
Illegal PORT command.</p>
<p>I had loaded the ip_nat_ftp kernel module. Just type the following command press Enter and voila!<br />
<strong><code># modprobe ip_nat_ftp</code></strong></p>
<p>Please note that modprobe command is already added to a shell script (above).</p>
<h4>(b) Port 443 redirection</h4>
<p>I had block out all connection request from our router settings except for our proxy (192.168.1.1) server. So all ports including 443 (https/ssl) request denied. You cannot redirect port 443, from <a href="http://lists.debian.org/debian-user/2004/05/msg01434.html">debian mailing list</a>, &#8220;<em>Long answer: SSL is specifically designed to prevent &#8220;man in the middle&#8221; attacks, and setting up squid in such a way would be the same as such a &#8220;man in the middle&#8221; attack. You might be able to successfully achive this, but not without breaking the encryption and certification that is the point behind SSL</em>&#8220;.</p>
<p>Therefore, I had quickly reopen port 443 (router firewall) for all my LAN computers and problem was solved.</p>
<h4>(c) Squid Proxy authentication in a transparent mode</h4>
<p>You cannot use Squid authentication with a transparently intercepting proxy.</p>
<h3>Further reading:</h3>
<ul>
<li><a href="http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/10/how-do-i-use-iptables-connection.html">How do I use Iptables connection tracking feature? </a></li>
<li><a href="http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/10/how-do-i-build-simple-linux-firewall.html">How do I build a Simple Linux Firewall for DSL/Dial-up connection? </a></li>
<li><strong>Update:</strong> <a href="http://www.cyberciti.biz/nixcraft/forum/viewtopic.php?t=457">Forum topic discussion: Setting up a transparent proxy with Squid peering to ISP squid server</a></li>
<li><a href="http://squid-docs.sourceforge.net/latest/html/book1.html">Squid, a user&#8217;s guide</a></li>
<li><a href="http://www.squid-cache.org/Doc/FAQ/">Squid FAQ</a></li>
<li><a href="http://tldp.org/HOWTO/TransparentProxy.html">Transparent Proxy with Linux and Squid mini-HOWTO</a></li>
</ul>
<p><a title="http://www.cyberciti.biz/tips/linux-setup-transparent-proxy-squid-howto.html" href="http://www.cyberciti.biz/tips/linux-setup-transparent-proxy-squid-howto.html" target="_blank"><strong>Source</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/12/18/setup-a-transparent-proxy-with-3-easy-steps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTPasswd Tutorial</title>
		<link>http://blog.nataprawira.com/tech/2009/11/24/htpasswd-tutorial/</link>
		<comments>http://blog.nataprawira.com/tech/2009/11/24/htpasswd-tutorial/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 02:35:18 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[HTaccess]]></category>
		<category><![CDATA[htpassword]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=119</guid>
		<description><![CDATA[

If you would like to have a set of web pages that are protected, requiring a username/password to gain access, this tutorial will show you how to set it up. This is geared towards the Unix Apache httpd servers used on holly, lamar, and www.colostate.edu. If you are using another web server, you&#8217;ll need to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F11%2F24%2Fhtpasswd-tutorial%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F11%2F24%2Fhtpasswd-tutorial%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<h1><span style="font-weight: normal;font-size: 13px">If you would like to have a set of web pages that are protected, requiring a username/password to gain access, this tutorial will show you how to set it up. This is geared towards the Unix Apache httpd servers used on holly, lamar, and www.colostate.edu. If you are using another web server, you&#8217;ll need to check that server&#8217;s documentation to see how to do this.</span></h1>
<p><span style="font-weight: normal;font-size: 13px"><span id="more-119"></span></span></p>
<p><span style="font-weight: normal;font-size: 13px"><strong>Steps to Password-protect a Directory</strong></span></p>
<p><span style="font-weight: normal;font-size: 13px"><strong><span style="font-weight: normal;font-size: 13px">First, create a subdirectory in your web area. For the sake of this tutorial, I have created the &#8220;protect&#8221; directory. Set the permissions on the directory so that the server has read/execute. I do this by using the local command chgrp-www to set the group to the www group. This is the group that the server runs under at Colorado State University for the lamar, holly and www servers. I have used the -sd flag which sets &#8220;set group id&#8221; for a directory. This will then force any files you create within the protect directory to the www group, so if you ftp files to this directory they will be automatically readable by the server but not by any other user on the system. I then cd into the protect directory. </span></strong></span></p>
<blockquote>
<pre><strong>cd ~ric/public_html
mkdir protect
chmod g+r,g+x,o-r,o-x protect
chgrp-www -sd protect
cd protect</strong></pre>
</blockquote>
<p>Next you must create a .htaccess file inside the directory you want protected. You can use either the vi or pico editors on the supported systems mentioned above or ftp the file to this directory. If you are new to unix or know little about vi then I suggest you use the pico editor or ftp the .htaccess file. The command to edit with pico is &#8220;pico .htaccess&#8221;. The .htaccess file should contain the following lines. The items in <strong>bold</strong> are things you will want to change depending on the location of the AuthUserFile and content of AuthName.</p>
<blockquote>
<pre><strong>AuthUserFile /z/ric/secret/.htpasswd
AuthGroupFile /dev/null
AuthName "Ric's protected files"
AuthType Basic

&lt;Limit GET&gt;
require valid-user
&lt;/Limit&gt;</strong></pre>
</blockquote>
<p>The <strong>AuthName</strong> is what the user will see when they&#8217;re prompted for a password &#8211; something to the effect of &#8220;Enter the username for Ric&#8217;s Protected files&#8221;. The <strong>AuthUserFile</strong> is location of the password file and should be not accessible with a url on the server for security reasons. This is a full unix path and the permissions should be set up like the &#8220;protect&#8221; directory using the chmod and chgrp-www commands above so the only one that can read this file is the owner and the server. To get the full path of a directory, cd to that directory and enter the command &#8220;pwd&#8221; to print the working directory path.</p>
<p>Now you&#8217;ll have to set up the password file. You&#8217;ll need to use the <strong>htpasswd</strong> program. It is included with the Apache httpd server.</p>
<p>First cd to the directory that contains the password file. In this example the password file is called .htpasswd and is in the directory /z/ric/secret/ as indicated by the AuthUserFile file entry in the .htaccess file. For every username you want to add to the password file, enter the following. (the -c is only required the first time; it indicates that you want to create the .htpasswd file).</p>
<blockquote>
<pre><strong>
$~ cd
$~ mkdir secret
$~ cd secret
$~ htpasswd -c .htpasswd pumpkin
<span style="font-weight: normal"><span style="color: #333399">
[ you're prompted for the password for pumpkin]
[ if you have other users enter the following. Don't use the -c]
</span></span>
$~ htpasswd .htpasswd user2
$~ htpasswd .htpasswd user3
</strong></pre>
</blockquote>
<p>Again, make sure the permissions are set up like the &#8220;protect&#8221; directory using the chmod and chgrp-www commands above so the only one that can read files in the &#8220;secret&#8221; directory is the owner and the server.</p>
<p>Here is the <a href="http://www.colostate.edu/~ric/protect/your.html" target="_blank">protected page</a> using the above setup to password protect this page. The username is &#8220;pumpkin&#8221; and password is &#8220;pie&#8221;.</p>
<p>[<a href="http://www.colostate.edu/~ric/htpass.html" target="_blank">source</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/11/24/htpasswd-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Web/Linux IP Address Lookup</title>
		<link>http://blog.nataprawira.com/tech/2009/10/22/ip-address-lookup/</link>
		<comments>http://blog.nataprawira.com/tech/2009/10/22/ip-address-lookup/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 17:58:01 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[IP Address]]></category>
		<category><![CDATA[Lookup]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=106</guid>
		<description><![CDATA[

If you&#8217;re going to be doing a lot of Geotargeting or IP Address  Lookups, please take a feed instead which will preserve both our bandwidth and  your bandwidth.
Simple GET
That said, there is an easy HTTP oriented API to locate IP  addresses and Geocode them. If you don&#8217;t supply the &#8220;?ip=aa.bb.cc.dd&#8221;  bit, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F10%2F22%2Fip-address-lookup%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F10%2F22%2Fip-address-lookup%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>If you&#8217;re going to be doing a lot of Geotargeting or IP Address  Lookups, please take a feed instead which will preserve both our bandwidth and  your bandwidth.</p>
<h1>Simple GET</h1>
<p>That said, there is an easy HTTP oriented API to locate <strong>IP  addresses</strong> and <strong>Geocode</strong> them. If you don&#8217;t supply the &#8220;?ip=aa.bb.cc.dd&#8221;  bit, then the ip address lookup of the calling machine will be located instead  (here, the aa,bb,cc,dd are decimal digits). If you add &amp;position=true to the  end of the URL then latitude and longitude will be returned also. Both HTML and  XML formats are supplied for your convenience.</p>
<blockquote><p><strong>http://api.hostip.info/country.php</strong><br />
US</p>
<p><strong>http://api.hostip.info/get_html.php?ip=12.215.42.19</strong><br />
Country: UNITED STATES (US)<br />
City: Sugar Grove, IL</p>
<p><strong>http://api.hostip.info/get_html.php?ip=12.215.42.19&amp;position=true</strong><br />
Country: UNITED STATES (US)<br />
City: Sugar Grove, IL<br />
Latitude: 41.7696<br />
Longitude: -88.4588</p>
<p><strong>http://api.hostip.info/?ip=12.215.42.19</strong><br />
[use the URL above for an example - XML too long to paste below]</p></blockquote>
<h1><span id="more-106"></span>Country Flag</h1>
<p>Paste the following code into your HTML to get a country  flag of the ip address. The database is significantly more accurate (it ought to  be 100%) for countries than for cities. It would be nice if y&#8217;all would make the  flag a link to the www.hostip.info home page (http://www.hostip.info/) so they  can come by if they&#8217;re interested &#8211; it&#8217;ll only benefit you in the long run.  After all, the results get more accurate as more visitors submit their IP  addresses!<br />
Flag of visitor&#8217;s location:</p>
<blockquote><p><strong>&lt;A HREF=&#8221;http://www.hostip.info&#8221;&gt;<br />
&lt;IMG SRC=&#8221;http://api.hostip.info/flag.php&#8221; BORDER=&#8221;0&#8243; ALT=&#8221;IP Address Lookup&#8221;&gt;<br />
&lt;/A&gt;</strong></p></blockquote>
<p>Flag of any IP address:</p>
<blockquote><p><strong>&lt;A HREF=&#8221;http://www.hostip.info&#8221;&gt;<br />
&lt;IMG SRC=&#8221;http://api.hostip.info/flag.php?ip=12.215.42.19&#8243; ALT=&#8221;IP Address Lookup&#8221;&gt;<br />
&lt;/A&gt;</strong></p></blockquote>
<h1>Embedded Applet</h1>
<p>The following is designed to be embedded within another HTML page using the OBJECT tag. This will reproduce the zoom-in applet, (or an explanatory message with a link to fix, if the IP address lookup is unknown). Which means you can embed the applet in your own site without needing to have the local database and map data (which runs to a few gigabytes&#8230;)</p>
<p>All you need do is include the OBJECT block below in your HTML.  Note, you can also add &#8220;?ip=aaa.bbb.ccc.ddd&#8221; to the frame.html url below to map a specific IP address.</p>
<blockquote>
<pre>&lt;OBJECT DATA='http://www.hostip.info/map/frame.html'

  TYPE='text/html' BORDER=0

  WIDTH=610 HEIGHT=330 HSPACE=0 VSPACE=0&gt;

&lt;/OBJECT&gt;</pre>
</blockquote>
<h1>*NIX Shell Script</h1>
<p>You can use the following shell script to call in your  favorite *NIX environment.</p>
<blockquote><p><strong>#!/bin/bash<br />
lynx -dump &#8220;http://api.hostip.info/get_html.php?ip=$1&#8243;</strong></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/10/22/ip-address-lookup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to tune Apache and Mysql</title>
		<link>http://blog.nataprawira.com/tech/2009/07/25/how-to-tune-apache-and-mysql/</link>
		<comments>http://blog.nataprawira.com/tech/2009/07/25/how-to-tune-apache-and-mysql/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 17:29:43 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[tune]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=66</guid>
		<description><![CDATA[

By default, Apache comes preconfigured to serve a maximum of 256 clients simultaneously. This particular configuration setting can be found in the file /etc/httpd/conf/httpd.conf
If your server has 2 GB of RAM, and you’re sharing your server with MySQL(true in my case), you’ll want to reserve about half of it for Apache (1 GB)

MaxClients: here is [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F07%2F25%2Fhow-to-tune-apache-and-mysql%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F07%2F25%2Fhow-to-tune-apache-and-mysql%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>By default, Apache comes preconfigured to serve a maximum of 256 clients simultaneously. This particular configuration setting can be found in the file <strong>/etc/httpd/conf/httpd.conf</strong></p>
<p>If your server has 2 GB of RAM, and you’re sharing your server with MySQL(true in my case), you’ll want to reserve about half of it for Apache (1 GB)</p>
<p><span id="more-66"></span></p>
<p>MaxClients: here is the process of determining MaxClients. type<strong> </strong></p>
<p style="padding-left: 30px"><strong>ps -U apache -u apache u</strong></p>
<p>See the number of apache process running in you command prompt.<strong></strong></p>
<p style="padding-left: 30px"><strong>USER       PID %CPU %MEM    VSZ     RSS  TTY    STAT START   TIME COMMAND<br />
apache     7694     0.0     0.3       42704  6680    ?        S       18:30   0:00 /usr/sbin/httpd</strong></p>
<p>The above indicates that a single httpd process is using 6.6 MB of RSS (Resident Set Size) memory (or non-swapped physical memory) and that it is using 42 MB of VSZ (Virtual Size) memory. This depends on the number of modules you have loaded and running in Apache.</p>
<p>As shared libraries are included in this number, it’s not 100 percent accurate. We can assume that half the RSS number is “real” memory. Let’s assume that each httpd process is using (6.6/2=3.3) 4 MB of memory. So if you have 1 GB ram then divide it with 4 MB of memory, which leaves room for around 256 concurrent httpd processes.</p>
<p style="padding-left: 30px"><strong>Set MaxClients 256</strong></p>
<p>Or</p>
<p>Somebody prefers to set MaxClients using following rule<strong></strong></p>
<p style="padding-left: 30px"><strong>MaxClients = 150 x RAM (GB) </strong></p>
<p>So for example if you have 2 GB RAM (dedicated for apache) set this value to 300. In my case IT WILL BE 150</p>
<p>Or</p>
<p>Some individuals maintain that each httpd thread uses about 5 MB of “real” memory. So they determine by the following way..</p>
<p>Or</p>
<p style="padding-left: 30px"><code>MaxClients = RAM(MB)/5</code></p>
<p><code>So for example if you have 2 GB RAM (dedicated for apache) set this value to 409. In my case IT WILL BE 204(1 GB for apache)</code><em></em></p>
<p><em>Note:</em> There is no reason for you to set it any higher unless you have a specific problem with this value. A high value can lead to a complete server hang in case of a DOS attack. A value too low can create timeout problems for your clients if the limit is reached</p>
<p><strong>StartServers</strong> &#8211; Sets the number of child server processes created on startup. This setting depends greatly on the type of webserver you run. If you run low traffic websites on that server set it low to something like 5. If you have resource intensive websites on that server you should set it close to MaxClients.</p>
<p><strong>MaxRequestsPerChild</strong> &#8211; Controls the number of request the a child serves before the child is killed. This should not be set too low as it will put an unnecessary load on the apache server to recreate the child. I suggest setting it to 1000.</p>
<p>But we are going to use 2000 for handling heavy traffic load properly.</p>
<p><strong>MinSpareServers and MaxSpareServers</strong> &#8211; MaxSpareServers and MinSpareServers control how many spare (unused) child-processes Apache will keep alive while waiting for more requests to put them to use. Each child-process consumes resources, so having MaxSpareServers set too high can cause resource problems. On the other hand, if the number of unused servers drops below MinSpareServers, Apache will fork. Leave those values to: MinSpareServers 5 MaxSpareServers 10</p>
<p><strong>ServerLimit</strong>: Its better to keep Server limit same as the value of MaxClients.<strong></strong></p>
<p><strong>MaxRequestsPerChild</strong>: I’ve Kept default apache value for this one.</p>
<p>So few changes need to be made in httpd.conf file which is located in /etc/httpd/conf/ directory<strong></strong></p>
<p style="padding-left: 30px"><strong>&lt;IfModule prefork.c&gt;<br />
StartServers     140<br />
MinSpareServers    5<br />
MaxSpareServers   10<br />
ServerLimit      150<br />
MaxClients       150<br />
MaxRequestsPerChild  4000<br />
&lt;/IfModule&gt;</strong></p>
<p>[Note]: Response time depends on MaxClients. If you increase the MaxClients number, server will response more quickly for each request but  a high value can lead to a complete server hang.</p>
<p>Ab is a tool for benchmarking the performance of your Apache HyperText Transfer Protocol (HTTP) server. It does this by giving you an indication of how many requests per second your Apache installation can serve.</p>
<p>uptime command in your root login should not yield a load average above 1, and the server should respond to commands quickly<strong></strong></p>
<p style="padding-left: 30px"><strong>ab -n 10000 -c 200 -k http://your_url<br />
-c = concurrent connections<br />
-t = time limit<br />
-n = # of requests</strong></p>
<p>Keep tuning until you hit your maximum desired load average. For servers used interactively often, having a load above 3 is way too much to use the server comfortably. For servers used mostly as real servers, a maximum load average of 10 should be acceptable. More than that, and you’ll find yourself needing to reboot the server when experiencing heavy traffic conditions, because no terminal or remote console will respond quickly to commands, and managing the server will be impossible.</p>
<p><strong>How to configure few things in php.ini file for supporting huge traffic</strong></p>
<p>* Enable the compression of HTML by putting in your php.ini:<strong></strong></p>
<p style="padding-left: 30px"><strong>output_handler = ob_gzhandler</strong></p>
<p>** Switch from file based sessions to shared memory sessions. Compile PHP with the –with-mm option and<strong></strong></p>
<p style="padding-left: 30px"><strong>set session.save_handler=mm</strong></p>
<p><strong>Configure mysql. Change my.cnf file for better performance.</strong></p>
<p>The database parameters are tuned for systems with 1 GB RAM (for ISO CD images). If you have higher RAM, please change the following in the “my.cnf” MySQL configuration file under /etc/mysql or /etc directory.<strong></strong></p>
<p><strong>For a machine running with 512 MB of RAM, you can set these to:</strong></p>
<p style="padding-left: 30px"><strong>key_buffer=128M table_cache=1024 sort_buffer=64M read_buffer=2M record_buffer=4M</strong></p>
<p><strong>For a machine running with 1 GB of RAM, you can set these to:</strong></p>
<p style="padding-left: 30px"><strong>key_buffer=256M table_cache=2048 sort_buffer=128M read_buffer=2M record_buffer=8M</strong></p>
<p><strong>For a machine running with 2 GB of RAM, you can set these to:</strong></p>
<p style="padding-left: 30px"><strong>key_buffer=512M table_cache=3072 sort_buffer=256M read_buffer=2M record_buffer=8M</strong></p>
<p><strong>For a machine running with 4 GB of RAM, you can set these to:</strong></p>
<p style="padding-left: 30px"><strong>key_buffer=1G table_cache=4096 sort_buffer=512M read_buffer=2M record_buffer=8M</strong></p>
<p><strong><a title="http://blog.shabuz.com/?p=54" href="http://blog.shabuz.com/?p=54" target="_blank">Original Post</a><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/07/25/how-to-tune-apache-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Necessary commands (tips) to tune apache</title>
		<link>http://blog.nataprawira.com/tech/2009/07/25/necessary-commands-tips-to-tune-apache/</link>
		<comments>http://blog.nataprawira.com/tech/2009/07/25/necessary-commands-tips-to-tune-apache/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 17:24:26 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=64</guid>
		<description><![CDATA[

To search in the current directory and all sub directories for a file named httpd.conf
find . -name “httpd.conf” -print
To find some string or text, type
find . -exec grep “MaxClients” ‘{}’ \; -print
This command will search in the current directory and all sub directories. All files that contain the string with the path.
If you want to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F07%2F25%2Fnecessary-commands-tips-to-tune-apache%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F07%2F25%2Fnecessary-commands-tips-to-tune-apache%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>To search in the current directory and all sub directories for a file named httpd.conf</p>
<p style="padding-left: 30px"><strong>find . -name “httpd.conf” -print</strong></p>
<p>To find some string or text, type</p>
<p style="padding-left: 30px"><strong>find . -exec grep “MaxClients” ‘{}’ \; -print</strong></p>
<p><span id="more-64"></span>This command will search in the current directory and all sub directories. All files that contain the string with the path.</p>
<p>If you want to just find each file then pass it on for processing use the -q grep option. This finds the first occurrance of the search string. It then signals success to find and find continues searching for more files.</p>
<p style="padding-left: 30px"><strong>find . -exec grep -q “www.athabasca” ‘{}’ \; -print</strong></p>
<p>Send 1000 Request to apache using apache benchmark</p>
<p style="padding-left: 30px"><strong>ab -n 1000 -c 200 -k YOUR_URL</strong></p>
<p>To view error log of httpd. type</p>
<p style="padding-left: 30px"><strong>grep -i maxclient /var/log/httpd/error_log*</strong></p>
<p>To view Process status type and load average type top and uptime respectively.</p>
<p>To open a file and search something(Here Example is: MaxClients) from there type</p>
<p style="padding-left: 30px"><strong>vi +/MaxClients /etc/httpd/conf/httpd.conf</strong></p>
<p>To view total memory used by httpd, type</p>
<p style="padding-left: 30px"><strong>ps -ylC httpd –sort:rss</strong></p>
<p><strong><a title="http://blog.shabuz.com/?p=55" href="http://blog.shabuz.com/?p=55" target="_blank">Original Post</a></p>
<p></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/07/25/necessary-commands-tips-to-tune-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Howto: HTACCESS Authentication restriction, but allow some IPs to get thru</title>
		<link>http://blog.nataprawira.com/tech/2009/06/22/howto-htaccess-authentication-restriction-but-allow-some-ips-to-get-thru/</link>
		<comments>http://blog.nataprawira.com/tech/2009/06/22/howto-htaccess-authentication-restriction-but-allow-some-ips-to-get-thru/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 11:29:55 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[HTaccess]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=57</guid>
		<description><![CDATA[

Easy part, just create like below .htaccess file on your web folder :
AuthName &#8220;My Protected Site&#8221;
AuthUserFile /home/apache/.htpasswd
AuthType basic
Require valid-user
Order Deny,Allow
Deny from all
Allow from 192.168.1. 192.168.2.
Satisfy Any
Good luck!
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F06%2F22%2Fhowto-htaccess-authentication-restriction-but-allow-some-ips-to-get-thru%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F06%2F22%2Fhowto-htaccess-authentication-restriction-but-allow-some-ips-to-get-thru%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>Easy part, just create like below .htaccess file on your web folder :</p>
<p style="padding-left: 30px">AuthName &#8220;My Protected Site&#8221;<br />
AuthUserFile /home/apache/.htpasswd<br />
AuthType basic<br />
Require valid-user<br />
Order Deny,Allow<br />
Deny from all<br />
Allow from 192.168.1. 192.168.2.<br />
Satisfy Any</p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/06/22/howto-htaccess-authentication-restriction-but-allow-some-ips-to-get-thru/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Add Godaddy SSL Site Seal Image</title>
		<link>http://blog.nataprawira.com/tech/2009/06/01/how-to-add-godaddy-ssl-site-seal-image/</link>
		<comments>http://blog.nataprawira.com/tech/2009/06/01/how-to-add-godaddy-ssl-site-seal-image/#comments</comments>
		<pubDate>Sun, 31 May 2009 17:26:40 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Godaddy]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Site Seal]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=52</guid>
		<description><![CDATA[

We have 2 ways, to get this done. You just need to choose, which way is suitable for you  

Long Way:
1. Log in to your Account Manager.
2. Visit: https://certs.godaddy.com/ManageProducts.do
3. On &#8220;Manage SSL Certificates&#8221;, click on your domain name.
4. Click on &#8220;SITE SEAL&#8221; tab to manage your site seal
5. Choose &#8220;Site Seal Image Size&#8221;
6. Click [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F06%2F01%2Fhow-to-add-godaddy-ssl-site-seal-image%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F06%2F01%2Fhow-to-add-godaddy-ssl-site-seal-image%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>We have 2 ways, to get this done. You just need to choose, which way is suitable for you <img src='http://blog.nataprawira.com/tech/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span id="more-52"></span></p>
<p><span style="text-decoration: underline"><strong>Long Way:</strong></span></p>
<p>1. Log in to your Account Manager.</p>
<p>2. Visit: <a href="https://certs.godaddy.com/ManageProducts.do" target="_blank"><strong>https://certs.godaddy.com/ManageProducts.do</strong></a></p>
<p>3. On &#8220;Manage SSL Certificates&#8221;, click on your domain name.</p>
<p>4. Click on &#8220;SITE SEAL&#8221; tab to manage your site seal</p>
<p>5. Choose &#8220;Site Seal Image Size&#8221;</p>
<p>6. Click on Submit button.</p>
<p>7. On the right side box, copy-paste the javascript provided, into your sidebar website.</p>
<p>8. Done.</p>
<p><span style="text-decoration: underline"><strong>Easy way:</strong></span></p>
<p>1. Log in to your Account Manager.</p>
<p>2. Visit Manage Site Seal page: <a href="https://certs.godaddy.com/ManageSiteSeal.do" target="_blank"><strong>https://certs.godaddy.com/ManageSiteSeal.do</strong></a></p>
<p>3. Choose &#8220;Site Seal Image Size&#8221;</p>
<p>4. Click on Submit button.</p>
<p>5. On the right side box, copy-paste the javascript provided, into your sidebar website.</p>
<p>6. Done.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/06/01/how-to-add-godaddy-ssl-site-seal-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Securing Linux</title>
		<link>http://blog.nataprawira.com/tech/2009/04/12/securing-linux/</link>
		<comments>http://blog.nataprawira.com/tech/2009/04/12/securing-linux/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 00:49:07 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Secure]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=48</guid>
		<description><![CDATA[



Mod_security(ModSecurity is an open source intrusion detection and prevention engine for web applications)
Features 
•	filtering POST and GET requests (including hearders)
•	filters inheritance and ability to add filters in each vhosts configuration file, and    per directory
•	include a way to chroot apache in an easiest way
•	ability to fake apache output (like telling &#8220;Microsoft IIS&#8221; on error page or [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F04%2F12%2Fsecuring-linux%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F04%2F12%2Fsecuring-linux%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<div id="matter_container">
<div class="matter_matter">
<h1 class="title">Mod_security(ModSecurity is an open source intrusion detection and prevention engine for web applications)</h1>
<h2><span class="content_title_blue">Features </span></h2>
<p><span class="content_text">•	filtering POST and GET requests (including hearders)<br />
•	filters inheritance and ability to add filters in each vhosts configuration file, and    per directory<br />
•	include a way to chroot apache in an easiest way<br />
•	ability to fake apache output (like telling &#8220;Microsoft IIS&#8221; on error page or whatever    you want to display)<br />
•	can store uploaded files in a tmp directory and call an anti-virus scan like clamav on     these files </span></p>
<p><span id="more-48"></span></p>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">wget http://www.modsecurity.org/download/modsecurity-apache_1.9.4.tar.gz<br />
tar zxvf modsecurity-apache_1.9.4.tar.gz<br />
cd modsecurity-apache_1.9.4<br />
/usr/local/apache/bin/apxs -cia mod_security.c<br />
/usr/local/apache/bin/apachectl stop<br />
/usr/local/apache/bin/apachectl start</p>
<p class="content_text">Add required modsecurity directives in httpd.conf</p>
<h1 class="title">Mod_evasive( mod_evasive is intended to avoid DDOS attacks by baning IPs that have reached a configured limit of requests during a laps of time)</h1>
<h2><span class="content_title_blue">Features </span></h2>
<p><span class="content_text">•	Its quite easy to deploy on a webserver and can be very usefull.<br />
•	IP addresses of trusted clients can be whitelisted to insure they are never denied<br />
• This tool is excellent at fending off request-based DoS attacks or scripted<br />
attacks, and brute force attack </span></p>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">wget http://www.zdziarski.com/projects/mod_evasive/mod_evasive_1.10.1.tar.gz<br />
1. Extract this archive into src/modules in the Apache source tree<br />
2. Run ./configure &#8211;add-module=src/modules/evasive/mod_evasive.c<br />
3. make, install<br />
4. Restart Apache<br />
With DSO Support, Ensim, or CPanel:<br />
1. /usr/local/apache/bin/apxs -iac mod_evasive.c<br />
2. Restart Apache</p>
<p class="content_text">Add required directive in httpd.conf</p>
<h1 class="title">Mod_limitipconn(mod_limitipconn allows web server administrators to limit the number of simultaneous downloads permitted from a single IP address)</h1>
<h2><span class="content_title_blue">Features </span></h2>
<p class="content_text">•	Allows inclusion and exclusion of files based on MIME type.<br />
•	Partially fixes the problem of dangling browser connections counting towards the    download limit</p>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">wget<br />
http://dominia.org/djao/limit/mod_limitipctar xzvf mod_limitipconn-0.04.tar.gz<br />
tar xzvf mod_limitipconn-0.04.tar.gz<br />
cd apache_1.3.27<br />
patch -p1 &lt; /root/mod_limitipconn-0.04/apachesrc.diff<br />
cp /root/mod_limitipconn-0.04/mod_limitipconn.c src/modules/extra/<br />
./configure &#8211;activate-module=src/modules/extra/mod_limitipconn.c &#8211;with-forward<br />
make ,install</p>
<p class="content_text"><strong>With DSO Support, Ensim, or CPanel:</strong><br />
1.cd mod_limitipconn-0.04<br />
2.make<br />
3.make install</p>
<p class="content_text">add required directives in httpd.conf</p>
<h1 class="title">APF (Advanced Policy Firewall is a policy based iptables firewall system designed for ease of use and configuration)</h1>
<h2><span class="content_title_blue">Features</span></h2>
<p class="content_text">- detailed and well commented configuration file<br />
- granular inbound and outbound network filtering<br />
- user id based outbound network filtering<br />
- application based network filtering<br />
- trust based rule files with an optional advanced syntax<br />
- global trust system where rules can be downloaded from a central management<br />
server<br />
- debug mode provided for testing new features and configuration setups<br />
- fast load feature that allows for 1000+ rules to load in under 1 second<br />
- inbound and outbound network interfaces can be independently configured<br />
- global tcp/udp port &amp; icmp type filtering with multiple methods of excuting<br />
filters (drop, reject, prohibit)<br />
- configurable policies for each ip on the system with convenience variables to<br />
import settings<br />
- packet flow rate limiting that prevents abuse on the most widely abused<br />
protocol, icmp<br />
- prerouting and postrouting rules for optimal network performance<br />
- dshield.org block list support to ban networks exhibiting suspicious activity<br />
- spamhaus Don&#8217;t Route Or Peer List support to ban known &#8220;hijacked zombie&#8221; IP<br />
blocks<br />
- antidos subsystem to stop attacks before they become a significant threat<br />
- any number of additional interfaces may be configured as firewalled<br />
(untrusted) or trusted (not firewalled)<br />
- additional firewalled interfaces can have there own unique firewall policies<br />
applied<br />
- intelligent route verification to prevent embarrassing configuration errors<br />
- advanced packet sanity checks to make sure traffic coming and going meets<br />
- filter attacks such as fragmented UDP, port zero floods, stuffed routing,<br />
arp poisoning and more<br />
- configurable type of service options to dictate the priority of different types<br />
of network traffic<br />
- intelligent default settings to meet every day server setups<br />
- dynamic configuration of your servers local DNS revolvers into the firewall<br />
- optional filtering of common p2p applications<br />
- optional filtering of private &amp; reserved IP address space<br />
- optional implicit blocks of the ident service<br />
- configurable connection tracking settings to scale the firewall to the size of<br />
your network<br />
- configurable kernel hooks (ties) to harden the system further to syn-flood<br />
attacks &amp; routing abuses<br />
- advanced network control such as explicit congestion notification and overflow<br />
control<br />
- special chains that are aware of the state of FTP DATA and SSH connections to<br />
prevent client side issues<br />
- control over the rate of logged events, want only 30 filter events a minute?<br />
300 a minute? &#8211; you are the boss<br />
- logging subsystem that allows for logging data to user space programs or<br />
standard syslog files<br />
- logging that details every rule added and a comprehensive set of error checks<br />
to prevent config errors<br />
- if you are familiar with netfilter you can create your own rules in any of<br />
the policy files<br />
- pluggable and ready advanced use of QoS algorithms provided by the Linux</p>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">wget http://www.rfxnetworks.com/downloads/apf-current.tar.gz<br />
tar -xvzf apf-current.tar.gz<br />
cd apf-0.9.6-2/<br />
./install.sh</p>
<p class="content_text">configure apf(/etc/apf/conf.apf) upon requrements</p>
<p class="content_text">then  start apf<br />
/usr/local/sbin/apf -s</p>
<h1 class="title">BFD( Brute Force Detection is a modular shell script for parsing applicable logs and checking for authentication</h1>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">wget http://www.rfxnetworks.com/downloads/bfd-current.tar.gz<br />
tar -xvzf bfd-current.tar.gz<br />
cd bfd-0.7<br />
./install.sh</p>
<p>configure bfd (/usr/local/bfd/conf.bfd ) upon requirements</p>
<p>to start bdf running<br />
/usr/local/sbin/bfd -s</p>
<h1 class="title">SIM (System Integrity Monitor is a system and services monitor for ‘SysVinit’ systems. It is designed to be intuitive and modular in nature)</h1>
<h2><span class="content_title_blue">Features </span></h2>
<p><span class="content_text">- Service monitoring of HTTP, FTP, DNS, SSH, MYSQL &amp; more<br />
- Event tracking and alert system<br />
- Auto restart ability for downed services<br />
- Checks against network sockets &amp; process list to ensure services are online<br />
- HTTP log size monitor, to avoid segfaults from apache due to large logs<br />
- URL Aware monitoring, to ensure HTTP does not &#8216;lockup&#8217;<br />
- System load monitor with customizable warning levels, actions, and more&#8230;<br />
- Informative command line status display<br />
- Easily customizable configuration file<br />
- Auto configuration script<br />
- Auto cronjob setup feature<br />
- Caching feature for ps/netstat output, to ease on runtime load<br />
- Simple &amp; Informative installation script<br />
- Integrated auto-update feature</span></p>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">wget http://www.r-fx.org/downloads/sim-current.tar.gz<br />
tar -xzvf sim-current.tar.gz<br />
cd sim-2.5-4/<br />
./setup -i<br />
Then press &#8220;Enter&#8221;<br />
Then when it says MORE press the &#8220;space bar&#8221;<br />
Then press &#8220;Enter&#8221;<br />
Then when it says MORE press the &#8220;space bar&#8221;<br />
Now you will press ENTER one more time to do the auto-configuration script for SIM</p>
<p class="content_text">To add a cron.<br />
Type: ./setup -c<br />
If it says &#8220;Removed SIM cronjob.&#8221; then you must type it again.<br />
Type: ./setup -c</p>
<h1 class="title">Portsentry(  PortSentry is a tcpwrapper that listens for port scans, which can be used to send back fake ping replys)</h1>
<h2><span class="content_title_blue">Features</span></h2>
<p class="content_text">-help us to protect our network from unsolicited intrusions<br />
-we can choose which ports we want to be open and which one&#8217;s we dont</p>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">wget http://www.macosxunleashed.com/downloads/portsentry-1.0.tar.gz<br />
tar zxvfx portsentry-1.0.tar.gz<br />
cd  portsentry-1.0<br />
make linux<br />
make install</p>
<p class="content_text">conf file( /usr/local/psionic/portsentry/portsentry.conf)make relevant changes</p>
<h1 class="title">chkrootkit (it is a tool to locally check for signs of a rootkit)</h1>
<h2><span class="content_title_blue">Features</span></h2>
<p class="content_text"><strong>*</strong> chkrootkit: shell script that checks system binaries for rootkit modification.<br />
<strong>*</strong> ifpromisc.c: checks if the interface is in promiscuous mode.<br />
<strong>*</strong> chklastlog.c: checks for lastlog deletions.<br />
<strong>*</strong> chkwtmp.c: checks for wtmp deletions.<br />
<strong>*</strong> check_wtmpx.c: checks for wtmpx deletions. (Solaris only)<br />
<strong>* </strong>chkproc.c: checks for signs of LKM trojans.<br />
<strong>*</strong> chkdirs.c: checks for signs of LKM trojans.<br />
<strong>*</strong> strings.c: quick and dirty strings replacement.<br />
<strong>*</strong> chkutmp.c: checks for utmp deletions.</p>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz<br />
tar zxvf chkrootkit.tar.gz<br />
cd chkrootkit-0.47/<br />
make sense<br />
./chkrootkit</p>
<p class="content_text">configure reporting cronjob:-</p>
<p class="content_text">cd /etc/cron.daily<br />
vi chkrootkit.cron<br />
#!/bin/bash<br />
cd /root/chkrootkit-0.47/<br />
./chkrootkit 2&gt;&amp;1 | mail –s “chkrootkit daily report” ndztest@gmail.com</p>
<p class="content_text">Save &amp; exit<br />
chmod +x chkrootkit.cron</p>
<h1 class="title">RKHunter (RootKit Hunter Is a security scanning tool which will scan for rootkits, backdoors, and local exploits)</h1>
<h2><span class="content_title_blue">Features</span></h2>
<p class="content_text">It runs many tests, including MD5 hash comparisons, default filenames used by rootkits, wrong file permissions for binaries, and suspicious strings in LKM and KLD modules</p>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">wget http://downloads.rootkit.nl/rkhunter-1.1.4.tar.gz<br />
tar -xzvf rkhunter-1.1.4.tar.gz<br />
cd rkhunter<br />
./installer.sh</p>
<p class="content_text">configure reporting cronjob:-<br />
cd /etc/cron.daily<br />
vi rkhunter.cron<br />
#!/bin/bash<br />
/usr/local/bin/rkhunter -c &#8211;cronjob 2&gt;&amp;1 | mail -s &#8220;RKhunter Scan Details&#8221; ndztest@gmail.com</p>
<p class="content_text">Save  &amp; exit<br />
chmod +x rkhunter.cron</p>
<h1 class="title">Snort(Snort is an open source network intrusion detection and prevention system)</h1>
<h2><span class="content_title_blue">Features</span></h2>
<p class="content_text">* capable of performing real-time traffic analysis, alerting, blocking and packet    logging on IP networks<br />
* Protocol Analysis<br />
* Content searching / matching<br />
* Real-time alerting capability<br />
* Can read in a TCPDump trace and run against a rule set<br />
* Flexible rules language to describe traffic that it should collect or pass</p>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">wget http://www.snort.org/dl/current/snort-2.6.1.5.tar.gz<br />
tar zxvf snort-2.6.1.5.tar.gz<br />
cd snort-2.6.1.5<br />
./configure<br />
make<br />
make install</p>
<p class="content_text">mkdir /etc/snort<br />
cp -rf etc/* /etc/snort</p>
<p class="content_text">change /etc/snort/snort.conf according to your requirements</p>
<h1 class="title">Tripwire(Tripwire data integrity assurance software monitors the reliability of critical system files and directories by identifying changes made to them)</h1>
<h2><span class="content_title_blue">Features</span></h2>
<p class="content_text">*  Centralized management console with web interface<br />
*  Centralized database that stores historical changes<br />
*  Tailorable reports and dashboards<br />
*  Customizable roles and permissions to ensure a secure audit trail<br />
*  Integration with change management systems, providing automated change     reconciliation</p>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">yum install tripwire</p>
<p class="content_text">/usr/sbin/tripwire-setup-keyfiles</p>
<p class="content_text">To generate database<br />
/usr/sbin/tripwire &#8211;init</p>
<p class="content_text">To view Tripwire database<br />
/usr/sbin/twprint -m d &#8211;print-dbfile | less</p>
<h1 class="title">libsafe(Libsafe is a library that try to prevent buffer overflow attack)</h1>
<h2><span class="content_title_blue">Features</span></h2>
<p class="content_text">* Detection and protection against stack smashing attacks</p>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">wget http://fresh.t-systems-sfr.com/linux/src/libsafe-2.0-16.tgz<br />
tar zxvfp libsafe-2.0-16.tgz<br />
cd libsafe-2.0-16<br />
make<br />
make install<br />
cd exploits<br />
make<br />
./int.sh t1<br />
- hit carraige return  and watch</p>
<p class="content_text">./int.sh t3<br />
- hit carraige return  and watch</p>
<p class="content_text">./int.sh t4<br />
- hit carraige return  and watch</p>
<p class="content_text">./xlock -nolock</p>
<p class="content_text">./canary-exploit</p>
<p class="content_text">./exploit-non-exec-stack</p>
<p class="content_text">Enable libsafe</p>
<p class="content_text">export LD_PRELOAD=/lib/libsafe.so.2</p>
<p class="content_text">Permanently install libsafe</p>
<p class="content_text">vi  /etc/profile<br />
export LD_PRELOAD=/lib/libsafe.so.2</p>
<h1 class="title">PHP mail() header patch(This patch attempts to address this weakness by inserting an informational header to messages sent from PHP via the mail() function)</h1>
<h2><span class="content_title_blue">Features</span></h2>
<p class="content_text">* The header identifies both the script and the apparent IP address that called it<br />
* This can make it difficult to trace misuse, even if you have comprehensive mail and    webserver logs</p>
<h2><span class="content_title_blue">Installation</span></h2>
<p class="content_text">wget http://www.lancs.ac.uk/~steveb/patches/php-mail-header-patch/php5-mail-header.patch</p>
<p class="content_text">cd /root/php-5.2.1<br />
patch -p1 &lt; ../php5-mail-header.patch</p>
<p class="content_text">Recompile Php</p>
<h1 class="title">Limit compiler and fetch utilities access to root only</h1>
<p class="content_text">chmod 700 /usr/bin/gcc<br />
chmod 700 /usr/bin/wget</p>
<h1 class="title">Ensure OpenSSH protocol is only using protocol 2</h1>
<p class="content_text">vi /etc/ssh/ssh_config<br />
Find the line #Protocol 2, 1 and change it to Protocol 2</p>
<h1 class="title">Disable DNS recursion</h1>
<p class="content_text">vi /etc/named.conf<br />
Give &#8220;recursion no;&#8221; in the &#8220;options&#8221; clause</p>
<p class="content_text">If you need to enable recursion for your local network<br />
give  allow-recursion { 192.168.1.1;192.168.1.20;192.168.1.21;192.168.1.59;192.168.1.22; } in &#8220;options&#8221; section</p>
<h1 class="title">Disable used services(eg:telnet)</h1>
<p class="content_text">vi /etc/xinetd.d/telnet<br />
replace &#8220;disable = no&#8221; and with &#8220;disable = yes&#8221;<br />
/etc/init.d/xinetd restart<br />
chkconfig telnet off<br />
chkconfig &#8211;del telnet<br />
Scan server to ensure port 23 is closed<br />
nmap -sT -O localhost</p>
<h1 class="title">Disable IP source routing</h1>
<p class="content_text">vi /etc/sysctl.conf</p>
<p class="content_text">net.ipv4.conf.default.accept_source_route = 0</p>
<h1 class="title">Ensure cannot SSH directly to root. Must SSH to admin first</h1>
<p class="content_text">For cPanel make sure you add your admin user to the ‘wheel’ group so that you will be able to ’su -’ to root<br />
After that<br />
vi /etc/ssh/sshd_config<br />
PermitRootLogin no</p>
<h1 class="title">Disable ICMP Redirect Acceptance  <span class="content_title_hash">(When hosts use a non-optimal or defunct route to a particular destination, an ICMP redirect packet is used by routers to inform the hosts what the correct route should be. If an attacker is able to forge ICMP redirect packets, he or she can alter the routing tables on the host and possibly subvert the security of the host by causing traffic to flow via a path you didn&#8217;t intend. It&#8217;s strongly recommended to disable ICMP Redirect Acceptance to protect your server from this hole.)</span></h1>
<p class="content_text">vi /etc/sysctl.conf<br />
net.ipv4.conf.all.accept_redirects = 0<br />
/etc/init.d/network restart</p>
<h1 class="title">Enforce noexec &amp; nosuid on temporary directories /tmp and /var/tmp</h1>
<p class="content_text">vi /etc/fstab<br />
LABEL=/tmp /tmp ext3 noexec,nosuid,rw 0 0<br />
/dev/shm /dev/shm tmpfs   noexec,nosuid defaults 0 0</p>
<p class="content_text">chmod 0777 /tmp</p>
<p class="content_text">umount /dev/shm<br />
mount /dev/shm<br />
rm -rf /var/tmp/<br />
ln -s /tmp/ /var/</p>
<h1 class="title">Enable IP spoofing protection( The spoofing protection prevents your network from being the source of spoofed i.e. forged communications that are often used in DoS attacks)</h1>
<p class="content_text">vi /etc/sysctl.conf<br />
net.ipv4.conf.all.rp_filter = 1<br />
/etc/init.d/network restart</p>
<h1 class="title">Enable syncookie protection</h1>
<p class="content_text">vi /etc/sysctl.conf<br />
net.ipv4.tcp_syncookies = 1<br />
/etc/init.d/network restart</p>
<h1 class="title">Disable certain php functions (system, exec, shell_exec)</h1>
<p class="content_text">vi /usr/local/lib/php.ini<br />
disable_functions = system, exec, shell_exec</p>
<h1 class="title">Harden host.conf</h1>
<p class="content_text">vi /etc/host.conf<br />
order hosts,bind<br />
nospoof on<br />
/etc/init.d/network restart</p>
<h1 class="title">Email spoofing prevention ( Email spoofing is the practice of changing your name in email so that it looks like the email came from somewhere or someone else.)</h1>
<p class="content_text"><strong>Router filtering</strong><br />
Putting a filter on your router is the first preventive step. By using an Access Control List, you can block private IP addresses.</p>
<p class="content_text"><strong>Encryption and authentication</strong><br />
By using encryption and authentication, you can reduce spoofing attacks. Ensuring the right authentication procedures are in place with a secure network will make it much more difficult for an attack to take place.</p>
<h1 class="title">Upgrade kernal to latest OS release</h1>
<p class="content_text">wget http://download.openvz.org/kernel/branches/2.6.20/2.6.20-ovz005.1<br />
//kernel-2.6.20-ovz005.1.i686.rpm<br />
rpm -ivh kernel-2.6.20-ovz005.1.i686.rpm</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/04/12/securing-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mixing PHP and SSI</title>
		<link>http://blog.nataprawira.com/tech/2009/03/24/mixing-php-and-ssi/</link>
		<comments>http://blog.nataprawira.com/tech/2009/03/24/mixing-php-and-ssi/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 03:54:53 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Mixing PHP and SSI]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=45</guid>
		<description><![CDATA[

This information is ONLY relevant to PHP4 and Apache 1.3. (BUT possible can be work also in PHP 5.x and Apache 2.x ) We historically used PHP for all our web work. We have decided to migrate to ruby for lots of reasons for all our new web development but we still have lots of [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F03%2F24%2Fmixing-php-and-ssi%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F03%2F24%2Fmixing-php-and-ssi%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><strong>This information is ONLY relevant to PHP4 and Apache 1.3</strong>. <em><strong>(BUT possible can be work also in PHP 5.x and Apache 2.x )</strong></em> We historically used PHP for all our web work. We have decided to migrate to <a href="http://www.zytrax.com/tech/lang/ruby/" target="_blank">ruby</a> for lots of reasons for all our new web development but we still have lots of PHP stuff hanging around.</p>
<h3>Background</h3>
<p>We regularly mix PHP and SSIs for the following reasons:</p>
<ul>
<li>Laziness &#8211; we have a lot of historic SSI stuff lying around and do not want to change it. We prefer evolution to revolution.</li>
<li>Appropriateness. Not all systems are good at everything. We find that conditionally selecting &#8216;lumps&#8217; of code to deliver browser specific pages (see <a href="http://www.zytrax.com/tech/web/browser_sniffing.html" target="_blank">server side browser sniffing</a>) is a lot cleaner and easier with SSI. That does not take away from either technology.</li>
</ul>
<h3>Nesting PHP and SSI</h3>
<p>The rules go like this (PHP4 and Apache 1.3 &#8211; we understand that Apache 2 is more flexible but have not yet made the transition):</p>
<ol>
<li>You can invoke SSI files from within PHP but must use the PHP <strong>virtual()</strong> function not <strong>include()</strong>. Variables set within PHP are NOT available to SSI so our favorite &#8216;wheeze&#8217; of supplying last modified dates to a standard footer do not work.</li>
<li>You can include SSI files using the <a href="http://www.zytrax.com/tech/web/ssi.htm#include" target="_blank">include virtual</a> SSI directive but the SSI filename must have a .shtml extension even if the XBitHack is being used.</li>
<li>You cannot include PHP files using the <a href="http://www.zytrax.com/tech/web/ssi.htm#include" target="_blank">include virtual</a> SSI directive.</li>
<li>Variables set within the General Apache section (we use this <a href="http://www.zytrax.com/tech/web/browser_sniffing.html" target="_blank">technique for server side bowser sniffing</a>) are available to both .php and .shtml files no matter how they are called.</li>
</ol>
<p><strong>Note:</strong> We would guess that the Apache environment for each type of file (.php and .shtml) is initialised to the same state as when the page is first called, whereas a nested .php files uses the same php environment and therefore reflects any dynamic changes.</p>
<p><span id="more-45"></span></p>
<h2>Examples</h2>
<p>The following is our standard level 1 template implemented in SSI first and then PHP.</p>
<h3>SSI Version</h3>
<pre>&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Language" content="en-us"&gt;
&lt;meta http-equiv="Content-Type" content="text/html"&gt;
&lt;meta name="GENERATOR" content="company"&gt;
&lt;!--#include virtual="/templates/meta.html" --&gt;
&lt;title&gt;Level 1 template&lt;/title&gt;
&lt;!-- conditionally generated style sheet --&gt;
&lt;!--#include virtual="/templates/styles.shtml" --&gt;
&lt;!-- conditionally generated javascript code --&gt;
&lt;!--#include virtual="/scripts/javascript.shtml" --&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;!-- banner/page headings --&gt;
&lt;!--#include virtual="/templates/level_1.shtml" --&gt;
&lt;div class="page-content"&gt;

&lt;!-- unique page contents go here --&gt;

&lt;/div&gt;
&lt;!--#config timefmt="%B %d %Y" --&gt;
&lt;!--#set var="real_date" value="$LAST_MODIFIED" --&gt;
&lt;!--#include virtual="/templates/footer.shtml" --&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h3>PHP Version</h3>
<pre>&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Language" content="en-us"&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=windows-1252"&gt;
&lt;meta name="GENERATOR" content="company"&gt;
&lt;meta name="keywords" content="blah, blah"&gt;
&lt;title&gt;Cool Tools&lt;/title&gt;
&lt;?php
&lt;!-- conditionally generated style sheet --&gt;
  virtual ("/templates/styles.shtml");
&lt;!-- conditionally generated javascript code --&gt;
  virtual ("/scripts/javascript.shtml");
?&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php
&lt;!-- banner/page headings --&gt;
  virtual ("/templates/level_1.shtml");
?&gt;
&lt;div class="page-content"&gt;

&lt;!-- unique page contents go here --&gt;

&lt;/div&gt;
&lt;?php
  $real_date = date("F d, Y.", getlastmod());
  include ("../templates/footer.php");
?&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong>Notes:</strong></p>
<ol>
<li>You will notice that the styles, javascript and standard page navigation header use the PHP <strong>virtual()</strong> function because they contain SSI directives but the files are otherwise unchanged.</li>
<li>Our SSI &#8216;last modified&#8217; date &#8216;wheeze&#8217; for the footer does not work in a mixed PHP/SSI environment (because you cannot pass variables between PHP and SSI). Instead we have to create a &#8220;footer.php&#8221; file and set the variable &#8216;real_date&#8217; using the PHP <strong>date()</strong> and  <strong>getlastmod()</strong> functions. This file is invoked with the <strong>include()</strong> function because it is a standard PHP file. In &#8216;footer.php&#8217; we just use &#8216;echo $real_date&#8217; to place our last modified date in the output stream. Yes its simpler in PHP but now we have to maintain two versions of our standard footer.</li>
</ol>
<p><strong><a title="http://www.zytrax.com/tech/php/php_ssi.htm" href="http://www.zytrax.com/tech/php/php_ssi.htm" target="_blank">Original</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/03/24/mixing-php-and-ssi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use .htaccess to block a range of IP</title>
		<link>http://blog.nataprawira.com/tech/2009/03/21/use-htaccess-to-block-a-range-of-ip/</link>
		<comments>http://blog.nataprawira.com/tech/2009/03/21/use-htaccess-to-block-a-range-of-ip/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 10:05:46 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Block IP]]></category>
		<category><![CDATA[HTaccess]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=44</guid>
		<description><![CDATA[

Question:
I am having troubles with serverpronto bots attacking my site in droves.
How would I block this range of ip address in .htaccess using deny:
69.60.114.0 &#8211; 69.60.125.255
for example, to block one ip I would have:
Deny from 64.251.14.99
But how would I block the whole range given?
Thank you in advance
jdMorgan
Answer:

Denying 69.60.114.0 &#8211; 69.60.125.255
Any of the following:
Deny from 64.251.114
Deny [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F03%2F21%2Fuse-htaccess-to-block-a-range-of-ip%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F03%2F21%2Fuse-htaccess-to-block-a-range-of-ip%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><strong>Question:</strong></p>
<blockquote><p>I am having troubles with serverpronto bots attacking my site in droves.</p>
<p>How would I block this range of ip address in .htaccess using deny:</p>
<p>69.60.114.0 &#8211; 69.60.125.255</p>
<p>for example, to block one ip I would have:<br />
Deny from 64.251.14.99</p>
<p>But how would I block the whole range given?</p>
<p>Thank you in advance<br />
jdMorgan</p></blockquote>
<p><strong>Answer:</strong></p>
<p><span id="more-44"></span></p>
<p>Denying 69.60.114.0 &#8211; 69.60.125.255</p>
<p>Any of the following:</p>
<blockquote><p>Deny from 64.251.114<br />
Deny from 64.251.115<br />
Deny from 64.251.116<br />
Deny from 64.251.117<br />
Deny from 64.251.118<br />
Deny from 64.251.119<br />
Deny from 64.251.120<br />
Deny from 64.251.121<br />
Deny from 64.251.122<br />
Deny from 64.251.123<br />
Deny from 64.251.124<br />
Deny from 64.251.125</p></blockquote>
<p>-or-</p>
<blockquote><p># Deny 69.60.114.0 &#8211; 69.60.115.255 (512 addresses)<br />
Deny from 69.60.114.0/23<br />
# Deny 69.60.116.0 &#8211; 69.60.119.255 (1024 addresses)<br />
Deny from 69.60.116.0/22<br />
# Deny 69.60.120.0 &#8211; 69.60.123.255 (1024 addresses)<br />
Deny From 69.60.120.0/22<br />
# Deny 69.60.124.0 &#8211; 69.60.125.255 (512 addresses)<br />
Deny from 69.60.124.0/23</p></blockquote>
<p>-or-</p>
<blockquote><p># Deny 69.60.114.0 &#8211; 69.60.115.255 (512 addresses)<br />
Deny from 69.60.114.0/255.255.254.0<br />
# Deny 69.60.116.0 &#8211; 69.60.119.255 (1024 addresses)<br />
Deny from 69.60.116.0/255.255.252.0<br />
# Deny 69.60.120.0 &#8211; 69.60.123.255 (1024 addresses)<br />
Deny From 69.60.120.0/255.255.252.0<br />
# Deny 69.60.124.0 &#8211; 69.60.125.255 (512 addresses)<br />
Deny from 69.60.124.0/255.255.254.0</p></blockquote>
<p>-or-</p>
<blockquote><p>Setenvif Remote-Addr &#8220;^69\.60\.1(1[4-9]¦2[0-5])\.&#8221; getout<br />
Deny from getout</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/03/21/use-htaccess-to-block-a-range-of-ip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP configuration inside httpd.conf</title>
		<link>http://blog.nataprawira.com/tech/2009/03/13/php-configuration-inside-httpdconf/</link>
		<comments>http://blog.nataprawira.com/tech/2009/03/13/php-configuration-inside-httpdconf/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 13:53:34 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[httpd.conf]]></category>
		<category><![CDATA[PHP Configuration]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=43</guid>
		<description><![CDATA[

How to set PHP error notice hidden in httpd.conf (vhost):

&#60;VirtualHost *:80&#62;
  ...
  php_flag display_startup_errors off
  php_flag display_errors off
  php_flag html_errors off
  ...
&#60;/VirtualHost&#62;

How to set individual php.ini in httpd.conf (vhost):

&#60;VirtualHost *:80&#62;
  ...
  PHPIniDir '/path/to/php/conf/php-foo.ini'
  ...
&#60;/VirtualHost&#62;

How to set individual PHPError.log in httpd.conf (vhost):

&#60;VirtualHost *:80&#62;
  ...
  php_flag  [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F03%2F13%2Fphp-configuration-inside-httpdconf%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F03%2F13%2Fphp-configuration-inside-httpdconf%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><strong>How to set PHP error notice hidden in httpd.conf (vhost):</strong></p>
<blockquote>
<pre>&lt;VirtualHost *:80&gt;
  ...
  php_flag display_startup_errors off
  php_flag display_errors off
  php_flag html_errors off
  ...
&lt;/VirtualHost&gt;</pre>
</blockquote>
<p><strong>How to set individual php.ini in httpd.conf (vhost):</strong></p>
<blockquote>
<pre>&lt;VirtualHost *:80&gt;
  ...
  PHPIniDir '/path/to/php/conf/php-foo.ini'
  ...
&lt;/VirtualHost&gt;</pre>
</blockquote>
<p><strong>How to set individual PHPError.log in httpd.conf (vhost):</strong></p>
<blockquote>
<pre>&lt;VirtualHost *:80&gt;
  ...
  php_flag  log_errors on
  php_value error_log  /path/to/site/PHPerror.log
  ...
&lt;/VirtualHost&gt;</pre>
</blockquote>
<p><a title="http://perishablepress.com/press/2007/12/17/how-to-enable-php-error-logging-via-htaccess/" rel="nofollow" href="http://perishablepress.com/press/2007/12/17/how-to-enable-php-error-logging-via-htaccess/" target="_blank">Complete Information</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/03/13/php-configuration-inside-httpdconf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install FFmpeg in Linux (RPM Version)</title>
		<link>http://blog.nataprawira.com/tech/2009/02/27/install-ffmpeg-in-linux-rpm-version/</link>
		<comments>http://blog.nataprawira.com/tech/2009/02/27/install-ffmpeg-in-linux-rpm-version/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 10:57:06 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[RPM]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[DAG]]></category>
		<category><![CDATA[FFMPEG]]></category>
		<category><![CDATA[FFMPEG-PHP]]></category>
		<category><![CDATA[FlvTool2]]></category>
		<category><![CDATA[GLIBC]]></category>
		<category><![CDATA[Mencoder]]></category>
		<category><![CDATA[Mplayer]]></category>
		<category><![CDATA[Repo]]></category>
		<category><![CDATA[RPM Installation]]></category>
		<category><![CDATA[RPMFORGE]]></category>
		<category><![CDATA[RUBY]]></category>
		<category><![CDATA[Yum]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=42</guid>
		<description><![CDATA[

How to Install FFmpeg in Linux ~The Easy Way~
Original Post
FFmpeg is so important    if you are planning to run a video website with streaming with conversion of    video files to different video formats. This tutorial is intended for Centos/Redhat    versions of Linux where any novice user [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F27%2Finstall-ffmpeg-in-linux-rpm-version%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F27%2Finstall-ffmpeg-in-linux-rpm-version%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<h1>How to Install FFmpeg in Linux ~The Easy Way~</h1>
<p><strong><a title="http://www.mysql-apache-php.com/ffmpeg-install.htm" href="http://www.mysql-apache-php.com/ffmpeg-install.htm" target="_blank"><em>Original Post</em></a></strong></p>
<p><a href="http://ffmpeg.mplayerhq.hu/" target="_blank">FFmpeg</a> is so important    if you are planning to run a video website with streaming with conversion of    video files to different video formats. This tutorial is intended for Centos/Redhat    versions of Linux where any novice user can install ffmpeg without compiling    the source which is a more traditional way of installing the FFmpeg software    on linux servers. In this tutorial i will show you the easy way to install ffmpeg    and ffmpeg-php (php extension) with just yum rather than compiling ffmpeg from    source files.</p>
<blockquote><p>FFmpeg (<a href="http://ffmpeg.mplayerhq.hu/" target="_blank">http://ffmpeg.mplayerhq.hu</a>)<br />
Mplayer + Mencoder (<a href="http://www.mplayerhq.hu/design7/dload.html" target="_blank">http://www.mplayerhq.hu/design7/dload.html</a>)<br />
Flv2tool (<a href="http://inlet-media.de/flvtool2" target="_blank">http://inlet-media.de/flvtool2</a>)<br />
Libogg + Libvorbis (<a href="http://www.xiph.org/downloads" target="_blank">http://www.xiph.org/downloads</a>)<br />
LAME MP3 Encoder (<a href="http://lame.sourceforge.net/" target="_blank">http://lame.sourceforge.net</a>)<br />
FlowPlayer &#8211; A Free Flash Video Player &#8211; <a href="http://flowplayer.org/" target="_blank">http://flowplayer.org/</a></p></blockquote>
<h1>Installing FFMpeg</h1>
<p><span id="more-42"></span></p>
<blockquote><p><strong>yum install ffmpeg ffmpeg-devel</strong></p></blockquote>
<p>If you get <strong>package not found, </strong>then you will need to add few    lines in the yum repository for dag packages installation. Create a file named    <strong>dag.repo</strong> in <strong>/etc/yum.repos.d</strong> with the following    contents on it</p>
<blockquote><p><strong>[dag]<br />
name=Dag RPM Repository for Red Hat Enterprise Linux<br />
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag<br />
gpgcheck=1<br />
enabled=1</strong></p></blockquote>
<p>then</p>
<blockquote><p><strong>yum install ffmpeg ffmpeg-devel</strong></p></blockquote>
<p>If everything is fine, then the installation should proceed smoothly. If not    you will get something like warning GPG public key missing .</p>
<h2>Common Errors</h2>
<p><strong>To fix rpmforge GPG key warning: </strong></p>
<blockquote><p><strong>rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm</strong></p></blockquote>
<p>For more information refer to <a href="http://dag.wieers.com/rpm/FAQ.php#B4" target="_blank"><strong>this    faq </strong></a>depending on Centos version</p>
<p><strong>Missing Dependency Error:</strong></p>
<p>If you get missing dependency error like shown below, in the middle of ffmpeg    installation</p>
<blockquote><p><strong><span class="box">Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed    by package ffmpeg<br />
Error: Missing Dependency: libtheora.so.0(libtheora.so.1.0) is needed by package    ffmpeg<br />
Error: Missing Dependency: rtld(GNU_HASH) is needed by package ffmpeg<br />
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package imlib2<br />
Error: Missing Dependency: rtld(GNU_HASH) is needed by package a52dec<br />
Error: Missing Dependency: rtld(GNU_HASH) is needed by package imlib2<br />
Error: Missing Dependency: rtld(GNU_HASH) is needed by package gsm<br />
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package x264<br />
Error: Missing Dependency: rtld(GNU_HASH) is needed by package xvidcore<br />
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package lame<br />
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package a52dec<br />
Error: Missing Dependency: rtld(GNU_HASH) is needed by package faad2<br />
Error: Missing Dependency: rtld(GNU_HASH) is needed by package x264<br />
Error: Missing Dependency: rtld(GNU_HASH) is needed by package lame<br />
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package xvidcore<br />
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package faac<br />
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package faad2<br />
Error: Missing Dependency: libgif.so.4 is needed by package imlib2<br />
Error: Missing Dependency: rtld(GNU_HASH) is needed by package faac<br />
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package gsm<br />
Error: Missing Dependency: libpng12.so.0(PNG12_0) is needed by package imlib2<br />
Error: Missing Dependency: rtld(GNU_HASH) is needed by package libmp4v2<br />
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package libmp4v2</span></strong></p></blockquote>
<p>then most commonly you have GLIB 2.3 installed instead of GLIB 2.4 version.    To check the current GLIB version installed on your server. just use:</p>
<blockquote><p><strong>yum list glib*</strong></p></blockquote>
<p>and it should list the latest GLIB package version.</p>
<p>The reason i was getting this error was my rpmforge packages was pointed to    centos 5 versions instead of centos 4.6.</p>
<p><strong>To fix dependency error:</strong></p>
<p>To fix this error, you might need to check your rpmforge packages compatible    to the release of your existing CentOS version.<br />
Check the file <strong>/etc/yum.repos.d/rpmforge.repo </strong>and it should    look like for Centos 4.6(Final). If you have lines like <strong>http://apt.sw.be/redhat/<span style="color: #0000ff">el5</span>/en/mirrors-rpmforge </strong> you might need to make changes to the <strong>rpmforge.repos</strong> like shown below</p>
<blockquote><p><strong>Note:</strong> Backup the original<strong> rpmforge.repo</strong> file    before you edit its content.</p></blockquote>
<blockquote><p><strong><span class="box">[rpmforge]<br />
name = Red Hat Enterprise $releasever &#8211; RPMforge.net &#8211; dag<br />
#baseurl = http://apt.sw.be/redhat/<span style="color: #0000ff">el4</span>/en/$basearch/dag<br />
mirrorlist = http://apt.sw.be/redhat/<span style="color: #0000ff">el4</span>/en/mirrors-rpmforge<br />
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge<br />
enabled = 1<br />
protect = 0<br />
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag<br />
gpgcheck = 1</span></strong></p></blockquote>
<p><strong>To know what linux type and version you are running </strong></p>
<blockquote><p><strong>cat /etc/redhat-release</strong></p></blockquote>
<p>Once this is done, do again:  <strong>yum install ffmpeg. </strong></p>
<p>This trick resolved the problem in my linux box running Centos 4.6 and this    is the <em>only way</em> i found to install ffmpeg using yum.</p>
<h2>To check the FFmpeg working:</h2>
<p>Finally, check the ffmpeg whether it is working or not.</p>
<blockquote><p><strong>&gt; ffmpeg<br />
&gt; ffmpeg -formats<br />
&gt; ffmpeg &#8211;help<br />
</strong>// This lists path of mpeg, its modules and other path information</p></blockquote>
<blockquote><p><strong> ffmpeg -i Input.file Output.file</strong></p></blockquote>
<h2>To check what audi/video formats are supported</h2>
<blockquote><p><strong>ffmpeg -formats &gt; ffmpeg-format.txt</strong></p></blockquote>
<p>Open the <strong>ffmpeg-formats.txt</strong> to see the ooutput</p>
<blockquote><p><strong>D means decode<br />
E means encode<br />
V means video<br />
A means audio<br />
T = Truncated</strong></p></blockquote>
<h1>Install FFMPEG-PHP Extension</h1>
<p><a href="http://ffmpeg-php.sourceforge.net/" target="_blank">FFmpeg-php</a> is a very good extension and wrapper for PHP which can pull useful information    about video through API interface. Inorder to install it you will need to download    the source file and then compile and install extension in your server. You can    download the source tarball : <a href="http://ffmpeg-php.sourceforge.net/" target="_blank">http://ffmpeg-php.sourceforge.net/</a></p>
<blockquote><p><strong>wget /path/to/this/file/ffmpeg-php-0.5.2.1.tbz2</strong></p>
<p><strong>tar -xjf ffmpeg-0.5.2.1.tbz2</strong></p>
<p><strong>phpize</strong></p>
<p><strong>./configure<br />
make<br />
make install</strong></p></blockquote>
<p><strong>Common Errors</strong></p>
<p><strong>1.</strong> If you get <strong>command not found error</strong> for    phpize, then you will need to do <strong>yum install php-devel</strong></p>
<p><strong>2.</strong> If you get error like <strong>&#8220;ffmpeg headers not    found&#8221;</strong> while configuring the source.</p>
<blockquote><p><strong>configure: error: ffmpeg headers not found. Make sure ffmpeg is    compiled as shared libraries using the &#8211;enable-shared option</strong></p></blockquote>
<p>then it means you have not installed<strong> ffmpeg-devel</strong> packages.</p>
<p><strong>To Fix:</strong> Just install <strong>ffmpeg-devel</strong> using</p>
<blockquote><p><strong>yum install ffmpeg-devel</strong></p></blockquote>
<p><strong>3. </strong>If you get an error like shared libraries not found problem    and the program halts in the middle, then you must specify the ffmpeg installed    path explicitly to the ./configure.</p>
<blockquote><p><strong>configure: error: ffmpeg shared libraries not found. Make sure    ffmpeg is compiled as shared libraries using the &#8211;enable-shared option</strong></p></blockquote>
<p><strong>To Fix:</strong></p>
<p>1. First find out the ffmpeg path with <strong>ffmpeg &#8211;help</strong> command.    The prefix default path should be like <strong>/usr/local/cpffmpeg</strong><br />
2. Configure the FFmpeg-php with &#8211;with-ffmpeg option</p>
<blockquote><p><strong>./configure &#8211;with-ffmpeg=/usr/local/cpffmpeg</strong></p></blockquote>
<p>That should resolve the problem!</p>
<h2>Editing PHP.INI</h2>
<p>Once you have done that without any problems then you will see the php extension    file <strong>/usr/local/lib/php/extensions/no-debug-non-zts-20060613/ffmpeg.so</strong> and you will need mention that extension in php.ini file</p>
<blockquote><p><strong>nano /usr/local/lib/php.ini</strong></p></blockquote>
<p>Put the below two lines at the end of the <strong>php.ini</strong> file</p>
<blockquote><p><strong>[ffmpeg]<br />
extension=ffmpeg.so</strong></p></blockquote>
<p>Then restart the server <strong>service httpd restart</strong></p>
<p>To check whether <strong>ffmpeg enabled with php</strong>, point your browser    to <strong>test.php</strong> file. It should show the confirmation of installed    ffmpeg php extension</p>
<blockquote><p><strong>// #test.php</strong></p>
<p><strong> &lt;?php</strong></p>
<p><strong>phpinfo()</strong></p>
<p><strong>?&gt;</strong></p></blockquote>
<p>If any case the ffmpeg does not show in the phpinfo() test make sure that php.ini    path to ffmpeg.so is correct. Still the problem occurs, the reason could be    you might be using older versions of ffmpeg-php which is buggy. Just download    the latest version of ffmpeg-php source then compile it.</p>
<h1>Installing Mplayer + Mencoder</h1>
<p>Just issue the following yum commands to install the rest of the packages.</p>
<blockquote><p><strong>yum install mplayer mencoder</strong></p></blockquote>
<h1>Installing FlvTool2</h1>
<p>Flvtool2 is a flash video file manipulation tool. It can calculate metadata    and can cut and edit cue points for flv files.</p>
<p>If you are on Centos 5 try <strong>yum install flvtool2</strong> with dag    repository and if you get package not found you will need to manually download    and compile the flvtool2. You can download latest version of flvtool2 here:    <a href="http://rubyforge.org/projects/flvtool2/" target="_blank">http://rubyforge.org/projects/flvtool2/</a></p>
<blockquote><p><strong>wget &lt;url-link&gt;</strong></p>
<p><strong>ruby setup.rb config<br />
ruby setup.rb setup<br />
sudo ruby setup.rb install</strong></p></blockquote>
<p>If you get <strong>command not found</strong> error, it probably means that    you dont have ruby installed.</p>
<blockquote><p><strong>yum install ruby</strong></p></blockquote>
<p>Thats it! Once ffmpeg works fine with php extension, download a sample video,    convert to .flv format in the command line and plug it to <strong><a href="http://flowplayer.org/" target="_blank">flowplayer</a></strong> to see it work on your web browser. Try also to download the video file offline    and see whether the converted flv file works well with both audio and video.</p>
<h2>Useful Links</h2>
<ul>
<li>FFmpeg (<a href="http://ffmpeg.mplayerhq.hu/" target="_blank">http://ffmpeg.mplayerhq.hu</a>)</li>
<li>Mplayer + Mencoder (<a href="http://www.mplayerhq.hu/design7/dload.html" target="_blank">http://www.mplayerhq.hu/design7/dload.html</a>)</li>
<li>Flv2tool (<a href="http://inlet-media.de/flvtool2" target="_blank">http://inlet-media.de/flvtool2</a>)</li>
<li>Libogg + Libvorbis (<a href="http://www.xiph.org/downloads" target="_blank">http://www.xiph.org/downloads</a>)</li>
<li>LAME MP3 Encoder (<a href="http://lame.sourceforge.net/" target="_blank">http://lame.sourceforge.net</a>)</li>
<li>FlowPlayer &#8211; A Free Flash Video Player &#8211; <a href="http://flowplayer.org/" target="_blank">http://flowplayer.org/</a></li>
<li>Install FFmpeg from Compiling Source (<a href="http://rshagrawal.blogspot.com/2007/12/howt-o-for-installing-ffmpeg.html" target="_blank">Tutorial    Link</a>)</li>
<li>Nice FFmpeg Installation Tutorial (<a href="http://forums.theplanet.com/index.php?showtopic=64541" target="_blank">click    here</a>)</li>
<li>Important Audio Codecs (<a href="http://www.mplayerhq.hu/DOCS/HTML/en/audio-codecs.html" target="_blank">http://www.mplayerhq.hu/DOCS/HTML/en/audio-codecs.html</a>)</li>
<li>Common Errors &amp; Fixes while Installing FFmpeg (<a href="http://www.webmasterpals.com/forumdisplay.php?f=6" target="_blank">click    here</a>)</li>
</ul>
<p><!-- Kontera ContentLink(TM);--></p>
<p><!-- Kontera ContentLink(TM) --></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/02/27/install-ffmpeg-in-linux-rpm-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiling PHP 5.2.x / cannot find -lltdl</title>
		<link>http://blog.nataprawira.com/tech/2009/02/26/compiling-php-52x-cannot-find-lltdl/</link>
		<comments>http://blog.nataprawira.com/tech/2009/02/26/compiling-php-52x-cannot-find-lltdl/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 10:35:11 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[BASH]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[cannot find -lltdl]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=41</guid>
		<description><![CDATA[

 When compiling PHP from source, some of the CentOS users reported that they getting errors like below:

/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status

What you need to do, is just follow the below steps.

Verify that the libtool and libtool-ltdl packages are installed.
Symlink libltdl.so to libltdl.so.x.x.x

If libtool and libtool-ltdl already exist, you may go [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F26%2Fcompiling-php-52x-cannot-find-lltdl%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F26%2Fcompiling-php-52x-cannot-find-lltdl%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<hr size="1" /><!-- / icon and title --> <!-- message -->When compiling PHP from source, some of the CentOS users reported that they getting errors like below:</p>
<div style="margin: 5px 20px 20px">
<pre style="border: 1px inset;margin: 0px;padding: 6px;width: 640px;height: 50px;text-align: left"><strong>/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status</strong></pre>
</div>
<p>What you need to do, is just follow the below steps.</p>
<ol>
<li><strong>Verify that the libtool and libtool-ltdl packages are installed.</strong></li>
<li><strong>Symlink libltdl.so to libltdl.so.x.x.x</strong></li>
</ol>
<p>If libtool and libtool-ltdl already exist, you may go to Step Two.<br />
<strong> Step One</strong></p>
<div style="margin: 5px 20px 20px">
<pre style="border: 1px inset;margin: 0px;padding: 6px;width: 640px;height: 34px;text-align: left">[root@banzaibill ~]# <strong>yum install libtool-ltdl libtool</strong></pre>
</div>
<p>Now you have <strong>libtool</strong> installed. To check it out, do:</p>
<div style="margin: 5px 20px 20px">
<pre style="border: 1px inset;margin: 0px;padding: 6px;width: 640px;height: 34px;text-align: left">[root@banzaibill ~]# <strong>yum info libtool*</strong></pre>
</div>
<p><strong> Step Two</strong></p>
<p>PHP looks for the libltdl library only at <strong>/usr/lib/libltdl.so</strong></p>
<p>The symlink to this file is not included in the libtool packages. Do below commands:</p>
<div style="margin: 5px 20px 20px">
<pre style="border: 1px inset;margin: 0px;padding: 6px;width: 640px;height: 50px;text-align: left">[root@banzaibill ~]# <strong>cd /usr/lib</strong>
[root@banzaibill lib]# <strong>ln -s libltdl.so.3.1.4 libltdl.so</strong></pre>
</div>
<p>And that&#8217;s it. PHP should configure and compile without error.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/02/26/compiling-php-52x-cannot-find-lltdl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux Firewalls with IPTABLES (Good Tutorials)</title>
		<link>http://blog.nataprawira.com/tech/2009/02/23/linux-firewalls-with-iptables-good-tutorials/</link>
		<comments>http://blog.nataprawira.com/tech/2009/02/23/linux-firewalls-with-iptables-good-tutorials/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 14:39:06 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Firewall]]></category>
		<category><![CDATA[IPTables]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=38</guid>
		<description><![CDATA[

I found good examples for this.
- Quick HOWTO (from LinuxHomeNetworking.com) &#8211; download
- Sample IPTABLES Configuration (RedHat/CentOS) &#8211; download
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F23%2Flinux-firewalls-with-iptables-good-tutorials%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F23%2Flinux-firewalls-with-iptables-good-tutorials%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>I found good examples for this.</p>
<p>- <strong><a title="Quick HOWTO" href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch14_:_Linux_Firewalls_Using_iptables" target="_blank">Quick HOWTO</a></strong> (from LinuxHomeNetworking.com) &#8211; <a title="DOWNLOAD" href="http://blog.nataprawira.com/tech/files/2009/02/linux-firewalls-using-iptables.pdf" target="_blank">download</a></p>
<p>- <strong><a title="Sample IPTables Configuration" href="http://www.liniac.upenn.edu/sysadmin/security/iptables.html" target="_blank">Sample IPTABLES Configuration</a></strong> (RedHat/CentOS) &#8211; <a title="DOWNLOAD" href="http://blog.nataprawira.com/tech/files/2009/02/sample-iptables-configuration-redhat.pdf" target="_blank">download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/02/23/linux-firewalls-with-iptables-good-tutorials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Be your own Certificate Authority (CA)</title>
		<link>http://blog.nataprawira.com/tech/2009/02/18/be-your-own-certificate-authority-ca/</link>
		<comments>http://blog.nataprawira.com/tech/2009/02/18/be-your-own-certificate-authority-ca/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 05:04:10 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CA]]></category>
		<category><![CDATA[Certificate Authority]]></category>
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=34</guid>
		<description><![CDATA[

I declare from the beginning that I am no authority on digital certificates.
This document is a summary of all the articles I have read about openssl. It describes in short how to become your own Certificate Authority (CA) and how to create and sign your own certificate requests. Make no mistake, these certificates are good [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F18%2Fbe-your-own-certificate-authority-ca%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F18%2Fbe-your-own-certificate-authority-ca%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><a title="ORIGINAL POST" href="http://www.g-loaded.eu/2005/11/10/be-your-own-ca/" target="_blank">I declare from the beginning that I am no authority on digital <strong>certificates</strong>.</a></p>
<blockquote><p>This document is a summary of all the articles I have read about <strong>openssl</strong>. It describes in short how to become your own <strong>Certificate Authority</strong> (CA) and how to create and sign your own <strong>certificate requests</strong>. Make no mistake, these certificates are good only for personal use or for use in your intranet in order to provide a secure way to login or communicate with your services, so that passwords or other data is not transmitted in the clear. Noone else will or should trust these certificates.</p></blockquote>
<h4>Prerequisites</h4>
<p>The package <strong>openssl</strong> should be installed in the machine you will use to manage your certificates or create the certificate requests.</p>
<h4>First things first…</h4>
<p><span id="more-34"></span></p>
<p>The <strong>openssl</strong> package comes with some scripts that can help you create your server certificates fast, but here I will describe how to set things up from scratch in a new directory, so that you can customize things later if you like or delete everything without touching openssl’s or the system’s default files. This article is based on a Fedora installation, but will do for all distributions.</p>
<h5>Creating the necessary directories</h5>
<p>First of all we will create a directory tree where all certificate stuff will be kept. Fedora’s default directory is <strong>/etc/pki/tls/</strong>. So, as root, we create our own directories:</p>
<pre># mkdir -m 0755 /etc/pki_jungle</pre>
<p>And then we create our CA’s directory tree:</p>
<pre># mkdir -m 0755 \
     /etc/pki_jungle/myCA \
     /etc/pki_jungle/myCA/private \
     /etc/pki_jungle/myCA/certs \
     /etc/pki_jungle/myCA/newcerts \
     /etc/pki_jungle/myCA/crl</pre>
<ul>
<li><strong>myCA</strong> is our Certificate Authority’s directory.</li>
<li><strong>myCA/certs</strong> directory is where our server certificates will be placed.</li>
<li><strong>myCA/newcerts</strong> directory is where openssl puts the created certificates in PEM (unencrypted) format and in the form <em>cert_serial_number.pem</em> (eg 07.pem). Openssl needs this directory, so we create it.</li>
<li><strong>myCA/crl</strong> is where our certificate revokation list is placed.</li>
<li><strong>myCA/private</strong> is the directory where our private keys are placed. Be sure that you set restrictive permissions to all your private keys so that they can be read only by root, or the user with whose priviledges a server runs. If anyone steals your private keys, then things get really bad.</li>
</ul>
<h5>Initial openssl configuration</h5>
<p>We are going to copy the default openssl configuration file (<strong>openssl.cnf</strong>) to our CA’s directory. In Fedora, this file exists in <strong>/etc/pki/tls</strong>. So, we copy it to our CA’s dir and name it <strong>openssl.my.cnf</strong>. As root:</p>
<pre># cp /etc/pki/tls/openssl.cnf /etc/pki_jungle/myCA/openssl.my.cnf</pre>
<p>This file does not need to be world readable, so we change its attributes:</p>
<pre># chmod 0600 /etc/pki_jungle/myCA/openssl.my.cnf</pre>
<p>We also need to create two other files. This file serves as a database for openssl:</p>
<pre># touch /etc/pki_jungle/myCA/index.txt</pre>
<p>The following file contains the next certificate’s serial number. Since we have not created any certificates yet, we set it to &#8220;<strong>01</strong>&#8220;:</p>
<pre># echo '01' &gt; /etc/pki_jungle/myCA/serial</pre>
<h4>Things to remember</h4>
<p>Here is a small legend with <strong>file extensions</strong> we will use for the created files and their meaning. All files that will be created will have one of these extensions:</p>
<ul>
<li><strong>KEY</strong> &#8211; Private key (Restrictive permissions should be set on this)</li>
<li><strong>CSR</strong> &#8211; Certificate Request (This will be signed by our CA in order to create the server certificates. Afterwards it is not needed and can be deleted)</li>
<li><strong>CRT</strong> &#8211; Certificate (This can be publicly distributed)</li>
<li><strong>PEM</strong> &#8211; We will use this extension for files that contain both the Key and the server Certificate (Some servers need this). Permissions should be restrictive on these files.</li>
<li><strong>CRL</strong> &#8211; Certificate Revokation List (This can be publicly distributed)</li>
</ul>
<h4>Create the CA Certificate and Key</h4>
<p>Now, that all initial configuration is done, we may create a self-signed certificate, that will be used as our CA’s certificate. In other words, we will use this to sign other certificate requests.</p>
<p>Change to our CA’s directory. <span style="text-decoration: underline">This is where we should issue all the openssl commands because here is our openssl’s configuration file (openssl.my.cnf).</span> As root:</p>
<pre># cd /etc/pki_jungle/myCA/</pre>
<p>And then create your CA’s Certificate and Private Key. As root:</p>
<pre># openssl req -config openssl.my.cnf -new -x509 -extensions v3_ca -keyout private/myca.key -out certs/myca.crt -days 1825</pre>
<p>This creates a self-signed certificate with the default CA extensions which is valid for 5 years. You will be prompted for a <strong>passphrase</strong> for your CA’s private key. <span style="text-decoration: underline">Be sure that you set a strong passphrase.</span> Then you will need to provide some info about your CA. Fill in whatever you like. Here is an example:</p>
<pre>Country Name (2 letter code) [GB]:GR
State or Province Name (full name) [Berkshire]:Greece
Locality Name (eg, city) [Newbury]:Thessaloniki
Organization Name (eg, company) [My Company Ltd]:My Network
Organizational Unit Name (eg, section) []:My Certificate Authority
Common Name (eg, your name or your server's hostname) []:server.example.com
Email Address []:whatever@server.example.com</pre>
<p>Two files are created:</p>
<ul>
<li><strong>certs/myca.crt</strong> &#8211; This is your CA’s certificate and can be publicly available and of course world readable.</li>
<li><strong>private/myca.key</strong> &#8211; This is your CA’s private key. Although it is protected with a passphrase you should restrict access to it, so that only root can read it:
<pre># chmod 0400 /etc/pki_jungle/myCA/private/myca.key</pre>
</li>
</ul>
<h4>More openssl configuration (mandatory)</h4>
<p>Because we use a custom directory for our certificates’ management, some modifications to <strong>/etc/pki_jungle/myCA/openssl.my.cnf</strong> are necessary. Open it in your favourite text editor as root and find the following part (around line 35):</p>
<pre>[ CA_default ]

dir     = ../../CA      # Where everything is kept
certs       = $dir/certs        # Where the issued certs are kept
crl_dir     = $dir/crl      # Where the issued crl are kept
database    = $dir/index.txt    # database index file.
#unique_subject = no            # Set to 'no' to allow creation of
                    # several ctificates with same subject.
new_certs_dir   = $dir/newcerts     # default place for new certs.

certificate = $dir/cacert.pem   # The CA certificate
serial      = $dir/serial       # The current serial number
#crlnumber  = $dir/crlnumber    # the current crl number must be
                    # commented out to leave a V1 CRL
crl     = $dir/crl.pem      # The current CRL
private_key = $dir/private/cakey.pem    # The private key
RANDFILE    = $dir/private/.rand    # private random number file

x509_extensions = usr_cert      # The extentions to add to the cert</pre>
<p>You should modify the following settings in order to coform to our custom directory and our custom CA key and certificate:</p>
<pre>[ CA_default ]

dir     = <strong>.</strong>                # <strong>&lt;--CHANGE THIS</strong>
certs       = $dir/certs
crl_dir     = $dir/crl
database    = $dir/index.txt
#unique_subject = no

new_certs_dir   = $dir/newcerts

certificate = $dir/<strong>certs/myca.crt</strong>   # <strong>&lt;--CHANGE THIS</strong>
serial      = $dir/serial
#crlnumber  = $dir/crlnumber

crl     = $dir/crl.pem
private_key = $dir/private/<strong>myca.key</strong>    # <strong>&lt;--CHANGE THIS</strong>
RANDFILE    = $dir/private/.rand

x509_extensions = usr_cert</pre>
<h4>Create a Server certificate</h4>
<p>Further openssl.my.cnf file’s customization is possible, so that we define our policy for certificate creation and signing or define our desired extensions for the new certificates. I may add this info to a future version of this document. It’s easy though, just try to familiarize yourself with the openssl.cnf’s structure and you’ll figure it out.</p>
<p>Anyway, the certificates we are going to create, without customizing openssl.my.cnf any further, are <strong>general purpose certificates</strong> and their usage in not restricted to server authentication only. One thing that you should take a note of is that <strong>the private keys will not be protected by a passphrase</strong>, so that when the services are restarted they do not ask for a passphrase. This means that you should <strong>set restrictive permissions on the private keys</strong>, so that only root or the user under whose priviledges a server runs can read these files.</p>
<h5>Generate a Certificate Request</h5>
<p>First, we change to our CA’s directory:</p>
<pre># cd /etc/pki_jungle/myCA/</pre>
<p>Then we create the certificate request:</p>
<pre># openssl req -config openssl.my.cnf -new -nodes -keyout private/server.key -out server.csr -days 365</pre>
<p>The <strong>-nodes</strong> option is needed so that the private key is not protected with a passphrase. If you do not intend to use the certificate for server authentication, you should not include it in the above command.<br />
You can customize the number of days you want this certificate to be valid for.</p>
<p>You will be prompted for the certificate’s info. Here is an example:</p>
<pre>Country Name (2 letter code) [GB]:GR
State or Province Name (full name) [Berkshire]:Greece
Locality Name (eg, city) [Newbury]:Thessaloniki
Organization Name (eg, company) [My Company Ltd]:My Network
Organizational Unit Name (eg, section) []:My Web Server
Common Name (eg, your name or your server's hostname) []:www.server.example.com
Email Address []:whatever@server.example.com</pre>
<p>The <strong>Common Name (CN)</strong> is the info that uniquely distinguishes your service, so be sure that you type it correctly.</p>
<p>When prompted for some extra attributes (challenge password, optional company name) just hit the [Enter] key.<br />
Two files are created:</p>
<ul>
<li><strong>server.csr</strong> &#8211; this is the certificate request.</li>
<li><strong>private/server.key</strong> &#8211; this is the private key, which is not protected with a passphrase.</li>
</ul>
<p>Set restrictive permissions on the private key. Only root or the user that is used to run the server should be able to read it. For example:</p>
<pre># chown root.root /etc/pki_jungle/myCA/private/server.key
# chmod 0400 /etc/pki_jungle/myCA/private/server.key</pre>
<p>Or:</p>
<pre># chown root.apache /etc/pki_jungle/myCA/private/server.key
# chmod 0440 /etc/pki_jungle/myCA/private/server.key</pre>
<h5>Sign the Certificate Request</h5>
<p>Now we are going to sign the certificate request and generate the server’s certificate.</p>
<p>First, we change to our CA’s directory:</p>
<pre># cd /etc/pki_jungle/myCA/</pre>
<p>Then we sign the certificate request:</p>
<pre># openssl ca -config openssl.my.cnf -policy policy_anything -out certs/server.crt -infiles server.csr</pre>
<p>You will need to supply the CA’s private key in order to sign the request. You can check the openssl.my.cnf file about what <strong>policy_anything</strong> means. In short, the fields about the Country, State or City is not required to match those of your CA’s certificate.</p>
<p>After all this is done two new files are created:</p>
<ul>
<li><strong>certs/server.crt</strong> &#8211; this is the server’s certificate, which can be made available publicly.</li>
<li><strong>newcerts/01.pem</strong> &#8211; This is exactly the same certificate, but with the certificate’s serial number as a filename. It is not needed.</li>
</ul>
<p>You can now delete the certificate request (server.csr). It’s no longer needed:</p>
<pre># rm -f /etc/pki_jungle/myCA/server.csr</pre>
<h5>Verify the certificate</h5>
<p>You can see the certificate’s info with the following:</p>
<pre># openssl x509 -subject -issuer -enddate -noout -in /etc/pki_jungle/myCA/certs/server.crt</pre>
<p>Or the following:</p>
<pre># openssl x509 -in certs/server.crt -noout -text</pre>
<p>And verify that the certificate is valid for server authentication with the following:</p>
<pre># openssl verify -purpose sslserver -CAfile /etc/pki_jungle/myCA/certs/myca.crt /etc/pki_jungle/myCA/certs/server.crt</pre>
<h5>Server certificate and key in one file</h5>
<p>Some servers, for example vsftpd, require that both the private key and the certificate exist in the same file. In a situation like that just do the following:</p>
<pre># cat certs/server.crt private/server.key &gt; private/server-key-cert.pem</pre>
<p>You should restrict access to the final file and delete server.crt and server.key since thay are no longer needed.</p>
<pre># chown root.root private/server-key-cert.pem
# chmod 0400 private/server-key-cert.pem
# rm -f certs/server.crt
# rm -f private/server.key</pre>
<h4>Revoke a Server Certificate</h4>
<p>If you do not want a certificate to be valid any more, you have to revoke it. This is done with the command:</p>
<pre># openssl ca -config openssl.my.cnf -revoke certs/server.crt</pre>
<p>Then you should generate a new CRL (Certificate Revokation List):</p>
<pre># openssl ca -config openssl.my.cnf -gencrl -out crl/myca.crl</pre>
<p>The CRL file is <strong>crl/myca.crl</strong>.</p>
<h4>Distribute your certificates and CRL</h4>
<p>Your CA’s certificate and your servers’ certificates should be distributed to those who trust you so they can import them in their client software (web browsers, ftp clients, email clients etc). The CRL should also be published.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/02/18/be-your-own-certificate-authority-ca/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sendmail Problem</title>
		<link>http://blog.nataprawira.com/tech/2009/02/13/sendmail-problem/</link>
		<comments>http://blog.nataprawira.com/tech/2009/02/13/sendmail-problem/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 07:27:40 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Sendmail]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=33</guid>
		<description><![CDATA[

There are often problems with sendmail once it has been installed due to the  tightening up of sendmail to stop spammers

Sendmail-8.11.6-15 Connection refused
Sendmail &#38; tcp wrapper rejection
Cannot relay from valid  ip address (Outlook)


 1) Sendmail-8.11.6-15 Connection refused
Cannot telnet to port 25, then Sendmail has not been corretly set up. This is a problem [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F13%2Fsendmail-problem%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F13%2Fsendmail-problem%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p class="text">There are often problems with sendmail once it has been installed due to the  tightening up of sendmail to stop spammers</p>
<blockquote>
<p class="head3"><a href="http://mail.access-info.co.nz/docs/?postid=11#sendmail-8.11.6-15%20Connection%20refused" target="_blank">Sendmail-8.11.6-15 Connection refused</a></p>
<p class="head3"><a href="http://mail.access-info.co.nz/docs/?postid=11#Sendmail%20&amp;%20tcpwrappers%20rejection" target="_blank">Sendmail &amp; tcp wrapper rejection</a></p>
<p class="head3"><a href="http://mail.access-info.co.nz/docs/?postid=11#Cannot%20relay%20from%20valid%20ip%20address%20%28Outlook%29" target="_blank">Cannot relay from valid  ip address (Outlook)</a></p>
</blockquote>
<p class="head2"><span id="more-33"></span></p>
<p class="head2"><strong> 1) <a name="sendmail-8.11.6-15 Connection refused">Sendmail-8.11.6-15 Connection refused</a></strong></p>
<p class="text">Cannot telnet to port 25, then Sendmail has not been corretly set up. This is a problem with RedHat 7.3 or more where Sendmail by default is set to only send from the localhost, you could say this is Good as Sendmail can not spew when set up on a system that is not going to use it.</p>
<p class="head3">File: <span style="text-decoration: underline"><strong>/etc/sendmail.cf</strong></span></p>
<p class="text">Did you make the DAEMON_OPTIONS change mentioned in the release notes? Your sendmail.cf should *NOT* have this line:</p>
<blockquote>
<p class="commands"><strong> O DaemonPortOptions=Port=smtp,Addr=127.0.0.1, Name=MTA</strong></p>
</blockquote>
<p class="text">It needs to be hashed out to this:</p>
<blockquote>
<p class="head3"><strong> #O DaemonPortOptions=Port=smtp,Addr=127.0.0.1, Name=MTA</strong></p>
</blockquote>
<p class="head3">
<p class="head3">File: <span style="text-decoration: underline"><strong>/etc/mail/sendmail.mc</strong></span></p>
<p class="text">You can also change sendmail.mc, but this is just the configuration file that is used to create sendmail.cf. You can either delete it or change the .mc file from</p>
<blockquote>
<p class="commands"><strong> DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA&#8217;)</strong></p>
</blockquote>
<p class="text">to:</p>
<blockquote>
<p class="commands"><strong> dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA&#8217;)</strong></p>
</blockquote>
<p class="text">You do not need to rebuild sendmail.cf if you make the changes directly to sendmail.cf.</p>
<p class="text">To rebuild sendmail.cf is a headache so better to edit sendmail.cf and restart sendmail.</p>
<p class="text">
<p class="head2"><strong> 2) <a name="Sendmail &amp; tcpwrappers rejection">Sendmail &amp; tcpwrappers rejection</a></strong></p>
<p class="head3">File: <span style="text-decoration: underline"><strong>/etc/hosts.allow</strong></span></p>
<blockquote>
<p class="commands"><strong> sendmail: ALL EXCEPT \<br />
203.204. \<br />
218. </strong></p>
</blockquote>
<p class="head2">
<p class="head2"><strong>3) <a name="Cannot relay from valid ip address (Outlook)"> Cannot relay from valid ip address (Outlook)</a></strong></p>
<p class="text">Sendmail has been installed and the above patches have been  appilied, email is being sent fine from with in Horde, but as soon as a valid  client (ip address) seeks to send emails through the server using a client mail  program (outlook), we get a Relaying Rejected message.</p>
<p class="text">The answer to this problem was archived when researching this  page on sendmail.org.<br />
<a href="http://www.sendmail.org/%7Eca/email/relayingdenied.html" target="_blank"> http://www.sendmail.org/~ca/email/relayingdenied.html</a></p>
<p class="commands"><strong>Feb 24 08:39:20 mail sendmail[17602]: i1NJdKCq017602:  ruleset=check_rcpt, arg1=&lt;someone@someone.co.nz&gt;, relay=me.somehereelse.co.nz  [192.168.xx.19], reject=550 5.7.1 &lt;someone@someone.co.nz&gt;&#8230; Relaying denied</strong><br />
<em> (parts of message changed for security)</em></p>
<p class="text">Generally the /etc/mail/access file only has allowed client ip  addresses for relaying. Now with new versions of Sendmail I have found it  necessary to put in the allowed name that the PCs are giving to sendmail.</p>
<p class="head3">File: <span style="text-decoration: underline"><strong>/etc/mail/access</strong></span></p>
<blockquote>
<p class="commands"><strong>access-info.co.nz                  RELAY</strong></p>
</blockquote>
<p class="text">This lines is needed in /etc/mail/access to enable name  resolution.</p>
<p class="text">You may also need the following line in hosts to also enable dns  ip lookup</p>
<p class="head3">File: <span style="text-decoration: underline"><strong>/etc/hosts</strong></span></p>
<blockquote>
<p class="commands"><strong>192.168.xx.xx    laptop.access-info.co.nz     laptop</strong></p>
</blockquote>
<p class="text">Replace xs with valid ip address for the PC trying to send via  outlook.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/02/13/sendmail-problem/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CSS Underscore Hack</title>
		<link>http://blog.nataprawira.com/tech/2009/02/06/css-underscore-hack/</link>
		<comments>http://blog.nataprawira.com/tech/2009/02/06/css-underscore-hack/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 04:08:07 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Underscore Hack]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=32</guid>
		<description><![CDATA[

Original Post



 Update: note that this article is from 2003. The CSS hack described is outdated and (maybe) shouldn’t be used.
I learned another CSS hack today – the underscore hack. You can read all about it in detail, but in essence it’s very simple.
Browsers are supposed to simply ignore CSS properties that they don’t understand. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F06%2Fcss-underscore-hack%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F06%2Fcss-underscore-hack%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><abbr class="updated" title="00"><em><strong><a title="Original Post" href="http://allinthehead.com/retro/150/" target="_blank">Original Post</a></strong></em><br />
</abbr></p>
<div class="entry-content">
<blockquote><p><strong><br />
<em> </em>Update:</strong> note that this article is from 2003. The <span class="caps">CSS</span> hack described is outdated and (maybe) shouldn’t be used.</p></blockquote>
<p>I learned another <span class="caps">CSS</span> hack today – the underscore hack. You can <a title="The Underscore Hack" href="http://www.pixy.cz/blogg/clanky/cssunderscorehack/" target="_blank">read all about it in detail</a>, but in essence it’s very simple.</p>
<p>Browsers are supposed to simply ignore <span class="caps">CSS</span> properties that they don’t understand. This much should be obvious. However, IE/Win does its usual trick of trying too hard to cope with user error and will read and process any valid <span class="caps">CSS</span> property with an underscore tacked on to the front. All other browsers will ignore the mystery property. Example:</p>
<pre><strong><code>p{
   color: black;
   _color: blue;
}</code></strong></pre>
<p>All browsers save IE/Win will display the paragraph text as black – IE/Win displays it as blue. It reads the <strong><code>_color</code></strong> property and allows it to replace the one that came before.</p>
<p>I discovered this technique whilst looking for a solution to IE’s lack of support for <code>min-height</code> to specify the minimum height of an object. Decent browsers like Mozilla support this property, but IE doesn’t. Thanks to another IE bug (one that results in <strong><code>overflow</code> </strong>being treated strangely), it’s possible to set a minimum height for both IE and proper browsers in a fashion such as this:</p>
<pre><strong><code>div#content{
    height: auto;
    min-height: 400px;
    _height: 400px;
}</code></strong></pre>
<p>Not a new technique, but new to me, and helped me out of a layout problem. Be sure to read <a title="Simon Willison - The Underscore Hack" href="http://simon.incutio.com/archive/2003/11/23/underscore" target="_blank">Simon’s discussion</a> of the pros and cons. With the appropriate care, it’s a useful tool to add to your hack list.</p>
</div>
<address> &#8211; <a href="http://allinthehead.com/retro/150/#about" target="_blank">Drew McLellan</a> </address>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/02/06/css-underscore-hack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Schedule Tasks in Windows Server 2003</title>
		<link>http://blog.nataprawira.com/tech/2009/02/02/how-to-schedule-tasks-in-windows-server-2003/</link>
		<comments>http://blog.nataprawira.com/tech/2009/02/02/how-to-schedule-tasks-in-windows-server-2003/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 03:54:51 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Schedule Tasks]]></category>
		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=30</guid>
		<description><![CDATA[

In Windows Server 2003, you can use Scheduled Tasks in 		  Control Panel to create, delete, configure, or display scheduled tasks. You can 		  also use Schtasks.exe to schedule tasks manually.
Back to the top
Overview of the 				Schtasks.exe Tool

loadTOCNode(2, &#8217;summary&#8217;);
Schtasks schedules commands and programs to run periodically or at 		  a specific time. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F02%2Fhow-to-schedule-tasks-in-windows-server-2003%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F02%2F02%2Fhow-to-schedule-tasks-in-windows-server-2003%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>In Windows Server 2003, you can use Scheduled Tasks in 		  Control Panel to create, delete, configure, or display scheduled tasks. You can 		  also use Schtasks.exe to schedule tasks manually.</p>
<div class="topOfPage"><a href="http://support.microsoft.com/kb/814596#top"><img src="http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif" alt="" />Back to the top</a></div>
<h3>Overview of the 				Schtasks.exe Tool</h3>
<p><span id="more-30"></span></p>
<p>loadTOCNode(2, &#8217;summary&#8217;);<br />
Schtasks schedules commands and programs to run periodically or at 		  a specific time. Schtasks adds and removes tasks from the schedule, starts and 		  stops tasks on demand, and displays and changes scheduled tasks.</p>
<div class="topOfPage"><a href="http://support.microsoft.com/kb/814596#top"><img src="http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif" alt="" />Back to the top</a></div>
<h3>Syntax and Parameters</h3>
<p>loadTOCNode(2, &#8217;summary&#8217;);<br />
The following is a list of the syntax and parameters that you can 		  use with Schtasks.exe:</p>
<ul>
<li>
<h4>Schtasks /Create</h4>
<p>loadTOCNode(3, &#8217;summary&#8217;);<br />
Creates a new scheduled task.</p>
<ul>
<li><strong>Syntax</strong>:<br />
<strong>schtasks /create</strong><strong>/tn </strong><em>TaskName </em><strong>/tr </strong><em>TaskRun </em><strong>/sc </strong><em>schedule </em>[<strong>/mo </strong><em>modifier</em>] [<strong>/d </strong><em>day</em>] [<strong>/m </strong><em>month</em>[,<em>month</em>...] [<strong>/i </strong><em>IdleTime</em>] [<strong>/st </strong><em>StartTime</em>] [<strong>/sd </strong><em> StartDate</em>] [<strong>/ed </strong><em>EndDate</em>] [<strong>/du </strong><em>duration</em>] [<strong>/s </strong><em>computer</em> [<strong>/u </strong> [<em>domain\]user </em><strong>/p </strong><em>password</em>]] [<strong>/ru </strong> {[<em>Domain\]User</em> | <em>&#8220;System&#8221;</em>} [<strong>/rp </strong><em>Password</em>]] <strong>/?</strong></li>
<li><strong>Parameters</strong>:
<ul>
<li><strong>/tn </strong><em>TaskName</em> Specifies a name for the task.</li>
<li><strong>/tr </strong><em>TaskRun</em> Specifies the program or command that the task runs. Type the 						  fully qualified path and file name of an executable file, script file, or batch 						  file. If you omit the path, Schtasks.exe assumes that the file is in the 						  Systemroot\System32 folder.</li>
<li><strong>/sc </strong><em>schedule</em> Specifies the schedule type. Valid values are MINUTE, HOURLY, 						  DAILY, WEEKLY, MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE.</li>
<li><strong>/mo </strong><em> modifier</em> Specifies how frequently the task runs in its schedule type. This 						  parameter is required for a MONTHLY schedule. This parameter is valid, but 						  optional, for a MINUTE, HOURLY, DAILY, or WEEKLY schedule. The default value is 						  1.</li>
<li><strong>/d </strong><em> day</em> Specifies a day of the week or a day of a month. Valid only with 						  a WEEKLY or MONTHLY schedule.</li>
<li><strong>/m </strong><em>month</em>[,<em>month</em>...] Specifies a month of the year. Valid values are JAN &#8211; DEC and 						  * (every month). The <strong>/m </strong> parameter is valid only with a MONTHLY schedule. It is required 						  when the LASTDAY modifier is used. Otherwise, it is optional and the default 						  value is * (every month).</li>
<li><strong>/i </strong><em>IdleTime</em> Specifies how many minutes the computer is idle before the task 						  starts. Type a whole number from 1 to 999. This parameter is valid only with an 						  ONIDLE schedule, and then it is required.</li>
<li><strong>/st </strong><em>StartTime</em> Specifies the time of day that the task starts in HH:MM:SS 						  24-hour format. The default value is the current local time when the command 						  completes. The <strong>/st </strong> parameter is valid with MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, 						  and ONCE schedules. It is required with a ONCE schedule.</li>
<li><strong>/sd </strong><em>StartDate</em> Specifies the date that the task starts in MM/DD/YYYY format. The 						  default value is the current date. The <strong>/sd </strong> parameter is valid with all schedules, and is required for a ONCE 						  schedule.</li>
<li><strong>/ed </strong><em>EndDate</em> Specifies the last date that the task is scheduled to run. This 						  parameter is optional. It is not valid in a ONCE, ONSTART, ONLOGON, or ONIDLE 						  schedule. By default, schedules have no ending date.</li>
<li><strong>/du</strong><em> Duration</em> Specifies a maximum length of time for a minute or hourly schedule in the <em> HHHH:MM</em> 24-hour format. After the specified time elapses, Schtasks does not start the task again until the start time happens again. By default, task schedules have no maximum duration. This parameter is optional and valid only with a MINUTE or HOURLY schedule.</li>
<li><strong>/s </strong><em>Computer</em> Specifies the name or IP address of a remote computer, with or 						  without backslash characters. The default is the local computer.</li>
<li><strong>/u </strong> [<em>domain\</em>]<em>user</em> Runs the command with the permissions of the specified user 						  account. By default, the command runs with the permissions of the user who is 						  logged on to the computer that is running Schtasks.</li>
<li><strong>/p </strong><em>password</em> Specifies the password of the user account that you specified in 						  the /u parameter. This parameter is required when the <strong>/u </strong><em>parameter</em> is used.</li>
<li><strong>/ru </strong> {[<em>Domain</em>\]<em>User</em> | <em>&#8220;System&#8221;</em>} Runs the tasks with the permission of the specified user 						  account. By default, the task runs with the permissions of the user who is 						  logged on to the computer that is running Schtasks.</li>
<li><strong>/rp </strong><em>Password</em> Specifies the password of the user account that is specified in 						  the <strong>/ru </strong> parameter. If you omit this parameter when you specify a user 						  account, Schtasks.exe prompts you for the password and obscures the text you 						  type. Tasks that run with permissions of the NT Authority\System account do not 						  require a password and Schtasks.exe does not prompt for one.</li>
<li><strong>/? </strong> Displays help at the command prompt.</li>
</ul>
</li>
</ul>
<p><span><a href="http://support.microsoft.com/kb/814596#1">back to the 				top</a></span></li>
<li>
<h4>Schtasks /Change</h4>
<p>loadTOCNode(3, &#8217;summary&#8217;);<br />
Changes one or more of the following properties of a task:</p>
<ul>
<li>The program that the task runs (<strong>/tr </strong>).</li>
<li>The user account under which the task runs (<strong>/ru </strong>).</li>
<li>The password for the user account (<strong>/rp </strong>).</li>
</ul>
<ul>
<li><strong>Syntax</strong>:<strong>schtasks /change /tn </strong> TaskName [<strong>/s </strong><em>computer</em> [<em>/u [domain\]user</em><strong> /p </strong><em>password</em>]] [<strong>/tr </strong> TaskRun] [<strong>/ru </strong> [<em>Domain\]User | &#8220;System&#8221;</em>] [<strong>/rp </strong><em>Password</em>]</li>
<li><strong>Parameters</strong>:
<ul>
<li><strong>/tn </strong><em> TaskName</em> Identifies the task to be changed. Type the task name.</li>
<li><strong>/s </strong><em>Computer</em> Specifies the name or IP address of a remote computer with or 						  without backslash characters. The default is the local computer.</li>
<li><strong>/u </strong> [<em>domain\</em>]<em>user </em>Runs the command with the permissions of the specified user 						  account. By default, the command runs with the permissions of the user who is 						  logged on to the computer that is running Schtasks.</li>
<li><strong>/p </strong><em>password </em>Specifies the password of the user account that you specified in 						  the /u parameter. This parameter is required when the /u parameter is used.</li>
<li><strong>/tr </strong><em>TaskRun </em>Changes the program that the task runs. Type the fully qualified 						  path and file name of an executable file, script file, or batch file. If you 						  omit the path, Schtasks.exe assumes that the file is in the Systemroot\System32 						  folder. The specified program replaces the original program that is run by the 						  task.</li>
<li><strong>/ru </strong> [<em>Domain\</em>]<em>User | &#8220;System&#8221;</em> Changes the user account for the task.</li>
<li><strong>/rp </strong><em>Password </em>Changes the account password for the task. Type the new password.</li>
<li><strong>/? </strong> Displays help at the command prompt.</li>
</ul>
</li>
</ul>
<p><span><a href="http://support.microsoft.com/kb/814596#1">back to the 				top</a></span></li>
<li>
<h4>Schtasks /Run</h4>
<p>loadTOCNode(3, &#8217;summary&#8217;);<br />
Starts a scheduled task immediately. The run operation ignores the 				schedule, but uses the program file location, user account, and password that 				are saved in the task to run the task immediately.</p>
<ul>
<li><strong>Syntax</strong>:<strong>schtasks /run /tn </strong><em>TaskName </em>[<strong>/s </strong><em>computer </em>[<strong>/u </strong> [<em>domain\</em>]<em>user </em><strong>/p</strong><em> password</em>]] <strong>/? </strong></li>
<li><strong>Parameters</strong>:
<ul>
<li><strong>/tn </strong><em>TaskName </em>Identifies the task. This parameter is required.</li>
<li><strong>/s </strong><em>Computer </em>Specifies the name or IP address of a remote computer with or 						  without backslash characters. The default is the local computer.</li>
<li><strong>/u </strong> [<em>domain\</em>]<em>user </em>Runs the command with the permissions of the specified user 						  account. By default, the command runs with the permissions of the user who it 						  logged on to the computer that is running Schtasks.</li>
<li><strong>/p </strong><em>password </em>Specifies the password of the user account that you specified in 						  the /u parameter. This parameter is required when the /u parameter is used.</li>
<li><strong>/? </strong> Displays help at the command prompt.</li>
</ul>
</li>
</ul>
<p><span><a href="http://support.microsoft.com/kb/814596#1">back to the 				top</a></span></li>
<li>
<h4>Schtasks /End</h4>
<p>loadTOCNode(3, &#8217;summary&#8217;);<br />
Stops a program that was started by a task.</p>
<ul>
<li><strong>Syntax</strong>: <strong>schtasks /end /tn </strong><em>TaskName </em>[<strong>/s </strong><em>computer</em> [<strong>/u </strong> [<em>domain\</em>]<em>user </em><strong>/p </strong><em>password</em>]] <strong>/? </strong></li>
<li><strong>Parameters</strong>:
<ul>
<li><strong>/tn </strong><em>TaskName </em>Identifies the task that started the program. This parameter is 						  required.</li>
<li><strong>/s </strong><em>Computer </em>Specifies the name or IP address of a remote computer with or 						  without backslash characters. The default is the local computer.</li>
<li><strong>/u </strong> [<em>domain\</em>]<em>user</em> Runs the command with the permissions of the specified user 						  account. By default, the command runs with the permissions of the user who is 						  logged on to the computer that is running Schtasks.</li>
<li><strong>/p </strong><em>password</em> Specifies the password of the user account that is specified in 						  the <strong>/u </strong> parameter. This parameter is required when the <strong>/u </strong> parameter is used. <strong>/? </strong> Displays help.</li>
</ul>
</li>
</ul>
<p><span><a href="http://support.microsoft.com/kb/814596#1">back to the 				top</a></span></li>
<li>
<h4>Schtasks /Delete</h4>
<p>loadTOCNode(3, &#8217;summary&#8217;);<br />
Deletes a scheduled task.</p>
<ul>
<li><strong>Syntax</strong>:<strong>schtasks /delete /tn </strong><em>{TaskName</em> |<em> *</em>} [<strong>/f </strong>] [<strong>/s </strong><em>computer</em> [<strong>/u </strong> [<em>domain</em>\]<em>user</em><strong>/p </strong><em>password</em>]] [<strong>/? </strong>]</li>
<li><strong>Parameters</strong>:
<ul>
<li><strong>/tn </strong> {<em>TaskName</em> |<em> *</em>} Identifies the task being deleted. This parameter is required.
<ul>
<li><em>TaskName</em> Deletes the named task.</li>
<li><em>*</em> Deletes all the scheduled tasks on the computer.</li>
</ul>
</li>
<li><strong>/f </strong>Suppresses the confirmation message. The task is deleted without 						  warning.</li>
<li><strong>/s </strong><em>Computer</em> Specifies the name or IP address of a remote computer with or 						  without backslash characters. The default is the local computer.</li>
<li><strong>/u </strong> [<em>domain</em>\]<em>user</em> Runs the command with the permissions of the specified user 						  account. By default, the command runs with the permissions of the user who is 						  logged on to the computer that is running Schtasks.</li>
<li><strong>/p </strong><em>password</em> Specifies the password of the user account that you specified in 						  the <strong>/u </strong> parameter. This parameter is required when the <strong>/u </strong>parameter is used.</li>
<li><strong>/? </strong> Displays help at the command prompt.</li>
</ul>
</li>
</ul>
<p><span><a href="http://support.microsoft.com/kb/814596#1">back to the 				top</a></span></li>
<li>
<h4>Schtasks /Query</h4>
<p>loadTOCNode(3, &#8217;summary&#8217;);<br />
Displays all the tasks that are scheduled to run on the computer, 				including those that are scheduled by other users:</p>
<ul>
<li><strong>Syntax</strong>:<strong>schtasks</strong> [<strong>/query</strong>] [<strong>/fo </strong> {<em>TABLE</em> | <em>LIST</em> | <em>CSV</em>}] [<strong>/nh </strong>] [<strong>/v</strong>] [<strong>/s </strong><em>computer</em> [<strong>/u </strong> [<em>domain</em>\]<em>user</em><strong>/p </strong><em>password</em>]]</li>
<li><strong>Parameters</strong>:[<strong>/query</strong>] The operation name is optional. Typing 					 <span class="userInput">schtasks</span> without any parameters performs a query.</li>
<li><strong>/fo </strong> {<em>TABLE</em> |<em> LIST</em> | <em>CSV</em>} Specifies the output format. <em>TABLE</em> is the default. <strong>/nh </strong> Omits column headings from the table display. This parameter is 					 valid with the <em>TABLE</em> and <em>CSV</em> output formats.</li>
<li><strong>/v </strong>Adds advanced properties of the tasks to the display. Queries 					 using <strong>/v </strong> should be formatted as LIST or CSV.</li>
<li><strong>/s </strong><em>Computer</em> Specifies the name or IP address of a remote computer with or 					 without backslash characters. The default is the local computer.</li>
<li><strong>/u </strong> [<em>domain</em>\]<em>user</em> Runs the command with the permissions of the specified user 					 account. By default, the command runs with the permissions of the user who is 					 logged on to the computer that is running Schtasks.</li>
<li><strong>/p </strong><em>password</em> Specifies the password of the user account that is specified in 					 the <strong>/u </strong> parameter. This parameter is required when the <strong>/u </strong> parameter is used.</li>
<li><strong>/? </strong> Displays help at the command prompt.</li>
</ul>
</li>
</ul>
<div class="topOfPage"><a href="http://support.microsoft.com/kb/814596#top"><img src="http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif" alt="" />Back to the top</a></div>
<h3>How to Create a Scheduled Task</h3>
<p>loadTOCNode(2, &#8217;summary&#8217;);<br />
To create a scheduled task:</p>
<ol>
<li>Click <strong>Start</strong>, click <strong>Run</strong>, 				type <span class="userInput">cmd</span>, and then click <strong>OK</strong>.</li>
<li>At the command prompt, type <span class="userInput">net 				start</span>, and then press ENTER to display a list of currently running 				services. If Task Scheduler is not displayed in the list, type <strong>net 				start &#8220;task scheduler&#8221;</strong>, and then press ENTER.</li>
<li>At the command prompt, type <span class="userInput">schtasks /create /tn 				&#8220;<var>Application_Name</var>&#8221; /tr 				c:\apps\<var>Application_Name</var> /sc 				<var>Value</var> /st <var>HH:MM:SS</var> /ed 				<var>MM/DD/YYYY</var></span>, and then press ENTER. Note 				that you may have to change the parameters for your situation. For example, you 				might type <span class="userInput">schtasks /create /tn &#8220;My App&#8221; /tr c:\apps\myapp.exe /sc 				daily /st 08:00:00 /ed 12/31/2004 </span> This example schedules the MyApp 				program to run once a day, every day, at 8:00 A.M. until December 31, 2004. 				Because it omits the /mo parameter, the default interval of 1 is used to run 				the command every day.</li>
</ol>
<div class="topOfPage"><a href="http://support.microsoft.com/kb/814596#top"><img src="http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif" alt="" />Back to the top</a></div>
<h3>How to Change a Scheduled Task</h3>
<p>loadTOCNode(2, &#8217;summary&#8217;);<br />
To change a scheduled task:</p>
<ol>
<li>Click <strong>Start</strong>, click <strong>Run</strong>, 				type <span class="userInput">cmd</span>, and then click <strong>OK</strong>.</li>
<li>At the command prompt, type<span class="userInput">net 				start</span>, and then press ENTER to display a list of currently running 				services. If Task Scheduler is not displayed in the list, type <strong>net 				start &#8220;task scheduler&#8221;</strong>, and then press ENTER.</li>
<li>At the command prompt, type<span class="userInput">schtasks /change /tn <em>TaskName</em> [/s <em>computer</em> [/u [<em>domain</em>\]<em>user</em> /p <em>password</em>]] [/tr <em>TaskRun</em>] [/ru [<em>Domain</em>\]<em>User</em> | &#8220;System&#8221;] [/rp <em>Password</em>] </span>, and then press ENTER. Note that you may have to 				change the parameters for your situation. For example, to change the program 				that a task runs, type: <span class="userInput">schtasks /change /tn &#8220;Application_Name&#8221; /tr 				C:\File_Path\Application_Name.exe</span></li>
</ol>
<div class="topOfPage"><a href="http://support.microsoft.com/kb/814596#top"><img src="http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif" alt="" />Back to the top</a></div>
<h3>How to Run a Scheduled Task</h3>
<p>loadTOCNode(2, &#8217;summary&#8217;);<br />
To manually run a scheduled task outside its schedule:</p>
<ol>
<li>Click <strong>Start</strong>, click <strong>Run</strong>, 				type <span class="userInput">cmd</span>, and then click <strong>OK</strong>.</li>
<li>At the command prompt, type <span class="userInput">net 				start</span>, and then press ENTER to display a list of currently running 				services. If Task Scheduler is not displayed in the list, type <strong>net 				start &#8220;task scheduler&#8221;</strong>, and then press ENTER.</li>
<li>At the command prompt, type <span class="userInput">schtasks /run /tn <em>TaskName</em> [/s <em>computer</em> [/u [<em>domain</em>\]<em>user</em> /p<em> password</em>]] </span>, and then press ENTER. Note that you may have to 				change the parameters for your situation. For example, to run a task on the 				local computer, type <span class="userInput"> schtasks /run /tn 				&#8220;<var>Task_Name</var>&#8221; </span>.</li>
</ol>
<div class="topOfPage"><a href="http://support.microsoft.com/kb/814596#top"><img src="http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif" alt="" />Back to the top</a></div>
<h3>How to End a Scheduled Task</h3>
<p>loadTOCNode(2, &#8217;summary&#8217;);<br />
To end a scheduled task:</p>
<ol>
<li>Click <strong>Start</strong>, click <strong>Run</strong>, 				type <span class="userInput">cmd</span>, and then click <strong>OK</strong>.</li>
<li>At the command prompt, type <span class="userInput">net 				start</span>, and then press ENTER to display a list of currently running 				services. If Task Scheduler is not displayed in the list, type <strong>net 				start &#8220;task scheduler&#8221;</strong>, and then press ENTER.</li>
<li>At the command prompt, type <span class="userInput"><strong>schtasks /end /tn </strong>TaskName [<strong>/s</strong> computer [<strong>/u</strong> [domain\]user <strong>/p</strong> password]] </span>, and then press ENTER. For example, to 				end the instances of a program that was started by a scheduled task on a local 				computer, type <span class="userInput">schtasks /end /tn 				&#8220;<var>Task_Name</var>&#8220;</span>.</li>
</ol>
<div class="topOfPage"><a href="http://support.microsoft.com/kb/814596#top"><img src="http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif" alt="" />Back to the top</a></div>
<h3>How to Delete a Scheduled Task</h3>
<p>loadTOCNode(2, &#8217;summary&#8217;);<br />
To delete a scheduled task:</p>
<ol>
<li>Click <strong>Start</strong>, click <strong>Run</strong>, 				type <span class="userInput">cmd</span>, and then click <strong>OK</strong>.</li>
<li>At the command prompt, type <span class="userInput">net 				start</span>, and then press ENTER to display a list of currently running 				services. If Task Scheduler is not displayed in the list, type <strong>net 				start &#8220;task scheduler&#8221;</strong>, and then press ENTER.</li>
<li>At the command prompt, type <span class="userInput"><strong>schtasks /delete /tn</strong> {TaskName | *} [<strong>/f</strong>] [<strong>/s</strong> computer [<strong>/u</strong> [domain\]user <strong>/p</strong> password]]</span>, and then press ENTER. For example, to 				delete all tasks scheduled for the local computer, type <span class="userInput">schtasks 				/delete /tn * /f</span>.</li>
</ol>
<div class="topOfPage"><a href="http://support.microsoft.com/kb/814596#top"><img src="http://support.microsoft.com/library/images/support/kbgraphics/public/en-us/uparrow.gif" alt="" />Back to the top</a></div>
<h3>How to Perform a Query of Scheduled Tasks</h3>
<p>loadTOCNode(2, &#8217;summary&#8217;);<br />
To perform a query of scheduled tasks:</p>
<ol>
<li>Click <strong>Start</strong>, click <strong>Run</strong>, 				type <span class="userInput">cmd</span>, and then click <strong>OK</strong>.</li>
<li>At the command prompt, type <span class="userInput">net 				start</span>, and then press ENTER to display a list of currently running 				services. If Task Scheduler is not displayed in the list, type <strong>net 				start &#8220;task scheduler&#8221;</strong>, and then press ENTER.</li>
<li>At the command prompt, type <span class="userInput">schtasks /query </span>, and then press ENTER. Output from this example displays a table 				of tasks that have been scheduled to run.</li>
</ol>
<p>For more information about how to use Schtasks.exe, search for 		  Schtasks.exe in Windo</p>
<div class="indent">After the specified time elapses, Schtasks does not start the task again until the start time recurs. By default, task schedules have no maximum duration. This parameter is optional and valid only with a MINUTE or HOURLY schedule.</div>
<p>ws Server 2003 Help.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/02/02/how-to-schedule-tasks-in-windows-server-2003/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Data Recovery on Linux and ext3</title>
		<link>http://blog.nataprawira.com/tech/2009/01/21/data-recovery-on-linux-and-ext3/</link>
		<comments>http://blog.nataprawira.com/tech/2009/01/21/data-recovery-on-linux-and-ext3/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 04:42:20 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[ext3]]></category>
		<category><![CDATA[Recovery]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=29</guid>
		<description><![CDATA[

By: Abe Getchell 2008-10-03
This article discusses the process of recovering deleted data from an ext3 partition, on a system running Linux, using a process called data carving. This basic technique is useful in any number of situations, such as recovering data that has been accidentally deleted by a user, information removed in an attempt to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F01%2F21%2Fdata-recovery-on-linux-and-ext3%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F01%2F21%2Fdata-recovery-on-linux-and-ext3%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><em>By: Abe Getchell 2008-10-03</em></p>
<p>This article discusses the process of recovering deleted data from an ext3 partition, on a system running Linux, using a process called data carving. This basic technique is useful in any number of situations, such as recovering data that has been accidentally deleted by a user, information removed in an attempt to erase signs of a system intrusion that could be used to track the source, or data erased by an end-user attempting to cover up an acceptable use policy infraction.</p>
<p><span id="more-29"></span></p>
<p>This article assumes that you have a basic understanding of ext3 and the inner workings of filesystems. It is important to note that there is a certain amount of risk associated with this process. When performed improperly, the data you are attempting to recover, or other data stored on the system, could be permanently lost. While this technique is quite accurate most of the time, and very useful in any number of different situations, it is not &#8220;forensically sound&#8221; and will not hold up legally for use in court. Special software, hardware, and procedures &#8212; or professional services &#8212; are a must in situations when legal action is required.</p>
<p>The tools used in this article are freely available and can be downloaded from their respective websites.</p>
<p><strong>The basic recovery process</strong></p>
<p>In this section we will go step-by-step through the data recovery process and describe the tools, and their options, in detail. We start by listing a directory below.</p>
<p>[abe@abe-laptop test]$ ls -al<br />
total 27<br />
drwxrwxr-x 2 abe abe 4096 2008-03-29 17:48 .<br />
drwx&#8212;&#8212; 71 abe abe 4096 2008-03-29 17:47 ..<br />
-rwxr&#8211;r&#8211; 1 abe abe 42736 2008-03-29 17:47 weimaraner1.jpg</p>
<p>In the listing above we can see that there is a file named weimaraner1.jpg in the test directory. This is a picture of my dog. I don&#8217;t want to delete it. I like my dog.</p>
<p>[abe@abe-laptop test]$ rm -f *</p>
<p>Here we can see I am deleting it. Whoops! Sorry buddy. Let&#8217;s gather some basic information about the system so we can begin the recovery process.</p>
<p>[abe@abe-laptop test]$ df -h<br />
Filesystem Size Used Avail Use% Mounted on<br />
/dev/sda2 71G 14G 53G 21% /<br />
/dev/sda1 99M 19M 76M 20% /boot<br />
tmpfs 1007M 12K 1007M 1% /dev/shm<br />
/dev/sdb1 887M 152M 735M 18% /media/PUBLIC</p>
<p>Here we see that the full path to the test directory (which is /home/abe/test) is part of the / filesystem, represented by the device file /dev/sda2.</p>
<p>[abe@abe-laptop test]$ su -<br />
Password:<br />
[root@abe-laptop ~]# debugfs /dev/sda2</p>
<p>Using su to gain root access, we can start the debugfs program giving it the target of /dev/sda2. The debugfs program is an interactive file system debugger that is installed by default with most common Linux distributions. This program is used to manually examine and change the state of a filesystem. In our situation, we&#8217;re going to use this program to determine the inode which stored information about the deleted file and to what block group the deleted file belonged.</p>
<p>debugfs 1.40.4 (31-Dec-2007)<br />
debugfs: cd /home/abe/test<br />
debugfs: ls -d<br />
1835327 (12) . 65538 (4084) .. &lt;1835328&gt; (4072) weimaraner1.jpg</p>
<p>After debugfs starts, we cd into /home/abe/test and run the ls -d command. This command shows us all deleted entries in the current directory. The output shows us that we have one deleted entry and that its inode number is 1835328 &#8212; that is, the number between the angular brackets.</p>
<p>debugfs: imap &lt;1835328&gt;<br />
Inode 1835328 is part of block group 56<br />
located at block 1835019, offset 0&#215;0f80</p>
<p>The next command we want to run is imap, giving it the inode number above so we can determine to which block group the file belonged. We see by the output that it belonged to block group 56.</p>
<p>debugfs: stats<br />
[...lots of output...]<br />
Blocks per group: 32768<br />
[...lots of output...]<br />
debugfs: q</p>
<p>Running the stats command will generate a lot of output. The only data we are interested in from this list, however, is the number of blocks per group. In this case, and most cases, it’s 32768. Now we have enough data to be able to determine the specific set of blocks in which the data resided. We&#8217;re done with debugfs now, so we type q to quit.</p>
<p>[root@abe-laptop ~]# dls /dev/sda2 1835008-1867775 &gt; /media/PUBLIC/block.dat</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>The next thing we need to do is pull all unallocated blocks from block group 56 so we can examine their content. The dls program, from The Sleuth Kit (TSK), allows us to do just that. We simply need to know the device file, a range of blocks, and have enough space in the appropriate place to output this data. Using the information above, we can calculate the block range by multiplying the block group number and the block group size and then multiplying the block group number plus one by the blocks per group minus one. In this case, the formula would look like this:</p>
<p>(56 x 32768) through ((56 + 1) x 32768 &#8211; 1)</p>
<p>This would give us a range of 1835008 through 1867775. It&#8217;s very important that the destination of the output does not reside on the same partition as the data you&#8217;re attempting to recover. What will most likely be a large amount of data being written to disk from the output of this command could potentially overwrite the data you are trying to recover (as the blocks which stored the data from the deleted file have already been marked unallocated). You want as little disk activity as possible on the partition you&#8217;re working with. In this example, I&#8217;m using a USB thumb drive (located on /media/PUBLIC) as a location to store this data.</p>
<p>[root@abe-laptop ~]# mkdir /media/PUBLIC/output<br />
[root@abe-laptop ~]# foremost -dv -t jpg -i /media/PUBLIC/block.dat -o /media/PUBLIC/output/</p>
<p>Next we need to attempt to extract this data from the unallocated blocks we extracted with the dls command above. To do this, we are going to use Foremost. This program is used to recover files based on header information, footer information, and internal data structures. This is the process, mentioned earlier, called data carving. First we are going to create a directory to store the foremost output (again, this should be on a separate partition). Next we are going to run the foremost command giving it the file type of jpg (which is an internally recognized type &#8211; more on custom types below), the input file, and the output directory. The output from this command is listed below.</p>
<p>Foremost version 1.5.3 by Jesse Kornblum, Kris Kendall, and Nick Mikus<br />
Audit File</p>
<p>Foremost started at Sat Mar 29 18:02:29 2008<br />
Invocation: foremost -dv -t jpg -i /media/PUBLIC/block.dat -o /media/PUBLIC/output/<br />
Output directory: /media/PUBLIC/output<br />
Configuration file: /usr/local/etc/foremost.conf<br />
Processing: /media/PUBLIC/block.dat<br />
|&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
File: /media/PUBLIC/block.dat<br />
Start: Sat Mar 29 18:02:29 2008<br />
Length: 110 MB (115941376 bytes)</p>
<p>Num Name (bs=512) Size File Offset Comment</p>
<p>0: 00033272.jpg 26 KB 17035264<br />
1: 00033328.jpg 184 KB 17063936<br />
2: 00033704.jpg 58 KB 17256448<br />
3: 00033824.jpg 62 KB 17317888</p>
<p>[...]</p>
<p>*46: 00210136.jpg 2 KB 107589632<br />
47: 00210144.jpg 3 KB 107593728<br />
48: 00210392.jpg 6 KB 107720704<br />
*<br />
Finish: Sat Mar 29 18:02:29 2008</p>
<p>49 FILES EXTRACTED</p>
<p>jpg:= 49<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Foremost finished at Sat Mar 29 18:02:29 2008<br />
[root@abe-laptop ~]#</p>
<p>As we can see, Foremost found forty-nine previously deleted jpg files (this output is also saved in a file named audit.txt in the root of the specified output directory). How do we know which is the file we are trying to recover? We could, as is most commonly done, open all of these files and see their contents. Another option is to simply compare file sizes. We know from our directory listing above that the jpg file we are looking for is 41k in size. There&#8217;s only one file that foremost extracted into the output directory that&#8217;s 41k, and indeed, 00114144.jpg is the file we are attempting to recover. Comparing size only works, of course, if you &#8220;know your data&#8221;. Integrity checking programs such as Tripwire play a big role in a recovery operation as you can identify the recovered data without ever inspecting the content, as well as verify its integrity. This becomes quite useful if the information you&#8217;re attempting to recover is confidential and you are not authorized to view the data.</p>
<p><strong>Defining custom types in <em>Foremost</em></strong></p>
<p>As of Foremost v1.5.3, the internally supported data types that the program will recover without custom rules are jpg, gif, png, bmp, avi, exe, mpg, wav, riff, wmv, mov, pdf, ole, doc, zip, rar, htm, and cpp. If you need to recover data beyond these built-in data types, you will need to define custom types in Foremost&#8217;s configuration file (foremost.conf).</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>An entry that defines a type in the foremost configuration file (as explained in the documentation at the beginning of foremost.conf or in the manpage) consists of several columns: extension, case sensitivity, maximum size, header and footer (optional), and special keywords (optional). As an example that most should be familiar with, here is the entry for an html file:</p>
<p>htm n 50000 &lt;html &lt;/html&gt;</p>
<p>We see here that the file extension is htm (NONE can be specified if no file extension should be used during the output of extracted data), the header and footer are not case sensitive, the maximum file size is 50k bytes (which means that 50k bytes after the header will be recovered if no footer is specified or 50k bytes will be recovered if that amount of data is recovered before the defined footer is detected), the recovered file should start with &#8220;&lt;html&#8221; (header) and end with &#8220;&lt;/html&gt;&#8221; (footer).</p>
<p>The ASCII keyword can also be used when attempting to recover ASCII files. Specifying this keyword at the end of an entry will tell Foremost to extract all ASCII printable characters before and after the keyword defined. An example of this would be a type to recover a perl script. If, for example, you need to recover a perl script that you know included Crypt::CBC, you could use the following type definition:</p>
<p>pl y 100000 Crypt::CBC Crypt::CBC ASCII</p>
<p>Note that Crypt::CBC is listed in both the header and footer fields. This is done so that Foremost will recognize this as the string to search around when the ASCII keyword is used. A more general type to find perl scripts could be defined as follows:</p>
<p>pl n 100000 #!/usr/bin/perl #!/usr/bin/perl ASCII</p>
<p>When attempting to recover files that are not ASCII, hexadecimal and octal notation can be used by specifying \x[0-f][0-f] or \[0-3][0-7][0-7], respectively. Below is an example of hexadecimal notation describing the header and footers of a gif file:</p>
<p>gif y 155000000 \x47\x49\x46\x38\x37\x61 \x00\x3b</p>
<p>As you may have realized by now, Foremost is a very powerful tool. Learn its intricacies and it can be a wonderfully flexible tool in data recovery and computer security forensic operations. Read the Foremost man page or consult the configuration file for a complete guide to creating custom data types.</p>
<p><strong>ext2 vs ext3 Data Recover </strong></p>
<p>You may be asking yourself why this process is so much more difficult with ext3 than it is with ext2? This question is answered by one of the ext3 developers in the Linux ext3 FAQ:</p>
<p>Q: How can I recover (undelete) deleted files from my ext3 partition?<br />
Actually, you can&#8217;t! This is what one of the developers, Andreas Dilger, said about it:</p>
<p>In order to ensure that ext3 can safely resume an unlink after a crash, it actually zeros out the block pointers in the inode, whereas ext2 just marks these blocks as unused in the block bitmaps and marks the inode as &#8220;deleted&#8221; and leaves the block pointers alone.<br />
Your only hope is to &#8220;grep&#8221; for parts of your files that have been deleted and hope for the best.</p>
<p>The process, as described in this article, is the &#8220;grep&#8221; that Andreas is referring to. Hopefully, as ext3 is developed further, some effort will be put in to making this process easier and more reliable.</p>
<p><strong>Conclusion</strong></p>
<p>While going through this process may be necessary to recover information lost in any number of situations, it’s not a process you want to go through on a Monday morning to recover your organization&#8217;s payroll data after an administrator fat-fingers an rm command. The single most important piece of information you should take away from this article, in that vein, is to keep current, tested backups of business critical data that reside on the systems you manage. Regardless of the reason for its use, the process covered in this article is something that every system administrator and security analyst should have in their toolbelt.</p>
<p><a href="http://www.securityfocus.com/infocus/1902/1" target="_blank"><em><strong>Source</strong></em></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/01/21/data-recovery-on-linux-and-ext3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to remove / delete  `sqmdataXX.sqm` files on my drive C:\ ?</title>
		<link>http://blog.nataprawira.com/tech/2009/01/19/how-to-remove-delete-sqmdataxxsqm-files-on-my-drive-c/</link>
		<comments>http://blog.nataprawira.com/tech/2009/01/19/how-to-remove-delete-sqmdataxxsqm-files-on-my-drive-c/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 17:35:09 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[.sqm]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[MSN]]></category>
		<category><![CDATA[Software Quality Metrics]]></category>
		<category><![CDATA[Windows Live Messenger]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=27</guid>
		<description><![CDATA[

.SQM files are created by a number of Microsoft applications, most commonly Windows Live Messenger (previously known as MSN).
According to Microsoft, SQM files (standing for Software Quality Metrics) are used as part of their &#8220;Microsoft Customer Experience Program&#8221; and help improve their products by anonymously monitoring usage habits and reporting software errors/bugs.
To stop these files [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F01%2F19%2Fhow-to-remove-delete-sqmdataxxsqm-files-on-my-drive-c%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F01%2F19%2Fhow-to-remove-delete-sqmdataxxsqm-files-on-my-drive-c%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><strong>.SQM</strong> files are created by a number of Microsoft applications, most commonly Windows Live Messenger (previously known as MSN).</p>
<p>According to Microsoft, SQM files (standing for Software Quality Metrics) are used as part of their &#8220;Microsoft Customer Experience Program&#8221; and help improve their products by anonymously monitoring usage habits and reporting software errors/bugs.</p>
<p>To stop these files being created, you will need to disable the option in Windows Live Messenger. You can do this through the options menu:</p>
<p>1. Click HELP.<br />
2. Select &#8216;Customer Experience Improvement Program&#8217;.<br />
3. Tick on &#8216;I don&#8217;t want to participate right now&#8217; box.<br />
4. Click OK.</p>
<p>Please take note, that .SQM files are NOT viruses and do not contain spyware/malware and do not contain any personal information.</p>
<p>SQM files have a naming convention such as &#8220;sqmnoopt00.sqm&#8221;. They are normally found in the root folder of your hard-drive (C:) and more recently, the &#8220;Documents and settings/Application Data/Microsoft/MSN Messenger/&#8221; folder.</p>
<p>Dot What!? visitors have found that deleting SQM files is safe. Although probably true, we advise you to backup the files first.</p>
<p style="text-align: center">################### Simple Story ###################</p>
<p style="text-align: center">By default, you participate in a data-gathering program. Open Live Messenger, click on Help, then on Customer Experience Improvement Program, then de-check the radio button which says you want to participate. Try that. It will almost certainly work, and it&#8217;s not dangerous.</p>
<p style="text-align: center">####################################################</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/01/19/how-to-remove-delete-sqmdataxxsqm-files-on-my-drive-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SMTP AUTH and STARTTLS with sendmail (RedHat, Centos, Fedora)</title>
		<link>http://blog.nataprawira.com/tech/2009/01/07/using-smtp-auth-and-starttls-with-sendmail-redhat-centos-fedora/</link>
		<comments>http://blog.nataprawira.com/tech/2009/01/07/using-smtp-auth-and-starttls-with-sendmail-redhat-centos-fedora/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 07:34:00 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Sendmail]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=26</guid>
		<description><![CDATA[

Step 1: Back up important files
Red Hat has finally placed sendmail.cf in /etc/mail, where it belongs. To verify the location of your configuration file, type this command:
sendmail -d0.20 -bv &#124; grep sendmail.cf
The default installation outputs this:
Conf file: /etc/mail/sendmail.cf (default for MTA)
Conf file: /etc/mail/sendmail.cf (selected)
Be sure to use this path when generating your new sendmail.cf from [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F01%2F07%2Fusing-smtp-auth-and-starttls-with-sendmail-redhat-centos-fedora%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2009%2F01%2F07%2Fusing-smtp-auth-and-starttls-with-sendmail-redhat-centos-fedora%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p><strong>Step 1: Back up important files</strong></p>
<p>Red Hat has finally placed sendmail.cf in /etc/mail, where it belongs. To verify the location of your configuration file, type this command:</p>
<p>sendmail -d0.20 -bv | grep sendmail.cf</p>
<p>The default installation outputs this:</p>
<p>Conf file: /etc/mail/sendmail.cf (default for MTA)<br />
Conf file: /etc/mail/sendmail.cf (selected)</p>
<p>Be sure to use this path when generating your new sendmail.cf from sendmail.mc, or no changes will take place. Back up your current sendmail.cf and the m4 file that generated it (probably /etc/mail/sendmail.mc):</p>
<p>cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf~<br />
cp /etc/mail/sendmail.mc /etc/mail/sendmail.mc~</p>
<p><strong>Step 2: Make your certificate</strong></p>
<p><span id="more-26"></span></p>
<p>We are also setting up STARTTLS, which allows sendmail to communicate over an encrypted layer using TLS. This is very important, as it allows us to use the LOGIN or PLAIN authentication mechanisms without transferring the password in plain text. It also allows the entire message to remain encrypted from the user&#8217;s machine to the mail server. If sendmail relays the message to another server that offers STARTTLS, the message will be encrypted again. But the most important advantage of this approach is that we get to authenticate using regular system logins and passwords, with no need to maintain a separate user database.</p>
<p>Red Hat&#8217;s openssl package includes a Makefile that makes it extremely easy to generate a certificate (note that on Fedora Core 4 the location is now /etc/pki/tls/certs):</p>
<p>cd /usr/share/ssl/certs<br />
make sendmail.pem</p>
<p>Just follow the prompts and be sure to use the fully qualified domain name of the mail server for the Common Name prompt. Users will still be warned that the certificate is self-signed or not trusted, but you will prevent a warning that the certificate doesn&#8217;t match the host offering it. This certificate is suitable for testing, but you may want to investigate further about the use of certificates before deploying it in a production environment, a topic that is beyond the scope of this howto.</p>
<p><strong>Step 3: Edit sendmail.mc<br />
</strong><br />
If you take a look at the sendmail.mc provided by Red Hat, you will notice that the necessary directives are already present but have been commented out (m4 doesn&#8217;t use the # symbol for comments, it starts a line with dnl, which stands for &#8220;delete until new line&#8221;). Since we want the easiest method possible, without sacrificing security, we need to edit these lines. Don&#8217;t cut &amp; paste from this web page, or you may introduce unwanted characters into your configuration file that will prevent sendmail from starting.</p>
<p>The confAUTH_OPTIONS macro allows you to instruct sendmail not to offer plain text authentication until after a secure mechanism such as TLS is active (the p option). We are also prohibiting anonymous logins (the y option). The A option is a workaround for broken MTAs:</p>
<p>define(`confAUTH_OPTIONS&#8217;, `A p y&#8217;)dnl</p>
<p>Now we define which authentication mechanisms we will trust and use:</p>
<p>TRUST_AUTH_MECH(`LOGIN PLAIN&#8217;)dnl<br />
define(`confAUTH_MECHANISMS&#8217;, `LOGIN PLAIN&#8217;)dnl</p>
<p>Next, we tell sendmail where to find the certificates:</p>
<p>define(`confCACERT_PATH&#8217;,`/usr/share/ssl/certs&#8217;)<br />
define(`confCACERT&#8217;,`/usr/share/ssl/certs/ca-bundle.crt&#8217;)<br />
define(`confSERVER_CERT&#8217;,`/usr/share/ssl/certs/sendmail.pem&#8217;)<br />
define(`confSERVER_KEY&#8217;,`/usr/share/ssl/certs/sendmail.pem&#8217;)</p>
<p>And finally, it may be useful to increase the log level for debugging purposes (delete or comment out this line after everything is working properly):</p>
<p>define(`confLOG_LEVEL&#8217;, `14&#8242;)dnl</p>
<p>Use the m4 command to generate a new sendmail.cf:</p>
<p>m4 /etc/mail/sendmail.mc &gt; /etc/mail/sendmail.cf</p>
<p>Be sure to use the right location for sendmail.cf, as determined earlier. Alternatively, you can use the following command in a stock Red Hat 9.0 or Fedora Core installation:</p>
<p>make -C /etc/mail sendmail.cf</p>
<p>This uses the commands in /etc/mail/Makefile to generate the new sendmail.cf configuration file.</p>
<p><strong>Step 4: Test the configuration<br />
</strong><br />
This is where things get really interesting. sendmail must be restarted before it can use the new configuration file. Rather than simply restarting sendmail with our fingers crossed, we can test it to verify that every thing works properly. You can stop sendmail and then start it with command line options that cause it to log to a specified file. There are various ways to stop sendmail on a Red Hat/Fedora system:</p>
<p>service sendmail stop</p>
<p>or</p>
<p>cd /etc/mail<br />
make stop</p>
<p>or</p>
<p>make -C /etc/mail stop</p>
<p>or</p>
<p>/etc/init.d/sendmail stop</p>
<p>We want to start sendmail with arguments to make it log the SMTP transaction to a special file while we are testing it:</p>
<p>sendmail -bD -X /tmp/test.log</p>
<p>Now, try to send a message from an e-mail client on another computer that does not have relay access, using your server as the outgoing mail server. You should be denied relaying. Edit your preferences so that the client uses authentication, with a login and password (not Secure Password Authentication, or SPA, which is something completely different). You should still be denied access. The last thing you need to do is to instruct the client to use SSL or TLS with the outgoing mail server (there is no need to specify a special port). After making this change, you should be able to send mail (you will be prompted to accept the certificate, however, which you might want to install to prevent further prompts). Now hit ctrl-c to stop sendmail. Restart it normally:</p>
<p>service sendmail restart</p>
<p>Now it&#8217;s time to look at the log. After the first EHLO, sendmail offers something like this:</p>
<p>30245 &gt;&gt;&gt; 250-ENHANCEDSTATUSCODES<br />
30245 &gt;&gt;&gt; 250-PIPELINING<br />
30245 &gt;&gt;&gt; 250-8BITMIME<br />
30245 &gt;&gt;&gt; 250-SIZE<br />
30245 &gt;&gt;&gt; 250-DSN<br />
30245 &gt;&gt;&gt; 250-ETRN<br />
30245 &gt;&gt;&gt; 250-STARTTLS<br />
30245 &gt;&gt;&gt; 250-DELIVERBY<br />
30245 &gt;&gt;&gt; 250 HELP</p>
<p>The important thing is that AUTH is not offered here, because the channel isn&#8217;t encrypted. If you see AUTH in the first exchange, and it offers PLAIN or LOGIN, something is wrong. Look at your logs, go over the previous steps, and make sure that you generated a new sendmail.cf in the right location. The next entries in our log show that TLS is activated:</p>
<p>30245 &lt;&lt;&lt; STARTTLS<br />
30245 &gt;&gt;&gt; 220 2.0.0 Ready to start TLS</p>
<p>Another EHLO takes place, followed by something like this:</p>
<p>30245 &gt;&gt;&gt; 250-ENHANCEDSTATUSCODES<br />
30245 &gt;&gt;&gt; 250-PIPELINING<br />
30245 &gt;&gt;&gt; 250-8BITMIME<br />
30245 &gt;&gt;&gt; 250-SIZE<br />
30245 &gt;&gt;&gt; 250-DSN<br />
30245 &gt;&gt;&gt; 250-ETRN<br />
30245 &gt;&gt;&gt; 250-AUTH LOGIN PLAIN<br />
30245 &gt;&gt;&gt; 250-DELIVERBY<br />
30245 &gt;&gt;&gt; 250 HELP</p>
<p>Now AUTH is offered with the allowed mechanisms (but not STARTTLS, which isn&#8217;t needed here, as the channel is already encrypted). Authentication takes place, and the message is relayed to its destination.</p>
<p>It&#8217;s interesting to note that the username and password is Base64 encoded by the client, so it isn&#8217;t really sent as clear text:</p>
<p>30245 &lt;&lt;&lt; AUTH PLAIN AHJvYmVydABzbHVncw==<br />
30245 &gt;&gt;&gt; 235 2.0.0 OK Authenticated</p>
<p>Nevertheless, it would be trivial to decode the string into the correct username/login pair (robert/slugs, in this case). Therefore, it is best to secure the transaction with TLS. If you want to verify that the transaction is encrypted, open another terminal for root, and run tcpdump:</p>
<p>tcpdump -s 1500 -vvxX port 25</p>
<p>Send a mail with easy to identify strings. You shouldn&#8217;t see your login or the message in tcpdump&#8217;s output.</p>
<p>Note that the certificate will be exchanged in plain text before TLS is enabled. If the mail is relayed to another server that doesn&#8217;t offer STARTTLS, you will see the content of the outgoing message in plain text.</p>
<p><em><strong><a href="http://www.joreybump.com/code/howto/smtpauth.html" target="_blank">Source</a></strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2009/01/07/using-smtp-auth-and-starttls-with-sendmail-redhat-centos-fedora/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE ignores custom error pages</title>
		<link>http://blog.nataprawira.com/tech/2008/12/18/ie-ignores-custom-error-pages/</link>
		<comments>http://blog.nataprawira.com/tech/2008/12/18/ie-ignores-custom-error-pages/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 04:10:45 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=20</guid>
		<description><![CDATA[

if you use php to create custom error  pages (such as header('HTTP/1.1 500 Internal Server Error');) Internet Explorer  ignores you custom page unless it is at least 512 (or sometimes 1024 bytes)
IE ignores custom error pages that are less than 512 (or from what i've  read 1024) bytes.
just place this before any [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2008%2F12%2F18%2Fie-ignores-custom-error-pages%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2008%2F12%2F18%2Fie-ignores-custom-error-pages%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<div class="phpcode"><code><span class="html">if you use php to create custom error  pages (such as header('HTTP/1.1 500 Internal Server Error');) Internet Explorer  ignores you custom page unless it is at least 512 (or sometimes 1024 bytes)</p>
<p>IE ignores custom error pages that are less than 512 (or from what i've  read 1024) bytes.</p>
<p>just place this before any output on your custom error  page--- and be sure that your custom error page includes proper html tags (it  must have a &lt;/body&gt; for this specific example to work)</p>
<p><span class="default">&lt;?php<br />
</span><span class="comment">// set your custom error  header --- example --- header('HTTP/1.1 503 Service Unavailable');</p>
<p></span><span class="keyword">function </span><span class="default">padding</span><span class="keyword">(</span><span class="default">$html</span><span class="keyword">){<br />
return (</span><span class="default">$padding</span><span class="keyword">=</span><span class="default">1024</span><span class="keyword">-</span><span class="default">ob_get_length</span><span class="keyword">()) &gt; </span><span class="default">0 </span><span class="keyword">? </span><span class="default">str_replace</span><span class="keyword">(</span><span class="string">'&lt;/body&gt;'</span><span class="keyword">,</span><span class="string">'&lt;!--'</span><span class="keyword">. (</span><span class="default">$padding</span><span class="keyword">&gt;</span><span class="default">8</span><span class="keyword">?</span><span class="default">str_repeat</span><span class="keyword">(</span><span class="string">'  '</span><span class="keyword">,</span><span class="default">$padding</span><span class="keyword">-</span><span class="default">8</span><span class="keyword">)  :</span><span class="default">null </span><span class="keyword">).</span><span class="string">'--&gt;'</span><span class="keyword">.</span><span class="string">"\n"</span><span class="keyword">.</span><span class="string">'&lt;/body&gt;'</span><span class="keyword">,</span><span class="default">$html</span><span class="keyword">) : </span><span class="default">$html</span><span class="keyword">;<br />
}</p>
<p></span><span class="default">ob_start</span><span class="keyword">(</span><span class="string">'padding'</span><span class="keyword">);<br />
</span><span class="default">?&gt;<br />
</span><br />
and then place this somewhere within the html  error page output</p>
<p>&lt;!-- ---- --&gt;</p>
<p>that will auto-adjust to  pad the file to 1024 bytes to override the default Internet Explorer error  pages.</span> </code></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2008/12/18/ie-ignores-custom-error-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to show image file that&#8217;s not accessible to public ?</title>
		<link>http://blog.nataprawira.com/tech/2008/12/17/how-to-show-image-file-thats-not-accessible-to-public/</link>
		<comments>http://blog.nataprawira.com/tech/2008/12/17/how-to-show-image-file-thats-not-accessible-to-public/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 07:03:40 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=19</guid>
		<description><![CDATA[

You can use below script to show the image file for public access, but public don&#8217;t have direct access to the file itself. Because its located outside of the public folder.
&#60;?php
/* Read local file from /home/bar */
$localfile = file_get_contents("/home/userX/foo.jpg");
echo $localfile;
?&#62;
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2008%2F12%2F17%2Fhow-to-show-image-file-thats-not-accessible-to-public%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2008%2F12%2F17%2Fhow-to-show-image-file-thats-not-accessible-to-public%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>You can use below script to show the image file for public access, but public don&#8217;t have direct access to the file itself. Because its located outside of the public folder.</p>
<p><code><span style="color: #000000"><span style="color: #0000bb">&lt;?php<br />
</span><span style="color: #ff8000">/* Read local file from /home/bar */<br />
</span><span style="color: #0000bb">$localfile </span><span style="color: #007700">= </span><span style="color: #0000bb"><span style="color: #ffffff">file_get_contents</span></span><span style="color: #007700">(</span><span style="color: #dd0000">"/home/userX/foo.jpg"</span><span style="color: #007700">);</span></span></code></p>
<p><code><span style="color: #000000"><span style="color: #0000bb">echo $localfile;</span></span></code><br />
<span style="color: #0000bb">?&gt;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2008/12/17/how-to-show-image-file-thats-not-accessible-to-public/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to know ID number that inserted by the mysql insert query ?</title>
		<link>http://blog.nataprawira.com/tech/2008/12/17/mysql_insert_id-example/</link>
		<comments>http://blog.nataprawira.com/tech/2008/12/17/mysql_insert_id-example/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 06:52:44 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=18</guid>
		<description><![CDATA[

Use below scripts :
mysql_insert_id() example
&#60;?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');
mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n", mysql_insert_id());
?&#62; 
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2008%2F12%2F17%2Fmysql_insert_id-example%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2008%2F12%2F17%2Fmysql_insert_id-example%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<p>Use below scripts :</p>
<p><strong><strong>mysql_insert_id()</strong> example</strong></p>
<div class="example-contents"><code><span style="color: #000000"><span style="color: #0000bb">&lt;?php<br />
$link </span><span style="color: #007700">= </span><span style="color: #0000bb">mysql_connect</span><span style="color: #007700">(</span><span style="color: #dd0000">'localhost'</span><span style="color: #007700">, </span><span style="color: #dd0000">'mysql_user'</span><span style="color: #007700">, </span><span style="color: #dd0000">'mysql_password'</span><span style="color: #007700">);<br />
if (!</span><span style="color: #0000bb">$link</span><span style="color: #007700">) {<br />
die(</span><span style="color: #dd0000">'Could not connect: ' </span><span style="color: #007700">. </span><span style="color: #0000bb">mysql_error</span><span style="color: #007700">());<br />
}<br />
</span><span style="color: #0000bb">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #dd0000">'mydb'</span><span style="color: #007700">);</p>
<p></span><span style="color: #0000bb">mysql_query</span><span style="color: #007700">(</span><span style="color: #dd0000">"INSERT INTO mytable (product) values ('kossu')"</span><span style="color: #007700">);<br />
</span><span style="color: #0000bb">printf</span><span style="color: #007700">(</span><span style="color: #dd0000">"Last inserted record has id %d\n"</span><span style="color: #007700">, </span><span style="color: #0000bb">mysql_insert_id</span><span style="color: #007700">());<br />
</span><span style="color: #0000bb">?&gt;</span> </span></code></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2008/12/17/mysql_insert_id-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to fetch data(s) using mysql_fetch_assoc ?</title>
		<link>http://blog.nataprawira.com/tech/2008/12/17/an-expanded-mysql_fetch_assoc-example/</link>
		<comments>http://blog.nataprawira.com/tech/2008/12/17/an-expanded-mysql_fetch_assoc-example/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 06:50:46 +0000</pubDate>
		<dc:creator>Denie</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.nataprawira.com/tech/?p=17</guid>
		<description><![CDATA[


mysql_fetch_assoc — Fetch a result row as an associative array


&#60;?php
$conn
= mysql_connect("localhost", "mysql_user", "mysql_password");
if (!
$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!
mysql_select_db("mydbname")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
$sql = "SELECT id as userid, fullname, userstatus
FROM   sometable
WHERE  userstatus = 1";
$result = mysql_query($sql);
if (!
$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (
mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
//       then create $userid, $fullname, and $userstatus

while ($row = mysql_fetch_assoc($result)) {
echo $row["userid"];
echo $row["fullname"];
echo $row["userstatus"];
}
mysql_free_result($result);
?&#62; 
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2008%2F12%2F17%2Fan-expanded-mysql_fetch_assoc-example%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.nataprawira.com%2Ftech%2F2008%2F12%2F17%2Fan-expanded-mysql_fetch_assoc-example%2F" height="61" width="51" /></a></div>
<!-- ALL ADSENSE ADS DISABLED -->
<div class="example-contents">
<p><strong>mysql_fetch_assoc</strong> — Fetch a result row as an associative array</p>
</div>
<div class="example-contents"></div>
<div class="example-contents"><code><span style="color: #000000"><span style="color: #0000bb">&lt;?php</p>
<p>$conn</p>
<p></span><span style="color: #007700">= </span><span style="color: #0000bb">mysql_connect</span><span style="color: #007700">(</span><span style="color: #dd0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #dd0000">"mysql_user"</span><span style="color: #007700">, </span><span style="color: #dd0000">"mysql_password"</span><span style="color: #007700">);</p>
<p>if (!</p>
<p></span><span style="color: #0000bb">$conn</span><span style="color: #007700">) {<br />
echo </span><span style="color: #dd0000">"Unable to connect to DB: " </span><span style="color: #007700">. </span><span style="color: #0000bb">mysql_error</span><span style="color: #007700">();<br />
exit;<br />
}</p>
<p>if (!</p>
<p></span><span style="color: #0000bb">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #dd0000">"mydbname"</span><span style="color: #007700">)) {<br />
echo </span><span style="color: #dd0000">"Unable to select mydbname: " </span><span style="color: #007700">. </span><span style="color: #0000bb">mysql_error</span><span style="color: #007700">();<br />
exit;<br />
}</p>
<p></span><span style="color: #0000bb">$sql </span><span style="color: #007700">= </span><span style="color: #dd0000">"SELECT id as userid, fullname, userstatus<br />
FROM   sometable<br />
WHERE  userstatus = 1"</span><span style="color: #007700">;</p>
<p></span><span style="color: #0000bb">$result </span><span style="color: #007700">= </span><span style="color: #0000bb">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000bb">$sql</span><span style="color: #007700">);</p>
<p>if (!</p>
<p></span><span style="color: #0000bb">$result</span><span style="color: #007700">) {<br />
echo </span><span style="color: #dd0000">"Could not successfully run query ($sql) from DB: " </span><span style="color: #007700">. </span><span style="color: #0000bb">mysql_error</span><span style="color: #007700">();<br />
exit;<br />
}</p>
<p>if (</p>
<p></span><span style="color: #0000bb">mysql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000bb">$result</span><span style="color: #007700">) == </span><span style="color: #0000bb">0</span><span style="color: #007700">) {<br />
echo </span><span style="color: #dd0000">"No rows found, nothing to print so am exiting"</span><span style="color: #007700">;<br />
exit;<br />
}</p>
<p></span><span style="color: #ff8000">// While a row of data exists, put that row in $row as an associative array<br />
// Note: If you're expecting just one row, no need to use a loop<br />
// Note: If you put extract($row); inside the following loop, you'll<br />
//       then create $userid, $fullname, and $userstatus</span></span></code></div>
<div class="example-contents"><code><span style="color: #000000"><span style="color: #ff8000"><br />
</span><span style="color: #007700">while (</span><span style="color: #0000bb">$row </span><span style="color: #007700">= </span><span style="color: #0000bb">mysql_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000bb">$result</span><span style="color: #007700">)) {<br />
echo </span><span style="color: #0000bb">$row</span><span style="color: #007700">[</span><span style="color: #dd0000">"userid"</span><span style="color: #007700">];<br />
echo </span><span style="color: #0000bb">$row</span><span style="color: #007700">[</span><span style="color: #dd0000">"fullname"</span><span style="color: #007700">];<br />
echo </span><span style="color: #0000bb">$row</span><span style="color: #007700">[</span><span style="color: #dd0000">"userstatus"</span><span style="color: #007700">];<br />
}</p>
<p></span><span style="color: #0000bb">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000bb">$result</span><span style="color: #007700">);</p>
<p></span><span style="color: #0000bb">?&gt;</span> </span></code></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nataprawira.com/tech/2008/12/17/an-expanded-mysql_fetch_assoc-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

