Category: tagged

  • Latitude & longitude weather API

    While looking for a free and decent weather service API to display localised weather forecasts on tudomo‘s property details pages, I came across another blog describing how to get the current weather by using the iGoogle weather gadget API.

    The examples provided were mainly to locate the weather in a certain known city. My situation was a bit different as I never know beforehand where the properties for sale on tudomo are located in the world. So what I needed was a weather service based on latitude and longitude solely. Then it would not matter where in the world a property was located as I would get the closest possible matching weather measurement.

    To accomplish this you need to change the original query to the following. Please note all the commas are needed to make it work.:

    http://www.google.com/ig/api?weather=,,,36575560,-04670219

    Which will output some XML as the following:

    <xml_api_reply version="1">

    <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">

    <forecast_information>
    <city data=""/>
    <postal_code data=""/>
    <latitude_e6 data="36575560"/>
    <longitude_e6 data="-4670219"/>
    <forecast_date data="2009-05-11"/>
    <current_date_time data="2009-05-11 17:09:51 +0000"/>
    <unit_system data="US"/>
    </forecast_information>

    <current_conditions>
    <condition data="Partly Cloudy"/>
    <temp_f data="71"/>
    <temp_c data="21"/>
    <humidity data="Humidity: 62%"/>
    <icon data="/ig/images/weather/partly_cloudy.png"/>
    <wind_condition data="Wind: SW at 13 mph"/>
    </current_conditions>

    <forecast_conditions>
    <day_of_week data="Mon"/>
    <low data="53"/>
    <high data="75"/>
    <icon data="/ig/images/weather/sunny.png"/>
    <condition data="Clear"/>
    </forecast_conditions>

    <forecast_conditions>
    <day_of_week data="Tue"/>
    <low data="53"/>
    <high data="75"/>
    <icon data="/ig/images/weather/sunny.png"/>
    <condition data="Clear"/>
    </forecast_conditions>

    <forecast_conditions>
    <day_of_week data="Wed"/>
    <low data="53"/>
    <high data="75"/>
    <icon data="/ig/images/weather/sunny.png"/>
    <condition data="Clear"/>
    </forecast_conditions>

    <forecast_conditions>
    <day_of_week data="Thu"/>
    <low data="46"/>
    <high data="71"/>
    <icon data="/ig/images/weather/mostly_sunny.png"/>
    <condition data="Mostly Sunny"/>
    </forecast_conditions>
    </weather>
    </xml_api_reply>

    Now it is up to you to simply parse the XML and process it as you wish. Please note that this is untested as I did not end up using the iGoogle API but instead Wunderground‘s as I felt it was more dedicated for the purpose. The same example call with Wunderground’s weather API would be:

    http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=36.575560,-4.670219

    Note there is a slight difference on how the latitude and longitude values are included in the GET request between the two APIs.

  • ip2.cc an alternative to hostip.info

    I have used the API of hostip.info for long time to resolve IP addresses to country codes or country names. The web service has been hit by some severe downtime lately returning “500 – Internal Server Error” for any calls including both API and website page requests. As of now hostip.info has been down and unreachable for several days in a row, with no signs of coming up in the near future. Perhaps the maintainer is on holiday or something…

    I manage several applications depending on this web service so I started searching for an alternative solution to lookup IP addresses. I did not find anything suitable so I decided to launch my own free IP to country lookup API instead.

    This new web service can be found at ip2.cc (IP to Country Code) for everyone to use.

  • Console recursive FTP client

    Sometimes data needs moving from server to server without FXP support. For this task there is nothing simpler than good old FTP.

    What about if you have a large number of subdirectories? As the plain FTP client can not fetch the files recursively shell scripting is usually the solution. But in cases where you do not really know neither the depth of the recursion or the naming convention of the file system structure, an alternative method is needed.

    This method is named NcFTP Client. I got to know about it today as I quickly needed to copy several gigabytes of data spread over several subdirectories and NcFTP did its job flawlessly. I did not even have to install it as Fedora 10 already came with it by default.

  • Pidgin certificate prompt

    Today using the version of Pidgin that came with Fedora 10 I received the following certificate prompt:

    Accept certificate for ows.messenger.msn.com?
    The root certificate this one claims to be issued by is unknown to Pidgin.

    The majority of cases of unknown certificate issuers are due to the chain of trust breaking down. This break down in the certificate chain is mainly caused by the software in question not including the intermediate certificate authorities certificates. Without these intermediate certificates the software can not verify through the certificate hierarchy up till the root certificate and therefore prompts the user about what to do.

    The options I received in the Pidgin prompt were:

    View certificate
    Accept
    Reject

    Upon selecting “View certificate” I am presented with the following details:

    Common name: ows.messenger.msn.com
    Fingerprint (SHA1): a9:9c:2d:ee:4a:d1:c8:7d:a7:c5:c3:05:32:98:5f:ee:57:87:73:8a
    Activation date: Tue Jan 29 14:37:21 2008
    Expiration date: Wed Jan 28 14:37:21 2009

    So far everything looks as it is a bona fide certificate but to verify the identity completely I load the page https://ows.messenger.msn.com/ in Firefox. As expected no certificate warnings were received and I opened the certificate viewer to see its details and confirmed the data matches up with the data received in Pidgin:

    certificate
    Certificate Viewer

    I can safely trust this certificate as Firefox has verified through the certificate chain that all intermediate certificates are valid too:

    certificate_chain
    Certificate Chain

    This certificate is simply used by Microsoft for the Live Messenger offline messaging service. Although you normally would trust verified certificates it did happen in the past that certificates were incorrectly issued to the wrong people. So always be cautious!

  • Virtualmin & suEXEC

    If by chance you have installed the Webmin module Virtualmin at some point you may have come across the following error message when setting up the module:

    Failed to save enabled features: The Suexec command on your system is configured to only run scripts under /var/www, but the Virtualmin base directory is /home. CGI and PHP scripts run as domain owners will not be executed.

    This error message is caused by using a version of suEXEC compiled by default to use /var/www as the document root of Apache. The suEXEC feature allows to execute scripts as the user owning the virtual host instead of the global apache user increasing security. The solution has either been to recompile suEXEC with the new desired path (/home in this case) or simply disable (Server Templates > Apache Website > Automatically add appropriate SuExec directive?) suEXEC completely inside the Virtualmin module configuration.

    A much simpler approach I used was to create a link between the two directories. I used mount to bind the two directories together and act as one. Voila, Virtualmin now continued the module setup without a remark!

    To achieve this I ran the following command as root:

    mount --bind /var/www /home

    That is it really. Now the directories act as one for the suEXEC wrapper too.

    Please note this will usually only last till next reboot. To mount permanently include the following line into your /etc/fstab:

    /var/www /home none bind

    The following is the extract from the mount man page:

    Since Linux 2.4.0 it is possible to remount part of the file hierarchy somewhere else. The call is
    mount --bind olddir newdir
    or fstab entry is:
    /olddir  /newdir  none  bind
    After this call the same contents is accessible in two places.  One can also remount a single file (on a single file).

    One note is that if you already had local users set up inside the /home directory you will mount on top of it, making the existing users data unavailable (not deleted). Simply unmount again and the users data will be back again. To get around this change the default path Virtualmin uses to create new virtual hosts home directories to something else e.g. /virtualmin. This can be done in the Users & Groups module.