-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathqndtmf.sh
executable file
·111 lines (99 loc) · 3.15 KB
/
qndtmf.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
# Copyright (C) 2011 by Scott Lawson KI4LKF
# Copyright (C) 2018 by Thomas A. Early N7TAE
#
# This script finds files in the /tmp directory
# The files have a name like x_mod_DTMF_NOTIFY, where x is one of A B or C, the local module
# The contents of these files can be as follows:
# Example: # will unlink local module, " U"
# Example: B75703 will link local module to XRF757 C
# Example: D00617 will link local module to DCS006 Q
# Example: *00103 will link local module to REF001 C
# Example: 0 or 00 will report status of the link, " I"
# Example: ##08 will execute the exec_H.sh script (shutdown the system)
# Please note that scripts exec_[0-9].sh are not accessible from DTMF.
# We set this to spaces, it will be set later
GetLetter () {
local i
if [[ $1 == +([0-9]) ]]; then
i=`expr $1 - 1`
if [ $i -ge 0 ] && [ $i -lt 26 ]; then
LETTER=${LETTERS[$i]}
return
fi
fi
LETTER=$BAD
}
LUSER=" "
LETTERS=( {A..Z} )
BAD='bad'
cd /tmp
echo started at `date`
while [[ 1 ]]
do
for i in `ls ?_mod_DTMF_NOTIFY 2>/dev/null`
do
echo found file $i at `date`
LOCAL_BAND=${i:0:1}
if [[ "$LOCAL_BAND" == 'A' ]] || [[ "$LOCAL_BAND" == 'B' ]] || [[ "$LOCAL_BAND" == 'C' ]]; then
CMD=`head -n 1 $i 2>/dev/null`
LUSER=`tail -n 1 $i 2>/dev/null`
echo "... with these contents: " $CMD " " $LUSER
if [[ "$CMD" == '#' ]]; then
echo Unlinking local band $LOCAL_BAND requested by $LUSER
qnremote ${LOCAL_BAND} "$LUSER" U >/dev/null 2>&1
echo
elif [[ "$CMD" == '0' ]] || [[ "$CMD" == '00' ]]; then
echo Link Status on local band $LOCAL_BAND requested by $LUSER
qnremote ${LOCAL_BAND} "$LUSER" I >/dev/null 2>&1
echo
elif [[ "$CMD" == '**' ]]; then
echo Load Hosts on local band $LOCAL_BAND requested by $LUSER
qnremote ${LOCAL_BAND} "$LUSER" F >/dev/null 2>&1
else
if [ ${#CMD} -eq 4 ] && [[ ${CMD:0:2} == '##' ]]; then
GetLetter ${CMD:2:2}
if [[ "$LETTER" == "$BAD" ]]; then
echo "bad script letter index: '${CMD:2:2}'"
qnvoice $LOCAL_BAND baddtmfcmd.dat "Bad DTMF CMD"
else
qnremote $LOCAL_BAND $LUSER ${LETTER}X >/dev/null 2>&1
fi
elif [ ${#CMD} -eq 6 ]; then
PFX=${CMD:0:1}
if [[ "$PFX" = 'B' ]]; then
RMT=XRF
elif [[ "$PFX" = 'D' ]]; then
RMT=DCS
elif [[ "$PFX" = '*' ]]; then
RMT=REF
else
RMT=$BAD
fi
REMOTE_NODE=${CMD:1:3}
if [[ $REMOTE_NODE != +([0-9]) ]]; then
REMOTE_NODE=$BAD
fi
GetLetter ${CMD:4:2}
REMOTE_BAND=$LETTER
if [[ "$RMT" == "$BAD" ]] || [[ "$REMOTE_NODE" == "$BAD" ]] || [[ "$REMOTE_BAND" == "$BAD" ]]; then
echo "Bad link command: '$CMD'"
qnvoice $LOCAL_BAND baddtmfcmd.dat "Bad Link CMD"
else
echo linking local band $LOCAL_BAND to remote node ${RMT}${REMOTE_NODE} $REMOTE_BAND requested by $LUSER
qnremote ${LOCAL_BAND} "$LUSER" ${RMT}${REMOTE_NODE}${REMOTE_BAND}L >/dev/null 2>&1
echo
fi
else
echo "Bad command: '$CMD'"
qnvoice $LOCAL_BAND baddtmfcmd.dat "Bad CMD"
fi
fi
else
echo "Local band '${LOCAL_BAND}' is bad"
fi
rm -f $i
done
sleep 2
done
exit 0