<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Andrew E. Bruno &#187; Hacks</title>
	<atom:link href="http://left.subtree.org/category/hacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://left.subtree.org</link>
	<description>A sourceful of secrets</description>
	<lastBuildDate>Tue, 07 Feb 2012 12:25:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='left.subtree.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/e14c799c6e8030a8abefcb495c0b0e17?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Andrew E. Bruno &#187; Hacks</title>
		<link>http://left.subtree.org</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://left.subtree.org/osd.xml" title="Andrew E. Bruno" />
	<atom:link rel='hub' href='http://left.subtree.org/?pushpress=hub'/>
		<item>
		<title>passtab &#8211; store passwords in your wallet</title>
		<link>http://left.subtree.org/2011/07/01/passtab-store-passwords-in-your-wallet/</link>
		<comments>http://left.subtree.org/2011/07/01/passtab-store-passwords-in-your-wallet/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 04:15:21 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[passtab]]></category>
		<category><![CDATA[passwords]]></category>

		<guid isPermaLink="false">http://left.subtree.org/?p=334</guid>
		<description><![CDATA[Here&#8217;s a quote from Bruce Schneier that essentially sums up the motivation for this post: We&#8217;re all good at securing small pieces of paper. I recommend that people write their passwords down on a small piece of paper, and keep it with their other valuable small pieces of paper: in their wallet. I recently read [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=left.subtree.org&amp;blog=13566420&amp;post=334&amp;subd=qnot&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quote from <a href="http://www.schneier.com/blog/archives/2005/06/write_down_your.html">Bruce Schneier</a> that essentially sums up the motivation for this post:</p>
<blockquote><p>
We&#8217;re all good at securing small pieces of paper. I recommend that people write<br />
their passwords down on a small piece of paper, and keep it with their other<br />
valuable small pieces of paper: in their wallet.
</p></blockquote>
<p>I recently read an excellent <a href="http://blog.jgc.org/2010/12/write-your-passwords-down.html">blog post</a> by John Graham-Cumming in which he presents a elegant system for writing down your passwords using a <a href="http://en.wikipedia.org/wiki/Tabula_recta">Tabula Recta</a>. I was inspired by this concept so I created a tool called <a href="https://github.com/aebruno/passtab">passtab</a> which aims to provide a light-weight system for managing passwords based on his idea. This post is about the general usage of passtab and presents some of the password management capabilities. This is not your grandmothers password manager so if you&#8217;re looking for a nice GUI point and click application that&#8217;s easy to use you can stop reading right here. This is for hardcore folks who enjoy looking up their passwords in archaic <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Tabula_recta">tablets</a> invented by ancient cryptographers with last names like <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Johannes_Trithemius">Trithemius</a>. For the impatient, you can grab a copy of the latest version on <a href="https://github.com/aebruno/passtab/archives/master">github</a>.  </p>
<p><strong>Introducing passtab</strong></p>
<p><a href="https://github.com/aebruno/passtab">passtab</a> is a light-weight system for managing passwords using a Tabula Recta. passtab has two main features: 1. generating random Tabula Recta&#8217;s in PDF format for printing and storing in your wallet 2. fetching passwords from the Tabula Recta (password managment). These features are independent and you can use passtab to only generate PDFs or optionally make use of the password management features. One unique benefit is the ability to have both an electronic and paper copy of your passwords. You can download the binary release of passtab at github <a href="https://github.com/aebruno/passtab/archives/master">here</a>. Unpack the distribution and run <code>./bin/passtab --help</code> for a list of options. If the startup shell script doesn&#8217;t work you can run <code>java -jar lib/passtab-uber.jar --help</code>. The following sections illustrate some use cases of passtab.</p>
<p><strong>Generate a random Tabula Recta in PDF</strong></p>
<p>passtab can generate random Tabula Recta&#8217;s in PDF format. </p>
<p><pre class="brush: plain;">
$ ./bin/passtab --format pdf --output passtab.pdf
Jun 12, 2011 11:16:29 AM org.qnot.passtab.PassTab generate
INFO: Generating a random Tabula Recta (might take a while)...
$ ls *.pdf
passtab.pdf
</pre></p>
<p>Here&#8217;s an <a href='http://qnot.files.wordpress.com/2011/06/passtab.pdf'>example PDF</a> generated from passtab. You can now print this PDF out and store in your wallet!</p>
<p><strong>How to use the Tabula Recta</strong></p>
<p>Here&#8217;s a simple example (taken directly from the <a href="https://github.com/aebruno/passtab/blob/master/README">README</a>), suppose we have the following Tabula Recta:</p>
<pre>

    | A B C D E F G H I J K L M N
  --|----------------------------
  A | _ u } I ` } R ) a &lt; L : a A
  B | - o ( : p # O % . _ ; ' j L
  C | w c ( c y 2 h y ~ N O * &gt; w
  D | o : R m L % V , d H r Y B j
  E | 9 , &lt; 0 J p a o ) O w 0 w #
  F | C j i } i z 2 $ O R 5 @ T I
  G | Q - E m 8 N c / + u W Y V &gt;
  H | , y } U Y i j i q w q c - 4
  I | K j W H e ; I ? E 7 H v 2 +
  J | g * 7 4 E } a h Y z &lt; " : w
  K | . _ } I / J k 1 a D ^ ; p K
  L | ` &lt; A L c z } } I P ? 4 y T
  M | F D &lt; 8 &lt; 0 R B t 9 X o B 2
  N | I r O E m o a + Y W w ; : 7
</pre>
<p></p>
<p>And suppose we want to get our password for logging into webmail at acme.com. We decide to use the first and last letter of the domain name as the start row/column of the password and we want a password 8 characters in length. So we start at the intersection of &#8216;A&#8217; and &#8216;E&#8217; and read off 8 characters diagonally resulting in the password: <code>'#h,)RWc</code></p>
<p>Defining a scheme for selecting the starting row/column for a given password is completely up to the user and can be as simple or as complex as one desires. The direction for reading the password is also up to the user to define (left, right, diagonally, etc.). See John Graham-Cumming&#8217;s excellent <a href="http://blog.jgc.org/2010/12/write-your-passwords-down.html">blog post</a> for more examples. </p>
<p>This method is slightly more complex than just writing down your passwords on a sheet of paper but the added complexity offers some advantages:</p>
<ol>
<li>Can store <i>all</i> your passwords on a single sheet of paper</li>
<li>If someone steals this sheet of paper they&#8217;ll have a harder time figuring out what your passwords are</li>
<li>Allows you to use strong random passwords</li>
<li>If you want to change your passwords just re-generate a new Tabula Recta. Your scheme for selecting passwords can stay the same</li>
</ol>
<p>passtab makes no assumptions about how passwords are read nor does it know anything about your scheme (unless you configure it). Now that you don&#8217;t have to remember long random passwords anymore what <i>do</i> you need to remember when using a Tabula Recta? Well first, you need to come up with a method for finding the starting position for a given password. In the example above this can be as simple as using characters from a domain/host name. But the beauty is you can be as creative as you want. A scheme that works for most of your passwords would probably be ideal but you can certainly generate multiple Tabula Recta&#8217;s if you like. Once you have a way of coming up with a starting location you need to define a method for reading off the password. In passtab this is called a <code>sequence</code>. In the example above we simply read 8 characters diagonally. But again you can be creative here. You could read 8 characters diagonally skipping every 3rd character, etc. Lastly, you&#8217;ll need to remember what to do if you hit the edge of the Tabula Recta before the end of the password. For example, if you start at Z:Z and want to read 8 characters diagonally you can&#8217;t because you reached the end of the Tabula Recta. In passtab this is called a <code>collision</code>. In this case we could just continue reading following the edge.</p>
<p>Using the Tabula Recta allows you to make use of long secure random passwords and only have to remember three simple things. You also have <i>all</i> your passwords on a single sheet of paper that fits in your wallet.</p>
<p><strong>Custom Alphabets</strong></p>
<p>In passtab, a Tabula Recta consists of two alphabets. The header alphabet and the data alphabet. The header alphabet is used for the row and column heading of the Tabula Recta and forms the basis for finding the starting location of the passwords. The data alphabet is used to generate the contents of the Tabula Recta and passtab will randomly pick characters from this alphabet using a cryptographically secure random number generator. By default, passtab uses a header alphabet of <code>0-9A-Z</code> and a data alphabet consisting of all printable ASCII characters. It&#8217;s important to keep in mind that the data alphabet directly effects the <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Password_strength#Entropy_as_a_measure_of_password_strength">entropy</a> of your passwords. passtab allows you to customize these alphabets allowing you to generate any kind of Tabula Recta, for example:</p>
<p><pre class="brush: plain;">
$ ./bin/passtab -b A,B,C,D -a 'a,b,c,d,1,2,3,4,!,@,#'
Jun 12, 2011 10:24:26 PM org.qnot.passtab.PassTab generate
INFO: Generating a random Tabula Recta (might take a while)...
  A B C D 
A d 1 @ 4 
B c 4 @ 2 
C b 3 3 ! 
D 1 a @ 4 
</pre></p>
<p>Here&#8217;s a Tabula Recta using greek symbols as the header alphabet (here&#8217;s the <a href='http://qnot.files.wordpress.com/2011/06/passtab-greek.pdf'>example PDF</a>):</p>
<p><pre class="brush: plain;">
$ ./bin/passtab -b 'Σ,Τ,Π,ρ,ϋ,ψ' -a 'a,b,c,d,1,2,3,4,!,@,#'
Jun 12, 2011 11:26:00 PM org.qnot.passtab.PassTab generate
INFO: Generating a random Tabula Recta (might take a while)...
  Σ Τ Π ρ ϋ ψ 
Σ 1 2 1 d d c 
Τ 1 2 b b @ c 
Π 1 # c 3 2 @ 
ρ 4 2 d 2 @ 3 
ϋ 2 3 b 1 ! b 
ψ d @ # c ! a
</pre></p>
<p><b>Password Management</b></p>
<p>So this is all well and great, but in reality it can be a huge pain to have to look up your webmail password in a Tabula Recta that&#8217;s on a sheet of paper in your wallet <i>every time you login</i>. For this reason, passtab has some optional features to help read passwords from the Tabula Recta. This allows you to have both a hard copy of the Tabula Recta in your wallet and an electronic version stored on your hard drive for quick access to your passwords. This obviously comes with some security considerations and care must be taken to protect the passtab database as you would any ssh private key for example. If someone got a hold of the passtab database file they could brute force your Tabula Recta. I ended up creating an encrypted thumb drive and store my passtab configuration and database files on it. You could also use gpg to encrypt it or any other method to protect it from the bad guys. This next section discusses the password management features of passtab.</p>
<p>First some definitions:</p>
<ul>
<li><strong>Direction</strong>: a <code>direction</code> to move on the Tabula Recta. Valid values are <code>N,S,E,W,NE,NW,SE,SW</code></li>
<li><strong>Sequence Item</strong>: a <code>sequence item</code> consists of a <code>length</code> and <code>direction</code>. For example, <code>12:SE</code> would mean move 12 characters in the SE direction (diagonally)</li>
<li><strong>Sequence</strong>: a <code>sequence</code> is a list of <code>sequence items</code>. This allows you to define arbitrary sequences for reading passwords. For example, <code>4:SE,3:N,1:S</code> would mean read 4 characters SE (diagonally) followed by 3 characters N (up) followed by 1 character S (down)</li>
<li><strong>Collision</strong>: a <code>collision</code> defines what directions to move if we hit the edge of the Tabula Recta before the end of the password. You can define more than one direction and they will be tried in order. For example, N,NE,E,SE,S,SW,W,NW would mean if we hit a wall try those directions in order until we&#8217;re able to move again</li>
</ul>
<p><strong>Generate a Tabula Recta in PDF and save to a passtab database</strong></p>
<p>passtab can generate a Tabula Recta in PDF along with storing it in a passtab database. The passtab database is stored in <a href="http://json.org/">JSON</a> format and can be easily accessed outside of passtab (any language that can read JSON files). Again, you&#8217;ll want to store that JSON file someplace safe. For example:</p>
<p><pre class="brush: plain;">
$ ./bin/passtab --dbsave --name mypasstab
Jun 12, 2011 10:48:33 PM org.qnot.passtab.PassTab generate
INFO: Generating a random Tabula Recta (might take a while)...
$ ls mypasstab.*
mypasstab.json  mypasstab.pdf
</pre></p>
<p><strong>Reading passwords from the passtab database</strong></p>
<p>Once we&#8217;ve created our passtab database we can now fetch passwords by telling passtab the starting location and the sequence to read. For example, suppose we want to read a password starting at row &#8216;B&#8217; and column &#8216;N&#8217; and we want a password 10 characters in length reading diagonally:</p>
<p><pre class="brush: plain;">
$ ./bin/passtab -i mypasstab.json --getpass B:N --sequence 9:SE
o6,ZzH{e$@
</pre></p>
<p>Copy the password to the clipboard using xclip:</p>
<p><pre class="brush: plain;">
$ ./bin/passtab -i mypasstab.json --getpass B:N --sequence 9:SE --chomp | xclip
</pre></p>
<p>We used <code>9:SE</code> as our sequence because passtab includes the character at the start location in the password. If we didn&#8217;t want to include this character we can optionally skip it like so:</p>
<p><pre class="brush: plain;">
$ ./bin/passtab -i mypasstab.json --getpass B:N --sequence 10:SE --skipstart
6,ZzH{e$@_
</pre></p>
<p>Define a list of directions to try in the event of a collision. This will try the directions N,S,E,W in order until we can move again. Here we start at Z:Z and can&#8217;t move SE (diagonally) so we try N (up) which works so we move N (up) until we hit another collision:</p>
<p><pre class="brush: plain;">
$ ./bin/passtab -i mypasstab.json --getpass Z:Z --sequence 9:SE --collision N,S,E,W
a((vy&amp;0bV&amp;
</pre></p>
<p><strong>Conclusion</strong></p>
<p>This post introduced a new tool called passtab for managing passwords using a Tabula Recta. I&#8217;m sure it has plenty of bugs so use at your own risk and if by chance you find it somewhat useful I&#8217;d be very interested in any feedback.   </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnot.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnot.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnot.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnot.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnot.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnot.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnot.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnot.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnot.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnot.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnot.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnot.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnot.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnot.wordpress.com/334/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=left.subtree.org&amp;blog=13566420&amp;post=334&amp;subd=qnot&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://left.subtree.org/2011/07/01/passtab-store-passwords-in-your-wallet/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">sigma110</media:title>
		</media:content>
	</item>
		<item>
		<title>WordPress Blog to Print Book &#8211; A Case Study</title>
		<link>http://left.subtree.org/2011/04/09/wordpress-blog-to-print-book-a-case-study/</link>
		<comments>http://left.subtree.org/2011/04/09/wordpress-blog-to-print-book-a-case-study/#comments</comments>
		<pubDate>Sat, 09 Apr 2011 05:05:18 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://left.subtree.org/?p=257</guid>
		<description><![CDATA[In this post I discuss my experience converting a WordPress blog into a print book. This is by no means a generic how-to guide but more along the lines of a case study. There&#8217;s a number of ways one could tackle this problem however I wasn&#8217;t able to find any existing methods that fit my [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=left.subtree.org&amp;blog=13566420&amp;post=257&amp;subd=qnot&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this post I discuss my experience converting a WordPress blog into a print book. This is by no means a generic how-to guide but more along the lines of a case study. There&#8217;s a number of ways one could tackle this problem however I wasn&#8217;t able to find any existing methods that fit my needs. Specifically, I wanted to convert the content of a WordPress blog into a high quality print ready PDF book (complete with chapters, sections, table of contents, images, figures, page numbering, index, etc.) which could then be sent to various <a href="http://en.wikipedia.org/wiki/Print_on_demand">POD</a> publishers such as <a href="http://www.lulu.com/">Lulu</a> for printing. I wanted to streamline as much of the process as possible to allow for regenerating the PDF book as new posts are made. Ideally there would be a WordPress plugin for this but to make such a plugin generic enough would be tricky and require many assumptions to be made regarding the structure of your blog (i.e. what constitutes a chapter or a section?, etc.). In this post I describe how I ended up creating a PDF book from WordPress and discuss a few challenges I encountered along the way. A brief disclaimer: this post is intended for folks who are familiar with *nix command line and enjoy mucking around in code (and don&#8217;t mind slinging around some XML here and there). It&#8217;s not for the faint of heart but hopefully it will be useful to others interested in a similar outcome.</p>
<p>If you&#8217;d rather skip this epic post and dive right into the code you can browse it all over on <a href="https://github.com/aebruno/wp2print">github</a>. There&#8217;s a <a href="https://github.com/aebruno/wp2print/blob/master/README">README</a> file and a <a href="https://github.com/aebruno/wp2print/blob/master/Makefile">Makefile</a> which details how to run wp2print and includes a simple example. </p>
<p><strong>Background and Assumptions</strong></p>
<p>The idea for this project came about as my family has been writing a private blog that I want to be able to share with my children some day. I&#8217;ve often thought about giving them a copy of the blog when their much older and wondered what would be the best way to preserve the content ensuring it&#8217;s viewable years down the road. I thought by creating a physical copy of the blog I could have something tangible to pass down through the generations. Using the services provided by companies like Lulu and Blurb printing a book is as simple as uploading a PDF and designing a cover. Having <a href="http://oreilly.com/">worked</a> in the publishing industry in a former life I had some experience generating PDF books so I looked forward to the challenge. </p>
<p>As my goal was to create a book I needed to convert the content of the blog into an intermediate format which represented the book and could then be used to generate a PDF file. As I had a good amount of experience slinging around <a href="http://www.docbook.org/">DocBook</a>, my general idea was to export the content from WordPress and convert it into DocBook. Then converting DocBook into a PDF is fairly straightforward using the wonderful <a href="http://docbook.sourceforge.net/">DocBook stylesheets</a> and <a href="http://xmlgraphics.apache.org/fop/">Apache FOP</a>. </p>
<p>The first obvious challenge when converting a blog into a book is deciding how to go about organizing the blog posts into chapters and sections. Our family blog was authored in such a way that each post had only one tag (category) and most importantly all posts were tagged chronologically. Meaning that all posts in a given category were sequential. For example, posts 0-5 are all tagged with &#8220;tag1&#8243;, posts 6-10 are all tagged with &#8220;tag2&#8243;, and so on. You can probably see where this is going. Having authored the blog in this format allowed me to easily use each tag as a Chapter and each post appeared as a section within that chapter. If your unable to make these assumptions about your blog (and most likely you won&#8217;t be able to) just keep this in mind as we delve into the code later on. You would need to modify the script I wrote and add in the appropriate logic to slice your blog posts up into chapters/sections or however you&#8217;d like to structure your DocBook file. I experimented with just making each post a chapter (and even a series of DocBook <a href="http://www.docbook.org/tdg5/en/html/article.html">articles</a>) which isn&#8217;t a bad option however depending on the number of posts you may want to consider omitting the table of contents.</p>
<p>A few other assumptions I made:</p>
<ul>
<li>All posts were written by the same author so I omitted displaying any author information. Easy enough to add in if needed</li>
<li>All comments were excluded from the book. Comments are an important part of any blog but in this case my blog didn&#8217;t have very many comments. I was most interested in the content of the post only and decided to omit any and all comments. These could certainly be added in but some thought would be needed on which DocBook element to use for structuring them within the book.</li>
<li>There was one page (not a post) with the title &#8220;About&#8221; that I used as the preface for the book. This can be any post/page or omitted completely if desired.</li>
<li>Access to the WordPress code that runs the blog. This won&#8217;t work if your blog is hosted for example at WordPress.com. You&#8217;ll need to export your blog and run it on your own server.</li>
</ul>
<p>Here&#8217;s a brief outline of the entire process. I&#8217;ll go over each step in detail in the next section. </p>
<ol>
<li>Convert WordPress content to DocBook &#8211; using PHP and some XSLT</li>
<li>Convert DocBook to <a href="https://secure.wikimedia.org/wikipedia/en/wiki/XSL_Formatting_Objects">XSL-FO</a> &#8211; using DocBook stylesheets</li>
<li>Convert XSL-FO to PDF &#8211; using Apache FOP</li>
<li>Upload PDF file to Lulu and order print book</li>
</ol>
<p><strong>Convert WordPress content to DocBook</strong></p>
<p>First step was to convert the blog into DocBook. This was by far the most challenging step. My first attempt was to use the <a href="https://en.support.wordpress.com/export/">Export</a> feature in WordPress which dumps the entire contents of your blog in XML format (WordPress eXtended RSS) and write an XSLT to convert into DocBook. This turned out to be slightly harder than I anticipated because of how the content of each post was formatted in the WordPress XML dump. It appeared to be in the native format WordPress uses to store the post in the database and I didn&#8217;t want to have to write a custom WordPress post renderer for DocBook. I decided to instead write a fairly simple PHP script which used the WordPress API to render each post in HTML just like it normally would if someone visited the site, then convert the HTML to DocBook. I found converting the HTML to DocBook was slightly easier than having to parse the native WordPress format. I did this in two steps, first I wrote a PHP script to generate a quasi-DocBook file which uses the WordPress API to embed the HTML content of each post within a <code>&lt;section/&gt;</code>. Then I wrote an XSLT which transforms the quasi-DocBook and embedded HTML into a final valid DocBook file. The main PHP code is <a href="https://github.com/aebruno/wp2print/blob/master/lib/export-docbook.php">here</a>. You&#8217;ll need to change the include paths in <a href="https://github.com/aebruno/wp2print/blob/master/lib/config.php">config.php</a> to point to your WordPress installation (see the <a href="https://github.com/aebruno/wp2print/blob/master/Makefile">Makefile</a> for a complete example).  The XSLT is <a href="https://github.com/aebruno/wp2print/blob/master/wp-html2docbook.xsl">here</a>. It looks for various HTML tags that appear in my blog and converts those to valid DocBook elements. I built up the XSLT by trial and error. I first just rendered the quasi-DocBook generated from the PHP script as PDF. The DocBook stylesheets have a nice feature in that any invalid DocBook elements it encounters are highlighted in red in the resulting PDF. By iterating through the invalid elements I was able to add the correct templates to my XSLT to account for all HTML tags found in my blog posts. You&#8217;ll most certainly need to modify this XSLT file to suite your specific needs but should serve as a decent starting point. Here&#8217;s an example of the HTML generated by WordPress for an image included in a blog post:</p>
<p><pre class="brush: xml;">
&lt;div id=&quot;attachment_155&quot; class=&quot;wp-caption aligncenter&quot; style=&quot;width: 310px&quot;&gt;
  &lt;a href=&quot;/wp-content/media/2008/11/image.jpg&quot;&gt;
        &lt;img class=&quot;size-medium wp-image-155&quot; title=&quot;image title&quot; src=&quot;/wp-content/media/2008/11/image-300x218.jpg&quot; alt=&quot;image alt&quot; width=&quot;300&quot; height=&quot;218&quot;/&gt;
  &lt;/a&gt;
  &lt;p class=&quot;wp-caption-text&quot;&gt;This is a description of the image&lt;/p&gt;
&lt;/div&gt;
</pre></p>
<p>Which then gets converted to a DocBook <a href="http://www.docbook.org/tdg5/en/html/mediaobject.html">mediaobject</a> element:</p>
<p><pre class="brush: xml;">
&lt;para&gt;
  &lt;mediaobject&gt;
    &lt;imageobject&gt;
       &lt;imagedata align=&quot;center&quot; fileref=&quot;images/2008/11/image.jpg&quot; width=&quot;4.0in&quot; depth=&quot;3.0in&quot; scalefit=&quot;1&quot; format=&quot;JPG&quot;/&gt;
    &lt;/imageobject&gt;
    &lt;caption&gt;&lt;para&gt;This is a description of the image&lt;/para&gt;&lt;/caption&gt;
  &lt;/mediaobject&gt;
&lt;/para&gt;
</pre></p>
<p><strong>A note about images&#8230;</strong></p>
<p>Care must be taken to ensure any images you want included in the book are print ready. I ended up having quite a few images in my blog that I wanted to include in the final PDF which required some extra work to get them ready for printing. For best results you&#8217;ll want make to be sure the resolution of your images are at least 300ppi (<a href="https://secure.wikimedia.org/wikipedia/en/wiki/Dots_per_inch#DPI_or_PPI_in_digital_image_files">pixels per inch</a>). See <a href="http://connect.lulu.com/t5/Interior-Formatting/What-resolution-DPI-should-my-images-have-to-achieve-optimum/ta-p/31434">this post on Lulu</a>. For example, if your image is 600x600px and you set the resolution to be 300ppi, the printed image will be roughly 2x2in. In my case I was printing a 6&#215;9 book and after factoring in margins/spine/bleed etc. I calculated the maximum print size I wanted each image was 4x3in (as defined in the DocBook XML element <code>&lt;imagedata width="4.0in" height="3.0in"/&gt;</code> in the above example). As most of the images were pictures, this print size ended up being large enough so the photo was still viewable but small enough to allow for 2 images per page. This meant that the minimum size (in pixels) each image had to be was 1200x900px. The problem was when we uploaded pictures to our blog we had WordPress resize them to 500x400px (from their original size of 2816x2112px from the camera). Fortunately, I still had the original image files which I collected and used in the final PDF. Something to keep in mind if you have images (especially photographs) in your blog that you want printed. I ran into another edge case with the images which required a little bit of <a href="http://www.imagemagick.org">imagemagick</a>. I had a few important pictures that were taken with photo booth on a mac in which the original size image was a mere 640x480px. I knew the print version of the images would look dreadful so my only option was to resample them to a higher resolution. This can easily be accomplished using imagemagick&#8217;s <a href="http://www.imagemagick.org/script/command-line-options.php#resample">convert command</a>:</p>
<p><pre class="brush: plain;">
$ convert -resample 300x orig.jpg hires.jpg
</pre></p>
<p>In summary, be sure your images are high enough resolution for printing. It&#8217;s definitely worth the extra work. I had roughly 100 images in my blog and all of them turned out really nice in the final print book. I was quite impressed with the quality of Lulu&#8217;s printers. </p>
<p><strong>DocBook &#8211;&gt; XSL-FO &#8211;&gt; PDF</strong></p>
<p>Converting DocBook to PDF was fairly straightforward using two excellent projects <a href="http://docbook.sourceforge.net/">DocBook stylesheets</a> and <a href="http://xmlgraphics.apache.org/fop/">Apache FOP</a>. I won&#8217;t cover how to install them on your platform and refer you to the excellent INSTALL guides at the <a href="http://docbook.sourceforge.net/release/xsl/current/INSTALL">respective</a> <a href="http://xmlgraphics.apache.org/fop/quickstartguide.html">sites</a>. If you happen to be running Ubuntu using the stock packages should work fine. Simply run <code>aptitude install fop docbook-xsl</code> and you should be all set. The basic goal for this step was to use the DocBook XSL FO stylesheets to convert the DocBook created from the previous step into XSL-FO which can be fed into Apache FOP for conversion into PDF. This step required that an XSLT processor be installed such as xsltproc (libXML), Saxon, Xalan, etc. I used xsltproc and can easily be installed on Ubuntu <code>aptitude install xsltproc</code>. After running xsltproc I passed the resulting XSL-FO output into Apache FOP to generate the final PDF. For more details see the <a href="https://github.com/aebruno/wp2print/blob/master/Makefile">Makefile</a>. Here&#8217;s the basic commands:</p>
<p><pre class="brush: plain;">
$ xsltproc /path/to/docbook-xsl/fo/docbook.xsl docbook-final.xml &gt; book.fo
$ fop book.fo book.pdf
</pre></p>
<p>The DocBook XSL FO stylesheets provide a <a href="http://docbook.sourceforge.net/release/xsl/current/doc/fo/index.html">generous number of parameters</a> for customizing the resulting FO. The default parameter settings produce a very nice looking PDF but if you like to tweak things there&#8217;s no shortage of knobs to turn. As I ended up printing my book with Lulu there were a few specific customizations that were required. First I was interested in printing a US Trade 6&#215;9 inch hard cover book so the default page <a href="http://docbook.sourceforge.net/release/xsl/current/doc/fo/page.width.html">width</a>/<a href="http://docbook.sourceforge.net/release/xsl/current/doc/fo/page.height.html">height</a> needed to be set accordingly. Some other tweaks I made included adjusting the <a href="http://docbook.sourceforge.net/release/xsl/current/doc/fo/page.margin.inner.html">margins</a> slightly to provide some extra room on the <a href="http://connect.lulu.com/t5/Interior-Formatting/How-big-should-my-margins-be/ta-p/31404">spine edge</a> of the book, customizing the <a href="http://docbook.sourceforge.net/release/xsl/current/doc/fo/generate.toc.html">table of contents</a> to only include the chapter/sections, and <a href="http://docbook.sourceforge.net/release/xsl/current/doc/fo/body.start.indent.html">customizing the indentation</a> of chapters and sections (in this case I didn&#8217;t want any indentation). Here&#8217;s the resulting xsltproc command with the custom parameter settings:</p>
<p><pre class="brush: plain;">
    xsltproc \
    --stringparam page.width 6in \
    --stringparam page.height 9in \
    --stringparam page.margin.inner 1.0in \
    --stringparam page.margin.outer 0.8in \
    --stringparam body.start.indent 0pt \
    --stringparam body.font.family  Times \
    --stringparam title.font.family Times \
    --stringparam dingbat.font.family Times \
    --stringparam generate.toc 'book toc title' \
    --stringparam hyphenate false \
    /path/to/docbook-xsl/fo/docbook.xsl \
    docbook-final.xml &gt; book.fo
</pre></p>
<p><strong>A note about Fonts..</strong></p>
<p>The last and most important configuration I made was with fonts. Lulu requires fonts to be fully <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Portable_Document_Format#Fonts">embedded</a> which means any font you use in your PDF <a href="http://www.lulu.com/help/embed_fonts">must be embedded</a> (the font files are included directly in the PDF file) or else they will reject the PDF. Embedding fonts is supported by Apache FOP but requires some custom configuration. First I had to decide which font to use. Fonts can be really tricky and I didn&#8217;t want to get too fancy. Using a single font for the entire book was fine with me and I decided to stick with a traditional Times New Roman font. I ended up using the FreeSerif TrueType font from <a href="http://www.gnu.org/software/freefont/">GNU FreeFont</a>. It was already installed on my Ubuntu machine and very easy to embed with Apache FOP. By default these fonts are installed in <code>/usr/share/fonts/truetype/freefont/</code>.There&#8217;s lots of other free fonts out there that you could use including the <a href="https://fedorahosted.org/liberation-fonts/">Liberation Fonts</a> and even the <a href="http://packages.ubuntu.com/lucid/ttf-mscorefonts-installer">Micro$oft True Type Core Fonts</a> which can be installed on Ubuntu by running <code>aptitude install msttcorefonts</code>. To configure Apache FOP to use GNU Free Fonts and embed them into the final PDF I created a file called <code>userconf.xconf</code> with the following lines:</p>
<p><pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;fop version=&quot;1.0&quot;&gt;
&lt;renderers&gt;
   &lt;renderer mime=&quot;application/pdf&quot;&gt;
      &lt;!-- Full path to truetype fonts to be embedded in PDF file --&gt;
      &lt;fonts&gt;
        &lt;font embed-url=&quot;file:///usr/share/fonts/truetype/freefont/FreeSerif.ttf&quot;&gt;
          &lt;font-triplet name=&quot;Times&quot; style=&quot;normal&quot; weight=&quot;normal&quot;/&gt;
        &lt;/font&gt;
        &lt;font embed-url=&quot;file:///usr/share/fonts/truetype/freefont/FreeSerifBold.ttf&quot;&gt;
          &lt;font-triplet name=&quot;Times&quot; style=&quot;normal&quot; weight=&quot;bold&quot;/&gt;
        &lt;/font&gt;
        &lt;font embed-url=&quot;file:///usr/share/fonts/truetype/freefont/FreeSerifItalic.ttf&quot;&gt;
          &lt;font-triplet name=&quot;Times&quot; style=&quot;italic&quot; weight=&quot;normal&quot;/&gt;
        &lt;/font&gt;
        &lt;font embed-url=&quot;file:///usr/share/fonts/truetype/freefont/FreeSerifBoldItalic.ttf&quot;&gt;
          &lt;font-triplet name=&quot;Times&quot; style=&quot;italic&quot; weight=&quot;bold&quot;/&gt;
        &lt;/font&gt;
      &lt;/fonts&gt;
   &lt;/renderer&gt;
&lt;/renderers&gt;
&lt;/fop&gt;
</pre></p>
<p>Then ran fop passing the -f option like so: <code>fop -f userconf.xconf book.fo book.pdf</code>. Note the <code>&lt;font-triplet <strong>name="Times"</strong> /&gt;</code> attribute must match the <code>body.font.family Times</code> XSLT parameter passed to xsltproc command. </p>
<p><strong>Simple Example</strong></p>
<p>All the code described in this post is available on <a href="https://github.com/aebruno/wp2print">github</a>. I also include a simple example to demonstrate the entire conversion process and provide some sample PDFs to see how final book renders. I created a simple test blog consisting of Shakespeare&#8217;s Sonnets I thru X and exported the content in WordPress eXtended RSS so you can then import into a fresh install of WordPress. I tested using the latest version of WordPress at the time of this writing (v3.1). To try it out yourself download the code for wp2print and read thru the <a href="https://github.com/aebruno/wp2print/blob/master/README">README</a> file which outlines all the gory details. The <a href="https://github.com/aebruno/wp2print/blob/master/Makefile">Makefile</a> outlines the general process and should provide a good starting point for experimenting. Here&#8217;s some sample PDFs that were rendered from the example Shakespeare blog:</p>
<ul>
<li><a href="http://qnot.files.wordpress.com/2011/04/book-with-chapters.pdf">Book with Chapters and Sections</a></li>
<li><a href="http://qnot.files.wordpress.com/2011/04/book-with-articles.pdf">Book with all posts as DocBook Articles</a></li>
<li><a href="https://github.com/aebruno/wp2print/blob/master/sample/sample-docbook.xml">Raw DocBook output</a></li>
</ul>
<p><strong>Conclusion</strong></p>
<p>With the help of a few simple scripts it&#8217;s possible to create a high quality print ready PDF book from a WordPress blog. Depending on the content of the blog you&#8217;ll most certainly need to tailor these scripts to suite your specific requirements. The main challenges are figuring out how you want to organize your blog posts into the framework of a book and then modifying the XSLT templates to convert the WordPress html markup of your blog into valid DocBook elements. The services offered by print on demand publishers such as Lulu provide an easy way to turn the resulting PDF into a high quality paper book.  </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnot.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnot.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnot.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnot.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnot.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnot.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnot.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnot.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnot.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnot.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnot.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnot.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnot.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnot.wordpress.com/257/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=left.subtree.org&amp;blog=13566420&amp;post=257&amp;subd=qnot&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://left.subtree.org/2011/04/09/wordpress-blog-to-print-book-a-case-study/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">sigma110</media:title>
		</media:content>
	</item>
		<item>
		<title>Database Design with Dia</title>
		<link>http://left.subtree.org/2007/12/05/database-design-with-dia/</link>
		<comments>http://left.subtree.org/2007/12/05/database-design-with-dia/#comments</comments>
		<pubDate>Thu, 06 Dec 2007 05:23:48 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://left.subtree.org/2007/12/05/database-design-with-dia/</guid>
		<description><![CDATA[In this post I&#8217;m going to give a quick how-to on creating database schemas with a wonderful tool called Dia. I&#8217;ve often found having a nice visual representation of a database to be quite helpful but can&#8217;t stand keeping it up to date. As soon as you add a new column or change the design [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=left.subtree.org&amp;blog=13566420&amp;post=14&amp;subd=qnot&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this post I&#8217;m going to give a quick how-to on creating database schemas with a wonderful tool called <a href="http://live.gnome.org/Dia">Dia</a>. I&#8217;ve often found having a nice visual representation of a database to be quite helpful but can&#8217;t stand keeping it up to date. As soon as you add a new column or change the design around you end up having to sync your visual diagram with your SQL files. It&#8217;s tedious having to  manage the various SQL for building the database and this can be a larger pain when trying to support different database platforms each with their own SQL syntax. So before you create your next database read on and see how Dia can make your life a bit easier.</p>
<p><a href="http://live.gnome.org/Dia">Dia</a> is a program for creating diagrams and for this exercise we&#8217;ll be creating UML diagrams from within Dia. We&#8217;re also going to use a perl script called <a href="http://tedia2sql.tigris.org/">tedia2sql</a> which will transform our Dia files directly to SQL for our target database. What&#8217;s also nice about creating database schemas this way is that you can generate SQL for multiple target databases without the maintenance overhead.</p>
<p>First off, install a copy of Dia as well as tedia2sql. You can download tedia2sql <a href="http://tedia2sql.tigris.org/servlets/ProjectDocumentList">here</a> and download Dia <a href="http://live.gnome.org/Dia/Download">here</a>. I&#8217;m not going to cover the install in this post but there should be packages available for most Linux distro&#8217;s and if your not running Linux now is a great time to start!</p>
<p>Fire up Dia, create a new diagram and save it as &#8220;employee.dia&#8221;. Select the UML sheet from the drop down list. We&#8217;ll be using various UML objects to represent tables and definitions that make up our database. Here&#8217;s a quick overview of the main UML objects and their usage:</p>
<table style="width:100%;border:none;">
<tr>
<td style="border:none;"><img style="border:1px solid #ccc;" src="http://qnot.files.wordpress.com/2007/12/dia_menu.jpg?w=700" alt="" title="dia_menu"   class="aligncenter size-full wp-image-154" /></td>
<td style="border:none;">
<div style="margin-bottom:20px;">
   <img src="http://qnot.files.wordpress.com/2007/12/dia_class.png?w=700" alt="" title="dia_class"   class="size-full wp-image-155" style="float:left;padding:4px;" /> <span style="font-weight:bold;">Class</span> represents a table in the database. A Class has a name which corresponds to the name of the table and attributes which map to the columns of the table. Attributes in classes can have visibility (public, private, protected). Protected attributes are primary keys. More on classes later.
</div>
<div style="margin-bottom:20px;">
   <img src="http://qnot.files.wordpress.com/2007/12/dia_component.png?w=700" alt="" title="dia_component"   class="alignnone size-full wp-image-158" style="float:left;padding:4px;" /> <span style="font-weight:bold;">Component</span> is a special object that lets you define a list of default values to be inserted into a table. These are equivalent to hard coding &#8220;insert into ..&#8221; statements in your SQL files.
</div>
<div>
   <img src="http://qnot.files.wordpress.com/2007/12/dia_small_package.png?w=700" alt="" title="dia_small_package"   class="alignnone size-full wp-image-159" style="float:left;padding:4px;" /> <span style="font-weight:bold;">Small Package</span> represents a typemap. Typemaps are used for adding custom SQL types such as MySQL tinyint.
</div>
</td>
</tr>
</table>
<p>Now lets create our first table. Select the &#8220;Class&#8221; object icon from the UML sheet and click inside the diagram editor window. This will add the class to your diagram. Now right click on the new class and select &#8220;Show Properties&#8221;. This will bring up a rather large and complex property window for the UML class you&#8217;ve just created. We&#8217;re only going to customize a few properties outlined below.</p>
<p>First, under the &#8220;Class&#8221; tab enter the name of the table (employee) in the &#8220;Class Name: &#8221; field. Next click on the &#8220;Attributes&#8221; tab and enter in the columns of the table as attributes. In the &#8220;Name: &#8221; field enter in the column name. In the &#8220;Type: &#8221; field enter in the SQL type for the column. If you want to support multiple database platforms try to be generic here and only use ANSI SQL 1992 or else use a typemap. More on typemaps later. In the &#8220;Value: &#8221; field enter any default values for the column. For example, this is where you could add in &#8220;not null&#8221;. If the column your adding is a primary key then don&#8217;t put &#8220;not null&#8221; here and instead select &#8220;Protected&#8221; for the &#8220;Visibility: &#8221; field. Not null will automatically get added to all primary keys on output generation. The screen shot below is an example of the Class property editor window.</p>
<p><img src="http://qnot.files.wordpress.com/2007/12/dia_attributes.jpg?w=700" alt="" title="dia_attributes"   class="aligncenter size-full wp-image-161" style="border:1px solid #ccc;" /></p>
<p>Next, repeat the process for as many tables as you need in your database. For this example, create two tables &#8220;employee&#8221; and &#8220;department&#8221; with the columns as shown in the screenshot below (note the &#8216;#&#8217; in front of an attribute indicates that it&#8217;s visibility is &#8220;Protected&#8221; thus making it a Primary Key):</p>
<p><img src="http://qnot.files.wordpress.com/2007/12/dia_employee.jpg?w=700" alt="" title="dia_employee"   class="aligncenter size-full wp-image-162" style="border:1px solid #ccc;" /></p>
<p>This is a simple example of a database which stores employee data along with the department they belong to. Now suppose we have a default list of departments that we&#8217;d like to load into the department table when our database is created. To do this we&#8217;ll use the &#8220;Component&#8221; object from the UML sheet. Select the &#8220;Component&#8221; object and add it to your diagram editor window. Right click and select &#8220;Properties&#8221;.</p>
<p><img src="http://qnot.files.wordpress.com/2007/12/dia_comp_prop.jpg?w=700" alt="" title="dia_comp_prop"   class="aligncenter size-full wp-image-163" style="border:1px solid #ccc;" /></p>
<p>In the &#8220;Stereotype: &#8221; field you basically enter in the first part of an &#8220;insert into ..&#8221; SQL statement. For this example, to insert a default list of departments we&#8217;d normally write the following SQL:</p>
<p><pre class="brush: sql;">
insert into department (department_id, name) values (1, 'Marketing');
insert into department (department_id, name) values (2, 'Production');
insert into department (department_id, name) values (3, 'Design');
</pre></p>
<p>So in this case, for the &#8220;Stereotype: &#8221; field we&#8217;d enter in &#8220;department (department_id, name)&#8221;. Click OK to close the properties dialog. Now in the Component object box enter in the values you&#8217;d like to insert, one per line. Here&#8217;s what our diagram should look like now:</p>
<p><img src="http://qnot.files.wordpress.com/2007/12/dia_employee2.jpg?w=700" alt="" title="dia_employee2"   class="aligncenter size-full wp-image-164" style="border:1px solid #ccc;" /></p>
<p>Now lets add in a typemap. Typemaps are used for when you&#8217;d like to configure custom types which are specific to a database platform. A good example of this is MySQL auto_increment. This is a feature specific to MySQL and not supported in all databases. Lets suppose we&#8217;d like to have a primary key column which gets auto incremented upon each insert. But we also want to support both MySQL and Apache Derby without having to maintain separate SQL files. To achieve this we&#8217;ll create a custom typemap and define the specific SQL for each target db.</p>
<p>Typemaps are created using a Small Package so select the &#8220;Small Package&#8221; object and add it to your diagram editor window. Right click and select &#8220;Properties&#8221;.</p>
<p><img src="http://qnot.files.wordpress.com/2007/12/dia_type_prop.jpg?w=700" alt="" title="dia_type_prop"   class="aligncenter size-full wp-image-165" style="border:1px solid #ccc;" /></p>
<p>In the &#8220;Stereotype: &#8221; field you enter in the target database. So for example &#8220;mysql: typemap&#8221;.  For a list of supported target databases see tedia2sql &#8211;help. Some common ones are: postgres, mysql, sybase, oracle, db2, and innodb. Click OK to close the properties dialog. Now inside the Small package box you can enter custom types one per line. For this example we&#8217;ll create a custom type with a name of &#8220;identity&#8221;. This means that when we generate our SQL files, tedia2sql will replace the column type with our custom type. Here&#8217;s a few examples:</p>
<table style="width:100%;border:none;">
<tr>
<td style="border:none;">
MySQL typemaps<br />
<pre class="brush: plain; light: true; wrap-lines: false;">
identity: int unsigned auto_increment
bigid: bigint unsigned auto_increment
</pre>
</td>
<td style="border:none;">Apache Derby typemaps<br />
<pre class="brush: plain; light: true; wrap-lines: false;">
identity: int generated by default as identity
bigid: long generated by default as identity
</pre></td>
</tr>
</table>
<p>Repeat the process for Apache Derby using &#8220;db2: typemap&#8221;.  Now that we&#8217;ve defined our custom identity typemap we can change the employee_id column from type &#8220;int&#8221; to type &#8220;identity&#8221;. We can also do the same for our department table. Now these columns will be auto incrementing columns and depending on which target database we select on output the correct SQL will be generated. Our diagram should now look like this:</p>
<p><img src="http://qnot.files.wordpress.com/2007/12/dia_employee3.jpg?w=700" alt="" title="dia_employee3"   class="aligncenter size-full wp-image-166" style="border:1px solid #ccc;" /></p>
<p>At this point we have created our database schema and defined a default list of departments to be inserted. We also created a typemap called &#8220;identity&#8221; which defines auto incrementing columns for both MySQL and Apache derby. Now lets generate the SQL files to create the database using tedia2sql. Before we run tedia2sql we need to apply a small patch to the tedia2sql script. This fixes a very small formatting issue in tedia2sql related to the typemaps we created. Edit the tedia2sql script (/usr/bin/tedia2sql) and comment out the line inside the parseTypeMap(..) subroutine that looks like this:</p>
<p><pre class="brush: perl; highlight: [3]; light: true;">
$defStr =~ s/s//g; # ignore spaces
     -- change to --
#   $defStr =~ s/s//g; # ignore spaces
</pre></p>
<p>or just apply the patch I created <a href="http://www.qnot.org/code/tedia2sql-typemap-1.2.12.patch">here</a> (works for version 1.2.12):</p>
<p><pre class="brush: plain; light: true;">
$ patch /usr/bin/tedia2sql &amp;lt; tedia2sql-typemap-1.2.12.patch
</pre></p>
<p>Now we can generate the SQL files for our target databases:<br />
<pre class="brush: plain; light: true;">
$ tedia2sql -i employee.dia -o employee-mysql.sql -t mysql -d
$ tedia2sql -i employee.dia -o employee-derby.sql -t db2 -d
</pre></p>
<p>This will generate two SQL files for building the database in both MySQL and Apache derby. If you view these files you can see how tedia2sql handled our typemaps for the auto incrementing columns in each target database:</p>
<p>MySQL<br />
<pre class="brush: sql;">
-- employee
create table employee (
  employee_id                int unsigned auto_increment not null,
  department_id             int not null,
  first_name                varchar(255) not null,
  last_name                 varchar(255),
  start_date                date,
  constraint pk_Employee primary key (employee_id)
) ;
</pre></p>
<p>Apache Derby<br />
<pre class="brush: sql;">
-- employee
create table employee (
  employee_id                int generated by default as identity  not null,
  department_id             int not null,
  first_name                varchar(255) not null,
  last_name                 varchar(255),
  start_date                date,
  constraint pk_Employee primary key (employee_id)
) ;
</pre></p>
<p>You can download the files generated as well as the employee.dia file I used in this tutorial here:</p>
<ul>
<li><a href="http://www.qnot.org/code/employee.dia">employee.dia</a></li>
<li><a href="http://www.qnot.org/code/employee-mysql.sql">employee-mysql.sql</a></li>
<li><a href="http://www.qnot.org/code/employee-derby.sql">employee-derby.sql</a></li>
</ul>
<p>You can test the SQL files generated by tedia2sql and create the employee database as follows:</p>
<p>MySQL<br />
<pre class="brush: plain; light: true;">
$ mysql -u user -p dbname &amp;lt; employee-mysql.sql
</pre></p>
<p>Apache Derby<br />
<pre class="brush: plain; light: true;">
$ java -cp derby.jar:derbytools.jar \
       -Dderby.system.home=/path/to/dbroot \
       -Dij.protocol=jdbc:derby: \
       -Dij.database='employee;create=true'
    org.apache.derby.tools.ij employee-derby.sql
</pre></p>
<p>A quick Makefile will help out a lot in testing out your database schema:</p>
<p><pre class="brush: plain; light: true;">
all:
      tedia2sql -i employee.dia -o employee-mysql.sql -t mysql -d
      tedia2sql -i employee.dia -o employee-derby.sql -t db2 -d
clean:
      rm -f *.sql
</pre></p>
<p>I&#8217;ve found that for small to moderate size projects creating database schemas in Dia and using tedia2sql for SQL generation to be a lifesaver. You can also make use of Dia&#8217;s export feature to export your database schema to a number of different formats such as jpg, png, eps, tiff, etc. I really only scratched the surface of what can be done using these great tools. tedia2sql has support for lots of cool features like indexes, foreign key constraints, views and much more. For more information check out <a href="http://tedia2sql.tigris.org/usingtedia2sql.html">using tedia2sql</a>  and <a href="http://dia-installer.de/doc/en/index.html">Dia&#8217;s manual</a>.</p>
<p>Happy <span style="font-weight:bold;">Dia</span>gramming!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/qnot.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/qnot.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnot.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnot.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnot.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnot.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnot.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnot.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnot.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnot.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnot.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnot.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnot.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnot.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnot.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnot.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=left.subtree.org&amp;blog=13566420&amp;post=14&amp;subd=qnot&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://left.subtree.org/2007/12/05/database-design-with-dia/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">sigma110</media:title>
		</media:content>

		<media:content url="http://qnot.files.wordpress.com/2007/12/dia_menu.jpg" medium="image">
			<media:title type="html">dia_menu</media:title>
		</media:content>

		<media:content url="http://qnot.files.wordpress.com/2007/12/dia_class.png" medium="image">
			<media:title type="html">dia_class</media:title>
		</media:content>

		<media:content url="http://qnot.files.wordpress.com/2007/12/dia_component.png" medium="image">
			<media:title type="html">dia_component</media:title>
		</media:content>

		<media:content url="http://qnot.files.wordpress.com/2007/12/dia_small_package.png" medium="image">
			<media:title type="html">dia_small_package</media:title>
		</media:content>

		<media:content url="http://qnot.files.wordpress.com/2007/12/dia_attributes.jpg" medium="image">
			<media:title type="html">dia_attributes</media:title>
		</media:content>

		<media:content url="http://qnot.files.wordpress.com/2007/12/dia_employee.jpg" medium="image">
			<media:title type="html">dia_employee</media:title>
		</media:content>

		<media:content url="http://qnot.files.wordpress.com/2007/12/dia_comp_prop.jpg" medium="image">
			<media:title type="html">dia_comp_prop</media:title>
		</media:content>

		<media:content url="http://qnot.files.wordpress.com/2007/12/dia_employee2.jpg" medium="image">
			<media:title type="html">dia_employee2</media:title>
		</media:content>

		<media:content url="http://qnot.files.wordpress.com/2007/12/dia_type_prop.jpg" medium="image">
			<media:title type="html">dia_type_prop</media:title>
		</media:content>

		<media:content url="http://qnot.files.wordpress.com/2007/12/dia_employee3.jpg" medium="image">
			<media:title type="html">dia_employee3</media:title>
		</media:content>
	</item>
		<item>
		<title>Customizing Pidgin Chat Windows</title>
		<link>http://left.subtree.org/2007/07/06/customizing-pidgin-chat-windows/</link>
		<comments>http://left.subtree.org/2007/07/06/customizing-pidgin-chat-windows/#comments</comments>
		<pubDate>Sat, 07 Jul 2007 05:53:55 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://left.subtree.org/2007/07/06/customizing-pidgin-chat-windows/</guid>
		<description><![CDATA[In my previous post I discussed customizing Gaim chat windows. Since then Gaim has formally changed it&#8217;s name to Pidgin due to legal issues with AOL. I finally upgraded to Pidgin and had to do a few minor tweaks to get the same chat window customizations as before. I updated ~/.purple/gtkrc-2.0 which previously resided in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=left.subtree.org&amp;blog=13566420&amp;post=19&amp;subd=qnot&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my <a href="/2007/01/14/customizing-gaim-chat-windows/">previous post</a> I discussed customizing Gaim chat windows. Since then Gaim has formally changed it&#8217;s name to <a href="http://pidgin.im/pidgin/home/">Pidgin</a> due to <a href="http://pidgin.im/~elb/cgi-bin/pyblosxom.cgi/going_public.html">legal issues with AOL</a>. I finally upgraded to Pidgin and had to do a few minor tweaks to get the same chat window customizations as before. I updated <code>~/.purple/gtkrc-2.0</code> which previously resided in <code>~/.gaim</code> and changed the widget names from <code>gaim_gtkconv_*</code> to <code>pidgin_conv_*</code>. Here&#8217;s my updated <code>~/.purple/gtkrc-2.0</code> file:</p>
<p><pre class="brush: plain;">
style &quot;pidgin-dark&quot; {
    base[NORMAL]=&quot;#000000&quot;
    text[NORMAL]=&quot;#00FF00&quot;
    GtkIMHtml::hyperlink-color=&quot;#007FFF&quot;
    GtkWidget::cursor-color=&quot;#60AFFE&quot;
    GtkWidget::secondary-cursor-color=&quot;#A4D3EE&quot;
}
widget &quot;*pidgin_conv_imhtml&quot; style &quot;pidgin-dark&quot;
widget &quot;*pidgin_conv_entry&quot; style &quot;pidgin-dark&quot;
</pre></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/qnot.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/qnot.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnot.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnot.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnot.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnot.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnot.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnot.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnot.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnot.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnot.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnot.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnot.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnot.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnot.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnot.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=left.subtree.org&amp;blog=13566420&amp;post=19&amp;subd=qnot&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://left.subtree.org/2007/07/06/customizing-pidgin-chat-windows/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">sigma110</media:title>
		</media:content>
	</item>
		<item>
		<title>phpLDAPadmin and Kerberos</title>
		<link>http://left.subtree.org/2007/06/26/phpldapadmin-and-kerberos/</link>
		<comments>http://left.subtree.org/2007/06/26/phpldapadmin-and-kerberos/#comments</comments>
		<pubDate>Wed, 27 Jun 2007 02:56:55 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://left.subtree.org/2007/06/26/phpldapadmin-and-kerberos/</guid>
		<description><![CDATA[I&#8217;ve been experimenting with phpLDAPadmin for browsing/searching LDAP directories over the web and found it to be a wonderful tool. I&#8217;m currently working with LDAP in a central authentication system together with Kerberos and wanted to have a nice web interface for managing user information within the LDAP directory. phpLDAPadmin provides a very nice interface [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=left.subtree.org&amp;blog=13566420&amp;post=16&amp;subd=qnot&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been experimenting with <a href="http://phpldapadmin.sourceforge.net/">phpLDAPadmin</a> for browsing/searching LDAP directories over the web and found it to be a wonderful tool. I&#8217;m currently working with LDAP in a central authentication system together with Kerberos and wanted to have a nice web interface for managing user information within the LDAP directory. phpLDAPadmin provides a very nice interface for browsing, searching, and updating entries which makes it a bit easier than working with the ldap* command line tools. Here&#8217;s my basic setup of phpLDAPadmin using Kerberos for authentication. This assumes you already have an LDAP/Kerberos setup working and are using Apache as your web server.</p>
<p>First step is to make sure you have <a href="http://en.wikipedia.org/wiki/Simple_Authentication_and_Security_Layer">SASL</a> support compiled into the LDAP PHP extension <code>--with-ldap-sasl</code>. Check out phpinfo() and make sure you see <code>SASL Support   Enabled</code> under the LDAP extension. If not re-compile PHP.<br />
<span id="more-16"></span><br />
Grab a copy of phpLDAPadmin <a href="http://phpldapadmin.sourceforge.net/download.php">here</a> and untar into a directory of your choice (/usr/local). Copy the config.php.example to config.php:</p>
<p><pre class="brush: plain; light: true;">
$ tar -xvxf phpldapadmin-x.x.x.tar.gz
$ ln -s phpldapadmin-x.x.x phpldapadmin
$ cd phpldapadmin
$ cp config/config.php.example config/config.php
</pre></p>
<p>Edit config/config.php. A few options to define are as follows:</p>
<p><pre class="brush: php;">
$ldapservers-&gt;SetValue($i,'server','name','My LDAP Server');
$ldapservers-&gt;SetValue($i,'server','host','ldap.host.com');
$ldapservers-&gt;SetValue($i,'server','port','389');
$ldapservers-&gt;SetValue($i,'server','auth_type','config');
$ldapservers-&gt;SetValue($i,'login','dn','');
$ldapservers-&gt;SetValue($i,'login','pass','');
$ldapservers-&gt;SetValue($i,'server','tls',false);
$ldapservers-&gt;SetValue($i,'server','sasl_auth',true);
$ldapservers-&gt;SetValue($i,'server','sasl_mech','GSSAPI');
$ldapservers-&gt;SetValue($i,'server','sasl_authz_id_regex','/^uid=([^,]+)(.+)/i');
$ldapservers-&gt;SetValue($i,'server','sasl_authz_id_replacement','$1');
$ldapservers-&gt;SetValue($i,'login','anon_bind',false); 
</pre></p>
<p>Basically, we&#8217;re configuring phpLDAPadmin with <code>auth_type = config</code> which means that the user/pass used to bind to the LDAP server is hard coded in the config.php file. We leave the user/pass blank because each user will first be authenticating through Kerberos and using their tickets to bind to the LDAP server. Internally phpLDAPadmin calls the <code><a href="http://us.php.net/manual/en/function.ldap-sasl-bind.php">ldap_sasl_bind(..)</a></code> function with an <code>auth_mech of <a href="http://en.wikipedia.org/wiki/Generic_Security_Services_Application_Program_Interface">GSSAPI</a></code> which does the work of binding using Kerberos tickets.</p>
<p>Next, we&#8217;ll configure apache to point to the location where we installed phpLDAPadmin. Edit your httpd.conf file or equivalent. If your running redhat usually create a file in /etc/httpd/conf.d or on Debian /etc/apache2/site-available/. You will probably want to add this to an SSL vhost to ensure your username/passwords are transmitted over a secure connection.</p>
<p><pre class="brush: plain;">
Alias /ldapadmin /usr/local/phpldapadmin/htdocs/
&lt;Location /ldapadmin&gt;
    AuthType Kerberos
    AuthName &quot;LDAP Admin&quot;
    KrbAuthRealms kerb.yourhost.com
    KrbVerifyKDC off
    KrbServiceName HTTP
    Krb5KeyTab /path/to/your/httpd.keytab
    KrbSaveCredentials on
    require valid-user
&lt;/Location&gt;
</pre></p>
<p>In order to authenticate users against Kerberos and obtain the necessary Kerberos tickets we use the apache module <a href="http://modauthkerb.sourceforge.net/">mod_auth_kerb</a>. The apache config above defines our location for phpLDAPadmin and adds in the necessary config for mod_auth_kerb. More info can be found <a href="http://modauthkerb.sourceforge.net/configure.html">here</a>. Make sure to add in the <code>KrbSaveCredentails on</code> directive so that mod_auth_kerb will save the Kerberos tickets for use throughout the request.</p>
<p>Next we need to expose the location of the Kerberos tickets to phpLDAPadmin. mod_auth_kerb sets an environment variable <code>KRB5CCNAME</code> to the location of the credential cache. To expose this environment variable to the phpLDAPadmin code edit the file <code>[phpLDAPadmin_install]/lib/common.php</code> and add this line to the very top:</p>
<p><pre class="brush: php; light: true;">
putenv(&quot;KRB5CCNAME={$_SERVER['KRB5CCNAME']}&quot;); 
</pre></p>
<p>That should do it. Now when you access http://yourserver.com/ldapadmin you should be challenged with HTTP basic auth, which authenticates against Kerberos and uses the Kerberos credentials to bind to your LDAP server. There might be an easier way to go about doing this but I wasn&#8217;t able to turn much up on google so I thought I&#8217;d share one way I was able to get things working.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/qnot.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/qnot.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/qnot.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/qnot.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/qnot.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/qnot.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/qnot.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/qnot.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/qnot.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/qnot.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/qnot.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/qnot.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/qnot.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/qnot.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/qnot.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/qnot.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=left.subtree.org&amp;blog=13566420&amp;post=16&amp;subd=qnot&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://left.subtree.org/2007/06/26/phpldapadmin-and-kerberos/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">sigma110</media:title>
		</media:content>
	</item>
	</channel>
</rss>
