mirror of
https://git.yip.gay/c3gov/c3gov.git
synced 2026-08-11 22:54:39 +00:00
662 lines
14 KiB
Bash
Executable File
662 lines
14 KiB
Bash
Executable File
#!/bin/bash
|
|
. gettext.sh
|
|
|
|
export TEXTDOMAIN=start_dialog
|
|
export TEXTDOMAINDIR=$PWD/i18n/
|
|
|
|
export LANG=C
|
|
export TERM=vt220
|
|
|
|
export DIALOGRC=dialogrc
|
|
|
|
source $(dirname $0)/config
|
|
|
|
export PRINTDEVICE="/dev/ttyUSB$CLIENTS"
|
|
export DEVICE="$PRINTDEVICE"
|
|
|
|
LOCKFILE=/tmp/c3govlock
|
|
TMP=/tmp/$RANDOM
|
|
BT="c3gov - v0.5.2.0"
|
|
|
|
cd $(dirname "$0")
|
|
|
|
function checkDependencies() {
|
|
which curl >> /dev/null
|
|
if [ $? -ne 0 ]; then
|
|
echo "curl not installed."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
function infoBox() {
|
|
h=8
|
|
w=60
|
|
if [ -n "$3" ]; then
|
|
h=$3
|
|
fi
|
|
if [ -n "$4" ]; then
|
|
w=$4
|
|
fi
|
|
dialog --title "$1" \
|
|
--backtitle "$BT" \
|
|
--infobox "$2" $h $w
|
|
}
|
|
|
|
function diaBox() {
|
|
h=8
|
|
w=60
|
|
if [ -n "$3" ]; then
|
|
h=$3
|
|
fi
|
|
if [ -n "$4" ]; then
|
|
w=$4
|
|
fi
|
|
dialog --title "$1" \
|
|
--backtitle "$BT" \
|
|
--msgbox "$2" $h $w
|
|
}
|
|
|
|
function ynBox() {
|
|
h=8
|
|
w=60
|
|
if [ -n "$3" ]; then
|
|
h=$3
|
|
fi
|
|
if [ -n "$4" ]; then
|
|
w=$4
|
|
fi
|
|
|
|
dialog --title "$1" \
|
|
--backtitle "$BT" \
|
|
--yesno "$2" $h $w
|
|
|
|
return $?
|
|
}
|
|
|
|
function askStr() {
|
|
h=12
|
|
w=60
|
|
if [ -n "$5" ]; then
|
|
h=$5
|
|
fi
|
|
if [ -n "$6" ]; then
|
|
w=$6
|
|
fi
|
|
|
|
dialog --title "$2" \
|
|
--backtitle "$BT" \
|
|
--max-input $1 \
|
|
--inputbox "$3" $h $w "$4" 2> $TMP
|
|
return $?
|
|
}
|
|
|
|
function askPw() {
|
|
h=12
|
|
w=60
|
|
if [ -n "$5" ]; then
|
|
h=$5
|
|
fi
|
|
if [ -n "$6" ]; then
|
|
w=$6
|
|
fi
|
|
|
|
dialog --title "$2" \
|
|
--backtitle "$BT" \
|
|
--max-input $1 \
|
|
--insecure \
|
|
--passwordbox "$3" $h $w "$4" 2> $TMP
|
|
return $?
|
|
}
|
|
|
|
function confirm() {
|
|
h=12
|
|
w=60
|
|
if [ -n "$3" ]; then
|
|
h=$3
|
|
fi
|
|
if [ -n "$4" ]; then
|
|
w=$4
|
|
fi
|
|
|
|
dialog --title "$(eval_gettext "Confirm: \$1")" \
|
|
--backtitle "$BT" \
|
|
--yesno "$(eval_gettext "Please confirm those information:\n\$2")" $h $w
|
|
return $?
|
|
}
|
|
|
|
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 "$(eval_gettext "GPG Search")" "$(eval_gettext "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 "$(eval_gettext "Searching for GPG key...")"
|
|
gpg --keyserver "hkps://keys.openpgp.org" --search "$(cat $TMP)"
|
|
if [ $? -eq 0 ]; then
|
|
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"
|
|
if [ "$FFP" = "" ]; then
|
|
diaBox "$(eval_gettext "GPG Search")" "$(eval_gettext "No fingerprint has been found for \$(cat \$TMP)")"
|
|
return 1
|
|
else
|
|
return 0
|
|
fi
|
|
else
|
|
diaBox "$(eval_gettext "GPG Search")" "$(eval_gettext "No fingerprint has been found for \$(cat \$TMP)")"
|
|
return 1
|
|
fi
|
|
else
|
|
diaBox "$(eval_gettext "GPG Search")" "$(eval_gettext "This is no valid mail address.")"
|
|
return 1
|
|
fi
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
function enterGPG() {
|
|
askStrThird 49 "$(eval_gettext "GPG Fingerprint")" "$(eval_gettext "Enter GPG fingerprint WITH SPACES. E.g.:\n 1234 5678 9ABC DEF0 1234 5678 9ABC DEF0 1234 5678")" "$(eval_gettext "Search...")" "$1"
|
|
|
|
ret=$?
|
|
case $ret in
|
|
0)
|
|
FP=$(cat $TMP)
|
|
rm $TMP
|
|
if ! [[ $FP =~ ^([[:xdigit:]]{4} ){9}[[:xdigit:]]{4}$ ]]; then
|
|
diaBox "$(eval_gettext "GPG Fingerprint")" "$(eval_gettext "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"
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
if [ "$2" == "no-confirm" ]; then
|
|
return 0
|
|
else
|
|
confirm "$(eval_gettext "GPG Fingerprint")" " GPG:\n $FP"
|
|
return $?
|
|
fi
|
|
}
|
|
|
|
function checkLockFile() {
|
|
while [ -f $LOCKFILE ]; do
|
|
infoBox "$(eval_gettext "Printer is in use...")" "$(eval_gettext "Printer is in use. Please wait.")"
|
|
sleep 1
|
|
done
|
|
touch $LOCKFILE
|
|
}
|
|
|
|
function printGPG() {
|
|
askForField "$(eval_gettext "GPG fingerprint")" "$1"
|
|
if [ $? -eq 0 ]; then
|
|
checkLockFile
|
|
diaBox "$(eval_gettext "Insert Passport")" "$(eval_gettext "Please insert passport (Visas) into the printer.")"
|
|
cd "$1"
|
|
./gpgkey $FIELD $FP
|
|
cd ..
|
|
rm $LOCKFILE
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
function printReg() {
|
|
checkLockFile
|
|
diaBox "$(eval_gettext "Insert Passport")" "$(eval_gettext "Please insert passport (First page, name, place) into the printer.")"
|
|
cd "$1"
|
|
./reg "$FNAME" "$SNAME" "$PLANET"
|
|
cd ..
|
|
rm $LOCKFILE
|
|
return 0
|
|
}
|
|
|
|
function printc3govStamp() {
|
|
askForField "$(eval_gettext "c3gov stamp")" "$1"
|
|
if [ $? -eq 0 ]; then
|
|
checkLockFile
|
|
diaBox "$(eval_gettext "Insert Passport")" "$(eval_gettext "Please insert passport (Visas) into the printer.")"
|
|
cd "$1"
|
|
./c3gov $FIELD
|
|
cd ..
|
|
rm $LOCKFILE
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
function askForField() {
|
|
declare -A layout
|
|
declare -A maxfield
|
|
text=$(eval_gettext "\$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[bounddipl]="
|
|
------------------\n
|
|
| VISAS || VISAS |\n
|
|
==================\n
|
|
| 0 | 1 || 4 | 5 |\n
|
|
|---|---||---|---|\n
|
|
| 2 | 3 || 6 | 7 |\n
|
|
==================\n
|
|
"
|
|
|
|
layout[stapleddipl]="
|
|
------------------\n
|
|
| VISAS || VISAS |\n
|
|
==================\n
|
|
| 0 | 1 || 4 | 5 |\n
|
|
|---|---||---|---|\n
|
|
| 2 | 3 || 6 | 7 |\n
|
|
==================\n
|
|
"
|
|
|
|
|
|
maxfield[jhp]=11
|
|
maxfield[bounddipl]=7
|
|
maxfield[stapleddipl]=7
|
|
|
|
askStr 2 "$(eval_gettext "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 ${maxfield[$2]} ]; then
|
|
askForField "$1" "$2"
|
|
else
|
|
return 0
|
|
fi
|
|
}
|
|
|
|
|
|
function askReg() {
|
|
# Max length of passport fields
|
|
declare -A MAXLENGTH
|
|
MAXLENGTH[jhp]=25
|
|
MAXLENGTH[bounddipl]=17
|
|
MAXLENGTH[stapleddipl]=17
|
|
MAXLENGTH[stapled_glossy_dipl]=17
|
|
|
|
askStr ${MAXLENGTH[$1]} "$(eval_gettext "Forename/Nickname")" "$(eval_gettext "Enter forename/nickname")"
|
|
if [ $? -eq 1 ]; then
|
|
return 1
|
|
fi
|
|
FNAME=$(cat $TMP)
|
|
|
|
askStr ${MAXLENGTH[$1]} "$(eval_gettext "Surname")" "$(eval_gettext "Enter surname")"
|
|
if [ $? -eq 1 ]; then
|
|
return 1
|
|
fi
|
|
SNAME=$(cat $TMP)
|
|
|
|
askStr ${MAXLENGTH[$1]} "$(eval_gettext "Place")" "$(eval_gettext "Enter place")"
|
|
if [ $? -eq 1 ]; then
|
|
return 1
|
|
fi
|
|
PLANET=$(cat $TMP)
|
|
|
|
confirm="$(eval_gettext " Forename: \$FNAME\n Surname: \$SNAME\n Place: \$PLANET")"
|
|
|
|
ynBox "$(eval_gettext "Security")" "$(eval_gettext "Secure this passport using security stickers?")"
|
|
if [ $? -eq 0 ]; then
|
|
SECURE=true
|
|
else
|
|
SECURE=false
|
|
fi
|
|
|
|
ynBox "$(eval_gettext "c3gov Stamp")" "$(eval_gettext "Does this entity want to have a c3gov stamp?")"
|
|
if [ $? -eq 0 ]; then
|
|
STAMP=true
|
|
else
|
|
STAMP=false
|
|
fi
|
|
|
|
ynBox "$(eval_gettext "GPG")" "$(eval_gettext "Does the entity have a GPG key to register?")"
|
|
if [ $? -eq 0 ]; then
|
|
enterGPG "" no-confirm
|
|
if [ $? -eq 0 ]; then
|
|
confirm="$confirm\n GPG:\n $FP"
|
|
fi
|
|
fi
|
|
|
|
confirm "$(eval_gettext "Everything")" "$confirm"
|
|
return $?
|
|
|
|
}
|
|
|
|
function enterSecurityCode() {
|
|
MAXLENGTH=6
|
|
|
|
askStr ${MAXLENGTH} "$(eval_gettext "Security code")" "$(eval_gettext "Enter security code from the security sticker (e.g. S12345).")"
|
|
if [ $? -eq 1 ]; then
|
|
return 1
|
|
fi
|
|
SECURITYCODE=$(cat $TMP)
|
|
confirm "$(eval_gettext "Security code")" "$(eval_gettext "Security code: \$SECURITYCODE")"
|
|
return $?
|
|
|
|
}
|
|
|
|
function printSecurePassportFirstPage(){
|
|
checkLockFile
|
|
diaBox "$(eval_gettext "Insert Passport")" "$(eval_gettext "Pleast insert the FIRST PAGE (Identity) into the printer.")"
|
|
|
|
cd "$1"
|
|
./secure_firstpage "$SECURITYCODE"
|
|
cd ..
|
|
rm $LOCKFILE
|
|
}
|
|
|
|
function printSecurePassport(){
|
|
checkLockFile
|
|
diaBox "$(eval_gettext "Insert Passport")" "$(eval_gettext "Please insert passport (Visas) into the printer.\nA print on EVERY Visa page is necessary.")"
|
|
|
|
cd "$1"
|
|
./secure "$SECURITYCODE"
|
|
cd ..
|
|
rm $LOCKFILE
|
|
}
|
|
|
|
function printAttendanceLetter() {
|
|
checkLockFile
|
|
cd attendance
|
|
if [ "$GERMAN" = "true" ]; then
|
|
./german "$FNAME" "$STREET" "$CITY" "$COUNTRY"
|
|
else
|
|
./english "$FNAME" "$STREET" "$CITY" "$COUNTRY"
|
|
fi
|
|
cd ..
|
|
unset FNAME
|
|
unset STREET
|
|
unset CITY
|
|
unset COUNTRY
|
|
rm $LOCKFILE
|
|
|
|
}
|
|
|
|
function enableSecurity() {
|
|
if [ "$1" = "bounddipl" ]; then
|
|
diaBox "$(eval_gettext "Error")" "$(eval_gettext "Passport security: Passport not supported.")"
|
|
else
|
|
enterSecurityCode
|
|
if [ $? -eq 0 ]; then
|
|
case $1 in
|
|
"bounddipl")
|
|
;;
|
|
"jhp")
|
|
printSecurePassport "$1"
|
|
;;
|
|
*)
|
|
printSecurePassportFirstPage "$1"
|
|
printSecurePassport "$1"
|
|
;;
|
|
esac
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function askPreReg() {
|
|
# Max length of passport fields
|
|
|
|
while [ true ]; do
|
|
|
|
askStr 32 "$(eval_gettext "\$1: Pre-Registration")" "$(eval_gettext "\$1: Please scan the Data Matrix code.")"
|
|
if [ $? -eq 1 ]; then
|
|
return 1
|
|
fi
|
|
|
|
api_request=$(curl -X POST -d "referenceNumber=$(cat $TMP)" "$API")
|
|
|
|
if [ "$api_request" != "null" ]; then
|
|
FNAME=$(echo "$api_request" | jq -r .first_name)
|
|
SNAME=$(echo "$api_request" | jq -r .last_name)
|
|
PLANET=$(echo "$api_request" | jq -r .location)
|
|
SECURE=true
|
|
STAMP=true
|
|
unset api_request
|
|
break;
|
|
fi
|
|
done
|
|
|
|
confirm=$(eval_gettext " Forename: \$FNAME\n Surname: \$SNAME\n Place: \$PLANET")
|
|
|
|
ynBox "GPG" "$(eval_gettext "Does the entity have a GPG key to register?")"
|
|
if [ $? -eq 0 ]; then
|
|
enterGPG "" no-confirm
|
|
if [ $? -eq 0 ]; then
|
|
confirm="$confirm\n GPG:\n $FP"
|
|
fi
|
|
fi
|
|
|
|
confirm "$(eval_gettext "Everything")" "$confirm"
|
|
return $?
|
|
|
|
}
|
|
|
|
function attendance() {
|
|
|
|
askStr 2048 "$(eval_gettext "Proof of Attendance")" "$(eval_gettext "(Full) Name of the attendee")"
|
|
if [ $? -eq 1 ]; then
|
|
return 1
|
|
fi
|
|
FNAME=$(cat $TMP)
|
|
|
|
askStr 2048 "$(eval_gettext "Proof of Attendance")" "$(eval_gettext "Street and House Number")"
|
|
if [ $? -eq 1 ]; then
|
|
return 1
|
|
fi
|
|
STREET=$(cat $TMP)
|
|
|
|
askStr 2048 "$(eval_gettext "Proof of Attendance")" "$(eval_gettext "Zip code and City")"
|
|
if [ $? -eq 1 ]; then
|
|
return 1
|
|
fi
|
|
CITY=$(cat $TMP)
|
|
|
|
askStr 2048 "$(eval_gettext "Proof of Attendance")" "$(eval_gettext "Country")"
|
|
if [ $? -eq 1 ]; then
|
|
return 1
|
|
fi
|
|
COUNTRY=$(cat $TMP)
|
|
|
|
confirm=" $FNAME\n $STREET\n $CITY\n $COUNTRY"
|
|
|
|
confirm "$(eval_gettext "Everything")" "$confirm"
|
|
|
|
ynBox "$(eval_gettext "Proof of Attendance - Language")" "$(eval_gettext "Print in German (Deutsch)?")"
|
|
if [ $? -eq 0 ]; then
|
|
GERMAN="true"
|
|
else
|
|
GERMAN="false"
|
|
fi
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
function menuFor() {
|
|
dialog --backtitle "$BT" \
|
|
--menu "$(eval_gettext "Select purpose:")" 14 40 3 \
|
|
1 "$(eval_gettext "Registration P1/P2/P3")" \
|
|
2 "$(eval_gettext "Pre-Registration P5")" \
|
|
3 "$(eval_gettext "c3gov Stamp")" \
|
|
4 "$(eval_gettext "GPG")" \
|
|
5 "$(eval_gettext "Letter")" \
|
|
8 "$(eval_gettext "Secure Passport P3")" \
|
|
9 "$(eval_gettext "Back")" 2> $TMP
|
|
|
|
choice=$(cat $TMP)
|
|
|
|
case $choice in
|
|
1) askReg "$1"
|
|
if [ $? -eq 0 ]; then
|
|
printReg "$1"
|
|
if [ "$SECURE" = "true" ]; then
|
|
enableSecurity "$1"
|
|
fi
|
|
if [ "$STAMP" = "true" ]; then
|
|
printc3govStamp "$1"
|
|
fi
|
|
if [ -n "$FP" ]; then
|
|
printGPG "$1"
|
|
fi
|
|
fi
|
|
;;
|
|
2) askPreReg "$1"
|
|
if [ $? -eq 0 ]; then
|
|
printReg "$1"
|
|
if [ "$SECURE" = "true" ]; then
|
|
enableSecurity "$1"
|
|
fi
|
|
if [ "$STAMP" = "true" ]; then
|
|
printc3govStamp "$1"
|
|
fi
|
|
if [ -n "$FP" ]; then
|
|
printGPG "$1"
|
|
fi
|
|
fi
|
|
;;
|
|
3) printc3govStamp "$1"
|
|
;;
|
|
4) enterGPG
|
|
if [ $? -eq 0 ]; then
|
|
printGPG "$1"
|
|
fi
|
|
;;
|
|
5)
|
|
;;
|
|
8) enableSecurity "$1"
|
|
;;
|
|
|
|
esac
|
|
|
|
unset FNAME
|
|
unset SNAME
|
|
unset PLANET
|
|
unset FP
|
|
unset FIELD
|
|
unset FFP
|
|
unset SECURITYCODE
|
|
}
|
|
|
|
function askForFunnyUserCreds() {
|
|
# clear
|
|
# echo "Press Enter to start."
|
|
# read -s
|
|
|
|
askStr 12 "$(eval_gettext "Login")" "$(eval_gettext "Username:")" ""
|
|
username=$(cat $TMP)
|
|
askPw 12 "$(eval_gettext "Login")" "$(eval_gettext "Password:")" ""
|
|
password=$(cat $TMP)
|
|
|
|
if [ -f ".pw/$username" ]; then
|
|
if [ "$password" != "$(cat .pw/$username)" ]; then
|
|
clear
|
|
echo "$(eval_gettext "Wrong credentials.")"
|
|
sleep 3
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "$(eval_gettext "Wrong credentials.")"
|
|
sleep 3
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
|
|
function setLanguage() {
|
|
read -n 1 -p "Language: Deutsch? (y/N): " chr
|
|
if [[ "$chr" == "y" || "$chr" == "Y" ]]; then
|
|
export LC_ALL=de_DE
|
|
fi
|
|
}
|
|
|
|
|
|
### START
|
|
|
|
checkDependencies
|
|
|
|
setLanguage
|
|
|
|
askForFunnyUserCreds
|
|
|
|
while [ true ]; do
|
|
|
|
dialog --backtitle "$BT" \
|
|
--menu "$(eval_gettext "Select ID type:")" 16 40 3 \
|
|
1 "$(eval_gettext "Stapled diplomatic passport")" \
|
|
2 "$(eval_gettext "Stapled glossy paper diplomatic passport")" \
|
|
3 "$(eval_gettext "Junghackerpass")" \
|
|
4 "$(eval_gettext "Bound diplomatic passport")" \
|
|
5 "$(eval_gettext "Attendance paper")" \
|
|
9 "$(eval_gettext "Logout")" 2> $TMP
|
|
|
|
if [ $? -eq 9 ]; then
|
|
break
|
|
fi
|
|
|
|
TYPE=$(cat $TMP)
|
|
|
|
|
|
case $TYPE in
|
|
1) menuFor stapleddipl
|
|
;;
|
|
2) menuFor stapled_glossy_dipl
|
|
;;
|
|
3) menuFor jhp
|
|
;;
|
|
4) menuFor bounddipl
|
|
;;
|
|
5) attendance
|
|
if [ $? -eq 0 ]; then
|
|
printAttendanceLetter
|
|
fi
|
|
;;
|
|
9) break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
rm $TMP
|
|
clear
|