Thursday, July 31, 2008

Running Two Tomcat Service Instances On The Same Machine

I saw this question on a forum recently and though the requirement may not be very common, it was certainly an interesting idea. At first I thought it wasn't possible but after little tampering with the registry, it turned out to be quite easy to achieve.

 Editing the registry is risky! If you're unsure or can't live with the consequences, don't do it. And remember, ALWAYS BACKUP!

The instructions below are for Tomcat 6.0 which is installed as service on a Windows [XP] machine.

To begin with, these are the keys that are created by the Tomcat installer in the registry; you'll need to modify them. I'll refer to them by their numbers in the steps.

I. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet \Services\Tomcat6
II. HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun 2.0\Tomcat6
III. HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Tomcat\6.0
IV. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows \CurrentVersion\Run
V. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows \CurrentVersion\Uninstall\Apache Tomcat 6.0
VI. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum \Root\LEGACY_TOMCAT6

  1. Install your first instance of Tomcat to, say, C:\Tomcat6_1
  2. Start > Run > regedit > [ENTER] will bring up the registry editor
  3. Navigate to key I and rename it from [...]Tomcat6 to, say, [...]Tomcat6_1. This will ensure the next install will not overwrite this key
  4. You should see the values for this key in the right pane; modify DisplayName from Apache Tomcat to, say, Apache Tomcat 1. This is so that you know which service is which later, in the Services console (Start > Run > services.msc > [ENTER])
  5. Modify the ImagePath value from [...]//RS//Tomcat6 to [...]//RS//Tomcat6_1. This is the name of the service instance that will be started; we'll need this name later so keep it in mind
  6. The Enum key under key I has a value 0 which points to key VI. Change the data to reflect the change in the key name that you'll be making later i.e. modify Root\LEGACY_TOMCAT6\0000 to Root\LEGACY_TOMCAT6_1\0000
  7. Navigate to key II and rename it also; from [...]Tomcat6 to [...]Tomcat6_1. Again, this is to avoid overwriting when installing the second service
  8. Similarly, modify key III from [...]6.0 to [...]6.0_1. Same reason as above
  9. Navigate to key IV and modify the value (not the value's data) from ApacheTomcatMonitor to ApacheTomcatMonitor_1. This key is for the monitor application; modifying the key will avoid overwriting of the key on the second install and you'll be able to run two instances of the monitor, one for each service
  10. Now you modify the data of this value; [...]//MS//Tomcat6 to [..]//MS//Tomcat6_1. This is the name of the service that you modified above, for the ImagePath value
  11. If you want to be able to uninstall both the instances of Tomcat later (recommended!), you need to modify key V and rename it from [...]Apache Tomcat 6.0 to [...]Apache Tomcat 6.0_1. Again, to avoid overwriting of the uninstall information
  12. I'm not very sure about key VI but I suggest you modify it also. Rename it from [..]LEGACY_TOMCAT6 to [..]LEGACY_TOMCAT6_1
  13. Restart your system now for the changes to take place
  14. Once you're sure the current install is working as expected, you can install the second instance of your Tomcat. I installed to C:\Tomcat6_2
  15. Before you start the second service, you need to change the ports since otherwise it's going to start with exactly the same ones as your first service and throw exceptions and quit. (You could've changed the HTTP listen port while installing) You need to change the HTTP and SHUTDOWN listen ports at least. If either of these is the same or bound to some other process, Tomcat will not start.
    1. Go to $CATALINA_HOME\conf\server.xml ($CATALINA_HOME refers to the Tomcat install directory)
    2. Modify the value for <Server port="8005" shutdown="SHUTDOWN"> appropriately
    3. Ditto for <Connector port="8080" protocol="HTTP/1.1"

  16. Restart the system and the two instances of the monitor as well as the services should start up with no issues


You can, of course, extend this to any number of services.

Wednesday, July 16, 2008

Making A 2/3-Pin Socket Power Cord For A CN13/CN14 (Standard PC) Power Point

OR Putting An Old UPS To Use



The power situation in India is pretty bad; I've had days when the power would go keep coming and going out every 10-15 minutes. Needless to say, the effect on my Internet experience is pretty dampening.

A friend of mine recently lent me an old APC UPS. We figured it'd be enough to power my network switch and my DSL modem, keeping my connection alive.

Unfortunately, the UPS only had output in the form of IEC C13 sockets (female).


This wasn't going to work for me because I needed to connect common C, D or M type 2/3-pin plugs. I asked at a few shops but there doesn't seem to be any connector or convertor for this purpose. So I decided to hack together something to use.

I bought a CN14-CN13 cable and a box type 3-pin socket.



I sliced off the CN13 (female) connector on the cable and separated the wires in the remaining part. I then wired them to the plug-point and, well, that was it! I now have this:


I simply plug it into the back of the UPS and I have backup power! Very easy, very obvious but it still pretty satisfying and very useful :D

 Be careful with the wiring! If you've never done it before, you should consider getting someone who has to assist you. I had a bit of trouble when some loose wires I'd left in the box short-circuited and blew the connection apart!

Tuesday, July 1, 2008

Google Toolbar Flags orkut.co.in As A Web Forgery

A funny thing happened today; I was checking out my communities on orkut when this popped up in Firefox -

orkut-web-forgery
This is the first time that I've seen this. I believe it's a Google Toolbar feature, but I'm not quite sure. The odd thing is that the warning only appeared when I tried to go to the communities pages while on the orkut.co.in domain and not on orkut.com.

I followed the This isn't a web forgery link ( which took me to a Google page, hence my assumption this is a Google Toolbar feature ) and reported the error. But it's ironic that Google's feature would block one of Google's own websites!

Wednesday, June 4, 2008

Hacking The Cisco 7940 IP Phone

Or How To Change The Ringtone And Idle Logo On The Cisco 7940G IP Phone


Quick-Links

  1. Pre-requisites
  2. Setup a TFTP server
  3. Configure the phone to use your TFTP server
  4. Get the phone configuration data
  5. Modify the configuration files
  6. Create a new logo
  7. Create a new ringtone
  8. Update the phone
  9. Notes and troubleshooting
  10. Samples
  11. Resources
  I want to point out right at the start that this is what I've put together after gleaning information from various sources on the Internet. I don't really know what I'm doing!

I was sitting around doing nothing at work yesterday and I started fiddling with my desk phone, a Cisco 7940 IP Phone. I changed the ringtone and reached the Network Configuration menu. I noticed the phone's IP and just for the heck of it, tried to open it up in the browser. Surprise! It shows a lot of the details of the phone and its network settings.

I then realized that there was more to the device than it would appear and I Google'd around for some hacks. The first few things I came across were that it was possible to load your own ringtones and change the idle logo.

  Before you make any changes, make sure you note down the original value/ setting! You don't want to be calling your Help-Desk and explaining to them what you were doing!

You can save almost all the relevant information by going to http://[your-phone-ip-address] in your browser and choosing the Network Configuration link. You should see a page that looks like:

You can save/ print this page for future reference and roll-backs. To get your phones IP address, check under Settings > Network Configuration on the phone.

Pre-requisites

You're going to need the following things for this:
  1. A Cisco IP Phone - I've got the 7940 model but from what I can tell, these steps should work on other similar ones also.
  2. A TFTP server - I used the free TFTP server from SolarWinds
  3. A web server - This applies only if you want to change the logo.
  4. A utility to convert images to CIP - Again, this applies only if you want to change the logo. And if you don't want to be coding the required files by hand!
      Cisco provides an SDK that includes these but you need to register on the site ( and you might need to enter contract details, which might not be possible if the phone is at your workplace ). I wasn't able to complete the registration, kept getting session timeout errors so, I'm not sure how/ if this works.
     


    I used the free utilities by Mark Palmer that can be downloaded from http://search.cpan.org/~mrpalmer/Cisco-IPPhone-0.05
  5. An image editor that supports GIFs and resizing - Again, you'll only need this to create logos. I used Adobe Photoshop but any decent editor should server you well.
  6. An audio editor that supports creation of RAW audio files - This only applies if you want to be able to create ringtones. I used the trial version of GoldWave; it’ll let you perform 150 commands in a session and up to 2000 commands after which the trial version will expire.

Setup a TFTP server

  TFTP is NOT the same as FTP! The servers/clients are not interchangeable!

Your OS probably has a built-in TFTP client ( try typing tftp at the console ) but you'll need a server.

The phone uses TFTP to pick up its configuration files when it boots. Usually this is some server that the IT department in your company maintains but you can easily modify the phone's settings to use your private TFTP server instead.

The SolarWinds TFTP server is really simple to use. Simply install and run the application. Choose File > Configure. Modify the options as you see fit. Do note down the TFTP Server Root Directory ( C:\TFTP-Root by default ). Don't forget to start the service!

  The SolarWinds TFTP server automatically logs all the requests it gets. If you're using some other server, see if you can/ need to increase the logging level, at least initially, to get a list of files required.
 

That's it; your TFTP server is now running. You can check it with the command line TFTP client that Windows XP and Mac OS X have ( I don't know about Linux but I'm sure it must! ). Go to the command line and type in tftp. On Windows XP, you'll get the following:

C:\>tftp

Transfers files to and from a remote computer running the TFTP service.

TFTP [-i] host [GET | PUT] source [destination]

-i              Specifies binary image transfer mode (also called
octet). In binary image mode the file is moved
literally, byte by byte. Use this mode when
transferring binary files.
host            Specifies the local or remote host.
GET             Transfers the file destination on the remote host to
the file source on the local host.
PUT             Transfers the file source on the local host to
the file destination on the remote host.
source          Specifies the file to transfer.
destination     Specifies where to transfer the file.


C:\>

On the Mac, you'll simply get the TFTP prompt: tftp>

The command is not very hard to figure out so I'll leave out part explaining how to use it.

Configure the phone to use your TFTP server

Now that you have a TFTP server running you need to point the phone to it. Do the following:
  1. On the phone, go to the settings menu and select Network Configuration. The options are not editable by default so you need to key in the secret password, **#. You should see the tiny lock icon at the top unlock.
  2. A long way down in the list of options ( option #32 on my phone ), you'll find the option for Alternate TFTP. You need to set this to YES so that you can change the actual TFTP server address.
  3. Go back up to the top of the list ( irritating? Yes, I know! But you can key in the option number to speed things up. ) to reach the option for TFTP Server 1. Edit this, type in the IP to your machine and Validate.

  Note down the original TFTP server IP address before you modify it!
  • Once you choose to Save, the phone will reboot. It will now try to get the configuration files from your TFTP server. In the TFTP server logs, you should see the requests for various files, collate the file names into a handy list.

  • Get the phone configuration data

    As noted above, your TFTP server should be logging all the requests from the phone. This will give you a list of configuration and resource files required by the phone.

    You should now use the original TFTP server ( you did note down the IP address didn't you? ) to get all these files ( use the command line TFTP client built-in to your OS ). Then copy them into your TFTP server root so that your phone can pick them up from there instead. Simple, huh?

    Modify the configuration files

    You'll find some XML files in the collateral that you download from the original TFTP server. One of these would be named something like SEP0123456789AB.cnf.xml. This name comes from the host name of your phone ( SEP0123456789AB in this case ) which itself is derived from the MAC address of the phone ( 01-23-45-67-89-AB ). This is the main configuration file.

    Open it in any text editor and look for the tag <idleURL>. This points to the place where the 'screensaver' graphics are picked up.

    The graphics displayed on the phone are not your usual image files but instead a special XML. You can see how to create the required XML file below. For now, you need to know that you will need to host this XML on a web server on your machine so that the phone can pick it up from there. You can also leave it as it is, the phone will then continue to use the original logo that it had.

      Make sure that your web server uses the mime-type text/xml when serving XML!

    I spent almost half an hour trying to debug why an XML hosted on Tomcat was not being used for the logo when I could see the phone hitting the correct URL and getting the correct response from the server.

    It hit me later that it was probably a mime-type mismatch and I then tried IIS. Voila! That worked! I then checked the responses of each server using the Live HTTP Headers plugin for Firefox and saw the difference in content-type.

    Create a new logo

      I'd suggest downloading the original XML that the <idleURL> tag was pointing to and putting that on your web server at first. This will help rule out malformed or unsupported images while troubleshooting. Once you get everything setup, you can replace this with your custom file.

    The logo is usually in the CIP ( Cisco IP Phone Image document ) format which is an XML file with some specific tags and the image data in hex. You can use the gif2cip application to convert a GIF image into the required XML. The Cisco 7940 IP Phone uses images that are a max of 133 pixels wide by 65 pixels tall. You can find out more about your particular phone model by checking out the Cisco site for appropriate documentation.

    The logos seem to come out better if they have minimum gradients, sharp boundaries and fewer colours. You might have to give this quite a few tries to get acceptable results.

    Get an image you like, use an image editor to resize it within the supported boundary limits and then save it as a GIF. Use the gif2cip application to convert this to a CIP document. If you have Photoshop, you can also use the plugin to save it directly as a .CIP file. If you open the document in a text editor, you'll see the XML tag for <Prompt>. This is the text that is displayed on the phone when the screensaver is on. Modify it as you see fit.

    You can now put up this XML on your web server, ready to be requested by the phone.

      The phone requests the logo XML every time the screensaver comes on! This means you could serve this images dynamically to some purpose like random images or whatever else you can think of.

    Create a new ringtone


    The ringtones supported by the phone must conform to certain strict requirements. I'm not very clear on these.

    All I did was use GoldWave to snip out parts of an MP3 and save as a Raw (*.snd) file with the attributes you can see in the image. These worked for me but the length of the tone is pretty short. I'll try out some more options to see if it can be longer but I doubt it.

    The ringtones are listed in a file named RINGLIST.XML ( you should have got this from the original TFTP server and it should be available in your TFTP server root directory ). It has entries of the form

    <Ring>
        <DisplayName>Are You There 1</DisplayName>
        <FileName>AreYouThere.raw</FileName>
    </Ring>
    

    You'll need to add your new ringtone in similar elements. The display name is what the phone shows in its UI. The filename is the name of the ringtone you created ( change the extension to raw if it isn't already ).Save the changes you've made to the file.

      If you want to be able to use the ring tones that were available on your phone by default, you will need to get those from the TFTP server as well. The RINGLIST.XML entries will tell you the names of the ringtones and you should put them in your TFTP server root directory along with the rest of the files.

    Update the phone

    Now that you've got all your stuff ready and made all necessary configuration changes, you're ready to try it out!

    The phone picks up configuration files only when it's booting. So you can either unplug then replug it or use **#** while in the Network Configuration menu.

    You should see your TFTP server logging requests for various files, just like before. Only this time, it actually has those files and can serve them up to the phone! Once it's done booting, you should see the logo come up after the default idle timeout ( you can change this too; check the SEP0123456789AB.cnf.xml we modified earlier for <idleTimeout> ).

    If you followed my suggestion earlier and used your original XML, you should now replace it with your custom file and refresh the screensaver ( you don't need to restart the phone, you can either select Update or just perform some action, like picking up the handset and putting it back; that interrupts the screensaver and then starts it again ). If everything has been setup correctly, you should see the image you want!

    Your ringtone should be listed under Settings > Ring Type > Default Ring. When you choose to Play the file, you should see a request on your TFTP server, for the corresponding .raw audio file. If it's too big or not in the correct format, you'll see errors. If it's acceptable, you'll hear your ringtone play.

    Notes and troubleshooting

    Like I mentioned earlier, I got this to work on the Cisco 7940 IP Phone specifically, using instructions and information from various sources. So I'm not sure how this applies to other models. However, the following checklist should help you locate the problem:

      Verify that your TFTP server is working properly by trying to fetch a file using a client other than the phone.
     

      Verify that the changes you made to the TFTP server IP address on your phone have indeed been saved.
     

      Verify that your server is not logging any failed file transfers. If it is, you may have forgotten to get some files from the original TFTP server or you mustn't have placed them in the current TFTP server's root directory.
     

      Verify that you've modified the <idleURL> tag to point to the correct location of the logo.
     

      Verify that the changed URL for the logo is seen in the settings on the phone, to make sure it's picking up the correct configuration.
     

      Verify that you can fetch the required logo XML from your web server by using a browser to hit the URL. Also verify the content-type being returned by the server; my phone required it to be text/xml.
     

      Once you try to load your ringtone, you should see a request for the *.raw audio file getting logged by the TFTP server. Verify that it's the correct filename.
     

      If the phone displays an error, try to make the ringtone again. The requirements are pretty strict and you may need to snip quite a bit of the audio to be able to load the file onto the phone.
     

    Samples

    You can try out some of these sample logos and ringtones that I'd made; they're working for me and could be a starting point for you in case you don't have immediate access to the required tools. Save the files and host them on your server.

      Linking directly to these graphics files will probably not work:
    • I'm not sure if the phone would pick up something off of the Internet
    • Your admin would have proabably restricted access to the Internet from the phone
    • The mime-type these servers respond with may not be what the phone expects

    Graphics:
    The Batman Logo
    The Unreal Logo

    Ringtones:
    The opening notes of the M:I-2 theme
    Moby's In My Heart, from the Nokia ad.

    You can also get the ringtone of the [Cisco IP] phones from the TV show 24 from here. In case the page is down, you can get the files it linked to from here, here and here.

    If you create something that you think others might like, please let me know, I'll link to it in the list above.

    Resources


    Friday, May 30, 2008

    Google Has A New Favicon

    Google now sports a brand-new favicon (http://www.google.com/favicon.ico).

    Just in case you never noticed or were so used to it that you don't remember, this is what the old one looked like:

    Can't say I'm a fan of the new one though; seems too generic somehow.

    Tuesday, May 27, 2008

    Cleaning Out ADVIRS.exe, A Relatively Unknown Virus

    At work today, a friend of mine told me that he was unable to start Command Prompt or Task Manager. Any seasoned PC user will immediately recognize these as the symptoms of a possible virus infection. He then admitted that he'd let his brother use his pen drive to copy some stuff off his laptop over the weekend. Bingo!

    But now what? We had no idea what virus it was and his updated enterprise edition of McAfee Anti-Virus didn't detect anything ( so much for all that money we pay them! ) and we couldn't run Task Manager to see which suspicious process were running.


    Just yesterday, I'd read this article on Slashdot about gaining system privileges in Vista. The comments noted that this was also possible in Windows 2000/XP et al.

    I had been planning to try it out and here was a great chance to see if it would work.

    Here's the idea: The accessibility utilities, like Magnifier ( C:\WINDOWS\system32\magnify.exe ) and Sticky Keys ( C:\WINDOWS\system32\sethc.exe ) are applications that can be run from the login screen before logging into the computer ( Use Win + U and/or press the Shift key 5 times ). They are started with privileges higher than that of any user, including administrator.


     Starting them after you login will start them with your user account and they'll get those privileges. You must start them from the login screen.
     


    So if you can replace the EXEs with some other application EXE, it would get invoked with those privileges. And what would be the best candidate for such a replacement? Good old Command Prompt ( C:\WINDOWS\system32\cmd.exe ). Once you do this and invoke Magnifier ( or Sticky Keys ), you'd end up starting Command Prompt with system level access. You can now do stuff that even the administrator accounts would not be able to ( I'm yet to discover what these are but the comments on the aforementioned Slashdot article have me convinced that this is indeed the case )

    So, to do this, you should :

    1. Make a copy of cmd.exe
    2. Rename magnify.exe to magnify.exe.bak ( Always backup! )
    3. Rename the copy of cmd.exe to magnify.exe

    You'll have to do steps 3 pretty quickly because in about 5 odd seconds, Windows realizes that magnify.exe is missing and replaces it! So you could copy the filename and keep it ready and then quickly paste it. It's up to you. The idea is that rename the copy before the original magically reappears.

    Back to the anecdote. Once I did this, I then started Magnifier and lo behold! Command Prompt opened up! We could now run tasklist to get a list of running processes and their PIDs. We were luck, my friend immediately spotted two instances of advirs.exe and when we Google'd it, we knew it was the culprit. We used taskkill to end the two processes and then tried running Task Manager and it worked!


    Image Name                   PID Session Name     Session#    Mem Usage
    ========================= ====== ================ ======== ============
    ADVIRS.exe                  3276 Console                 0      5,992 K
    YahooMessenger.exe          4056 Console                 0     15,416 K
    JabberMessenger.exe         3560 Console                 0     42,748 K
    GoogleToolbarNotifier.exe   4028 Console                 0      1,060 K
    ADVIRS.exe                  3652 Console                 0      5,980 K
    


     We'd redirected the output of tasklist into a text file but when we opened it to see the PID of ADVIRS.EXE, the dumb virus wouldn't let us search for the string 'advirs'! So we searched for 'advi'. Clever, huh?
     


    I then got my friend to install WinPatrol to protect against future autorun programs. We also used it to remove the registry key for running advirs.exe on startup - HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Advirs

    RemoteIT was the only antivirus that turned up in the search results for this virus and specifically claimed to clean it. We didn't try it because we'd already got rid of the problem by then but you could give it a shot, in case you're unlucky enough to get infected!

    It does seem a pretty simple thing to get rid of though so maybe this wasn't really required. I think if we'd simply renamed a copy of cmd.exe to something else, it would have bypassed the virus' blocks, so you might want to try that first :D


      EXE name : advirs.exe
    Location: c:\windows\system32\advirs.exe
    Registry Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Advirs

    Saturday, May 17, 2008

    Gmail Has A New Loading Page And Now Loads Faster

    When I logged into Gmail today, I noticed a different 'loading' page. Instead of the usual blank, there is now a progress bar visible.

    Click To See The Complete Image of Gmail's New Loading Page
    Click To See The Complete Image of Gmail's New Loading Page

    There also seem to be improvements behind the scene, as this post on the Gmail blog explains.

    Thursday, May 1, 2008

    Free Stuff For Your Domain

    Or What To Do With Your Domain Name, For Free



    So you've finally got that really cool domain name you've always wanted; now what? How do you let everyone know how uber-cool you and domain name are? You could give some of these free services that allow you to use custom domains a shot.

    I bought my domain almost a year ago. I didn't really have anything specific in mind that I wanted to use the domain for, except perhaps my blog. I didn't want to shell out for hosting or other services that I wasn't really going to use but I also didn't want the domain name to lie idle. So I looked about for free services that I could use. I found only a few and they're listed below (mostly from Google!). The ones that I've not used are starred.



    One more advantage of putting your stuff on a custom domain name is that if you should ever choose to switch providers ( be it email, blogging platform, feed publisher, whatever ), all you need to do is update your domain settings to point that URL to the new host. Your friends and readers need not update anything!

    If you know of any other services that can be added to this list, post a comment! I'll add them to the list ( and credit you, of course :D ).

    * I've not used these services but the sites seemed to indicate that they were free and had domain customization features.

    Monday, April 7, 2008

    Yahoo! Messenger Doesn't Login? Check IE Proxy Settings


    The other day, I wasn't able to login to Yahoo! Messenger on my company laptop. I fiddled around a bit and finally realized that I had the company proxy set in Internet Explorer. Once I cleared that, everything worked fine.

    Yahoo! Messenger has connection options for -
    • No proxies
    • Use proxies
    • No network detection
    But it seems that even if you choose 'No proxies', the option doesn't override the proxy set in IE. Not very obvious and a potential blocker. Firefox does not cause this problem.