Source Update

This commit is contained in:
Christer Warén 2024-04-29 07:18:35 +03:00
parent 963770b974
commit 6619193dc6
2 changed files with 194 additions and 124 deletions

View File

@ -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

159
wx
View File

@ -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