briankelly63
Guru
- Joined
- Nov 14, 2008
- Messages
- 1,396
- Reaction score
- 320
Below is an example of a programmatic interface between a SIP phone, Wazo and a ELK alarm panel configured for lighting control.
The example could easily be changed to send whatever you like, wherever you like and is just meant to illustrate how this type of thing is put in place on an existing Wazo install.
In the example the string to send is constructed and then sent to the ELK device over the lan. The ELK has an Ethernet to RS232 interface.
Without the appropriate entries in the Wazo locations directory the ngix webserver would not accept the URL.
An ELK command specification manual is attached.
The example could easily be changed to send whatever you like, wherever you like and is just meant to illustrate how this type of thing is put in place on an existing Wazo install.
In the example the string to send is constructed and then sent to the ELK device over the lan. The ELK has an Ethernet to RS232 interface.
Without the appropriate entries in the Wazo locations directory the ngix webserver would not accept the URL.
An ELK command specification manual is attached.
Code:
create the file /etc/nginx/locations/https-available/elk-commands
with the following contents:
location ~ /elk/ {
root /var/www/html;
index index.php;
try_files $uri $uri/ =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
then create this link to it
ln -s /etc/nginx/locations/http-enabled/elk-commands /etc/nginx/locations/http-available/elk-commands
create the file:
/var/www/html/elk/elkm1y.php
add this content:
<?php
#Elk M1 php command sender
#Syntax Example: Source ip -> Destination IP Port Command
#http://XXX.XXX.XXX.XXX/elk/elkm1y.php?elkip=XXX.XXX.XXX.XXX&elkport=2101&&elkcmd=pnI11
#Brian Kelly 2017
#Initialize some variables
$command = 0;
$val = 0;
$i = 0;
$EOF = "\r\n";
#Get input values from XML URL sent by phone
$elkcmd=$_GET['elkcmd'];
$elkip=$_GET['elkip'];
$elkport=$_GET['elkport'];
# Add the two future use characters to the string.
$elkcmd .= '00';
# Assemble it, prepend length value + 2.
$command = sprintf('%02X',strlen($elkcmd) + 2 ).$elkcmd;
#Loop through string and calc checksum
for ($i=0;$i<strlen($command);$i++) {
$val += ord(substr($command,$i,1));
}
#Attach value to end of string command
$command .= sprintf('%02X',((~$val + 1) & 0xFF));
#Open addr and port, send command plus EOF
$fp = fsockopen($elkip, $elkport);
fwrite($fp, $command.$EOF);
fclose($fp);
exit;
?>
Commands can then be sent by crafting a URL (see example above) and either executing it from a browser (for testing) or assigning it to
a URL button on a phone.