<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts on mwclabs</title><link>https://mwclabs.net/posts/</link><description>Recent content in Posts on mwclabs</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>&lt;a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener">CC BY-NC 4.0&lt;/a></copyright><lastBuildDate>Fri, 21 Feb 2014 17:49:41 -0300</lastBuildDate><atom:link href="https://mwclabs.net/posts/index.xml" rel="self" type="application/rss+xml"/><item><title>Fix origin IP address in Apache access log when behind a proxy</title><link>https://mwclabs.net/posts/2014/02/fix-origin-ip-address-in-apache-access-log-when-behind-a-proxy/</link><pubDate>Fri, 21 Feb 2014 17:49:41 -0300</pubDate><guid>https://mwclabs.net/posts/2014/02/fix-origin-ip-address-in-apache-access-log-when-behind-a-proxy/</guid><description>&lt;p>When your app is behind any sort of reverse proxy (like a Load Balancer, API Gateway, CDN, etc), by default, the Apache access log will start showing the proxy&amp;rsquo;s IP address as the origin instead of the client one.&lt;/p>
&lt;p>Most of those proxies append the client IP address to the &lt;code>X-Forwarded-For&lt;/code> HTTP header, so we can use it to get the IP into the access log using a &lt;code>CustomLog&lt;/code> as seen below:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-apache" data-lang="apache">&lt;span style="display:flex;">&lt;span>LogFormat &lt;span style="color:#e6db74">&amp;#34;%{X-Forwarded-For}i %l %u %t \&amp;#34;%r\&amp;#34; %&amp;gt;s %b \&amp;#34;%{Referer}i\&amp;#34; \&amp;#34;%{User-Agent}i\&amp;#34;&amp;#34;&lt;/span> proxy
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>SetEnvIf X-Forwarded-For &lt;span style="color:#e6db74">&amp;#34;^.*\..*\..*\..*&amp;#34;&lt;/span> forwarded
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>CustomLog ${APACHE_LOG_DIR}/mywebsite_access.log combined env=!forwarded
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>CustomLog ${APACHE_LOG_DIR}/mywebsite_access.log proxy env=forwarded
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;em>Reference:&lt;/em> &lt;a href="https://www.techstacks.com/howto/log-client-ip-and-xforwardedfor-ip-in-apache.html">https://www.techstacks.com/howto/log-client-ip-and-xforwardedfor-ip-in-apache.html&lt;/a>&lt;/p></description><content type="html"><![CDATA[<p>When your app is behind any sort of reverse proxy (like a Load Balancer, API Gateway, CDN, etc), by default, the Apache access log will start showing the proxy&rsquo;s IP address as the origin instead of the client one.</p>
<p>Most of those proxies append the client IP address to the <code>X-Forwarded-For</code> HTTP header, so we can use it to get the IP into the access log using a <code>CustomLog</code> as seen below:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-apache" data-lang="apache"><span style="display:flex;"><span>LogFormat <span style="color:#e6db74">&#34;%{X-Forwarded-For}i %l %u %t \&#34;%r\&#34; %&gt;s %b \&#34;%{Referer}i\&#34; \&#34;%{User-Agent}i\&#34;&#34;</span> proxy
</span></span><span style="display:flex;"><span>SetEnvIf  X-Forwarded-For <span style="color:#e6db74">&#34;^.*\..*\..*\..*&#34;</span> forwarded
</span></span><span style="display:flex;"><span>CustomLog ${APACHE_LOG_DIR}/mywebsite_access.log combined env=!forwarded
</span></span><span style="display:flex;"><span>CustomLog ${APACHE_LOG_DIR}/mywebsite_access.log proxy env=forwarded
</span></span></code></pre></div><p><em>Reference:</em> <a href="https://www.techstacks.com/howto/log-client-ip-and-xforwardedfor-ip-in-apache.html">https://www.techstacks.com/howto/log-client-ip-and-xforwardedfor-ip-in-apache.html</a></p>]]></content></item><item><title>Using an authenticated proxy in Java</title><link>https://mwclabs.net/posts/2014/02/using-an-authenticated-proxy-in-java/</link><pubDate>Thu, 06 Feb 2014 22:51:08 -0300</pubDate><guid>https://mwclabs.net/posts/2014/02/using-an-authenticated-proxy-in-java/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-java" data-lang="java">&lt;span style="display:flex;">&lt;span>Authenticator.&lt;span style="color:#a6e22e">setDefault&lt;/span>(&lt;span style="color:#66d9ef">new&lt;/span> Authenticator() {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">protected&lt;/span> PasswordAuthentication &lt;span style="color:#a6e22e">getPasswordAuthentication&lt;/span>() {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> &lt;span style="color:#66d9ef">new&lt;/span> PasswordAuthentication(&lt;span style="color:#e6db74">&amp;#34;domain\\user&amp;#34;&lt;/span>,&lt;span style="color:#e6db74">&amp;#34;password&amp;#34;&lt;/span>.&lt;span style="color:#a6e22e">toCharArray&lt;/span>());
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>});
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;em>Reference:&lt;/em> &lt;a href="https://stackoverflow.com/questions/120797/how-do-i-set-the-proxy-to-be-used-by-the-jvm/12295125#12295125">https://stackoverflow.com/questions/120797/how-do-i-set-the-proxy-to-be-used-by-the-jvm/12295125#12295125&lt;/a>&lt;/p></description><content type="html"><![CDATA[<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span>Authenticator.<span style="color:#a6e22e">setDefault</span>(<span style="color:#66d9ef">new</span> Authenticator() {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">protected</span> PasswordAuthentication <span style="color:#a6e22e">getPasswordAuthentication</span>() {
</span></span><span style="display:flex;"><span> 
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">new</span> PasswordAuthentication(<span style="color:#e6db74">&#34;domain\\user&#34;</span>,<span style="color:#e6db74">&#34;password&#34;</span>.<span style="color:#a6e22e">toCharArray</span>());
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>});
</span></span></code></pre></div><p><em>Reference:</em> <a href="https://stackoverflow.com/questions/120797/how-do-i-set-the-proxy-to-be-used-by-the-jvm/12295125#12295125">https://stackoverflow.com/questions/120797/how-do-i-set-the-proxy-to-be-used-by-the-jvm/12295125#12295125</a></p>]]></content></item><item><title>Installing OpenBSD using softraid</title><link>https://mwclabs.net/posts/2013/12/installing-openbsd-using-softraid/</link><pubDate>Thu, 05 Dec 2013 17:02:41 -0300</pubDate><guid>https://mwclabs.net/posts/2013/12/installing-openbsd-using-softraid/</guid><description>&lt;p>Installing OpenBSD 5.4 with two disks configured as software RAID 1 array (softraid):&lt;/p>
&lt;pre tabindex="0">&lt;code>(I)nstall, (U)pgrade or (S)hell? s
# cd /dev
# sh /dev/MAKEDEV sd1 sd2
# fdisk -iy sd0
Writing MBR at offset 0.
# fdisk -iy sd1
Writing MBR at offset 0.
# disklabel -E sd0
Label editor (enter ‘?’ for help at any prompt)
&amp;gt; a a
offset: [64] [ENTER]
size: [41929586] [ENTER]
FS type: [4.2BSD] RAID
&amp;gt; q
Write new label?: [y] y
# cd /tmp
# disklabel sd0 &amp;gt; protofile
# disklabel -R sd1 protofile
# bioctl -c 1 -l /dev/sd0a,/dev/sd1a softraid0
sd2 at scscibus2 targ 1 lun 0: &amp;lt;OPENBSD, SR RAID 1, 005&amp;gt; SCSI2 0/direct fixed
sd2: 20473MB, 512 bytes/sector, 41929058 sectors
softraid0: RAID 1 volume attached as sd2
# dd if=/dev/zero of=/dev/rsd2c bs=1m count=1
1+0 records in
1+0 records out
1048576 bytes transferred in 0.009 secs (111337439 bytes/sec)
# exit
&lt;/code>&lt;/pre></description><content type="html"><![CDATA[<p>Installing OpenBSD 5.4 with two disks configured as software RAID 1 array (softraid):</p>
<pre tabindex="0"><code>(I)nstall, (U)pgrade or (S)hell? s
# cd /dev
# sh /dev/MAKEDEV sd1 sd2
# fdisk -iy sd0
Writing MBR at offset 0.
# fdisk -iy sd1
Writing MBR at offset 0.
# disklabel -E sd0
Label editor (enter ‘?’ for help at any prompt)
&gt; a a
offset: [64] [ENTER]
size: [41929586] [ENTER]
FS type: [4.2BSD] RAID
&gt; q
Write new label?: [y] y
# cd /tmp
# disklabel sd0 &gt; protofile
# disklabel -R sd1 protofile
# bioctl -c 1 -l /dev/sd0a,/dev/sd1a softraid0
sd2 at scscibus2 targ 1 lun 0: &lt;OPENBSD, SR RAID 1, 005&gt; SCSI2 0/direct fixed
sd2: 20473MB, 512 bytes/sector, 41929058 sectors
softraid0: RAID 1 volume attached as sd2
# dd if=/dev/zero of=/dev/rsd2c bs=1m count=1
1+0 records in
1+0 records out
1048576 bytes transferred in 0.009 secs (111337439 bytes/sec)
# exit
</code></pre>]]></content></item><item><title>Error installing Port security/openvpn-auth-ldap on FreeBSD 9</title><link>https://mwclabs.net/posts/2013/11/error-installing-port-security/openvpn-auth-ldap-on-freebsd-9/</link><pubDate>Mon, 04 Nov 2013 18:21:02 -0300</pubDate><guid>https://mwclabs.net/posts/2013/11/error-installing-port-security/openvpn-auth-ldap-on-freebsd-9/</guid><description>&lt;p>On FreeBSD 9, the Port &lt;code>security/openvpn-auth-ldap&lt;/code> is flagged as &lt;strong>BROKEN&lt;/strong> because of the following error in the &lt;strong>configure&lt;/strong> build step.&lt;/p>
&lt;pre tabindex="0">&lt;code>configure: WARNING: Check library not found. Unit tests will not be built or run.
checking for openvpn-plugin.h... no
configure: error: Could not locate a working openvpn source tree.
See `config.log&amp;#39; for more details.
===&amp;gt; Script &amp;#34;configure&amp;#34; failed unexpectedly.
Please report the problem to snb@FreeBSD.org [maintainer] and attach the
&amp;#34;/usr/ports/security/openvpn-auth-ldap/work/auth-ldap-2.0.3/config.log&amp;#34;
including the output of the failure of your make command. Also, it might be
a good idea to provide an overview of all packages installed on your system
(e.g. a /usr/sbin/pkg_info -Ea).
*** Error code 1
&lt;/code>&lt;/pre>&lt;p>Looking at the &lt;code>config.log&lt;/code>, we have:&lt;/p>
&lt;pre tabindex="0">&lt;code>configure:5511: checking for openvpn-plugin.h
configure:5544: cc -o conftest -O2 -pipe -DLDAP_DEPRECATED -fno-strict-aliasing -I/usr/ports/security/openvpn/work/openvpn-2.3.0 -export-dynamic conftest.c &amp;gt;&amp;amp;5
conftest.c:15:34: error: openvpn-plugin.h: No such file or directory
&lt;/code>&lt;/pre>&lt;p>Other error that might happen:&lt;/p>
&lt;pre tabindex="0">&lt;code>checking how to run the Objective C preprocessor... /lib/cpp
configure: error: Objective C preprocessor &amp;#34;/lib/cpp&amp;#34; fails sanity check
&lt;/code>&lt;/pre>&lt;p>To fix this, a &lt;a href="https://mwclabs.net/pub/openvpn-auth-ldap.patch">patch&lt;/a> can be applied:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>cd /usr/ports/security/openvpn-auth-ldap
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>wget https://mwclabs.net/pub/openvpn-auth-ldap.patch
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>patch -p0 &amp;lt; openvpn-auth-ldap.patch
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>make &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> make install
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description><content type="html"><![CDATA[<p>On FreeBSD 9, the Port <code>security/openvpn-auth-ldap</code> is flagged as <strong>BROKEN</strong> because of the following error in the <strong>configure</strong> build step.</p>
<pre tabindex="0"><code>configure: WARNING: Check library not found. Unit tests will not be built or run.
checking for openvpn-plugin.h... no
configure: error: Could not locate a working openvpn source tree.
See `config.log&#39; for more details.
===&gt; Script &#34;configure&#34; failed unexpectedly.
Please report the problem to snb@FreeBSD.org [maintainer] and attach the
&#34;/usr/ports/security/openvpn-auth-ldap/work/auth-ldap-2.0.3/config.log&#34;
including the output of the failure of your make command. Also, it might be
a good idea to provide an overview of all packages installed on your system
(e.g. a /usr/sbin/pkg_info -Ea).
*** Error code 1
</code></pre><p>Looking at the <code>config.log</code>, we have:</p>
<pre tabindex="0"><code>configure:5511: checking for openvpn-plugin.h
configure:5544: cc -o conftest -O2 -pipe -DLDAP_DEPRECATED -fno-strict-aliasing -I/usr/ports/security/openvpn/work/openvpn-2.3.0 -export-dynamic conftest.c &gt;&amp;5
conftest.c:15:34: error: openvpn-plugin.h: No such file or directory
</code></pre><p>Other error that might happen:</p>
<pre tabindex="0"><code>checking how to run the Objective C preprocessor... /lib/cpp
configure: error: Objective C preprocessor &#34;/lib/cpp&#34; fails sanity check
</code></pre><p>To fix this, a <a href="/pub/openvpn-auth-ldap.patch">patch</a> can be applied:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cd /usr/ports/security/openvpn-auth-ldap
</span></span><span style="display:flex;"><span>wget https://mwclabs.net/pub/openvpn-auth-ldap.patch
</span></span><span style="display:flex;"><span>patch -p0 &lt; openvpn-auth-ldap.patch
</span></span><span style="display:flex;"><span>make <span style="color:#f92672">&amp;&amp;</span> make install
</span></span></code></pre></div>]]></content></item><item><title>Error "tar: Unrecognized archive format" on FreeBSD 8.2</title><link>https://mwclabs.net/posts/2013/05/error-tar-unrecognized-archive-format-on-freebsd-8.2/</link><pubDate>Mon, 20 May 2013 21:11:25 -0300</pubDate><guid>https://mwclabs.net/posts/2013/05/error-tar-unrecognized-archive-format-on-freebsd-8.2/</guid><description>&lt;p>After trying to install a certain Port on FreeBSD 8.2, the following error was being reported:&lt;/p>
&lt;pre tabindex="0">&lt;code>tar: Unrecognized archive format
&lt;/code>&lt;/pre>&lt;p>After a bit of digging, I found out the distributed version of bsdtar wasn&amp;rsquo;t recognizing &lt;code>xz&lt;/code> compression between &lt;code>-7&lt;/code> and &lt;code>-9&lt;/code>.&lt;/p>
&lt;p>As a workaround, while not upgrading to FreeBSD 8.3, you can do the following:&lt;/p>
&lt;ul>
&lt;li>Install the Port &lt;code>archivers/libarchive&lt;/code>; and&lt;/li>
&lt;li>Append the line below in the file &lt;code>/etc/make.conf&lt;/code>:&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-make" data-lang="make">&lt;span style="display:flex;">&lt;span>TAR&lt;span style="color:#f92672">=&lt;/span>/usr/local/bin/bsdtar
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>That being done, you now will be able to successfully install the failing Port.&lt;/p>
&lt;p>&lt;a href="http://forums.freebsd.org/showthread.php?t=39404">More info.&lt;/a>&lt;/p>
&lt;p>&lt;strong>UPDATE&lt;/strong>&lt;/p>
&lt;p>If you are getting the error below while installing &lt;code>archivers/libarchive&lt;/code>:&lt;/p>
&lt;pre tabindex="0">&lt;code>error: spawn.h: No such file or directory
&lt;/code>&lt;/pre>&lt;p>You should try installing it with the following commands:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>make clean
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>make ac_cv_header_spawn_h&lt;span style="color:#f92672">=&lt;/span>no
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>make install
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description><content type="html"><![CDATA[<p>After trying to install a certain Port on FreeBSD 8.2, the following error was being reported:</p>
<pre tabindex="0"><code>tar: Unrecognized archive format
</code></pre><p>After a bit of digging, I found out the distributed version of bsdtar wasn&rsquo;t recognizing <code>xz</code> compression between <code>-7</code> and <code>-9</code>.</p>
<p>As a workaround, while not upgrading to FreeBSD 8.3, you can do the following:</p>
<ul>
<li>Install the Port <code>archivers/libarchive</code>; and</li>
<li>Append the line below in the file <code>/etc/make.conf</code>:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-make" data-lang="make"><span style="display:flex;"><span>TAR<span style="color:#f92672">=</span>/usr/local/bin/bsdtar
</span></span></code></pre></div><p>That being done, you now will be able to successfully install the failing Port.</p>
<p><a href="http://forums.freebsd.org/showthread.php?t=39404">More info.</a></p>
<p><strong>UPDATE</strong></p>
<p>If you are getting the error below while installing <code>archivers/libarchive</code>:</p>
<pre tabindex="0"><code>error: spawn.h: No such file or directory
</code></pre><p>You should try installing it with the following commands:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>make clean
</span></span><span style="display:flex;"><span>make ac_cv_header_spawn_h<span style="color:#f92672">=</span>no
</span></span><span style="display:flex;"><span>make install
</span></span></code></pre></div>]]></content></item><item><title>Disabling foreign key check on MySQL</title><link>https://mwclabs.net/posts/2011/07/disabling-foreign-key-check-on-mysql/</link><pubDate>Mon, 11 Jul 2011 14:32:31 -0300</pubDate><guid>https://mwclabs.net/posts/2011/07/disabling-foreign-key-check-on-mysql/</guid><description>&lt;p>Useful when you need to quickly restore a backup.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-sql" data-lang="sql">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">SET&lt;/span> FOREIGN_KEY_CHECKS &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">0&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">SOURCE&lt;/span> db_xyz.&lt;span style="color:#66d9ef">sql&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">SET&lt;/span> FOREIGN_KEY_CHECKS &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#ae81ff">1&lt;/span>;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description><content type="html"><![CDATA[<p>Useful when you need to quickly restore a backup.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#66d9ef">SET</span> FOREIGN_KEY_CHECKS <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">SOURCE</span> db_xyz.<span style="color:#66d9ef">sql</span>;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">SET</span> FOREIGN_KEY_CHECKS <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;
</span></span></code></pre></div>]]></content></item><item><title>Burning .img image to DVD on the command line</title><link>https://mwclabs.net/posts/2011/05/burning-.img-image-to-dvd-on-the-command-line/</link><pubDate>Tue, 24 May 2011 09:25:49 -0300</pubDate><guid>https://mwclabs.net/posts/2011/05/burning-.img-image-to-dvd-on-the-command-line/</guid><description>&lt;p>Install &lt;code>udftools&lt;/code> package using APT (Debian/Ubuntu):&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>apt-get install udftools
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Burn your image:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>growisofs -Z /dev/dvdrw1&lt;span style="color:#f92672">=&lt;/span>/home/theone/myimage.img
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>&lt;code>/dev/dvdrw1&lt;/code> is the DVD device&lt;/li>
&lt;li>&lt;code>/home/theone/myimage.img&lt;/code> is your image&lt;/li>
&lt;/ul>
&lt;p>&lt;em>Reference:&lt;/em>&lt;/p>
&lt;ul>
&lt;li>&lt;a href="http://www.centraldolinux.org/como-gravar-um-arquivo-img-em-dvd/">http://www.centraldolinux.org/como-gravar-um-arquivo-img-em-dvd/&lt;/a>&lt;/li>
&lt;/ul></description><content type="html"><![CDATA[<p>Install <code>udftools</code> package using APT (Debian/Ubuntu):</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>apt-get install udftools
</span></span></code></pre></div><p>Burn your image:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>growisofs -Z /dev/dvdrw1<span style="color:#f92672">=</span>/home/theone/myimage.img
</span></span></code></pre></div><ul>
<li><code>/dev/dvdrw1</code> is the DVD device</li>
<li><code>/home/theone/myimage.img</code> is your image</li>
</ul>
<p><em>Reference:</em></p>
<ul>
<li><a href="http://www.centraldolinux.org/como-gravar-um-arquivo-img-em-dvd/">http://www.centraldolinux.org/como-gravar-um-arquivo-img-em-dvd/</a></li>
</ul>]]></content></item><item><title>Transparent proxy in a different server using PF</title><link>https://mwclabs.net/posts/2010/05/transparent-proxy-in-a-different-server-using-pf/</link><pubDate>Tue, 25 May 2010 17:35:32 -0300</pubDate><guid>https://mwclabs.net/posts/2010/05/transparent-proxy-in-a-different-server-using-pf/</guid><description>&lt;p>To have a transparent web proxy in a different server from your gateway/firewall, besides the port 80 redirect rule to your proxy server, you will also need a NAT rule.&lt;/p>
&lt;p>&lt;strong>On your network gateway/firewall:&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>Set the following sysctl:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sysctl net.inet.ip.redirect&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">0&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol start="2">
&lt;li>Add the following rule in your PF config:&lt;/li>
&lt;/ol>
&lt;pre tabindex="0">&lt;code class="language-pf" data-lang="pf">pass in quick on $int_if route-to ($int_if $IP_Proxy) proto tcp from ! $IP_Proxy to any port www
&lt;/code>&lt;/pre>&lt;p>&lt;strong>On your proxy server:&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>Set the following sysctl:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sysctl net.inet.ip.redirect&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">0&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol start="2">
&lt;li>Add a PF rule to redirect port 80 traffic to port 3128:&lt;/li>
&lt;/ol>
&lt;pre tabindex="0">&lt;code class="language-pf" data-lang="pf">rdr inet proto tcp from ! $IP_Proxy to any port www -&amp;gt; $IP_Proxy port 3128
&lt;/code>&lt;/pre></description><content type="html"><![CDATA[<p>To have a transparent web proxy in a different server from your gateway/firewall, besides the port 80 redirect rule to your proxy server, you will also need a NAT rule.</p>
<p><strong>On your network gateway/firewall:</strong></p>
<ol>
<li>Set the following sysctl:</li>
</ol>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sysctl net.inet.ip.redirect<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>
</span></span></code></pre></div><ol start="2">
<li>Add the following rule in your PF config:</li>
</ol>
<pre tabindex="0"><code class="language-pf" data-lang="pf">pass in quick on $int_if route-to ($int_if $IP_Proxy) proto tcp from ! $IP_Proxy to any port www
</code></pre><p><strong>On your proxy server:</strong></p>
<ol>
<li>Set the following sysctl:</li>
</ol>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sysctl net.inet.ip.redirect<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>
</span></span></code></pre></div><ol start="2">
<li>Add a PF rule to redirect port 80 traffic to port 3128:</li>
</ol>
<pre tabindex="0"><code class="language-pf" data-lang="pf">rdr inet proto tcp from ! $IP_Proxy to any port www -&gt; $IP_Proxy port 3128
</code></pre>]]></content></item><item><title>Reading and writing NTFS on FreeBSD</title><link>https://mwclabs.net/posts/2010/05/reading-and-writing-ntfs-on-freebsd/</link><pubDate>Tue, 25 May 2010 17:18:32 -0300</pubDate><guid>https://mwclabs.net/posts/2010/05/reading-and-writing-ntfs-on-freebsd/</guid><description>&lt;p>Mouting your NTFS device on write mode.&lt;/p>
&lt;p>This will mount your HD on read-only mode:&lt;/p>
&lt;p>&lt;code>mount -t nfs /dev/da0s1 /mnt&lt;/code>&lt;/p>
&lt;p>To be able to mount your NTFS and write, you will need &lt;code>NTFS-3G&lt;/code>.&lt;/p>
&lt;p>Install the port:&lt;/p>
&lt;p>&lt;code>cd /usr/ports/sysutils/fusefs-ntfs&lt;/code>&lt;/p>
&lt;p>&lt;code>make install&lt;/code>&lt;/p>
&lt;p>Load the kernel module:&lt;/p>
&lt;p>&lt;code>kldload /usr/local/modules/fuse.ko&lt;/code>&lt;/p>
&lt;p>Mount the desired device:&lt;/p>
&lt;p>&lt;code>mount -t ntfs-3g /dev/da0s1 /mnt&lt;/code>&lt;/p>
&lt;p>Alternative mounting command:&lt;/p>
&lt;p>&lt;code>ntfs-3g /dev/da0s1 /mnt&lt;/code>&lt;/p></description><content type="html"><![CDATA[<p>Mouting your NTFS device on write mode.</p>
<p>This will mount your HD on read-only mode:</p>
<p><code>mount -t nfs /dev/da0s1 /mnt</code></p>
<p>To be able to mount your NTFS and write, you will need <code>NTFS-3G</code>.</p>
<p>Install the port:</p>
<p><code>cd /usr/ports/sysutils/fusefs-ntfs</code></p>
<p><code>make install</code></p>
<p>Load the kernel module:</p>
<p><code>kldload /usr/local/modules/fuse.ko</code></p>
<p>Mount the desired device:</p>
<p><code>mount -t ntfs-3g /dev/da0s1 /mnt</code></p>
<p>Alternative mounting command:</p>
<p><code>ntfs-3g /dev/da0s1 /mnt</code></p>]]></content></item><item><title>Transparent proxy using Squid and PF on OpenBSD</title><link>https://mwclabs.net/posts/2009/04/transparent-proxy-using-squid-and-pf-on-openbsd/</link><pubDate>Fri, 17 Apr 2009 11:05:20 -0300</pubDate><guid>https://mwclabs.net/posts/2009/04/transparent-proxy-using-squid-and-pf-on-openbsd/</guid><description>&lt;p>How to install and configure &lt;a href="http://www.squid-cache.org/">Squid&lt;/a> on transparent mode and the necessary (&lt;a href="http://www.openbsd.org/faq/pf/">PF&lt;/a>) rules.&lt;/p>
&lt;p>&lt;strong>1. Install&lt;/strong>&lt;/p>
&lt;p>You can using the pre-compiled packages (pkg_add) or from the source using &lt;a href="http://www.openbsd.org/ports.html">Ports&lt;/a>.&lt;/p>
&lt;p>&lt;strong>Via Package Manager (pkg_add)&lt;/strong>&lt;/p>
&lt;p>Set the repository mirror:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>export PKG_PATH&lt;span style="color:#f92672">=&lt;/span>ftp://ftp.das.ufsc.br/pub/OpenBSD/4.4/packages/i386/
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Install the package:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>pkg_add -i -v squid
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Selected version was: &lt;strong>squid-2.7.STABLE3-ldap&lt;/strong>.&lt;/p>
&lt;p>&lt;strong>Via Ports&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>cd /usr/ports/www/squid
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>env FLAVOR&lt;span style="color:#f92672">=&lt;/span>transparent make install
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>2. Configuration&lt;/strong>&lt;/p>
&lt;p>&lt;strong>2.1. Squid&lt;/strong>&lt;/p>
&lt;p>To make squid start on boot, edit the file &lt;strong>/etc/rc.local&lt;/strong> and append the following files after &lt;code># Add your local startup actions here&lt;/code>:&lt;/p>
&lt;pre tabindex="0">&lt;code># Squid
/usr/local/sbin/squid
&lt;/code>&lt;/pre>&lt;p>Now, edit the Squid configuration file &lt;code>/etc/squid/squid.conf&lt;/code>, you can use a configuration like the following:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-squid" data-lang="squid">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_port&lt;/span> &lt;span style="color:#ae81ff">3128&lt;/span> transparent
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">visible_hostname&lt;/span> neatproxy.myorg.corp
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>error_directory /usr/local/share/squid/errors/Portuguese
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Logs&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">cache_access_log&lt;/span> /var/log/squid/access.log
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">cache_log&lt;/span> /var/log/squid/cache.log
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># SVN&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>extension_methods REPORT MERGE MKACTIVITY CHECKOUT PROPFIND
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># ACLs&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> &lt;span style="color:#66d9ef">all&lt;/span> &lt;span style="color:#66d9ef">src&lt;/span> &lt;span style="color:#ae81ff">0.0.0.0/0.0.0.0&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> localnet &lt;span style="color:#66d9ef">src&lt;/span> &lt;span style="color:#ae81ff">192.168.1.0/24&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> SSL_Ports &lt;span style="color:#66d9ef">port&lt;/span> &lt;span style="color:#ae81ff">443&lt;/span> &lt;span style="color:#ae81ff">563&lt;/span> &lt;span style="color:#ae81ff">2096&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> Safe_ports &lt;span style="color:#66d9ef">port&lt;/span> &lt;span style="color:#ae81ff">80&lt;/span> &lt;span style="color:#ae81ff">21&lt;/span> &lt;span style="color:#ae81ff">443&lt;/span> &lt;span style="color:#ae81ff">563&lt;/span> &lt;span style="color:#ae81ff">70&lt;/span> &lt;span style="color:#ae81ff">210&lt;/span> &lt;span style="color:#ae81ff">1025-65535&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> Safe_ports &lt;span style="color:#66d9ef">port&lt;/span> &lt;span style="color:#ae81ff">280&lt;/span> &lt;span style="color:#75715e"># http-mgmt&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> Safe_ports &lt;span style="color:#66d9ef">port&lt;/span> &lt;span style="color:#ae81ff">488&lt;/span> &lt;span style="color:#75715e"># gss-http&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> Safe_ports &lt;span style="color:#66d9ef">port&lt;/span> &lt;span style="color:#ae81ff">591&lt;/span> &lt;span style="color:#75715e"># filemaker&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> Safe_ports &lt;span style="color:#66d9ef">port&lt;/span> &lt;span style="color:#ae81ff">777&lt;/span> &lt;span style="color:#75715e"># multiling http&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> CONNECT &lt;span style="color:#66d9ef">method&lt;/span> CONNECT
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Full access users&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> vips arp &amp;#34;/etc/squid/users.vips&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># BlackList&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> blacklist &lt;span style="color:#66d9ef">dstdomain&lt;/span> &amp;#34;/etc/squid/domains.blacklist&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">##&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Allow and deny rules&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_access&lt;/span> &lt;span style="color:#66d9ef">deny&lt;/span> !Safe_ports
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_access&lt;/span> &lt;span style="color:#66d9ef">deny&lt;/span> CONNECT !SSL_ports
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_access&lt;/span> &lt;span style="color:#66d9ef">allow&lt;/span> vips
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_access&lt;/span> &lt;span style="color:#66d9ef">deny&lt;/span> blacklist
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_access&lt;/span> &lt;span style="color:#66d9ef">allow&lt;/span> localnet
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_access&lt;/span> &lt;span style="color:#66d9ef">deny&lt;/span> &lt;span style="color:#66d9ef">all&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">##&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;em>Create the &lt;code>/etc/squid/users.vips&lt;/code> e &lt;code>/etc/squid/domains.blacklist&lt;/code> if used.&lt;/em>&lt;/p>
&lt;p>Run Squid with the &lt;code>-z&lt;/code> flag in order to init swap directories:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>/usr/local/sbin/squid -z
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Start the Squid service:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>/usr/local/sbin/squid
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>After configuration changes, run the following command to reload rules:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>/usr/local/sbin/squid -k reconfigure
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>2.2. PF&lt;/strong>&lt;/p>
&lt;p>Edit PF configuration file &lt;code>/etc/pf.conf&lt;/code> and use/adapt the following rules:&lt;/p>
&lt;pre tabindex="0">&lt;code class="language-pf" data-lang="pf">rdr on $int_if inet proto tcp from any to any port www -&amp;gt; 127.0.0.1 port 3128
pass in on $int_if inet proto tcp from any to 127.0.0.1 port 3128
pass out on $ext_if inet proto tcp from any to any port www
&lt;/code>&lt;/pre>&lt;p>Permissions for Squid to access &lt;code>/dev/pf&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>chgrp _squid /dev/pf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>chmod g+rw /dev/pf
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;hr>
&lt;p>&lt;em>Reference:&lt;/em>&lt;/p>
&lt;ul>
&lt;li>&lt;a href="http://www.openbsd-br.org/index.php?q=node/15">http://www.openbsd-br.org/index.php?q=node/15&lt;/a>&lt;/li>
&lt;/ul></description><content type="html"><![CDATA[<p>How to install and configure <a href="http://www.squid-cache.org/">Squid</a> on transparent mode and the necessary (<a href="http://www.openbsd.org/faq/pf/">PF</a>) rules.</p>
<p><strong>1. Install</strong></p>
<p>You can using the pre-compiled packages (pkg_add) or from the source using <a href="http://www.openbsd.org/ports.html">Ports</a>.</p>
<p><strong>Via Package Manager (pkg_add)</strong></p>
<p>Set the repository mirror:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>export PKG_PATH<span style="color:#f92672">=</span>ftp://ftp.das.ufsc.br/pub/OpenBSD/4.4/packages/i386/
</span></span></code></pre></div><p>Install the package:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>pkg_add -i -v squid
</span></span></code></pre></div><p>Selected version was: <strong>squid-2.7.STABLE3-ldap</strong>.</p>
<p><strong>Via Ports</strong></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cd /usr/ports/www/squid
</span></span><span style="display:flex;"><span>env FLAVOR<span style="color:#f92672">=</span>transparent make install
</span></span></code></pre></div><p><strong>2. Configuration</strong></p>
<p><strong>2.1. Squid</strong></p>
<p>To make squid start on boot, edit the file <strong>/etc/rc.local</strong> and append the following files after <code># Add your local startup actions here</code>:</p>
<pre tabindex="0"><code># Squid
/usr/local/sbin/squid
</code></pre><p>Now, edit the Squid configuration file <code>/etc/squid/squid.conf</code>, you can use a configuration like the following:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-squid" data-lang="squid"><span style="display:flex;"><span><span style="color:#66d9ef">http_port</span> <span style="color:#ae81ff">3128</span> transparent
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">visible_hostname</span> neatproxy.myorg.corp
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>error_directory /usr/local/share/squid/errors/Portuguese
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Logs</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">cache_access_log</span> /var/log/squid/access.log
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">cache_log</span> /var/log/squid/cache.log
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># SVN</span>
</span></span><span style="display:flex;"><span>extension_methods REPORT MERGE MKACTIVITY CHECKOUT PROPFIND
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># ACLs</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">acl</span> <span style="color:#66d9ef">all</span> <span style="color:#66d9ef">src</span> <span style="color:#ae81ff">0.0.0.0/0.0.0.0</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">acl</span> localnet <span style="color:#66d9ef">src</span> <span style="color:#ae81ff">192.168.1.0/24</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">acl</span> SSL_Ports <span style="color:#66d9ef">port</span> <span style="color:#ae81ff">443</span> <span style="color:#ae81ff">563</span> <span style="color:#ae81ff">2096</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">acl</span> Safe_ports <span style="color:#66d9ef">port</span> <span style="color:#ae81ff">80</span> <span style="color:#ae81ff">21</span> <span style="color:#ae81ff">443</span> <span style="color:#ae81ff">563</span> <span style="color:#ae81ff">70</span> <span style="color:#ae81ff">210</span> <span style="color:#ae81ff">1025-65535</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">acl</span> Safe_ports <span style="color:#66d9ef">port</span> <span style="color:#ae81ff">280</span> <span style="color:#75715e"># http-mgmt</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">acl</span> Safe_ports <span style="color:#66d9ef">port</span> <span style="color:#ae81ff">488</span> <span style="color:#75715e"># gss-http</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">acl</span> Safe_ports <span style="color:#66d9ef">port</span> <span style="color:#ae81ff">591</span> <span style="color:#75715e"># filemaker</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">acl</span> Safe_ports <span style="color:#66d9ef">port</span> <span style="color:#ae81ff">777</span> <span style="color:#75715e"># multiling http</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">acl</span> CONNECT <span style="color:#66d9ef">method</span> CONNECT
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Full access users</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">acl</span> vips arp &#34;/etc/squid/users.vips&#34;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># BlackList</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">acl</span> blacklist <span style="color:#66d9ef">dstdomain</span> &#34;/etc/squid/domains.blacklist&#34;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">##</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Allow and deny rules</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">http_access</span> <span style="color:#66d9ef">deny</span> !Safe_ports
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">http_access</span> <span style="color:#66d9ef">deny</span> CONNECT !SSL_ports
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">http_access</span> <span style="color:#66d9ef">allow</span> vips
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">http_access</span> <span style="color:#66d9ef">deny</span> blacklist
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">http_access</span> <span style="color:#66d9ef">allow</span> localnet
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">http_access</span> <span style="color:#66d9ef">deny</span> <span style="color:#66d9ef">all</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">##</span>
</span></span></code></pre></div><p><em>Create the <code>/etc/squid/users.vips</code> e <code>/etc/squid/domains.blacklist</code> if used.</em></p>
<p>Run Squid with the <code>-z</code> flag in order to init swap directories:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>/usr/local/sbin/squid -z
</span></span></code></pre></div><p>Start the Squid service:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>/usr/local/sbin/squid
</span></span></code></pre></div><p>After configuration changes, run the following command to reload rules:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>/usr/local/sbin/squid -k reconfigure
</span></span></code></pre></div><p><strong>2.2. PF</strong></p>
<p>Edit PF configuration file <code>/etc/pf.conf</code> and use/adapt the following rules:</p>
<pre tabindex="0"><code class="language-pf" data-lang="pf">rdr on $int_if inet proto tcp from any to any port www -&gt; 127.0.0.1 port 3128

pass in on $int_if inet proto tcp from any to 127.0.0.1 port 3128
pass out on $ext_if inet proto tcp from any to any port www
</code></pre><p>Permissions for Squid to access <code>/dev/pf</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>chgrp _squid /dev/pf
</span></span><span style="display:flex;"><span>chmod g+rw /dev/pf
</span></span></code></pre></div><hr>
<p><em>Reference:</em></p>
<ul>
<li><a href="http://www.openbsd-br.org/index.php?q=node/15">http://www.openbsd-br.org/index.php?q=node/15</a></li>
</ul>]]></content></item></channel></rss>