<?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>Never Use This Font &#187; Server Software</title>
	<atom:link href="http://neverusethisfont.com/blog/topics/server-software/feed/" rel="self" type="application/rss+xml" />
	<link>http://neverusethisfont.com/blog</link>
	<description>Aaron Parecki is the co-founder of Geoloqi.com, and specializes in backend systems development.</description>
	<lastBuildDate>Mon, 11 Jul 2011 22:50:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Enabling SSH on the Seagate BlackArmor NAS 220</title>
		<link>http://neverusethisfont.com/blog/2011/07/enabling-ssh-on-the-seagate-blackarmor-nas-220/</link>
		<comments>http://neverusethisfont.com/blog/2011/07/enabling-ssh-on-the-seagate-blackarmor-nas-220/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 01:54:47 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Software]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=514</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>I recently acquired a <a href="http://aaron.pk/asin/B0046TSGNE">6 TB Seagate NAS drive</a> which I am using for nightly backups of my servers, as well as <a href="http://neverusethisfont.com/blog/2010/07/how-to-back-up-dropbox-automatically-daily-weekly-monthly-snapshots/">snapshots of several Dropbox accounts</a>.</p>
<p>While the web interface on the device isn&#8217;t too bad, I wanted a little more control over it, as well as the ability to monitor the device&#8217;s health with some custom <a href="https://github.com/aaronpk/Munin-Plugins">munin graphs</a>.</p>
<p>Here&#8217;s how to enable SSH without wiping the drive and installing custom firmware.</p>
<ol>
<li>Set up a new user account on the device from the web interface, and create a password.</li>
<li>Shut down the device, remove both drives, and connect them to a local computer with SATA cables.</li>
<li>Boot your linux computer with the drives attached, it&#8217;s probably safest to boot from some sort of Live CD. I used Fedora.</li>
<li>When you get to a shell, execute the following commands to mount the drives.<br />
<code>$ mdadm -A /dev/md0 /dev/sda1 /dev/sdb1<br />
mdadm: /dev/md0 has been started with 2 drives.<br />
$ mkdir /mnt/md0<br />
$ mount /dev/md0 /mnt/md0<br />
</code></li>
<li>Add the following line to the file <code>/mnt/md0/etc/inetd.conf</code>:<br />
<code>ssh stream tcp nowait root /usr/sbin/dropbear dropbear -i</code><br />
You can do this in one shell command by executing this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;ssh stream tcp nowait root /usr/sbin/dropbear dropbear -i&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>md0<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>inetd.conf</pre></div></div>

</li>
<li>Edit <code>/mnt/md0/etc/shadow</code> with a text editor, and replace the hashed password for &#8220;root&#8221; with the hashed password of the user you created. The hashed password is the characters between the second two colons, and begins with <code>$1$$</code>.</li>
<li>Unmount the drives and shut down the array:<code><br />
$ cd<br />
$ umount /mnt/md0<br />
$ mdadm -S /dev/md0<br />
mdadm: stopped /dev/md0</code></li>
<li>Put the drives back in the NAS device and turn it back on!</li>
<li>After it boots, you&#8217;ll be able to ssh in as <code>root</code> with the password you set from the web interface.</li>
</ol>
<p><img src="http://neverusethisfont.com/blog/wp-content/uploads/2011/07/2011-07-10_1850.png" alt="" title="SSH" width="414" height="152" class="aligncenter size-full wp-image-523" /></p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2011/07/enabling-ssh-on-the-seagate-blackarmor-nas-220/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why do I use Tropo over Twilio?</title>
		<link>http://neverusethisfont.com/blog/2010/12/why-do-i-use-tropo-over-twilio/</link>
		<comments>http://neverusethisfont.com/blog/2010/12/why-do-i-use-tropo-over-twilio/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 19:14:58 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Server Software]]></category>
		<category><![CDATA[phono]]></category>
		<category><![CDATA[sip]]></category>
		<category><![CDATA[sms]]></category>
		<category><![CDATA[tropo]]></category>
		<category><![CDATA[twilio]]></category>
		<category><![CDATA[voice]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=291</guid>
		<description><![CDATA[Many people keep asking me why I use Tropo instead of Twilio. It seems that Twilio does a great job of getting the word out about their service, so many people end up using them first. But there are a few reasons I&#8217;m using Tropo instead. Basically it comes down to features, scalability and support. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tropo.com"><img src="/blog/wp-content/uploads/2010/12/Tropo-Vert1.png" alt="Tropo Logo" title="Tropo-Vert" width="180" height="150" class="alignright size-full wp-image-301 no-border" /></a>Many people keep asking me why I use <a href="http://blog.tropo.com">Tropo</a> instead of Twilio. It seems that Twilio does a great job of getting the word out about their service, so many people end up using them first. But there are a few reasons I&#8217;m using Tropo instead. Basically it comes down to features, scalability and support.</p>
<h3>AIM, Yahoo IM, MSN, Jabber and Twitter!</h3>
<p>In addition to sending SMSs and calling phone numbers, Tropo can send messages over <a href="https://www.tropo.com/docs/webapi/say.htm">other text channels</a> such as AIM, Google Chat, MSN, Yahoo IM, Jabber and Twitter, and can also call Skype and SIP numbers. </p>
<h3>In-Browser Phone</h3>
<p>Tropo recently released <a href="http://phono.com">Phono</a>, a browser-based SIP client, so you can now do things like have a click-to-call button on your website which will use the computer&#8217;s mic and speakers to make the call!</p>
<h3>Browser-Based Chat Client</h3>
<p>Phono also turns a browser into a Jabber client. Your browser gets an address you can use to send messages to via the Jabber protocol. This means you can quickly make a <a href="http://s.phono.com/releases/0.1/samples/kitchen-sink/index.htm">chat interface</a> without having to build the server-side code dealing with sockets.</p>
<h3>Custom Caller ID</h3>
<p>Tropo lets you <a href="https://www.tropo.com/docs/webapi/call.htm">set the caller ID</a> of outgoing calls to any arbitrary phone number, which can be used to more tightly integrate with existing phone systems. For example, I&#8217;m using caller ID tricks for a client to route calls directly to extensions in their office phone system.</p>
<h3>Voice Recognition</h3>
<p><a href="https://www.tropo.com/docs/webapi/ask.htm"><img src="/blog/wp-content/uploads/2010/12/2010-12-16_1023.png" alt="" title="2010-12-16_1023" width="261" height="53" class="alignleft size-full wp-image-299" /></a> Tropo can do great <a href="https://www.tropo.com/docs/webapi/ask.htm">voice recognition</a> to let callers speak instead of enter digits. For example, you can prompt a caller to say &#8220;sales&#8221; or &#8220;support&#8221; instead of just entering 1 or 2 on the keypad.  This is especially great for when you need to ask the caller to choose from a large number of options such as states, or cities within a state. </p>
<h3>Free for Development</h3>
<p>Tropo doesn&#8217;t charge anything for development applications until you put them onto the production network. This is really great for experimenting with a new idea without running down your development &#8220;credits.&#8221; </p>
<h3>Scalability</h3>
<p>Twilio runs on Amazon EC2. Tropo runs in the private <a href="http://voxeo.com">Voxeo</a> network. &#8220;Co-tenancy is hard.&#8221; says John from Netflix in a blog post titled <a href="http://techblog.netflix.com/2010/12/5-lessons-weve-learned-using-aws.html">5 Lessons We’ve Learned Using AWS</a>. Personally, voice data and SMSs are not something I want running in a shared environment where resources may be allocated away from a call while I&#8217;m on the phone.</p>
<p>Additionally, if you are building an application that needs to be secure, such as for a bank or a government agency, they probably won&#8217;t allow the application to run on the Amazon cloud for security reasons. With Tropo, you can license Prophecy and run your own Tropo platform in a secure location.</p>
<h3>Support</h3>
<p>I&#8217;ve had nothing but great experiences with Tropo support. They are very responsive to tickets submitted, I usually get a response back in less than an hour.</p>
<p>There are also several Tropo staff available on their <a href="https://www.tropo.com/chat/">IRC channel</a> (#tropo on freenode.net) at pretty much any time of the day. There are also several community members that hang out on the channel and can help with questions and issues.</p>
<h3>More Information</h3>
<p>Here are some links about projects built using Tropo.</p>
<ul>
<li><a href="/blog/2010/12/random-hacks-of-kindness/">Mobile Assessment of Damage Hotline</a> built during the Random Hacks of Kindness hackathon in December 2010.</a></li>
<li><a href="http://oakhazelnut.com/2010/11/20/loqi-me-wins-best-in-show-at-civicapps-for-greater-portland-competition/">Loqi.me Wins Most Useful App and Best in Show at CivicApps Award Ceremony</a></li>
<li><a href="http://geoloqi.com/blog/2010/10/apps-built-at-the-tropo-geoloqi-open-gov-hackathon/">Apps built at the Geoloqi+Tropo hackathon</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2010/12/why-do-i-use-tropo-over-twilio/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Tracking typos of your domain name in Google Analytics</title>
		<link>http://neverusethisfont.com/blog/2010/12/tracking-typos-of-your-domain-name-in-google-analytics/</link>
		<comments>http://neverusethisfont.com/blog/2010/12/tracking-typos-of-your-domain-name-in-google-analytics/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 17:41:53 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Software]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[redirection]]></category>
		<category><![CDATA[tracking]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=279</guid>
		<description><![CDATA[Say you want to register a couple different typos of your domain name, and redirect everyone seamlessly to the correct site. This can be done quite easily in Apache using ServerAlias and a simple RewriteRule. I just registered geoloqui.com after noticing a couple articles linking to it instead of geoloqi.com. But then I thought, wouldn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Say you want to register a couple different typos of your domain name, and redirect everyone seamlessly to the correct site. This can be done quite easily in Apache using ServerAlias and a simple RewriteRule. I just registered geoloqui.com after noticing a couple articles linking to it instead of geoloqi.com. But then I thought, wouldn&#8217;t it be useful if I could track these typos and see which ones are most common? Turns out it&#8217;s not difficult! </p>
<p>Here is a snippet of my virtual hosts definition for geoloqi.com:</p>
<pre>
&lt;VirtualHost *:80&gt;
	ServerName geoloqi.com
	ServerAlias *.geoloqi.com
	ServerAlias geoloqui.com
	ServerAlias *.geoloqui.com

	RewriteEngine on
	RewriteCond %{HTTP_HOST} !^geoloqi.com
	RewriteRule ^/(.*)$ http://geoloqi.com/$1?utm_source=DomainRedirect&#038;utm_medium=%{HTTP_HOST} [R=permanent,L]
...
</pre>
<p>This will make domain typos visible in Google Analytics under the &#8220;All Traffic Sources&#8221; section. You can clearly see the referrals from the typo&#8217;d domain name at the bottom of this list.</p>
<p><img src="http://neverusethisfont.com/blog/wp-content/uploads/2010/12/referrers_-_fake.png" alt="" title="geoloqi.com traffic sources" width="522" height="348" class="aligncenter size-full wp-image-282" /></p>
<p>You could also use the filter box to search for &#8220;DomainRedirect&#8221; and see only the typos. </p>
<p>I&#8217;d be curious to know if anybody else has other suggestions for tracking this type of thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2010/12/tracking-typos-of-your-domain-name-in-google-analytics/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Linux Software RAID and LVM</title>
		<link>http://neverusethisfont.com/blog/2009/08/linux-software-raid-and-lvm/</link>
		<comments>http://neverusethisfont.com/blog/2009/08/linux-software-raid-and-lvm/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 17:48:48 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Software]]></category>
		<category><![CDATA[ext3]]></category>
		<category><![CDATA[LVM]]></category>
		<category><![CDATA[mdadm]]></category>
		<category><![CDATA[RAID 5]]></category>
		<category><![CDATA[Terabyte]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=97</guid>
		<description><![CDATA[I wanted to create a RAID 5 array with four 1tb drives. I only have three, but I have a 750gb and 320gb drive lying around. I figured there was probably a way to combine them into a 1tb drive that I could use with the others. Using Linux&#8217;s LVM, I can create a logical [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to create a RAID 5 array with four 1tb drives. I only have three, but I have a 750gb and 320gb drive lying around. I figured there was probably a way to combine them into a 1tb drive that I could use with the others.</p>
<p>Using Linux&#8217;s LVM, I can create a logical partition from the two smaller drives as big as the 1tb drive.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ pvdisplay</pre></div></div>

<p>Lists all physical volumes managed by LVM. First we have to create the physical volumes for LVM. I prefer to create the volumes out of partitions, although you can do it from raw drives too.</p>
<p>First let&#8217;s use fdisk to create &#8220;Linux LVM&#8221; partitions on the two drives.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ fdisk <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb
Press <span style="color: #ff0000;">&quot;n&quot;</span> to create a new partition
Press <span style="color: #ff0000;">&quot;t&quot;</span> to <span style="color: #000000; font-weight: bold;">set</span> the partition <span style="color: #7a0874; font-weight: bold;">type</span>, and enter <span style="color: #ff0000;">&quot;8e&quot;</span> <span style="color: #000000; font-weight: bold;">for</span> Linux LVM.</pre></div></div>

<p>When creating the partition, accepting the defaults will make it use the whole drive. I want to use the entire 750 drive and only part of the 320 drive, so that in total it has the same number of blocks as the 1tb drives. So I first created the &#8220;Linux RAID&#8221; partitions on the 1tb drives so I could see how many cylinders it listed, which ended up being <b>121601</b>. So I created a partition the full size of the 750 drive (91201 cylinders), then created a 121601-91201 cylinder partition on the 320 drive.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ fdisk <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb
Disk <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb: <span style="color: #000000;">320.0</span> GB, <span style="color: #000000;">320072933376</span> bytes
<span style="color: #000000;">255</span> heads, <span style="color: #000000;">63</span> sectors<span style="color: #000000; font-weight: bold;">/</span>track, <span style="color: #000000;">38913</span> cylinders
   Device Boot      Start         End      Blocks   Id  System
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1               <span style="color: #000000;">1</span>       <span style="color: #000000;">30400</span>   <span style="color: #000000;">244187968</span>+  8e  Linux LVM
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb2           <span style="color: #000000;">30401</span>       <span style="color: #000000;">38913</span>    <span style="color: #000000;">68380672</span>+  <span style="color: #000000;">83</span>  Linux
&nbsp;
$ fdisk <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdj
Disk <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdj: <span style="color: #000000;">750.1</span> GB, <span style="color: #000000;">750156374016</span> bytes
<span style="color: #000000;">255</span> heads, <span style="color: #000000;">63</span> sectors<span style="color: #000000; font-weight: bold;">/</span>track, <span style="color: #000000;">91201</span> cylinders
   Device Boot      Start         End      Blocks   Id  System
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdj1               <span style="color: #000000;">1</span>       <span style="color: #000000;">91201</span>   <span style="color: #000000;">732572001</span>   8e  Linux LVM</pre></div></div>

<p>Now that I have the two partitions ready, I moved on to LVM setup.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ pvcreate <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1
$ pvcreate <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdj1</pre></div></div>

<p>This sets up the two partitions as physical volumes for LVM.</p>
<p>Next is creating a logical volume group:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ vgcreate vg_tb <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdj1</pre></div></div>

<p>This creates a volume group called &#8220;vg_tb&#8221; using the two physical volumes sdb1 and sdj1.</p>
<p>Let&#8217;s take a look at what we have so far:</p>
<pre>
$ pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               vg_tb
  PV Size               232.88 GB / not usable 832.50 KB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              59616
  Free PE               59616
  Allocated PE          0
  PV UUID               70hPKX-n11U-RcB6-0Kyt-1SOP-ni7E-2Y9hcE

  --- Physical volume ---
  PV Name               /dev/sdj1
  VG Name               vg_tb
  PV Size               698.64 GB / not usable 2.34 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              178850
  Free PE               178850
  Allocated PE          0
  PV UUID               PzFb9b-lapG-KdT3-78nh-Gq75-F0Lo-I3xCrl

  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup00
  PV Size               111.60 GB / not usable 2.86 MB
  Allocatable           yes
  PE Size (KByte)       32768
  Total PE              3571
  Free PE               1
  Allocated PE          3570
  PV UUID               1wM65Z-3QGd-vDiq-mq1R-YhEE-Ackp-hh3g13

$ vgdisplay
  --- Volume group ---
  VG Name               vg_tb
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               931.51 GB
  PE Size               4.00 MB
  Total PE              238466
  Alloc PE / Size       0 / 0
  Free  PE / Size       238466 / 931.51 GB
  VG UUID               olg9GP-x1sC-sFAD-TgWY-KIIx-YWNt-kL763n

  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               111.59 GB
  PE Size               32.00 MB
  Total PE              3571
  Alloc PE / Size       3570 / 111.56 GB
  Free  PE / Size       1 / 32.00 MB
  VG UUID               IZ25LV-oMOG-DwKK-QuFN-bqqp-ClUe-d71k5l
</pre>
<p>So far so good. The next step is to create a logical volume in the new volume group:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ lvcreate vg_tb <span style="color: #660033;">-n</span> onetb <span style="color: #660033;">-l</span> <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span>VG
  Logical volume <span style="color: #ff0000;">&quot;onetb&quot;</span> created</pre></div></div>

<p>This creates a new logical volume called &#8220;onetb&#8221; in the &#8220;vg_tb&#8221; group using 100% of the group&#8217;s available space. Now let&#8217;s take a look at the list of logical volumes:</p>
<pre>
$ lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg_tb/onetb
  VG Name                vg_tb
  LV UUID                sQKaq9-D6Mv-p8it-vWGW-O7DX-FGmC-cl5FSh
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                931.51 GB
  Current LE             238466
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                G5hlbb-tA3S-qhTS-03us-f9dl-1Vxy-9vDSU5
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                109.62 GB
  Current LE             3508
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                7NZrY9-1wSJ-4fRp-VPnM-V07u-9rj8-vmtxTx
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.94 GB
  Current LE             62
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
</pre>
<p>You can ignore all of the VolGroup00 things, those are the auto-created volumes from when I installed Fedora. </p>
<p>At this point, I have a new device at /dev/vg_tb/onetb which is the same size as my 1tb drives, and I can use it exactly as I would use the 1tb partition at /dev/sdf1.</p>
<p>Now it&#8217;s time to create the RAID 5 array from these four volumes.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ mdadm <span style="color: #660033;">-v</span> <span style="color: #660033;">--create</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md1 <span style="color: #660033;">--chunk</span>=<span style="color: #000000;">128</span> <span style="color: #660033;">--level</span>=<span style="color: #000000;">5</span> <span style="color: #660033;">--raid-devices</span>=<span style="color: #000000;">4</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdf1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdh1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdi1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>vg_tb<span style="color: #000000; font-weight: bold;">/</span>onetb
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: <span style="color: #c20cb9; font-weight: bold;">size</span> <span style="color: #000000; font-weight: bold;">set</span> to 976756608K
mdadm: array <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md1 started.</pre></div></div>

<p>The array will begin syncing, and you can watch it by running:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">watch</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">1</span> <span style="color: #ff0000;">&quot;cat /proc/mdstat&quot;</span>
Personalities : <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid6<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid5<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid4<span style="color: #7a0874; font-weight: bold;">&#93;</span>
md1 : active raid5 dm-<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdi1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdh1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdf1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
      <span style="color: #000000;">2930269824</span> blocks level <span style="color: #000000;">5</span>, 128k chunk, algorithm <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>UUU_<span style="color: #7a0874; font-weight: bold;">&#93;</span>
      <span style="color: #7a0874; font-weight: bold;">&#91;</span>=<span style="color: #000000; font-weight: bold;">&gt;</span>...................<span style="color: #7a0874; font-weight: bold;">&#93;</span>  recovery =  <span style="color: #000000;">5.5</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">54017536</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">976756608</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">finish</span>=593.1min <span style="color: #007800;">speed</span>=25925K<span style="color: #000000; font-weight: bold;">/</span>sec
&nbsp;
md0 : active raid5 sdg1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdc1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sde1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdd1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
      <span style="color: #000000;">2197715712</span> blocks level <span style="color: #000000;">5</span>, 64k chunk, algorithm <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>UUUU<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
unused devices: <span style="color: #000000; font-weight: bold;">&lt;</span>none<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>While this is syncing, we can create the ext3 filesystem.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ mke2fs <span style="color: #660033;">-j</span> <span style="color: #660033;">-b</span> <span style="color: #000000;">4096</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-E</span> <span style="color: #007800;">stride</span>=<span style="color: #000000;">32</span>,stripe-width=<span style="color: #000000;">96</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md1</pre></div></div>

<p>This creates an ext2 filesystem with journaling (ext3), the block size is 4kb, and 0% of the blocks are reserved for the superuser. The stride is calculated as the raid block size / ext2 block size (128k / 4k = 32). The stripe width is calculated as the stride value times the number of data disks in the array. In a 4-disk RAID 5 array, there are three data disks, one being for the parity data. </p>
<p>This will take some time, and will significantly slow down the sync process. Mine dropped from 25mb/s to around 1mb/s. I figure I&#8217;ll let it create the filesystem so I can start copying data to it right away, and let it finish its sync on its own time.</p>
<p>While you&#8217;re at it, you should set up <a href="http://munin.projects.linpro.no/">munin</a> to monitor the SMART data from all the drives as well as the status of the array using my <a href="http://aaronparecki.com/GitHub">munin-raid-monitor</a> plugin.</p>
<p>Additional Reading:</p>
<div style="font-size:10px">
<ul>
<li><a href="http://linux-raid.osdl.org/index.php/RAID_setup">http://linux-raid.osdl.org/index.php/RAID_setup</a></li>
<li><a href="http://bfish.xaedalus.net/2006/11/software-raid-5-in-ubuntu-with-mdadm/">http://bfish.xaedalus.net/2006/11/software-raid-5-in-ubuntu-with-mdadm/</a></li>
<li><a href="http://www.linuxquestions.org/questions/linux-hardware-18/how-can-i-override-the-5.00-reserved-for-the-super-user-mkfs.ext3-creates-616546/">http://www.linuxquestions.org/questions/linux-hardware-18/how-can-i-override-the-5.00-reserved-for-the-super-user-mkfs.ext3-creates-616546/</a></li>
<li><a href="http://www.linuxconfig.org/Linux_lvm_-_Logical_Volume_Manager">http://www.linuxconfig.org/Linux_lvm_-_Logical_Volume_Manager</a></li>
<li><a href="http://www.centos.org/docs/5/html/Cluster_Logical_Volume_Manager/LV_create.html">http://www.centos.org/docs/5/html/Cluster_Logical_Volume_Manager/LV_create.html</a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2009/08/linux-software-raid-and-lvm/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>IMAP Authentication for WordPress 2.7.1</title>
		<link>http://neverusethisfont.com/blog/2009/02/imap-authentication-for-wordpress-271/</link>
		<comments>http://neverusethisfont.com/blog/2009/02/imap-authentication-for-wordpress-271/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 18:36:59 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Server Software]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=69</guid>
		<description><![CDATA[Due to some significant changes to the WordPress authentication mechanism, my original IMAP Authentication plugin stopped working in version 2.7.1. I have updated the plugin to work in 2.7.1. The only difference is that users are no longer automatically created in WordPress if they have a valid IMAP account. I will try to add that [...]]]></description>
			<content:encoded><![CDATA[<p>Due to some significant changes to the WordPress authentication mechanism, my original <a href="/blog/2008/08/imap-authentication-for-wordpress/">IMAP Authentication plugin</a> stopped working in version 2.7.1. I have updated the plugin to work in 2.7.1. The only difference is that users are no longer automatically created in WordPress if they have a valid IMAP account. I will try to add that back in soon, but for now this will do. </p>
<p>Download <a href="http://aaronpk.net/wp-imap-authentication/imap-authentication1.2.php">imap-authentication1.2.php</a></p>
<p><span id="more-69"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Plugin Name: IMAP Authentication 2
Version: 1.2
Plugin URI: http://blog.neverusethisfont.com/2009/02/imap-authentication-for-wordpress-271/
Description: Authenticate users using IMAP authentication. For Wordpress 2.7.1
Author: Aaron Parecki
Author URI: http://www.aaronparecki.com
&nbsp;
&nbsp;
Copyright 2009 by Aaron Parecki  (email : aaron@parecki.com)
&nbsp;
	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
&nbsp;
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
&nbsp;
	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_menu'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'admin_menu'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lost_password'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'disable_password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'retrieve_password'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'disable_password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password_reset'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'disable_password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'show_password_fields'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'show_password_fields'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_authenticate_user'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'authenticate_user'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'check_password'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'check_password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> is_plugin_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$mailbox</span> <span style="color: #339933;">=</span> IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">get_mailbox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user_suffix</span> <span style="color: #339933;">=</span> IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">get_user_suffix</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div class=&quot;wrap&quot;&gt;
  &lt;h2&gt;IMAP Authentication Options&lt;/h2&gt;
  &lt;form name=&quot;imapauthenticationoptions&quot; method=&quot;post&quot; action=&quot;options.php&quot;&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_nonce_field<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'update-options'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;update&quot; /&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;page_options&quot; value=&quot;imap_authentication_mailbox,imap_authentication_user_suffix&quot; /&gt;
    &lt;fieldset class=&quot;options&quot;&gt;
      &lt;table width=&quot;100%&quot; cellspacing=&quot;2&quot; cellpadding=&quot;5&quot; class=&quot;form-table&quot;&gt;
        &lt;tr valign=&quot;top&quot;&gt;
        &lt;th width=&quot;33%&quot; scope=&quot;row&quot;&gt;&lt;label for=&quot;imap_authentication_mailbox&quot;&gt;Mailbox&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;&lt;input name=&quot;imap_authentication_mailbox&quot; type=&quot;text&quot; id=&quot;imap_authentication_mailbox&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mailbox</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; size=&quot;80&quot; /&gt;&lt;br /&gt;eg: {mail.example.com/readonly}INBOX or {mail.example.com:993/ssl/novalidate-cert/readonly}INBOX&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr valign=&quot;top&quot;&gt;
        &lt;th scope=&quot;row&quot;&gt;&lt;label for=&quot;imap_authentication_user_suffix&quot;&gt;User Suffix&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;&lt;input name=&quot;imap_authentication_user_suffix&quot; type=&quot;text&quot; id=&quot;imap_authentication_user_suffix&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_suffix</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; size=&quot;50&quot; /&gt;&lt;br /&gt;A suffix to add to usernames (typically used to automatically add the domain part of the login).&lt;br /&gt;eg: @example.com&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/fieldset&gt;
    &lt;p class=&quot;submit&quot;&gt;
      &lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Save Changes'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
    &lt;/p&gt;
  &lt;/form&gt;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">class</span> IMAPAuthentication <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">/*
         * Add an options pane for this plugin.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> admin_menu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            add_options_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAP Authentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'IMAP Authentication'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
         * Return the mailbox option from the database, creating the option if it doesn't exist.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> get_mailbox<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$cache_nonexistantoptions</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$mailbox</span> <span style="color: #339933;">=</span> get_settings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'imap_authentication_mailbox'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #000088;">$mailbox</span> or <span style="color: #000088;">$cache_nonexistantoptions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'imap_authentication_mailbox'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$mailbox</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'{localhost:143}INBOX'</span><span style="color: #339933;">;</span>
                IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">add_mailbox_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mailbox</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$mailbox</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
         * Add the mailbox option to the database.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> add_mailbox_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mailbox</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            add_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'imap_authentication_mailbox'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mailbox</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The mailbox to try and log into.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
         * Return the user_suffix option from the database, creating the option if it doesn't exist.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> get_user_suffix<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$cache_nonexistantoptions</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$user_suffix</span> <span style="color: #339933;">=</span> get_settings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'imap_authentication_user_suffix'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #000088;">$user_suffix</span> or <span style="color: #000088;">$cache_nonexistantoptions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'imap_authentication_user_suffix'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$user_suffix</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
                IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">add_user_suffix_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_suffix</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$user_suffix</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
         * Add the user_suffix option to the database.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> add_user_suffix_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_suffix</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            add_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'imap_authentication_user_suffix'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user_suffix</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'A suffix to add to usernames (typically used to automatically add the domain part of the login).'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// custom error handler</span>
        <span style="color: #000000; font-weight: bold;">function</span> eh<span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$msg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line</span><span style="color: #339933;">,</span> <span style="color: #000088;">$context</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$error</span><span style="color: #339933;">.</span><span style="color: #000088;">$msg</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> authenticate_user<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// Apparently this method is no longer called for users who are not in the WP database</span>
&nbsp;
			<span style="color: #000088;">$mbox</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imap_open</span><span style="color: #009900;">&#40;</span>IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">get_mailbox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_login</span><span style="color: #339933;">.</span>IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">get_user_suffix</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> OP_HALFOPEN<span style="color: #339933;">|</span>OP_READONLY<span style="color: #009900;">&#41;</span> or <span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imap_last_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mbox</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$userInfo</span> <span style="color: #339933;">=</span> get_userdatabylogin<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_login</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #990000;">imap_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mbox</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> WP_User<span style="color: #009900;">&#40;</span><span style="color: #000088;">$userInfo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				do_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'wp_login_failed'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_login</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> WP_Error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'incorrect_password'</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;strong&gt;ERROR&lt;/strong&gt;: Incorrect password. '</span><span style="color: #339933;">.</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">function</span> check_password<span style="color: #009900;">&#40;</span><span style="color: #000088;">$unknown</span><span style="color: #339933;">,</span> <span style="color: #000088;">$enteredPassword</span><span style="color: #339933;">,</span> <span style="color: #000088;">$storedPassword</span><span style="color: #339933;">,</span> <span style="color: #000088;">$userID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WP_User<span style="color: #009900;">&#40;</span><span style="color: #000088;">$userID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span> IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">authenticate_user</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$enteredPassword</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
         * Used to disable certain login functions, e.g. retrieving a
         * user's password.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> disable_password<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            login_header<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Login'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;p class=&quot;message&quot;&gt;&lt;strong&gt;ERROR&lt;/strong&gt;: You can\'t do that here. This blog uses the IMAP login mechanism. Your password is set with your email account.&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
         * Used to disable certain display elements, e.g. password
         * fields on profile screen.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> show_password_fields<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2009/02/imap-authentication-for-wordpress-271/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>SSHfs on OS X via Samba</title>
		<link>http://neverusethisfont.com/blog/2008/11/sshfs-on-os-x-via-samba/</link>
		<comments>http://neverusethisfont.com/blog/2008/11/sshfs-on-os-x-via-samba/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 19:39:03 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OS X/Apple]]></category>
		<category><![CDATA[Server Software]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=62</guid>
		<description><![CDATA[Why, you ask? Because sshfs on OSX&#8217;s version of sshfs is wonky. My solution is to use an intermediate linux server which does the sshfs mount, then serves that to os x over a samba share. Another benefit to this is that you only need one samba share to mount all your sshfs connections, since [...]]]></description>
			<content:encoded><![CDATA[<p>Why, you ask?</p>
<p>Because sshfs on OSX&#8217;s version of sshfs is wonky.</p>
<p><a href="http://neverusethisfont.com/blog/wp-content/uploads/2008/11/osx-samba-sshfs.jpg"><img class="aligncenter size-full wp-image-64" title="osx-samba-sshfs" src="http://neverusethisfont.com/blog/wp-content/uploads/2008/11/osx-samba-sshfs.jpg" alt="" width="500" height="166" /></a></p>
<p>My solution is to use an intermediate linux server which does the sshfs mount, then serves that to os x over a samba share. Another benefit to this is that you only need one samba share to mount all your sshfs connections, since the linux server will be taking care of those. Also if you had a windows computer you wanted to use this with, it would also be able to mount the samba share from the linux server.</p>
<p>Let&#8217;s get started.</p>
<p>I ran into a couple tricky config issues while setting this up. This post is here mostly for me to remember them for next time I need to do them. If anybody else happens to stumble across this and finds it useful, then that&#8217;s a bonus.</p>
<p>On the linux server, you&#8217;ll need to install fuse-sshfs as well as samba. In Fedora, this can be done like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ yum <span style="color: #c20cb9; font-weight: bold;">install</span> samba
$ yum <span style="color: #c20cb9; font-weight: bold;">install</span> fuse-sshfs</pre></div></div>

<p>You need to add the linux user to the fuse group, and create a samba user account.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ usermod <span style="color: #660033;">-a</span> <span style="color: #660033;">-G</span> fuse aaron
$ smbpasswd <span style="color: #660033;">-a</span> aaron</pre></div></div>

<p>Here&#8217;s something that isn&#8217;t normally covered in fuse tutorials. In order to allow samba to access the fuse mount, you need to create a file, /etc/fuse.conf with the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user_allow_other</pre></div></div>

<p>If you don&#8217;t do that, the mounted folder just disappears from the samba share.</p>
<p>You need to make some changes to /etc/samba/smb.conf file in order for symlinks to be shared to os x. I&#8217;m not sure if this is required for fuse to work, but it&#8217;s nice to have anyway:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">unix extensions = no  <span style="color: #7a0874; font-weight: bold;">&#40;</span>add this outside of a share definition<span style="color: #7a0874; font-weight: bold;">&#41;</span>
follow symlinks = <span style="color: #c20cb9; font-weight: bold;">yes</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span>add this inside a share definition<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Of course, you need to configure the firewall to allow access to samba, (tcp and udp ports 445, 137, 138, 139 should do). And, you&#8217;ll need to make sure samba starts when the machine boots.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ chkconfig smb on</pre></div></div>

<p>We&#8217;re almost there.</p>
<p>To actually mount the sshfs folder, you&#8217;ll run a command which looks something like this. Note the extra option at the end:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sshfs username<span style="color: #000000; font-weight: bold;">@</span>example.com:<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>username mount_target <span style="color: #660033;">-o</span> allow_other</pre></div></div>

<p>Now you can mount your home folder on the linux server over samba, and you&#8217;ll see a folder mount_target, which is the sshfs mount.</p>
<p>Note: you&#8217;ll probably want to set up your ssh server with public key authentication so you don&#8217;t have to enter your password every time you connect. This is not the topic of this post, so I won&#8217;t bother mentioning how. There&#8217;s <a href="http://sial.org/howto/openssh/publickey-auth/">plenty</a> of <a href="http://www.ssh.com/support/documentation/online/ssh/adminguide/32/Public-Key_Authentication-2.html">other</a> <a href="http://www.onlamp.com/pub/a/onlamp/excerpt/ssh_8/">tutorials</a> on the Internet.</p>
<p>I hope this covers it, but feel free to comment if I&#8217;ve left anything out.</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2008/11/sshfs-on-os-x-via-samba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redundant web &amp; database servers on a budget using Virtual Private Servers</title>
		<link>http://neverusethisfont.com/blog/2008/09/redundant-web-database-servers-on-a-budget-using-virtual-private-servers/</link>
		<comments>http://neverusethisfont.com/blog/2008/09/redundant-web-database-servers-on-a-budget-using-virtual-private-servers/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 03:33:41 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Server Software]]></category>
		<category><![CDATA[Website Development]]></category>

		<guid isPermaLink="false">http://neverusethisfont.com/blog/?p=55</guid>
		<description><![CDATA[Background First let me just say that I have been struggling with this problem for quite some time now. The problem is to provide redundancy for a website so that the website continues to run even if there is a problem with one of the servers it&#8217;s running on. In a typical simple server setup, [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>First let me just say that I have been struggling with this problem for quite some time now. The problem is to provide redundancy for a website so that the website continues to run even if there is a problem with one of the servers it&#8217;s running on.</p>
<p>In a typical simple server setup, there is a single machine running the web and mysql servers. The machine can be either a dedicated server, or as I have been using, a <a href="http://en.wikipedia.org/wiki/Virtual_private_server">VPS</a>. I have been running my websites off of VPSs for several years now, with minimal trouble. This works most of the time, but the having a site on must one machine means a Single Point Of Failure. If something is wrong with that server, the websites are non-functional until it is fixed. The trouble I have run in to falls under a few categories:</p>
<ol>
<li>A problem with the physical host</li>
<li>A problem at the VPS level (operating system, Apache or MySQL errors, etc)</li>
<li>A problem at the network level</li>
</ol>
<h3>Problems with the physical host</h3>
<p>Problems with the physical host do occur. With a VPS, these are completely out of your control, and are the responsibility of the hosting provider. Some examples of things I&#8217;ve encountered include a failed RAID array, a corrupted filesystem on the host, requiring a several-hour-long fsck, or an unplugged power cord. The worst issue I&#8217;ve had was when the provider said they had lost 2 drives in a RAID 5 array, and all the VPSs on that host were completely gone. Luckily I had a backup of the system and was up and running on a new VPS within a couple hours.</p>
<h3>Problems at the application level</h3>
<p>I haven&#8217;t actually run in to many problems at the VPS level compared to the other types of problems. However the latest issue I&#8217;m having does fall in to this category. Apache periodically starts crashing part way through serving a page with the error &#8220;[notice] child pid 21106 exit signal Segmentation fault (11)&#8221;. Visitors see a completely blank page some of the time.</p>
<h3>Problems at the nework level</h3>
<p>By far the most frequently occurring problem I encounter is network-related. These problems are usually out of both my and the hosting provider&#8217;s control. If there is a problem with the network, the downtime can vary greatly, anywhere from 5 minutes to 12 hours. It can be caused by a <a href="http://en.wikipedia.org/wiki/Denial-of-service_attack">Denial of Service</a> attack on a completely different server in the same datacenter, or it could just be a routing issue somewhere along the path from me to the server.</p>
<p>A typical redundant setup will cover both #1 and #2. Typical setups may include one or more load balancers in front of multiple application servers. If a machine goes down, the load balancers can stop sending requests to it. This works great if you&#8217;re trying to protect against servers failing. However if the load balancers are all on the same network, unless the network has multiple redundant paths, the whole system is still vulnerable to network issues.</p>
<h2>My Solution</h2>
<p>Since I most frequently encounter network issues, I can&#8217;t get away with a just a typical load-balancing solution. What I really need is a copy of the entire website in a geographically different location. Here is my solution:</p>
<p>One VPS in Dallas, TX (called triton), and another VPS in Newark, NJ (called proteus). (Yes, I name my servers after Greek mythology.) Triton holds the master copies of the websites&#8217; php files, and proteus gets a copy of them via rsync. If I ever need to update the site, I edit the files on triton and then rsync them to proteus. Here is where the redundancy comes in. My DNS entries point the domain to both IP addresses. This means during normal operation, visitors will be more or less distributed between the two hosts evenly. If one server goes down, I can stop resolving DNS queries to it, and the worst that will happen is some dead pages for as long as the TTL on the domain.</p>
<p>This works as long as you&#8217;re just serving static content. Serving dynamic content, such as from a database, gets a little more complicated. MySQL&#8217;s NDB clusters are apparently only effective when run within a high speed network, with at least a 10 MBPS connection between them. Replication turns out to be more along the lines of what I&#8217;m looking for.</p>
<h2>Replication to the rescue!</h2>
<p>Replication is designed for a one-way sync between a master and slave. However, it is possible to configure two servers to be both a master and a slave. They will both notify each other of changes made to their databases. There is one trick you need to do in order to prevent primary key conflicts if rows are written to both databases while the link is down. It involves setting the auto_increment offset and increment, so that one server will only create even keys, and the other creates only odd keys.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>my.cnf
    auto_increment_increment = <span style="color: #000000;">2</span>
    auto_increment_offset = <span style="color: #000000;">1</span></pre></div></div>

<p>Here&#8217;s some dry reading on <a href="http://dev.mysql.com/doc/refman/5.0/en/replication.html">replication</a> from the MySQL manual. Here is a <a href="http://www.onlamp.com/pub/a/onlamp/2006/04/20/advanced-mysql-replication.html">slightly clearer guide to replication</a> which sums everything up pretty nicely. Overall, replication was pretty easy to set up. It seems to be pretty robust as well. I simulated network problems by adding firewall rules to block the servers from each other. I was able to continue to interact with each database, and the changes were all carried over when the link came back up.</p>
<p>Feel free to comment if you have any experience or insights into configuring web and database servers! I&#8217;m curious to hear what other people have done.</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2008/09/redundant-web-database-servers-on-a-budget-using-virtual-private-servers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IMAP Authentication for WordPress</title>
		<link>http://neverusethisfont.com/blog/2008/08/imap-authentication-for-wordpress/</link>
		<comments>http://neverusethisfont.com/blog/2008/08/imap-authentication-for-wordpress/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 08:00:16 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Server Software]]></category>

		<guid isPermaLink="false">http://blog.neverusethisfont.com/2008/08/imap-authentication-for-wordpress/</guid>
		<description><![CDATA[UPDATE 2/13/09: There is a newer version of the IMAP Authentication plugin for WordPress 2.7.1. It seems like IMAP authentication would be a pretty basic plugin to find for WordPress. A google search doesn&#8217;t turn up much. I found this one which was apparently written for an older version of WordPress. Never having written a [...]]]></description>
			<content:encoded><![CDATA[<p><b>UPDATE 2/13/09: There is a newer version of the <a href="/blog/2009/02/imap-authentication-for-wordpress-271/">IMAP Authentication plugin</a> for WordPress 2.7.1.</b></p>
<p>It seems like IMAP authentication would be a pretty basic plugin to find for WordPress. A google search doesn&#8217;t turn up much. I found <a href="http://norman.rasmussen.co.za/77/imap-authentication-plugin/">this one</a> which was apparently written for an older version of WordPress. Never having written a WordPress plugin before, naturally I decided to fix it to work with version 2.6.</p>
<p>Below is the result of my efforts. I started with Norman&#8217;s code, and modified it until it worked with version 2.6. I apologize if it is written poorly or if I missed something terribly obvious; I&#8217;ve never written a WordPress plugin before. </p>
<p>Download <a href="http://aaronpk.net/wp-imap-authentication/imap-authentication2.php">imap-authentication2.php</a></p>
<p><span id="more-52"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Plugin Name: IMAP Authentication
Version: 0.1
Plugin URI: http://blog.neverusethisfont.com/2008/08/imap-authentication-for-wordpress/
Description: Authenticate users using IMAP authentication.
Author: Aaron Parecki
Author URI: http://www.aaronparecki.com
&nbsp;
Assumes a successful login against the IMAP server is a valid user, and auto-creates
the user in Wordpress if they don't already exist.
&nbsp;
&nbsp;
&nbsp;
Copyright 2007 by Aaron Parecki  (email : aaron@parecki.com)
&nbsp;
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
&nbsp;
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
&nbsp;
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
&nbsp;
*/</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_menu'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'admin_menu'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lost_password'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'disable_password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'retrieve_password'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'disable_password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password_reset'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'disable_password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'show_password_fields'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'show_password_fields'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> is_plugin_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$mailbox</span> <span style="color: #339933;">=</span> IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">get_mailbox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user_suffix</span> <span style="color: #339933;">=</span> IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">get_user_suffix</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div class=&quot;wrap&quot;&gt;
  &lt;h2&gt;IMAP Authentication Options&lt;/h2&gt;
  &lt;form name=&quot;imapauthenticationoptions&quot; method=&quot;post&quot; action=&quot;options.php&quot;&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_nonce_field<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'update-options'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;update&quot; /&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;page_options&quot; value=&quot;imap_authentication_mailbox,imap_authentication_user_suffix&quot; /&gt;
    &lt;fieldset class=&quot;options&quot;&gt;
      &lt;table width=&quot;100%&quot; cellspacing=&quot;2&quot; cellpadding=&quot;5&quot; class=&quot;form-table&quot;&gt;
        &lt;tr valign=&quot;top&quot;&gt;
        &lt;th width=&quot;33%&quot; scope=&quot;row&quot;&gt;&lt;label for=&quot;imap_authentication_mailbox&quot;&gt;Mailbox&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;&lt;input name=&quot;imap_authentication_mailbox&quot; type=&quot;text&quot; id=&quot;imap_authentication_mailbox&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mailbox</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; size=&quot;80&quot; /&gt;&lt;br /&gt;eg: {mail.example.com/readonly}INBOX or {mail.example.com:993/ssl/novalidate-cert/readonly}INBOX&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr valign=&quot;top&quot;&gt;
        &lt;th scope=&quot;row&quot;&gt;&lt;label for=&quot;imap_authentication_user_suffix&quot;&gt;User Suffix&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;&lt;input name=&quot;imap_authentication_user_suffix&quot; type=&quot;text&quot; id=&quot;imap_authentication_user_suffix&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_suffix</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; size=&quot;50&quot; /&gt;&lt;br /&gt;A suffix to add to usernames (typically used to automatically add the domain part of the login).&lt;br /&gt;eg: @example.com&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/fieldset&gt;
    &lt;p class=&quot;submit&quot;&gt;
      &lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Save Changes'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
    &lt;/p&gt;
  &lt;/form&gt;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAPAuthentication'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">class</span> IMAPAuthentication <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">/*
         * Add an options pane for this plugin.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> admin_menu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            add_options_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAP Authentication'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'IMAP Authentication'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
         * Return the mailbox option from the database, creating the option if it doesn't exist.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> get_mailbox<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$cache_nonexistantoptions</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$mailbox</span> <span style="color: #339933;">=</span> get_settings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'imap_authentication_mailbox'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #000088;">$mailbox</span> or <span style="color: #000088;">$cache_nonexistantoptions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'imap_authentication_mailbox'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$mailbox</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'{localhost:143}INBOX'</span><span style="color: #339933;">;</span>
                IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">add_mailbox_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mailbox</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$mailbox</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
         * Add the mailbox option to the database.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> add_mailbox_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mailbox</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            add_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'imap_authentication_mailbox'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mailbox</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The mailbox to try and log into.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
         * Return the user_suffix option from the database, creating the option if it doesn't exist.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> get_user_suffix<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$cache_nonexistantoptions</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$user_suffix</span> <span style="color: #339933;">=</span> get_settings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'imap_authentication_user_suffix'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #000088;">$user_suffix</span> or <span style="color: #000088;">$cache_nonexistantoptions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'imap_authentication_user_suffix'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$user_suffix</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
                IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">add_user_suffix_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_suffix</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$user_suffix</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
         * Add the user_suffix option to the database.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> add_user_suffix_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_suffix</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            add_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'imap_authentication_user_suffix'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user_suffix</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'A suffix to add to usernames (typically used to automatically add the domain part of the login).'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// custom error handler</span>
        <span style="color: #000000; font-weight: bold;">function</span> eh<span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$msg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line</span><span style="color: #339933;">,</span> <span style="color: #000088;">$context</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$error</span><span style="color: #339933;">.</span><span style="color: #000088;">$msg</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> login<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$mbox</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imap_open</span><span style="color: #009900;">&#40;</span>IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">get_mailbox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">.</span>IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">get_user_suffix</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> OP_HALFOPEN<span style="color: #009900;">&#41;</span> or <span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imap_last_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mbox</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> get_userdatabylogin<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// the user checked out on the IMAP server, but there was no record in the database. Automatically add it now.</span>
					<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO <span style="color: #006699; font-weight: bold;">$wpdb-&gt;users</span> (user_login, user_nicename, user_email, display_name) VALUES(<span style="color: #009933; font-weight: bold;">%s</span>, <span style="color: #009933; font-weight: bold;">%s</span>, <span style="color: #009933; font-weight: bold;">%s</span>, <span style="color: #009933; font-weight: bold;">%s</span>)&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">.</span>IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">get_user_suffix</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> get_userdatabylogin<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO <span style="color: #006699; font-weight: bold;">$wpdb-&gt;usermeta</span> (user_id, meta_key, meta_value) VALUES(<span style="color: #009933; font-weight: bold;">%d</span>, <span style="color: #009933; font-weight: bold;">%s</span>, <span style="color: #009933; font-weight: bold;">%s</span>)&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'nickname'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO <span style="color: #006699; font-weight: bold;">$wpdb-&gt;usermeta</span> (user_id, meta_key, meta_value) VALUES(<span style="color: #009933; font-weight: bold;">%d</span>, <span style="color: #009933; font-weight: bold;">%s</span>, <span style="color: #009933; font-weight: bold;">%s</span>)&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rich_editing'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'true'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO <span style="color: #006699; font-weight: bold;">$wpdb-&gt;usermeta</span> (user_id, meta_key, meta_value) VALUES(<span style="color: #009933; font-weight: bold;">%d</span>, <span style="color: #009933; font-weight: bold;">%s</span>, <span style="color: #009933; font-weight: bold;">%s</span>)&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wp_capabilities'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'a:1:{s:6:&quot;author&quot;;b:1;}'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO <span style="color: #006699; font-weight: bold;">$wpdb-&gt;usermeta</span> (user_id, meta_key, meta_value) VALUES(<span style="color: #009933; font-weight: bold;">%d</span>, <span style="color: #009933; font-weight: bold;">%s</span>, <span style="color: #009933; font-weight: bold;">%s</span>)&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wp_user_level'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'2'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #990000;">imap_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mbox</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> WP_User<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				do_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'wp_login_failed'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> WP_Error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'incorrect_password'</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;strong&gt;ERROR&lt;/strong&gt;: Incorrect password.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
         * Used to disable certain login functions, e.g. retrieving a
         * user's password.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> disable_password<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            login_header<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Login'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;p class=&quot;message&quot;&gt;&lt;strong&gt;ERROR&lt;/strong&gt;: You can\'t do that here. This blog uses the IMAP login mechanism. Your password is set with your email account.&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/*
         * Used to disable certain display elements, e.g. password
         * fields on profile screen.
         */</span>
        <span style="color: #000000; font-weight: bold;">function</span> show_password_fields<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>is_plugin_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> wp_authenticate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> IMAPAuthentication<span style="color: #339933;">::</span><span style="color: #004000;">login</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2008/08/imap-authentication-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>iptables not logging to syslog</title>
		<link>http://neverusethisfont.com/blog/2007/09/iptables-not-logging-to-syslog/</link>
		<comments>http://neverusethisfont.com/blog/2007/09/iptables-not-logging-to-syslog/#comments</comments>
		<pubDate>Sat, 01 Sep 2007 20:10:06 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Server Software]]></category>

		<guid isPermaLink="false">http://blog.neverusethisfont.com/2007/09/iptables-not-logging-to-syslog/</guid>
		<description><![CDATA[I was scratching my head on this one for several hours before finally figuring out the solution which turned out to be ridiculously simple. I wanted to log all incoming tcp connections on port 25 and then drop them. I read through several guides on how to set up logging in iptables. (linuxgurus.com, linuxquestions.org) Seemed [...]]]></description>
			<content:encoded><![CDATA[<p>I was scratching my head on this one for several hours before finally figuring out the solution which turned out to be ridiculously simple.</p>
<p>I wanted to log all incoming tcp connections on port 25 and then drop them. I read through several guides on how to set up logging in iptables. (<a href="http://www.linuxguruz.com/iptables/howto/iptables-HOWTO-6.html" >linuxgurus.com</a>, <a href="http://www.linuxquestions.org/questions/showthread.php?t=385165">linuxquestions.org</a>)</p>
<p>Seemed straightforward enough. Here are the rules I ended up with: (output from iptables-save)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #660033;">-A</span> LOGDROP <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">/</span>sec <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">10</span> <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #000000;">7</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;LOGDROP: &quot;</span>
<span style="color: #660033;">-A</span> LOGDROP <span style="color: #660033;">-j</span> REJECT
...
<span style="color: #660033;">-A</span> RH-Firewall-<span style="color: #000000;">1</span>-INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">25</span> <span style="color: #660033;">-j</span> LOGDROP</pre></div></div>

<p>Any tcp connections to port 25 should get logged and rejected. You then need to decide what to do with the logged packets, which is where /etc/syslog.conf comes in. You need something like this in /etc/syslog.conf:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">kern.=debug     <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>firewall</pre></div></div>

<p>Note that there must be no spaces, only tabs in that line. That line tells any kernel messages that have the &#8220;debug&#8221; level to be written to the file /var/log/firewall. The &#8211;log-prefix 7 part of the iptables rule tells iptables to set the level of the message to &#8220;debug&#8221;. After changing syslog.conf, you need to restart the syslog daemon, with /etc/init.d/syslog restart:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>localhost ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># /etc/init.d/syslog restart</span>
Shutting down kernel logger:                               <span style="color: #7a0874; font-weight: bold;">&#91;</span>PASSED<span style="color: #7a0874; font-weight: bold;">&#93;</span>
Shutting down system logger:                               <span style="color: #7a0874; font-weight: bold;">&#91;</span>  OK  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
Starting system logger:                                    <span style="color: #7a0874; font-weight: bold;">&#91;</span>  OK  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
Starting kernel logger:                                    <span style="color: #7a0874; font-weight: bold;">&#91;</span>PASSED<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>I hadn&#8217;t seen [PASSED] show up there before, but I didn&#8217;t think much of it at the time.</p>
<p>The problem I was having was that there was nothing in the log file. I could see the packets being logged by running dmesg, but nothing went to the file. </p>
<p>I opened up syslog&#8217;s startup script, /etc/init.d/syslog, and examined the part where it is supposed to start klogd, the kernel logger. It was commented out, apparently by my vps host. Here is a snippet of my startup script. The bold lines are the ones I added, the commented out ones are what was originally there</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> $<span style="color: #ff0000;">&quot;Starting system logger: &quot;</span>
        daemon syslogd <span style="color: #007800;">$SYSLOGD_OPTIONS</span>
        <span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> $<span style="color: #ff0000;">&quot;Starting kernel logger: &quot;</span>
        <span style="color: #666666; font-style: italic;">#passed klogd skipped #daemon klogd $KLOGD_OPTIONS</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>b<span style="color: #000000; font-weight: bold;">&gt;</span>daemon klogd <span style="color: #007800;">$KLOGD_OPTIONS</span><span style="color: #000000; font-weight: bold;">&lt;/</span>b<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$RETVAL</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lock<span style="color: #000000; font-weight: bold;">/</span>subsys<span style="color: #000000; font-weight: bold;">/</span>syslog
        <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$RETVAL</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> $<span style="color: #ff0000;">&quot;Shutting down kernel logger: &quot;</span>
        <span style="color: #666666; font-style: italic;">#passed klogd skipped #killproc klogd</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>b<span style="color: #000000; font-weight: bold;">&gt;</span>killproc klogd<span style="color: #000000; font-weight: bold;">&lt;/</span>b<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> $<span style="color: #ff0000;">&quot;Shutting down system logger: &quot;</span>
        killproc syslogd
        <span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span>
        <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$RETVAL</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lock<span style="color: #000000; font-weight: bold;">/</span>subsys<span style="color: #000000; font-weight: bold;">/</span>syslog
        <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$RETVAL</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>According to some people <a href="http://forums.vpslink.com/showthread.php?page=2&#038;t=132">here</a>, it is not necessary to log kernel messages, and it significantly increases the loadavg. I have already been monitoring my loadavgs on my servers, so I&#8217;ll wait a week and see if there is any significant change.</p>
<p>Of course, now that I realize klogd wasn&#8217;t even started, this whole thing seems pretty silly.</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2007/09/iptables-not-logging-to-syslog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with caller ID!</title>
		<link>http://neverusethisfont.com/blog/2007/06/fun-with-caller-id/</link>
		<comments>http://neverusethisfont.com/blog/2007/06/fun-with-caller-id/#comments</comments>
		<pubDate>Thu, 07 Jun 2007 04:39:44 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Server Software]]></category>

		<guid isPermaLink="false">http://blog.neverusethisfont.com/2007/06/fun-with-caller-id/</guid>
		<description><![CDATA[We just got caller ID at my house. One of my roommates doesn&#8217;t have a cell phone, so eventually everyone else stopped answering the house phone because it was always for him. But then he would come home and not know who called. Now of course, caller ID solves this problem by logging who called [...]]]></description>
			<content:encoded><![CDATA[<p>We just got caller ID at my house. One of my roommates doesn&#8217;t have a cell phone, so eventually everyone else stopped answering the house phone because it was always for him. But then he would come home and not know who called. Now of course, caller ID solves this problem by logging who called on the phone handset, but being me, that is not enough!</p>
<p>My plan is to hook up a computer to the phone system, so that when a call comes through, it will send the caller ID information to a list of subscribed AIM screennames, that way I and he and anyone else will be instantly notified of who is calling without having to run to the phone.</p>
<p>So far, I&#8217;ve found a great guide for a simple setup of a linux answering machine, which I will adapt to use as this caller ID notifier. <a href="http://linuxgazette.net/120/smith.html" >A $10 Linux Answering Machine</a>.</p>
<p>I&#8217;m installing the zaptel driver at the moment, on a Fedora Core 6 box. Here is the process so far:</p>
<blockquote><p>cd /usr/src<br />
wget http://ftp.digium.com/pub/zaptel/zaptel-1.4.2.1.tar.gz<br />
tar -xzf zaptel-1.4.2.1.tar.gz<br />
cd zaptel-1.4.2.1
</p></blockquote>
<p>I got an error the first time I tried to run make:</p>
<blockquote><p>xbus-core.c:171: error: &#8216;struct inode&#8217; has no member named &#8216;u&#8217;</p></blockquote>
<p>Because I am using FC6, I needed to make a small tweak to the source code, according to <a href="http://lists.digium.com/pipermail/asterisk-users/2007-April/184142.html" >this message</a>.</p>
<p>edit this file:<br />
xpp/xbus-core.c<br />
and search for u.generic_ip<br />
change the line above that from 2,6,19 to 2,6,18</p>
<p>Now continue the normal build process: make, make install</p>
<p>The location of the zapata library has moved to:<br />
<a href="http://ftp.digium.com/pub/zaptel/releases/" >http://ftp.digium.com/pub/zaptel/releases/</a></p>
<p>When I tried to run &#8216;make&#8217;, I got a bunch of errors about undeclared constants, starting with</p>
<blockquote><p>zap.c:571:26: error: linux/zaptel.h: No such file or directory</p></blockquote>
<p>It looks like the zap.c and goertzel.c files are looking for the zaptel.h file in linux/zaptel.h, but not finding it. I have no idea why, but I change the include lines to look for /usr/include/zaptel/zaptel.h, and it works.</p>
<p>Continuing with Bob&#8217;s instructions, I got down to where I need to compile his program. I got some errors like:</p>
<blockquote><p>answering_machine.c:77: warning: incompatible implicit declaration of built-in function &#8216;exit&#8217;<br />
answering_machine.c:87: warning: incompatible implicit declaration of built-in function &#8216;strncpy&#8217;</p></blockquote>
<p>I found that it is necessary to add a couple of include lines:</p>
<blockquote><p>#include &lt;stdlib.h&gt;<br />
#include &lt;string.h&gt;</p></blockquote>
<p>I also disabled SElinux before I could run this program.</p>
<blockquote><p>vi /etc/sysconfig/selinux<br />
SELINUX=disabled<br />
echo 0 > /selinux/enforce
</p></blockquote>
<p>This will disable SElinux from ever starting again, and disable it in the current boot</p>
]]></content:encoded>
			<wfw:commentRss>http://neverusethisfont.com/blog/2007/06/fun-with-caller-id/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

