2020-06-01 15:02:43 +00:00
|
|
|
#!/bin/bash
|
2020-11-22 18:30:29 +00:00
|
|
|
export LANG=C
|
2020-06-01 15:05:42 +00:00
|
|
|
export EVENT=DiVOC
|
2020-06-01 15:02:43 +00:00
|
|
|
|
2020-10-30 17:40:33 +00:00
|
|
|
export DIALOGRC=dialogrc
|
|
|
|
|
|
|
|
LOCKFILE=/tmp/irolock
|
2020-06-01 15:02:43 +00:00
|
|
|
TMP=/tmp/$RANDOM
|
2020-11-22 18:30:29 +00:00
|
|
|
BT="Intergalactic Registration Office - v0.3\n========================================"
|
2020-06-13 13:22:26 +00:00
|
|
|
|
2020-11-22 18:30:29 +00:00
|
|
|
cd $(dirname "$0")
|
|
|
|
|
|
|
|
function clr() {
|
|
|
|
printf "\033H\033J"
|
|
|
|
}
|
2020-06-13 13:22:26 +00:00
|
|
|
|
2020-10-30 17:40:33 +00:00
|
|
|
function infoBox() {
|
2020-11-22 18:30:29 +00:00
|
|
|
clr
|
|
|
|
echo -e "$BT\n\n$1\n\n\n$2"
|
|
|
|
read -n 1 -s -r -p "Press any key to continue"
|
2020-10-30 17:40:33 +00:00
|
|
|
}
|
2020-06-01 15:02:43 +00:00
|
|
|
|
|
|
|
function diaBox() {
|
2020-11-22 18:30:29 +00:00
|
|
|
clr
|
|
|
|
echo -e "$BT\n\n$1\n\n\n$2"
|
|
|
|
read -r -p "Okay? [(o)kay/(a)bort] " resp
|
|
|
|
echo "$resp" > $TMP
|
2020-06-01 15:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ynBox() {
|
2020-11-22 18:30:29 +00:00
|
|
|
clr
|
|
|
|
echo -e "$BT\n\n$1\n\n\n$2"
|
|
|
|
read -r -p "Are you sure? [y/N] " resp
|
|
|
|
if [ "$resp" = "" ]; then
|
|
|
|
resp="N"
|
2020-06-01 15:02:43 +00:00
|
|
|
fi
|
2020-11-22 18:30:29 +00:00
|
|
|
echo "$resp" > $TMP
|
2020-06-01 15:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function askStr() {
|
2020-11-22 18:30:29 +00:00
|
|
|
clr
|
|
|
|
echo -e "$BT\n\n$2\n\n\n$3"
|
|
|
|
read resp
|
|
|
|
|
|
|
|
echo "$resp" > $TMP
|
2020-06-01 15:02:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-30 17:40:33 +00:00
|
|
|
function askPw() {
|
2020-11-22 18:30:29 +00:00
|
|
|
clr
|
|
|
|
echo -e "$BT\n\n$2\n\n"
|
2020-10-30 17:40:33 +00:00
|
|
|
|
2020-11-22 18:30:29 +00:00
|
|
|
stty -echo
|
|
|
|
|
|
|
|
read -r -p "$3 " resp
|
|
|
|
|
|
|
|
echo "$resp" > $TMP
|
2020-10-30 17:40:33 +00:00
|
|
|
}
|
|
|
|
|
2020-06-01 15:02:43 +00:00
|
|
|
function confirm() {
|
|
|
|
h=12
|
|
|
|
w=60
|
|
|
|
if [ -n "$3" ]; then
|
|
|
|
h=$3
|
|
|
|
fi
|
|
|
|
if [ -n "$4" ]; then
|
|
|
|
w=$4
|
|
|
|
fi
|
|
|
|
|
|
|
|
dialog --title "Confirm: $1" \
|
|
|
|
--backtitle "$BT" \
|
|
|
|
--yesno "Please confirm those information:\n$2" $h $w
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2020-06-13 13:22:26 +00:00
|
|
|
function askStrThird() {
|
|
|
|
h=12
|
|
|
|
w=60
|
|
|
|
if [ -n "$6" ]; then
|
|
|
|
h=$5
|
2020-06-01 15:02:43 +00:00
|
|
|
fi
|
2020-06-13 13:22:26 +00:00
|
|
|
if [ -n "$7" ]; then
|
|
|
|
w=$6
|
2020-06-01 15:02:43 +00:00
|
|
|
fi
|
|
|
|
|
2020-06-13 13:22:26 +00:00
|
|
|
dialog --backtitle "$BT" \
|
|
|
|
--max-input $1 \
|
|
|
|
--title "$2" \
|
|
|
|
--extra-button --extra-label "$4" \
|
|
|
|
--inputbox "$3" $h $w "$5" 2> $TMP
|
|
|
|
return $?
|
2020-06-01 15:02:43 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 13:22:26 +00:00
|
|
|
function gpgSearch() {
|
|
|
|
askStr 255 "GPG Search" "Type in the mail address you'd like to look up on keys.openpgp.org."
|
2020-06-01 15:02:43 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
2020-06-13 13:22:26 +00:00
|
|
|
if [[ "$(cat $TMP)" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$ ]]; then
|
|
|
|
clear
|
|
|
|
echo "Searching for GPG key..."
|
|
|
|
gpg --keyserver "hkps://keys.openpgp.org" --search "$(cat $TMP)"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
export FFP=$(gpg -k "$(cat $TMP)" | head -n 2 | tail -n 1 | awk '{print $1}' | sed 's/.\{4\}/& /g;s/^\(.*\) $/\1/g')
|
|
|
|
gpg --batch --delete-key "$FFP"
|
2021-01-04 19:36:16 +00:00
|
|
|
if [ "$FFP" = "" ]; then
|
|
|
|
gpgSearch
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
2020-06-13 13:22:26 +00:00
|
|
|
else
|
|
|
|
gpgSearch
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
gpgSearch
|
2020-06-01 15:02:43 +00:00
|
|
|
fi
|
|
|
|
fi
|
2020-06-13 13:22:26 +00:00
|
|
|
return 1
|
2020-06-01 15:02:43 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 13:22:26 +00:00
|
|
|
function enterGPG() {
|
|
|
|
askStrThird 49 "GPG Fingerprint" "Enter GPG fingerprint WITH SPACES. E.g.:\n 1234 5678 9ABC DEF0 1234 5678 9ABC DEF0 1234 5678" "Search..." "$1"
|
|
|
|
|
|
|
|
ret=$?
|
|
|
|
case $ret in
|
|
|
|
0)
|
|
|
|
FP=$(cat $TMP)
|
|
|
|
rm $TMP
|
|
|
|
if ! [[ $FP =~ ^([[:xdigit:]]{4} ){9}[[:xdigit:]]{4}$ ]]; then
|
|
|
|
diaBox "GPG Fingerprint" "This does not match the RegEx of a GPG fingerprint.\nPlease type in the whole fingerprint."
|
|
|
|
enterGPG
|
|
|
|
fi
|
|
|
|
FP=$(echo "$FP" | tr [a-f] [A-F])
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
3)
|
|
|
|
gpgSearch
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
enterGPG "$FFP" "no-confirm"
|
|
|
|
fi
|
|
|
|
return
|
|
|
|
;;
|
2020-06-01 15:02:43 +00:00
|
|
|
esac
|
2020-06-11 15:54:10 +00:00
|
|
|
|
2020-06-13 13:22:26 +00:00
|
|
|
if [ "$2" == "no-confirm" ]; then
|
2020-06-11 15:54:10 +00:00
|
|
|
return 0
|
2020-06-13 13:22:26 +00:00
|
|
|
else
|
|
|
|
confirm "GPG Fingerprint" " GPG:\n $FP"
|
|
|
|
return $?
|
2020-06-11 15:54:10 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-10-30 17:40:33 +00:00
|
|
|
function checkLockFile() {
|
|
|
|
while [ -f $LOCKFILE ]; do
|
|
|
|
infoBox "Printer is in use..." "Printer is in use. Please wait."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
touch $LOCKFILE
|
|
|
|
}
|
|
|
|
|
2020-06-13 13:22:26 +00:00
|
|
|
function printGPG() {
|
|
|
|
askForField "GPG fingerprint" "$1"
|
2020-06-11 15:54:10 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
2020-10-30 17:40:33 +00:00
|
|
|
checkLockFile
|
2020-06-11 15:54:10 +00:00
|
|
|
diaBox "Insert Passport" "Please insert passport (Visas) into the printer."
|
2020-06-13 13:22:26 +00:00
|
|
|
cd "$1"
|
2020-06-11 15:54:10 +00:00
|
|
|
./gpgkey $FIELD $FP
|
|
|
|
cd ..
|
2020-10-30 17:40:33 +00:00
|
|
|
rm $LOCKFILE
|
2020-06-11 15:54:10 +00:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-06-13 13:22:26 +00:00
|
|
|
function printReg() {
|
2020-10-30 17:40:33 +00:00
|
|
|
checkLockFile
|
2020-06-11 15:54:10 +00:00
|
|
|
diaBox "Insert Passport" "Please insert passport (First page, name, place) into the printer."
|
2020-06-13 13:22:26 +00:00
|
|
|
cd "$1"
|
2020-06-11 15:54:10 +00:00
|
|
|
./reg "$FNAME" "$SNAME" "$PLANET"
|
|
|
|
cd ..
|
2020-10-30 17:40:33 +00:00
|
|
|
rm $LOCKFILE
|
2020-06-11 15:54:10 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-06-13 13:22:26 +00:00
|
|
|
function printIROStamp() {
|
|
|
|
askForField "IRO stamp" "$1"
|
2020-06-11 15:54:10 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
2020-10-30 17:40:33 +00:00
|
|
|
checkLockFile
|
2020-06-11 15:54:10 +00:00
|
|
|
diaBox "Insert Passport" "Please insert passport (Visas) into the printer."
|
2020-06-13 13:22:26 +00:00
|
|
|
cd "$1"
|
2020-06-11 15:54:10 +00:00
|
|
|
./iro $FIELD
|
|
|
|
cd ..
|
2020-10-30 17:40:33 +00:00
|
|
|
rm $LOCKFILE
|
2020-06-11 15:54:10 +00:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-06-13 13:22:26 +00:00
|
|
|
function askForField() {
|
|
|
|
declare -A layout
|
|
|
|
declare -A maxfield
|
|
|
|
text="$1: Please choose a free field on the passport.\n"
|
|
|
|
|
|
|
|
layout[jhp]="
|
|
|
|
------------------\n
|
|
|
|
| Archievements |\n
|
|
|
|
==================\n
|
|
|
|
| 0 | 1 || 6 | 7 |\n
|
|
|
|
|---|---||---|---|\n
|
|
|
|
| 2 | 3 || 8 | 9 |\n
|
|
|
|
|---|---||---|---|\n
|
|
|
|
| 4 | 5 || 10| 11|\n
|
|
|
|
==================\n
|
|
|
|
"
|
|
|
|
|
|
|
|
layout[adafruit]="
|
|
|
|
------------------\n
|
|
|
|
| VISAS || VISAS |\n
|
|
|
|
==================\n
|
|
|
|
| 0 | 1 || 4 | 5 |\n
|
|
|
|
|---|---||---|---|\n
|
|
|
|
| 2 | 3 || 6 | 7 |\n
|
|
|
|
==================\n
|
|
|
|
"
|
|
|
|
|
|
|
|
maxfield[jhp]=11
|
|
|
|
maxfield[adafruit]=7
|
|
|
|
|
|
|
|
askStr 2 "Select a field" "$text ${layout[$2]}" "" 18
|
|
|
|
if [ $? -eq 1 ]; then
|
2020-06-11 15:54:10 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2020-06-13 13:22:26 +00:00
|
|
|
FIELD=$(cat $TMP)
|
|
|
|
if ! [[ "$FIELD" =~ ^[0-9]+$ ]] || [ -z "$FIELD" ] || [ $FIELD -lt 0 ] || [ $FIELD -gt ${maxfield[$2]} ]; then
|
|
|
|
askForField "$1" "$2"
|
|
|
|
else
|
2020-06-11 15:54:10 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-13 13:22:26 +00:00
|
|
|
function askReg() {
|
|
|
|
# Max length of passport fields
|
|
|
|
declare -A MAXLENGTH
|
|
|
|
MAXLENGTH[jhp]=25
|
|
|
|
MAXLENGTH[adafruit]=17
|
|
|
|
|
|
|
|
askStr ${MAXLENGTH[$1]} "Forename/Nickname" "Enter forename/nickname"
|
2020-06-11 15:54:10 +00:00
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
FNAME=$(cat $TMP)
|
|
|
|
|
2020-10-31 22:22:29 +00:00
|
|
|
askStr ${MAXLENGTH[$1]} "Surname" "Enter surname"
|
2020-06-11 15:54:10 +00:00
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
SNAME=$(cat $TMP)
|
|
|
|
|
2020-06-13 13:22:26 +00:00
|
|
|
askStr ${MAXLENGTH[$1]} "Place" "Enter place"
|
2020-06-11 15:54:10 +00:00
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
PLANET=$(cat $TMP)
|
|
|
|
|
2020-10-31 22:22:29 +00:00
|
|
|
confirm=" Forename: $FNAME\n Surname: $SNAME\n Place: $PLANET"
|
2020-06-11 15:54:10 +00:00
|
|
|
|
|
|
|
ynBox "IRO Stamp" "Does this being want to have a IRO stamp?"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
STAMP=true
|
|
|
|
else
|
|
|
|
STAMP=false
|
|
|
|
fi
|
|
|
|
|
|
|
|
ynBox "GPG" "Does the being have a GPG key to register?"
|
|
|
|
if [ $? -eq 0 ]; then
|
2020-06-13 13:22:26 +00:00
|
|
|
enterGPG "" no-confirm
|
2020-06-11 15:54:10 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
confirm="$confirm\n GPG:\n $FP"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
confirm "Everything" "$confirm"
|
|
|
|
return $?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-13 13:22:26 +00:00
|
|
|
function menuFor() {
|
2020-06-11 15:54:10 +00:00
|
|
|
dialog --backtitle "$BT" \
|
|
|
|
--menu "Select ID type:" 14 40 3 \
|
|
|
|
1 "Registration" \
|
|
|
|
2 "IRO Stamp" \
|
|
|
|
3 "GPG" \
|
|
|
|
9 "Back" 2> $TMP
|
|
|
|
|
|
|
|
choice=$(cat $TMP)
|
|
|
|
|
|
|
|
case $choice in
|
2020-06-13 13:22:26 +00:00
|
|
|
1) askReg "$1"
|
2020-06-11 15:54:10 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
2020-06-13 13:22:26 +00:00
|
|
|
printReg "$1"
|
2020-06-11 15:54:10 +00:00
|
|
|
if [ "$STAMP" == "true" ]; then
|
2020-06-13 13:22:26 +00:00
|
|
|
printIROStamp "$1"
|
2020-06-11 15:54:10 +00:00
|
|
|
fi
|
|
|
|
if [ -n "$FP" ]; then
|
2020-06-13 13:22:26 +00:00
|
|
|
printGPG "$1"
|
2020-06-11 15:54:10 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
2020-06-13 13:22:26 +00:00
|
|
|
2) printIROStamp "$1"
|
2020-06-11 15:54:10 +00:00
|
|
|
;;
|
2020-06-13 13:22:26 +00:00
|
|
|
3) enterGPG
|
2020-06-11 15:54:10 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
2020-06-13 13:22:26 +00:00
|
|
|
printGPG "$1"
|
2020-06-11 15:54:10 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
unset FNAME
|
|
|
|
unset SNAME
|
|
|
|
unset PLANET
|
|
|
|
unset FP
|
|
|
|
unset FIELD
|
2020-06-13 13:22:26 +00:00
|
|
|
unset FFP
|
2020-06-11 15:54:10 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 17:40:33 +00:00
|
|
|
function askForFunnyUserCreds() {
|
2021-01-02 18:41:29 +00:00
|
|
|
clr
|
|
|
|
echo "Press Enter to start."
|
|
|
|
read -s
|
|
|
|
|
2020-10-30 17:40:33 +00:00
|
|
|
askStr 12 "Login" "Username:" ""
|
|
|
|
username=$(cat $TMP)
|
|
|
|
askPw 12 "Login" "Password:" ""
|
|
|
|
password=$(cat $TMP)
|
|
|
|
|
|
|
|
if [ -f .pw/$username ]; then
|
|
|
|
if [ "$password" != $(cat .pw/$username) ]; then
|
2021-01-02 18:41:29 +00:00
|
|
|
clr
|
2020-10-30 17:40:33 +00:00
|
|
|
echo "Wrong credentials."
|
|
|
|
sleep 3
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Wrong credentials."
|
2020-11-22 18:30:29 +00:00
|
|
|
sleep 3
|
2020-10-30 17:40:33 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
askForFunnyUserCreds
|
|
|
|
|
2020-06-01 15:02:43 +00:00
|
|
|
while [ true ]; do
|
|
|
|
|
|
|
|
dialog --backtitle "$BT" \
|
|
|
|
--menu "Select ID type:" 10 40 3 \
|
|
|
|
1 "Junghackerpass" \
|
2020-06-11 15:54:10 +00:00
|
|
|
2 "New Adafruit passport" \
|
2020-10-30 17:40:33 +00:00
|
|
|
9 "Logout" 2> $TMP
|
2020-06-01 15:02:43 +00:00
|
|
|
|
2020-06-11 15:54:10 +00:00
|
|
|
if [ $? -eq 9 ]; then
|
2020-06-01 15:02:43 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
TYPE=$(cat $TMP)
|
|
|
|
|
|
|
|
|
|
|
|
case $TYPE in
|
2020-06-13 13:22:26 +00:00
|
|
|
1) menuFor jhp
|
2020-06-01 15:02:43 +00:00
|
|
|
;;
|
2020-06-13 13:22:26 +00:00
|
|
|
2) menuFor adafruit
|
2020-06-11 15:54:10 +00:00
|
|
|
;;
|
2020-10-30 17:40:33 +00:00
|
|
|
9) break
|
2020-06-01 15:02:43 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
rm $TMP
|
|
|
|
clear
|