Initial Commit || New Files - "bssh.sh"

Uploaded FIles: 
"bssh.sh": Main File for Better SSH, handles all Commands.
This commit is contained in:
Saige Bowerman 2024-07-02 14:15:02 -05:00
parent 89963d6f1c
commit 81e48d7ef2
1 changed files with 85 additions and 0 deletions

85
bssh.sh Normal file
View File

@ -0,0 +1,85 @@
#!/usr/bin/env bash
SERVER_URL="http://se-chat.zelz.net"
show_help() {
echo "Usage: bssh [options] <CONF_NAME>"
echo ""
echo "Options:"
echo " -h, --help Show this help message and exit"
echo " -l, --list List all available configurations"
echo " -u, --user Login with username"
echo " -p, --password Password for login"
echo " -s, --save Save configuration to Cloud"
echo ""
echo "Examples:"
echo " bssh -u kimeru -p password Login with user kimeru"
echo " bssh -l List all available configurations"
echo " bssh -s web2 web2.yml Save configuration web2.yml to Cloud"
}
list_configs() {
echo "Cloud Configurations Available:"
curl -s "${SERVER_URL}/configurations"
}
login_user() {
local username="$1"
local password="$2"
response=$(curl -s -X POST -d "username=${username}&password=${password}" "${SERVER_URL}/login")
echo "$response"
}
save_configuration() {
local name="$1"
local filename="$2"
content=$(cat "$HOME/ssh_confs/$filename")
response=$(curl -s -X POST -d "name=${name}&content=${content}" "${SERVER_URL}/save-configuration")
echo "$response"
}
# Check for options
if [ $# -eq 0 ]; then
show_help
exit 0
fi
case $1 in
-h|--help)
show_help
exit 0
;;
-l|--list)
list_configs
exit 0
;;
-u|--user)
if [ $# -ne 3 ]; then
echo "Error: Username and password required."
exit 1
fi
login_user "$2" "$3"
exit 0
;;
-p|--password)
echo "Error: Password option must be used with -u/--user."
exit 1
;;
-s|--save)
if [ $# -ne 3 ]; then
echo "Error: Configuration name and filename required."
exit 1
fi
save_configuration "$2" "$3"
exit 0
;;
*)
CONF_NAME=$1
;;
esac
echo "Unknown option: $1"
show_help
exit 1