<?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>Web-In-Sight</title>
	<atom:link href="http://web-in-sight.nl/feed/" rel="self" type="application/rss+xml" />
	<link>http://web-in-sight.nl</link>
	<description>Inzicht in internet en werken</description>
	<lastBuildDate>Mon, 30 Jan 2012 09:00:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>ABN Amro / Rabobank nep mails (hoax) in omloop</title>
		<link>http://web-in-sight.nl/2012/01/26/abn-amro-rabobank-nep-mails-in-omloop/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=abn-amro-rabobank-nep-mails-in-omloop</link>
		<comments>http://web-in-sight.nl/2012/01/26/abn-amro-rabobank-nep-mails-in-omloop/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 20:16:54 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[Broadcasts]]></category>

		<guid isPermaLink="false">http://web-in-sight.nl/?p=1944</guid>
		<description><![CDATA[Voor de mensen die niet bekend zijn met het fenomeen HOAX een artikel over recent ontvangen nep mails. Ik ontving onderstaande email ogenschijnlijk van de ABN Amro bank maar daar kwam hij niet vandaan. De symptomen Waarom is de mail &#8230; <a href="http://web-in-sight.nl/2012/01/26/abn-amro-rabobank-nep-mails-in-omloop/">Lees verder <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Voor de mensen die niet bekend zijn met het fenomeen HOAX een artikel over recent ontvangen nep mails. Ik ontving onderstaande email ogenschijnlijk van de ABN Amro bank maar daar kwam hij niet vandaan.</p>
<p><a href="http://web-in-sight.nl/wp-content/uploads/2012/01/abnamro-hoax.png"><img class="aligncenter size-medium wp-image-1945" title="abnamro-hoax" src="http://web-in-sight.nl/wp-content/uploads/2012/01/abnamro-hoax-269x300.png" alt="" width="269" height="300" /></a></p>
<h2>De symptomen</h2>
<p>Waarom is de mail niet van de bank? <strong><tt></tt></strong>Afgezien van een ogenschijnlijk echte inhoud zijn er een aantal zaken waaruit blijkt dat dit een nepmail, ofwel Hoax, is:<span id="more-1944"></span></p>
<ul>
<li>De mail is niet rechtstreeks aan mij geadresseerd. Daarbij komt dat een afzender adres eenvoudig te vervalsen is.</li>
<li>Een bank zal dergelijke mails niet snel versturen. Heb je argwaan kan je gerust de versturende partij even bellen voor opheldering.</li>
<li>Als je de link in de mail kopieert en plakt in je kladblok zie je dat de url heel ergens ander naar verwijst.</li>
</ul>
<p>De link bevatte de volgende url: http://64.15.147.205/~abverify/secure</p>
<p>Dit geeft de doorslag want ze vroegen daar vervolgens al je gegevens in te vullen. Als daar niet de domeinnaam van je bank staat dan is er vast en zeker iets niet pluis.</p>
<p>Ik heb (in minder dan een week) nog twee andere mails ontvangen en wel met de volgende afzender en titel:</p>
<p>From:     RABO BANK &lt;info@rabobank.nl&gt;<br />
Subject:     Klanten Service</p>
<p>en</p>
<p>From:     ABN-AMRO Bank &lt;ABNAMRO_Alert@accountant.nl&gt;<br />
Subject:     ABN-AMRO Alert &#8211; Uw Internet Bankieren is geblokkeerd</p>
<p>Ook beiden met een link die niet lijdt naar de website van de betreffende bank, en zoals we zojuist hebben geleerd dus beiden een hoax.</p>
<p>Uit nieuwsgierigheid een link gevolg en daar kom je inderdaad op een website die LIJKT op de website van de bank.  Dat is hij niet en vul ook zeker niets in.</p>
<p><a href="http://web-in-sight.nl/wp-content/uploads/2012/01/abnamro-fakesite.png"><img class="aligncenter" title="Nep website abnamro" src="http://web-in-sight.nl/wp-content/uploads/2012/01/abnamro-fakesite-300x259.png" alt="" width="300" height="259" /></a></p>
<p>Surf veilig!</p>
<p>&nbsp;</p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2012%2F01%2F26%2Fabn-amro-rabobank-nep-mails-in-omloop%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2012/01/26/abn-amro-rabobank-nep-mails-in-omloop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebTip #2: Gebruik niet al te lange zinnen op je site &#8230;</title>
		<link>http://web-in-sight.nl/2012/01/23/webtip-2-gebruik-niet-al-te-lange-zinnen-op-je-site/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=webtip-2-gebruik-niet-al-te-lange-zinnen-op-je-site</link>
		<comments>http://web-in-sight.nl/2012/01/23/webtip-2-gebruik-niet-al-te-lange-zinnen-op-je-site/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 07:21:51 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[Broadcasts]]></category>

		<guid isPermaLink="false">http://web-in-sight.nl/?p=1936</guid>
		<description><![CDATA[Gebruik niet al te lange zinnen op je site. Een website leest anders als een boek en het is de bedoeling dat je boodschap goed over komt.]]></description>
			<content:encoded><![CDATA[<p data-ft="{&quot;type&quot;:1}">Gebruik niet al te lange zinnen op je site. Een website leest anders als een boek en het is de bedoeling dat je boodschap goed over komt.</p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2012%2F01%2F23%2Fwebtip-2-gebruik-niet-al-te-lange-zinnen-op-je-site%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2012/01/23/webtip-2-gebruik-niet-al-te-lange-zinnen-op-je-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web-In-Sight op Facebook / WebTip #1</title>
		<link>http://web-in-sight.nl/2012/01/18/web-in-sight-op-facebook/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=web-in-sight-op-facebook</link>
		<comments>http://web-in-sight.nl/2012/01/18/web-in-sight-op-facebook/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 09:11:48 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[Broadcasts]]></category>

		<guid isPermaLink="false">http://web-in-sight.nl/?p=1927</guid>
		<description><![CDATA[Fan-page geplaatst en de eerste webtip <a href="http://web-in-sight.nl/2012/01/18/web-in-sight-op-facebook/">Lees verder <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Met het online gaan van de nieuwe vormgeving is Web-In-Sight ook op facebook te vinden.</p>
<p>Heb je vragen over je website, je CMS, je hosting provider, of hoe nu verder? Stel ze op de <a title="Web-In-Sight fan-page" href="http://www.facebook.com/WebInSight" target="_blank">Web-In-Sight fan-page</a>.</p>
<p>WebTip #1: &#8220;Hou je website overzichtelijk voor je bezoekers. Minder zoeken draagt bij aan de effectiviteit.&#8221;</p>
<p>&nbsp;</p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2012%2F01%2F18%2Fweb-in-sight-op-facebook%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2012/01/18/web-in-sight-op-facebook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dirty hack for WordPress to realize a hard return</title>
		<link>http://web-in-sight.nl/2012/01/10/dirty-hack-for-wordpress-to-realize-a-hard-return/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dirty-hack-for-wordpress-to-realize-a-hard-return</link>
		<comments>http://web-in-sight.nl/2012/01/10/dirty-hack-for-wordpress-to-realize-a-hard-return/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 11:33:19 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[All ENGLISH articles]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.gp-net.nl/?p=78</guid>
		<description><![CDATA[Update: As long as this post hast lasted and thanking everybody for their reply&#8217;s &#8230; In WordPress 3.3.1 the extra &#8216;return&#8217; now stays in your text after saving your pages and posts. &#160; Ever wanted to have an extra white &#8230; <a href="http://web-in-sight.nl/2012/01/10/dirty-hack-for-wordpress-to-realize-a-hard-return/">Lees verder <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: As long as this post hast lasted and thanking everybody for their reply&#8217;s &#8230;</p>
<p>In WordPress 3.3.1 the extra &#8216;return&#8217; now stays in your text after saving your pages and posts.</p>
<hr />
<p>&nbsp;</p>
<p>Ever wanted to have an extra white line in your post just because it looks nice? Searched the forums and all you got was replies to go straight into the CSS code? &#8230; But I just want that 1 line d*mned &#8230; <img src='http://web-in-sight.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Mind you, It&#8217;s beyond dirty but very effective. Here&#8217;s how:</p>
<p>Put a &#8220;.&#8221; (dot) on a new line and give it the same color as the background.</p>
<p><span style="color: #ffffff;">.</span></p>
<p>Regards,</p>
<p>Gerard.</p>
<p>P.S. noticed the space above &#8220;Regards,&#8221; &#8230; <img src='http://web-in-sight.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2012%2F01%2F10%2Fdirty-hack-for-wordpress-to-realize-a-hard-return%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2012/01/10/dirty-hack-for-wordpress-to-realize-a-hard-return/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Refactoring apache vhosts</title>
		<link>http://web-in-sight.nl/2011/06/25/refactoring-apache-vhosts/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=refactoring-apache-vhosts</link>
		<comments>http://web-in-sight.nl/2011/06/25/refactoring-apache-vhosts/#comments</comments>
		<pubDate>Sat, 25 Jun 2011 09:17:05 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[All ENGLISH articles]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[vhost]]></category>

		<guid isPermaLink="false">http://www.gerardjp.com/?p=1623</guid>
		<description><![CDATA[Apache VirtualHost: Seperating network and application data with mod_define for optimal deployment <a href="http://web-in-sight.nl/2011/06/25/refactoring-apache-vhosts/">Lees verder <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>- Apache VirtualHost: Separating network and application data with mod_define for clean deployment -</em></p>
<p>Ever had the pleasure of supporting a development team in their efforts to reach deadlines and therewith smoothing out the deployment process? It can be a complex task when the deployment covers multiple servers at once. From a sysadmin point of view you are concerned with network and naming conventions of your web-, database- and possibly other servers.</p>
<h1>The context</h1>
<p>Nevertheless, you need to communicate with the developers about this without overloading them with network details. Practically a set of server names should be enough for their deployment configuration. Of course I&#8217;m primarily talking about framework based application deployment running on Django, Rails and so on.</p>
<p>When handling SSL only websites there&#8217;s the IP address per website restriction (not taking <a title="Server Name Indication" href="http://en.wikipedia.org/wiki/Server_Name_Indication" target="_blank">SNI</a> into account). Then there&#8217;s the gray area; The configuration parts that are both server and application related. Doing an article on Apache 2.x trickery I&#8217;m talking about the VirtualHost setup, but there are others to consider like logrotation, cron vs. application framework jobs, etc.</p>
<p>Having peeked, this article indeed describes a setup that involves Apache and how to ease the work of the development team. Before taking of I&#8217;d like to add one more detail into the mix. For design reasons I consider it good practice to have a seperate IP to address a server besides the ones you use for your services as web, database, file uploads or any other. This separates traffic to your server for e.g. monitoring, backups, abuse filtering, security, etc. next to your regular service traffic.</p>
<p>Having such a clean setup, but also for security reasons, setting up Apache with 0.0.0.0:443 or *:443 doesn&#8217;t fit in my opinion (better explicit then implicit).</p>
<p>Having set the context I&#8217;ll get into the technical details.</p>
<h1>The setup</h1>
<p>As was written we need a &#8216;VirtualHost&#8217; setup that is transparent to the developers but should contain all information for Apache to operate properly.  Besides necessary modules and what not the snippet below displays the minimal required configuration directives.</p>
<pre>NameVirtualhost 1.2.3.4:443
Listen 1.2.3.4:443

&lt;Virtualhost 1.2.3.4:443&gt;

    # Your vhost config

&lt;/Virtualhost&gt;</pre>
<p><strong>Note</strong>: I&#8217;m putting the listen statement in the virtualhost config file and not in Apache&#8217;s ports.conf to keep things contained with the application&#8217;s configuration. Here&#8217;s the first conflict because this would mean different configs in de developers codebase for every server they deploy on. We&#8217;ll resolve that in a minute.</p>
<p>&nbsp;</p>
<h1>Apache symlink intermezzo</h1>
<p>More on keeping things contained along side your application, mainly for upscale portability, we put the file with Apache&#8217;s vhost config in an etc directory under the application codebase. E.g: [app basedir]/etc/apache.conf</p>
<p>Usually, with Apache, site configurations are stored in /etc/apache2/sites-available and they are enabled when symlinked to from /etc/apache2/sites-enabled.</p>
<p>When putting the vhost configuration under your app codebase you simply link from &#8216;sites-enabled&#8217; to that location.</p>
<pre>$ cd /etc/apache2/sites-enabled
$ ls -l
total 0
lrwxrwxrwx 1 root root   74 2011-05-04 19:47 www.example.com -&gt; /home/appuser1/sites/www.example.com/config/etc/apache.conf
lrwxrwxrwx 1 root root   79 2011-05-04 19:48 www.other.com -&gt; /home/appuser2/sites/www.other.com/config/etc/apache.conf
lrwxrwxrwx 1 root root   71 2011-06-10 15:22 another.other.com -&gt; /home/appuser2/sites/another.other.com/config/etc/apache.conf</pre>
<p>The thing to lookout for when running multiple apps: the symlink sourcename must be set different from the name &#8216;apache.conf&#8217; otherwise you get a name conflict in the /etc/apache2/sites-enabled directory. This is done with the &#8216;ln&#8217; command in de following manor:</p>
<pre>$ cd /etc/apache2/sites-enabled
$ ln -s /home/appuser1/sites/www.example.com/config/etc/apache.conf www.example.com</pre>
<p>Now that we know what goes where we can work on the relation between the IP adresses and the different applications or vhosts.</p>
<h1>Installing the glue</h1>
<p>We need mod_define for this, found here: <a title="mod_define" href="http://people.apache.org/~rjung/mod_define/" target="_blank">mod_define</a>. With this module we have the ability to set $variables within the Apache configuration files.</p>
<p>Installation is rather simple. Download it and run (as root):</p>
<pre>$ apxs2 -i -a -c mod_define.c</pre>
<p>Good chance the module is automatically enabled using the apxs2 command but that might depend on your distro. Otherwise you can either use a2enmod or simply symlink between /etc/apache2/mods-available and /etc/apache2/mods-enabled. The file your looking (linking) for contains the following:</p>
<pre>$ cat /etc/apache2/mods-enabled/define.load
LoadModule define_module      /usr/lib/apache2/modules/mod_define.so</pre>
<p>Enable the module linking it like so:</p>
<pre>$ cd /etc/apache2/mods-enabled
$ ln -s ../mods-available/define.load</pre>
<p>Note that your installed module, as configured in &#8216;define.load&#8217;, might end up elsewhere under &#8216;/usr/&#8230;. &#8216; depending on your distro.</p>
<h1>The glue in effect</h1>
<p>Besides the seemingly complicated context it simply comes down to a list of variable names containing IP adress/port number combinations. The below example should explain this.</p>
<pre>&lt;IfModule define_module&gt;
    # IP's are example public addresses
    Define bind_address_www_example_com 1.2.3.4:443
    Define bind_address_www_other_com 2.3.4.5:443
&lt;/IfModule&gt;</pre>
<p>After making sure the module is enabled we place the &#8216;vhost_bind_adresses.conf&#8217; file in &#8216;/etc/apache2/conf.d&#8217;. After this file has been set up we can use the defined variables in our VirtualHost configuration. These are about the only thing that the development team should stick to (assuming the vhost file is included in their codebase). Considering the file wherein we defined the variables a vhost file looks like this:</p>
<pre>Listen $bind_address_www_example_com
NameVirtualHost $bind_address_www_example_com

&lt;VirtualHost $bind_address_www_example_com&gt;

    ServerName www.example.com
    ServerAdmin webmaster@example.com

    LogLevel warn
    CustomLog /home/appuser1/sites/www.example.com/log/apache.access.log combined
    ErrorLog /home/appuser1/sites/www.example.com/log/apache.error.log

    DocumentRoot /home/appuser1/sites/www.example.com/

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/www.example.com.cert
    SSLCertificateKeyFile /etc/ssl/certs/www.example.com.key

    # &lt;-- SNIP --&gt;

&lt;/VirtualHost&gt;</pre>
<p><strong>Note</strong>: As said, the Listen and NameVirtualHost directives are in de vhost file instead of the ports.conf.</p>
<p>The beauty of this setup is that we can shuffle our server configuration without any changes to the developers code base. Creating/deploying new apps simply means adding a variable to &#8216;vhost_bind_adresses.conf&#8217; and updating the development team about the name.</p>
<h1>Gotcha&#8217;s</h1>
<p>Not much I can think of. If you agree on a variable name with the development team that is unambiguous, for instance: $bind_addr_www_domain_com there&#8217;s not much that can go wrong.</p>
<p>One more tip: Learn yourself to use apache2ctl -t after changing stuff because restarting Apache while having syntax errors results in only stopping Apache. Which in it&#8217;s turn causes already running websites being unavailable for your audience.</p>
<p>Any comments or questions are welcome.</p>
<p>GrtzG</p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2011%2F06%2F25%2Frefactoring-apache-vhosts%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2011/06/25/refactoring-apache-vhosts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Virtualbox: virtual networking anywhere</title>
		<link>http://web-in-sight.nl/2011/03/21/virtualbox-virtual-networking-anywhere/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=virtualbox-virtual-networking-anywhere</link>
		<comments>http://web-in-sight.nl/2011/03/21/virtualbox-virtual-networking-anywhere/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 12:19:16 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[All ENGLISH articles]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[virtual]]></category>
		<category><![CDATA[virtualbox]]></category>

		<guid isPermaLink="false">http://www.gerardjp.com/?p=1590</guid>
		<description><![CDATA[For lack of a better title, ever had the problem with Virtualbox where you&#8217;re working happily in the guest OS, unplug your laptop, get underway, and see the end of your guest OS access. It&#8217;s always either Internet access or &#8230; <a href="http://web-in-sight.nl/2011/03/21/virtualbox-virtual-networking-anywhere/">Lees verder <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For lack of a better title, ever had the problem with Virtualbox where you&#8217;re working happily in the guest OS, unplug your laptop, get underway, and see the end of your guest OS access. It&#8217;s always either Internet access or local access for your VM. Well, that&#8217;s no longer an issue.</p>
<h1>Case exploration</h1>
<p>In this example I use my own setup but it should be doable on any host/guest OS combination. My setup is a Macbook running OSX snow leopard with a guest OS running Ubuntu server. Before getting into the details; The trick is to hook up Ubuntu&#8217;s eth0 to one of your normal interfaces (physical or wifi) and link Ubuntu&#8217;s eth1 to a virtual network device  in your host OS. In this setup you always have local (back-end) access to your virtual guest OS and whenever you have Internet access so does your guest OS.</p>
<h1>The details</h1>
<p>I&#8217;m assuming you&#8217;re already running Virtualbox on OS X and an Ubuntu installation as guest OS. First we need to create a virtual network interface to which we can &#8216;link&#8217; our eth1. For this we need a driver that emulates a network device. Typically we need a <a href="http://en.wikipedia.org/wiki/TUN/TAP">tun/tap driver</a>. Therefore download and install <a href="http://tuntaposx.sourceforge.net/">Tuntap for OS X</a>. In the Virtualbox network configuration for the guest OS we need to configure (and enable) the second ethernet adapter and set it as &#8216;host only&#8217;.</p>
<p><a href="http://www.gerardjp.com/wp-content/uploads/2011/03/enable_2nd_nic.png"><img class="size-full wp-image-1596 aligncenter" title="Enable second NIC" src="http://www.gerardjp.com/wp-content/uploads/2011/03/enable_2nd_nic.png" alt="Enable second NIC" width="648" height="520" /><br />
</a>NB: the name vboxnet0 will be changed to be tap0 but that will be handled in a minute.</p>
<p>To setup the virtual interface you need to download and run the following script: <a href="../wp-content/uploads/2011/03/tap.sh.zip">tap.sh</a>. Running tap.sh (as root) will create a virtual network device that can be used for Ubuntu&#8217;s eth1 to hook into. Whilst having the tap0 device operational with IP address 10.10.10.1 the following commands will set the Virtualbox settings for Ubuntu to bind to it.</p>
<p>List your VM&#8217;s and pick the right one:</p>
<pre>$ VBoxManage list vms</pre>
<p>Enable the 2nd network interface of your VM</p>
<pre>$ VBoxManage modifyvm [VM name] --intnet2 hostif</pre>
<p>Set the interface to &#8216;host only&#8217;:</p>
<pre>$ VBoxManage modifyvm [VM name] --hostonlyadapter2  tap0</pre>
<p>Note:  The last command(s) seem obsolete since the release of Virtualbox version 4.0.4 r70112 or later. In older versions the tap0 used to fallback to vboxnet0 after closing Virtualbox. But the network configuration is now persistent when set to device tap0.  So, depending on the version you use your mileage may vary. Test it with restarting Virtualbox and see if your VM network config looks similar to this:</p>
<p><a href="http://www.gerardjp.com/wp-content/uploads/2011/03/network_settings.png"><img class="alignnone size-full wp-image-1597 aligncenter" title="Network settings" src="http://www.gerardjp.com/wp-content/uploads/2011/03/network_settings.png" alt="Network settings" width="571" height="75" /></a></p>
<p>Running that last command once will suffice for the long run instead of between every Virtualbox or workstation startup (besides the tap.sh script that is).</p>
<p>That being said, you&#8217;re now ready to start the Ubuntu VM. You should probably access Ubuntu via the front-end nic the first time since the back-end nic in the guest OS isn&#8217;t configured yet. Having logged into Ubuntu you should setup your interfaces as follows. For eth0 you can either choose static or dhcp, whatever runs easiest on your network. Setup Eth1 as static in network segment 10.10.10.0/24, e.g. 10.10.10.2 with 10.10.10.1 being your tap0 hosts OS interface.</p>
<p>Either reboot your Ubuntu VM, or nicer, restart the network with:</p>
<pre>$ /etc/init.d/networking restart</pre>
<p>You should now be able to login on Ubuntu with:</p>
<pre>$ ssh you@10.10.10.2</pre>
<p>Now unplug your physical network connection in your host OS (that&#8217;s Ubuntu&#8217;s eth0) and you can still login on your VM via the 10.10.10.0/24 network.</p>
<h1>Gotcha&#8217;s</h1>
<p>The only one I can think of is the need to manually add the default route to the outside world over etho. This happens when the host OS&#8217;s physical network has been disconnected. I assume it&#8217;s because Ubuntu&#8217;s  eth0 has been down with which the route is dropped. You can easily resolve this with the following command:</p>
<pre>$ ip route add default via [your gateway's IP]</pre>
<p>If you have any questions or comments please feel free to drop me a line.</p>
<h1>References</h1>
<p>- The inspiration for this article: <a href="http://tinyurl.com/6z29w45">http://tinyurl.com/6z29w45</a><br />
- OSX&#8217;s TunTap driver: <a href="http://tuntaposx.sourceforge.net/">http://tuntaposx.sourceforge.net/</a><br />
- Tun/Tap info on wikipedia: <a href="http://en.wikipedia.org/wiki/TUN/TAP">http://en.wikipedia.org/wiki/TUN/TAP</a><br />
- The tap.sh script: <a href="http://www.gerardjp.com/wp-content/uploads/2011/03/tap.sh.zip">tap.sh</a></p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2011%2F03%2F21%2Fvirtualbox-virtual-networking-anywhere%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2011/03/21/virtualbox-virtual-networking-anywhere/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>nexec, distributed terminal commands</title>
		<link>http://web-in-sight.nl/2011/03/20/nexec-distributed-terminal-commands/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nexec-distributed-terminal-commands</link>
		<comments>http://web-in-sight.nl/2011/03/20/nexec-distributed-terminal-commands/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 09:01:19 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[All ENGLISH articles]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.gp-net.nl/?p=45</guid>
		<description><![CDATA[Update: since there&#8217;s been a change in pylib&#8217;s netexec that breaks nexec.py I&#8217;ve updated the script. Click here to download the newest version! I Developed this commandline tool to make it easier to maintain stuff on a groing amount of &#8230; <a href="http://web-in-sight.nl/2011/03/20/nexec-distributed-terminal-commands/">Lees verder <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><!--TOC--><em><strong>Update</strong>: since there&#8217;s been a change in <a href="http://codespeak.net/execnet/">pylib&#8217;s netexec</a> that breaks nexec.py I&#8217;ve updated the script. <a href="http://www.gerardjp.com/wp-content/uploads/2008/06/nexec-1.1.zip">Click here to download the newest version</a>!</em></p>
<p>I Developed <a href="http://www.gerardjp.com/wp-content/uploads/2008/06/nexec-10.tgz">this</a> commandline tool to make it easier to maintain stuff on a groing amount of servers. <strong>nexec </strong>is a tool that can help you gather ad-hoc info when it&#8217;s needed quickly. <strong>nexec</strong> is written in python, it depends on <a title="Py lib from codespeak" href="http://codespeak.net/py/dist/" target="_blank">codespeak&#8217;s pylib</a>, and does all it&#8217;s communication over SSH. The only thing you need on &#8216;the other side&#8217; is a python interpreter. (that&#8217;s right, no further libs or modules). Oh, and you need your SSH key pairs in place, otherwise it&#8217;s &#8216;password galore&#8217;.</p>
<p>Of course, the bash-ers out there would say that the same functionality can be achieved with a for loop. True! But that&#8217;s exactly what <strong>nexec</strong> does for you so you can concentrate on what you&#8217;re doing remote. And ofcourse you can have nightly cron-ed scripts in place that do this every day. But <strong>nexec</strong> aids in all those things that are not &#8216;in place&#8217;.</p>
<h2>Examples</h2>
<p>Before getting into any details, first some tricks of the &#8216;nexec&#8217; trade to get you warmed up &#8230; <img src='http://web-in-sight.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Are my server systems running the proper time:</p>
<pre>$ ./nexec.py -n 'server1 server2  server3' -c 'date'
server2: Fri May 23 16:21:18 CEST 2008
server1: Fri May 23 16:21:17 CEST 2008
server3: Fri May 23 16:21:19 CEST 2008</pre>
<p>See if all your servers are running ssh protocol 2 only:</p>
<pre>$ ./nexec.py -n 'server1 server2  server3' -c 'cat /etc/ssh/sshd_config | grep -v ^# | grep Protocol' | sort
server1: Protocol 2
server2: Protocol 2
server3: Protocol 2</pre>
<p>(You could also do a &#8220;-n ALL&#8221;, then nexec reads your server list from a config file. More on that in a minute)</p>
<p>Get a list with all different kernel versions that are running on your systems:</p>
<pre>$ ./nexec.py -n ALL -q -c 'uname -r' | sort -u
2.6.18-5-686
2.6.18.8-xen</pre>
<p>(The &#8220;-q&#8221; parameter suppresses the &#8216;per line&#8217; hostname prefix).</p>
<p>See if &#8216;john&#8217; is a member of the sudo group on servers 1 and 2:</p>
<pre>./nexec.py -v -q -n 'server1 server2' -c 'cat /etc/group | grep sudo | grep -v john'
Host:  server1.example.com
sudo:x:27:jane,jerry
Host:  server2.example.com
sudo:x:27:jane</pre>
<p>(The&#8221;-v&#8221; adds the &#8220;Host: &#8230;.&#8221; header, per server output. Note that &#8220;-v&#8221; and &#8220;-q&#8221; are interchangeable)</p>
<p>As you can see, by combining local and remote greps and using the -v and/or -q parameters there are some interesting ways to obtain live data from your server.</p>
<p>Lets look at the configuration.</p>
<h2>Configuration</h2>
<p>Run without parms, <strong>nexec</strong> shows help output. Furthermore the only two files <strong>nexec</strong> depends on (and not even necessarily) are a &#8220;~/.nexec.conf&#8221; file and a possible &#8220;~/.ssh/config&#8221;.</p>
<p>The &#8220;~/.nexec.conf&#8221; does not contain much, just &#8220;key: value&#8221; pairs under a hosts section. The actual &#8216;value&#8217; is only obtained when using the &#8220;-v&#8221; option to display the header above each server output &#8220;<em>Host: server1.example.com</em>&#8220;.</p>
<pre>$ cat .nexec.conf
[hosts]
server1:   server1.example.com
server2:   server2.example.com
#server3:   server3.example.com</pre>
<p>Other then that, <strong>nexec</strong> simply expands &#8220;-c ALL&#8221; to all available keys under the &#8220;[hosts]&#8221; section, skipping the usual hashsign &#8216;#&#8217; being a comment. In this case the &#8220;ALL&#8221; parameter given to &#8220;-c&#8221; would be expanded to &#8220;server1 server2&#8243; in the previous example. After that the full name is taken from the &#8220;~.ssh/config&#8221; file.</p>
<pre>$ cat .ssh/config
# server1
Host server1
Hostname server1.example.com
User john
Port 4321
# server2
Host server2
Hostname server2.example.com
User john
<a href="http://www.gerardjp.com/wp-content/uploads/2008/06/nexec-1.0.tgz"></a>Port 4321</pre>
<p>I deliberately left all that in there so other usernames and port numbers can be specified. Besides, that&#8217;s all access related and shouldn&#8217;t be anywhere else anyway.</p>
<p>Then one more note on the &#8220;-q&#8221; and &#8220;-v&#8221; option. What they basically do is mark (or suppress mark&#8217;s) on the output that get&#8217;s returned. So you can mark output per server adding the &#8220;-v&#8221;, and output get&#8217;s marked per line (default) if not suppressed with &#8220;-q&#8221;.</p>
<h2>Download</h2>
<p>The script can be downloaded here: <a href="http://www.gerardjp.com/wp-content/uploads/2008/06/nexec-10.tgz">nexec-10.tgz</a></p>
<p>Set the &#8216;execute&#8217; bit with chmod and put it in your $PATH somewhere. And for the &#8220;ALL&#8221; parameter, set up the config file as the example shows in the <a title="TOC: Configuration" href="#toc-configuration">Configuration</a> section.</p>
<h3>Gotcha&#8217;s</h3>
<p>Escape your backticks with with a backslash if you want remote expansion.</p>
<p>This runs the uname part locally and then sends the command to the other side.</p>
<pre>$ nexec.py -n ALL -c "date | mailx -s `uname -n` root"</pre>
<p>This also executes the uname command on the other side.</p>
<pre>$ nexec.py -n ALL -c "date | mailx -s \`uname -n\` root"</pre>
<h2>Todo</h2>
<p>There&#8217;s two things still on my list.</p>
<ul>
<li>Catch a non-existing hostname when taken from the &#8220;.ssh/config&#8221; file. The script breaks if a host is not resolvable. (Being a sysadmin you should know what your doing .. <img src='http://web-in-sight.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </li>
<li>Make the &#8220;<em>Host: server1.example.com</em>&#8221; header not show when no output is returned from a host. That is when using the &#8220;-c ALL&#8221;.</li>
</ul>
<p>New tricks might be added in the future, so if there&#8217;s stuff that you think should be added drop me a reply.</p>
<p>That&#8217;s all folks &#8230;</p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2011%2F03%2F20%2Fnexec-distributed-terminal-commands%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2011/03/20/nexec-distributed-terminal-commands/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>(Sociale) gegevens versus Informatie &#8230; Waarom zeggen we iets?</title>
		<link>http://web-in-sight.nl/2010/12/25/sociale-gegevens-versus-informatie-waarom-zeggen-we-iets/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sociale-gegevens-versus-informatie-waarom-zeggen-we-iets</link>
		<comments>http://web-in-sight.nl/2010/12/25/sociale-gegevens-versus-informatie-waarom-zeggen-we-iets/#comments</comments>
		<pubDate>Sat, 25 Dec 2010 11:23:14 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[Leven en gezondheid]]></category>
		<category><![CDATA[communicatie]]></category>
		<category><![CDATA[kerst]]></category>
		<category><![CDATA[psychologie]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.gerardjp.com/?p=1566</guid>
		<description><![CDATA[Enige tijd geleden gepost op LinkedIn. Bij wijze van kerstgedachte, als in tijd van bezinning, ik denk ik post hem ook gewoon hier &#8212; Het valt me op dat de status updates op linkedIn steeds vaker gebruikt worden voor berichtgeving &#8230; <a href="http://web-in-sight.nl/2010/12/25/sociale-gegevens-versus-informatie-waarom-zeggen-we-iets/">Lees verder <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Enige tijd geleden gepost op <a title="Linked in post" href="http://www.linkedin.com/groupAnswers?viewQuestionAndAnswers=&amp;gid=1906367&amp;discussionID=31885311&amp;sik=&amp;trk=mywl_artile&amp;goback=.mwg_*2_1" target="_blank">LinkedIn</a>. Bij wijze van kerstgedachte, als in tijd van bezinning, ik denk ik post hem ook gewoon hier <img src='http://web-in-sight.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&#8212;<br />
Het valt me op dat de status updates op linkedIn steeds vaker gebruikt worden voor berichtgeving als &#8220;ik ben vanavond tennissen&#8221;, of wat zakelijker &#8220;ik ben naar een seminar&#8221;. Je ziet dit heel veel op Twitter gebeuren maar LinkedIn heeft toch een wat zakelijker karakter.</p>
<p>Nog even over voornoemd seminar; Het lijkt me zinvol om, naast waar je geweest bent, bijvoorbeeld een resumeetje te plaatsen over wat je gehoord/gezien hebt. Zo hebben anderen er ook wat aan naast de mededeling dat je geweest bent <img src='http://web-in-sight.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Voorts bezigt me over voornoemde categorie Twitter posts overigens de vraag waarom iemand neer zet &#8220;Ik ben naar tennissen geweest&#8221;. Er zijn in dit land duizenden mensen die tennissen op een avond dus zo spannend is dat niet. En als mensen van achter hun scherm bij houden wat vrienden doen is dat toch wel een sociale verarming te noemen. Face-2-face gesprekken zijn toch immers veel levendiger, mooier en intrigerende. Om nog maar niet te spreken van gezonder en behulpzaam bij het mentaal afwikkelen van dagelijkse bezigheden.</p>
<p>Dit ruikt naar psychologie, maar dan zou je denken dat mensen het posten omdat ze door het drukke leven zichzelf geen tijd gunnen om na te denken of (bijvoorbeeld met partner) te praten over wat hun beweegt. Wat ik hier probeer aan te geven is het verschil tussen aan iemand iets vertellen omdat de andere persoon dit horen wil versus aan iemand iets vertellen omdat je het zelf kwijt moet. De richting van de boodschap is dezelfde kant uit alleen ligt de initiatie ervan aan de andere zijde.</p>
<p>En nu maar hopen dat e.e.a. wat bewustwording teweeg brengt <img src='http://web-in-sight.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Ik ben overigens voor twitter nog op zoek naar een manier om bepaalde berichten op trefwoord (denk aan gowalla.com) te onderdrukken. Dus a la google&#8217;s zoeken: &#8220;+woord1 -woord2&#8243;. Met &#8220;-&#8221; sluit je dan posts uit. En dan als &#8216;raw input&#8217; gewoon de twitteraars die je &#8216;followed&#8217;. Als iemand daar een oplossing voor heeft dan hoor ik die graag.</p>
<p>Gezonde groet!</p>
<p>&#8212;</p>
<p>Maar dan daarbij de kerst groet aan allen!</p>
<p>GrtzG</p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2010%2F12%2F25%2Fsociale-gegevens-versus-informatie-waarom-zeggen-we-iets%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2010/12/25/sociale-gegevens-versus-informatie-waarom-zeggen-we-iets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Downsize an image while keeping aspect ratio</title>
		<link>http://web-in-sight.nl/2010/11/02/downsize-an-image-while-keeping-aspect-ratio/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=downsize-an-image-while-keeping-aspect-ratio</link>
		<comments>http://web-in-sight.nl/2010/11/02/downsize-an-image-while-keeping-aspect-ratio/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 14:53:18 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[All ENGLISH articles]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://www.gerardjp.com/?p=1478</guid>
		<description><![CDATA[A simple python function to downsize an image and calculate the new dimensions while keeping aspect ratio, whether it's in portrait or landscape <a href="http://web-in-sight.nl/2010/11/02/downsize-an-image-while-keeping-aspect-ratio/">Lees verder <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>A simple python function to downsize an image and calculate the new dimensions while keeping aspect ratio.</em></p>
<p>I needed this functionality for a web application. There are some variations found on the net from which I constructed this simple but effective python function to get &#8216;the other&#8217; value.</p>
<p>Based on the original image dimensions &#8220;i_&#8230;&#8221; it figures out whether the image is portrait or landscape and calculates either the width or height.</p>
<pre>def calculate_image_resize(i_width, i_height, max=0):

    i_width = float(i_width)
    i_height = float(i_height)
    ratio = i_width / i_height

    print 'w:', i_width, 'h:', i_height, 'r:', ratio

    if i_width &lt; i_height:
        print 'portrait'
        c_height = max
        c_width = max * ratio
    else:
        print 'landscape'
        c_width = max
        c_height = max / ratio

    c_width = int(c_width)
    c_height = int(c_height)

    return c_width, c_height
</pre>
<p>Dropping the function in a python shell and calling it results in this output:</p>
<pre>In [2]: calculate_image_resize(1700, 330, max=150)
w: 1700.0 h: 330.0 r: 5.15151515152
landscape
Out[2]: (150, 29)

In [3]: calculate_image_resize(170, 330, max=150)
w: 170.0 h: 330.0 r: 0.515151515152
portrait
Out[3]: (77, 150)
</pre>
<p>I deliberately left in the obvious 150 so you know instantly which dimension was calculated &#8220;c_&#8230;&#8221;.</p>
<p>Hope this saves people the trouble to figure it out by them selves.</p>
<p>GrtzG</p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2010%2F11%2F02%2Fdownsize-an-image-while-keeping-aspect-ratio%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2010/11/02/downsize-an-image-while-keeping-aspect-ratio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up your own custom python userlib</title>
		<link>http://web-in-sight.nl/2010/09/28/setting-up-your-own-custom-python-userlib/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=setting-up-your-own-custom-python-userlib</link>
		<comments>http://web-in-sight.nl/2010/09/28/setting-up-your-own-custom-python-userlib/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 11:29:04 +0000</pubDate>
		<dc:creator>Gerard</dc:creator>
				<category><![CDATA[All ENGLISH articles]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.gerardjp.com/?p=1222</guid>
		<description><![CDATA[Never were able, when in need of a simple script, to do a quick finish. Always end up copying code from your other scripts for such a simple thing as sending an email? Then this might be something for you. <a href="http://web-in-sight.nl/2010/09/28/setting-up-your-own-custom-python-userlib/">Lees verder <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently wrote a a script that monitors file/dir changes, acts on a change and notifies me via <a title="Notify OSD" href="https://wiki.ubuntu.com/NotifyOSD" target="_blank">notify-osd</a> or email. While writing this I came to the conclusion that a simple thing as sending an email easily kicks up to at least 10 lines of code and some settings. So it was time to find an easier way for this.</p>
<p>You can of course create distributable modules or packages but with simple local workstation like maintenance this seems overkill &#8230; yep, you are allowed to disagree <img src='http://web-in-sight.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>So, we need a place to put code that is easy to import in our used scripts and it should be easy to maintain. Dropping it in my homedir in a directory called &#8220;.python&#8221; seems well suited for this.</p>
<h2>The Setup</h2>
<p>Create the directory &#8220;.python&#8221; in your $HOMEDIR. Then add a line to your &#8220;.bashrc&#8221; to export $PYTHONPATH so when you do an import in python it is actually found.</p>
<pre>PYTHONPATH=~/.python
export PYTHONPATH</pre>
<p>Python picks up the paths from this variable and adds them to &#8220;sys.path&#8221; so there&#8217;s no need to add the path in every script you make. In individual cases you can of course do it like it is <a title="Appending to Your Python Path" href="http://www.johnny-lin.com/cdat_tips/tips_pylang/path.html" target="_blank">explained here</a>.</p>
<p>Then create a file in &#8220;~/.python/&#8221; for instance &#8220;userconfig.py&#8221;.</p>
<p>To make it available in your script simply import it and execute one of your functions.</p>
<pre>import userconfig as mystuff
mystuff.function(with, parms)</pre>
<p>I&#8217;ll give an example of a userconfig.py function to easily send out emails.</p>
<pre>import os
import sys
import pynotify
import smtplib
from email.mime.text import MIMEText

# Settings &lt;&lt; These are the "Sensible defaults" <img src='http://web-in-sight.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
MAILSERVER = 'localhost'
MAILFROM = 'somebody'
MAILTO = 'you@yourdomain.com'

def send_mail(subject, body, fro=MAILFROM, to=MAILTO):
    """
    Stripped function to send mail from local code
    """
    msg = MIMEText(body)
    msg['Subject'] = subject
    msg['From'] = fro
    msg['To'] = to

    s = smtplib.SMTP(MAILSERVER)
    s.sendmail(msg['From'], msg['To'], msg.as_string())
    s.close()</pre>
<p>The code above composes and sends an email. Doing all this in the script you are writing results in quite a bunch of these lines ending up in every one of your scripts.</p>
<h2>Sensible defaults</h2>
<p>How about not having to enter those &#8216;always the same defaults&#8217;? Well &#8230; When using the setup described in this article most can be omitted and parameters only need to be added when you deviate from your sensible defaults.</p>
<p>For argument sake I&#8217;ll give an example script that just mails something and calls the &#8220;send_mail()&#8221; function.</p>
<pre>import userconfig as user

body = """Some multiline triple quoted body mass\n\nwith lot's of

funky stuff in it."""

fish = 'whale'
subject = 'something fishy: %s' % fish

user.send_mail(subject, body)</pre>
<p>So that&#8217;s only 1 line for the actual &#8216;send my mail&#8217; command. Should you want a different FROM address then you just change the function call to this.</p>
<pre>user.send_mail(subject, body, 'notme')</pre>
<p>Thus, add parms when you need them or rely on your &#8220;Sensible Defaults&#8221; from your userconfig.py.</p>
<p>You can build a world of functionality in your &#8220;~/.python&#8221;. Import and use system wide installed packages in there, test if they are present on your system, etc.</p>
<h2>Gotcha&#8217;s</h2>
<p>When using scripts under CRON you need to add the PYTHONPATH to the  definition like below because CRON does not read your  &#8220;.bashrc&#8221;.</p>
<pre>*/1 * * * *  (PYTHONPATH=~/.python; /path/to/your/script.py)</pre>
<p>NB: Mind the parenthesis and semicolon on the line above.</p>
<p>Besides the fact that you should watch for name clashes, I can&#8217;t think of any other gotcha&#8217;s. If you do, then please teach me something and drop me a line <img src='http://web-in-sight.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>GrtzG</p>
<div class="AWD_like_button "><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fweb-in-sight.nl%2F2010%2F09%2F28%2Fsetting-up-your-own-custom-python-userlib%2F&amp;send=false&amp;layout=button_count&amp;width=&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:21px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://web-in-sight.nl/2010/09/28/setting-up-your-own-custom-python-userlib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

