Tuesday 29 September 2009

Fedora: Using and authenticating yum through a proxy

I have just finished a Fedora 11 installation here at the office. We needed a test bed for working with symfony and our EL machines did not provide php 5.2.

Next thing was to update the new machine and install additional software and that meant being able to go through a squid proxy server, that requires authentication.

A little bit of digging and the magic man yum.conf revealed the following :

Edit /etc/yum.conf and add the following lines:

proxy=http://proxy.domain.local:port
proxy_username=your_user_name
proxy_password=your_password

Needless to say that the same configuration works perfectly on CentOS 5.4 ...

When your machine is behind a proxy then, in order for many other programs -- like wget -- to function correctly, you also need to export the http_proxy variable. The correct format for it is :

export http_proxy=http://username:password@proxy.domain:port

Friday 11 September 2009

Javascript : Yet an other email address validator.

I was building a Conduct us page the other day and run into the need for a JavaScript e-mail validator. I googled around a bit only to discover that the approaches were so many that I didn't know which one to choose.

So, eventually I did what every hard headed person would do, I sat down amd wrote my own validateEmail function. The code is a merge of ideas coming from the fifth edition of Tom Mergino's and Dori Smith's JavaScript for the World Wide Web, and Anita Sudhakar's approach from SmartWebby.

The resulted code looks like the following :

function validateMail(str)
{
  var at = "@";
  var dot = ".";
  var atPos = str.indexOf(at);    // position of '@' in the string
  var stringLength = str.length;  // position of '.' after the '@'
  var dotPos = str.indexOf(dot, atPos);
  var invalidChars = "~`/!#$%^&*()+={}[];:";
  var i;
  var badChar;

  // Step 1 Do not allow blank emails
  if ( str == "")
    return false;

  // Step 2 Make sure that the address does not contain invalid characters
  for (i = 0; i < invalidChars.length; i++) {
    badChar = invalidChars.charAt(i);
    if (str.indexOf( badChar) > -1)
      return false;
  }

  // Step 3: Make sure that the @ character is present and
  // that is not the first or the last character of the
  // email address string.
  if (atPos == -1 || atPos == 0 || atPos == stringLength)
     return false;

  // Step 4: Likewise make sure that a dot character exists and that
  // the distance between the @ and . is at least two characters apart
  if (dotPos == -1 || dotPos + 3 > stringLength)
      return false;

  // we have passed all tests let's hope that the email is valid
  return true;
}

The function should be called from an other function that will retrieve that value of an email filed and test it during form submit. A typical usage would be :


function validateEmailField( fieldID)
{
  var emailField = document.getElementById( eMailFieldID);
  var status = false;

  if (validateMail(emailField.value))
    status = true;
  else
    alert('Invalid email!');
  
  return status;
}

Friday 4 September 2009

Windows: The ultimate way to get rid of stuck print jobs.

Sometimes print jobs get stuck for good. Users try to delete them and then the entire queue gets stuck too. I have many times tried to find a remedy for that and even attempted to reboot the Windows server in question without always achieving the desired result. Lately, my eyes were opened by a friend who showed me they way by following the steps shown below.

  1. Stop the Print Spooler service.
  2. Delete all files from %SystemRoot%\system32\spool\PRINTERS/.
  3. Start the Print Spooler Service again.

... and that does it.

Wednesday 2 September 2009

Windows: Shutting down machines remotely

I have many times heard people complain about Windows machines freezing or being very slow to respond. The problem sometimes is so bad that not even the desktop user is able to close frozen applications or even shutdown her own machine. The remedy for 99% of all these cases, thank you Microsoft, -- as Mark Minasi would have said -- is the notorious shutdown command.

This posting will contain a brief overview of the command syntax. This command has been around since the days of Windows NT4 but Microsoft has changed it and now in Windows 2003 environments the arguments are not the same

So, to begin with the oldest version for those of us still stuck with NT4, the syntax for this platform is like this

shutdown \\machine_name /r /t:10 "Machine is going down in 10 seconds" /y /c

You can also use the /l switch to force a local shutdown. The /c, shown above, is very useful since it forces all running applications to close. The -t:N will display a message notifying the user that their machine is going down in N seconds. Here you can also provide an additional string explaining the reasons for the reboot, enclosed in double quotes. Finally if you forget the /r then the machine will just shutdown and then you 'll have to walk over there and power it down -- remember, this is NT4 we 're talking about -- and then up yourself. If after all you change your mind and you decide that the machine does not need to reboot, then -- if there is still enough time left -- use the command shutdown \\machine_name /A to abort the shutdown process.

Now with Windows 2003 the shutdown command has changed quite a bit. The equivalant command to shutdown a remote system now looks like this:

shutdown /r /m \\machine_name /t 10 /f /c "Machine is going down in 10 seconds"

The order of the arguments is significant. The /r switch can be replaced with /s to shutdown or /a to abort a shutdown in progress. The /t and the time interval are now separated by a space instead of a column ':' character. The /c switch now introduces the message for the shutdown reason and finally /f is now used to force closing of all running applications.

Shutdown for Windows 2003 has also an additional /d [p:]xx:yy switch that allows you to specify a coded reason for the shutdown, in exactly the same way you do when shutting down a Windows 2003 server via the GUI. The shutdown help screen provides detailed code listings about the meaning of each code. I never use them from the command line, so my most often issued command looks like this :

shutdown /r /m \\pc-bakalidis /t 0 /f 

Tuesday 1 September 2009

CentOS: Problems updating python

I have been running into the same problem while trying to update my 5.3 CentOS machine.

Yum reported three packages that needed update :

 java-1.6.0-openjdk     x86_64     1:1.6.0.0-1.2.b09.el5      updates      27 M
 libxml2-python         x86_64     2.6.26-2.1.2.8             updates     713 k
 python                 x86_64     2.4.3-24.el5_3.6           updates     5.9 M

When yum update was issued however, the same error message kept popping up.

--> Missing Dependency: /usr/lib64/python2.4 is needed by package
libxslt-python-1.1.17-2.el5_2.2.x86_64 (installed)

I tried disabling almost all my repositories, I removed many packages, almost ended up un-installing half my entire and then I googled on it. As always,, the answer was right there in front of me. Frank Cox wrote on the CentOS mailing list:

yum clean all
yum update

And that works. Thank you Frank.