#!/usr/local/bin/bash

# Server Hangup Extension

# Created by Ed Attfield
# Last edited: Oct 19, 2017

# This script calls two hangup extensions to chain two hangup rules.

# Script is not called if caller number or name is in ncidd.whitelist.

# This hangup-combo-skel script is REPLACED whenever NCID is updated.
# Rename this script to hangup-combo and make any changes.

# Be sure your hangup-combo script has the execute permission set.
# Make sure you 'set hupmode' to be non-zero in ncidd.conf.

# Input: The server passes one <string> to this script containing:
#        *DATE*<mmddyyyy>
#        *TIME*<hhmm>
#        *LINE*<lineid>
#        *NMBR*<number>
#        *NAME*<name>
#        *MODE*<1,2,3>*

EXTDIR=/usr/local/share/ncid/extensions

# Change the extension names to call different extensions
EXT1="hangup-fakenum"
EXT2="hangup-fcc"

result=`$EXTDIR/$EXT1 "$1" "$2" "$3" "$4" "$5"`
if [[ "$result" =~ .*hangup$ ]]; then
   echo "$result"
   exit 0
fi

result=`$EXTDIR/$EXT2 "$1" "$2" "$3" "$4" "$5"`
if [[ "$result" =~ .*hangup$ ]]; then
   echo "$result"
   exit 0
fi

# the name and number looks good
echo "OK"
exit 0
