commit d7c7c76e07aee7b3e2010111c69d34fc309806df Author: Bandie Date: Mon Jun 1 17:02:43 2020 +0200 Support for Junghackerpass diff --git a/README.md b/README.md new file mode 100644 index 0000000..620665c --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Galactic Registration Office +Fill out your hacker passport using a professional dot matrix printer. + +## Supported Passports +The following passports are supported atm: + - CmS Junghackerpass diff --git a/include/nixdorf b/include/nixdorf new file mode 100755 index 0000000..a7dea34 --- /dev/null +++ b/include/nixdorf @@ -0,0 +1,43 @@ +#!/bin/bash +DEVICE=/dev/ttyUSB0 +function init() { + stty -F $DEVICE 1:0:80000dbd:0:3:1c:7f:15:4:5:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0 + + # \x1b\x47 - Double Strike + # \x1b\x78\x01 - Standard Letter Mode + # \x1b\x52\x02 - German + printf "\x1b\x47\x1b\x78\x01\x1b\x52\x02" >> "$DEVICE" + +} + +function printFile() { + # Replace charset stuff + sed -i 's/╔/\xc9/g;s/═/\xcd/g;s/╗/\xbb/g;s/║/\xba/g;s/╚/\xc8/g;s/╝/\xbc/g;s/§/\x40/g;s/Ä/\x5b/g;s/Ö/\x5c/g;s/Ü/\x5d/g;s/ä/\x7b/g;s/ö/\x7c/g;s/ü/\x7d/g;s/ß/\x7e/g' "$1" + + # Eject + printf "\x0c" >> "$1" + + # Print + cat $1 >> "$DEVICE" +} + +function resetLetters() { + printf "\x12\x14\x1b\x35" >> "$1" +} + +function bigLetters() { + resetLetters "$1" + printf "\x0e" >> "$1" +} + +function smallLetters() { + resetLetters "$1" + printf "\x0f" >> "$1" +} + +function italicLetters() { + printf "\x1b\x34" >> "$1" +} + +init +resetLetters $DEVICE diff --git a/jhp/JunghackerPass b/jhp/JunghackerPass new file mode 100755 index 0000000..976de61 --- /dev/null +++ b/jhp/JunghackerPass @@ -0,0 +1,59 @@ +#!/bin/bash +FILE=/tmp/$RANDOM +TOP=7 +LEFT=2 +MAXLENGTH=25 + +GIVENNAME=$1 +SURNAME=$2 +HOME=$3 + +function makeNewline() { + for((i=0; i<$1; i++)); do + printf "\n" >> $FILE + done +} + +function makeLeft() { + for((i=0; i<$LEFT; i++)); do + printf " " >> $FILE + done +} + + +if [ ${#GIVENNAME} -gt $MAXLENGTH ] || [ ${#SURNAME} -gt $MAXLENGTH ] || [ ${#HOME} -gt $MAXLENGTH ]; then + echo "MAXLENGTH EXCEEDED." + exit 1 +fi + + +source ../include/nixdorf +init + +makeNewline $TOP +makeLeft +printf "$GIVENNAME" >> $FILE + +makeNewline 4 +makeLeft +printf "$SURNAME" >> $FILE + +makeNewline 3 +makeLeft +printf "$HOME" >> $FILE + +makeNewline 3 +makeLeft + +if [ -n "$EVENT" ]; then + printf "$EVENT, $(date -I)" >> $FILE +else + printf "$(date -I)" >> $FILE +fi + +makeNewline 1 +makeLeft +printf "Galactic Registr. Office" >> $FILE + +printFile $FILE +rm $FILE diff --git a/jhp/gpgkey b/jhp/gpgkey new file mode 100755 index 0000000..31f8a5b --- /dev/null +++ b/jhp/gpgkey @@ -0,0 +1,146 @@ +#!/bin/bash +FILE=/tmp/$RANDOM +TOP=0 +LEFT=3 + +# Additional heading space +HEADINGNEXTPAGE=28 +HEADINGLEFT=1 +HEADINGRIGHT=15 + +# GPG Space +NEXTPAGE=48 +NEXTFIELDBOTTOM=7 +NEXTFIELDRIGHT=25 +MAXLENGTH=22 + +if [ $# -eq 0 ]; then + echo -e "$0: Syntax:\n$0 FIELD GPG FINGERPRINT WITH SPACES\n\nExample:\n$0 7 1234 5678 1234 1234 1234 1234 1234 1234 1234 ABCD\n\n\nFields: + ================== + | 0 | 1 || 6 | 7 | + |---|---||---|---| + | 2 | 3 || 8 | 9 | + |---|---||---|---| + | 4 | 5 || 10| 11| + ================== + " + exit 1 +fi + +PAGE=$(($1 / 6)) +FIELD=$(($1 % 6)) + +shift 1 + + +echo "PAGE: $PAGE, FIELD: $FIELD" + + + +function moveDown() { + for((i=0; i<$(($FIELD / 2)); i++)); do + for((j=0; j<$NEXTFIELDBOTTOM; j++)); do + printf "\n" >> $FILE + done + done +} + +function makeNewline() { + for((i=0; i<$1; i++)); do + printf "\n" >> $FILE + done +} + +function makeLeft() { + for((i=0; i<$1; i++)); do + printf " " >> $FILE + done +} + + +function heading() { + moveDown + + + if [ $(($FIELD % 2)) -eq 0 ]; then + SPACE=$HEADINGLEFT + else + SPACE=$HEADINGRIGHT + fi + + if [ $PAGE -eq 1 ]; then + makeLeft $HEADINGNEXTPAGE + fi + + makeLeft $LEFT + makeLeft $SPACE + + bigLetters $FILE + printf "GPG" >> $FILE + resetLetters $FILE + printf "\n" >> $FILE +} + +function insertFP() { + if [ $(($FIELD % 2 )) -eq 0 ]; then + SPACE=0 + else + SPACE=$NEXTFIELDRIGHT + fi + + smallLetters $FILE + if [ $PAGE -eq 1 ]; then + makeLeft $NEXTPAGE + fi + makeLeft $LEFT + makeLeft $(($SPACE + 2)) + printf "$1 $2 $3 $4" >> $FILE + resetLetters $FILE + printf "\n" >> $FILE + shift 4 + + smallLetters $FILE + if [ $PAGE -eq 1 ]; then + makeLeft $NEXTPAGE + fi + makeLeft $LEFT + makeLeft $(($SPACE + 2)) + printf "$1 $2 $3 $4" >> $FILE + resetLetters $FILE + printf "\n" >> $FILE + shift 4 + + smallLetters $FILE + if [ $PAGE -eq 1 ]; then + makeLeft $NEXTPAGE + fi + makeLeft $LEFT + makeLeft $(($SPACE + 2)) + printf "$1 $2" >> $FILE + resetLetters $FILE + printf "\n" >> $FILE + shift 2 + + smallLetters $FILE + if [ $PAGE -eq 1 ]; then + makeLeft $NEXTPAGE + fi + makeLeft $LEFT + makeLeft $(($SPACE + 2)) + + if [ -n "$EVENT" ]; then + printf "$EVENT, $(date -I)" >> $FILE + else + printf "$(date -I)" >> $FILE + fi +} + +source ../include/nixdorf +init + +makeNewline $TOP +heading +insertFP $@ + +printFile $FILE +rm $FILE diff --git a/jhp/gro b/jhp/gro new file mode 100755 index 0000000..1bdd6e3 --- /dev/null +++ b/jhp/gro @@ -0,0 +1,137 @@ +#!/bin/bash +FILE=/tmp/$RANDOM +TOP=0 +LEFT=3 + +# Additional heading space +HEADINGNEXTPAGE=16 +HEADINGLEFT=0 +HEADINGRIGHT=8 + +# GPG Space +NEXTPAGE=30 +NEXTPAGESMALL=48 +NEXTFIELDBOTTOM=7 +NEXTFIELDRIGHT=14 +NEXTFIELDRIGHTSMALL=25 +MAXLENGTH=22 + +if [ $# -eq 0 ]; then + echo -e "$0: Syntax:\n$0 FIELD\n\nExample:\n$0 7\n\n\nFields: + ================== + | 0 | 1 || 6 | 7 | + |---|---||---|---| + | 2 | 3 || 8 | 9 | + |---|---||---|---| + | 4 | 5 || 10| 11| + ================== + " + exit 1 +fi + +PAGE=$(($1 / 6)) +FIELD=$(($1 % 6)) + +shift 1 + + +echo "PAGE: $PAGE, FIELD: $FIELD" + + + +function moveDown() { + for((i=0; i<$(($FIELD / 2)); i++)); do + for((j=0; j<$NEXTFIELDBOTTOM; j++)); do + printf "\n" >> $FILE + done + done +} + +function makeNewline() { + for((i=0; i<$1; i++)); do + printf "\n" >> $FILE + done +} + +function makeLeft() { + for((i=0; i<$1; i++)); do + printf " " >> $FILE + done +} + + +function heading() { + moveDown + + + if [ $(($FIELD % 2)) -eq 0 ]; then + HSPACE=$HEADINGLEFT + SPACE=0 + else + HSPACE=$HEADINGRIGHT + SPACE=$NEXTFIELDRIGHT + fi + + + if [ $PAGE -eq 1 ]; then + makeLeft $NEXTPAGE + fi + makeLeft 1 + makeLeft $SPACE + italicLetters $FILE + printf "GALACTIC\n" >> $FILE + + if [ $PAGE -eq 1 ]; then + makeLeft $NEXTPAGE + fi + makeLeft 1 + makeLeft $SPACE + printf "REGISTRATION\n" >> $FILE + bigLetters $FILE + + if [ $PAGE -eq 1 ]; then + makeLeft $HEADINGNEXTPAGE + if [ $(($FIELD % 2)) -eq 1 ]; then + makeLeft $(($HSPACE - 1)) + fi + else + if [ $(($FIELD % 2)) -eq 0 ]; then + makeLeft 1 + fi + makeLeft $HSPACE + fi + printf "OFFICE\n" >> $FILE + resetLetters $FILE + +} + +function insertDate() { + if [ $(($FIELD % 2 )) -eq 0 ]; then + SPACE=0 + else + SPACE=$NEXTFIELDRIGHTSMALL + fi + + smallLetters $FILE + if [ $PAGE -eq 1 ]; then + makeLeft $NEXTPAGESMALL + fi + makeLeft $LEFT + makeLeft $(($SPACE + 2)) + if [ -n "$EVENT" ]; then + printf "$EVENT, $(date -I)" >> $FILE + else + printf "$(date -I)" >> $FILE + fi + +} + +source ../include/nixdorf +init + +makeNewline $TOP +heading +insertDate + +printFile $FILE +rm $FILE diff --git a/jhp/msg5 b/jhp/msg5 new file mode 100755 index 0000000..a3a1bf3 --- /dev/null +++ b/jhp/msg5 @@ -0,0 +1,30 @@ +#!/bin/bash +FILE=/tmp/$RANDOM + +source ../include/nixdorf +init + +echo "1 +2 +3 +4 +5 +6 +7 +8 +9 +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +0 +1" > $FILE + +printFile $FILE +rm $FILE diff --git a/jhp/test b/jhp/test new file mode 100644 index 0000000..5626804 --- /dev/null +++ b/jhp/test @@ -0,0 +1 @@ +./JunghackerPass "Foobert" "van Barbert" "Erde / Earth" "37C3, $(date -I)" diff --git a/start b/start new file mode 100755 index 0000000..212aacc --- /dev/null +++ b/start @@ -0,0 +1,243 @@ +#!/bin/bash +export EVENT=37C3 + +TMP=/tmp/$RANDOM +BT="Galactic Registration Office - v0.1" + +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 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 $? +} + +function jhpAskForField() { + text="Please choose a free field on the passport.\n + ------------------\n + | Archievements |\n + ==================\n + | 0 | 1 || 6 | 7 |\n + |---|---||---|---|\n + | 2 | 3 || 8 | 9 |\n + |---|---||---|---|\n + | 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 + 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 + ./JunghackerPass "$FNAME" "$SNAME" "$PLANET" + cd .. + return 0 +} + +function jhpGROStamp() { + jhpAskForField + if [ $? -eq 0 ]; then + diaBox "Insert Passport" "Please insert passport (Archivements) into the printer." + cd jhp + ./gro $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 "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 "GPG" \ + 3 "GRO Stamp" \ + 9 "Back" 2> $TMP + + choice=$(cat $TMP) + + case $choice in + 1) jhpReg + if [ $? -eq 0 ]; then + jhpPrintReg + if [ -n "$FP" ]; then + jhpPrintGPG + fi + fi + ;; + 2) jhpGPG + if [ $? -eq 0 ]; then + jhpPrintGPG + fi + ;; + 3) jhpGROStamp + + esac + unset FNAME + unset SNAME + unset PLANET + unset FP + unset FIELD +} + +while [ true ]; do + + dialog --backtitle "$BT" \ + --menu "Select ID type:" 10 40 3 \ + 1 "Junghackerpass" \ + 2 "Usual" 2> $TMP + + if [ $? -eq 1 ]; then + break + fi + + TYPE=$(cat $TMP) + + + case $TYPE in + 1) jhpmenu + ;; + 2) exit 0 + ;; + esac +done + +rm $TMP +clear diff --git a/test/msg b/test/msg new file mode 100755 index 0000000..3f75bf8 --- /dev/null +++ b/test/msg @@ -0,0 +1,34 @@ +#!/bin/bash +./wincor + +TEMP=/tmp/$RANDOM + +printf "\t\t\t\t╔═════════════════════╗\n" | sed 's/╔/\xc9/g;s/═/\xcd/g;s/╗/\xbb/g;s/║/\xba/g;s/╚/\xc8/g;s/╝/\xbc/g' >> $TEMP +printf "\t\t\t\t║ SECRET DOCUMENT ║\n" | sed 's/╔/\xc9/g;s/═/\xcd/g;s/╗/\xbb/g;s/║/\xba/g;s/╚/\xc8/g;s/╝/\xbc/g' >> $TEMP +printf "\t\t\t\t╚═════════════════════╝\n" | sed 's/╔/\xc9/g;s/═/\xcd/g;s/╗/\xbb/g;s/║/\xba/g;s/╚/\xc8/g;s/╝/\xbc/g' >> $TEMP +printf " + + +\tThe following information you see below are classified as \n\t\t\t\t\xeTOP SECRET\xf.\n\n\n" >> $TEMP + +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP +printf "\t%s\n" "$(cat /dev/urandom | tr -dc 'A-Za-z0-9 ' | head -c115)" >> $TEMP + + + +printf "\xc" >> $TEMP + + +cat $TEMP >> /dev/ttyUSB0 +rm $TEMP diff --git a/test/msg2 b/test/msg2 new file mode 100755 index 0000000..a63620e --- /dev/null +++ b/test/msg2 @@ -0,0 +1,11 @@ +#!/bin/bash +./wincor +#printf "\t12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n" >> /dev/ttyUSB0 +#printf "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" >> /dev/ttyUSB0 +printf "\n\n\n\n\n\t12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n" >> /dev/ttyUSB0 +printf "\t x x x x x x x x x x x x x x\n" >> /dev/ttyUSB0 +printf "\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt\tt" >> /dev/ttyUSB0 + + + +printf "\xc" >> /dev/ttyUSB0 diff --git a/test/msg3 b/test/msg3 new file mode 100755 index 0000000..e22566b --- /dev/null +++ b/test/msg3 @@ -0,0 +1,20 @@ +#!/bin/bash +./wincor + +TEMP=/tmp/$RANDOM + +printf " +\x1b\x78\x01 +\x1b\x52\x02 +\x0fx\x1b\x53\x01asdf\x1b\x54 = x\x1b\x53\x00asdf\x1b\x54\x12 +\x5b\x5c\x5d\x7b\x7c\x7d\x7e +" >> $TEMP + + + + +printf "\xc" >> $TEMP + + +cat $TEMP >> /dev/ttyUSB0 +rm $TEMP diff --git a/test/msg4 b/test/msg4 new file mode 100755 index 0000000..c5e91eb --- /dev/null +++ b/test/msg4 @@ -0,0 +1,12 @@ +#!/bin/bash +source ./wincor + +TEMP=/tmp/$RANDOM + +init +printf "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" >> $TEMP +#bigLetters $TEMP +#printf "123456789012345678901234567890123456789012345678901234567890" >> $TEMP +printf " 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" >> $TEMP +printFile $TEMP +rm $TEMP