Ramblings from MostlyChris

Tech stuff and a bit more

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.

I recently was asked to allow access to a server's webmail. The problem was that there are no longer any domains pointed to the server. The solution, of course, was to connect to webmail via the IP address. Since this is a Plesk server, the following will allow access by IP.

Create a file in /etc/httpd/conf.d called zz012_horde.conf

Place the following in the file

<Directory /usr/share/psa-horde>
<IfModule sapi_apache2.c>
php_admin_flag engine on
php_admin_flag safe_mode off
php_admin_value open_basedir "/etc/psa:/usr/share/psa-horde:/usr/share/psa-horde/config:/tmp"
php_admin_value include_path "/usr/share/psa-horde/lib:/usr/share/psa-horde/pear:."
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
php_admin_value open_basedir "/etc/psa:/usr/share/psa-horde:/usr/share/psa-horde/config:/tmp"
php_admin_value include_path "/usr/share/psa-horde/lib:/usr/share/psa-horde/pear:."
</IfModule>
</Directory>
Alias /horde /usr/share/psa-horde

Restart apache and then access the file using the url http://ip.ad.dr.es/horde.

Ok.. so I am so going to plagiarize this but I needed a place to find it for easy reference. What better place than my blog. If psa fails to start after upgrade it is most likely a problem with a bug in the latest openssl package. Parallels has an update here:

http://kb.parallels.com/en/8338

Basically, you need to update the openssl package. Links for the various OS's are listed in the URL. Download the rpm, install it and then restart (or start) psa. Voila. Back to business as usual. I should also note that I experienced this in version 9.0.3 of Plesk. I don't know if it affects other versions.

HTML5

No comments

Today I begin my journey with HTML 5. I don't know how far I'll get until I get bored with it, but since it appears to be what we all might be moving to in the near future I am going to get some of it into my brain starting now.