How to fix “Mailbox in Use” Error in DirectAdmin

July 25th, 2008

Today I went back from my short trip to the country. First of all I decided to check my mail, and when I did it, I got the following error in my E-mail client: !25.07.2008, 19:20:39: FETCH  -ERR [IN-USE] Mailbox in use. That’s not the first time when such an error happens and I already know the solution - I think it’ll be useful for all server administrators (By the way, It’s Sysadmin’s day today).

When you get the message that mailbox is used, you must have some lock files, that prevent using locked mailboxes. It is not so easy to find out the reason why these files appear (If you know, just write about it in comments). The solution is obvious - to find and destroy these files.

Mailbox lock files are usually located at /var/spool/virtual/. You fill find domain name folders there and your e-mail account lock files should be right there. Just check them.  I usually use locate to find these files - their number shouldn’t be big.

After you delete these files, your mailboxes will start working as usual.

Free Software to Create Web Page Screenshots

July 22nd, 2008

Do you know Snap.com? If you don’t I’d encourage you to visit it as their tools make web much better. Even if I don’t like Ajax and Javascript tools, that often overload sites, I consider having site screenshots is a very good idea. But… where to take these shots and how to do them? If you try to do this manually, you’ll have to press print screen, then to run paint, then save the image, then rename it… Hard work, isn’t it?

If you want this for one site and want to see what’s shown to user in different browsers, then browsershots.org will be great for you. This service allows to take screenshots with different browser - this is the most comprehensive tool related to page screens I’ve seen on the Web.

There is also a Windows software that allows to do this. It’s Thumbnail Grabber. Thumbnail Grabber is a free utility for creating thumbnail screenshots of web pages in JPEG format. You can choose web page size (width and height) and thumbnail image size (in percent of the web page size). The program can batch process URLs and domains from a text file that makes it extremely useful for sites that have reviews or galleries, etc.

Now the process of Image creation is very simple. All you have to do is to have a list of web pages to crawl and Thumbnail Grabber will do everything for you. Nice that it doesn’t capture any browser elements, so your screenshots are clear and look great

Awstats and Directadmin - Now Supported Officially

July 22nd, 2008

Today I have updated my Directadmin installation and found that version 1.322 has appeared a few days ago.  One of most intersting features I found was awstats support. I’ve been using awstats plugin for a while and now it is integrated in DirectAdmin.

In order to add awstats support to your Directadmin installation you have to perform some simple steps:

cd /usr/local/directadmin/scripts
./awstats.sh

This will do several things.
- download and install the awstats setup.
- add awstats=1 to your directadmin.conf
- add webalizer=0 in your directadmin.conf (webalizer will be shut off, you can override it if you want both)

Webalizer stats are quite simple and not so informative as awstats data is. You will have some log changes, but this should not affect your server performance. You can read more about this at DirectAdmin official site.

How to Create a db4 Database from a Text File or Array

July 21st, 2008

When you need to deal with big amounts of data, MySQL is not a good solution. db4 is much faster and easier - you don’t need any SQL queries to extract the necessary values and use them. The process of db4 file creation is quite easy; you need to have your PHP compiled with dba support. If you don’t know how to do it, you can find it on my blog: dba support for PHP

If you have a text file, you need to have your values arranged. The best way to do this is to start each key-value pair with a new line. This way you will easily explode your strings into little arrays and then add them to your db4 database. The code is here:

<?
// Let’s  create our db4 file - you should have all the necessary permissions to do it.
$id=dba_open(’./baza.db’, ‘c’, ‘cdb’);
dba_close($id);
// Opening for writing
$id=dba_open(’./baza.db’, ‘w’, ‘db4′);
// Here is an array with keys and values (you may get it from your text file or using any other

// convenient way for you
$positions=array(”some key”=>”some value”);
// We’re inserting these values into our db4 database.
foreach ($positions as $key=>$value)
{
dba_insert($key, $value, $id);
}
// Optimizing our database file
dba_optimize($id);
// That’s all. We can close it
dba_close($id);

?>

We have created a db4 file that should have bigger size than the initial txt file. Next tim I will show you how to access your db4 file and how to extract values from it.

How to Validate a Google Sitemap

July 20th, 2008

I hope you know what is Google sitemap and what it is used for. If not, you might want to read about it at Google site. There are a plenty of services and scripts that allow to create a sitemap for your site and it is not so hard to create your own script for this (maybe I will show you the code some later). When it is created, you are welcome so submit it to your Google Webmasters section. But it is important to check it against errors before submitting and it is a good practice to have it valid.

You may need to study sitemap protocol specifications. Some characters should be escaped before putting them in an xml file. But how to check whether your sitemap is valid or not?

I am using an online service that allows to check the sitemap without uploading it - all you need is just to have it on your server.  Let’s go to the page of Free Google SiteMap XML Validator and check our sitemaps. If something is wrong, you will receive a message where even number of error string will be shown.  I greatly recommend you to study that web site - t has lots of useful information on sitemaps, more than I can write here.

Now you can be sure your sitemaps are valid. Smart IT Consulting also allows you to submit your sitemaps, so I consider it’s a great resource.

How to Block Outgoing Connections using iptables

July 19th, 2008

Sometimes you should prevent outgoing connections from your server. The best way to do it is to use Linux system options, especially ipchains and iptables. I will show you how to do it using iptables, as this is the shortest way I know.

In order to block outgoing connections from your server to one IP issue the following command using command line:

iptables -A OUTPUT -d <IP Here> -j DROP

You can add whole subnets using this command. For example, if you need to block a subnet, the command will look like:

iptables -A OUTPUT -d 192.168.0.0/16 -j DROP

This will block all IPs from 192.168.x.x.

You might want to use the same method with incoming connec6tions. All you need to know is the IP range you need to block. You should just change OUTPUT to INPUT in the command above.

How to Change Owner of Files Created by Apache

July 18th, 2008

If you manage any script that creates files on the server, you might meet the prob;em that you cannot edit files created by this script. This is especially related to PHP scripts, that, for example, create some text files in a folder. When you try to open these files via your FTP client, you will most probably receive “Permission Denied” error when you try to save your changes.

When you run your PHP scripts, that are creating files, they almost in all cases are started by user Apache. This user has all the permissions on the created files. So we have Apache as an owner and Apache as the Group. That’s why we don’t have access to these files - we simply don’t own them.

I know two different solutions for this problem. The first one is quite intelligent - to use suphp. This is an Apache module, that allows to run php by the user that initially owns the executed file. That’s a great solution as it is done for entire server and all users’ scripts will be affected.

Another solution is not so beautiful, It’s a “patch” for scripts that are actually running. If you don’t have suphp installed or don’t want to install it for any reason, you can use root crontab to chown files created by your scripts. For example, we will recursively chown a folder where script generated files are located. Just add the following line to your root crontab:

*/10 * * * * chown user:user /folder_to_chown

This is not quite a good idea but I don’t know any other solutions at the moment.

How to Add a Directory to Your Command Search Path

July 17th, 2008

Often you need to run something from your directories without entering the full path to your executables. You may also like to customize some of your user settings, as you might know, .bashrc file allows you do do all this stuff.

In order to add a directory to your command search path you need to do the following:

export PATH=${PATH}:/your/path

The export command sets a variable in this script but also “exports” it so it affects things outside this script. The ${PATH} part is a special function that expands to your current search path. The colon (“:”) must be used to separate elements of the search path.

You can add this line to your .bashrc file or run it from your command line if you need to update your command search path only once.

More about .bashrc file possibilities you can read here

How to Deny Responses to Ping Requests Using iptables

July 16th, 2008

Sometimes you need to “hide” your server by denying responses to ping requests. This way your server will look like it is offline. ping <server_ip> will return connection timeout. There is a short linux command that will allow to do this using iptables. Here it is:

iptables -t filter -A INPUT -p icmp -j REJECT

This will ignore icmp packets send to your server (these packets are used to ping your server). You can also deny traffic send using any other protocol instead of icmp by modifying the command, changing icmp to the protocol name you need.

Another solution was found on Linuxquestions.org. It allows outgoing ICMP packets and blocks incoming. Here it is:

/sbin/iptables -A OUTPUT -p icmp -o eth0 -j ACCEPT
/sbin/iptables -A INPUT -p icmp –icmp-type echo-reply -s 0/0 -i eth0 -j ACCEPT
/sbin/iptables -A INPUT -p icmp –icmp-type destination-unreachable -s 0/0 -i eth0 -j ACCEPT
/sbin/iptables -A INPUT -p icmp –icmp-type time-exceeded -s 0/0 -i eth0 -j ACCEPT
/sbin/iptables -A INPUT -p icmp -i eth0 -j DROP

SEO Plugin for Firefox - SeoQuake

July 16th, 2008

Seoquake is a browser extension that allows you to monitor multiple parameters that are important for search engine optimization. It doesn’t do anything extraordinary, but the information is presented pretty well. Google, Yahoo and Live.com indexation, number of pages in each search engine, Alexa Rank and other parameters. It is fully customizable: you may tune almost all features that Seoquake has. Here is how it looks like:

Just try it and I’m sure you’ll find it useful. You may get it here. Plugin is often updated so it will be working even after any SERP changes.