#! /bin/sh #---------------------------------------------------------------------------------- # /var/install/bin/vbox-call-control - control if a call should be forced # # Copyright (c) 2002-2019 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2007-09-20 jed # Last Update: $Id$ # # 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 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------------- # read eislib . /var/install/include/eislib #exec 2> /tmp/vbox-call-control-trace-$$.test #set -x #---------------------------------------------------------------------------------- # new calls on todo-list # input: $1 - user name # return: 0 - content has been modified # 1 - nothing has been modified #---------------------------------------------------------------------------------- new_calls_on_list () { vbox_user=$1 retval=1 call_list=${vbox_spooldir}/${vbox_user}/vbox-call-list last_checked_file=${call_list}-last-processed if [ -f ${call_list} ] then # update lease file marker if [ ! -f ${last_checked_file} -o \( ${call_list} -nt ${last_checked_file} \) ] then > ${last_checked_file} retval=0 fi fi return ${retval} } #---------------------------------------------------------------------------------- # play voice messages of single vbox # $1 - user #---------------------------------------------------------------------------------- play_voice_msgs () { user=$1 if new_calls_on_list ${user} then # new calls on list, go on... userdir=${vbox_spooldir}/${user} # save current list mv ${userdir}/vbox-call-list ${userdir}/vbox-call-list.curr putty_conf=${vbox_spooldir}/${user}/vboxputty.conf # read configuration . ${userdir}/call_nbr echo "${VBOX_SENDTO}" | grep -q "params=" if [ $? -eq 0 ] then # extract optional parameters to_nbr="${VBOX_PREFIX}`echo ${VBOX_SENDTO}|cut -d' ' -f1`" params=`echo ${VBOX_SENDTO}|sed 's/.*params=//g'` else to_nbr="${VBOX_PREFIX}${VBOX_SENDTO}" params='' fi ring_sec="`echo ${params} |cut -d: -f1`" wait_sec="`echo ${params} |cut -d: -f2`" redial_sec="`echo ${params}|cut -d: -f3`" try_nbr="`echo ${params} |cut -d: -f4`" # if necessary set defaults if [ -z "${ring_sec}" ] then ring_sec=30 fi if [ -z "${wait_sec}" ] then wait_sec=1 fi if [ -z "${redial_sec}" ] then redial_sec=10 fi if [ -z "${try_nbr}" ] then try_nbr=1 fi if [ ! -f ${userdir}/vbox-nocallback ] then # check number of unsuccessfull calls ... if [ ! -f ${userdir}/vbox-call-list.count ] then call_count=1 echo "${call_count}" > ${userdir}/vbox-call-list.count else call_count=`cat ${userdir}/vbox-call-list.count` if [ ${call_count} -gt ${try_nbr} ] then # limit reached, stop calls for the moment rm -f ${userdir}/vbox-call-list.curr fi fi if [ -f ${userdir}/vbox-call-list.curr ] then # calls allowed, go on ... # call number and play voice message # # -f, --file FILE Overwrites "/usr/local/vbox/etc/vboxgetty.conf". # -d, --device TTY Use device TTY for modem operations [required]. # -c, --call NUMBER Number to dial is NUMBER. # -s, --ring SEC Ring SEC seconds, then hangup. # -w, --wait SEC sleep SEC seconds after connect. # -t, --try NUM try NUM times to reach NUMBER. # -r, --redial SEC Wait SEC seconds after connection-failure. # -h, --help Displays this short help. # -v, --version Displays the package version. # # return: 0 - call successfull # return: 99 - busy /usr/local/vbox/sbin/vboxputty -f ${putty_conf} -d ${vbox_calldev} -c ${to_nbr} \ -s ${ring_sec} -w ${wait_sec} -r ${redial_sec} -t ${try_nbr} if [ $? -eq 0 ] then # successfull call, delete counter rm -f ${userdir}/vbox-call-list.count else # unsuccessfull call, save message file name if [ -f ${userdir}/vbox-call-list ] then # new calls saved while processing callback, add them to list file cat ${userdir}/vbox-call-list.curr ${userdir}/vbox-call-list > ${userdir}/vbox-call-list.new mv ${userdir}/vbox-call-list.new ${userdir}/vbox-call-list else # no new calls saved while processing callback, restore original list mv ${userdir}/vbox-call-list.curr ${userdir}/vbox-call-list fi # set file ownership chown ${user}: ${userdir}/vbox-call-list chmod 0644 ${userdir}/vbox-call-list # update last access time to make sure it will be accessed again touch ${userdir}/vbox-call-list # increase call counter call_count=`expr ${call_count} + 1` echo "${call_count}" > ${userdir}/vbox-call-list.count fi fi # if [ -f ${userdir}/vbox-call-list.curr ] fi # if [ ! -f ${userdir}/vbox-nocallback ] rm -f ${userdir}/vbox-call-list.curr fi } #================================================================================== # main #================================================================================== ### set path names ### vbox_spooldir=/var/spool/vbox vbox_calldev=/dev/ttyI15 interval=0 pgmname=`basename $0` runmode='auto' if [ $# -gt 0 ] then while [ 1 ] do case "$1" in -all ) runmode='all' shift ;; -auto ) # set individual interval runmode='auto' if [ -n "$2" ] then interval=$2 shift fi shift break ;; -debug ) debug='-debug' shift ;; -user ) runmode='single' vboxuser="$2" shift; shift ;; *) runmode='help' break ;; esac done fi if [ ${interval} -lt 20 ] then # set default value interval=20 fi case ${runmode} in all ) # check all vboxes # save last run echo "`/bin/date +'%Y-%m-%d %H:%M:%S'`" > ${vbox_spooldir}/vbox-call-control-lastrun for CNAME in `find ${vbox_spooldir}/ -name call_nbr -type f` do vboxuser=`dirname ${CNAME}| sed 's#.*/##g'` play_voice_msgs ${vboxuser} done ;; auto ) # start control process while [ 1 ] do # save last run echo "`/bin/date +'%Y-%m-%d %H:%M:%S'`" > ${vbox_spooldir}/vbox-call-control-lastrun for CNAME in `find ${vbox_spooldir}/ -name call_nbr -type f` do vboxuser=`dirname ${CNAME}| sed 's#.*/##g'` play_voice_msgs ${vboxuser} done sleep ${interval} done & ;; single ) # check single vbox play_voice_msgs ${vboxuser} ;; * ) # show help mecho "Usage:" mecho " ${pgmname} -all - process all vboxes" mecho " ${pgmname} -auto [interval] - run as daemon and check vboxes on a regular base" mecho " ${pgmname} -single vbox-name - process a single vbox" ;; esac #================================================================================== # end #==================================================================================