<?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>Sébastien Wains &#187; Scripts</title>
	<atom:link href="http://www.wains.be/index.php/category/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wains.be</link>
	<description>Linux, Open Source, VoIP and other stuff</description>
	<lastBuildDate>Fri, 03 Sep 2010 21:31:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Script : renew your IP automatically through your router web interface</title>
		<link>http://www.wains.be/index.php/2009/09/25/script-renew-your-ip-automatically-through-your-router-web-interface/</link>
		<comments>http://www.wains.be/index.php/2009/09/25/script-renew-your-ip-automatically-through-your-router-web-interface/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 23:18:55 +0000</pubDate>
		<dc:creator>Sébastien Wains</dc:creator>
				<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.wains.be/?p=805</guid>
		<description><![CDATA[A little background : If you are not interested in the explanation behind this, skip to the script section. OK, I&#8217;ve been using Scarlet ISP for my DSL connection for something like 5 years. My contract mentions I get a dynamic IP. The thing is, until two days ago, as long as my DSL router [...]]]></description>
			<content:encoded><![CDATA[<p><strong>A little background :</strong></p>
<p>If you are not interested in the explanation behind this, skip to the script section.</p>
<p>OK, I&#8217;ve been using Scarlet ISP for my DSL connection for something like 5 years.<br />
My contract mentions I get a dynamic IP.<br />
The thing is, until two days ago, as long as my DSL router remained connected, I was keeping the same IP.<br />
Scarlet didn&#8217;t mind until Belgacom ISP bought them.</p>
<p>If you are a residential customer, Belgacom do not want you to keep the same IP for extended period of time (and by extended, Belgacom mean &#8220;2 days&#8221;)&#8230; Unless you pay for the professional package, of course.</p>
<p>So Belgacom disconnect residential customers on purpose every 36 hours. You&#8217;ll note they don&#8217;t disconnect every 24 hours. Smart alec could disconnect and reconnect their modem at 4am and not be distracted by disconnections ever again.</p>
<p>With the 36 hour rule, whatever you do, you&#8217;ll be disconnected in the middle of the day once every two days, say goodbye to your SSH sessions, rsync backups, etc..</p>
<p>In order to avoid such problems, I came up with a little script that I run every night at 1am.</p>
<p>Basically, it goes through the web interface of my Linksys WAG200G, click the disconnect button, wait for 5 seconds and click the connect button.</p>
<p>The &#8220;challenge&#8221; was to figure out which variables I needed to pass in the POST request, for that I used the firefox addon &#8220;<a href="https://addons.mozilla.org/en-US/firefox/addon/966">Tamper data</a>&#8220;.</p>
<p><strong>The script :</strong></p>
<pre><code>#!/usr/bin/perl -w

use strict;
use warnings;
use LWP;
use HTTP::Request::Common;

our $ua = LWP::UserAgent-&gt;new;

$ua-&gt;request(POST 'http://LOGIN:PASSWORD@192.168.177.254/apply.cgi',
[submit_button =&gt; 'Status_Router', submit_type =&gt; 'disconnect',
change_action =&gt; 'gozila_cgi', wan_proto =&gt; 'dhcp', status_connection =&gt; '0']);

sleep 5;

$ua-&gt;request(POST 'http://LOGIN:PASSWORD@192.168.177.254/apply.cgi',
[submit_button =&gt; 'Status_Router', submit_type =&gt; 'connect',
change_action =&gt; 'gozila_cgi', wan_proto =&gt; 'dhcp', status_connection =&gt; '0']);</code></pre>
<p>My dad&#8217;s router (SMC 7908) was a bit trickier as it required to pass the complete header set and referer or it rejected the authentication, by the way I decided to give curl a try :</p>
<pre><code>#!/bin/sh

# First we need to auth with headers and referer.. Authentication is IP based so after auth we can access the router config from any browser
/usr/bin/curl -d 'pws=password' -H "Host:192.168.2.1" -A "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3" -H "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language:en-us,en;q=0.5" -H "Accept-Encoding:gzip,deflate" -H "Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7" -H "Keep-Alive:300" -H "Connection:keep-alive" -e "http://192.168.2.1/login.stm" http://192.168.2.1/cgi-bin/login.exe

sleep 3

# Now we can proceed, we only need to disconnect, the router reconnects automatically
/usr/bin/curl -d 'pvc=0' -d 'cur_if=11' -d 'disconnect=Disconnect' -H "Host:192.168.2.1" -A "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3" -H "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language:en-us,en;q=0.5" -H "Accept-Encoding:gzip,deflate" -H "Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7" -H "Keep-Alive:300" -H "Connection:keep-alive" -e "http://192.168.2.1/login.stm" http://192.168.2.1/cgi-bin/statusprocess.exe</code></pre>
<p>This is a very interesting link with reconnect scripts for a lot of routers : <a href="http://www.paehl.de/reconnect/Curl_search.php?router=firmware">http://www.paehl.de/reconnect/Curl_search.php?router=firmware</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wains.be/index.php/2009/09/25/script-renew-your-ip-automatically-through-your-router-web-interface/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script : ban a country under iptables</title>
		<link>http://www.wains.be/index.php/2006/01/16/script-generate-iptables-rule-that-will-ban-some-country-ip-ranges-to-access-your-machines/</link>
		<comments>http://www.wains.be/index.php/2006/01/16/script-generate-iptables-rule-that-will-ban-some-country-ip-ranges-to-access-your-machines/#comments</comments>
		<pubDate>Mon, 16 Jan 2006 11:55:41 +0000</pubDate>
		<dc:creator>Sébastien Wains</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Iptables]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.wains.be/?p=56</guid>
		<description><![CDATA[Let&#8217;s say you want to completely ban a country from accessing your servers.. E.g. : countries that have very shallow internet laws Note : in regards to Epe&#8217;s comment, this article has been updated with a newer script, which should be doing a better job. Please drop me a comment, I&#8217;d love to hear feedback [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you want to completely ban a country from accessing your servers..<br />
E.g. : countries that have very shallow internet laws</p>
<p><strong>Note : in regards to Epe&#8217;s comment, this article has been updated with a newer script, which should be doing a better job. Please drop me a comment, I&#8217;d love to hear feedback !</strong></p>
<p>This script will parse the RIPE database and generate the iptables rules automatically..</p>
<p><span id="more-56"></span></p>
<p>Download the script here : <a href="http://www.wains.be/pub/update_country_block_list">http://www.wains.be/pub/update_country_block_list</a></p>
<p>The output would look like this :</p>
<p><code>-A INPUT -s 62.217.192.0/18 -m state --state NEW -j DROP<br />
-A INPUT -s 62.231.64.0/18 -m state --state NEW -j DROP<br />
-A INPUT -s 80.74.48.0/20 -m state --state NEW -j DROP</code></p>
<p>Or like this if you just want blocks :</p>
<p><code>62.217.192.0/18<br />
62.231.64.0/18<br />
80.74.48.0/20</code></p>
<p>You can use the output with iptables or any other firewall</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wains.be/index.php/2006/01/16/script-generate-iptables-rule-that-will-ban-some-country-ip-ranges-to-access-your-machines/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Script : courier-imap virtual mail accounts listing</title>
		<link>http://www.wains.be/index.php/2006/01/16/script-courier-imap-virtual-mail-accounts-listing/</link>
		<comments>http://www.wains.be/index.php/2006/01/16/script-courier-imap-virtual-mail-accounts-listing/#comments</comments>
		<pubDate>Mon, 16 Jan 2006 09:59:10 +0000</pubDate>
		<dc:creator>Sébastien Wains</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.wains.be/?p=55</guid>
		<description><![CDATA[I made this little script to get a daily report of the usage of our virtual mailboxes at work, the POP3 server is courier-imap. I don&#8217;t need to run any quota on the accounts but I just want to make sure people regularly check their mailboxes. #!/bin/sh # Check storage used by virtual mail accounts [...]]]></description>
			<content:encoded><![CDATA[<p>I made this little script to get a daily report of the usage of our virtual mailboxes at work, the POP3 server is courier-imap.<br />
I don&#8217;t need to run any quota on the accounts but I just want to make sure people regularly check their mailboxes.</p>
<p><span id="more-55"></span></p>
<pre><code>#!/bin/sh

# Check storage used by virtual mail accounts under courier-imap

DOMAINS="domain1.be domain2.be"
TIMESTAMP=`date +%d/%m/%Y`

echo "REPORT DATE : $TIMESTAMP"
echo " "
for domains in $DOMAINS

do
echo "---------------------------"
echo "$domains"
echo "===================================================="
echo "Size               Accounts"
echo "---------------------------"
echo " "
du -h /var/spool/postfix/vmail/$domains/ --max-depth=2 -c | \
        egrep "\/var\/spool\/postfix\/vmail\/$domains\/[a-z]\/" | \
        sed -re "s/\/var\/spool\/postfix\/vmail\/$domains\/[a-z]\///g" | \
        egrep "[0-9]{2,3}M" | \
        awk '{print $1, "               ",$2}' | \
        sort -r

du -h /var/spool/postfix/vmail/$domains/ --max-depth=2 -c | \
        egrep "\/var\/spool\/postfix\/vmail\/$domains\/[a-z]\/" | \
        sed -re "s/\/var\/spool\/postfix\/vmail\/$domains\/[a-z]\///g" | \
        egrep "[0-9]{1}\.[0-9]{1}M" | \
        awk '{print $1, "       ",$2}' | \
        sort -r

du -h /var/spool/postfix/vmail/$domains/ --max-depth=2 -c | \
        egrep "\/var\/spool\/postfix\/vmail\/$domains\/[a-z]\/" | \
        sed -re "s/\/var\/spool\/postfix\/vmail\/$domains\/[a-z]\///g" | \
        egrep "[0-9]{3}K" | \
        awk '{print $1, "       ",$2}' | \
        sort -r

du -h /var/spool/postfix/vmail/$domains/ --max-depth=2 -c | \
        egrep "\/var\/spool\/postfix\/vmail\/$domains\/[a-z]\/" | \
        sed -re "s/\/var\/spool\/postfix\/vmail\/$domains\/[a-z]\///g" | \
        egrep -v "[0-9]{3}" | \
        egrep "[0-9]{2}K" | \
        awk '{print $1, "       ",$2}' | \
        sort -r

        echo " "
done</code></pre>
<p>Output looks like this :</p>
<pre><code>REPORT DATE : 17/01/2006

---------------------------
mac-s.be
====================================================
Size             Accounts
---------------------------

23M              admin
1.1M              admin
221K              admin
24K              admin

---------------------------
label-design.be
====================================================
Size             Accounts
---------------------------

20K              admin</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.wains.be/index.php/2006/01/16/script-courier-imap-virtual-mail-accounts-listing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script : check services status easily</title>
		<link>http://www.wains.be/index.php/2005/12/14/script-easily-check-services-status-easily/</link>
		<comments>http://www.wains.be/index.php/2005/12/14/script-easily-check-services-status-easily/#comments</comments>
		<pubDate>Wed, 14 Dec 2005 08:30:30 +0000</pubDate>
		<dc:creator>Sébastien Wains</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.wains.be/?p=50</guid>
		<description><![CDATA[Since arpwatch and spamassassin crashed for some unknown reasons (probably bugs) lately, I needed a tool that would monitor services status on a regular basis. I found Nagios http://www.nagios.org/ but it was not really what I needed. Indeed, Nagios can only monitor some specific services (usually services opening a tcp port) and it offered just [...]]]></description>
			<content:encoded><![CDATA[<p>Since arpwatch and spamassassin crashed for some unknown reasons (probably bugs) lately, I needed a tool that would monitor services status on a regular basis.</p>
<p>I found Nagios <a href="http://www.nagios.org/">http://www.nagios.org/</a> but it was not really what I needed. Indeed, Nagios can only monitor some specific services (usually services opening a tcp port) and it offered just way too many features, thus requiring a lot of dependencies and was not the easiest piece of software to install.</p>
<p>To do the job, I made this (very) little script that runs from a cron on a daily basis :</p>
<p><span id="more-50"></span></p>
<pre><code>#!/bin/sh

SERVICES_REGULAR="squid smb 3dm mysqld postfix frox dhcpd sshd spamassassin httpd courier-imap arpwatch xinetd"

echo "Services"
echo "========"
for services_regular in $SERVICES_REGULAR
do
/sbin/service $services_regular status | sed -re 's/(pid|\(|\)|[0-9]{2,}|\.\.\.|\ )//g;s/\is/ : /g'
done
/sbin/service named status | grep server | sed -re 's/server/named/g;s/is/:/g'
echo " "</code></pre>
<p>The output is :</p>
<p>Services<br />
========<br />
squid : running<br />
smbd : running<br />
nmbd : running<br />
3dmd : running<br />
mysqld : running<br />
master : running<br />
Frox : running<br />
dhcpd : running<br />
sshd : running<br />
spamd : running<br />
httpd : running<br />
arpwatch : running<br />
xinetd : running<br />
named : up and running</p>
<p>This should work on many Redhat flavors, if you take a look at the code, named doesn&#8217;t output a regular &#8220;service is (running|stopped)&#8221;, I needed to make a special line for this service</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wains.be/index.php/2005/12/14/script-easily-check-services-status-easily/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
