Compare commits
56
Commits
4e9ae9109e
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d906696aa | ||
|
|
869a22cb73 | ||
|
|
21db6ac4e9 | ||
|
|
7dd2a07186 | ||
|
|
a37fce53e8 | ||
|
|
a9539ffb9d | ||
|
|
c479044caf | ||
|
|
c9008a981b | ||
|
|
a9e5b2c336 | ||
|
|
cf9bc49c27 | ||
|
|
d91a7c21c0 | ||
|
|
7898e55f30 | ||
|
|
3fafb66781 | ||
|
|
54409a4197 | ||
|
|
77a54ef1f6 | ||
|
|
fbaa5780d9 | ||
|
|
5a666e6f60 | ||
|
|
1e4f9ed508 | ||
|
|
592cd95f42 | ||
|
|
bce9c3c4d6 | ||
|
|
f91e69ee55 | ||
|
|
32e6b83611 | ||
|
|
2742d39818 | ||
|
|
fe5abf5419 | ||
|
|
43192faed1 | ||
|
|
a276adb6d2 | ||
|
|
b5186f0380 | ||
|
|
86bb04d2ea | ||
|
|
67fabf0ce1 | ||
|
|
fe56c50bfb | ||
|
|
eb14aa46ff | ||
|
|
c59d1b374d | ||
|
|
1a99d2e2a1 | ||
|
|
1d03f7be64 | ||
|
|
994e44d8f1 | ||
|
|
f016a452cd | ||
|
|
c17b9a0e42 | ||
|
|
a91d5d6011 | ||
|
|
3a0902fe8e | ||
|
|
9baae5bccc | ||
|
|
7b837fdba7 | ||
|
|
283b7538e6 | ||
|
|
14ae6e5dad | ||
|
|
87608f9bfb | ||
|
|
5903932328 | ||
|
|
96193196cc | ||
|
|
0186421fc6 | ||
|
|
714feda225 | ||
|
|
3d834933e7 | ||
|
|
dd72a873ab | ||
|
|
81cd3a1c1c | ||
|
|
b52f1d4486 | ||
|
|
42239ef54d | ||
|
|
256a79e427 | ||
|
|
b36f98e5e9 | ||
|
|
2f33daaaa7 |
Vendored
-6
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"files.trimTrailingWhitespace": true,
|
||||
"files.insertFinalNewline": true,
|
||||
"files.trimFinalNewlines": true,
|
||||
"editor.renderFinalNewline": false
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023-2024 Warén Group
|
||||
Copyright (c) 2023-2026 Warén Group
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -1,15 +1,4 @@
|
||||
# Warén Group - Warén CLI (wx)
|
||||
|
||||
## Install
|
||||
```
|
||||
mkdir $HOME/bin &> /dev/null
|
||||
curl https://git.waren.io/warengroup/wx/raw/branch/master/wx -o $HOME/bin/wx &> /dev/null
|
||||
chmod +x $HOME/bin/wx &> /dev/null
|
||||
export PATH=$HOME/bin:$PATH
|
||||
```
|
||||
|
||||
## Schedule
|
||||
```
|
||||
# Warén CLI
|
||||
*/30 * * * * $HOME/bin/wx auto
|
||||
```
|
||||
## Documentation
|
||||
Check documentation in Warén Group's Infra repository. This repository is going to be deprecated soon.
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ ! "$BASH_VERSION" ] ; then
|
||||
bash $0 $1 $2 $3 $4 $5 $6 $7 $8 $9
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -f "./wx" ]] && [[ -d "./src" ]]
|
||||
then
|
||||
podman run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/library/php:8-cli php generator.php &> /dev/null
|
||||
mv wx.tmp wx &> /dev/null
|
||||
chmod +x wx &> /dev/null
|
||||
fi
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
$base = file_get_contents(__DIR__."/src/base.sh");
|
||||
|
||||
|
||||
$dirs = [
|
||||
__DIR__.'/src/commands/*.sh',
|
||||
__DIR__.'/src/commands/*/*.sh',
|
||||
__DIR__.'/src/commands/*/*/*.sh',
|
||||
__DIR__.'/src/functions/*.sh'
|
||||
];
|
||||
|
||||
$codes = [];
|
||||
|
||||
foreach($dirs as $dir){
|
||||
foreach(glob($dir) as $file){
|
||||
if(str_contains($dir, "functions")){
|
||||
$codes['functions'][$file] = file_get_contents($file);
|
||||
}
|
||||
if(str_contains($dir, "commands")){
|
||||
$codes['commands'][$file] = file_get_contents($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$code = str_replace("{{ FUNCTIONS }}", implode("\n", $codes['functions']), $base);
|
||||
$code = str_replace("{{ COMMANDS }}", implode("\n", $codes['commands']), $code);
|
||||
|
||||
try {
|
||||
$file = __DIR__.'/wx.tmp';
|
||||
$file = fopen($file, "w");
|
||||
fwrite($file, $code);
|
||||
fclose($file);
|
||||
} catch (\Error $e) {
|
||||
}
|
||||
|
||||
?>
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ ! "$BASH_VERSION" ] ; then
|
||||
bash $0 $1 $2 $3 $4 $5 $6 $7 $8 $9
|
||||
exit 1
|
||||
fi
|
||||
|
||||
wxRed=$(tput setaf 196)
|
||||
wxGreen=$(tput setaf 46)
|
||||
wxYellow=$(tput setaf 226)
|
||||
wxBlue=$(tput setaf 21)
|
||||
wxPurple=$(tput setaf 165)
|
||||
wxTurquoise=$(tput setaf 14)
|
||||
wxPink=$(tput setaf 198)
|
||||
wxOrange=$(tput setaf 202)
|
||||
wxUnderline=$(tput smul)
|
||||
wxBold=$(tput bold)
|
||||
wxNormal=$(tput sgr0)
|
||||
|
||||
declare -Ax config
|
||||
|
||||
{{ FUNCTIONS }}
|
||||
{{ COMMANDS }}
|
||||
|
||||
if [[ ! -z $1 ]] && [[ $(type -t wx-$1) == function ]]
|
||||
then
|
||||
wx-$1 $2 $3 $4 $5 $6 $7 $8 $9
|
||||
else
|
||||
wx-welcome
|
||||
fi
|
||||
wx-stop
|
||||
@@ -1,171 +0,0 @@
|
||||
wx-login(){
|
||||
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]
|
||||
then
|
||||
wx-header "Login"
|
||||
echo "Status: Hostname Required"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
ORG=$1
|
||||
elif [[ $(hostname -d) = *"devices.waren.io" ]]
|
||||
then
|
||||
ORG=warengroup
|
||||
elif [[ $(hostname -d) = *"devices.cwinfo.net" ]]
|
||||
then
|
||||
ORG=cwinfo
|
||||
elif [[ $(hostname -d) = *"devices.christerwaren.fi" ]]
|
||||
then
|
||||
ORG=cwchristerw
|
||||
else
|
||||
wx-header "Login"
|
||||
echo "Status: Organization Required"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
if [[ $ORG == "warengroup" ]]
|
||||
then
|
||||
DOMAIN=waren.io
|
||||
elif [[ $ORG == "cwinfo" ]]
|
||||
then
|
||||
DOMAIN=cwinfo.net
|
||||
elif [[ $ORG == "cwchristerw" ]]
|
||||
then
|
||||
DOMAIN=christerwaren.fi
|
||||
else
|
||||
wx-header "Login"
|
||||
echo "Status: Organization Unsupported"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
FOLDER=$ORG
|
||||
DEVICE_DOMAIN="devices.$DOMAIN"
|
||||
IDM_DOMAIN="idm.cwinfo.net"
|
||||
VAULT_DOMAIN="vault.cwinfo.net"
|
||||
|
||||
if [[ ! -z $2 ]]
|
||||
then
|
||||
HOSTNAME="$2.$DEVICE_DOMAIN"
|
||||
elif [[ $(hostname -d) ]]
|
||||
then
|
||||
HOSTNAME=$(hostname --fqdn)
|
||||
else
|
||||
wx-header "Login"
|
||||
echo "Status: Hostname Required"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
if [[ -z $USER || $USER == "root" || $USER == "local" ]]
|
||||
then
|
||||
if [[ -z $SUDO_USER ]]
|
||||
then
|
||||
if [[ -z LOGNAME ]]
|
||||
then
|
||||
wx-header "Login"
|
||||
echo "Status: Username Required"
|
||||
wx-stop
|
||||
else
|
||||
USERNAME=$LOGNAME
|
||||
fi
|
||||
else
|
||||
USERNAME=$SUDO_USER
|
||||
fi
|
||||
else
|
||||
USERNAME=$USER
|
||||
fi
|
||||
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
|
||||
if [[ $USER != "root" && $USER != "local" && -f "$HOME/.config/warengroup/config.json" ]]
|
||||
then
|
||||
TOKEN="$(cat $HOME/.config/warengroup/config.json | jq -r .login.$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
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
if [[ $USER != "root" && $USER != "local" ]]
|
||||
then
|
||||
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json 1> $HOME/.config/warengroup/config.json.tmp
|
||||
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
|
||||
fi
|
||||
else
|
||||
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
|
||||
if [[ $IDM_STATUS -eq 301 ]]
|
||||
then
|
||||
wx-header "Login"
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" ]]
|
||||
then
|
||||
echo -n "Username: "
|
||||
read USERNAME
|
||||
else
|
||||
echo "Username: $USERNAME"
|
||||
fi
|
||||
|
||||
echo -n "Password: "
|
||||
read -s PASSWORD
|
||||
echo "****************"
|
||||
|
||||
if [[ -z $USERNAME || -z $PASSWORD ]]
|
||||
then
|
||||
echo "Status: Username & Password Required"
|
||||
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 "Status: Login Failed"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
|
||||
if [[ $USER != "root" && $USER != "local" ]]
|
||||
then
|
||||
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
|
||||
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
|
||||
fi
|
||||
fi
|
||||
else
|
||||
wx-header "Login"
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
echo -n "Token: "
|
||||
read -s TOKEN
|
||||
echo "****************"
|
||||
|
||||
if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]]
|
||||
then
|
||||
echo "Status: Vault Token Required"
|
||||
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 "Status: Login Failed"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
|
||||
if [[ $USER != "root" && $USER != "local" ]]
|
||||
then
|
||||
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
|
||||
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
wx-header "Login"
|
||||
echo $wxBold$ORG$wxNormal
|
||||
echo "Status: Vault Offline"
|
||||
wx-stop
|
||||
fi
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
wx-logout(){
|
||||
wx-header "Logout"
|
||||
if [[ $USER != "root" && $USER != "local" && -f "$HOME/.config/warengroup/config.json" ]]
|
||||
then
|
||||
VAULT_LOGIN=$(cat $HOME/.config/warengroup/config.json | jq -r .login)
|
||||
if [[ $VAULT_LOGIN != null && $VAULT_LOGIN != "{}" ]]
|
||||
then
|
||||
wx-clean
|
||||
jq '.login = {}' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp
|
||||
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
wx-help(){
|
||||
|
||||
wx-header "Help"
|
||||
|
||||
echo -n "
|
||||
Usage: $0 COMMAND [OPTIONS]
|
||||
|
||||
Common Commands:
|
||||
init Init
|
||||
help Help
|
||||
ssh SSH
|
||||
config Config
|
||||
edit Edit
|
||||
save Save
|
||||
sync Sync
|
||||
clean Clean
|
||||
keys Keys
|
||||
generate Generate
|
||||
sign Sign
|
||||
retrieve Retrieve
|
||||
save Save
|
||||
sync Sync
|
||||
delete Delete
|
||||
clean Clean
|
||||
|
||||
Authentication Commands:
|
||||
login Login
|
||||
logout Logout
|
||||
|
||||
Management Commands:
|
||||
auto Auto
|
||||
clean Clean
|
||||
settings Settings
|
||||
|
||||
Maintenance Commands:
|
||||
install Install
|
||||
update Update
|
||||
";
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
wx-infra(){
|
||||
wx-login
|
||||
wx-auto &> /dev/null
|
||||
|
||||
wx-header "Infra"
|
||||
wx-restricted
|
||||
|
||||
INFRA_PATH="/home/cwchristerw/Desktop/Work in Progress/Programming/warengroup/infra"
|
||||
|
||||
case $USERNAME in
|
||||
cwchristerw)
|
||||
if [[ -z $1 ]]
|
||||
then
|
||||
echo "Tag Required"
|
||||
else
|
||||
if [[ $1 == "init" ]]
|
||||
then
|
||||
if [[ -z $2 ]]
|
||||
then
|
||||
echo "Tag Required"
|
||||
else
|
||||
cd "$INFRA_PATH"
|
||||
ansible-playbook --vault-id warengroup@vault/warengroup playbooks/init.yml -t $2 $3 $4 $5 $6 $7 $8 $9
|
||||
cd "$OLDPWD"
|
||||
fi
|
||||
else
|
||||
cd "$INFRA_PATH"
|
||||
ansible-playbook --vault-id warengroup@vault/warengroup playbooks.yml -t $1 $2 $3 $4 $5 $6 $7 $8 $9
|
||||
cd "$OLDPWD"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "User Unsupported"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
wx-install(){
|
||||
if [[ -z $1 ]]
|
||||
then
|
||||
wx-header "Install"
|
||||
fi
|
||||
|
||||
wx-restricted
|
||||
|
||||
if [[ -f "./wx" ]] && [[ -d "./src" ]]
|
||||
then
|
||||
podman run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/library/php:8-cli php generator.php &> /dev/null
|
||||
mv wx.tmp wx &> /dev/null
|
||||
chmod +x wx &> /dev/null
|
||||
fi
|
||||
|
||||
mkdir $HOME/bin &> /dev/null
|
||||
curl https://git.waren.io/warengroup/wx/raw/branch/master/wx -o $HOME/bin/wx &> /dev/null
|
||||
chmod +x $HOME/bin/wx &> /dev/null
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
wx-uninstall(){
|
||||
wx-header "Uninstall"
|
||||
wx-logout
|
||||
if [[ ! -d "$HOME/.config/warengroup" ]]
|
||||
then
|
||||
rm "$HOME/.config/warengroup" -rf
|
||||
fi
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
wx-update(){
|
||||
wx-header "Update"
|
||||
wx-install --update
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
wx-auto(){
|
||||
wx-login
|
||||
wx-header "Auto"
|
||||
|
||||
wx-ssh-config-sync
|
||||
wx-ssh-keys-sync
|
||||
wx-ssh-keys-sign
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
wx-clean(){
|
||||
wx-login
|
||||
wx-header "Clean"
|
||||
wx-ssh-config-clean
|
||||
wx-ssh-keys-clean
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
wx-settings(){
|
||||
wx-login
|
||||
wx-header "Settings"
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
wx-ssh(){
|
||||
wx-login
|
||||
|
||||
mkdir -p $HOME/.ssh/keys
|
||||
chmod 700 -R $HOME/.ssh/keys
|
||||
mkdir -p $HOME/.ssh/multiplex
|
||||
chmod 700 -R $HOME/.ssh/multiplex
|
||||
|
||||
case $1 in
|
||||
keys)
|
||||
wx-ssh-keys $2 $3
|
||||
;;
|
||||
config)
|
||||
wx-ssh-config $2
|
||||
;;
|
||||
*)
|
||||
wx-header "SSH"
|
||||
wx-stop
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
wx-ssh-config(){
|
||||
wx-restricted
|
||||
|
||||
case $1 in
|
||||
edit)
|
||||
wx-ssh-config-sync
|
||||
wx-ssh-config-edit
|
||||
wx-ssh-config-save
|
||||
;;
|
||||
save)
|
||||
wx-ssh-config-save
|
||||
;;
|
||||
sync)
|
||||
wx-ssh-config-sync
|
||||
;;
|
||||
clean)
|
||||
wx-ssh-config-clean
|
||||
;;
|
||||
*)
|
||||
wx-ssh-config-sync
|
||||
wx-stop
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
wx-ssh-config-edit(){
|
||||
wx-header "SSH / Config / Edit"
|
||||
wx-restricted
|
||||
nano ~/.ssh/config
|
||||
}
|
||||
|
||||
wx-ssh-config-save(){
|
||||
wx-header "SSH / Config / Save"
|
||||
wx-restricted
|
||||
curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"data\": { \"data\": \"$(cat ~/.ssh/config | base64 -w 0)\" } }" -s &> /dev/null
|
||||
}
|
||||
|
||||
wx-ssh-config-sync(){
|
||||
wx-header "SSH / Config / Sync"
|
||||
wx-restricted
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.data') | base64 -d > ~/.ssh/config 2>&1
|
||||
chmod 700 ~/.ssh/config
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-config-clean(){
|
||||
wx-header "SSH / Config / Clean"
|
||||
wx-restricted
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ -f "$HOME/.ssh/config" && $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
rm "$HOME/.ssh/config"
|
||||
fi
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
wx-ssh-keys(){
|
||||
wx-restricted
|
||||
|
||||
case $1 in
|
||||
generate)
|
||||
wx-ssh-keys-retrieve $2
|
||||
wx-ssh-keys-generate $2
|
||||
wx-ssh-keys-save $2
|
||||
;;
|
||||
sign)
|
||||
wx-ssh-keys-sign
|
||||
;;
|
||||
retrieve)
|
||||
wx-ssh-keys-retrieve $2
|
||||
;;
|
||||
save)
|
||||
wx-ssh-keys-save $2
|
||||
;;
|
||||
sync)
|
||||
wx-ssh-keys-sync $2
|
||||
;;
|
||||
delete)
|
||||
wx-ssh-keys-delete $2
|
||||
;;
|
||||
clean)
|
||||
wx-ssh-keys-clean $2
|
||||
;;
|
||||
*)
|
||||
wx-stop
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
wx-ssh-keys-generate(){
|
||||
wx-header "SSH / Keys / Generate"
|
||||
wx-restricted
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
if [[ ! -f "$HOME/.ssh/keys/$1" ]]
|
||||
then
|
||||
ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$1 -q -N "" -C "$USERNAME" &> /dev/null
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-sign(){
|
||||
wx-header "SSH / Keys / Sign"
|
||||
wx-restricted
|
||||
|
||||
if [[ $ORG == "warengroup" ]]
|
||||
then
|
||||
wx-ssh-keys-sign-create warengroup sysadmin 3600
|
||||
elif [[ $ORG == "cwinfo" ]]
|
||||
then
|
||||
wx-ssh-keys-sign-create cwinfo sysadmin 3600
|
||||
elif [[ $ORG == "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-sign-create warengroup sysadmin 3600
|
||||
wx-ssh-keys-sign-create cwinfo sysadmin 3600
|
||||
wx-ssh-keys-sign-create cwchristerw sysadmin 3600
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-sign-create(){
|
||||
wx-restricted
|
||||
|
||||
NAME=$1
|
||||
ROLE=$2
|
||||
PRINCIPALS=$2
|
||||
TTL=$3
|
||||
|
||||
if [[ ! -f "$HOME/.ssh/keys/$NAME" ]]
|
||||
then
|
||||
ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$NAME -q -N "" -C "$USERNAME" &> /dev/null
|
||||
fi
|
||||
|
||||
if [[ -f "$HOME/.ssh/keys/$NAME" ]]
|
||||
then
|
||||
echo "$NAME/$ROLE"
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME.pub)\", \"valid_principals\": \"$PRINCIPALS,$USERNAME\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME.sig 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-retrieve(){
|
||||
if [[ -z $2 ]]
|
||||
then
|
||||
wx-header "SSH / Keys / Retrieve"
|
||||
fi
|
||||
|
||||
wx-restricted
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.private') | base64 -d > ~/.ssh/keys/$1 2>&1
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.public') | base64 -d > ~/.ssh/keys/$1.pub 2>&1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-save(){
|
||||
wx-header "SSH / Keys / Save"
|
||||
wx-restricted
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
if [[ -f "$HOME/.ssh/keys/$1" ]]
|
||||
then
|
||||
curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"data\": { \"private\": \"$(cat ~/.ssh/keys/$1 | base64 -w 0)\", \"public\": \"$(cat ~/.ssh/keys/$1.pub | base64 -w 0)\" } }" -s &> /dev/null
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-sync(){
|
||||
wx-header "SSH / Keys / Sync"
|
||||
wx-restricted
|
||||
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/metadata/$USERNAME/settings/ssh/keys -X LIST --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
for name in $(curl https://$VAULT_DOMAIN/v1/cli/metadata/$USERNAME/settings/ssh/keys -X LIST --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.keys | @sh' | tr -d \')
|
||||
do
|
||||
echo $name
|
||||
wx-ssh-keys-retrieve $name --multiple
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-clean(){
|
||||
if [[ -z $1 ]]
|
||||
then
|
||||
wx-header "SSH / Keys / Clean"
|
||||
fi
|
||||
wx-restricted
|
||||
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
if [[ -f "$HOME/.ssh/keys/$1" && $(basename "$HOME/.ssh/keys/$1") != "legacy" ]]
|
||||
then
|
||||
rm "$HOME/.ssh/keys/$1" &> /dev/null
|
||||
rm "$HOME/.ssh/keys/$1.pub" &> /dev/null
|
||||
rm "$HOME/.ssh/keys/$1.sig" &> /dev/null
|
||||
fi
|
||||
else
|
||||
if [[ $ORG == "warengroup" ]]
|
||||
then
|
||||
wx-ssh-keys-clean warengroup
|
||||
elif [[ $ORG == "cwinfo" ]]
|
||||
then
|
||||
wx-ssh-keys-clean cwinfo
|
||||
elif [[ $ORG == "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-clean warengroup
|
||||
wx-ssh-keys-clean cwinfo
|
||||
wx-ssh-keys-clean cwchristerw
|
||||
fi
|
||||
|
||||
for file in ~/.ssh/keys/*
|
||||
do
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$(basename "$file" .pub) -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $(basename "$file") != "legacy" && $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
rm "$file" &> /dev/null
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
wx-welcome(){
|
||||
wx-header "Welcome"
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
wx-header(){
|
||||
if [[ $2 == "h1" ]]
|
||||
then
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "=============================="
|
||||
wx-repeat " " $((30/2-${#1}/2))
|
||||
echo -n "$wxBold"
|
||||
echo -n "$1"
|
||||
echo -n "$wxNormal"
|
||||
echo ""
|
||||
echo "=============================="
|
||||
fi
|
||||
|
||||
if [[ $2 == "h2" || -z $2 ]]
|
||||
then
|
||||
wx-start
|
||||
wx-repeat " " $((30/2-6/2-${#1}/2))
|
||||
echo -n ">> $1 <<"
|
||||
echo ""
|
||||
echo "------------------------------"
|
||||
fi
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
wx-repeat() {
|
||||
local str=$1 n=$2 spaces
|
||||
printf -v spaces "%*s" $n " "
|
||||
printf "%s" "${spaces// /$str}"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
wx-restricted(){
|
||||
if [[ $USER == "root" || $USER == "local" ]]
|
||||
then
|
||||
echo "Status: Command Restricted"
|
||||
echo " "
|
||||
echo " "
|
||||
echo " "
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
wx-start(){
|
||||
wx-header "Warén CLI" h1
|
||||
|
||||
if [[ $USER != "root" && $USER != "local" ]]
|
||||
then
|
||||
mkdir -p $HOME/.config/warengroup &> /dev/null
|
||||
|
||||
if [[ ! -f "$HOME/.config/warengroup/config.json" ]]
|
||||
then
|
||||
echo '{}' | jq > $HOME/.config/warengroup/config.json
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
wx-stop (){
|
||||
echo " "
|
||||
echo " "
|
||||
echo " "
|
||||
|
||||
wx-install --auto
|
||||
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user