<?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>UnixGarage: Chronically attached to the CLI</title>
	<atom:link href="http://www.unixgarage.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.unixgarage.com/blog</link>
	<description>Unix Linux and Open source technologies</description>
	<lastBuildDate>Sat, 30 Apr 2011 22:31:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Software Freedom Day Presentations</title>
		<link>http://www.unixgarage.com/blog/2009/09/software-freedom-day-presentations/</link>
		<comments>http://www.unixgarage.com/blog/2009/09/software-freedom-day-presentations/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 20:35:08 +0000</pubDate>
		<dc:creator>mechanic</dc:creator>
				<category><![CDATA[Presentations]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Presentation]]></category>

		<guid isPermaLink="false">http://www.unixgarage.com/blog/?p=6</guid>
		<description><![CDATA[I was fortunate enough to give a presentation at software freedom day in Alexandria university. The audience were attentive and I had a great time.Â The main presentation was about using open source software to build secure infrastructure. I also got to spend some time demonstrating a simple PF policy on OpenBSD. The slides can be [...]]]></description>
			<content:encoded><![CDATA[<p>I was fortunate enough to give a presentation at software freedom day in Alexandria university. The audience were attentive and I had a great time.Â The main presentation was about using open source software to build secure infrastructure. I also got to spend some time demonstrating a simple PF policy on OpenBSD. The slides can be found <a title="OpenlySecure_Presentation" href="http://www.unixgarage.com/openlysecure.pdf" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.unixgarage.com/blog/2009/09/software-freedom-day-presentations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a Toolshed::Network</title>
		<link>http://www.unixgarage.com/blog/2008/07/the-network-monitoring-analysis-and-manipulation-toolshed/</link>
		<comments>http://www.unixgarage.com/blog/2008/07/the-network-monitoring-analysis-and-manipulation-toolshed/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 06:19:41 +0000</pubDate>
		<dc:creator>mechanic</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.unixgarage.com/blog/?p=5</guid>
		<description><![CDATA[I am making a list of apps and tools that I have come to rely on. As I discover new cool and reliable tools, they will be added to this repository. Network related hardware : Soekris: If you are dealing with lightweight traffic, this would be the first place to look. Interface masters : They [...]]]></description>
			<content:encoded><![CDATA[<p>I am making a list of apps and tools that I have come to rely on. As I discover new cool and reliable tools, they will be added to this repository.</p>
<p><strong>Network related hardware :</strong></p>
<p><a title="Sokeris" href="http://www.soekris.com">Soekris</a>: If you are dealing with lightweight traffic, this would be the first place to look.<br />
<a title="Interface Masters" href="http://www.interfacemasters.com">Interface masters</a> : They sell quad ports gigabit nics and bypass devices. They are open source friendly and overall awesome people to deal with.</p>
<p><strong>For software tools :</strong></p>
<ul>
<li><a title="Snort" href="http://www.snort.org" target="_blank"><strong>Snort</strong></a></li>
<li><strong><a title="Tomahawk" href="http://tomahawk.sourceforge.net/">Tomahawk</a></strong></li>
<li><strong><a title="Fragroute" href="http://monkey.org/~dugsong/fragroute/">Fragroute</a></strong></li>
<li><a title="Scapy" href="http://www.secdev.org/projects/scapy" target="_blank"><strong>Scapy</strong></a></li>
<li><a title="Scruby" href="http://sylv1.tuxfamily.org/projects/scruby.html" target="_blank"><strong>Scruby</strong></a></li>
<li><a title="LibNids" href="http://libnids.sourceforge.net/" target="_blank"><strong>Libnids</strong></a></li>
<li><strong><a title="Nmap" href="http://www.nmap.org">Nmap</a></strong></li>
<li><strong>mcollective<br />
</strong></li>
</ul>
<p>To be continued&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unixgarage.com/blog/2008/07/the-network-monitoring-analysis-and-manipulation-toolshed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple content management with eRuby and Apache</title>
		<link>http://www.unixgarage.com/blog/2008/03/simple-content-management-with-embedded-rubyapache-eruby/</link>
		<comments>http://www.unixgarage.com/blog/2008/03/simple-content-management-with-embedded-rubyapache-eruby/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 15:56:18 +0000</pubDate>
		<dc:creator>mechanic</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.unixgarage.com/blog/?p=4</guid>
		<description><![CDATA[Content management can mean different things to different people.I wanted to add some level of dynamic content management to the site but I did not want to deploy n-tier complex applications. My requirements are simple: Light weight: I don&#8217;t need some heavy java based solution Portable: I typically use 4-5 different operating systems throughout the [...]]]></description>
			<content:encoded><![CDATA[<p>Content management can mean different things to different people.I wanted to add some level of dynamic content management to the site but I did not want to deploy n-tier complex applications. My requirements are simple:</p>
<ul>
<li><font color="#00ff00"><strong>Light weight</strong></font>: I don&#8217;t need some heavy java based solution</li>
<li><font color="#00ff00"><strong>Portable</strong></font>: I typically use 4-5 different operating systems throughout the day. I don&#8217;t need something that will only work with certain browsers/operating systems. I also didn&#8217;t want any new markup(think wiki markup) or tagging. html/plain-text is good enough for me</li>
<li><font color="#00ff00"><strong>Accessible</strong></font>: I know MVCs are taking over the world and perhaps it makes sense to store text in database tables in some cases but for my purposes I have a strong preference to store text content in &#8220;surprise surprise&#8221; text files so I can grep, diff or version control it when I want to</li>
</ul>
<p>The design I had in mind was something where I could look into a location on the file system and list directories embedding them into html to generate a dynamic navigation menu.For the body of the pages, I wanted to be able to write the stories in html and have a script find them and embed them in the generated page.</p>
<p>Enter eruby! short for embedded ruby, itÂ  is one of several ways to write cgi scripts in ruby.With eruby you can embed ruby code in html files. I wanted to use ruby because it is dynamic and flexible but the task could have been accomplished with any of the Ps(Perl, Python or PHP).</p>
<p>I won&#8217;t go into details of setting up eruby,Hiveminds magazine has a pretty good introduction online, but as a quick reference you will need to tell apache about the new type of file. Usually you will save your ruby files in rhtml so you will want a directive like this in apache&#8217;s config file:</p>
<p>&#8220;<em><font color="#0000ff">AddType ruby .rhtml .rb</font></em>&#8221;</p>
<p>You will also want to tell apache which interpreter to use to execute your rhtml file, something like this should work:</p>
<p>&#8220;<font color="#0000ff">Action ruby /virtual-cgi/eruby</font>&#8221;</p>
<p>It was more difficult to find examples that go beyond &#8220;3.times do&#8221; so I thought I would share the story with whatever little code I have and hopefully it will be useful to someone.</p>
<p><strong>Code storage:<br />
</strong></p>
<p>When apache invokes your script, your cwd(current working directory) will be the real filesystem path where you specified the ruby handler. For example if  you configured apache like this:</p>
<p><font color="#0000ff">Action ruby /virtual-cgi/eruby</font></p>
<p>and virtual-cgi is configured like this:</p>
<p><font color="#0000f0"><em>ScriptAlias /virtual-cgi /jail/usr/local/cgi-handlers</em></font></p>
<p>Then your current working directory is going to be &#8220;/jail/usr/local/cgi-handlers&#8221;.By default you will only be able to load modules from directories if they are in your $LOAD_PATH or in your CWD.$LOAD_PATH is an array and you could add to it by a simple &#8216;<font color="#0000ff">$LOAD_PATH.push(&#8220;/path/to/directory&#8221;)&#8217;</font><br />
I created a unixgarage directory somewhere in my site_ruby tree.For now all the common code should go to a file helpers.rhtml in that directory till I find it compelling to make things more OO.</p>
<p>So first thing was to create the dynamic navigation menu and it was pretty easy, here is the code slightly edited for file/directory names:</p>
<blockquote><p><font color="#ffff00">      1 $rootdir = &#8220;/path/to/docroot/&#8221;</font></p>
<p><font color="#ffff00">      2 $forbidden =["secret","private","valuable"]</font></p>
<p><font color="#ffff00">      3 def listdirs<br />
4   puts &#8220;&lt;ul&gt;&#8221;<br />
5   Dir.foreach(&#8220;#{$rootdir}&#8221;)  do | fsentry |<br />
6     next if fsentry.length &lt; 3<br />
7     next if $forbidden.index(&#8220;#{fsentry}&#8221;)<br />
8     if File.directory?(&#8220;#{$rootdir}/#{fsentry}&#8221;)<br />
9       puts &#8220;&lt;li&gt;&lt;a href=\&#8221;/#{fsentry}\&#8221;&gt;#{fsentry}&lt;/a&gt;&lt;/li&gt;&#8221;<br />
10     end<br />
11   end<br />
12   puts &#8220;&lt;/ul&gt;&#8221;<br />
13 end</font></p></blockquote>
<p>Pretty simple: the method iterates over the contents of the global variable $rootdir .An array of directories that should not be listed is defined in the global variable $forbidden. We use ruby&#8217;s Dir class to loop over each entry in the directory, skipping any entries that exist in the forbidden array. The items we find are then printed as a list item.</p>
<p>Now on to reading and embedding contents from a file. For now, I use a hard coded file name to look for, &#8220;main.txt&#8221; but in the future I might make it more dynamic to use a config file of sorts. Here is the code:</p>
<blockquote><p><font color="#ff9900"><font color="#ffff00">     15 def mainbody(path)<br />
16   fullpath = $rootdir + path<br />
17   if File.exists?(&#8220;#{fullpath}main.txt&#8221;)<br />
18     puts IO.readlines(&#8220;#{fullpath}main.txt&#8221;)<br />
19   else<br />
20   puts &#8220;Coming soon&#8221;<br />
21     puts &#8220;&lt;br&gt;&#8221;<br />
22   end<br />
23 end</font><br />
</font></p></blockquote>
<p>The code checks to see if a file called &#8220;main.txt&#8221; exists in the directory we are generating content for. If the file exists it will read the contents and embed them. If the file doesn&#8217;t exist we print a &#8220;Coming soon&#8221; message.</p>
<p>But how do we know which directory are we in?That will be defined in the ENV hash apache passes to the calling script as the value of the key &#8216;<font color="#0000ff">REQUEST_URI</font>&#8216;. To access the key, use ENV["REQUEST_URI"]. To construct the full file system path, we add that value to the value of <font color="#0000ff">$rootdir</font>.</p>
<p>How about dynamically creating a list of links that represent the content of the directory?That too is very easy:</p>
<p><font color="#ffff00">25 def listDirContent(path)</font><br />
<font color="#ffff00">              26   fullpath = $rootdir + path<br />
27   Dir.foreach(&#8220;#{fullpath}&#8221;) do | dEntry |<br />
28     (fName, fExt) = dEntry.split(&#8220;.&#8221;)<br />
29     next if dEntry.length &lt; 3<br />
30     next if $forbidden.index(&#8220;#{dEntry}&#8221;)<br />
31     if File.file?(&#8220;#{fullpath}/#{dEntry}&#8221;)<br />
32       puts &#8220;&lt;li&gt;&lt;a href=\&#8221;#{path}#{dEntry}\&#8221;&gt;#{fName}&lt;/a&gt;&lt;/li&gt;&#8221;<br />
33     end<br />
34   end<br />
35 end</font><br />
Now what we need to do is write index.rhtml, or any other file that you tell apache is an index and load our helpers.rhtml:</p>
<p><font color="#99cc00">&lt;% load &#8216;unixgarage/helpers.rhtml&#8217;  %&gt;</font></p>
<p>you go on to write all the html you want to write and to call either of the functions created you simply do &lt;% functionname(arguments) %&gt;</p>
<p>so for the navigation menu, I have a line in index.rhtml that reads:</p>
<p><font color="#ff9900">&lt;% listdirs %&gt;</font></p>
<p>and for embedding the contents of main:</p>
<p><font color="#ff9900">&lt;%  mainbody(&#8220;#{ENV["REQUEST_URI"]}&#8221;)</font></p>
<p>To dynamically display links to the contents of the directory:</p>
<p>&lt;% listDirContent(&#8220;#ENV["REQUEST_URI"])</p>
<p>If you run into trouble, you can use eruby to execute your script to see where things are going wrong. To see it in action visit our <a href="http://www.unixgarage.com/ruby">ruby</a> section.</p>
<p>Comments and suggestions welcome</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unixgarage.com/blog/2008/03/simple-content-management-with-embedded-rubyapache-eruby/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

