Web Development


If you’ve used PLESK for any great length of time, you’ll know that whilst it is a great bit of software, for some reason it defaults to doing Reverse DNS lookups whenever a client connects to it to send mail.

Yeah rDNS is a useful tool for stopping spam and the like… but it also means that every single email sent takes 26-30 seconds to go out. That’s frankly unacceptable when you are trying to operate a commercial service and vastly undermines any possible benefits from it.

The good news is that it is (fairly) easily resolved. All you have to do is put in a command-line flag to tell the mail server not to perform an rDNS lookup. The hard part is figuring out exactly where to stick it.

Up to version 8, I used to refer to this handy guide, which resolved the problem though in ways I couldn’t quite understand! see here at

http://tyrannical.org/page-14

PLESK 8.4 introduces some major under-the-hood improvements, one of which is a subtle reorganisation of where the commands are stored. After some handy support from our ISP CWCS, we found that the command had moved to here:

/etc/inetd.conf

and all you have to do to switch off rDNS is to insert the following flag after the second occurrence of the phrase “tcp-env” in your inetd.conf.

-Rt0

More info and some other useful tips here

Anatomy of -Rt0
What does -Rt0 mean exactly? Well it’s a command that’s issued to the TCP server and it tells it to

R - Do not attempt to obtain $TCPREMOTEINFO from the remote host.
tn - Give up on the $TCPREMOTEINFO connection attempt after n seconds. (default is 26 seconds ho, hum)

The complete howto

  1. Login to your PLESK server using SSH
  2. type the command vi /etc/inetd.conf
  3. type the letter I (to insert)
  4. find the two lines that begin with smtp stream and smtps stream
  5. look for the second occurrence of tcp-env
  6. type -Rt0 into the line (note zero, not ‘o’)
  7. hit [esc]
  8. type : (shift-colon)
  9. type wq! (meaning write the file and quit from vi)
  10. hit [return]

now all you have to do is restart inetd, which is done on Ubuntu by entering the command

/etc/init.d/xinetd restart

You should now find that SMTP mail sending is lovely and quick. Phew!

Caveat
Please note that making some changes in the PLESK domain control panel will reset this command line, so you may need to edit it again if you start to notice delayed SMTP sends

This is a handy way to test sites that are in the process of being moved from one domain to another, or even to create your own “invisible” internet.
Normally when a user requests something from a web-based domain, their computer will connect to a Domain Name Server (DNS) and request the correct IP address for that domain. As you can see for everything that is requested on a web site you will have at least one and possibly two net requests (one for the domain translation to ip and one for the asset itself) taking place. This can slow the whole process down.

What you can do is log a set of special domains (frequently used, personal, etc) in your /etc/hosts file. This is a kind of static file DNS server if you like. This is always consulted first and you can in fact use this technique to override any web address. By creating a web site that responds to requests on a certain domain (even if it’s not registered to that server) and by “spoofing the host,” you can create extremely secret / secure web servers as they have no visible presence on the internet, except to those users who have manually set their host files up.

We’ll be using vim which is a slightly nicer version of vi the linux/unix text editor. It’s a little unwieldy at first - all keyboard commands and odd-shortcuts but it’s a doddle to use once you’re comfortable with it.

Anyway, here’s how to do it:

1. open Terminal

2. type

sudo vim /private/etc/hosts

3. press I (for Insert)

4. scroll to the bottom

5. hit return to enter a space

6. type the following line

# TEMPORARY SPOOFED IP FOR TESTING

7. hit return to enter a space

8. type the following line

123.456.789.101 www.example_domain.com

where the ip address and the example domain are those that you wish to use

9. hit return to enter another blank line

it should look like this

# SPOOFED HOST
123.456.789.101 www.example_domain.com

10. hit escape

11. type

!wq

to save the file

¡IMPORTANT! You will have to re-start your mac to refresh it’s internal dns

Windows Users: It’s pretty much the same process, with the hosts file living in c:\windows\system32\etc\ (on WinXP) usually and you can edit the file notepad.

If you do a lot of work with template based systems, as I sometimes do, you may find that Dreamweaver refuses to allow you to render some of the files in the Design view. This makes it incredibly difficult to find the correct template by loading it and viewing it.

The Dreamweaver documentation is not terribly clear on how to make the program recognise these files as HTML, or PHP type files. It seems to hint that you can go into your personal Library settings and edit a file called Extensions.txt - this will not work.

So here’s how to do it:

1) Browse to your ‘Applications’ folder

2) Open Adobe Dreamweaver CS3
3) Open Configuration / DocumentTypes

4) Edit the file MMDocumentTypes.xml

5) Find the section you wish to update - in my case it’s the PHP section

6) Edit this line:

documenttype id=”PHP_MySQL” servermodel=”PHP MySQL” internaltype=”Dynamic” winfileextension=”php,php3,php4,php5″ macfileextension=”php,php3,php4,php5,ihtml,pml” file=”Default.php” writebyteordermark=”false”

and add the other extensions that you wish Dreamweaver to interpret as displayable PHP files into the macfileextension section. I think it’s safe to assume that updating winfileextension will do the same for Windows Dreamweaver users.

7) Save the file

8) Restart Dreamweaver and voila!

Dashboard! What a cool app - there when you need it, gone when you don’t. That’s my idea of usefulness.

Now one of the Widgets I use the most is the Unit Converter widget. It’s very handy indeed and saves me having to browse through half a dozen Google results to find the conversion that I need.

However, for one reason or another, I was brought up to measure my weight in Stones - these don’t seem to relate to anything real except bodyweight and unfortunately I can only appreciate my weight in these terms (Kg mean nothing to me, though suffice it to say I have a lot of them!).

Unit Converter doesn’t have a facility for converting between Stones and Kilograms at present but actually adding one is very simple - all the information is contained in one script file that’s part of the widget and in fact the hardest part of the operation is changing the permissions on the file. This should work for any other type of conversion you wish to add as well.

Here’s how to do it:

This operation will require you to restart Dashboard (I think), which could mean you having to restart your mac. Ideally the best time to make this change is after you’ve booted up and before you start Dashboard up. That way, you can save your change, hit F12 and see it working straight away.

1) Launch Finder and browse to the Library folder on your hard disk

2) Browse to the Widgets folder

3) Ctrl-click the Unit Converter widget and choose Show Package Contents from the options

4) Now make a copy of Conversions.js to be on the safe side (you will need to enter your password to do this)

5) Highlight Conversions.js and Get Info on it

6) Here you will need to change the Ownership & Permissions on the file so that you can Read & Write it. You will need to enter your password again

OK, here’s the fun bit

7) Open up Conversions.js in a text editor.
You will see it’s made up of blocks for each of the conversion types, which look something like this
[js]var Weight = [
{name:'Short Ton (US)', toBase:linearForm(907.18474), fromBase:invLinForm(907.18474)},
{name:'Pound (US)', toBase:invLinForm(2.204622622), fromBase:linearForm(2.204622622)},
{name:'Ounce (US)', toBase:invLinForm(35.2739619), fromBase:linearForm(35.2739619)},
{name:'Long Ton (UK)', toBase:linearForm(1016.0469088), fromBase:invLinForm(1016.0469088)},
{name:'Metric Ton', toBase:linearForm(1000), fromBase:invLinForm(1000)},
{name:'Kilogram', toBase:linearForm(1.0), fromBase:invLinForm(1.0)},
{name:'Gram', toBase:invLinForm(1000), fromBase:linearForm(1000)}
];
[/js]
so you can see, all we need to do is add another line in there with our conversion in it. Now the way that the Unit Converter appears to work is that for each set of units, it has a base unit - in this case it is Kilograms and you can see that the conversion ratio for Kilograms is 1.0. Whenever a conversion is made, the unit is first converted to the base unit, and then converted to the required unit.

Looking at an entry, for example

{name: ‘Gram’, toBase:invLinForm(1000), fromBase:linearForm(1000)}

you can see that the key information we need to put in to create a new entry is a name and a single figure, that being the amount of the new unit (Gram) per one of the base unit (Kilogram), that is, 1000.

To create a new conversion, we need to get that ratio. I went here and retrieved the following information:

1 kilogram is equal to 0.15747304441777 stones.

so all we have to do now, is go to the bottom of the weights block and:

1) Add a comma, after the final conversion (Grams), so the end of the line looks like this

… fromBase:linearFrom(1000)},

2) Put in the following line after the last entry but before the closing square bracket
{name:’Stones’, toBase:invLinForm(0.15747304441777), fromBase:linearForm(0.15747304441777)}

3) Save the file and fire up Dashboard

Here’s a copy of the complete and working file:

Conversions script updated to include Stones

Troubleshooting

You will know if it has worked because Unit Converter will run the way it always does and Stones will now be an option to choose from. If you find that you can’t select any units and the image across the top does not look right, then there’s something wrong with your update to the script: you’ve missed a comma, a quote or a bracket or brace or square bracket. Go back and look at it. In the worst case scenario, you can copy your original backup of conversions.js over the new one but you will need to restart Dashboard and possibly your Mac for it to work again.