tuer3/webinterface/blaukraut/genpw.sh
2019-10-05 14:38:33 +02:00

67 lines
2.1 KiB
Bash
Executable file

#!/bin/bash
# tuer3 passphrase generation script
# Copyright (C) 2017-2019 Hackspace Jena e. V.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
QUESTTEXT='Wie ist dein Name/Nick?'
HELPTEXT="Nickname"
DLG=`which zenity`
if [[ $? -ne 0 ]] ; then
if [[ "$1" == "" ]] ; then
echo "Passphrasengenerierung abgebrochen. Bitte einen Nutzernamen als Kommandoparameter angeben."
exit 1
else
USER=$1
DIALOG=cmd
fi
else
if [[ "$1" == "" ]] ; then
USER=`zenity --entry --text="$QUESTTEXT" --entry-text=$HELPTEXT`
else
USER=`zenity --entry --text="$QUESTTEXT" --entry-text="$1"`
fi
if [[ $? -ne 0 || "$USER" == "$HELPTEXT" ]] ; then
echo "Passphrasengenerierung abgebrochen."
exit 1
fi
DIALOG=zenity
fi
STAMP=`date +%Y-%m-%dT%T`
FILE="$PWD/$USER.$STAMP.keyhash"
PASSPHRASE=`tr -dc _a-z0-9 </dev/urandom | head -c 31`
PPHASH=`echo "$PASSPHRASE" | sha512sum | tr --delete " -"`
echo "$USER;$STAMP;$PPHASH">>$FILE
# Ausgabe
TEXT="Hallo $USER,\ndeine neue Passphrase ist:\n\n\t$PASSPHRASE\n
Hinweis:\tDie Passphrase erscheint nur in diesem Dialog und im Terminal\n\t\tund wird sonst nirgendwo gespeichert. Sichere sie dir bitte!\n\n
Es wurde eine Datei mit deinen Schlüsseldaten generiert. Ihr Name lautet:
\n\t$FILE\n\nÜbergib sie bitte vertrauensvoll an einen Schließsystemverantwortlichen.\n"
case "$DIALOG" in
zenity)
zenity --info --text="$TEXT" --window-icon=warning
;;
*)
;;
esac
echo -e "$TEXT"