From 6619193dc66956631c29f8b78b26dfcf82c4757c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 29 Apr 2024 07:18:35 +0300 Subject: [PATCH] Source Update --- src/functions/login.sh | 159 +++++++++++++++++++++++++---------------- wx | 159 +++++++++++++++++++++++++---------------- 2 files changed, 194 insertions(+), 124 deletions(-) diff --git a/src/functions/login.sh b/src/functions/login.sh index ae9a80f..913d9c1 100644 --- a/src/functions/login.sh +++ b/src/functions/login.sh @@ -91,43 +91,104 @@ wx-login(){ VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health) if [[ $VAULT_STATUS -eq 200 ]] then - IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) - if [[ $IDM_STATUS -eq 301 ]] + if [[ -f "$HOME/.config/warengroup/login.json" ]] + then + TOKEN="$(cat $HOME/.config/warengroup/login.json | jq -r .$ORG)" + fi + + VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token') + if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]] then echo -n $wxBold echo -n $ORG echo $wxNormal - if [[ -z $USER || $USER == "root" || $USER == "local" ]] - then - echo -n "Username: " - echo -n $wxItalic - read USERNAME - echo -n $wxNormal - else - echo -n "Username: " - echo -n $wxItalic - echo -n $USER - echo $wxNormal - USERNAME=$USER - fi - - echo -n "Password: " + echo -n "Username: " echo -n $wxItalic - read -s PASSWORD - echo -n "****************" + echo -n $(curl https://$VAULT_DOMAIN/v1/auth/token/lookup-self -X GET --header "X-Vault-Token: $VAULT_LOGIN" -s | jq -r '.data.meta.username') echo $wxNormal - if [[ -z $USERNAME || -z $PASSWORD ]] - then - echo -n "Status: " - echo -n $wxItalic - echo -n "Username & Password Required" - echo -n $wxNormal + config[${ORG}]=$VAULT_LOGIN + echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json - wx-stop + wx-start + else + IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) + if [[ $IDM_STATUS -eq 301 ]] + then + echo -n $wxBold + echo -n $ORG + echo $wxNormal + + if [[ -z $USER || $USER == "root" || $USER == "local" ]] + then + echo -n "Username: " + echo -n $wxItalic + read USERNAME + echo -n $wxNormal + else + echo -n "Username: " + echo -n $wxItalic + echo -n $USER + echo $wxNormal + USERNAME=$USER + fi + + echo -n "Password: " + echo -n $wxItalic + read -s PASSWORD + echo -n "****************" + echo $wxNormal + + if [[ -z $USERNAME || -z $PASSWORD ]] + then + echo -n "Status: " + echo -n $wxItalic + echo -n "Username & Password Required" + echo -n $wxNormal + + wx-stop + else + VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/ldap/login/$USERNAME -X POST -d '{ "password": "'$PASSWORD'" }' -s | jq -r '.auth.client_token') + if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]] + then + echo -n "Status: " + echo -n $wxItalic + echo -n "Login Failed" + echo -n $wxNormal + + wx-stop + fi + fi + + config[${ORG}]=$VAULT_LOGIN + + mkdir -p $HOME/.config/warengroup &> /dev/null + touch $HOME/.config/warengroup/login.json &> /dev/null + + echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json + + wx-start else - VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/ldap/login/$USERNAME -X POST -d '{ "password": "'$PASSWORD'" }' -s | jq -r '.auth.client_token') + echo -n $wxBold + echo -n $ORG + echo $wxNormal + + echo -n "Token: " + read -s TOKEN + echo "****************" + + if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]] + then + echo -n "Status: " + echo -n $wxItalic + echo -n "Vault Token Required" + echo -n $wxNormal + + wx-stop + fi + + VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token') if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]] then echo -n "Status: " @@ -137,42 +198,16 @@ wx-login(){ wx-stop fi + + config[${ORG}]=$VAULT_LOGIN + + mkdir -p $HOME/.config/warengroup &> /dev/null + touch $HOME/.config/warengroup/login.json &> /dev/null + + echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json + + wx-start fi - - config[${ORG}]=$VAULT_LOGIN - wx-start - else - echo -n $wxBold - echo -n $ORG - echo $wxNormal - - echo -n "Token: " - read -s TOKEN - echo "****************" - - if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]] - then - echo -n "Status: " - echo -n $wxItalic - echo -n "Vault Token Required" - echo -n $wxNormal - - wx-stop - fi - - VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token') - if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]] - then - echo -n "Status: " - echo -n $wxItalic - echo -n "Login Failed" - echo -n $wxNormal - - wx-stop - fi - - config[${ORG}]=$VAULT_LOGIN - wx-start fi else echo -n $wxBold diff --git a/wx b/wx index 8c20a2e..7fe0068 100755 --- a/wx +++ b/wx @@ -113,43 +113,104 @@ wx-login(){ VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health) if [[ $VAULT_STATUS -eq 200 ]] then - IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) - if [[ $IDM_STATUS -eq 301 ]] + if [[ -f "$HOME/.config/warengroup/login.json" ]] + then + TOKEN="$(cat $HOME/.config/warengroup/login.json | jq -r .$ORG)" + fi + + VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token') + if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]] then echo -n $wxBold echo -n $ORG echo $wxNormal - if [[ -z $USER || $USER == "root" || $USER == "local" ]] - then - echo -n "Username: " - echo -n $wxItalic - read USERNAME - echo -n $wxNormal - else - echo -n "Username: " - echo -n $wxItalic - echo -n $USER - echo $wxNormal - USERNAME=$USER - fi - - echo -n "Password: " + echo -n "Username: " echo -n $wxItalic - read -s PASSWORD - echo -n "****************" + echo -n $(curl https://$VAULT_DOMAIN/v1/auth/token/lookup-self -X GET --header "X-Vault-Token: $VAULT_LOGIN" -s | jq -r '.data.meta.username') echo $wxNormal - if [[ -z $USERNAME || -z $PASSWORD ]] - then - echo -n "Status: " - echo -n $wxItalic - echo -n "Username & Password Required" - echo -n $wxNormal + config[${ORG}]=$VAULT_LOGIN + echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json - wx-stop + wx-start + else + IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) + if [[ $IDM_STATUS -eq 301 ]] + then + echo -n $wxBold + echo -n $ORG + echo $wxNormal + + if [[ -z $USER || $USER == "root" || $USER == "local" ]] + then + echo -n "Username: " + echo -n $wxItalic + read USERNAME + echo -n $wxNormal + else + echo -n "Username: " + echo -n $wxItalic + echo -n $USER + echo $wxNormal + USERNAME=$USER + fi + + echo -n "Password: " + echo -n $wxItalic + read -s PASSWORD + echo -n "****************" + echo $wxNormal + + if [[ -z $USERNAME || -z $PASSWORD ]] + then + echo -n "Status: " + echo -n $wxItalic + echo -n "Username & Password Required" + echo -n $wxNormal + + wx-stop + else + VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/ldap/login/$USERNAME -X POST -d '{ "password": "'$PASSWORD'" }' -s | jq -r '.auth.client_token') + if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]] + then + echo -n "Status: " + echo -n $wxItalic + echo -n "Login Failed" + echo -n $wxNormal + + wx-stop + fi + fi + + config[${ORG}]=$VAULT_LOGIN + + mkdir -p $HOME/.config/warengroup &> /dev/null + touch $HOME/.config/warengroup/login.json &> /dev/null + + echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json + + wx-start else - VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/ldap/login/$USERNAME -X POST -d '{ "password": "'$PASSWORD'" }' -s | jq -r '.auth.client_token') + echo -n $wxBold + echo -n $ORG + echo $wxNormal + + echo -n "Token: " + read -s TOKEN + echo "****************" + + if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]] + then + echo -n "Status: " + echo -n $wxItalic + echo -n "Vault Token Required" + echo -n $wxNormal + + wx-stop + fi + + VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token') if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]] then echo -n "Status: " @@ -159,42 +220,16 @@ wx-login(){ wx-stop fi + + config[${ORG}]=$VAULT_LOGIN + + mkdir -p $HOME/.config/warengroup &> /dev/null + touch $HOME/.config/warengroup/login.json &> /dev/null + + echo '{ "'$ORG'": "'$VAULT_LOGIN'" }' | jq > $HOME/.config/warengroup/login.json + + wx-start fi - - config[${ORG}]=$VAULT_LOGIN - wx-start - else - echo -n $wxBold - echo -n $ORG - echo $wxNormal - - echo -n "Token: " - read -s TOKEN - echo "****************" - - if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]] - then - echo -n "Status: " - echo -n $wxItalic - echo -n "Vault Token Required" - echo -n $wxNormal - - wx-stop - fi - - VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token') - if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]] - then - echo -n "Status: " - echo -n $wxItalic - echo -n "Login Failed" - echo -n $wxNormal - - wx-stop - fi - - config[${ORG}]=$VAULT_LOGIN - wx-start fi else echo -n $wxBold