2015-07-25, 23:21
Goal: Utilize VOIP adapter's logging feature to display incoming call callerid to all Raspberry PIs running Kodi (Milhouse Build).
I missed the TV callerID alert feature so bad after dropping the cable TV service, i started poking around the internet for a solution. Then I come across this post which resulted in a working callerID solution for me. Even though there are so many variables to get this right and the process/script looks bit clunky [my apology in advance], i thought i share the project as-is here for other's benefit. I am not good at instructions, hope this make sense to others.
Disclaimer: Credit goes to 'DmCK' from this thread. I simply modify his script to adopt to my environment.
If you are using Sipura or Linksys or Cisco (excluding Cisco ATA 18X) Phone adapters, the script should work as-is. The OBixx phone adapter works well as well but needs a slight adjustment in the script below. Similarly, this can be adjusted to make YAC Listner work to send callerID to MAC/PCs.
My Environment:
1. Ubuntu server/PI (openelec) - rsyslog server
2. 2 x PI2 Running Openelec Milhouse Build
3. 1 x Cisco SPA 122 Phone Adapter.
4. A BYOD VOIP Provider
I. Prepare Linksys/Cisco Phone Adapter
1. Login into Phone Adapter with admin privilege
2. Navigate to Voice - > System -> Enter syslog server IP address. Click "Save".
3. Navigate to Line 1 -> SIP Debug Option: -> select "full excl. OPT|NTFY|REG" from the drop down list. Click "Save"
4. Repeat step 3 if you are using Line 2 (Optional)
II. Prepare rSyslog Server (Ubuntu)
Note: Raspberry PI's rsyslog service is suffice but I am using separate Ubuntu as example here.
1. Install rsyslog and configure if it is not already.
2. Configure rsyslog to listen to udp 514. un-comment following lines.
nano /etc/rsyslog.conf
3. Allow syslog from phone adapter. Add following to rsyslog.conf. xxx = your phone adapter IP address
4. Save rsyslog.conf
5. Restart rsyslog
III. Rsyslog Rules
1. Don't log local0 and user stuff to /var/log/messages since the Linksys/Cisco SPA uses those facility categories
2. Add following to skip local0 and redirect the log to a separate file
3. save "50-default.conf" and restart rsyslog service
IV. Rsyslog default behavior
1. Add '-r' switch default/rsyslog
2. Save rsyslog and restart rsyslog service
V. Install Incron
(Note: Still available but sadly, i heard, the incron development incron has stopped.)
1. Install incron
2. Add user(s) to allow list.
3. Save "incron.allow" and exit
VI. User crontab
1. 2. add log file defined in Step III and 2 here
3. save and exit
VII. Kodi Setting
1.Enable the webserver
in kodi
2. Note username and password if any and adjust callerid.sh setting acordingly
callerid.sh
Note: Make you script (callerid.sh) executable
Edit: Sorry - Could not upload images here. Call.png and some screenshots are missing at this point.
I missed the TV callerID alert feature so bad after dropping the cable TV service, i started poking around the internet for a solution. Then I come across this post which resulted in a working callerID solution for me. Even though there are so many variables to get this right and the process/script looks bit clunky [my apology in advance], i thought i share the project as-is here for other's benefit. I am not good at instructions, hope this make sense to others.
Disclaimer: Credit goes to 'DmCK' from this thread. I simply modify his script to adopt to my environment.
If you are using Sipura or Linksys or Cisco (excluding Cisco ATA 18X) Phone adapters, the script should work as-is. The OBixx phone adapter works well as well but needs a slight adjustment in the script below. Similarly, this can be adjusted to make YAC Listner work to send callerID to MAC/PCs.
My Environment:
1. Ubuntu server/PI (openelec) - rsyslog server
2. 2 x PI2 Running Openelec Milhouse Build
3. 1 x Cisco SPA 122 Phone Adapter.
4. A BYOD VOIP Provider
I. Prepare Linksys/Cisco Phone Adapter
1. Login into Phone Adapter with admin privilege
2. Navigate to Voice - > System -> Enter syslog server IP address. Click "Save".
3. Navigate to Line 1 -> SIP Debug Option: -> select "full excl. OPT|NTFY|REG" from the drop down list. Click "Save"
4. Repeat step 3 if you are using Line 2 (Optional)
II. Prepare rSyslog Server (Ubuntu)
Note: Raspberry PI's rsyslog service is suffice but I am using separate Ubuntu as example here.
1. Install rsyslog and configure if it is not already.
2. Configure rsyslog to listen to udp 514. un-comment following lines.
nano /etc/rsyslog.conf
Code:
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
Code:
$AllowedSender UDP, 127.0.0.1, 192.168.1.xxx
5. Restart rsyslog
Code:
service rsyslog restart
III. Rsyslog Rules
1. Don't log local0 and user stuff to /var/log/messages since the Linksys/Cisco SPA uses those facility categories
Code:
nano /etc/rsyslog.d/50-default.conf
Code:
#Don't log local0 and user stuff to /var/log/messages since the SPA uses those facility categories
*.info;user.none;local0.none;syslog.none;mail.none;authpriv.none;cron.none /var/log/messages
#SPA is logging at user and local0 facility categories.
#user.debug;local0.debug; /var/log/voip/voip.log
if ($syslogfacility-text == 'user' or $syslogfacility-text == 'local0') and ($msg contains "Ringing") then /var/log/voip/voip.log
3. save "50-default.conf" and restart rsyslog service
IV. Rsyslog default behavior
1. Add '-r' switch default/rsyslog
Code:
nano /etc/default/rsyslog
RSYSLOGD_OPTIONS="-r"
V. Install Incron
(Note: Still available but sadly, i heard, the incron development incron has stopped.)
1. Install incron
Code:
apt-get install incron
Code:
nano /etc/incron.allow
root, yourusername
VI. User crontab
1.
Code:
sudo incrontab -e
Code:
"/var/log/voip/voip.log IN_MODIFY /bin/bash /home/yourusername/callerid.sh"
VII. Kodi Setting
1.Enable the webserver
Code:
Settings>Services>Webserver>Allow control of kodi via HTTP
2. Note username and password if any and adjust callerid.sh setting acordingly
callerid.sh
Note: Make you script (callerid.sh) executable
Code:
chmod 777 ~/callerid.sh
Code:
#!/bin/bash
##############
## lockfile ##
##############
exec 9>/tmp/callerid-lockfile
if ! flock -n 9 ; then
exit 1
fi
# this script now runs under the lock until 9 is closed. it will be closed automatically when the script ends.
####################
## Configuration ##
####################
LOGLOCATION="/var/log/voip/voip.log" # the location of your syslog log
kODIipBegin="192.168.1." # only the first 3 (octates) values and dots for your LAN IP Address
kODIipEnd=(109 108) # the last value(s) of the ip address(es) of your kodi devices(s)
kODIPort="80" # default port for kodi webserver
kODIPOPUPDURATION="20000" # in msecs (i.e., 20000 = an kodi popup for 20 seconds)
NotifiLogo="/storage/pictures/call.png" # Notification Logo
kODIUserName="" # Kodi username
kODIPassword="" # Kodi Password
#Check to see if username is being used
if [ -z "$kODIUserName" ]; then
kODIUserPass=""
else
kODIUserPass="$kODIUserName:$kODIPassword@"
fi
BEGIN="--data-binary"
END="-H content-type:application/json;"
####################################
## Extract string from the log ##
####################################
sleep 0.1 # allow a bit of time for log messages to complete.
STRINGFROMLOG=$(tac $LOGLOCATION | grep -B 0 -m1 'SIP/2.0 180 Ringing#015#012To:.*' | tac)
NAMEPHONE=$(grep -o -P ".{0,0}From.{0,50}" <<< "$STRINGFROMLOG")
NAME="CALLING..:"$(grep -oP '"\K[^"\047]+(?=["\047])' <<< "$NAMEPHONE") #Extract name btwn ""
NAME=${NAME//[[:space:]]/,} # Remove all spaces from the name
NAMEPHONE=${NAMEPHONE//:/} #remote : from the
PHONE=$(grep -oP '"\K[^"\072]+(?=["\100])' <<< "$NAMEPHONE") # gets all characters after the last space (i.e., the number)
PHONE=$(grep -Eo '[0-9]{1,10}' <<< "$PHONE")
for i in ${kODIipEnd[@]}; do
curl $BEGIN '{"jsonrpc": "2.0", "params": {"message": "-----------:'$PHONE'", "image": "'$NotifiLogo'", "displaytime": '$kODIPOPUPDURATION', "title": "'$NAME'"}, "method": "GUI.ShowNotification", "id": "libNotification"}' $END 'http://'$kODIUserPass$kODIipBegin${i}':'$kODIPort'/jsonrpc'
#echo $BEGIN '{"jsonrpc": "2.0", "params": {"message": "-----------:'$PHONE'", "image": "'$NotifiLogo'", "displaytime": '$kODIPOPUPDURATION', "title": "'$NAME'"}, "method": "GUI.ShowNotification", "id": "libNotification"}' $END 'http://'$kODIUserPass$kODIipBegin${i}':'$kODIPort'/jsonrpc'
done
exit 0
Edit: Sorry - Could not upload images here. Call.png and some screenshots are missing at this point.