Ramblings from MostlyChris

Tech stuff and a bit more

mod_deflate allows apache to compress files and deliver them to browsers that can use compressed files. This saves on bandwidth and renders page loads faster. It's a fairly simple process to do this. You need to have write access to the apache config files and need to be able to create a new conf file. I am doing this on a Redhat server with Apache 2.2.3.

The first step is to make sure that mod_deflate.so is loaded in apache. You should see a line in httpd.conf similar to the following:

LoadModule deflate_module modules/mod_deflate.so

If that line does not exist, then you'll need to get the mod_deflate object file. It is generally included with apache so all you need to do is locate it on your server and load it using the correct path for where it is.

The next step is to create a config file to house the mod_deflate configuration. On my server the conf.d directory is where all such files are stored. Apache then loads files in that directory if they end in '.conf'. I created a file called mod_deflate.conf.

In my configuration, I chose to compress all files except images, files such as gzip, tar, etc. that are already compressed and PDF files (they are already fairly compressed). The configuration for that looks like this:

SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \
    no-gzip dont-vary
SetEnvIfNoCase Request_URI \
    \.(?:exe|t?gz|zip|bz2|sit|rar)$ \
    no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

I then skip browsers that have problems with deflate.

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

Finally, I set some logging to test with.

DeflateFilterNote Input input_info
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog /var/log/httpd/deflate_log deflate

Make sure you restart apache after this so the new configuration file is used. Check your deflate_log to see that it is working.

To create an autoresponder or vacation notice on a server using Postfix, I use procmail on an individual account basis. In order to do this, first create a .forward file in the user's home directory with the following (quotes are to be included).

"|IFS=' ' && exec /usr/bin/procmail -f- || exit 75 #tina_fp"

Create a .procmailrc file in the same directory with the following:

SHELL=/bin/sh    # for other shells, this might need adjustment

:0 Whc: vacation.lock
 # Perform a quick check to see if the mail was addressed to us
* $^To:.*\<$\LOGNAME\>
 # Don’t reply to daemons and mailinglists
* !^FROM_DAEMON
 # Mail loops are evil
* !^X-Loop: racktest@fauxpanels.com
| formail -rD 8192 vacation.cache

  :0 ehc         # if the name was not in the cache
  | (formail -rI"Precedence: junk" \
       -A"X-Loop: racktest@fauxpanels.com" ; \
     echo "Hi,"; \
     echo "I will be out of the office from Monday August 2nd to Friday August 6th. "; \
     echo "If you need assistance, please send an email to info@blah.com or call 1-800-555-1212."; \
     echo "-Tina"; \
    ) | $SENDMAIL -oi -t

.

Replace the echo statements with your own reply text.

Read the contents of a cert:

openssl x509 -text -in [cert file]

To be continued…

Tonight I learned something. Yep! Still learning after all this time. What did I learn? Well I'm glad you asked. I had an occasion to have to delete all emails that were marked as spam but only for accounts that were forwarded to another email address.

The players:
RHEL 4
Plesk
Qmail

The magic:

for i in `find ./ -name .qmail | xargs grep '^\&' | cut -d: -f1 | sort | uniq `; do grep psa-spam
c $i > /dev/null; if [[ $? -eq "1" ]]; then sed -i '1i | /usr/local/psa/bin/psa-spamc reject' $i; fi; done

That's all there is to it. Wait? What? You don't understand? Well let me break it down for you. Actually, let me summarize for you. Time constraints don't permit me to write all day on this.

The one-liner above finds all .qmail files that have a forward email address in them. The forward address is denoted by a '&' at the beginning of a line. The cut command then strips off the beginning of the line and only shows the name of the file and the directory it is in. Since it is possible that there may be more than one line with '&' in the .qmail file, we sort uniq so that we don't enter the psa-spamc line more than once. Next, we use grep to check for the line '/usr/local/psa/bin/psa-spamc reject'. If that line already exists, we don't want to add it again. Finally, we use 'sed' to place that line at the top of the .qmail file. That's it. All done!

Using awk, it is possible to extract a single table from a mysql dump file. You will need to know the name of the table you want AND the name of the table immediately after the table you want. I was able to find this info quicker than loading the whole dump file by going to mysql and looking at the table order and finding the table after the one I was looking for.

After getting the required information, apply some awk magic like such.

awk '/Table structure for table .firstTable./,/Table structure for table .secondTable./{print}' name_of_dump_file > output_file.sql

The awk statement above is printing all text from the location of the first match to the location of the second match. Matches are denoted by the text inside the forward slashes. In the above, search criteria one (starting point) is "Table structure for table .firstTable." and search criteria two (stopping point) is "Table structure for table .secondTable.". Make sure you replace "firstTable" and "secondTable" with the tables discussed earlier.

Check over your new output file and make sure it has the table you wanted and then you can import it using standard mysql commands.