MACHINE POWER

This commit is contained in:
Geoffrey Frogeye 2017-10-07 13:20:10 +02:00
parent 15926280eb
commit 2075643ffe

View file

@ -67,9 +67,6 @@ function _machines-apiSigned {
_machines-api "$@" --certificate=$MACHINES_CONFIG/machines.crt --private-key=$MACHINES_CONFIG/machines.key _machines-api "$@" --certificate=$MACHINES_CONFIG/machines.crt --private-key=$MACHINES_CONFIG/machines.key
} }
function _machines-getQR {
_machines-apiSigned totp | qrencode -o - | feh -
}
# APPLICATION KEYS & CERTIFICATE # APPLICATION KEYS & CERTIFICATE
@ -142,16 +139,16 @@ function _machines-getAkey { # network
} }
function _machines-updateAkey { function _machines-updateAkey {
KEY_FILE=$(mktemp) MYKEY_FILE=$(mktemp)
network=$(cat $MACHINES_CONFIG/this | grep '^network=' | cut -d '=' -f 2) network=$(cat $MACHINES_CONFIG/this | grep '^network=' | cut -d '=' -f 2)
_machines-getAkey $network > $KEY_FILE _machines-getAkey $network > "$MYKEY_FILE"
if [ $? == 0 ]; then if [ $? == 0 ]; then
yes | mv $KEY_FILE $MACHINES_HOME/.ssh/authorized_keys &> /dev/null yes | mv $MYKEY_FILE $MACHINES_HOME/.ssh/authorized_keys &> /dev/null
return 0 return 0
else else
cat $KEY_FILE cat $MYKEY_FILE
echo "[ERROR] Authorized keys are not properly signed" echo "[ERROR] Authorized keys are not properly signed"
rm $KEY_FILE rm $MYKEY_FILE
exit 1 exit 1
fi fi
} }
@ -171,12 +168,12 @@ function _machines-addElement { # element elementType default
$EDITOR $FILE $EDITOR $FILE
data=$(_machines-postFile $FILE) data=$(_machines-postFile $FILE)
rm $FILE &> /dev/null rm $FILE &> /dev/null
machines-apiSigned $2 --post-data "name=$1$data" _machines-apiSigned $2 --post-data "name=$1$data"
} }
function _machines-editElement { # element elementType function _machines-editElement { # element elementType
FILE=$(mktemp) FILE=$(mktemp)
_machines-apiSigned $2/$1 _machines-apiSigned $2/$1 > $FILE
$EDITOR $FILE $EDITOR $FILE
data=$(_machines-postFile $FILE) data=$(_machines-postFile $FILE)
rm $FILE &> /dev/null rm $FILE &> /dev/null
@ -238,7 +235,6 @@ function machines_machine_add { # machine
machines_machine_add_help machines_machine_add_help
exit 1 exit 1
fi fi
_machines-addElement $1 machine "allowed[]=\nsecure=false"
_machines-addElement $1 machine "host[]=\nnetwork=\nuserkey=\nhostkey=\nuser=" _machines-addElement $1 machine "host[]=\nnetwork=\nuserkey=\nhostkey=\nuser="
} }
@ -435,6 +431,12 @@ function machines_update {
_machines-updateAkey _machines-updateAkey
} }
function machines_totp {
url=$(_machines-apiSigned totp)
echo "URL : $url"
echo "$url" | qrencode -o - | feh -
}
function machines_help { function machines_help {
command="$1" command="$1"
@ -457,6 +459,8 @@ function machines_help {
echo " network|net|n Modify networks" echo " network|net|n Modify networks"
echo " update-all Update all machines available via SSH" echo " update-all Update all machines available via SSH"
echo " regen-keys Regenerate system keys" echo " regen-keys Regenerate system keys"
echo " sign Sign recent transactions for propagation"
echo " totp Get TOTP generating QR code / URL"
return 0 return 0
} }