more secure password generation

This commit is contained in:
Léo Haf 2025-03-27 12:00:35 +01:00
parent 2addae292a
commit c3c2ecb5af
Signed by: Retropex
GPG Key ID: F5073C4F4882FFFC

View File

@ -98,9 +98,14 @@ if [ "$1" = "menu" ]; then
# set the title for the dialog # set the title for the dialog
dialogTitle=" ${APPID} " dialogTitle=" ${APPID} "
password=$(jq -r '.api.admin_password' /mnt/hdd/app-data/datum/datum_config.json)
# basic info text - for an web app how to call with http & self-signed https # basic info text - for an web app how to call with http & self-signed https
dialogText="Open in your local web browser: dialogText="Open in your local web browser:
http://${localIP}:${PORT_CLEAR}\n http://${localIP}:${PORT_CLEAR}\n
Datum user=admin
Datum admin password=$password
" "
# use whiptail to show SSH dialog & exit # use whiptail to show SSH dialog & exit
@ -170,7 +175,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
# make sure needed debian packages are installed # make sure needed debian packages are installed
# 'fbi' is here just an example - change to what you need or delete # 'fbi' is here just an example - change to what you need or delete
echo "# install from source code" echo "# install from source code"
sudo apt install -y cmake pkgconf libcurl4-openssl-dev libjansson-dev libmicrohttpd-dev libsodium-dev psmisc sudo apt install -y cmake pkgconf libcurl4-openssl-dev libjansson-dev libmicrohttpd-dev libsodium-dev psmisc pwgen
# download source code and verify # download source code and verify
# BACKGROUND is that now you download the code from github, reset to a given version tag/commit, # BACKGROUND is that now you download the code from github, reset to a given version tag/commit,
@ -206,6 +211,8 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
sudo -u ${APPID} touch /mnt/hdd/app-data/${APPID}/datum_config.json sudo -u ${APPID} touch /mnt/hdd/app-data/${APPID}/datum_config.json
fi fi
PASS=$(pwgen -N 1 -n 20)
sudo -u ${APPID} bash -c 'echo "{ sudo -u ${APPID} bash -c 'echo "{
\"bitcoind\": { \"bitcoind\": {
\"rpcuser\": \"auto-config\", \"rpcuser\": \"auto-config\",
@ -215,7 +222,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
\"api\": { \"api\": {
\"listen_port\": 21000, \"listen_port\": 21000,
\"modify_conf\": true, \"modify_conf\": true,
\"admin_password\": \"raspiblitz\" \"admin_password\": \"$1\"
}, },
\"mining\": { \"mining\": {
\"pool_address\": \"\", \"pool_address\": \"\",
@ -234,7 +241,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
\"pooled_mining_only\": true \"pooled_mining_only\": true
} }
} }
" > /mnt/hdd/app-data/datum/datum_config.json' " > /mnt/hdd/app-data/datum/datum_config.json' _ "$PASS"
# Configure bitcoind # Configure bitcoind
@ -347,8 +354,6 @@ if [ "$1" = "prestart" ]; then
jq --arg RPCPASS "$RPCPASS" '.bitcoind.rpcpassword = $RPCPASS' /mnt/hdd/app-data/${APPID}/datum_config.json > /mnt/hdd/app-data/${APPID}/datum_config.json.tmp && mv /mnt/hdd/app-data/${APPID}/datum_config.json.tmp /mnt/hdd/app-data/${APPID}/datum_config.json jq --arg RPCPASS "$RPCPASS" '.bitcoind.rpcpassword = $RPCPASS' /mnt/hdd/app-data/${APPID}/datum_config.json > /mnt/hdd/app-data/${APPID}/datum_config.json.tmp && mv /mnt/hdd/app-data/${APPID}/datum_config.json.tmp /mnt/hdd/app-data/${APPID}/datum_config.json
jq --arg RPCUSER "$RPCUSER" '.bitcoind.rpcuser = $RPCUSER' /mnt/hdd/app-data/${APPID}/datum_config.json > /mnt/hdd/app-data/${APPID}/datum_config.json.tmp && mv /mnt/hdd/app-data/${APPID}/datum_config.json.tmp /mnt/hdd/app-data/${APPID}/datum_config.json jq --arg RPCUSER "$RPCUSER" '.bitcoind.rpcuser = $RPCUSER' /mnt/hdd/app-data/${APPID}/datum_config.json > /mnt/hdd/app-data/${APPID}/datum_config.json.tmp && mv /mnt/hdd/app-data/${APPID}/datum_config.json.tmp /mnt/hdd/app-data/${APPID}/datum_config.json
jq --arg RPCPASS "$RPCPASS" '.api.admin_password = $RPCPASS' /mnt/hdd/app-data/${APPID}/datum_config.json > /mnt/hdd/app-data/${APPID}/datum_config.json.tmp && mv /mnt/hdd/app-data/${APPID}/datum_config.json.tmp /mnt/hdd/app-data/${APPID}/datum_config.json
echo "## PRESTART CONFIG DONE for ${APPID}" echo "## PRESTART CONFIG DONE for ${APPID}"
exit 0 exit 0
fi fi