#!/usr/bin/perl # searchdirectory.pl - # Version 1 - july 2009 # # Program to imp[lement a simple search for numbers on a CISCO IP # phone that supports XML # # just call this script as the services (or part thereof) URL # for a CISCO IP Phone # # For a 796x/7940, in the SIPDefault or specific SIP config file add # services_url: "http:////searchdirectory.pl # EG :- services_url: "http://1.2.3.4/cgi-bin/rss2cisco.pl" # # For a 797x/7945, in the SEP config file add # http://196.22.67.196/cgi-bin/rss2cisco.pl # EG :- http://1.2.3.4/cgi-bin/rss2cisco.pl" # # # This program is licensed under the BSD license :- # http://creativecommons.org/licenses/BSD/ # Nic Tjirkalli # # # requires the perl CGI module # It can be obtained from http://search.cpan.org/ use strict; use CGI; # Hash of names and numbers # The key is the name my %directory = ( 'Receptionist','1000000100', 'Person A','1000000389', 'Person B','1000000390', 'Person C','1000000391', ); #################################################################### ## There should be nothing to change after here ## Unless you wanna rewrite the internals #################################################################### my %property; # Construct url to where script is script $ENV{SERVER_NAME} =~ s!/+$!!; $ENV{SCRIPT_NAME} =~ s!^/+!!; my $pathto = "http://$ENV{SERVER_NAME}/$ENV{SCRIPT_NAME}"; # Get environment variables returned by phone web browser getenv(); # Get variables passed in response my $query = new CGI; #Return HTTP header my $header=$query->header(); # Get the mac address of the phone - well sort of MAC my $name=$query->param('name'); # Get other Variables my $letters=undef; $letters=$query->param('letters'); # First time page is being displayed so it needs to asjk the user # for what search criteria if (!defined($letters)) { &request_search; } # A search criteria was specified so it needs to do a lookup if (defined($letters)) { &printitems; } sub getenv { my $var; my $val; foreach $var (sort(keys(%ENV))) { $val = $ENV{$var}; $val =~ s|\n|\\n|g; $val =~ s|"|\\"|g; $property{$var} = $val; } } sub printitems { my $pth= "$pathto?opts="; my $hash_val = ""; print "Content-Type: text/xml\n\n"; print "\n"; print < IP Telephony Directory External directory TEST my $count = 0; # # Limit output to 30 hits # foreach (sort keys %directory) { $hash_val = $_; if ( ($hash_val =~ m/$letters/i) && ($count < 30)) { print < $hash_val $directory{$hash_val} TEST $count++; } } print < TEST } sub request_search() { print < Directory Lookup Who You Looking For? $pathto Name letters A TEXT }