Provisionar telefonos Grandstream con Elastix 1.6.2

Imagen de RazaMetaL

Tema: 

Administrar cientos de telefonos puede ser una tarea tediosa, Elastix cuenta con un módulo de provisionamiento que soporta varias marcas y modelos de teléfonos y gateways.

En este articulo explicaré como lograr provisionar de manera centralizada la configuración para dispositivos Grandstream GXP280 y GXP2000, he modificado la plantilla de creación del archivo de configuración para que contenga los parámetros generales comunes para todos mis teléfonos.

El modulo trae dos bugs que podemos corregir fácilmente, al momento de crear el archivo de configuración le agrega la extensión .cfg lo cual no es correcto y también el script que compila el archivo de configuración tiene erroneamente configurada la ruta del ejecutable de java.

Para arreglarlo:

* Reemplazamos el contenido de /tftpboot/GS_CFG_GEN/bin/encode.sh con:

#!/bin/bash

JAVA_HOME=/opt/openfire/jre
GAPSLITE_HOME=/tftpboot/GS_CFG_GEN

# Do NOT modify below this line
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:$GAPSLITE_HOME/lib/`uname -m`
export LD_LIBRARY_PATH

$JAVA_HOME/bin/java -classpath $GAPSLITE_HOME/lib/gapslite.jar:$GAPSLITE_HOME/lib/bcprov-jdk14-124.jar:$GAPSLITE_HOME/config com.grandstream.cmd.TextEncoder $*

Buscamos en /var/www/html/modules/endpoint_configuration/libs/paloSantoFileEndPoint.class.php :

exec("/tftpboot/GS_CFG_GEN/bin/encode.sh {$ArrayData['data']['filename']} /tftpboot/gxp{$ArrayData['data']['filename']}.cfg /tftpboot/cfg{$ArrayData['data']['filename']}.cfg",$arrConsole,$flagStatus);

Y lo reemplazamos con:

exec("/tftpboot/GS_CFG_GEN/bin/encode.sh {$ArrayData['data']['filename']} /tftpboot/gxp{$ArrayData['data']['filename']}.cfg /tftpboot/cfg{$ArrayData['data']['filename']}",$arrConsole,$flagStatus);

Después de estas modificaciones el módulo podrá crear y guardar los archivos que el teléfono requiere para que funcione en nuestra implementación.

Lo primero que necesitaremos es descargar el firmware, paquete de lenguaje castellano y tonos de timbre para el modelo de teléfono GXP280/GXP2000 (el mismo firmware sirve para ambos teléfonos):


cd /tftpboot
wget http://www.grandstream.com/DOWNLOAD/FIRMWARE/BT200_GXP/Release_BT200_GXP_1.2.2.26.zip
unzip Release_BT200_GXP_1.2.2.26.zip
wget http://www.grandstream.com/DOWNLOAD/FIRMWARE/BT200_GXP/GXP_Language_Pack.zip
unzip GXP_Language_Pack.zip
unzip Spanish.zip
wget http://www.grandstream.com/DOWNLOAD/FIRMWARE/BT200_GXP/RingTone.zip
unzip RingTone.zip

El modulo de provisionamiento no muestra en sus opciones el modelo GXP280, podemos agregarlo con el siguiente procedimiento:

sqlite3 /var/www/db/endpoint.db
sqlite> insert into model values(50,'GXP280','GXP280',3);
sqlite> insert into model values(51,'BT200','BT200',3);
sqlite> .exit

Reemplazamos la plantilla que esta ubicada en /var/www/html/modules/endpoint_configuration/libs/vendors/Grandstream.cfg.php :

<?php
/*
PrincipalFileGrandstream nos retorna el contenido del archivo de configuracion de los EndPoint
Grandstream, para ello es necesario enviarle el DisplayName, id_device, secret, ipAdressServer
*/
function PrincipalFileGrandstream($DisplayName, $id_device, $secret, $ipAdressServer)
{
$content="
# Clave de administracion del dispositivo
# Recuerden cambiarla por una contraseña mas segura
P2 = verysecurepassword

# Nombre de la cuenta
P270 = $id_device

# Servidor SIP
P47 = $ipAdressServer

# Proxy SIP
P48 = $ipAdressServer

# SIP User ID
P35 = $id_device

# Authenticate ID
P36 = $id_device

# Authenticate password
P34 = $secret

# Nombre a mostrar en la pantalla del telefono
P3 = $DisplayName

# Soporte DHCP. 0 - si, 1 - no
P8 = 0

# Tonos utilizados en Ecuador
# Dial Tone
P343 = f1=425,f2=425;

# Busy Tone
P348 = f1=425,f2=425,c=33/33;

# Send DTMF. 8 - in audio, 1 - via RTP, 2 - via SIP INFO
# 11 - In Audio & RTP & SIP INFO, 9 - In Audio & RTP
# 10 - IN Audio & SIP INFO, 3 - RTP & SIP INFO
P73 = 1

# Ringtone 1
P105 = ring1.bin

# Display Language. 0 - English, 3 - Secondary Language, 2 - Chinese
P342 = 2

# language file postfix
P399 = Spanish

# NTP Server
P30 = $ipAdressServer

# Enable Call Features. 0 - no, 1 - yes
P191 = 0

# Account Ring Tone. 0 - system ring tone, 1 - custom ring tone 1, 2 - custom ring tone 2
# 3 - custom ring tone 3.
P104 = 3

# Display CID instead of Name. 0 - no, 1 - yes
# GXP280 only
P1344 = 0

# SIP User ID is phone number. 0 - no, 1 - yes
P63 = 1

# SIP Registration. 0 - no, 1 - yes
P31 = 1

# Unregister On Reboot. 0 - no, 1 - yes
P81 = 1

# Register Expiration (in minutes. default 1 hour, max 45 days)
P1812 = 60

# Lock Keypad Update. 0 - no, 1 - yes
P88 = 1

# Firmware Upgrade. 0 - TFTP Upgrade, 1 - HTTP Upgrade.
P212 = 0

# Firmware Server Path
P192 = $ipAdressServer

# Config Server Path
P237 = $ipAdressServer

# Automatic Upgrade. 0 - No, 1 - Yes. Default is No.
P194 = 0

# Check for new firmware every () minutes, unit is in minute, minimnu 60 minutes, default is 7 days.
P193 = 10080

# Use firmware pre/postfix to determine if f/w is required
# 0 = Always Check for New Firmware
# 1 = Check New Firmware only when F/W pre/suffix changes
# 2 = Always Skip the Firmware Check
P238 = 1

#----------------------------------------
# XML Phonebook
#----------------------------------------
# Enable Phonebook XML Download
# 0 = No
# 1 = YES, HTTP
# 2 = YES, TFTP
P330 = 2

# Phonebook XML Server Path
P331 = $ipAdressServer

# Phonebook Download Interval
# This is an integer variable in hours.
# Valid value range is 0-720 (default 0), and greater values will default to 720
P332 = 12

# Remove Manually-edited entries on Download
# 0 - No, 1 - Yes, other values ignored
P333 = 0";

return $content;
}

function templatesFileGrandstream($ipAdressServer)
{
$content= <<

Para habilitar la libreta de direcciones, se debe crear el siguiente archivo /tftpboot/gs_phonebook.php :


<?php

// File: gs_phonebook.php
// version: 1.0
// Date: 07-17-2006
// Author: Shane Steinbeck http://www.steinbeckconsulting.com
// Description: Realtime XML phonebook from MySQL database for Grandstream GXP-2000 firmware 1.1.1.17
// Modified by Guillermo Salas to use the FreePBX database to show the name and
// extension number.

header("Content-type: text/xml");

$host = "localhost";
$user = "root";
$pass = "eLaStIx.2oo7";
$database = "asterisk";

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");

$query = "SELECT user, description FROM devices ORDER BY description ASC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");

$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t\n";
$xml_output .= "\t\t" . $row['description'] . "\n";
$xml_output .= "\t\t\n";
$xml_output .= "\t\t\t\n\t\t\t\t" . $row['user'] . "\n";
$xml_output .= "\t\t\t\t0\n";

$xml_output .= "\t\t\t\n";
$xml_output .= "\t\n";
}

$xml_output .= "";

/***************************************************************************************

* Author: Mike
* Date: 10/03/2006
* This snipplet will save your xml file to the server for easier updating of your phone.
* To facilitate automatic updates, add a cron job to run this file at your desired interval (i.e. hourly).
*/

$filename = "/tftpboot/gs_phonebook.xml";

$fp = fopen($filename, 'wb');
fwrite($fp, $xml_output);
fclose($fp);

/**************************************************************************************/

print($xml_output);
echo $xml_output;

?>

Creamos una tarea programada para mantener el archivo de direcciones actualizado:

vi /etc/cron.daily/gs_phonebook

/usr/bin/php /tftpboot/gs_phonebook.php

En el módulo de provisionamiento damos click en "Mapear Endpoint", seleccionamos el dispositivo, seleccionamos el modelo, la extensión que se va a configurar y damos click en configurar. El módulo creará el archivo de configuración en /tftpboot.

Configuramos cada dispositivo para que descargue la configuración desde el TFTP que Elastix trae configurado y donde residen los archivos creados por el modulo de provisionamiento, reinciamos el teléfono y este descargará el firmware, archivo de lenguaje, archivo de configuración y la libreta de direcciones.

Comentarios