feat: exec and notify commands

This commit is contained in:
CyberL1 2024-11-30 19:48:56 +01:00
parent c60eafc6a2
commit f4892f14cf

24
dlinux
View File

@ -21,13 +21,15 @@ $0 stats - Get your container memory usage statistics
$0 time - Get your container expiration time
$0 rootpass - Reset root user password
$0 key-time - Get your api key expiration time
$0 exec - Execute a command in your container
$0 notify - Send a message DM to your discord
"
}
# Helper function
call_api() {
curl -X $1 -H "x-ssh-auth: $API_KEY" "https://api.ssh.surf/$2" 2> /dev/null
curl -X $1 -H "x-ssh-auth: $API_KEY" -H "Content-Type: application/json" "https://api.ssh.surf/$2" -d "$3" 2> /dev/null
}
# Commands
@ -92,10 +94,28 @@ command_key-time() {
call_api GET key-time | jq -r .keyexpireString
}
command_exec() {
while test $# -gt 0; do
case $1 in
--pwd|-p) pwd=$2; shift ;;
--cmd|-c) cmd=$2; shift ;;
esac
shift
done
pwd=${pwd:-"/"}
call_api POST exec "{\"pwd\":\"$pwd\",\"cmd\":\"$cmd\"}" | jq -r .stdout
}
command_notify() {
call_api POST notify "{\"message\":\"$2\"}" | jq -r .message
}
# Command handler
if [ $1 ]; then
command_$1
command_$1 "$@"
else
print_help
fi