Some useful custom SpamAssassin rules and settings – modify your own

 

I have a Linux server that I use for managing web sites, development work, etc.  In addition, I use it to host a mail server for two domains that I have had since 1993.  Because of their age, and the number of email addresses that were used on them over the years, they receive a LOT of Spam.  In order to manage this huge volume of SPAM, I use SpamAssassin, and a ton of custom rules in Postfix to minimize the amount of spam that ultimately reached my inbox.  

Here is a collection of score changes, and custom filters that I use.  These change on a fairly regular basis, as the Spammers are always making changes.  I will try and keep this updated fairly often.

If you have any questions on how to write a rule, or have a suggestion for a good one, leave a comment or email.  

score RAZOR2_CHECK 5
score BAYES_999 1.0
score BAYES_00 -4
score T_FREEMAIL_DOC_PDF 2
score DIGEST_MULTIPLE 5
score MPART_ALT_DIFF 5
score RCVD_IN_MSPIKE_L5 4
score URIBL_BLACK 5
score URIBL_DBL_SPAM 5
score DCC_CHECK 5
score PYZOR_CHECK 5

mimeheader ZIP_ATTACHED Content-Type =~ /zip|xls|docm|doc/i
describe ZIP_ATTACHED email contains a zip file attachment
score ZIP_ATTACHED 4.5
header CUSTOM_PHP_ID_SPAM X-PHP-Originating-Script =~ /class.php/
score CUSTOM_PHP_ID_SPAM 5

header CUSTOM_UNQ_ID_SPAM X-MC-Unique =~ /randcase/
score CUSTOM_UNQ_ID_SPAM 5

header CUSTOM_UA_ID_SPAM User-Agent =~ /Mutt/
score CUSTOM_UA_ID_SPAM 5

rawbody CUSTOM_GMAIL_SPAM /style\=\”color\:\#245dc1\;text\-decoration\:none\;/
score CUSTOM_GMAIL_SPAM 4

rawbody CUSTOM_WHATSAP_SPAM /background\:\#d9d9d9\;font\-family\:arial\;font\-weight\:normal\;font\-size\:11px\;color\:\#808080\;/
score CUSTOM_WHATSAP_SPAM 4

rawbody CUSTOM_FEDEX_SPAM /style\=\”text\-decoration\:none\;color\:\#4d148c\;\” alt\=\”Privacy policy\” title\=\”Privacy policy/
score CUSTOM_FEDEX_SPAM 4

body CUSTOM_FARGO_SPAM /FARGO\, ND 58103/
score CUSTOM_FARGO_SPAM 4

rawbody CUSTOM_INLINE_IMAGE /src=”cid:/
score CUSTOM_INLINE_IMAGE 5.5

rawbody CUSTOM_TRACKING_CODE /img src=”(.*)\.us(.*)\?email/
score CUSTOM_TRACKING_CODE 5.5

rawbody CUSTOM_ENDS_IN_GUID /[A-Za-z0-9]{8}[A-Za-z0-9]{4}[A-Za-z0-9]{4}[A-Za-z0-9]{4}[A-Za-z0-9]{12}$/
score CUSTOM_ENDS_IN_GUID 7.5

rawbody CUSTOM_ALT_IN_GUID /alt=”[A-Za-z0-9]{8}[A-Za-z0-9]{4}[A-Za-z0-9]{4}[A-Za-z0-9]{4}[A-Za-z0-9]{12}”/
score CUSTOM_ALT_IN_GUID 0.5

 


Building a custom version of Apache 2.4 on CentOS – Support for socket.io proxying

Last year I needed a way to create a specific Apache version that would support proper handling of proxying socket.io  connections to a Node client.  I had to hunt around, however here are some notes I created to get the version I needed built.

There are a lot of threads on the Internet that point to running Apache 2.4 on RHEL 6 as being a difficult setup. It’s actually quite easy, thanks to Apache’s wonderful packaging. Since Apache builds their source packages so they can easily be compiled into RPMs. (All of these steps were performed on a fresh installation of CentOS 6.6.)

First we need to install all of the tools for building RPMs and create the directory structure –

yum -y install rpm-build
mkdir -p ~/rpmbuild/{SOURCES,SPECS,BUILD,RPMS,SRPMS}

Let’s start by downloading the Apache Httpd sources and trying to compile –

cd ~/rpmbuild/SOURCES
wget http://www.gtlib.gatech.edu/pub/apache/httpd/httpd-2.4.4.tar.bz2

Now we can identify the missing dependencies and figure out how to continue –

# rpmbuild -tb httpd-2.4.4.tar.bz2 
error: Failed build dependencies:
    autoconf is needed by httpd-2.4.4-1.x86_64
    apr-devel >= 1.4.0 is needed by httpd-2.4.4-1.x86_64
    apr-util-devel >= 1.4.0 is needed by httpd-2.4.4-1.x86_64
    pcre-devel >= 5.0 is needed by httpd-2.4.4-1.x86_64
    openldap-devel is needed by httpd-2.4.4-1.x86_64
    lua-devel is needed by httpd-2.4.4-1.x86_64
    libxml2-devel is needed by httpd-2.4.4-1.x86_64
    distcache-devel is needed by httpd-2.4.4-1.x86_64

We have packages available for autoconf, pcre-devel, openldap-devel, lua-devel, and libxml2-devel. APR is included in RHEL and CentOS, but it’s unfortunately an old version, so we’ll have to recompile that too. distcache is often the problem people are reporting when installing Apache 2.4, but continue reading for a nice trick to make this easier.

Next, we’ll download the sources of all of the custom packages we need to compile for Apache (your versions may change) –

cd ~/rpmbuild/SOURCES
wget http://www.gtlib.gatech.edu/pub/apache/apr/apr-1.4.6.tar.bz2
wget http://www.gtlib.gatech.edu/pub/apache/apr/apr-util-1.5.2.tar.bz2

Each of these can now be easily used to create RPMs for installation. Let’s start with APR –

cd ~/rpmbuild/SOURCES
# Install apr dependencies
yum -y install autoconf libtool doxygen
rpmbuild -tb apr-1.4.6.tar.bz2
# Install our freshly build apr RPMs
rpm -ivh ~/rpmbuild/RPMS/x86_64/apr-1.4.6-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-devel-1.4.6-1.x86_64.rpm
# Install apr-util dependencies
yum -y install expat-devel libuuid-devel db4-devel postgresql-devel mysql-devel freetds-devel unixODBC-devel openldap-devel nss-devel
# For some reason this has failed for me once or twice, but completed successfully the next time.
rpmbuild -tb apr-util-1.5.2.tar.bz2
rpm -ivh ~/rpmbuild/RPMS/x86_64/apr-util-1.5.2-1.x86_64.rpm ~/rpmbuild/RPMS/x86_64/apr-util-devel-1.5.2-1.x86_64.rpm

Installing distcache on RHEL can be a pain, but we can take advantage of Fedora’s SRPM to get us started –

cd ~/rpmbuild/SRPMS
wget http://www.gtlib.gatech.edu/pub/fedora.redhat/linux/releases/18/Fedora/source/SRPMS/d/distcache-1.4.5-23.src.rpm
rpmbuild --rebuild distcache-1.4.5-23.src.rpm
rpm -ivh ~/rpmbuild/RPMS/x86_64/distcache-1.4.5-23.x86_64.rpm ~/rpmbuild/RPMS/x86_64/distcache-devel-1.4.5-23.x86_64.rpm

Now that we have apr and distcache taken care of, the Apache compilation and install is quite easy –

cd ~/rpmbuild/SOURCES/
# Install remaining httpd dependencies
yum -y install pcre-devel lua-devel libxml2-devel
rpmbuild -tb httpd-2.4.4.tar.bz2

Now you’re ready to install httpd, but you’ll get one last error –

$ rpm -ivh ~/rpmbuild/RPMS/x86_64/httpd-2.4.4-1.x86_64.rpm 
    error: Failed dependencies:
        /etc/mime.types is needed by httpd-2.4.4-1.x86_64

Let’s find out which package provides that file –

$ yum whatprovides "/etc/mime.types"
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: ftp.osuosl.org
 * epel: ftp.osuosl.org
 * extras: ftp.osuosl.org
 * updates: ftp.usf.edu
mailcap-2.1.31-2.el6.noarch : Helper application and MIME type associations for file types
Repo        : base
Matched from:
Filename    : /etc/mime.types

We’re finally ready to install httpd –

yum -y install mailcap
rpm -ivh ~/rpmbuild/RPMS/x86_64/httpd-2.4.4-1.x86_64.rpm

Now you’re all ready to go with Apache 2.4! And since you’ve built proper RPMs, you’re also ready to deploy the packages out to all of your servers.

ProxyPass        /    ws://localhost:8080/
ProxyPassReverse /    ws://localhost:8080/
ProxyPass        /    wss://localhost:8080/
ProxyPassReverse /    wss://localhost:8080/

ProxyPass        /  http://localhost:8080/
ProxyPassReverse /  http://localhost:8080/

 

This works

RewriteEngine on

    RewriteCond %{QUERY_STRING} transport=polling
    RewriteRule /(.*)$ http://localhost:$port/$1 [P]

    ProxyRequests off
    ProxyPass /socket.io-client/ ws://localhost:$port/socket.io-client/
    ProxyPassReverse /socket.io-client/ ws://localhost:$port/socket.io-client/

    ProxyPass / http://localhost:$port/
    ProxyPassReverse / http://localhost:$port/


How to add DRL and LED to your Miata NA.

girl fixing a miata

As I have been daily driving my 1994 Miata NA for the last year or so, I have been more cognisant of trying to make the little Miata more visible. We also have a lot of divided highways out this way that require headlights to be on, and the police enforce it. I hate raising the barn doors, and if I just turn on my parking lights, they don’t really do much, and I always forget that I left them on.

So, I decided to get a couple of smoked replacement lights ($50 on Amazon for a pair), and modify them. I opened up the unused half of the light and used a LED for the parking and turn signal, and used the main bay with a H11 LED.  If you follow along, I will show you what you need to do to make this work.  In addition, you can easily wire in a relay to make your parking lights come on whenever the car is running.

First get some of these nice smoked turn signal assemblies.

IMG_1783

Then buy a set of 3157 parking and turn signal bulbs, I like these, and get this pigtail harness.  I also used H11 LED bulbs as the main DRL, I got these, and also the pigtails.  What we are going to do is open up the normally closed section on the parking light assembly.  I used a soldering iron to melt it out.   Once you get a good fit, a glob of silicone sealant will hold them in place and seal the opening from moisture.

IMG_1781

You will now need to wire the lights up.  This will vary by pigtail, lights, and assembly, but in general you will want to wire red to red and black to black.  The blue for the turn signal light will connect with the turn signal light coming from your original parking light wiring.  This is all pretty simple, leave a message if you have any issues.

IMG_1782

As you can see, it worked out pretty well. I wired in a relay that turns them on whenever the the car is in Run, instant DRL. I also wired the side markers to flash with the turn signals.

IMG_1784

 


How to Repair a Lotus Switch Pack – Or, why don’t my Elise’s parking lights work?

LotusGirl

Odds are you are either reading this page because your Lotus parking lights suddenly stopped working and you don’t know why, or you already know you need to replace or repair you Lotus Switch Pack.  That is great, because either way I will help you solve your problem.

I normally do not drive the Lotus that often in the Winter, and sometimes it can sit for a month or so with no venture outside.  This Winter was no different, and in addition, I had to get it moving at the beginning of March because I needed to get it emission tested.  That all went great, however when driving home I went to turn on the parking lights because it was misting slightly.  Imagine my surprise when the parking lights refused to turn on.  However, everything else worked, headlights, flashers, hazards, etc.  After looking at the schematics, it looked like Fuse F6 could be the issue.  I checked it, but it was fine.

Ok, this was not going to be a simple fix.  Maybe the switch was bad?  Remove the panel on the left that holds the switches, two screws on bottom, swap headlight switch connector and parking light connector.  As expected, parking light switch would turn on the headlights, so the problem was not the switch.   This panel is displayed below, the two green connector at bottom left are the ones you want to swap.

IMG_1721

After some more reading, and reviewing the Elise electrical schematic, it became pretty obvious the issue was the infamous Lotus Switch Pack pictured below!

IMG_1729

So, where is this Lotus Switch Pack located?  It is mounted on the steering column behind the instrument cluster.  Some online guides will tell you need to remove the full dash to get to it, however that is not true.  You can get to this by removing the cluster cover, unbolting the instrument cluster, and moving it out of the way.  Here is how you do it.

IMG_1726

First, remove (4 or 6 screws depending on if car was built on a Monday or Wednesday) the bottom cover around steering wheel.  One or two screws on each side, and two screws on the bottom.  Remove the top and bottom cover.  Then, you need to remove the instrument cluster housing.  This part sucks.  Remove two screws on each side.  The back of the cluster is just velcroed in place, yep 50K car uses velcro…  That part is easy, just lift up slightly.  The next is hard.  You need to pull the whole cluster back straight to release clips holding it on.  This requires pulling hard, if it does not come out, pull harder.  Take your time, and try not to crack anything.

It should look like the below when all is removed.

IMG_1725

I did not get a picture of the unit installed, but imagine in the picture below it is connected to those two connectors, and is mounted vertically with a screw on each side.  That part is easy, remove two screws, release the connectors.  There is a tab in center of connector you need to hold down while pulling carefully on connector.  Wiggle as needed.

IMG_1723

Success, you now have the Lotus Switch Pack module in your hands.  At this point, you have two choices, you can either simply buy a replacement, or you can attempt a repair.  If you decide to buy a replacement, you will need to search for the proper unit.  My 2005 Lotus was part number C117M0008f.  This has actually been superseded by two newer model numbers, D117M0008f was used in some later models, and E117M0008f appears to be the current replacement model.  I was able to find new versions online for between $160-$250.

However what if I told you that you could repair the unit for free? Worst case, for less than $25.  So, how do you do this?  Read on.

Inside the Lotus Switch Pack are two little relays, and one of them is preventing your parking lights from working.  The other relay is installed for the factory fog lights, which in many cases will not be installed on your Lotus.  You will know because you will have a fog light switch below the headlight switch.  If you don’t have fog lights, you can simply swap relays and solve your parking light issue.

IMG_1730

If you remove the switch pack module cover, you will see the guts of the unit.  On the top are relays, which are soldered below.  If you look carefully below (taken after removing the fog light relay), you will see five empty holes.  These are the five connections that you need to desolder.

IMG_1731

The picture below shows the relays.  The one in the center is the fog light relay, the parking light relay is directly below.  You will need a desoldering vacuum pump and/or desoldering wick.  Carefully remove ALL the solder from the relays and gently rock them loose.  There is some sticky substance that causes the relays to adhere to the board, be careful as it is easy to damage the relay when removing.  In fact, my guess is there is a 50/50 chance that it WILL be damaged, so be prepared to have to replace the relay.  If you email me or leave a comment with your contact info, I can provide replacements that WILL work with your unit for $25.  If you purchase on your own, be careful of your source, as it appears there are a lot of used units on eBay that will not work.

IMG_1732

How do you know if your relay is good or bad?  If you measure the coil with your ohmmeter, it should have a value between 120-140 ohms.  The proper pins to  test are the outer pins of the three in a row.  In picture below, it would be the pins that go into the three holes in the center.  Here you can see that I have removed the fog light relay, and replaced the parking light relay with a new unit.

IMG_1733

Connect the unit back up, and if you press the button, you should hear the relay click, and you now have parking lights!

IMG_6322

Put everything back together in the reverse order, and have a cold one.  Think about the $750 you saved by not going to the dealer, and leave a comment with your success story.  If you have any questions on the process, connect me and I will see what I can do to help you out.  Good Luck!

IMG_6321


How to fix your snapping, popping, sparking microwave oven – replace waveguide easily

audrey_hepburn_checking_the_oven

So there I was the day after Thanksgiving…  The previous evening we enjoyed a yummy dinner of turkey, mashed potatoes, and gravy.   Now we all know that Thanksgiving leftovers are the best.  I quickly grab some turkey meat, pour some gravy on them, and pop them in the microwave for a quick reheat.  Imagine my surprise when I suddenly hear a loud crackle sound, and then a boom coming from the microwave.  Looking over, I even see some flashes of light coming from within the oven.

Now, I have a Sharp R-520KS microwave, but it turns out the problem I was experiencing is pretty common to all microwave ovens.  Within the microwave oven there is a device call the waveguide.   This is a hole  inside of the microwave that focuses the microwaves into the oven.  And over this hole is a cover which is made from mica paper.

Over time, this cover will collect food and crud on it, and eventually it will start to arc, if it gets bad enough, you will experience the same fireworks inside your oven that I did.  It is recommended that you try to keep it clean, but eventually it will probably need to be replaced.  Official replacements are often not cheap, and if you have an older oven, may no longer be available.

Luckily it is fairly easy to buy a sheet of mica paper and cut it yourself to match your existing cover.  I bought mine from Amazon (click on link below), and carefully traced the existing cover onto the paper.  Use a sharp knife, or scissors to cut out the new pattern.  Simply pop your new cover into place, and your microwave will be ready for many more years of service.

img_1563


How do you extract POST form data and file uploads in node.js?

 

laptop_shutterstock_119563954

One of the most common tasks in creating a Node web server is handling GET and POST calls.  GET calls are fairly straightforward, however POST calls are more involved.  POST form data and POST file uploads provide the ability for a web client to upload enormous amounts of data to your server.  Proper safeguards must be put into place to insure that your server does not crash if it runs out of resources required to handle a POST of unlimited size.

Many of the common Node frameworks, like Express, provide an abstraction layer that allows you to more easily access POST data.  However, if you are rolling your own web server in Node, you will need to handle this with your own code.  The example below will allow you to do so.

var http = require('http');
var querystring = require('querystring');

function receivePost(request, response, callback) {
    var queryData = "";
    if(typeof callback !== 'function') return null;
    request.on('data', function(data) {
         queryData += data;
         if(queryData.length > 6e6) { // limit uploaded data to 6M
             queryData = "";
             response.writeHead(413, {'Content-Type': 'text/plain'}).end();
              // Kill connection if over 6M of data received
             request.connection.destroy();
         }
     });

    request.on('end', function() {
        // Parse the final result and save as request.post
        request.post = querystring.parse(queryData);
        callback();
    });
}

http.createServer(function(request, response) {
    if(request.method == 'POST') {
        receivePost(request, response, function() {
            console.log(request.post);
            
            // This section is where you would process the result of receivePost

            response.writeHead(200, "OK", {'Content-Type': 'text/plain'});
            response.end();
        });
    } else {
        response.writeHead(200, "OK", {'Content-Type': 'text/plain'});
        response.end();
    }

}).listen(3000);

Wherever you are handling POST requests, just simply pass the request and response fields to receivePost.  This function will collect the incoming data, and it to a working variable, and insure that it does not exceed 6MB of data (easily changed if you want to allow more or less).  When it returns, request.post will contain the POST data object that you can then manipulate and process as required.