verify numbers with pn

master
noneofyourbusiness 4 years ago committed by Stacy Harper
parent e444553ae4
commit 3599be95f4
No known key found for this signature in database
GPG Key ID: 5BAC92328B7C5D65
  1. 17
      scripts/core/sxmo_contactmenu.sh
  2. 1
      scripts/core/sxmo_contacts.sh
  3. 2
      scripts/modem/sxmo_modemcall.sh
  4. 23
      scripts/modem/sxmo_modemmonitor.sh

@ -4,14 +4,19 @@
. "$(dirname "$0")/sxmo_common.sh" . "$(dirname "$0")/sxmo_common.sh"
valid_number() { valid_number() {
number="$(echo "$1" | sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/")" if pn valid "$1"; then
echo "$1"
return
fi
if echo "$number" | grep -q "^+[0-9]\{11\}$"; then REFORMATTED="$(pn find ${DEFAULT_COUNTRY:+-c "$DEFAULT_COUNTRY"} "$1")"
echo "$number" if pn valid "$REFORMATTED"; then
else echo "$REFORMATTED"
notify-send "\"$number\" is not a valid phone number" return
notify-send "Valid format is \"+[0-9]{11}\""
fi fi
notify-send "\""$1"\" is not a valid phone number"
exit
} }
newcontact() { newcontact() {

@ -18,7 +18,6 @@ LOGFILE="$XDG_DATA_HOME"/sxmo/modem/modemlog.tsv
prepare_contacts_list() { prepare_contacts_list() {
cut -f3 | cut -f3 |
sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/" |
tac | tac |
awk '!($0 in a){a[$0]; print}' | awk '!($0 in a){a[$0]; print}' |
sed '/^[[:space:]]*$/d' | sed '/^[[:space:]]*$/d' |

@ -53,7 +53,7 @@ vid_to_number() {
} }
number_to_contactname() { number_to_contactname() {
NUMBER="$(echo "$1" | sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/")" NUMBER="$1"
CONTACT=$(sxmo_contacts.sh --all | CONTACT=$(sxmo_contacts.sh --all |
grep "^$NUMBER:" | grep "^$NUMBER:" |
cut -d':' -f 2 | cut -d':' -f 2 |

@ -35,6 +35,21 @@ modem_n() {
err "Couldn't find modem - is your modem enabled? Disabling modem monitor" err "Couldn't find modem - is your modem enabled? Disabling modem monitor"
} }
cleanupnumber() {
if pn valid "$1"; then
echo "$1"
return
fi
REFORMATTED="$(pn find ${DEFAULT_COUNTRY:+-c "$DEFAULT_COUNTRY"} "$1")"
if [ -n "$REFORMATTED" ]; then
echo "$REFORMATTED"
return
fi
echo "$1"
}
lookupnumberfromcallid() { lookupnumberfromcallid() {
VOICECALLID=$1 VOICECALLID=$1
mmcli -m "$(modem_n)" --voice-list-calls -o "$VOICECALLID" -K | mmcli -m "$(modem_n)" --voice-list-calls -o "$VOICECALLID" -K |
@ -47,16 +62,15 @@ lookupcontactname() {
if [ "$1" = "--" ]; then if [ "$1" = "--" ]; then
echo "Unknown number" echo "Unknown number"
else else
NUMBER="$(echo "$1" | sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/")"
CONTACT=$(sxmo_contacts.sh --all | CONTACT=$(sxmo_contacts.sh --all |
grep "^$NUMBER:" | grep "^$1:" |
cut -d':' -f 2 | cut -d':' -f 2 |
sed 's/^[ \t]*//;s/[ \t]*$//' #strip leading/trailing whitespace sed 's/^[ \t]*//;s/[ \t]*$//' #strip leading/trailing whitespace
) )
if [ -n "$CONTACT" ]; then if [ -n "$CONTACT" ]; then
echo "$CONTACT" echo "$CONTACT"
else else
echo "Unknown ($NUMBER)" echo "Unknown ($1)"
fi fi
fi fi
} }
@ -70,6 +84,7 @@ checkforfinishedcalls() {
cut -d'/' -f2 cut -d'/' -f2
); do ); do
FINISHEDNUMBER="$(lookupnumberfromcallid "$FINISHEDCALLID")" FINISHEDNUMBER="$(lookupnumberfromcallid "$FINISHEDCALLID")"
FINISHEDNUMBER="$(cleanupnumber "$FINISHEDNUMBER")"
mmcli -m "$(modem_n)" --voice-delete-call "$FINISHEDCALLID" mmcli -m "$(modem_n)" --voice-delete-call "$FINISHEDCALLID"
rm -f "$CACHEDIR/${FINISHEDCALLID}.monitoredcall" rm -f "$CACHEDIR/${FINISHEDCALLID}.monitoredcall"
@ -142,6 +157,7 @@ checkforincomingcalls() {
# Determine the incoming phone number # Determine the incoming phone number
echo "sxmo_modemmonitor: Incoming Call:">&2 echo "sxmo_modemmonitor: Incoming Call:">&2
INCOMINGNUMBER=$(lookupnumberfromcallid "$VOICECALLID") INCOMINGNUMBER=$(lookupnumberfromcallid "$VOICECALLID")
INCOMINGNUMBER="$(cleanupnumber "$INCOMINGNUMBER")"
CONTACTNAME=$(lookupcontactname "$INCOMINGNUMBER") CONTACTNAME=$(lookupcontactname "$INCOMINGNUMBER")
xset dpms force on xset dpms force on
@ -181,6 +197,7 @@ checkfornewtexts() {
grep sms.content.number | grep sms.content.number |
sed -E 's/^sms\.content\.number\s+:\s+//' sed -E 's/^sms\.content\.number\s+:\s+//'
)" )"
NUM="$(cleanupnumber "$NUM")"
TIME="$(echo "$TEXTDATA" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')" TIME="$(echo "$TEXTDATA" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')"
mkdir -p "$LOGDIR/$NUM" mkdir -p "$LOGDIR/$NUM"

Loading…
Cancel
Save