<?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>Red Green Software &#187; Programming</title>
	<atom:link href="http://www.red-green.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.red-green.com</link>
	<description>We take stopped projects and get them going again.</description>
	<lastBuildDate>Sun, 05 Sep 2010 15:27:00 +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>Walking the perlmonk walk</title>
		<link>http://www.red-green.com/2010/02/walking-the-perlmonk-walk/</link>
		<comments>http://www.red-green.com/2010/02/walking-the-perlmonk-walk/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 08:03:22 +0000</pubDate>
		<dc:creator>stevet</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.red-green.com/?p=179</guid>
		<description><![CDATA[Having been an avid perl user for quite some time now, I understand a lot more about why perl people hate RHEL, RedHat Enterprise Linux (as well as CentOS), and why some people hate perl.&#160; RedHat has a bad, but well earned reputation for breaking perl.&#160; They like to upgrade perl versions, and include some [...]]]></description>
			<content:encoded><![CDATA[<p>Having been an avid perl user for quite some time now, I understand a lot more about why perl people hate RHEL, RedHat Enterprise Linux (as well as CentOS), and why some people hate perl.&nbsp; RedHat has a bad, but well earned reputation for breaking perl.&nbsp; They like to upgrade perl versions, and include some older perl modules, and other things that just break perl badly.&nbsp; So what does a perl loving <a href="http://perlmonks.org" target="_blank">perlmonk</a> do?</p>
<p>Well, you could whine about RHEL in #perl on the freenode servers.&nbsp; But whining isn&#39;t productive or helpful, it just annoys people that need to get things done, and doesn&#39;t help anyone get the most out of their perl experience.</p>
<p>So what do you do?&nbsp; Do what most power perl programmers do &#8212; Build your own perl.&nbsp; That is probably the best kept secret in the perl developer community, unfortunately!</p>
<p>When you do that, you can safely ignore the perl your Linux distribution includes.&nbsp; You can keep your Linux distribution updated, and you won&#39;t have to worry about breaking your production perl programs.&nbsp; And, when there is a new version of perl, you can build it, and safely test your code with the new version!</p>
<h2>Building perl</h2>
<p>First, download the <a href="http://www.perl.org/" target="_blank">perl source</a>.&nbsp; You will end up with the file latest.tar.bz2.&nbsp;</p>
<p>Extract with <code>tar -xjf latest.tar.bz2</code> then change into the source directory.&nbsp; Today, that is perl-5.10.1.</p>
<p>Now comes the questions:&nbsp; Do you want 64 bit integer support?&nbsp; Do you want threads, or do you want your perl to run faster?&nbsp; There is some overhead in making variables thread-safe.&nbsp; Some of these options are discussed at <a href="http://www.ccl4.org/~nick/P/Fast_Enough/" target="_blank">&quot;When perl is not fast enough&quot;</a>.</p>
<p>Here are the defaults that were recommended to me by Khisanth in #perl:</p>
<p><tt>sh Configure -Dprefix=$HOMEperl5100 -Duseshrplib -Dusemultiplicity -Duse64bitint -Duseperlio -Duselargefiles -des<br />
	</tt></p>
<p>Ok, that&#39;s not what I use.&nbsp; I don&#39;t need a shared perl library file (which run slower), because I won&#39;t be embedding perl anywhere.&nbsp; I haven&#39;t found anything on usemultiplicity, so I don&#39;t use that either.&nbsp; But, everything else is good.&nbsp; This is what I have been using:</p>
<p><tt>sh Configure -Dprefix=/opt/perl510 -Duse64bitint -Duseperlio -Duselargefiles -des<br />
	</tt></p>
<p>Note:&nbsp; Using $HOME doesn&#39;t actually work, I think he meant not for the shell to replace $HOME with your home directory, but rather it to be replaced by the person typing.&nbsp; Also, I am using the /opt directory, because I want my built perl to be used system-wide.&nbsp; For local use, or testing, -Dprefix=/home/stevet/perl510 is what I use.</p>
<p>Next, comes the build process: <tt>make&nbsp; </tt>Then, comes the test process: <tt>make test&nbsp; </tt>If everything passes: <tt>make install</tt></p>
<p>Congratulations, in your prefix directory, you now have a bin directory that contains: perl, perldoc, and cpan.&nbsp; Try it out, /opt/perl510/bin/perl -v should display the version information:</p>
<p><tt>This is perl, v5.10.1 (*) built for i686-linux-64int<br />
	</tt></p>
<h2>Testing new versions of perl</h2>
<p>To test new versions of perl, use the above directions, or run perl -V on your current production perl.&nbsp; (This will show what build options you used.)&nbsp; Grab the source to the new version of perl, and do everything the same except the -Dprefix.&nbsp; Install the new perl into another directory.&nbsp; Then, use the new perl with your code.&nbsp; If it works, wonderful!&nbsp; If not, continue to use the original perl binary until you get the new version worked out.</p>
<p>Most of the time, it is simply a matter of installing needed modules into the new version.&nbsp; Make sure you run the new perl&#39;s cpan!</p>
<h2>When cpan goes bad</h2>
<p>This is why I am writing this.&nbsp; Things went horribly wrong when I tried this.&nbsp; Strange failures installing XML::Parser, and then again installing MIME::Entities.&nbsp; Consult <a href="http://en.wikipedia.org/wiki/The_Hitchhiker%27s_Guide_to_the_Galaxy">the guide and don&#39;t panic</a>.</p>
<p>First, make sure that you have read the <a href="http://sial.org/howto/perl/life-with-cpan/">&quot;Life with CPAN&quot;</a> guide.&nbsp; Some of the things it talks about applies to having your own perl build.&nbsp; But that only gets you so far.&nbsp; Debugging cpan install failures is quite a challenge sometimes.&nbsp; But, it does get easier with time and practice.&nbsp; So let&#39;s get started with some CPAN debug tips, and then I&#39;ll finish up with my personal experiences with XML::Parser and MIME::Entities.</p>
<h2>Debugging CPAN installs</h2>
<p>Ok, you are at the cpan prompt, you type in: <tt>install DBD::mysql</tt> and suddenly pages of errors go flying by.&nbsp; Now what?&nbsp; Start with the <u>very first line</u> that gives an error.&nbsp; But that was many screens ago, how do you find that?&nbsp; Use the *nix tools available for just such things:&nbsp; <tt>screen</tt> or <tt>script</tt>.&nbsp; In screen, type ctrl-a and H.&nbsp; That turns on screen logging, and you&#39;ll see it starts logging everything to a file called screenlog.0.&nbsp; With script, you would type something like: <tt>script -c cpan</tt> and the output will be in a file called typescript.</p>
<p>Ok, so the first line that gives an error.&nbsp; What type of error is it?&nbsp; Does it look something like this:</p>
<p><tt>In file included from dbdimp.c:20:<br />
	dbdimp.h:22:49: error: mysql.h: No such file or directory<br />
	dbdimp.h:23:45: error: mysqld_error.h: No such file or directory<br />
	dbdimp.h:24:49: error: errmsg.h: No such file or directory</tt></p>
<p><tt>This is from the c compiler (in this case gcc).&nbsp; It is saying that it needs some header files.</tt></p>
<h2>Missing header files</h2>
<p>This means that you don&#39;t have the development version of the program or library installed on your system.&nbsp; Using your Linux distribution tools, install the development version.&nbsp;</p>
<p>In the above case of mysql, it would be something like this for RHEL/CentOS: <tt>yum install mysql-devel</tt>.</p>
<h2>Missing modules</h2>
<p>When cpan goes to make test, does it error out with: <tt>Can&#39;t locate Test/Pod.pm in @INC (@INC contains: ...)</tt>.&nbsp; Ok, this is probably a minor bug in the module.&nbsp; The module is supposed to list all of the modules that it has dependencies on, but maybe the author forgot one.&nbsp; At the cpan prompt try: <tt>install Test::Pod</tt>, or whatever the module name was that it couldn&#39;t find.&nbsp; If the missing module installs, retry installing the module that was giving you problems.&nbsp; Odds are good that it will work fine now.</p>
<h2>Failing tests, or what to try next</h2>
<p>Probably the best part of perl, and of cpan, is the testing modules.&nbsp; These allow the developer to design tests to exercise their code, and the libraries they depend upon to make sure that they function correctly.&nbsp; But, what when those tests fail?</p>
<p>First stop is <a href="http://search.cpan.org">search.cpan.org</a>.&nbsp; Search for the module that you are having problems with.&nbsp; Select the link to the module, and then on the right hand side click, <u>View bug reports</u>.&nbsp; Look through the reports.&nbsp; Are other people having the same error that you are?&nbsp; Or, even better, are there patches available that fix the problem?</p>
<p>If you don&#39;t see your particular error listed, you might want to report it to the developer.&nbsp; Or, even better, figure out what caused the error and report that!&nbsp; Writing code that works well on many platforms is hard, and the developer might not have access to a machine like what you are using.</p>
<p>As a last resort you can also go to <a href="http://www.cpantesters.org">http://www.cpantesters.org</a> and search for the troublesome module there.&nbsp; While you won&#39;t find any answers there, you will see if anyone else is having problems installing the module, and what error messages they are getting.&nbsp; Here are cpan testers&#39; <a href="http://www.cpantesters.org/distro/X/XML-Parser.html">results of installing XML::Parser</a> for example.</p>
<h2>Google the error message</h2>
<p>Just use google on error messages.&nbsp; Don&#39;t use google when working with normal perl, because there is a lot of old perl code out there on the Internet.&nbsp; There are still tutorials, which, when they were written 10 years ago were cutting edge.&nbsp; But now, they show you the wrong way to write modern perl code.&nbsp; If you want modern perl help use <a href="http://perlmonks.org">perlmonks</a>.</p>
<p>Ok, so maybe you have found something, like what I found on my failed test installing XML::Parser.</p>
<h2>XML::Parser</h2>
<p>First, I got:</p>
<pre><tt>Expat.xs:12:19: error: expat.h: No such file or directory</tt></pre>
<p>Ok, so install the expat-devel, using yum and you&#39;re set, right?&nbsp; No, this one gets much worse.&nbsp; The module builds, but now it fails tests.&nbsp; Searching around, I find out that debian is aware of this bug, thanks to failing perl tests.&nbsp; What happened was a bug was found in the expat library that caused a security issue.&nbsp; The library was quickly patched, however, the patch actually broke the expat library.&nbsp; It wasn&#39;t detected by the expat developers, but it was detected by XML::Parser.&nbsp;</p>
<p>Remember those module tests that are so great?&nbsp; Yes, they are great at finding problems, but sometimes it is slow getting the fixes.&nbsp; And RHEL, well, they have the broken security patch for expat.&nbsp; They haven&#39;t gotten the latest correct patch into their system.&nbsp; So, just like building your own perl, now you build your own expat.</p>
<p>Downloaded the expat 2.0.1 library from <a href="http://expat.sourceforge.net/">http://expat.sourceforge.net/</a> and installed it into /opt/expat.&nbsp; Finally, a working, bug free, xml parsing library is installed.</p>
<p>Configuring XML::Parser to use the working expat library was a challenge, but by doing <tt>look XML::Parser</tt> in cpan, I was able to build using:</p>
<p><tt>perl Makefile.PL EXPATLIBPATH=/opt/expat/lib EXPATINCPATH=/opt/expat/include</tt></p>
<p>Then make (which compiles the module), make test (which now passed for me), and finally make install.</p>
<h2>MIME::Entity</h2>
<p>This on fails like this:</p>
<p><tt>t/Smtpsend.t ......... accept failed: Connection timed out at t/Smtpsend.t line 46.<br />
	# Looks like your test exited with 110 before it could output anything.<br />
	</tt></p>
<p>If you are seeing this error, I would almost bet that you are using a dual-core or have multiple processors!&nbsp; The bug is in the test script itself.&nbsp; Use <tt>look MIME::Entity</tt> at the cpan prompt to get into the build directory.&nbsp; Edit the t/Smtpsend.t with your favorite editor, and jump to line 41.&nbsp; You should be right before the following lines:</p>
<p><tt># In the parent<br />
	my $s = $sock-&gt;accept();</tt></p>
<p>Above these lines add: <tt>sleep 1</tt></p>
<p>Ok, type: <tt>make test</tt> and it should pass just fine.&nbsp; What I think happens is when the test script forks on a dual core system, the connection is accepted before the connection happens, so it fails.&nbsp; But, with a 1 second sleep, the accept works correctly, and the test now passes.</p>
<h2>Crypt::SSLeay</h2>
<p>This fails on:</p>
<p><tt>t/01-connect.t .. 1/8<br />
	#&nbsp;&nbsp; Failed test &#39;Net::SSL-&gt;new&#39;<br />
	#&nbsp;&nbsp; at t/01-connect.t line 25.<br />
	# SSL negotiation failed:&nbsp; at t/01-connect.t line 11<br />
	#&nbsp; at t/01-connect.t line 11<br />
	# ; Interrupted system call at t/01-connect.t line 11<br />
	# ; Interrupted system call at t/01-connect.t line 11<br />
	# ; Interrupted system call at t/01-connect.t line 11<br />
	# Looks like you failed 1 test of 8.<br />
	t/01-connect.t .. Dubious, test returned 1 (wstat 256, 0x100)<br />
	Failed 1/8 subtests<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (less 7 skipped subtests: 0 okay)</tt></p>
<p>Again, the problem is with the test.&nbsp; If you failed this test, it means you are installing this on a server that has https running on port 443.&nbsp; Edit the t/01-connect.t script, and search for the two occurrences of 443 that look like:</p>
<p><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PeerPort =&gt; 443,</tt></p>
<p>and</p>
<p><tt>skip( &quot;nothing listening on localhost:443&quot;, 7 )</p>
<p>	</tt></p>
<p>Change them to some other port that isn&#39;t in use, like 4443.&nbsp; Re-run make test.&nbsp; If passing, now make install.</p>
<h2>Wouldn&#39;t it be easier to just force the install?</h2>
<p>No.&nbsp; Forcing the install of perl modules that fail their tests is just asking for trouble.&nbsp; Find out why it is failing.&nbsp; If the test is bad, fix the test.&nbsp; In the case of the expat bug, you would be opening your system up to exploits from malformed XML.&nbsp; Really, don&#39;t force installs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-green.com/2010/02/walking-the-perlmonk-walk/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hacking Web Applications Exposed</title>
		<link>http://www.red-green.com/2009/11/hacking-web-applications-exposed/</link>
		<comments>http://www.red-green.com/2009/11/hacking-web-applications-exposed/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 05:15:43 +0000</pubDate>
		<dc:creator>stevet</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.red-green.com/?p=171</guid>
		<description><![CDATA[Reading, "Hacking Web Applications Exposed", I've learned a lot so far.]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>It is always nice when I get a chance to sit down and read a book I bought over year ago.&nbsp; Finally!&nbsp; I&#8217;ve been enjoying the book, and what I&#8217;ve enjoyed so far is the evolutionary process between attacks and web servers.</p>
<p>For example, Microsoft IIS was exploitable with long URLs.&nbsp; Microsoft fixes that, but attackers learn that they can just keep running the attacks anyway, and eventually the server dies anyway when it runs out of disk space from logging all those long URLs.&nbsp; Microsoft fixes that by reducing the length of information stored in the logs.&nbsp; Attackers still continue to use long URLs, because their complete attempts won&#8217;t be logged.&nbsp; You&#8217;ll know someone tried something with IIS, but you won&#8217;t know exactly what.&nbsp; It is an interesting technology arms race.</p>
<p>The other thing that I&#8217;ve enjoyed so far about the book is the real stories about how systems have been audited, and how they find silly security flaws in the system.&nbsp; Example:&nbsp; Being able to view, edit, or become other accounts in the web application.</p>
<p><a href="http://www.owasp.org/index.php/Category:OWASP_WebScarab_Project" target="_blank">WebScarab</a> is quite a useful tool to see what is going on between web browser and server.&nbsp; And the ability to save all of the complete conversations within a browsing session is fantastic.&nbsp; It is certainly going to be useful when I have to interface into websites that insist on using javascript for authentication and browsing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-green.com/2009/11/hacking-web-applications-exposed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Injection</title>
		<link>http://www.red-green.com/2008/12/sql-injection/</link>
		<comments>http://www.red-green.com/2008/12/sql-injection/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 05:40:28 +0000</pubDate>
		<dc:creator>stevet</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.red-green.com/?p=123</guid>
		<description><![CDATA[While reading the SANS Internet Storm Center&#8217;s RSS feed, I found an interesting article on SQL Injections. http://isc.sans.org/diary.html?storyid=5416 The intriguing part was doing injections without the use of quote or semicolons.&#160; Which allowed me to do some injections of my own on a production server! It really is very important to treat any data coming [...]]]></description>
			<content:encoded><![CDATA[<p>While reading the SANS Internet Storm Center&#8217;s RSS feed, I found an interesting article on SQL Injections.  <a target="_blank" href="http://isc.sans.org/diary.html?storyid=5416">http://isc.sans.org/diary.html?storyid=5416</a></p>
<p>The intriguing part was doing injections without the use of quote or semicolons.&nbsp; Which allowed me to do some injections of my own on a production server!</p>
<p>It really is very important to treat any data coming from the Internet as &#8216;tainted&#8217;, and sanitize it.&nbsp; If you think it can&#8217;t be &#8216;tainted&#8217;, <a target="_blank" href="http://www.opera.com/download/">download a copy of Opera</a>.&nbsp; Visit the web page with Opera.&nbsp; Use View Source, and edit away!&nbsp; Change all the default values you expect to unsafe data.&nbsp; Click the Apply Changes button.&nbsp; Use your altered form to inject with.</p>
<p>Notes from my experience:</p>
<ol>
<li>Remove debugging messages that show the final SQL statement.&nbsp; Showing the statement allows the attacker to see what they need to change in their input to cause the SQL to behave badly.&nbsp; Note:&nbsp; Showing &quot;SQL error&quot; is just as bad!&nbsp; Better to say, &quot;No records found&quot;.</li>
<li>Log SQL errors.&nbsp; Any form input in production should never generate a SQL error.</li>
<li>Test, test, and retest.&nbsp; Once you know what to look for, share what you have found with the rest of your development team.&nbsp; Security is paramount in this day and age.</li>
<li>Code review.&nbsp; Look for code that doesn&#8217;t sanitize input.</li>
<li>Add these checks into your routine testing process.</li>
<li>Try not to laugh when using PHP and security in the same sentence.&nbsp; It can be done, really!&nbsp; And secure PHP code can be written, really!</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.red-green.com/2008/12/sql-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Six Stages of Debugging</title>
		<link>http://www.red-green.com/2008/01/the-six-stages-of-debugging/</link>
		<comments>http://www.red-green.com/2008/01/the-six-stages-of-debugging/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 20:42:02 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Humor]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.red-green.com/2008/01/the-six-stages-of-debugging/</guid>
		<description><![CDATA[That can&#39;t happen. That doesn&#39;t happen on my machine. That shouldn&#39;t happen. Why is that happening? Oh, I see. How did that ever work?]]></description>
			<content:encoded><![CDATA[<ol>
<li>That can&#39;t happen.</li>
<li>That doesn&#39;t happen on my machine.</li>
<li>That shouldn&#39;t happen.</li>
<li>Why is that happening?</li>
<li>Oh, I see.</li>
<li>How did that ever work?</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.red-green.com/2008/01/the-six-stages-of-debugging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Logfile</title>
		<link>http://www.red-green.com/2007/12/perl-logfile/</link>
		<comments>http://www.red-green.com/2007/12/perl-logfile/#comments</comments>
		<pubDate>Mon, 03 Dec 2007 21:29:29 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.red-green.com/2007/06/perl-logfile/</guid>
		<description><![CDATA[Logging to a file Using search.cpan.org there are many options to logging to a file.&#160; Finding just one that does exactly what you need can be a challenge. Here, I will talk just about one:&#160; Log::LogLite LogLite was almost exactly what I was looking for, but I found it to be lacking in one area:&#160; [...]]]></description>
			<content:encoded><![CDATA[<h1>Logging to a file</h1>
<p>Using <a href="http://search.cpan.org/search?query=log&amp;mode=all" title="Cpan Logging Modules" target="_blank">search.cpan.org</a>  there are many options to logging to a file.&nbsp; Finding just one that does exactly what you need can be a challenge.</p>
<p>Here, I will talk just about one:&nbsp; Log::LogLite</p>
<p>LogLite was almost exactly what I was looking for, but I found it to be lacking in one area:&nbsp; The date output formatting was most useless, and not customizable. &quot;YYYY-DD-MM&quot;!?&nbsp; Why not YYYY-MM-DD like most computer programmers like, since it alpha sorts correctly? </p>
<p>A simple change near line 69 like so:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$line</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>TEMPLATE<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$line</span> <span style="color: #339933;">=~</span> <span style="color: #000066;">s</span><span style="color: #339933;">!</span><span style="color: #009999;">&lt;date&gt;</span><span style="color: #339933;">!</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">date_string</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!</span>igoe<span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;"># changed to $self-&gt;date_string() so module can be customized by deriving from.</span></pre></div></div>

<p>And now I can derive modules from Log::LogLite and customize the date formatting.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000066;">package</span> MyLog<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Log<span style="color: #339933;">::</span><span style="color: #006600;">LogLite</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">@ISA</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Log::LogLite&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> date_string <span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sec</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$min</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$hour</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$mday</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$mon</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$year</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$wday</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$yday</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$isdst</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">localtime</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066;">return</span> <span style="color: #000066;">sprintf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;%02d/%02d/%04d %02d:%02d:%02d&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">$mon</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$mday</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$year</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1900</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$hour</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$min</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$sec</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;"># of date_string</span></pre></div></div>

<p>But since I have to modify the original module in order to have the flexibility to customize it, I just renamed the module LogLite.pm to <a href='http://www.red-green.com/wp-content/uploads/2007/12/mylog.pm' title='MyLog a Log::LogLite modified logger that allows the date to be modified.'>MyLog.pm</a>, made the above two changes and copy it around to where I need it.&nbsp;</p>
<p>So much for code reuse.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-green.com/2007/12/perl-logfile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic SSH login using RSA/DSA keys</title>
		<link>http://www.red-green.com/2007/06/automatic-ssh-login-using-rsadsa-keys/</link>
		<comments>http://www.red-green.com/2007/06/automatic-ssh-login-using-rsadsa-keys/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 20:28:26 +0000</pubDate>
		<dc:creator>stevet</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.red-green.com/2007/06/automatic-ssh-login-using-rsadsa-keys/</guid>
		<description><![CDATA[Creating the RSA Key ssh-keygen -t rsa This will create the id_rsa and id_rsa.pub files. The id_rsa.pub file located in ~/.ssh is your public key. Copy it to the system you want to automatically login to. See `man ssh-keygen` for more options. Why do I only show RSA keys? Because it&#39;s safer then the DSA [...]]]></description>
			<content:encoded><![CDATA[<h1>Creating the RSA Key</h1>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> rsa</pre></div></div>

<p>This will create the id_rsa and id_rsa.pub files. The id_rsa.pub file located in ~/.ssh is your public key. Copy it to the system you want to automatically login to. See `man ssh-keygen` for more options. Why do I only show RSA keys? Because it&#39;s <a href="http://the.earth.li/~sgtatham/putty/0.53b/htmldoc/Chapter8.html#8.2.2" target="_blank" title="RSA Safer then DSA">safer then the DSA keys according to the putty developers (see section 8.2.2)</a> . I&#39;m sure that all the bugs in DSA have been fixed by now, including the key generation problems, but why take unnecessary risks?</p>
<h1>Public Key Adding Script</h1>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;"># September 23, 2003 (initial)</span>
<span style="color: #666666; font-style: italic;"># Updated August 23, 2006 (updated)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Steve Thielemann</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># A script file to add ssh key</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># 1.) Verifies ~/.ssh directory exists, if not creates and</span>
<span style="color: #666666; font-style: italic;">#     fixes permissions.</span>
<span style="color: #666666; font-style: italic;"># 2.) Verifies ~/.ssh/authorized_keys exists, if not creates and</span>
<span style="color: #666666; font-style: italic;">#     fixes permissions.</span>
<span style="color: #666666; font-style: italic;"># 3.) Checks to see if ssh key is already present, if not adds to</span>
<span style="color: #666666; font-style: italic;">#     ~/.ssh/authorized_keys.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># dependant on:  grep, touch, chmod, cut</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;I need the filename of a public key to add.<span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #7a0874; font-weight: bold;">&#40;</span>The .pub <span style="color: #c20cb9; font-weight: bold;">file</span> created from <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> rsa<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;Example:  $<span style="color: #000000;">0</span> remote_rsa.pub<span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #007800;">keyid</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f3-</span> <span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #666666; font-style: italic;">#39;-d &amp;#39; &amp;lt; $1`</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;I can<span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #666666; font-style: italic;">#39;t find $1 !&amp;quot;</span>
<span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;Using ID <span style="color: #007800;">$keyid</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #666666; font-style: italic;"># variables to make life easier</span>
<span style="color: #007800;">sshdir</span>=~<span style="color: #000000; font-weight: bold;">/</span>.ssh
<span style="color: #007800;">keyfile</span>=~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$sshdir</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot; <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;Making <span style="color: #007800;">$sshdir</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$sshdir</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$sshdir</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot; <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;Creating <span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">644</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$keyid</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot; <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot; <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;Adding key to <span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #c20cb9; font-weight: bold;">cat</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">&amp;</span>quot;<span style="color: #007800;">$keyfile</span><span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&amp;</span>quot;Key <span style="color: #007800;">$keyid</span> already present.<span style="color: #000000; font-weight: bold;">&amp;</span>quot;
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #666666; font-style: italic;"># the end</span></pre></div></div>

<p>Or: <a href="http://red-green.com/keyit.sh" title="Script to automatically add a RSA/DSA public key">download the auto SSH script</a> .</p>
<h1>Notes About the Script</h1>
<p>The script doesn&#39;t do anything fancy, and once it has been run, adding additional keys is as simple as doing cat id_rsa.pub &gt;&gt; ./ssh/authorized_keys ! But, if the system hasn&#39;t been rsa public keyed before, this script will take care of setting all the file permissions correctly.</p>
<h1>Configuring SSH to use the RSA Key</h1>
<p>In your ~/.ssh/config file, add the following lines: <code>Host nameyoucallsite Hostname 10.0.0.1 (or hostname) IdentityFile ~/.ssh/id_rsa User usernameonsite</code> The hostname, if you set it with an IP address, it will always work (assuming your internet connection is working). If you use a hostname, it will only work if DNS is working. (Hint, if the server you are sshing into is the DNS server for that domain, make sure you have the IP address somewhere just in case!) User is the login name for that box. The IdentityFile is the file that you created, I usually create many keys, one for each project that I am involved in. Once configured, doing `ssh nameyoucallsite` is all that is required to login to the site.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-green.com/2007/06/automatic-ssh-login-using-rsadsa-keys/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
