A few photos from Hawaii
So here are a few of those photos I promised to post…
A few svn pre-commit hooks
I’ve recently been looking around for some pre-commit hooks for our subversion repositories. I figured that since I have them all up and running now, I might as well share them.
I can’t remember where I got all of these from, so if it’s one of yours, then I apologise. Feel free to contact me and I’ll give you credit for it.
Check for blank/empty commit messages and reject
This goes in hooks/pre-commit
TXN="$2"
# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
SVNLOOKOK=1
$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0
if [ $SVNLOOKOK = 0 ]; then
echo Empty log messages are not allowed. Please provide a proper log message. 1>&2
exit 1
fi
exit 0
Check that the commit message has a reference to a JIRA issue
This goes in hooks/pre-commit, it also uses ‘check_log_message.sh’ which can be found down further.
TXN="$2"
# Check log message for proper task/bug identification
if [ -x ${REPOS}/hooks/check_log_message.sh ]; then
${REPOS}/hooks/check_log_message.sh "${REPOS}" "${TXN}" 1>&2 || exit 1
fi
exit 0
check_log_message.sh
REPOS="${1}"
TXN="${2}"
SVNLOOK=/usr/bin/svnlook
LOG_MSG_LINE1=`${SVNLOOK} log -t "${TXN}" "${REPOS}" | head -n1`
if (echo "${LOG_MSG_LINE1}" | egrep '^[a-zA-Z]+[-][1-9][0-9]*[:]?[\s]*.*$' > /dev/null;) \
|| (echo "${LOG_MSG_LINE1}" | egrep '^[nN][oO][jJ][iI][rR][aA][:]?[\s]*.*$' > /dev/null;) \
|| (echo "${LOG_MSG_LINE1}" | egrep '^\[maven-release-plugin\][\s]*.*$' > /dev/null;)
then
exit 0
else
echo ""
echo "Your log message does not contain a JIRA Issue identifier (or bad format used)"
echo "The JIRA Issue identifier must be the first item on the first line of the log message."
echo ""
echo "Proper JIRA format: 'AAA-000'"
echo "JIRA regex: '^[a-zA-Z]+[-][1-9][0-9]*[:]?[\s]*.*$'"
exit 1
fi
Check that commit message is more than 5 characters long
This goes in hooks/pre-commit
TXN="$2"
SVNLOOK=/usr/bin/svnlook
LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep [a-zA-Z0-9] | wc -c)
if [ "$LOGMSG" -lt 5 ]; then
echo -e "Please provide a meaningful comment when committing changes." 1>&2
exit 1
fi
exit 0
Follow up to SPA942 Personal Directory with LDAP
I just wanted to follow up on my previous post about using LDAP and PHP to push the directories on the SPA942.
I’ve included a whole lot of code below, and please note that a lot of this is me just getting the job done. The code is probably messy and poorly written, and some of it is taken from other sites/samples.
Unfortunately, blogger seems to take away all my nice formatting (indents etc…), so you’ll have to bear with me. Also, long comments appear across multiple lines in here, so that could make it even harder. Copy the code into a program like notepad++ and set language to php to make it easier to read.
Firstly, just need to include a few files etc…
set_time_limit(240);
include_once("common/dbConnection.php");
include_once("common/header.php");
include_once("common/ldapInfo.php");
include_once("voip_ext.php");
dbConnection.php connects to a Mysql DB that I use basically as an asset register. It contains IPs, allocations, extensions, invoice numbers yada yada yada. Originally, I drove this script entirely from LDAP, however once users started to have multiple extensions (depending on which site they were working from), LDAP (well Active Directory actually) just couldn’t cut it. Note that this still uses LDAP for getting user details (display name) and extensions. It cross references these with Mysql.
header.php is just some menu’s etc
ldapInfo.php is the connection to LDAP. It returns the info as $info
voip_ext.php is a list of extensions returned as $extensions. Note that the extensions have changed with firmware updates, so check your phone to see what yours are.
The rest of the code follows.
I’ve tried my best to include comments, and please remember this is not a complete solution (due to DB dependencies etc…) but will hopefully get you started.
If anyone is interested in the DB schema, leave a comment and I can post it here.
//MAIN
//get users extensions
$UserExtensions = getExtensions();
//100 slots to use. fill from bottom, so 99 -> 0
$extID = 99;
//for each extension, find the appropriate info
foreach ($UserExtensions as $ext) {
if ($ext <> "" && $ext <> 0){
$pDir .= ("&".dirEntry($info,$ext));
}
}
//tidy up and sort the pdir string
$pDir = substr($pDir,1);
$pDir = explode("&",$pDir);
sort($pDir);
//assign an extid to each entry
foreach ($pDir as &$entry) {
$entry = ($extensions[$extID]."=n%3D".$entry);
$extID--;
}
//more tidying of pdir
$pDir = implode("&",$pDir);
$pDir .= getGroups($info);
$pDir = str_replace(" ","%20",$pDir);
//need to fill in from extID to 0 to clean vacant entries from pdir
//note that this will wipe out any duplicate names (was occuring when users were leaving)
//this will also wipe out any personal entries (i.e. this script is the only way that entries will appear in the directory)
while ($extID > 0) {
$pDir .= "&".$extensions[$extID]."=;";
$extID--;
echo $extID."<br />";
echo $pDir."<br />";
}
//run the wget (comment this out to test sending to a single phone - use next bit instead)
$phoneIPs = GetPhoneIPs();
foreach ($phoneIPs as $phoneIP) {
updatePhonePDir($phoneIP,$pDir);
}
//uncomment for testing
//updatePhonePDir("192.168.10.170",$pDir);
//FUNCTIONS
function getExtensions(){
//this gets all the phone extensions that i've allocated in mysql. Note that other extensions probably exist in ldap, but they're not assigned to a phone and hence we don't want them here.
$sql = "select allocation.extension from allocation order by allocation.extension asc";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$extensions .=$row["extension"].";";
}
mysql_free_result($result);
$extensions = explode(";", $extensions);
return $extensions;
}
function GetPhoneIPs(){
//this gets the ips of the phones. need this when performing the wget command
$sql = "select distinct phone_ip from asset where phone_ip not like ''";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$phoneIPs .=$row["phone_ip"].";";
}
mysql_free_result($result);
$phoneIPs = explode(";", $phoneIPs);
return $phoneIPs;
}
function dirEntry($info,$ext){
//this is creating the sting that we eventually want to POST to the phone's pdir
$allocationDetails = getAllocationDetails($ext);
$phoneMAC = $allocationDetails[0];
$phoneIP = $allocationDetails[1];
$siteName = $allocationDetails[2];
$serverIP = $allocationDetails[3];
$userDetails = ldapUserDetails($info,$ext);
$userSamAccountName = $userDetails[0];
$userDisplayName = $userDetails[1];
$userComany = $userDetails[2];
$ringtone = getRingTone($phoneIP);
return "$userDisplayName;p%3D$ext;r%3D$ringtone";
//return "n%3D$userDisplayName;p%3D$ext;r%3D$ringtone";
}
function ldapUserDetails($info,$ext){
//this matches the extensions with the names from ldap (we don't keep names in mysql)
for ($i=0; $i<$info["count"]; $i++) {
if ($info[$i]["ipphone"][0] == $ext) {
$samaccountname = strtolower($info[$i]["samaccountname"][0]);
$displayName = $info[$i]["displayname"][0];
$company = $info[$i]["company"][0];
if ($company == "") $company = "GLiNTECH"; //catch accounts with no company name specified
}
}
$results = array($samaccountname,$displayName,$company);
return $results;
}
function getAllocationDetails($extension){
// this gets more info about the phone (we use multiple sites and servers)
$sql = "select asset.mac, allocation.extension, server.server_ip, asset.phone_ip, site.site_name
from allocation
join asset as asset on allocation.asset_id = asset.asset_id
join site as site on allocation.site_id = site.site_id
join server as server on site.site_id = server.site_id
where allocation.extension = '".$extension."' limit 1";
$result = mysql_query($sql);
if (!$result) {
$thisPhoneMac = $row["0000000000"];
$thisPhoneIP = $row["0.0.0.0"];
$thisSiteName = $row["NULL"];
$thisServerIP = $row["0.0.0.0"];
} elseif (mysql_num_rows($result) == 0) {
$thisPhoneMac = $row["0000000000"];
$thisPhoneIP = $row["0.0.0.0"];
$thisSiteName = $row["NULL"];
$thisServerIP = $row["0.0.0.0"];
} else {
// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
// then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
$thisPhoneMac = $row["mac"];
$thisPhoneIP = $row["phone_ip"];
$thisSiteName = $row["site_name"];
$thisServerIP = $row["server_ip"];
}
mysql_free_result($result);
}
$results = array($thisPhoneMac,$thisPhoneIP,$thisSiteName,$thisServerIP);
return $results;
}
function getRingTone($phoneIP){
//this checks to see if a user as set a custom ringtone.
if ($xmlstr = file_get_contents("http://$phoneIP/admin/spacfg.xml")){
if (strlen($xmlstr) < 1){
$ringtone = "1";
} else {
$xml = new SimpleXMLElement($xmlstr);
$ringtone = $xml->Default_Ring_1_;
if ($ringtone == "User 1") {
$ringtone = "11";
} elseif ($ringtone == "User 2") {
$ringtone = "12";
}
}
} else {
//default ringtone for people in the directory
$ringtone = "12";
}
return $ringtone;
}
function updatePhonePDir($phoneIP,$pDir){
//this generates the wget command. -t 1 means it will only try once. if it fails then it won't try again until the next day.
$command = "wget --post-data '".$pDir."' http://".$phoneIP."/pdir.spa -t 1";
runCommand($command); // or die("update to $phoneIP failed");
}
function runCommand($command){
//calls the command and writes some debugging to the screen
system($command,$returned);
echo $command."<br />";
echo $returned."<br /><br />";
return $returned;
}
function getGroups($info){
//this is used for getting groups in ldap and finding their exts etc... read up in a previous post for more on this. Note that groups are prepended with '*' to make them appear at the top of the directory
global $extID;
global $extensions;
for ($i=0; $i<$info["count"]; $i++) {
if (ereg("[[6][0-9]{3}]",substr($info[$i]["info"][0],0,6))){
//calling groups
$extensionstring .= "&".$extensions[$extID]."=n%3D*".strtoupper(str_replace(" ","%20",$info[$i]["name"][0])).";";
$extensionstring .= "p%3D".substr($info[$i]["info"][0],1,4).";r%3D11";
$extID--;
}
}
return $extensionstring;
}
SPA942 and Daylight Saving
Well daylight savings just hit for the first time since we’ve had the SPA942s and needless to say I overlooked that parameter when setting them up.
Unfortunately it wasn’t as simple as ticking a box or setting a parameter to 1 or 0 which I was kind of hoping it would be, instead you need to have a ‘Daylight Saving Time Rule’ which I guess is fair enough as different states and countries treat it differently.
Also unfortunate was Linksys’ decision to not allow daylight savings rules to span more than one calendar year. Luckily some people on the Linksys boards were able to provide me with the work around I needed.
Basically you need to set Time_Zone to GMT+11:00 even though it should be GMT+10:00 and then subtract hours rather than adding them.
End result looks something like:
GMT+11:00
</time_Zone>
<daylight_Saving_Time_Rule group="Regional/Miscellaneous">
start=3/-1/7;end=10/-1/7;save=-1
</daylight_Saving_Time_Rule>
More SPA942 Firmware stuff
Well I’m trailing out the 5.15a firmware for the SPA942 phones. Firstly, I have figured out the problem I was having previously with the first line being one pixel out of alignment. For our users, we display $EXT – Line # on each of the lines, so for me it appears as:
In the previous (5.1.5) firmware, this was left aligned, where as the newer firmwares are right aligned. Because the number 1 is thinner than the numbers 2,3 and 4, the text looked out of line. Other people probably wouldn’t have this issue, because adding in the Line numbers was a custom change I made for my users (in response to too many questions about why there where 4 buttons).
The other issue I was having with
has been changed to
There’s also a new feature that allows you to set a background image that I’m hoping to play around with shortly – more info about that on voip-info
Problems with latest SPA942 Firmware (5.1.10)
I’ve noticed that the spacfg.xml seems to be malformed and it’s causing my scripts to break :’(
It seems that Linksys have added
which presumably due to the fact that it starts with the number 2 is breaking it ![]()
I’ve posted over on the Linksys boards and hopefully someone will be able to shed some light on it.












