<?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>Ben Jao Ming</title>
	<atom:link href="http://overtag.dk/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://overtag.dk/wordpress</link>
	<description>101% objective... always</description>
	<lastBuildDate>Wed, 02 May 2012 13:16:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Ubuntu tip: Save a list of installed packages for reinstallation purposes</title>
		<link>http://overtag.dk/wordpress/2012/04/ubuntu-tip-save-a-list-of-installed-packages-for-reinstallation-purposes/</link>
		<comments>http://overtag.dk/wordpress/2012/04/ubuntu-tip-save-a-list-of-installed-packages-for-reinstallation-purposes/#comments</comments>
		<pubDate>Sun, 08 Apr 2012 15:26:52 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=309</guid>
		<description><![CDATA[If you have a nicely running Ubuntu system with all your favourite packages installed, it might not seem like a good idea to start all over or to replace your hard drive. But here&#8217;s a tip: To save a list &#8230; <a href="http://overtag.dk/wordpress/2012/04/ubuntu-tip-save-a-list-of-installed-packages-for-reinstallation-purposes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you have a nicely running Ubuntu system with all your favourite packages installed, it might not seem like a good idea to start all over or to replace your hard drive. But here&#8217;s a tip: To save a list of all packages that are currently installed! This should be a part of any good backup.</p>
<pre language="bash">apt-cache --installed pkgnames</pre>
<p>Save them in a file:</p>
<pre language="bash">apt-cache --installed pkgnames > installed.packages.lst</pre>
<p>To install all packages in a file:</p>
<pre language="bash">sudo apt-get install `cat installed.packages.lst`</pre>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2012/04/ubuntu-tip-save-a-list-of-installed-packages-for-reinstallation-purposes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Overriding change_form.html and accessing the object instance</title>
		<link>http://overtag.dk/wordpress/2012/04/overriding-change_form-html-and-accessing-the-object-instance/</link>
		<comments>http://overtag.dk/wordpress/2012/04/overriding-change_form-html-and-accessing-the-object-instance/#comments</comments>
		<pubDate>Tue, 03 Apr 2012 09:55:39 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=304</guid>
		<description><![CDATA[Here&#8217;s an example for a custom change_form.html located in app/templates/admin/appname/modelname/change_form.html &#8211; and the cool thing is that it accesses the actual instance of the object, which I found to be very convenient and undocumented. If you want it to be &#8230; <a href="http://overtag.dk/wordpress/2012/04/overriding-change_form-html-and-accessing-the-object-instance/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an example for a custom change_form.html located in app/templates/admin/appname/modelname/change_form.html &#8211; and the cool thing is that it accesses the actual instance of the object, which I found to be very convenient and undocumented. If you want it to be more explicit than access through the builtin context variable adminform.form.instance, you can also make your own <a href="https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#django.contrib.admin.ModelAdmin.change_view" target="_blank">change_view</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">{% extends &quot;admin/change_form.html&quot; %}
&nbsp;
{% block object-tools %}
  {{ block.super }}
  &lt;h2&gt;{{ adminform.form.instance }}&lt;/h2&gt;
{% endblock %}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2012/04/overriding-change_form-html-and-accessing-the-object-instance/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>To all my Thinkpad friends running Linux</title>
		<link>http://overtag.dk/wordpress/2012/03/to-all-my-thinkpad-friends-running-linux/</link>
		<comments>http://overtag.dk/wordpress/2012/03/to-all-my-thinkpad-friends-running-linux/#comments</comments>
		<pubDate>Fri, 09 Mar 2012 10:28:00 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[thinkfan]]></category>
		<category><![CDATA[thinkpad]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=293</guid>
		<description><![CDATA[Hello there! A little tip that can really improve your battery life and give you peace of mind while working: Install thinkfan: A simple fan control program. Installation Here is how it goes on Ubuntu: Step zero is to become &#8230; <a href="http://overtag.dk/wordpress/2012/03/to-all-my-thinkpad-friends-running-linux/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hello there!</p>
<p>A little tip that can really improve your battery life and give you peace of mind while working: Install <em>thinkfan: A simple fan control program</em>.</p>
<h2>Installation</h2>
<p>Here is how it goes on Ubuntu: Step zero is to become superuser (<strong>sudo bash</strong>). Then you install the thinkfan package.</p>
<pre>~# apt-get install thinkfan</pre>
<p>Once the package is installed, you can try running it as a normal process to see how it works:</p>
<pre>~# thinkfan -n</pre>
<p>It will most likely give you an error because <b>fan_control=1</b> has not been set for the <b>thinkpad_acpi</b> module. You can enable fan control like this:</p>
<pre>~# echo "options thinkfan_acpi fan_control=1" > /etc/modprobe.d/thinkfan.conf
~# rmmod thinkpad_acpi
~# modprobe thinkpad_acpi</pre>
<p>In order to run thinkfan as an <b>upstart script</b> (actually rc.d), you should set <b>START=yes</b> in <b>/etc/defaults/thinkfan</b>.</p>
<pre>~# nano -w /etc/defaults/thinkfan</pre>
<h2>Customizing</h2>
<p>What thinkfan does is to turn the speed of your fan up and down according to the currently <em>highest</em> measured temperature of all your sensors. If you wish to see the temperature of your sensors, simply run:</p>
<pre>~# sensors</pre>
<p>Now it&#8217;s time to look in <b>/etc/thinkfan.conf</b>. Besides instructions, you&#8217;ll see this matrix at the bottom:</p>
<pre>(0,     0,      55)
(1,     48,     60)
(2,     50,     61)
(3,     52,     63)
(4,     56,     65)
(5,     59,     66)
(7,     63,     32767)</pre>
<p>The default settings are very safe, but if when running thinkfan, you get too much or too little fan activity, you can adjust the numbers. The first vector (0, 0, 55) says that whenever a sensor reaches 55C, the fan should step up one level. The second vector (1,48,60) says that if we are at level 1 and a sensor reaches down to 48C or below, we can step back to level 0, however if we reach 60C we should go to level 2 etc.<br />
<strong style="color: #C00"><br />
Please keep in mind that your hard drive temperatures are very important</strong>, and that you can add a line that automatically adds a safety value to those more sensible temperatures. For instance, to ensure that thinkfan is responsive to sensor value 5, we can add this adjustment vector:</p>
<pre>sensor /proc/acpi/ibm/thermal (0, 0, 0, 0, 0, 15, 0, 0, 0, 0)</pre>
<p>To identify which sensor number your hard drive has, go to <a href="http://www.thinkwiki.org/wiki/Thermal_Sensors">ThinkWiki</a> or run Disk Utility (System->Administration->Disk Utility), click your hard drive and click <b>SMART Data</b> to see the temperature of your hard drive.</p>
<h2>Troubleshooting</h2>
<p>If you have problems:</p>
<ul>
<li>Check that <b>/proc/acpi/ibm/thermal</b> exists, otherwise you might have to look for something else</li>
<li>If you run T420 (or some other model that uses the coretemp module), check out <a href="http://ubuntuforums.org/showpost.php?p=10866947&#038;postcount=9">mejo&#8217;s forum post</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2012/03/to-all-my-thinkpad-friends-running-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>django-cms 2.0.2 and Django 1.2 &#8211; 1.3</title>
		<link>http://overtag.dk/wordpress/2012/02/django-cms-2-0-2-and-django-1-2-1-3/</link>
		<comments>http://overtag.dk/wordpress/2012/02/django-cms-2-0-2-and-django-1-2-1-3/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 14:56:33 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[django-cms]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=280</guid>
		<description><![CDATA[If you are running an old version of django-cms, you can still upgrade Django. I would strongly suggest doing this since it&#8217;s very uncomplicated. However, if you are running django-cms 2.0, you should first upgrade to 2.0.2 and run the &#8230; <a href="http://overtag.dk/wordpress/2012/02/django-cms-2-0-2-and-django-1-2-1-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you are running an old version of django-cms, you can still upgrade Django. I would strongly suggest doing this since it&#8217;s very uncomplicated. However, if you are running django-cms 2.0, you should first upgrade to 2.0.2 and run the South migrations, which is also totally uncomplicated.</p>
<p>django-cms 1.x are most likely stuck on older versions of Django as well. I did once try to get them running on new Django versions but gave up.</p>
<p>Basically this guide just fixes a little bug in admin/pageadmin.py and a few issues regarding a missing csrf_token in the templates. It also means that django-cms 2.0.2 becomes SSL compatible. This is not backwards-compatible, however, so if you apply this stuff, your django-cms will no longer work with Django 1.1.</p>
<p>After upgrading to django 1.3.1 (also tested on 1.2.X btw), you need to make the following corrections manually in your django-cms installation.</p>
<p>1) Edit cms/admin/pageadmin.py, line 59 to say:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">    exclude = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></pre></div></div>

<p>2) Edit cms/templates/admin/cms/page/plugin_change_form.html, line 77, by adding the csrf_token tag:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form id=&quot;{{ opts.module_name }}_form&quot; action=&quot;{{ form_url }}&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;{% block form_top %}{% endblock %}
{% csrf_token %}</pre></div></div>

<p>2.1) Do the same in cms/templates/admin/cms/page/change_form.html, line 99:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form id=&quot;page_form&quot; action=&quot;?language={{ language }}{%if request.GET.target %}&amp;amp;target={{ request.GET.target }}{% endif %}&amp;amp;{%if request.GET.target %}position={{ request.GET.position }}{% endif %}&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;{% block form_top %}{% endblock %}
{% csrf_token %}</pre></div></div>

<p>2.2) Do the same in cms/templates/admin/cms/page/dialog/base.html, line 5:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">                {% block form %}{% if form %}&lt;form id=&quot;{{ dialog_id }}-form&quot;&gt;{% csrf_token %}{{ form.as_p }}{% endif %}{% endblock %}</pre></div></div>

<p>3) Ensure that you have CsrfViewMiddleware and CsrfResponseMiddleware installed. Your settings.py should contain something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">MIDDLEWARE_CLASSES = <span style="color: black;">&#40;</span>
    <span style="color: #483d8b;">'django.middleware.common.CommonMiddleware'</span>,
    <span style="color: #483d8b;">'django.contrib.sessions.middleware.SessionMiddleware'</span>,
    <span style="color: #483d8b;">'django.middleware.csrf.CsrfViewMiddleware'</span>,
    <span style="color: #483d8b;">'django.middleware.csrf.CsrfResponseMiddleware'</span>,
    <span style="color: #483d8b;">'django.contrib.auth.middleware.AuthenticationMiddleware'</span>,
    <span style="color: #483d8b;">'django.contrib.messages.middleware.MessageMiddleware'</span>,
    <span style="color: #483d8b;">'cms.middleware.page.CurrentPageMiddleware'</span>,
    <span style="color: #483d8b;">'cms.middleware.user.CurrentUserMiddleware'</span>,
<span style="color: black;">&#41;</span></pre></div></div>

<p>5) Finally, you need to bring in a file from later django-cms, csrf.js (<a href="https://github.com/divio/django-cms/blob/1dff25788a30b9e6e5c8cada405db60ae74764b7/cms/media/cms/js/csrf.js">github revision that I used</a>). Place it in media/cms/js/.</p>
<p>6) Add csrf.js to cms/admin/widgets.py in PluginEditor.media, around line 17:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">    <span style="color: #ff7700;font-weight:bold;">class</span> Media:
        js = <span style="color: black;">&#91;</span>join<span style="color: black;">&#40;</span>settings.<span style="color: black;">CMS_MEDIA_URL</span>, path<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> path <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: black;">&#40;</span>
            <span style="color: #483d8b;">'js/lib/jquery.js'</span>,
            <span style="color: #483d8b;">'js/lib/ui.core.js'</span>,
            <span style="color: #483d8b;">'js/lib/ui.sortable.js'</span>,
            <span style="color: #483d8b;">'js/csrf.js'</span>,
            <span style="color: #483d8b;">'js/plugin_editor.js'</span>,
        <span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></pre></div></div>

<p>7) Add this around line 97 in cms/media/cms/js/change_list.js:</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">	$(document).ready(function() {
		$.fn.cmsPatchCSRF();
	    selected_page = false;
	    action = false;</pre></div></div>

<p><span>8</span>) Do the same in cms/media/cms/js/plugin_editor.js at the first line:</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">$(document).ready(function() {
  	$.fn.cmsPatchCSRF();</pre></div></div>

<p>9) In /cms/templates/admin/cms/page/change_list.html you should also include csrf.js, around line 33:</p>
<pre class="js">&lt;script type="text/javascript" src="{{ CMS_MEDIA_URL }}js/csrf.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="{{ CMS_MEDIA_URL }}js/change_list.js"&gt;&lt;/script&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2012/02/django-cms-2-0-2-and-django-1-2-1-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stopforumspam Django Middleware</title>
		<link>http://overtag.dk/wordpress/2011/09/stopforumspam-django-middleware/</link>
		<comments>http://overtag.dk/wordpress/2011/09/stopforumspam-django-middleware/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 03:07:32 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=269</guid>
		<description><![CDATA[I have created a new Django app for keeping out spammers on the basis of data collected by stopforumspam.com. Read all about it here » It&#8217;s free, open source, and I hope people will make it better on github.]]></description>
			<content:encoded><![CDATA[<p><a href="http://overtag.dk/wordpress/wp-content/uploads/Screenshot.png"><img class="alignright size-thumbnail wp-image-272" title="Screenshot" src="http://overtag.dk/wordpress/wp-content/uploads/Screenshot-150x150.png" alt="" width="150" height="150" /></a>I have created a new Django app for keeping out spammers on the basis of data collected by stopforumspam.com. <a title="Stopforumspam Django Middleware" href="http://overtag.dk/wordpress/projects/stopforumspam-django-middleware/">Read all about it here »</a></p>
<p>It&#8217;s free, open source, and I hope people will make it better on github.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2011/09/stopforumspam-django-middleware/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automating stopforumspam.com ASAP (updated!)</title>
		<link>http://overtag.dk/wordpress/2011/09/automating-stopforumspam-com-updated/</link>
		<comments>http://overtag.dk/wordpress/2011/09/automating-stopforumspam-com-updated/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 19:06:41 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[stopforumspam.com]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=254</guid>
		<description><![CDATA[In case you need a quick way of getting rid of spammers on your apache server, use this method as a temporary solution until you find a better one. Please take not that it will evaluate EVERY SINGLE REQUEST through &#8230; <a href="http://overtag.dk/wordpress/2011/09/automating-stopforumspam-com-updated/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In case you need a quick way of getting rid of spammers on your apache server, use this method as a temporary solution until you find a better one.</p>
<p>Please take not that it will evaluate EVERY SINGLE REQUEST through a Deny policy in Apache&#8217;s mod_access &#8211; it does not halt your performance much if you&#8217;re just running a site with few requests. But I only suggest this solution as a temporary one until you have a better integration. I am currently working on a Django middleware that will only check the client&#8217;s IP address in case it is a POST request directed at a certain URL.</p>
<p>Since I&#8217;ve been told that Apache doesn&#8217;t use /etc/hosts.deny, you should probably use this method instead, unless you have a webserver that actually uses hosts.deny. Another method would be to add the IP addresses to iptables, if you&#8217;re running that &#8212; this is probably more efficient than using Apache configuration policies.</p>
<p>This method creates a file that you can include in httpd.conf (to cover ALL your virtual hosts). The overall goal is to avoid .htaccess files since they are evaluated at runtime. Thus, you won&#8217;t have to configure each site, and you save a but of CPU time.</p>
<ol>
<li>Copy the script below to a file on your server, eg. <strong>/usr/sbin/stopforumspam.py</strong>. You might want to read it quickly as it will pretty much explain itself&#8230;</li>
<li>Make the file executable, eg. <strong>chmod +x /usr/sbin/stopforumspam.py</strong></li>
<li>Add it to your crontab for automatic execution each night, eg. <strong>crontab -e</strong> and then insert the line <strong>0 0 * * * /usr/sbin/stopforumspam.py &amp;&amp; /etc/init.d/apache2 reload </strong></li>
<li>By default, we will ban an entire class C subnet if more than 5 IP addresses are in this space. You can configure this behavior by giving stopforumspam.py a single argument, ie. <strong>/usr/sbin/stopforumspam.py 10</strong> would mean that at least 10 IPs have to be within the class C subnet to qualify it for a ban.</li>
<li>By default stopforumspam.py creates <strong>/etc/apache2/stopforumspam.conf</strong> &#8211; you can change this by editing the script.</li>
<li>Add <strong>Include /etc/apache2/stopforumspam.conf</strong> to <strong>/etc/apache2/httpd.conf</strong> (Debian/Ubuntu).</li>
<li><strong style="color: #C00">Caution!</strong> Make sure that you DO NOT change the <strong>Order Deny,Allow</strong> option in VirtualHost directives or .htaccess files as this unblock the deny policies.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">zipfile</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span> <span style="color: #ff4500;">1</span>:
    SUBNET_THRESHOLD = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
    SUBNET_THRESHOLD = <span style="color: #ff4500;">5</span>
&nbsp;
DOWNLOAD_ZIP = <span style="color: #483d8b;">&quot;http://www.stopforumspam.com/downloads/listed_ip_7.zip&quot;</span>
ZIP_FILENAME = <span style="color: #483d8b;">&quot;listed_ip_7.txt&quot;</span>
&nbsp;
HTTPD_CONFIG_INCLUDE = <span style="color: #483d8b;">&quot;/etc/apache2/stopforumspam.conf&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># For security purposes we test that each line is actually an IP address</span>
IP_MATCH = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;^(<span style="color: #000099; font-weight: bold;">\d</span>+)<span style="color: #000099; font-weight: bold;">\.</span>(<span style="color: #000099; font-weight: bold;">\d</span>+)<span style="color: #000099; font-weight: bold;">\.</span>(<span style="color: #000099; font-weight: bold;">\d</span>+)<span style="color: #000099; font-weight: bold;">\.</span>(<span style="color: #000099; font-weight: bold;">\d</span>+)$&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
filename, headers = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlretrieve</span><span style="color: black;">&#40;</span>DOWNLOAD_ZIP<span style="color: black;">&#41;</span>
&nbsp;
z = <span style="color: #dc143c;">zipfile</span>.<span style="color: black;">ZipFile</span><span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>
ips = z.<span style="color: black;">read</span><span style="color: black;">&#40;</span>ZIP_FILENAME<span style="color: black;">&#41;</span>
&nbsp;
ips = ips.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Remove non-ip members</span>
ips = <span style="color: #008000;">filter</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> ip: IP_MATCH.<span style="color: black;">match</span><span style="color: black;">&#40;</span>ip<span style="color: black;">&#41;</span>, ips<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_ip_segments<span style="color: black;">&#40;</span>ip<span style="color: black;">&#41;</span>:
    segments_match = IP_MATCH.<span style="color: black;">search</span><span style="color: black;">&#40;</span>ip<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>segments_match.<span style="color: black;">group</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> convert_ip_to_number<span style="color: black;">&#40;</span>ip<span style="color: black;">&#41;</span>:
    numeric_value = <span style="color: #ff4500;">0</span>
    ip_segs = get_ip_segments<span style="color: black;">&#40;</span>ip<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span>:
      numeric_value += ip_segs<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: #66cc66;">*</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">255</span><span style="color: #66cc66;">**</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span>-i<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> numeric_value
&nbsp;
<span style="color: #808080; font-style: italic;"># Sort everything first</span>
ips.<span style="color: black;">sort</span><span style="color: black;">&#40;</span>key=convert_ip_to_number<span style="color: black;">&#41;</span>
&nbsp;
subnets = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> ip <span style="color: #ff7700;font-weight:bold;">in</span> ips:
    ip_segs = get_ip_segments<span style="color: black;">&#40;</span>ip<span style="color: black;">&#41;</span>
    key = <span style="color: black;">&#40;</span>ip_segs<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, ip_segs<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, ip_segs<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> key <span style="color: #ff7700;font-weight:bold;">in</span> subnets.<span style="color: black;">keys</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        subnets<span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span> = <span style="color: black;">&#91;</span>ip<span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        subnets<span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>ip<span style="color: black;">&#41;</span>
&nbsp;
final_list = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> subnet, subnet_ips <span style="color: #ff7700;font-weight:bold;">in</span> subnets.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>subnet_ips<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span> SUBNET_THRESHOLD:
        <span style="color: #808080; font-style: italic;"># Ban the whole subnet</span>
        final_list.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;.&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span>, subnet<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;.0/24&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        final_list = final_list + subnet_ips
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Lengh of original list: %d&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>ips<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Lengh of final list: %d&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>final_list<span style="color: black;">&#41;</span>
&nbsp;
apache_conf_file = <span style="color: #008000;">file</span><span style="color: black;">&#40;</span>HTTPD_CONFIG_INCLUDE, <span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#41;</span>
apache_conf_file.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
apache_conf_file.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;    Order Deny,Allow<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> entry <span style="color: #ff7700;font-weight:bold;">in</span> final_list:
    apache_conf_file.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;    Deny from %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #66cc66;">%</span> entry<span style="color: black;">&#41;</span>
&nbsp;
apache_conf_file.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
apache_conf_file.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2011/09/automating-stopforumspam-com-updated/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automating stopforumspam.com</title>
		<link>http://overtag.dk/wordpress/2011/09/automating-stopforumspam-com/</link>
		<comments>http://overtag.dk/wordpress/2011/09/automating-stopforumspam-com/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 22:33:40 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=251</guid>
		<description><![CDATA[THIS DOES NOT WORK WITH APACHE SINCE IT DOES NOT USE /etc/hosts.deny &#8211; See this post instead Use the following Python script to maintain a file in the hosts.deny syntax so that your Debian/Ubuntu box (or other Linux server) is &#8230; <a href="http://overtag.dk/wordpress/2011/09/automating-stopforumspam-com/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong><span style="color: #ff0000;">THIS DOES NOT WORK WITH APACHE SINCE IT DOES NOT USE /etc/hosts.deny<span style="color: #000000;"> &#8211; <a href="http://overtag.dk/wordpress/2011/09/automating-stopforumspam-com-updated/">See this post instead</a></span></span></strong></p>
<p>Use the following Python script to maintain a file in the hosts.deny syntax so that your Debian/Ubuntu box (or other Linux server) is kept undisturbed by forum spammers &#8212; COMPLETELY undisturbed, as the spammer is disallowed all access to the system.</p>
<p>1. Copy the script to a file on your server, eg. <strong>/usr/sbin/stopforumspam.py</strong><br />
2. Make the file executable, eg. <strong>chmod +x /usr/sbin/stopforumspam.py</strong><br />
3. Add it to your crontab for automatic execution each night, eg. <strong>crontab -e</strong> and then insert the line <strong>0 0 * * * /usr/sbin/stopforumspam.py</strong><br />
4. Add the path to the file containing the ip list to /etc/hosts.deny by inserting this line: <strong>ALL: /etc/hosts.deny.stopforumspam</strong></p>
<p>The script itself is here, modify it as you need.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">zipfile</span>
&nbsp;
DOWNLOAD_ZIP = <span style="color: #483d8b;">&quot;http://www.stopforumspam.com/downloads/listed_ip_7.zip&quot;</span>
ZIP_FILENAME = <span style="color: #483d8b;">&quot;listed_ip_7.txt&quot;</span>
&nbsp;
HOSTS_DENY = <span style="color: #483d8b;">&quot;hosts.deny.stopforumspam&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># For security purposes we test that each line is actually an IP address</span>
IP_MATCH = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\d</span>+<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\d</span>+<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\d</span>+<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\d</span>+&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
filename, headers = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlretrieve</span><span style="color: black;">&#40;</span>DOWNLOAD_ZIP<span style="color: black;">&#41;</span>
&nbsp;
z = <span style="color: #dc143c;">zipfile</span>.<span style="color: black;">ZipFile</span><span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>
ips = z.<span style="color: black;">read</span><span style="color: black;">&#40;</span>ZIP_FILENAME<span style="color: black;">&#41;</span>
&nbsp;
deny_file = <span style="color: #008000;">file</span><span style="color: black;">&#40;</span>HOSTS_DENY, <span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> ip <span style="color: #ff7700;font-weight:bold;">in</span> ips.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> IP_MATCH.<span style="color: black;">match</span><span style="color: black;">&#40;</span>ip<span style="color: black;">&#41;</span>:
        deny_file.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #66cc66;">%</span> ip<span style="color: black;">&#41;</span>
&nbsp;
deny_file.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2011/09/automating-stopforumspam-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Boycutt Paypal: Installing BitCoin on Ubuntu</title>
		<link>http://overtag.dk/wordpress/2011/07/boycutt-paypal-installing-bitcoin-on-ubuntu/</link>
		<comments>http://overtag.dk/wordpress/2011/07/boycutt-paypal-installing-bitcoin-on-ubuntu/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 19:30:01 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=245</guid>
		<description><![CDATA[BitCoin is a free and open currency that will exist safely and decentralized online. Read about it. This method is reported to work on 10.04 (Lucid), and I can confirm that it works on 10.10 (Maverick). I don&#8217;t yet know &#8230; <a href="http://overtag.dk/wordpress/2011/07/boycutt-paypal-installing-bitcoin-on-ubuntu/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>BitCoin is a free and open currency that will exist safely and decentralized online. <a href="http://www.bitcoin.org">Read about it</a>.</p>
<p>This method is reported to work on 10.04 (Lucid), and I can confirm that it works on 10.10 (Maverick). I don&#8217;t yet know about 11.04 (Natty).</p>
<ol>
<li>Open a terminal</li>
<li>Type:
<pre language="bash">sudo apt-add-repository ppa:stretch/bitcoin
sudo apt-get update
sudo apt-get install bitcoin</pre>
</li>
<li>To run BitCoin, navigate to <strong>Applications -> Internet -> BitCoin</strong>.
</ol>
<p>Also, remember there&#8217;s Flattr, too!</p>
<p><object width="640" height="390"><param name="movie" value="http://www.youtube.com/v/Um63OQz3bjo&#038;hl=en_US&#038;feature=player_embedded&#038;version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/Um63OQz3bjo&#038;hl=en_US&#038;feature=player_embedded&#038;version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2011/07/boycutt-paypal-installing-bitcoin-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using GtkBuilder and connect_signals</title>
		<link>http://overtag.dk/wordpress/2011/02/using-gtkbuilder-and-connect_signals/</link>
		<comments>http://overtag.dk/wordpress/2011/02/using-gtkbuilder-and-connect_signals/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 00:14:41 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[connect_signals]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[gtkbuilder]]></category>
		<category><![CDATA[pygtk]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=235</guid>
		<description><![CDATA[I have been hunting spontaneous crashes with errors from the C GTK libs. The errors looked somewhat like these: Warning: g_object_ref: assertion `G_IS_OBJECT (object)' failed gtk.main() Warning: instance of invalid non-instantiatable type `AtkSelection' gtk.main() Warning: g_signal_emit_valist: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed &#8230; <a href="http://overtag.dk/wordpress/2011/02/using-gtkbuilder-and-connect_signals/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have been hunting spontaneous crashes with errors from the C GTK libs. The errors looked somewhat like these:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Warning: g_object_ref: assertion `G_IS_OBJECT (object)' failed
  gtk.main()
Warning: instance of invalid non-instantiatable type `AtkSelection'
  gtk.main()
Warning: g_signal_emit_valist: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed
  gtk.main()
(...)
Warning: instance of invalid non-instantiatable type `'
  gtk.main()</pre></div></div>

<p>In most versions of GTK window decorators, this caused a crash &#8211; in a few lucky cases, it didn&#8217;t! My (wrong) assumption was that calling <strong>connect_signals</strong> was only of interest, if I actually had signal handlers to connect. This is also the case when looking at the docs. <a title="Go to PyGtk docs" href="http://www.pygtk.org/docs/pygtk/class-gtkbuilder.html#method-gtkbuilder--connect-signals" target="_blank">For instance</a>:</p>
<blockquote><p>The function connect_signals and variants thereof <del datetime="2011-02-22T23:44:27+00:00">can</del> MUST be used to connect handlers to the named signals in the description.</p>
<p>(&#8230;)</p>
<p>For each of handlers that cannot be found, a <code>RuntimeWarning</code> is issued.</p></blockquote>
<p>However, when the warning was issued, GTK would crash anyways. This behavior was most like caused by dereferencing and deleting GTK widgets, which caused GTK to look for an <strong>on_delete_event</strong> handler as some sort of default behavior. Since I have a program that adds and removes GTK widgets during runtime, my program needed to handle these signals, even if the event handler would simply be empty. To make a long story short, you should ALWAYS make sure to call <strong>connect_signals</strong> no matter what, as it will connect core event handlers that you may not be aware of. This is how it should look:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> YourObject<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        glade = add_from_file<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;x.glade&quot;</span><span style="color: black;">&#41;</span>
        win = glade.<span style="color: black;">get_object</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;window&quot;</span><span style="color: black;">&#41;</span>
        win.<span style="color: black;">show_all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #808080; font-style: italic;"># ALWAYS DO THIS:</span>
        glade.<span style="color: black;">connect_signals</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> on_delete_event<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #66cc66;">*</span>args<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">pass</span></pre></div></div>

<p>And even if the above may not fail, here is something that <em>will potentially</em> fail if you don&#8217;t connect the signals. Please beware, that using the same <strong>on_delete_event</strong> handler for two different objects is a bad strategy.</p>
<p>Always take care that widgets are removed and deleted, and that delete events may be invoked at very separate places in your application. You should also be aware that the python garbage collector could be the one initiating these events, causing those strange c library reference errors.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2011/02/using-gtkbuilder-and-connect_signals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Headaches over disabling/enabling services in Ubuntu?</title>
		<link>http://overtag.dk/wordpress/2011/02/headaches-over-disablingenabling-services-init-d-scripts-in-ubuntu-10-10/</link>
		<comments>http://overtag.dk/wordpress/2011/02/headaches-over-disablingenabling-services-init-d-scripts-in-ubuntu-10-10/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 13:02:53 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[init.d]]></category>
		<category><![CDATA[services]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[upstart]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=202</guid>
		<description><![CDATA[I&#8217;ve recently found myself trying to disable a service in Ubuntu 10.10 &#8212; problem was that every time I rebooted, it started anyways. The service I was trying to disable had changed from inetd to rc.d to Upstart during the &#8230; <a href="http://overtag.dk/wordpress/2011/02/headaches-over-disablingenabling-services-init-d-scripts-in-ubuntu-10-10/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently found myself trying to disable a service in Ubuntu 10.10 &#8212; problem was that every time I rebooted, it started anyways. The service I was trying to disable had changed from inetd to rc.d to Upstart during the past year or so, and I was looking all the wrong places.</p>
<p>The thing is, that you have to look for different ways that your service might be registered. Since Upstart has been only half-way integrated in 10.10, there are some different places you still have to look if the documentation isn&#8217;t clear about how the service is launched (and usually it isn&#8217;t). The following examples are for <em>disabling</em> services, as I think most services installed are automatically configured to run, and this is the task you&#8217;d be looking for&#8230;</p>
<p><strong>update-rc.d</strong></p>
<p>The old <em>System V</em> style of doing things is to call the <strong>update-rc.d </strong>command to disable any start-up links located in <strong>/etc/rcX.d/</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> update-rc.d NAMEOFJOB disable 0123456</pre></div></div>

<p>You should <span style="text-decoration: underline;">always</span> invoke this command, as it explicitly disables any start-up links that may reappear when Apt is doing updates to your programs. So don&#8217;t just go and delete the start-up links!</p>
<p><strong>/etc/init/yourjob.conf</strong></p>
<p>Another place to look is the configuration folder of jobs. Because all of these <em>.conf</em> files are loaded and if they contain a description of when to be run, then that command will be executed. Look for something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">start on <span style="color: #7a0874; font-weight: bold;">&#40;</span>filesystem
        and net-device-up IFACE<span style="color: #000000; font-weight: bold;">!</span>=lo<span style="color: #7a0874; font-weight: bold;">&#41;</span>
stop on runlevel <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">2345</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>In order to disable the job, you simply have to comment out the <i>start on</i> part, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#start on (filesystem</span>
<span style="color: #666666; font-style: italic;">#        and net-device-up IFACE!=lo)</span>
stop on runlevel <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">2345</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p><strong>inetd (OpenBSD style)<br />
</strong></p>
<p>Another common convention is to rename the .conf file to .disabled as Upstart only loads .conf files.</p>
<p>Some services are started in OpenBSD style, ie. their descriptions are found in <strong>/etc/inetd.conf</strong>, the <em>Internet superserver configuration database</em>.</p>
<p>The reason inetd is still used is basically historical. Back in the days, it was desired to save memory by not loading programs until there was a need for them. One thing inetd is still used for is to load ancient TFTP servers when a UDP request is made on the TFTP port (see /etc/services for a list of port aliases in Linux). This description looks like so, and you simply have to place a &#8216;#&#8217; in front of the line to disable it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">tftp           dgram   udp4    <span style="color: #7a0874; font-weight: bold;">wait</span>    nobody <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>tcpd <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>in.tftpd <span style="color: #660033;">--tftpd-timeout</span> <span style="color: #000000;">300</span> <span style="color: #660033;">--retry-timeout</span> <span style="color: #000000;">5</span> <span style="color: #660033;">--mcast-port</span> <span style="color: #000000;">1758</span> <span style="color: #660033;">--mcast-addr</span> 239.239.239.0-<span style="color: #000000;">255</span> <span style="color: #660033;">--mcast-ttl</span> <span style="color: #000000;">1</span> <span style="color: #660033;">--maxthread</span> <span style="color: #000000;">100</span> <span style="color: #660033;">--verbose</span>=<span style="color: #000000;">5</span> <span style="color: #000000; font-weight: bold;">/</span>srv<span style="color: #000000; font-weight: bold;">/</span>tftp</pre></div></div>

<p><strong>Other places&#8230;</strong></p>
<ul>
<li><strong>/etc/X11/Xsession.d/</strong> is the folder where scripts to be run when the X server is started are kept. I&#8217;ve never needed to change anything here, and I wonder why some things are kept in here and not explicitly run when switching to runlevel 5&#8230;</li>
<li>Gnome services can be disabled if you navigate to <em>System-&gt;Preferences-&gt;Startup Applications</em>. For instance, you can go here to disable the login sound (right?), Bluetooth manager (if you don&#8217;t use bt), some Evolution Alarm (since you don&#8217;t use Evolution, right?), Ubuntu One (don&#8217;t use neither) and Checking for new hardware drivers (since I guess you don&#8217;t constantly change hardware).</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2011/02/headaches-over-disablingenabling-services-init-d-scripts-in-ubuntu-10-10/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

