GPG search (usage of keys.openpgp.org), deleting keys after getting FP, removing code duplication, corrected layout for jhp
This commit is contained in:
parent
dfd9cda104
commit
80e0d2ee9c
@ -10,7 +10,7 @@ HEADINGRIGHT=15
|
||||
|
||||
# GPG Space
|
||||
NEXTPAGE=48
|
||||
NEXTFIELDBOTTOM=7
|
||||
NEXTFIELDBOTTOM=6
|
||||
NEXTFIELDRIGHT=25
|
||||
MAXLENGTH=22
|
||||
|
||||
|
2
jhp/iro
2
jhp/iro
@ -11,7 +11,7 @@ HEADINGRIGHT=8
|
||||
# GPG Space
|
||||
NEXTPAGE=30
|
||||
NEXTPAGESMALL=48
|
||||
NEXTFIELDBOTTOM=7
|
||||
NEXTFIELDBOTTOM=6
|
||||
NEXTFIELDRIGHT=14
|
||||
NEXTFIELDRIGHTSMALL=25
|
||||
|
||||
|
374
start
374
start
@ -2,7 +2,9 @@
|
||||
export EVENT=DiVOC
|
||||
|
||||
TMP=/tmp/$RANDOM
|
||||
BT="Intergalactic Registration Office - v0.1"
|
||||
BT="Intergalactic Registration Office - v0.3"
|
||||
|
||||
|
||||
|
||||
function diaBox() {
|
||||
h=8
|
||||
@ -68,8 +70,119 @@ function confirm() {
|
||||
return $?
|
||||
}
|
||||
|
||||
function jhpAskForField() {
|
||||
text="$1: Please choose a free field on the passport.\n
|
||||
function askStrThird() {
|
||||
h=12
|
||||
w=60
|
||||
if [ -n "$6" ]; then
|
||||
h=$5
|
||||
fi
|
||||
if [ -n "$7" ]; then
|
||||
w=$6
|
||||
fi
|
||||
|
||||
dialog --backtitle "$BT" \
|
||||
--max-input $1 \
|
||||
--title "$2" \
|
||||
--extra-button --extra-label "$4" \
|
||||
--inputbox "$3" $h $w "$5" 2> $TMP
|
||||
return $?
|
||||
}
|
||||
|
||||
function gpgSearch() {
|
||||
askStr 255 "GPG Search" "Type in the mail address you'd like to look up on keys.openpgp.org."
|
||||
if [ $? -eq 0 ]; then
|
||||
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"
|
||||
return 0
|
||||
else
|
||||
gpgSearch
|
||||
fi
|
||||
else
|
||||
gpgSearch
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
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
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$2" == "no-confirm" ]; then
|
||||
return 0
|
||||
else
|
||||
confirm "GPG Fingerprint" " GPG:\n $FP"
|
||||
return $?
|
||||
fi
|
||||
}
|
||||
|
||||
function printGPG() {
|
||||
askForField "GPG fingerprint" "$1"
|
||||
if [ $? -eq 0 ]; then
|
||||
diaBox "Insert Passport" "Please insert passport (Visas) into the printer."
|
||||
cd "$1"
|
||||
./gpgkey $FIELD $FP
|
||||
cd ..
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function printReg() {
|
||||
diaBox "Insert Passport" "Please insert passport (First page, name, place) into the printer."
|
||||
cd "$1"
|
||||
./reg "$FNAME" "$SNAME" "$PLANET"
|
||||
cd ..
|
||||
return 0
|
||||
}
|
||||
|
||||
function printIROStamp() {
|
||||
askForField "IRO stamp" "$1"
|
||||
if [ $? -eq 0 ]; then
|
||||
diaBox "Insert Passport" "Please insert passport (Visas) into the printer."
|
||||
cd "$1"
|
||||
./iro $FIELD
|
||||
cd ..
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
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
|
||||
@ -80,156 +193,8 @@ function jhpAskForField() {
|
||||
| 4 | 5 || 10| 11|\n
|
||||
==================\n
|
||||
"
|
||||
askStr 2 "Select a field" "$text" "" 18
|
||||
if [ $? -eq 1 ]; then
|
||||
return 1
|
||||
fi
|
||||
FIELD=$(cat $TMP)
|
||||
if ! [[ "$FIELD" =~ ^[0-9]+$ ]] || [ -z "$FIELD" ] || [ $FIELD -lt 0 ] || [ $FIELD -gt 11 ]; then
|
||||
jhpAskForField
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function jhpPrintGPG() {
|
||||
jhpAskForField "GPG fingerprint"
|
||||
if [ $? -eq 0 ]; then
|
||||
diaBox "Insert Passport" "Please insert passport (Archivements) into the printer."
|
||||
cd jhp
|
||||
./gpgkey $FIELD $FP
|
||||
cd ..
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function jhpPrintReg() {
|
||||
diaBox "Insert Passport" "Please insert passport (First page, name, planet, date) into the printer."
|
||||
cd jhp
|
||||
./reg "$FNAME" "$SNAME" "$PLANET"
|
||||
cd ..
|
||||
return 0
|
||||
}
|
||||
|
||||
function jhpIROStamp() {
|
||||
jhpAskForField "IRO stamp"
|
||||
if [ $? -eq 0 ]; then
|
||||
diaBox "Insert Passport" "Please insert passport (Archivements) into the printer."
|
||||
cd jhp
|
||||
./iro $FIELD
|
||||
cd ..
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function jhpGPG() {
|
||||
askStr 49 "GPG Fingerprint" "Enter GPG fingerprint WITH SPACES. E.g.:\n 1234 5678 9ABC DEF0 1234 5678 9ABC DEF0 1234 5678"
|
||||
if [ $? -eq 0 ]; then
|
||||
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."
|
||||
jhpGPG
|
||||
fi
|
||||
FP=$(echo "$FP" | tr [a-f] [A-F])
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
if [ "$1" == "no-confirm" ]; then
|
||||
return 0
|
||||
else
|
||||
confirm "GPG Fingerprint" " GPG:\n $FP"
|
||||
return $?
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function jhpReg() {
|
||||
askStr 25 "Forename/Nickname" "Enter forename/nickname"
|
||||
if [ $? -eq 1 ]; then
|
||||
return 1
|
||||
fi
|
||||
FNAME=$(cat $TMP)
|
||||
|
||||
askStr 25 "Surename" "Enter surename"
|
||||
if [ $? -eq 1 ]; then
|
||||
return 1
|
||||
fi
|
||||
SNAME=$(cat $TMP)
|
||||
|
||||
askStr 25 "Planet" "Enter planet" "Earth, Chaospott"
|
||||
if [ $? -eq 1 ]; then
|
||||
return 1
|
||||
fi
|
||||
PLANET=$(cat $TMP)
|
||||
|
||||
confirm=" Forename: $FNAME\n Surename: $SNAME\n Planet: $PLANET"
|
||||
|
||||
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
|
||||
jhpGPG no-confirm
|
||||
if [ $? -eq 0 ]; then
|
||||
confirm="$confirm\n GPG:\n $FP"
|
||||
fi
|
||||
fi
|
||||
|
||||
confirm "Everything" "$confirm"
|
||||
return $?
|
||||
|
||||
}
|
||||
|
||||
function jhpmenu() {
|
||||
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
|
||||
1) jhpReg
|
||||
if [ $? -eq 0 ]; then
|
||||
jhpPrintReg
|
||||
if [ "$STAMP" == "true" ]; then
|
||||
jhpIROStamp
|
||||
fi
|
||||
if [ -n "$FP" ]; then
|
||||
jhpPrintGPG
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
2) jhpIROStamp
|
||||
;;
|
||||
3) jhpGPG
|
||||
if [ $? -eq 0 ]; then
|
||||
jhpPrintGPG
|
||||
fi
|
||||
;;
|
||||
|
||||
esac
|
||||
unset FNAME
|
||||
unset SNAME
|
||||
unset PLANET
|
||||
unset FP
|
||||
unset FIELD
|
||||
}
|
||||
|
||||
|
||||
function adaAskForField() {
|
||||
text="$1: Please choose a free field on the passport.\n
|
||||
|
||||
layout[adafruit]="
|
||||
------------------\n
|
||||
| VISAS || VISAS |\n
|
||||
==================\n
|
||||
@ -238,88 +203,42 @@ function adaAskForField() {
|
||||
| 2 | 3 || 6 | 7 |\n
|
||||
==================\n
|
||||
"
|
||||
askStr 2 "Select a field" "$text" "" 18
|
||||
|
||||
maxfield[jhp]=11
|
||||
maxfield[adafruit]=7
|
||||
|
||||
askStr 2 "Select a field" "$text ${layout[$2]}" "" 18
|
||||
if [ $? -eq 1 ]; then
|
||||
return 1
|
||||
fi
|
||||
FIELD=$(cat $TMP)
|
||||
if ! [[ "$FIELD" =~ ^[0-9]+$ ]] || [ -z "$FIELD" ] || [ $FIELD -lt 0 ] || [ $FIELD -gt 7 ]; then
|
||||
adaAskForField
|
||||
if ! [[ "$FIELD" =~ ^[0-9]+$ ]] || [ -z "$FIELD" ] || [ $FIELD -lt 0 ] || [ $FIELD -gt ${maxfield[$2]} ]; then
|
||||
askForField "$1" "$2"
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function adaPrintGPG() {
|
||||
adaAskForField "GPG fingerprint"
|
||||
if [ $? -eq 0 ]; then
|
||||
diaBox "Insert Passport" "Please insert passport (Visas) into the printer."
|
||||
cd adafruit
|
||||
./gpgkey $FIELD $FP
|
||||
cd ..
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function adaPrintReg() {
|
||||
diaBox "Insert Passport" "Please insert passport (First page, name, place) into the printer."
|
||||
cd adafruit
|
||||
./reg "$FNAME" "$SNAME" "$PLANET"
|
||||
cd ..
|
||||
return 0
|
||||
}
|
||||
function askReg() {
|
||||
# Max length of passport fields
|
||||
declare -A MAXLENGTH
|
||||
MAXLENGTH[jhp]=25
|
||||
MAXLENGTH[adafruit]=17
|
||||
|
||||
function adaIROStamp() {
|
||||
adaAskForField "IRO stamp"
|
||||
if [ $? -eq 0 ]; then
|
||||
diaBox "Insert Passport" "Please insert passport (Visas) into the printer."
|
||||
cd adafruit
|
||||
./iro $FIELD
|
||||
cd ..
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function adaGPG() {
|
||||
askStr 49 "GPG Fingerprint" "Enter GPG fingerprint WITH SPACES. E.g.:\n 1234 5678 9ABC DEF0 1234 5678 9ABC DEF0 1234 5678"
|
||||
if [ $? -eq 0 ]; then
|
||||
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."
|
||||
adaGPG
|
||||
fi
|
||||
FP=$(echo "$FP" | tr [a-f] [A-F])
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
if [ "$1" == "no-confirm" ]; then
|
||||
return 0
|
||||
else
|
||||
confirm "GPG Fingerprint" " GPG:\n $FP"
|
||||
return $?
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function adaReg() {
|
||||
askStr 25 "Forename/Nickname" "Enter forename/nickname"
|
||||
askStr ${MAXLENGTH[$1]} "Forename/Nickname" "Enter forename/nickname"
|
||||
if [ $? -eq 1 ]; then
|
||||
return 1
|
||||
fi
|
||||
FNAME=$(cat $TMP)
|
||||
|
||||
askStr 25 "Surename" "Enter surename"
|
||||
askStr ${MAXLENGTH[$1]} "Surename" "Enter surename"
|
||||
if [ $? -eq 1 ]; then
|
||||
return 1
|
||||
fi
|
||||
SNAME=$(cat $TMP)
|
||||
|
||||
askStr 25 "Place" "Enter place" "Earth, Chaospott"
|
||||
askStr ${MAXLENGTH[$1]} "Place" "Enter place"
|
||||
if [ $? -eq 1 ]; then
|
||||
return 1
|
||||
fi
|
||||
@ -336,7 +255,7 @@ function adaReg() {
|
||||
|
||||
ynBox "GPG" "Does the being have a GPG key to register?"
|
||||
if [ $? -eq 0 ]; then
|
||||
adaGPG no-confirm
|
||||
enterGPG "" no-confirm
|
||||
if [ $? -eq 0 ]; then
|
||||
confirm="$confirm\n GPG:\n $FP"
|
||||
fi
|
||||
@ -347,7 +266,7 @@ function adaReg() {
|
||||
|
||||
}
|
||||
|
||||
function adamenu() {
|
||||
function menuFor() {
|
||||
dialog --backtitle "$BT" \
|
||||
--menu "Select ID type:" 14 40 3 \
|
||||
1 "Registration" \
|
||||
@ -358,22 +277,22 @@ function adamenu() {
|
||||
choice=$(cat $TMP)
|
||||
|
||||
case $choice in
|
||||
1) adaReg
|
||||
1) askReg "$1"
|
||||
if [ $? -eq 0 ]; then
|
||||
adaPrintReg
|
||||
printReg "$1"
|
||||
if [ "$STAMP" == "true" ]; then
|
||||
adaIROStamp
|
||||
printIROStamp "$1"
|
||||
fi
|
||||
if [ -n "$FP" ]; then
|
||||
adaPrintGPG
|
||||
printGPG "$1"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
2) adaIROStamp
|
||||
2) printIROStamp "$1"
|
||||
;;
|
||||
3) adaGPG
|
||||
3) enterGPG
|
||||
if [ $? -eq 0 ]; then
|
||||
adaPrintGPG
|
||||
printGPG "$1"
|
||||
fi
|
||||
;;
|
||||
|
||||
@ -383,17 +302,16 @@ function adamenu() {
|
||||
unset PLANET
|
||||
unset FP
|
||||
unset FIELD
|
||||
unset FFP
|
||||
}
|
||||
|
||||
|
||||
|
||||
while [ true ]; do
|
||||
|
||||
dialog --backtitle "$BT" \
|
||||
--menu "Select ID type:" 10 40 3 \
|
||||
1 "Junghackerpass" \
|
||||
2 "New Adafruit passport" \
|
||||
9 "Usual" 2> $TMP
|
||||
9 "Exit" 2> $TMP
|
||||
|
||||
if [ $? -eq 9 ]; then
|
||||
break
|
||||
@ -403,9 +321,9 @@ while [ true ]; do
|
||||
|
||||
|
||||
case $TYPE in
|
||||
1) jhpmenu
|
||||
1) menuFor jhp
|
||||
;;
|
||||
2) adamenu
|
||||
2) menuFor adafruit
|
||||
;;
|
||||
9) exit 0
|
||||
;;
|
||||
|
Loading…
Reference in New Issue
Block a user