Archive for July, 2007

ProFTPd IPv6 Error

Thursday, July 26th, 2007

If you get the error:

Starting ftp server: proftpd - IPv6 getaddrinfo ’server.host.com’ error: Name or service not known

And your NOT running IPv6 on your system, edit /etc/proftpd/proftpd.conf and set:

UseIPv6 on

to

UseIPv6 off

and then /etc/init.d/proftpd restart

ProFTPd Default Root Jail

Tuesday, July 24th, 2007

One of the annoying things in setting up new servers, is doing all the fiddly bits that are often forgotten about. One of those fiddly bits for me this week, was setting up the root jail for the ftp server. A quick and easy fix, none the less one I forgot about!

For those interested: (On Debian) Edit /etc/proftpd/proftpd.conf and modify the DefaultRoot directive to read:

DefaultRoot ~

Restart your service (/etc/init.d/proftpd restart) and your away! Additional note: If you want to default the chdir command on the client to a new directory (ie, /www) all you need to do is add the directive:

DefaultChdir [directory]
ie;
DefaultChdir vhosts

Dial-in page cannot be initialized

Sunday, July 22nd, 2007

Having trouble with the Windows 2003 Active Directory VPN/Dial in screen giving errors? Well, following the help on the Microsoft website can sometimes prove helpful, but actually there is one sure fire way to fix this problem. It’s more of a hack, than a fix - but it goes like this.

  1. Close all user properties screens (you can leave the user listing open) and go to Administrative Tools > Services.
  2. Stop the service: “Remote Registry” (sounds stupid - as this is the service we need running to maintain dial in settings) - Do not restart!
  3. Go into your user properties, go to dial-in tab. It will give you the same error - slightly quicker this time.
  4. Now, close that window (user properties) go back to your services window and start the service “Remote Registry.
  5. Now go back into your user properties screen and click the dial in tab - and look! It works!

One possible reason why this happens is that it caches the local service response to accessing the service. Who knows! This little trick worked a treat thou.

Axis WSDL Hijinx

Monday, July 16th, 2007

For all our friends in Java Land - or those who must utilitise Java web services! I ran into some gotchas today in regards to restrictions placed on simpletypes. Consider the following snippet:

 <xsd:simpleType name=”WSAccountID”>
<xsd:restriction base=”xsd:string”>
<xsd:pattern value=”[0-9]{12}” />
</xsd:restriction>
</xsd:simpleType>

All looks fine and dandy - however when Axis gets this WSDL it mangulates it into the following:

 <complexType name=”WSAccountID”>
<simpleContent>
<extension/>
</simpleContent>
</complexType>

Unfortunately this is not valid syntax! Extension must have the base attribute defined. Net Result = PHP (and presumably any other Soap Client) won;t be able to use the webservice.

It seems Axis cannot handle type restrictions. Remove them and it works fine!

PHP Mssql Function Syntax

Thursday, July 12th, 2007

Heres another one of those bizarre situations.

Consider the following code:

 $sql2 = ‘SELECT TOP 1 * FROM users WHERE Clue > 0′
if( $Res2 = mssql_query( $sql2 ) && $Row = mssql_fetch_assoc( $Res2 )) {
print “Holy shit, a User with a clue.”;
}

In theory it should work. In practice you get an error indicating that $Res2 is not a valid resource result. Same syntax using myssql functions works as expected.

Workaround is simply to add the fetch method to the next if() statement.

 $sql2 = ‘SELECT TOP 1 * FROM users WHERE Clue > 0′
if( $Res2 = mssql_query( $sql2 )) {
if( $Row = mssql_fetch_assoc( $Res2 )) {
print “Holy shit, a User with a clue.”;
}
}

Might save someone a few intense minutes of grief.

FreeTDS / ODBC Compatibility

Wednesday, July 11th, 2007

When I say compatibility I really mean - “attempt to replicate ODBC behaviour”.

There are a few gotchas here:

  1. MSSQL Server, if it detects an ODBC Connection automatically(and without any request from the client) sets certain SQL Options for that connection
  2. ODBC Drivers automatically set some SQL Options

When using FreeTDS it may be required for you to emulate ODBC behaviour (as near as possible, and disregarding any featuresets not implemented by FreeTDS) by implicitly declaring these options when you connect to an MSSQL Server.

The pertinent options are:

set SET CURSOR_CLOSE_ON_COMMIT off
set ANSI_NULL_DFLT_ON on
set ANSI_NULLS on
set SET ANSI_WARNINGS on
set SET CONCAT_NULL_YIELDS_NULL on
set SET QUOTED_IDENTIFIER on

You need to do this before you execute any SQL Queries.

With these options you can emulate ODBC behaviour and get around problems I specified in earlier postings re: NULL values in temporary tables.

Change Default Submit Button in Forms

Wednesday, July 11th, 2007

By default, when you press the enter key on your form, it will submit the first input type=’submit’ action in your form. This can be a problem, where you have more than 1 submit button and for style reasons, your ‘default’ button is not the first cab off the rank - so to speak.

The easy way around this, is to add a hidden submit button - a default button.

<form>
<input type=’submit’ name=’Default’ value=’EnterKey’ style=’display: none’ />

Providing your hidden input is immediately after your form declaration syntax, it will by default, use this input as your enter key action.

MySQL Unique Indexes and Nulls

Thursday, July 5th, 2007

This is one of those classic “gotchas” that leave you scratching your head for hours. This is not only limited to MySQL as this behavious is defined in the SQL92 Specifications.

Just say you have a table like this:

Create table test (
x smallint not null,
y char(5) default null,
Unique Key `s`(x, y)
) ENGINE=MyISAM

And then execute the following inserts - you would expect that the final insert would be caught by the Unique Key. Wrong

Insert into test values (1, ‘dan’, ‘yes’), (2, ‘joe’, ‘no’), (3, NULL,‘maybe’),(4,NULL,’maybe’

All 4 are inserted into the database.

From MySQL:

A UNIQUE index creates a constraint such that all values in the index must be distinct. An error occurs if you try to add a new row with a key value that matches an existing row. This constraint does not apply to NULL values except for the BDB storage engine. For other engines, a UNIQUE index allows multiple NULL values for columns that can contain NULL.

Anda further explanation from MySQL Developers:

http://bugs.mysql.com/bug.php?id=4140

Hopefully this saves someone some head scratching.

Verifying ZIP Files on *NIX

Thursday, July 5th, 2007

Ever wanted to verify a ZIP files integrity - but your not on windows (with Winzip the impaler?).

Its as easy as a single command:

zip -T filename

Not only is it super-fast, but it gives you some great debugging info on your archives!

Internet Protocols

Thursday, July 5th, 2007

There are four layers of networking. These are all exceptionally important to the way we actually use the internet, as well as our networks at home and the office. The layers are:

  • Application
  • Transport
  • Internetwork
  • Physical

Application Layers, means things like:

  • SMTP - Simple Mail Transfer Protocol
  • Telnet
  • FTP - File Transfer Protocol
  • SSH - Secure Shell
  • HTTP - Hypertext Transfer Protocol
  • DNS - Domain Name Service
  • NTP - Network Time Protocol
  • Etc

These are the protocols that our applications speak, in order to transmit information from one computer to another. To send that information, we need to send it over a transport layer. The two transport layers are:

  • Transmission Control Protocol (TCP)
  • User Datagram Protocol (UDP)

Now we need to send the information from one network to another. To do that, we use our internetwork layer. These consist of:

  • Internet Control Message Protocol (ICMP)
  • Internet Protocol (IP)

Okay - last step. We need to send it over a physical layer. (Mostly, the blue cables popping in and out of ocmputers and routers) Our physical layers are things like:

  • Ethernet (LAN/WAN)
  • Dial-Up (PPP)

Okay - recap. Application, Transport, Internetwork, Pyhsical.