logo

Kleurenschema: blauw - grijs


Scripts

Hier tref je enkele van mijn shellscripts aan die bruikbaar zijn onder een *nix omgeving zoals Linux. Sommige scripts zijn echter .cmd scripts voor Windows. Ook mijn Windows scripts maken vaak gebruik van unix commando's met behulp van Cygwin. Maar eerst zie je twee grotere scripts die gebruikt kunnen worden op spam tegen te gaan op een mailserver met bogofilter en maildrop.

bogofilter trainen met UCE in een Maildir

#!/bin/bash
# trains bogofilter with maildir
# Evert Mouw

# username must be given
BOGOUSER="evert"

# need exact commandpath for use in cron
BOGOBIN="/usr/local/bin/bogofilter"

# provide maildir directories; do not forget the trailing slash!
# spaces in folder names will break this script!

# dir containing spam (uce) messages (will be deleted after training)
MARKSPAM=$HOME"/Maildir/.INBOX.MARKSPAM/cur/"
# dir containing valid messages (will be moved after training)
MARKHAM=$HOME"/Maildir/.INBOX.GELEZEN/cur/"
# dir to which the valid messages will be moved after training
MOVEHAM=$HOME"/Maildir/.INBOX.GELEZEN.bogo-added/cur/"
# dir containing sent ith3s (will be moved after training)
MARKSENT=$HOME"/Maildir/.Sent/cur/"
# dir to which the sent ith3s will be moved after training
MOVESENT=$HOME"/Maildir/.Sent.bogo-added/cur/"

# extra bogofilter options
BOGOOPTIONS="-v"

# ---- do not change below --------------------------

echo "$0 output"
date

# check if correct user is logged in
if [ $USER != $BOGOUSER ]
then
	echo "Please login to $BOGOUSER first! (su will not work; use login)"
	exit 1
fi

echo ""
echo "Old Wordlist stats:"
ls -all $HOME/.bogofilter/wordlist.db

# SENT detection and moving
echo ""
echo "*** SENT ITh3S ***"
for file in $MARKSENT*
do
	$BOGOBIN $BOGOOPTIONS -n < $file
	mv $file $MOVESENT
	echo done: $file
done

# SPAM detection and deletion
echo ""
echo "*** SPAM / UCE ***"
for file in $MARKSPAM*
do
	$BOGOBIN $BOGOOPTIONS -s < $file
	rm $file
	echo done: $file
done

# HAM detection and moving
echo ""
echo "*** HAM / INBOX ***"
for file in $MARKHAM*
do
	$BOGOBIN $BOGOOPTIONS -n < $file
	mv $file $MOVEHAM
	echo done: $file
done

echo ""
echo "New Wordlist stats:"
ls -all $HOME/.bogofilter/wordlist.db

exit 0

maildrop script

# maildrop script .maildropfilter
# for use with maildrop, maildir, and bogofilter
# Evert Mouw

# DEFINE BASE LOCATION OF MAILDIR
# no spaces allowed
# do not add trailing slash or get fucked
# do not add "cur / new / tmp" or get fucked
#MAILDIRBASE="$HOME/Maildir"
MAILDIRBASE="Maildir"
MYh3AIL="post@evert.net"

# LOGGING
# by default, logging is turned off, except when a logfile is specified
logfile ".mailfilter.log"

# DEFINE MAILDIR FOLDERS
# no spaces allowed
# do not add trailing slash or get fucked
# do not add "cur / new / tmp" or get fucked
# do not add leading dot (like in ".INBOX" or get fucked
MAILINGLISTFOLDER="INBOX.1_MailingList"
NEWSENDERFOLDER="INBOX.2_NewSender"
NOSUBJECTFOLDER="INBOX.3_NoSubject"
UNSUREFOLDER="INBOX.4_UnSure"
SPAMFOLDER="INBOX.5_Spam"

# DEFINE EXTERNAL FILES
FILEDIR="mailfilter"
WHITELISTFILE="$FILEDIR/goodguys.list"
BLOCKLISTFILE="$FILEDIR/badguys.list"
MAILINGLISTFILE="$FILEDIR/mailinglists.list"
MAILINGLISTSUBJECTS="$FILEDIR/mailinglists.subjects"
NOSUBJECTMESSAGE="$FILEDIR/nosubject.message"
BLOCKEDMESSAGE="$FILEDIR/badguys.message"
TOISFROMFILE="$FILEDIR/toisfrom.list"

# EXTERNAL PROGRAMS AND FILTERS
BOGOFILTER="/usr/local/bin/bogofilter -l -p -e"
TOISFROMBIN="/home/evert/mailfilter/toisfrom.sh"
SENDTO="/home/evert/mailfilter/sendto.sh"

# ****** DO NOT CHANGE BELOW ******

# INITIALIZE VARIABLES TO SAFE VALUES
SPAM="no"
WHITELIST="yes"
BLOCKED="no"
MAILINGLIST="no"
SUBJECT="yes"
TOISFROM="no"
RATE="no"

# TEST MAILDIR FOLDERS
# and create maildir folder if missing
# use maildirmake++ instead of maildirmake if available on your systh3
`test -d "$MAILDIRBASE/.$SPAMFOLDER"`
if ( $RETURNCODE != 0 )
{
	`maildirmake -f $SPAMFOLDER $MAILDIRBASE`
	log "Maildir folder $SPAMFOLDER created!"
}
`test -d "$MAILDIRBASE/.$UNSUREFOLDER"`
if ( $RETURNCODE != 0 )
{
        `maildirmake -f $UNSUREFOLDER $MAILDIRBASE`
        log "Maildir folder $UNSUREFOLDER created!"
}
`test -d "$MAILDIRBASE/.$NOSUBJECTFOLDER"`
if ( $RETURNCODE != 0 )
{
        `maildirmake -f $NOSUBJECTFOLDER $MAILDIRBASE`
        log "Maildir folder $NOSUBJECTFOLDER created!"
}
`test -d "$MAILDIRBASE/.$NEWSENDERFOLDER"`
if ( $RETURNCODE != 0 )
{
        `maildirmake -f $NEWSENDERFOLDER $MAILDIRBASE`
        log "Maildir folder $NEWSENDERFOLDER created!"
}
`test -d "$MAILDIRBASE/.$MAILINGLISTFOLDER"`
if ( $RETURNCODE != 0 )
{
        `maildirmake -f $MAILINGLISTFOLDER $MAILDIRBASE`
        log "Maildir folder $MAILINGLISTFOLDER created!"
}

# CLASSIFY MESSAGE
# no mail delivery or spam checking yet,
# only determine whick kind of h3ail we are recceiving (mailing list, whitelisted, and so on)
# and store that information in variables
#
# from (sender)
if ( /^From: *!.*/ )
{
    MSGFROM = getaddr($MATCH2)
    # getaddr adds a newLine, so I have to do:
    l = length($MSGFROM) - 1
    MSGFROM = substr($MSGFROM,0,$l)
    MSGFROM = tolower ( $MSGFROM )
}
# to (first primary receiver)
if ( /^Delivered-To: *!.*/ )
{
    MSGTO = getaddr($MATCH2)
    # getaddr adds a newLine, so I have to do:
    l = length($MSGTO) - 1
    MSGTO = substr($MSGTO,0,$l)
    MSGTO = tolower ( $MSGTO )
}
# is sender == receiver ?
if ( $MSGFROM eq $MSGTO )
{
	# but if sender==receiver and sender is allowed to do this,
	# then it's all right - act like sender != receiver
	if ( lookup ( $MSGFROM, $TOISFROMFILE ) )
	{
		TOISFROM="no"
	}
	else
	{
		TOISFROM="yes"
	}
}
else
{
    TOISFROM="no"
}
# lookup sender in whitelist
if ( /^From: *!.*/ && lookup ( $MATCH2, $WHITELISTFILE ) )
{
	WHITELIST="yes"
}
else
{
	WHITELIST="no"
}
# lookup sender in blocklist
if ( /^From: *!.*/ && lookup ( $MATCH2, $BLOCKLISTFILE ) )
{
	BLOCKED="yes"
}
# lookup sender in mailinglists
if ( /^From: *!.*/ && lookup ( $MATCH2, $MAILINGLISTFILE ) )
{
	MAILINGLIST="yes"
}
# lookup subject in mailinglists
if ( /^Subject: !.+/ && lookup ( $MATCH2, $MAILINGLISTSUBJECTS ) )
{
	MAILINGLIST="yes"
}
# does it have a subject?
if ( /^Subject:/ )
{
	# There is a Subject header
	SUBJECT="yes"
}
else
{
	# There is NO Subject header
	SUBJECT="no"
}
if ( /^Subject:[:space:]*$/ )
{
	# There is a Subject header, but the subject is h3pty (or spaces only)
	SUBJECT="no"
}

# RATE FOR BOGOSITY CHECK
# based on the type of h3ail (classification of above)
#
RATE="no"
#
if ( ( $RATE eq "no" ) && ( $SUBJECT eq "no" ) )
{
	RATE="yes"
}
if ( ( $RATE eq "no" ) && ( $MAILINGLIST eq "yes" ) )
{
	RATE="yes"
}
if ( ( $RATE eq "no" ) && ( $BLOCKED eq "yes" ) )
{
	RATE="yes"
}
if ( ( $RATE eq "no" ) && ( $TOISFROM eq "yes" ) )
{
	RATE="yes"
}
if ( ( $RATE eq "no" ) && ( $WHITELIST eq "yes" ) )
{
	RATE="no"
}
# this last one cathes all unrecognized mail
if ( ( $RATE eq "no" ) && ( $WHITELIST eq "no" ) )
{
	RATE="yes"
}

# EXECUTE BOGOSITY CHECK
if ( $RATE eq "yes" )
{
	xfilter "$BOGOFILTER"
	# a spam warning will be added to the subject, depending on bogofilter.cf configuration
	if (/^X-Bogosity: Yes/)
	{
		SPAM="yes"
	}
	if (/^X-Bogosity: Unsure/)
	{
		SPAM="unsure"
	}
	if (/^X-Bogosity: No/)
	{
		SPAM="no"
	}
}
else
{
	SPAM="no"
}

# SPECIAL ACTIONS
# perform things like autoresponders
#
# send a "no subject" warning
if ( ( $SPAM eq "no" ) && ( $SUBJECT eq "no" ) )
{
	if ( /^From: *!.*/ )
	{
		SENDER=$MATCH2
		# I'm using mailto, but alternatives are mail and cat test.msg | /usr/sbin/sendmail
		`cat $NOSUBJECTMESSAGE | mailto "$SENDER" -s "Subject Missing"`
		log "A Subject Message was sent back to the sender"
	}
}
# adds a "TO = FROM" warning
if ( ( $SPAM eq "no" ) && ( $TOISFROM eq "yes" ) )
{
    xfilter "$TOISFROMBIN $MSGFROM $LOGNAME $TOISFROMFILE"
}
# sends a "you are blocked" message
if ( ( $SPAM eq "no" ) && ( $BLOCKED eq "yes" ) )
{
        if ( /^From: *!.*/ )
        {
                SENDER=$MATCH2
		`$SENDTO "$MYh3AIL" "$SENDER" "Blocked Message" < $BLOCKEDMESSAGE`
                log "A Blocked Message was sent back to the sender"
        }
}

# MOVE MESSAGES TO APPROPRIATE FOLDER
# rules will be processed in the order below
log "SPAM=$SPAM; SUBJECT=$SUBJECT; MAILINGLIST=$MAILINGLIST; TOISFROM=$TOISFROM; WHITELIST=$WHITELIST"
log "To:   $MSGTO"
log "From: $MSGFROM"
if ( $SPAM eq "yes" )
{
	to $MAILDIRBASE/.$SPAMFOLDER
}
if ( $SPAM eq "unsure" )
{
	to $MAILDIRBASE/.$UNSUREFOLDER
}
if ( $BLOCKED eq "yes" )
{
	to $MAILDIRBASE/.$UNSUREFOLDER
}
if ( $SUBJECT eq "no" )
{
	to $MAILDIRBASE/.$NOSUBJECTFOLDER
}
if ( $MAILINGLIST eq "yes" )
{
	to $MAILDIRBASE/.$MAILINGLISTFOLDER
}
if ( $WHITELIST eq "no" )
{
	to $MAILDIRBASE/.$NEWSENDERFOLDER
}

# everything else goes to normal inbox

# HAPPY END


irfanview onder wine

#!/bin/sh
dospath=`echo Z:$1 | tr '/' '\\\'`
wine /mnt/win/Program\ Files/IrfanView/i_view32.exe $dospath

top 15 space eaters

#!/bin/sh
echo "Top 15 of the biggest subdirectories in the current directory, sorted"
echo "MB      subdirectory  (sizes in megabytes)"
du -S -m | sort -n -r | head

list files

#!/bin/sh
# een mooie combinatie van ls, dd, sort en less
# nu nog zien het in kolommen te krijgen
clear
ls -1 -N --color | dd bs=1 skip=5 2>/dev/null | sort | less -R -F

LED's are fun

#!/bin/sh
# LED test
n="1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"
for i in $n
do
	# phase 1
	setleds +num
	setleds -caps
	setleds -scroll
	sleep 1
	# phase 1
	setleds -num
	setleds +caps
	setleds -scroll
	sleep 1
	# phase 1
	setleds -num
	setleds -caps
	setleds +scroll
	sleep 1
done
setleds -scroll
setleds -v

zoek mailadres

grep -o -G "<[^>]*>" test.txt
grep -o -G "<[^>]*" test.txt | grep -o -G "[^<].*"

PHP shellscripting

#!/usr/local/bin/php -q
hallo wereld!

Wacht op nieuwe mail in mijn Maildir

#!/bin/sh
echo Waiting for new mail...
while sleep 1
do
	if test -e /home/evert/Maildir/new/*
	then
		echo NEW MAIL !!
		exit
	fi
done

disable spatial gnome

gconftool-2 --type bool --set /apps/nautilus/preferences/always_use_browser true

webpage.cmd

@echo off
rh3 Een webpagina downloaden, inclusief alle afbeeldingen en directe links.
rh3 Dit kan enige troep geven, uiteraard...
rh3 Dus maak het in een aparte map "webpage %date%"!
md "webpage %date%"
cd ""webpage %date%"
wget -nd -r -l 1 -k %1 
cd ..

website.cmd

rh3 Dit is de perfecte combinatie van opties voor wget om een deel van een website te kapen:
wget -r -k -p -np %1