Aastra-day-night
You should throw a big "Thank You" at alexis who true to his word paid the bounty. It's people like alexis that make sure you have cool toys to deploy for you and your customers. If you use this, you should PM him and zip him $10 or $25 to help offset his expenditure.
That said, here are the instructions for obtaining and installing the Day/Night button on Aastra phones.
1.) First make sure you have the latest Aastra firmware on your phone. yum update aastra-ipphone and restart the phone(s).
2.) Copy the code below to a new file called daynight.php in /var/www/html/aastra (use winscp or nano in putty) (If you don't have an aastra directory, that means you have not installed the aastra-xml-scripts package, yum install aastra-xml-scripts)
<?
##############################################################################
# FreePBX Day/Night Control
#
# Aastra SIP Phones 1.4.1 or better
#
# Copyright 2008 Schmooze Communications, LLC
# View the blog at http://schmoozecom.blogspot.com
# All rights reserved. THIS COPYRIGHT NOTICE MUST NOT BE REMOVED
# UNDER ANY CIRCUMSTANCES.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Some code adapted from Copyrighted 2007 Aastra Telecom Ltd code
#
# Supported Aastra Phones
# All Phones, LED status on 5i Series
#
# daynight.php?user=XXX&key=YYYYY&daynight_index=X
# XXX is the extension of the phone on the platform
# YYYYY is the name of the key calling the XML app
# X is the FreePBX Day/Night Feature Code Index (0-9)
#
#############################################################################
#############################################################################
# Includes
#
include ("include/phpagi/misc.php");
include ("include/phpagi/phpagi-asmanager.php");
require_once('include/AastraCommon.php');
require_once('include/AastraIPPhoneTextScreen.class.php');
require_once('include/AastraIPPhoneFormattedTextScreen.class.php');
require_once('include/AastraIPPhoneExecute.class.php');
require_once('include/AastraIPPhoneConfiguration.class.php');
require_once('include/AastraIPPhoneStatus.class.php');
function Aastra_manage_daynight($daynight_index,$action) {
// Connect to Asterisk Manager
$asm = new AGI_AsteriskManager();
$res = $asm->connect();
// GET day/night status out of Asterisk DB for the slot in question
$res = $asm->Command('database get DAYNIGHT C'.$daynight_index);
$line = split("\n", $res['data']);
$value = split(" ", $line[1]);
if($value[1] == "NIGHT") {
$night = 1;
}
else {
$night = 0;
}
if($action == 'change') {
// change Day/Night status
if($night == 0) {
$res = $asm->Command('database put DAYNIGHT C'.$daynight_index.' NIGHT');
$night = 1;
}
else {
$res = $asm->Command('database put DAYNIGHT C'.$daynight_index.' DAY');
$night = 0;
}
}
$asm->disconnect();
return($night);
}
#####################################################################
# Global parameters
#####################################################################
# Retrieve parameters
$user = $_GET['user'];
$action = $_GET['action'];
$key = $_GET['key'];
$night = $_GET['night'];
// $daynight_index is the FreePBX Day/Night Feature Code Index (0-9)
$daynight_index = $_GET['daynight_index'];
# Test User Agent
Aastra_test_phone_version("1.4.1.",0);
# Force default action
if($action == "")
$action = "change";
# Get header info
$header = Aastra_decode_HTTP_header();
# Depending on action
switch($action) {
case 'display':
if(Aastra_is_formattedtextscreen_supported()) {
$object = new AastraIPPhoneFormattedTextScreen();
$object->setdestroyOnExit();
$object->setTimeout('2');
if($header['model']!="Aastra53i") {
$object->addLine("");
$object->addLine("");
}
if ($night == 1)
$object->addLine("Night Mode activated","double","center");
else
$object->addLine("Day Mode activated","double","center");
$object->addSoftKey("6","","SoftKey:Exit");
}
else {
$object = new AastraIPPhoneTextScreen();
$object->setdestroyOnExit();
if ($night == 1) {
$object->setTitle('Night Mode');
$object->setText("Activated");
}
else {
$object->setTitle('Day Mode');
$object->setText("Activated");
}
$object->addSoftKey("6","Exit","SoftKey:Exit");
}
break;
case 'msg':
case 'msg2':
$object = new AastraIPPhoneStatus();
$object->setSession('DAYNIGHT');
if($action == "msg")
$object->setBeep();
if ($night == 1)
$object->addEntry(0,'Night Mode');
else $object->addEntry(0,'');
break;
case 'key':
# Prepare result screen
$object = new AastraIPPhoneConfiguration();
if($night==1)
$object->addEntry($key." label",'Night Mode On');
else
$object->addEntry($key." label",'Day Mode On');
break;
case 'change':
case 'check':
$night = Aastra_manage_daynight($daynight_index,$action);
$object = new AastraIPPhoneExecute();
if($action == "change")
$object->addEntry($XML_SERVER."?action=msg&night=".$night);
else
$object->addEntry($XML_SERVER."?action=msg2&night=".$night);
if(Aastra_is_ledcontrol_supported()) {
if($night == 1)
$object->addEntry("Led: ".$key."=on");
else
$object->addEntry("Led: ".$key."=off");
}
else {
if(Aastra_is_configuration_supported())
$object->addEntry($XML_SERVER."?action=key&night=".$night."&key=".$key);
}
if($action == 'change')
$object->addEntry($XML_SERVER."?action=display&night=".$night);
break;
}
$object->output();
exit;
?>
To configure as a programmable key (9133i or 5i). If you have a 5i series phone, you can optionally skip to next set of instructions for adding a soft key instead.
a.) Go to the web interface of the phone, add a button of type XML
http://your.ip.address/aastra/daynight.php?user=$$SIPUSERNAME$$&key=prgkey6&daynight_index=0
b.) Note above, the prgkey6 and daynight_index=0 variables. You need to change prgkey6 to be whatever button number you are setting up and daynight_index=0 referrs to the FreePBX Day/Night index you chose in the web interface (0-9). Don't modify the user= variable. Aastra automatically does this substituion for you. It's probably not even necessary, but keep it there anyway.
To configure as a soft key on 5i Series (including 55i/57i/57ict):
a.) Go to the web interface of the phone, add a soft button of type XML
Name it "Night Mode" so the user knows that when the LED is lit, they are in Night Mode.
b.) Note above, the softkey1 and daynight_index=0 variables. You need to change softkey1 to be whatever button number you are setting up and daynight_index=0 refers to the FreePBX Day/Night index you chose in the web interface (0-9). Don't modify the user= variable. Aastra automatically does this substitution for you. It's probably not even necessary, but keep it there anyway.
Other notes:
Buttons are not "always aware". Therefore if Day/Night mode changes outside of the phone that the button is on, the BLF will not update. It will however recover and tell you what mode it switched it to on the PBX upon pressing the button.
These "updates" are exactly the same problem as the DND button on the aastra phones. If you change the DND for that user elsewhere, the phone isn't going to update (until one of the event hooks is executed). Aastra has specifically designed "events" for this issue. The current events are "startup", "register","on hook", "offhook", "incoming", and "outgoing". These are fairly self-explanatory. It is outside the scope of these instructions to set these parameters up. Theoretically, this can update the day/night status when the phone registers, anytime there is an incoming call or outgoing call, etc, etc. There is also a theoretical way to use XML push to specific phones, but that is *way* outside the scope of these instructions.
Programmably changing LEDs on the 9133i (and 480i) is currently impossible with the their current firmwares. Why, I do not know since they are there just like the 5i series of phones with LCD/BLF lights. When night mode is enabled on these phones, it will say "Night Mode" for the first line of the LCD. LED works on the 5i series of phones.
All credit goes to Ethan @ Schmooze.
Wiki Home|Tutorials|Troubleshooting|Additional Scripts and Tricks|Hardware Support

