voice ringing schedule, speed dialing and detailed call log support

This commit is contained in:
Sukru Senli 2015-05-30 15:15:45 +02:00 committed by Martin Schröder
parent e1aa319619
commit 824f729791
6 changed files with 141 additions and 56 deletions

View file

@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=asterisk18-mod
PKG_VERSION:=1.8.10.1
PKG_SOURCE_VERSION:=6512b7fafb92fa1ebd7e0078691b3156f5dec316
PKG_SOURCE_VERSION:=e6a06b24a4e3d5ff786a4ad55a7c90de1defb49e
PKG_SOURCE_PROTO:=git
ifeq ($(CONFIG_PACKAGE_bcmkernel),y)
PKG_SOURCE_URL:=git@ihgsp.inteno.se:asterisk-aa

View file

@ -125,6 +125,10 @@ exten => s,1, Set(linecfim=${DB(CFIM/${ARG1})})
; If we have CFIM set, go to CFIM call
exten => s,n, GotoIf(${linecfim}?call_cfim)
; If ringing is disabled, skip calling line normally
exten => s,n, Set(shouldring=${SHELL(/usr/lib/asterisk/ringing_schedule.sh ${ARG1}):0:-1})
exten => s,n, GotoIf(${shouldring}?:ringing_disabled)
;Call line normally, by going to call_line context
exten => s,n, Goto(call_line,${MACRO_EXTEN},1)
@ -132,6 +136,11 @@ exten => s,n, Goto(call_line,${MACRO_EXTEN},1)
exten => s,n(call_cfim), Dial(SIP/${linecfim}@${ARG1},)
exten => s,n, Hangup()
;Ringing disabled, give ringback for 60s and then hangup
exten => s,n(ringing_disabled), Ringing()
exten => s,n, Wait(60)
exten => s,n, Hangup()
[macro-callhandler-noanswer]
;
; ${ARG1} - Calling sip peer

View file

@ -19,7 +19,7 @@ exten => _X.,1, Transfer(SIP/${EXTEN}@|PROVIDER|,,)
[|PROVIDER|-outgoing]
; Context used for normal outgoing calls
|SPEED_DIAL|exten => _[*#0-9].,1, Set(DIAL_EXTEN=${EXTEN})
|SPEED_DIAL|exten => _[*#0-9].,1, Set(DIAL_EXTEN=${EXTEN})
exten => _[*#0-9].,n, Set(CALLERID(ANI)=|USERNAME|)
exten => _[*#0-9].,n, Set(CALLERID(number)=|USERNAME|)
exten => _[*#0-9].,n, |CUSTOM_OUTGOING|

View file

@ -157,3 +157,6 @@ config log 'LOG'
option syslog_facility 'local0'
option syslog ''
config ringing_status 'RINGING_STATUS'
option status '0'
option enabled '1'

View file

@ -1,54 +0,0 @@
#!/bin/sh
#######################################################
# log_call
#
# Adds a row to the call log file. Will truncate file
# at 100 rows. Some very basic concurrency is supported.
#
# Usage:
# log_call.sh Direction From To [Note]
#
# Examples:
# ./log_call Incoming 07012345678 07876543210
# ./log_call Outgoing 07876543210 07012345678 Blocked
#####################################################
# Check that there is a direction specified
if [ -z "$1" ] ; then
exit 1
fi
# Check that there is a calling number specified
if [ -z "$2" ] ; then
exit 2
fi
# Check that there is a called number specified
if [ -z "$3" ] ; then
exit 2
fi
direction=$1
# Remove any suffix starting with an underscore
from=$(echo $2 | sed 's/_.*//')
to=$(echo $3 | sed 's/_.*//')
note=$4
logfile="/var/call_log"
tempfile=$(mktemp)
now=$(date)
for i in 1 2 3 4 5 ; do
if mkdir /var/lock/log_call.lck ; then
echo "$now;$direction;$from;$to;$note" >> $tempfile
head -n99 $logfile >> $tempfile
mv $tempfile $logfile
rmdir /var/lock/log_call.lck
break
fi
sleep 1
done

View file

@ -0,0 +1,127 @@
#!/bin/sh
#######################################################
# RingingSchedule
#
# Checks if ringing is active for SIP account
# for the current time.
#
# Return value is 1 if ringing is active, 0 otherwise.
#
# Usage:
# ringing_schedule.sh SIPAccount
#
# Example:
# ./ringing_scheudle.sh sip0
#####################################################
. /lib/functions.sh
contains()
{
string="$1"
substring="$2"
if test "${string#*$substring}" != "$string"
then
echo "1"
else
echo "0"
fi
return
}
match_rules()
{
#Loop over voice_clients sections, look for ringing_schedules
local ___type=ringing_schedule
local section cfgtype
for section in ${CONFIG_SECTIONS}; do
config_get cfgtype "$section" TYPE
[ -n "$___type" -a "x$cfgtype" != "x$___type" ] && continue
#Found ringing_schedule
local sip_service_provider
local days
local time
config_get sip_service_provider $section sip_service_provider
config_get days $section days
config_get time $section time
#Match SIP Account
if [ "$sip_service_provider" != "$2" ]; then
continue
fi
#Match current day
days_matched=$(contains "$days" $3)
if [ $days_matched != 1 ]; then
continue
fi
#Match current time, split string of format 'HH:MM HH:MM'
start_hour=${time:0:2}
start_minute=${time:3:2}
end_hour=${time:6:2}
end_minute=${time:9:2}
if [ $4 -lt $start_hour -o $4 -eq $start_hour -a $5 -lt $start_minute ] ; then
continue
fi
if [ $4 -gt $end_hour -o $4 -eq $end_hour -a $5 -gt $end_minute ] ; then
continue
fi
#Matched a ringing_schedule rule
echo $1
return
done
echo "-1"
}
main()
{
config_load voice_client
local status
local enabled
local syslog
#Return immediately if no SIPAccount is given
if [ "$1" == "" ] || [ -z "$1" ]; then
echo 1
return
fi
#Return immediately if feature is disabled
config_get status RINGING_STATUS status
if [ "$status" == "0" ] || [ -z "$status" ]; then
echo 1
return
fi
#Check if ringing is enabled or disabled for the configured periods
config_get enabled RINGING_STATUS enabled
#Get current day and time
day=$(/bin/date "+%A")
hour=$(/bin/date "+%H")
minute=$(/bin/date "+%M")
#Check if configured periods are matched
result=$(match_rules $enabled $1 $day $hour $minute)
#If no rule matched, default is inverse of enabled
if [ $result -lt 0 ]; then
if [ $enabled -eq 0 ]; then
result=1
else
result=0
fi
fi
echo $result
}
result=$(main $1)
echo $result