Browse Source

init

master
Simon Vieille 1 month ago
commit
010eb7ba00
Signed by: Simon Vieille <simon@deblan.fr> GPG Key ID: 03383D15A1D31745
5 changed files with 135 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 18
    0
      README.md
  3. 0
    0
      cache/.gitkeep
  4. 59
    0
      extract-contacts
  5. 56
    0
      send-sms

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
/cache/*
!/cache/.gitkeep

+ 18
- 0
README.md View File

@@ -0,0 +1,18 @@
SMS-SENDER
==========

Send SMS using kdeconnect.

```bash
$ git clone https://gitnet.fr/deblan/sms-sender.git
$ cd sms-sender
$ FILE=/path/to/contacts.vcf DEVICE=XXXXXXXXXXXXXXXX ./send-sms
```

Requirements
------------

* SH
* whiptail
* kdeconnect
* vim

+ 0
- 0
cache/.gitkeep View File


+ 59
- 0
extract-contacts View File

@@ -0,0 +1,59 @@
#!/bin/sh

SCRIPT_NAME="$(realpath "$0")"
SCRIPT_PATH="$(dirname "$SCRIPT_NAME")"

cd "$SCRIPT_PATH"

if [ -z "$FILE" ]; then
printf " Usage:\\n"
printf " FILE=/path/to/contacts.vcf %s\\n" "$0"

exit 0
fi

CACHE="cache/$(basename "$FILE").cache"

if [ -f "$CACHE" ]; then
cat "$CACHE"

exit
fi

touch "$CACHE"
chmod 600 "$CACHE"

cat "$FILE" | while read LINE; do
FLAG="$(echo "$LINE" | cut -d: -f1)"
VALUE="$(echo "$LINE" | cut -d: -f2- | sed "s/\r//g" | sed "s/\n//g")"

if [ "$FLAG" = "END" ]; then
if [ -n "$FULL_NAME" ] && [ -n "$PHONE" ]; then
printf "%s|%s\\n" "$FULL_NAME" "$PHONE"
fi

FULL_NAME=
PHONE=

export FULL_NAME
export PHONE
elif [ "$FLAG" = "FN" ] && [ -n "$VALUE" ]; then
FULL_NAME="$VALUE"

export FULL_NAME
elif [ "$FLAG" = "FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE" ] && [ -n "$VALUE" ]; then
FULL_NAME="$(printf "$VALUE" | perl -MMIME::QuotedPrint -pe '$_=MIME::QuotedPrint::decode($_);')"

export FULL_NAME
elif [ "$FLAG" = "TEL;CELL;PREF" ] && [ -n "$VALUE" ]; then
PHONE="$VALUE"

export PHONE
elif [ "$FLAG" = "TEL;CELL" ] && [ -n "$VALUE" ]; then
PHONE="$VALUE"

export PHONE
fi
done > "$CACHE"

cat "$CACHE"

+ 56
- 0
send-sms View File

@@ -0,0 +1,56 @@
#!/bin/sh

SCRIPT_NAME="$(realpath "$0")"
SCRIPT_PATH="$(dirname "$SCRIPT_NAME")"

cd "$SCRIPT_PATH"

usage() {
printf " Usage:\\n"
printf " FILE=/path/to/contacts.vcf DEVICE=XXXXXXXXXXXXXXXX %s\\n" "$0"
}

if [ -z "$FILE" ] || [ -z "$DEVICE" ]; then
usage

exit 0
fi

SEARCH="$(whiptail --title "Filtre de contact" --inputbox "" 8 50 3>&1 1>&2 2>&3)"

COMMAND="whiptail --title \"Contacts\" --menu \"Choose a recipient\" 25 65 16"

COMMAND="$COMMAND $(FILE="$FILE" ./extract-contacts | sort | while read CONTACT; do
VALUE="$(echo "$CONTACT" | cut -d\| -f2 | sed 's/"//g')"
LABEL="$(echo "$CONTACT" | cut -d\| -f1 | sed 's/"//g')"

if [ -n "$SEARCH" ]; then
if [ -n "$(echo "$LABEL" | grep -i "$SEARCH")" ]; then
printf " \"%s\" \"%s\"" "$VALUE" "$LABEL"
fi
else
printf " \"%s\" \"%s\"" "$VALUE" "$LABEL"
fi
done)"

PHONE="$(eval "$COMMAND 3>&1 1>&2 2>&3")"

if [ -n "$PHONE" ]; then
TMP_FILE="/tmp/send-sms-$(tr -dc "qwertQWERTasdfgASDFGzxcvbZXCVB" < /dev/urandom | head -c 16)"
touch "$TMP_FILE"
chmod 600 "$TMP_FILE"

vim "$TMP_FILE"

if [ -n "$(cat "$TMP_FILE")" ]; then
whiptail --textbox "$TMP_FILE" --title "SMS pour $PHONE" 15 70

if (whiptail --title "Confirmation" --yesno "Valides-tu l'expédition du SMS ?" 8 50 3>&1 1>&2 2>&3) then
kdeconnect-cli --device "$DEVICE" --send-sms "$(cat "$TMP_FILE")" --destination "$PHONE"
else
printf "Aborded!\\n"
fi
fi

rm "$TMP_FILE"
fi

Loading…
Cancel
Save