Setup Web Dev Env in MacBook

Since Apple’s MacBook notebook uses OS/X that is built on top of Unix, it’s very like a server environment (while in Windows, we need to install something like Cygwin). So we can use this as a development environment. The problem is that it’s not so apparent to find where and how Apple organizes the things. For web development, it’s as follows:

Apache2

Apache2 is pre-installed.

  • script: apachectl (in path)
  • config: /etc/apache2/*
  • htdocs: /Users/<user_id>/Sites
  • URL: http://localhost/~user_id/
  • log: /var/log/apache2/*

PHP

PHP 5 is also pre-installed, we need to enable it in Apache’s config file: uncomment the line with ‘php’:

LoadModule php5_module        libexec/apache2/libphp5.so

add php type in “<IfModule mime_module>” block as follows:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Restart Apache, we can pass the php test by creating a test.php as follows and put it in ‘Sites’ dir:

<?php phpinfo(); ?>

Perl & CGI

Now comes the good-old Perl CGI. According to Apache’s configuration, the CGI dir is “/Library/WebServer/CGI-Executables”, it’s mapped to URL “http://localhost/cgi-bin”. To make it easier, we can create a soft link in home dir:

ln -s /Library/WebServer/CGI-Executables Cgi

Now it can be tested with following script:

#!/usr/bin/perl -wT

print "Content-Type: text/plain\n\n";

print "Hello CGI!\n";

mod_perl

Add following lines in proper  places:

 # load it
 LoadModule perl_module        libexec/apache2/mod_perl.so

# add a place to test mod_perl scripts
 ScriptAliasMatch ... (omitted, refer to the CGI one)

 <Directory "/var/www/cgi-bin/mod_perl">
 SetHandler perl-script
 PerlHandler ModPerl::Registry
 Options +ExecCGI
 PerlOptions +ParseHeaders
 </Directory>

Now we are pretty much done. The only remaining thing that is good to have is MySQL…

Published
Categorized as IT

Grab the Internet Trouble Makers!

There are a lot of people trying to crack or spam others’ web sites (in vain)… What they usually do can be categorized into two types: one is trying to post their articles (usually advertisements for drugs and so on) automatically to a lot of forums; the other one is trying to download files that the web masters might put there carelessly (for example, *.mdb, web.zip, etc.).

I don’t care about this too much, unless they keep doing this all the time, which consumes my band width. In order to grab them out and filter their requests out using a firewall, I did the follows:

First, in Apache’s configuration file, filter all these suspecious requests into a separate log file. For example, I am using Apache in Linux, but if someone requests for /forum/post.asp, or /data.mdb, then it’s for sure that they are from crackers or spammers. I put all of these in a file called worm_log (these things used to be from worms…).

Then I wrote a small script to calculate the number of hostile requests:

#!/bin/sh

allIPFile=/tmp/ips.txt
ipListFile=/tmp/ip_list.txt

myTmpFile=/tmp/mytmp.txt

cat worm* | cut -d ' ' -f 1 | sort > $allIPFile

cat $allIPFile | uniq > $ipListFile

lines=`cat $ipListFile`

rm -f $myTmpFile > /dev/null 2>&1

for ip in $lines ; do
        n=`grep $ip $allIPFile | wc -l`
        echo "$ip: $n" >> $myTmpFile
done

cat $myTmpFile | sort -nr -k 2,2 > spammers.txt

The output is something as follows:

222.73.173.10: 404
58.215.65.183: 355
222.73.173.11: 351
210.83.81.80: 314
121.14.212.82: 140
118.102.26.197: 117
221.231.114.10: 56
221.5.6.198: 48
...

Now we are very clear about who are the top trouble makers and should be blocked out of the firewall.

Published
Categorized as IT Tagged ,