Grandstream GXP21xx Weather

UPDATE: This article (and sadly many others) have sat in my “Drafts” folder for far too long. I had originally intended to give this a look-over before release about a year ago, but I never got around to it. One of my co-workers recently reported a problem with the weather display on their IP phone. It seems that the Yahoo! feed may now be down (as predicted in this article). I’m publishing this now to assist anyone who may be interested in working on a MITM-type replacement for it. The original intent of this article was to help people find the appropriate city-code for their area.

Grandstream GXP21xx-series phones have a neat weather application. I’m using a GXP2140 with color screen and I thought it would be nice to display the weather on the home screen (a feature native to the phone).


The trick is trying to find the Location ID, or as Grandstream calls it “City Code” for your area. The phone automatically tries to find the best Location ID to use, but at least in my case, it wasn’t as accurate as I would have liked. So how do you find the correct location?

A packet capture shows that the phone grabs its weather information from Yahoo!

GET /forecastrss?p=USNJ0234&u=f HTTP/1.1
User-Agent: Grandstream Model HW GXP2120 SW DevId 000b8200ff00
Accept: */*

A little research shows that Yahoo! gets this data from, and these Location IDs are related. You can query for a Location ID for a given place name in text form at the following link:

Only the first 10 results are shown:

<search ver="3.0">
 <loc id="UKXX0085" type="1">London, GLA, United Kingdom</loc>
 <loc id="USAR0340" type="1">London, AR</loc>
 <loc id="USCA9301" type="1">London, CA</loc>
 <loc id="USKY1090" type="1">London, KY</loc>
 <loc id="USOH0520" type="1">London, OH</loc>
 <loc id="USTX0788" type="1">London, TX</loc>
 <loc id="USWV0443" type="1">London, WV</loc>
 <loc id="SFXX6559" type="1">London, LP, South Africa</loc>
 <loc id="SFXX7547" type="1">London, MP, South Africa</loc>
 <loc id="FJXX0101" type="1">Londoni, C, Fiji</loc>

Let’s use New York, NY as an example.

$ wget -q -O- ""
<search ver="3.0">
 <loc id="USNY0996" type="1">New York, NY</loc>
 <loc id="UKXX7149" type="1">New York, LIN, United Kingdom</loc>
 <loc id="JMXX0950" type="1">New York, 14, Jamaica</loc>
 <loc id="JMXX1405" type="1">New York, 06, Jamaica</loc>

A few different results are returned for “New York“, but the one we want it USNY0996. Once we know this code we update it in the web interface of the IP phone. In the case of my phone this was found under Settings -> Web Services


It looks like Yahoo! is using a newer API for weather these days, so I’m not sure how much longer these phones will be able to get weather. Documentation about the API is available here:

For posterity I’ve included a quick partial example of the output from these requests, in case you should ever need to implement your own service (to be intercepted at your firewall, or via DNS) in order to maintain this feature on your phone.

curl -s ""

The results have been trimmed down for brevity

 <lastBuildDate>Thu, 20 Aug 2015 7:19 pm BST</lastBuildDate>
 <yweather:location city="London" region=""   country="UK"/>
 <yweather:units temperature="C" distance="km" pressure="mb" speed="km/h"/>
 <yweather:wind chill="20"   direction="210"   speed="16.09" />
 <yweather:atmosphere humidity="78"  visibility="9.99"  pressure="1015.92"  rising="0" />
 <yweather:astronomy sunrise="5:50 am"   sunset="8:12 pm"/>
 <pubDate>Thu, 20 Aug 2015 7:19 pm BST</pubDate>
 <yweather:condition  text="Mostly Cloudy"  code="28"  temp="20"  date="Thu, 20 Aug 2015 7:19 pm BST" />
 <yweather:forecast day="Thu" date="20 Aug 2015" low="17" high="22" text="Mostly Cloudy" code="27" />
 <yweather:forecast day="Fri" date="21 Aug 2015" low="15" high="24" text="AM Clouds/PM Sun" code="30" />
 <yweather:forecast day="Sat" date="22 Aug 2015" low="18" high="29" text="Sunny" code="32" />
 <yweather:forecast day="Sun" date="23 Aug 2015" low="14" high="22" text="Showers" code="11" />
 <yweather:forecast day="Mon" date="24 Aug 2015" low="12" high="20" text="Showers" code="11" />
Posted in General Nonsense | Leave a comment

Bash Snippet: Friendly MAC Address Names

This article is about adding manufacturer information when displaying MAC addresses in bash script output to create friendlier data for the user. A manufacturer name can suggest more about a device than just the MAC address alone. For example, if you saw a MAC address with an OUI of B8-27-EB it probably wouldn’t mean much to you, but if you saw the name “Raspberry Pi Foundation” you’d have a pretty good clue that the device in question was a Raspberry Pi.

As you may know, MAC address ranges are registered to manufacturers by the IEEE Standards Association. The IEEE-SA provides a web-based look-up form where you can see which OUI is assigned to a vendor, or vice versa. It’s possible for your script to scrap the IEEE-SA’s web look-up resource (in fact I’ve done that in a script to detect and report new Wi-Fi clients on my home network). This is a slow (and not very nice) process when dealing with a larger number of MAC addresses, and so an offline method would be preferable.

The IEEE-SA has a set of data files you could download for this purpose:

That method requires occasionally freshening local copies of those files to make sure OUI assignment changes are reflected in the script output.

An alternative option, and the one I’m going to be using is to reference the data in the “manuf” file that Wireshark uses for this same purpose. Wireshark displays ethernet addresses by replacing the vendor/OUI portion of the MAC address with a shortened vendor name, but leaves the unique device portion of the address untouched. Here is an example screen shot taken from Wireshark:


You can see that the MAC address 1c:6f:65:95:2b:ad belongs to a device made by Giga-byte and it is talking to 00:07:50:52:86:d1, a device made by Cisco.

If you download Wireshark’s “manuf” file through your package manager, you should receive updates to this list as part of your normal update routines. It is not necessary to download a full copy of Wireshark. Under Ubuntu and probably other Debian-based systems the file is provided by the package libwireshark-data.

apt-get install libwireshark-data

On Ubuntu the manuf file resides in /usr/share/wireshark, but you might need to update the script for your system.

get_line() {
        while read line
                if [ "${line//$1}" != "$line" ]; then
                        echo "$line"

format_mac() {
        if [ -f "/usr/share/wireshark/manuf" ]; then
                #prefix="$(grep -m1 "${MAC:0:8}" "/usr/share/wireshark/manuf")"
                prefix="$(get_line "${MAC:0:8}" <"/usr/share/wireshark/manuf")"
                prefix="${prefix%% *}"
                if [ -n "$prefix" ]; then
                        MAC="${prefix}_${MAC: -8}"
        echo "$MAC"
$ format_mac "00:07:50:52:86:d1"

The above example uses shell built-ins, but if you do not care about the purity of your bash script you could use grep (as shown in the comment) and omit the get_line function from your script for faster results. Notice that this script doesn’t currently parse OUI ranges that are shared across manufacturer’s despite that information being available in the manuf file.

Posted in General Nonsense | Leave a comment

Install Certified Asterisk 13 from source on Ubuntu 14.04 LTS

Need an Asterisk setup? Why not combine the long term support of an Ubuntu LTS release with the long term support of a Certified Asterisk release?

Certified Asterisk releases are supported for around 4 years, and Ubuntu LTS for around 5 years, helping ensure you don’t need to mess around with major reconfiguration again for some time.

We’ll be working with Certified Asterisk 13 and Ubuntu 14.04. Certified Asterisk 13 has an end-of-life date (EOL) of October 24, 2019, and Ubuntu 14.04 has an EOL of April 2019.

A list of Asterisk versions and their end of life dates can be found here:


Let’s start by making sure we are up to date

apt-get update && apt-get -y upgrade

Make sure kernel headers are installed

apt-get -y install linux-headers-$(uname -r)

Grab a sensible build environment along with subversion and git which we will use later to retrieve additional source code

apt-get -y install build-essential subversion git

For many people, the next two sections will be optional, you can probably skip down to the “Asterisk” section below.


On the system I’m working with, I have a Digium T1/E1 PRI card, so I’m going to grab the DAHDI modules and tools as well. You may want to install DAHDI regardless of your hardware for the dahdi_dummy timing driver. At one point the Zaptel dummy driver was used for MeetMe conferences when Digium hardware based timing was absent, although I’m not sure if this still remains the case.

We’ll be building our source under /usr/local/src, so switch in to that directory.

cd /usr/local/src

Download and unpack DAHDI

tar zxvf dahdi-linux-complete-current.tar.gz

Switch in to the newly created source directory, compile, and install DAHDI.

cd dahdi-linux-complete-
make all
make install
make config

If you have DAHDI hardware you should see the type of card in the make config output

 Adding system startup for /etc/init.d/dahdi ...
   /etc/rc0.d/K30dahdi -> ../init.d/dahdi
   /etc/rc1.d/K30dahdi -> ../init.d/dahdi
   /etc/rc6.d/K30dahdi -> ../init.d/dahdi
   /etc/rc2.d/S15dahdi -> ../init.d/dahdi
   /etc/rc3.d/S15dahdi -> ../init.d/dahdi
   /etc/rc4.d/S15dahdi -> ../init.d/dahdi
   /etc/rc5.d/S15dahdi -> ../init.d/dahdi
DAHDI has been configured.

List of detected DAHDI devices:

pci:0000:04:02.0     wcte13xp+    d161:800b Wildcard TE132/TE134

run 'dahdi_genconf modules' to load support for only
the DAHDI hardware installed in this system.  By
default support for all DAHDI hardware is loaded at
DAHDI start.

Switch back to /usr/local/src to continue building other packages

cd /usr/local/src


As I mentioned above I have a PRI card, so I also will be installing libpri, but you can skip this step if it doesn’t apply to you.

tar zxvf libpri-1.4-current.tar.gz
cd libpri-1.4.15/
make install
cd ..


OK, finally we can get to building Asterisk. Let’s find the latest certified Asterisk 13 on this page:

At the time of writing it looks like that is 13.1-cert1, so that’s what we’ll use in this example (you may need to adjust these instructions accordingly).

Download the gzip compressed Asterisk tarball.

cd /usr/local/src

Decompress and unpack the file

tar zxvf certified-asterisk-13.1-current.tar.gz

Switch in to the newly created source directory

cd certified-asterisk-13.1-cert1/

Add mp3 support


Fetch all the prerequisites available in the package repository

 ./contrib/scripts/install_prereq install

I ran into a problem on one computer where the install_prereq script Aborted with a message about conflicts. It looks like aptitude returned “:i386” prefixed on some of the output while searching for installed packages. When then data was later fed in to apt-get it failed.. so I modified it with:
aptitude -F ‘%c %p’ search ^build-essential$ ^libz-dev$ |awk ‘/^p/{print $2}’ |sed ‘s/:i386//g’

On line 74 changed:

| awk '/^p/{print $2}'


| awk '/^p/{print $2}' |sed 's/:i386//g'

I think the script also looks for pjproject-devel, and I wonder if that should be libpjproject-dev instead.

If you get conflicts and the script aborts, or if you prefer not installing everything but the kitchen sink you could manually grab the essentials:

apt-get install build-essential # Compiler
apt-get install libxml2-dev # Required
apt-get install libncurses5-dev libreadline-dev libreadline6-dev  # Termcap stuff
apt-get install libiksemel-dev # For Google Talk support
apt-get install libvorbis-dev  # For Ogg Vorbis format support
apt-get install libssl-dev # Needed for SIP
apt-get install libspeex-dev libspeexdsp-dev  # For speex codec
apt-get install mpg123 libmpg123-0 sox openssl wget subversion openssh-server # Odds and ends

If libvpb0 gets installed you may be prompted to type in your country calling code


After installation completes you should see a message indicating success.

## install completed successfully

There may be additional source code to grab that wasn’t retrieved from the Ubuntu repository. This will potentially install Network Broadcast Sound, libresample, jansson, libsrtp, and pjproject

./contrib/scripts/install_prereq install-unpackaged

Now that the prerequisites should be well covered, let’s configure Asterisk.
Run the configure script


If everything works out, you should get the ASCII art Asterisk logo

            .$7$7..          .7$$7:.
          .$$:.                 ,$7.7
        .$7.     7$$$$           .$$77
     ..$$.       $$$$$            .$$$7
    ..7$   .?.   $$$$$   .?.       7$$$.
   $.$.   .$$$7. $$$$7 .7$$$.      .$$$.
 .777.   .$$$$$$77$$$77$$$$$7.      $$$,
 $$$~      .7$$$$$$$$$$$$$7.       .$$$.
.$$7          .7$$$$$$$7:          ?$$$.
$$$          ?7$$$$$$$$$$I        .$$$7
$$$       .7$$$$$$$$$$$$$$$$      :$$$.
$$$       $$$$$$7$$$$$$$$$$$$    .$$$.
$$$        $$$   7$$$7  .$$$    .$$$.
$$$$             $$$$7         .$$$.
7$$$7            7$$$$        7$$$
 $$$$$                        $$$
  $$$$7.                       $$  (TM)
   $$$$$$$.           .7$$$$$$  $$

Ensure the the modules you want are enabled.

make menuconfig

You might want to see if there are any neat things you want. format_mp3 for example, or EXTRA-SOUNDS-EN-GSM might be desirable.

Channel Drivers -> chan_sip
Add-ons -> format_mp3
Extra Sounds Packages -> EXTRA-SOUNDS-EN-GSM


Recently the Asterisk project started using PJSIP as a replacement for the older chan_sip. If you want or need the classic Asterisk SIP module you’ll have to manually select it.

To use the deprecated chan_sip, unselect the the PJSIP channel driver.


Next, select the chan_sip driver.

When you are done making any changes “Save & Exit” out of menuconfig.

Now it is time to build Asterisk


You should get a message that the build completed successfully.

 +--------- Asterisk Build Complete ---------+
 + Asterisk has successfully been built, and +
 + can be installed by running:              +
 +                                           +
 +                make install               +

So let’s copy the newly built files into the right places on the system

make install

If everything went to plan, you should see a message that the install completed successfully.

 +---- Asterisk Installation Complete -------+
 +                                           +
 +                                           +
 + Asterisk has successfully been installed. +
 + If you would like to install the sample   +
 + configuration files (overwriting any      +
 + existing config files), run:              +
 +                                           +
 +                make samples               +
 +                                           +
 +-----------------  or ---------------------+
 +                                           +
 + You can go ahead and install the asterisk +
 + program documentation now or later run:   +
 +                                           +
 +               make progdocs               +
 +                                           +
 + **Note** This requires that you have      +
 + doxygen installed on your local system    +

Copy the init startup scripts to make asterisk start on boot

make config
 Adding system startup for /etc/init.d/asterisk ...
   /etc/rc0.d/K91asterisk -> ../init.d/asterisk
   /etc/rc1.d/K91asterisk -> ../init.d/asterisk
   /etc/rc6.d/K91asterisk -> ../init.d/asterisk
   /etc/rc2.d/S50asterisk -> ../init.d/asterisk
   /etc/rc3.d/S50asterisk -> ../init.d/asterisk
   /etc/rc4.d/S50asterisk -> ../init.d/asterisk
   /etc/rc5.d/S50asterisk -> ../init.d/asterisk

And you’re done.

Posted in General Nonsense | 1 Comment

Disable User Lookup Popup in osTicket v1.9.5.1

It appears I’m not the only person using osTicket for internal ticket tracking. The project has come a long way since I started using it, unfortunately most of the advancements are undesirable to my use. The software is geared toward having new tickets represent requests created by or in behalf of a user, rather than a pool of tasks needing assignment to agents. After replacing most of the default department names, groups, help topics, and SLA plans with things more meaningful to my use I was ready to get to work adding tickets. As I was populating tickets I grew increasingly annoyed by the need to fill in my name as the requester for each ticket. This dialog floats over the rest of the page content each time I click New Ticket.


Coworkers in my department already seemed uninterested in the prospect of using an internal ticket system, so I felt compelled to try and iron out foreseeable gripes about the particular implementation before subjecting them to it.

My fix for this annoyance was a quick edit to the file include/staff/ At the very end of that file I commented out the original javascript and added some that behaves as if a user was just selected through the popup. The user ID I choose was “6” which corresponds to a new user I created named “Internal Ticket”, but this value will obviously need to be adjusted for your own use.

    // Popup user lookup on the initial page load (not post) if we don't have a
    // user selected
    if (!$_POST && !$user) {?>
    /*setTimeout(function() {
      $.userLookup('ajax.php/users/lookup/form', function (user) {
        window.location.href = window.location.href+'&uid=';
    }, 100); */
    setTimeout(function() {
    window.location.href = window.location.href+'&uid=6';
    }, 100);
    } ?>

So now when I click on New Ticket, the “Internal Ticket” user is auto-filled for me.

Posted in General Nonsense | Leave a comment

YAC Caller ID Server for Asterisk

I recently upgraded the firmware of the IP phones in a small office using my Grandstream HTTP configuration pusher. One of the users complained that the Caller ID display under the new firmware was too small to be legible. I’m not convinced that the size of the font actually changed, but I wanted to offer some kind of solution. The ever helpful (although often outdated) wiki lists several options for call notifications under asterisk (the PBX in use in the office):

I liked the look of YAC: Yet Another Caller ID Program, by Jensen Harris the best. It is intended for use with a Caller ID capable modem, but works fine for my purpose as well. YAC has two pieces, a YAC listener, which runs on workstations that want to see incoming Caller ID, and a YAC server which collects Caller ID and sends to the listener(s). I’m using just the listener side and have written my own YAC server portion that collects its information through the Asterisk Management Interface. I used the SiComponents Resource Builder 3 resource editor to replace the yak graphic normally shown in YAC with the office’s logo inside of the yak.exe binary (a fake example is shown below).


Here is my YAC Caller ID server for Asterisk:


extensions=(1100[] 1101[] 1102[])


if [ "$1" == "--detach" ] ; then
        $0 >/dev/null &

exec 3<>/dev/tcp/$server/$port

ami_write() {
        echo "$@" >&3

ami_read() {
        read -t1 server_out  <&3
        # strip CR 0x0d line terminator
        echo "$server_out"


ami_get_response() {
        while [ 1 ]
                if [ "${response:0:10}" == "Response: " ]; then
                        echo "$response"

ami_logout() {
        if [ -n "$connected" ]; then
                ami_write "Action: Logoff"
                ami_write ""
                if [ "$(ami_get_response)" == "Goodbye" ]; then
                        echo "Logged out."

trap "ami_logout; exit" EXIT SIGTERM

ami_login() {
        ami_write "Action: Login"
        ami_write "Username: $ami_user"
        ami_write "Secret: $ami_pass"
        ami_write ""
        if [ "$(ami_get_response)" != "Success" ]; then
                echo "Login failed." >&2
                echo "Logged in."


echo "Waiting for calls..."

while [ 1 ];

        if [ "${line:0:11}" == "Event: Dial" ]; then
                while [ -n "$line" ]
                        if [ "${line:0:13}" == "CallerIDNum: " ]; then
                        if [ "${line:0:14}" == "CallerIDName: " ]; then
                                callerid="${line:14} $callerid"
                        if [ "${line:0:12}" == "Dialstring: " ]; then

        if [ -n "$called_extension" ] && [ -n "$callerid" ]; then
                for extension in ${extensions[@]}
                        if [ "$extension" == "$called_extension" ]; then
                                echo "New call to $extension from $callerid"
                                exec 4<>/dev/tcp/$ip/10629
                                echo "@CALL$callerid" >&4
                                exec 4>&-

                unset called_extension
                unset callerid

exec 3>&-
echo "Quit."

You’ll need to replace the server, port, user and password with the correct information for your AMI setup. The “extensions” variable includes the internal extension and the IP address of the associated desktop/workstation that is running the YAC listener. The format is 1100[] where 1100 is the extension, and is the This way people see the Caller ID destined for their extension on their desktop. In environments with dynamically assigned desktop IP addresses this will require some additional effort to keep updated. Ideally I’d like to see something like YAC that logs in to a SIP server to monitor calls that way, seems like less to deal with, but many offerings like that included too many other features for my liking (click to call functionality, dial pad, etc).

The server captures SIGTERM and tries to logoff the AMI server before exiting

[root@phone ~]# ./
Logged in.
Waiting for calls...
New call to 1100 from WIRELESS CALLER ~5551212"
Logged out.

You can start the script into the background by using the –detach switch.

[root@phone ~]# ./ --detach
Posted in Telephony | Tagged , , | Leave a comment