Skip to content

Instantly share code, notes, and snippets.

@ravnx
Created August 20, 2020 22:32
Show Gist options
  • Save ravnx/4226458c9aed27cdad9e9be466be36af to your computer and use it in GitHub Desktop.
Save ravnx/4226458c9aed27cdad9e9be466be36af to your computer and use it in GitHub Desktop.
Polycom Directory of all extensions for IP650 for Asterisk
#!/usr/bin/perl -w
# Quick script to hack out a directory for a mac address. I use it for the
# receptionist's BLF on her IP650 with sidecars.
use strict;
use Polycom::Contact::Directory;
use DBI;
# Grab the MAC address from ARGV and make a file
my $mac = $ARGV[0] or die "No MAC Specified\n";
my $contactFile = "/tftpboot/polycom/contacts/$mac-directory.xml";
# Create a new Empty Directory
my $dir = Polycom::Contact::Directory->new();
# Connect to the trixbox MySQL DB
my $dbh = DBI->connect('dbi:mysql:asterisk:localhost:3306','root','passw0rd',{ RaiseError => 1});
# Pull an array ref for the extensions
my $userAry = $dbh->selectall_arrayref("SELECT extension,name FROM users ORDER BY extension");
$dbh->disconnect();
# Set counter for speed dial index
my $x = 1;
# Loop through extensions
for my $a (@$userAry) {
# Split the trixbox name into first and last.
my ($fn,$ln) = split(/\s+/,$a->[1],2);
# My contacts are generally dirty, I'll make them look better. Some people may want
# to comment this out if you have people with unique capitalization.
$fn = ucfirst(lc($fn));
$ln = ucfirst(lc($ln));
# Insert the record into the object.
# I like the labels to be: extension firstname lastname "3721 Awesome Dude"
# -- buddy_watching lets the polycom monitor BLF status. For this to work,
# you must have feature.1.name="presence" feature.1.enabled="1" in
# /tftpboot/sip.cfg
# -- Check Polycom::Contact Documentation for Options
$dir->insert(
{ first_name => $fn, # <fn> in xml
last_name => $ln, # <ln> in xml
contact => "$a->[0]", # <ct> in xml
label => "$a->[0] $fn $ln", # <lb> in xml
buddy_watching => 1, # <bw> in xml
speed_index => $x, # <sd> in xml
buddy_block => 0, # <bb> in xml
auto_divert => 0, # <ad> in xml
auto_reject => 0, # <ar> in xml
},
);
$x++;
}
# Save the contact file.
$dir->save($contactFile);
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment