Sunday, February 11, 2007

Tighten up security, disable Apache's signature

...Server: Apache/2.0.55 (Debian) PHP/5.1.2

Apache by default with most packaged distributions will display the Apache version you are running in a signature and generally any other modules loaded into it too. This can be a problem if you are running old versions with know security issues.

So if doing an upgrade is an inconvenience then perhaps masking the server signature is the way to go.

First we'll begin with PHP. If you navigate to your php.ini file (generally stored in /etc/php5/apache2/), you'll find the expose_php is set to "On". We can turn this off by simply typing in "Off".

Apache itself will sign the version number running too. Again a security issue. If you open the apache2.conf file (generally in /etc/apache2/), you can turn this off with setting:

ServerTokens ProductOnly

Or perhaps you want to scrap it all together:

ServerSignature Off

Programmable Completion with BASH

Most people know that when using the BASH interpreter you can hit tab and the file will complete or output the matches for you to refine the search. But not all know you can do with with many binaries too. When I say this I mean actual parameters.

colabus@typhon:~# dpkg --cont<tab>
--contents --control
colabus@typhon:~# dpkg --contents /var/cache/apt/archives/ruby1.8_1.8.5-4_i386.deb

To do this run or add the following line to your .bashrc file.

. /etc/bash_completion

Simply sourcing the bash_completion file to use in the shell.

It's handy! :)

Friday, February 9, 2007

No such file or directory - irb (Errno::ENOENT)

Uhoh! Ever had this error before?

colabus@typhon:~/public_html/rails/workorders# ruby script/console
Loading development environment.
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/console.rb:25:in `exec': No such file or directory - irb -r irb/completion -r script/../config/../config/environment -r console_app -r console_with_helpers --simple-prompt (Errno::ENOENT)
from /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/console.rb:25
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'
from script/console:3

I came across it when I decided to upgrade the Rails 1.2 and installed an updated Ruby version. Took me a little while to work out what was wrong but it seems script/console calls irb and not irb1.8. If you check out the /usr/bin/ directory you'll find the issue. And a simple fix:

# sudo ln -s /usr/bin/irb1.8 /usr/bin/irb

colabus@typhon:~/public_html/rails/workorders# ruby script/console
Loading development environment.
>>

Test validations on model with base

Testing is a fairly simple process for ruby on rails development as it's "baked right in" as Mike Clark would say. But how do we test our validate/validate_on_create/etc methods when our helpers don't quite give us the flexibility we want?

We have our built in validation helpers in the model and we can execute a simple test like below.

Customer model:
validates_presence_of :address

Related test on validation helper:
def test_invalid_with_empty_attributes
customer = Customer.new

assert !customer.valid?
assert customer.errors.invalid?(:address)
end

Now suppose you have the method validate in the ruby on rails model and wish to run a test on it. Or more specifically you want to run a test on the asserted error, "assert_equal".

In our model:
protected
def validate
errors.add_to_base 'You must have at least a business name or first name.' if firstname.blank? and business.blank?
end

In our test:
def test_presence_with_validate
customer = Customer.new(
:business => nil,
:firstname => nil,
:address => "123 House Street"
)

assert !customer.valid?
assert_equal "You must have at least a business name or first name.", customer.errors.on(:base)
end

The trick is the specify :base as the "on" method parameter.

And so we test:
# ruby test/unit/customer_test.rb -n test_presence_with_validate
Loaded suite test/unit/customer_test
Started
.
Finished in 0.057076 seconds.

1 tests, 2 assertions, 0 failures, 0 errors

Windows Vista Unattended Installation Tips

Microsoft Windows Vista was released not 2 weeks ago and at work I've been busily working away at setting up the Unattended installation for our OEM computers. Seeing as we aren't a Microsoft Gold Member we aren't privy to the good documentation and explanations for the setup. It took a while but I've integrated drivers, software installs, business details and logos into the installation.

Here I'll explain a few tricks I've found..

Adding the business logo to the Systems Properties window:

In your Autounattend.xml make sure you have UseConfigurationSet set to true. This will cause the installation to copy the files in $OEM$ on your USB stick/CD/Floppy to the relative directories of the destination computer. I tend to place my business logo in the OOBE (out of the box environment) directory. As such my USB key looks something like:

\Autounattend.xml
\$OEM$\$$\system32\OOBE\oemlogo.bmp

The $ directory will copy all the other child branches into the C:\Windows (assuming your installing to C: drive). Now to tell the install the company details.

<OEMInformation>
<Logo>C:\Windows\System32\OOBE\oemlogo.bmp</Logo>
<Model>Vista Premium TV</Model>
</OEMInformation>

There's obviously more details you can add here, such as the company name, phone support number and system type. The OEMInformation section is a child of the Microsoft-Windows-Shell-Setup component. You can put this in a few passes but I generally go for specialize.

When running synchronized commands with cmd.exe

I was trying to get my silent software installs working for a while then discovered that a direct call doesn't cut it. You need to specify a parameter to the cmd.exe program. That nifty little parameter is /C, which carries out the command specified by string and then terminates.

So when end up with:

<RunSynchronousCommand wcm:action=\"add\">
<Path>cmd /C \\server\Software\Vista.bat</Path>
<Order>2</Order>
<Description>Installing applications</Description>
</RunSynchronousCommand>

Windows Vista OEM product keys

This one I scored from a nice guy on the MSFN forums. These are:

Business - 4D2XH-PRBMM-8Q22B-K8BM3-MRW4W
BusinessN - 76884-QXFY2-6Q2WX-2QTQ8-QXX44
HomeBasic - RCG7P-TX42D-HM8FM-TCFCW-3V4VD
HomeBasicN - HY2VV-XC6FF-MD6WV-FPYBQ-GFJBT
HomePremium - X9HTF-MKJQQ-XK376-TJ7T4-76PKF
Ultimate - VMCB9-FDRV6-6CDQM-RV23K-RP8F7

I'll add more later ..