dlinux-connect/connect.sh

24 lines
724 B
Bash
Raw Normal View History

2024-07-27 15:49:09 -04:00
#!/bin/bash
API_HOST="https://api.ssh.surf"
API_KEY=$(cat .api-key)
2024-07-27 16:03:50 -04:00
if [ ! -f .connector ]; then
echo "SSH Connector not found, getting for the first time"
[ -z $API_KEY ] && echo "API key not found" && exit 1
2024-07-27 15:49:09 -04:00
2024-07-27 16:03:50 -04:00
hello=$(curl -w %{http_code} -sH "x-ssh-auth: $API_KEY" $API_HOST/hello -o /dev/null)
2024-07-27 15:49:09 -04:00
2024-07-27 16:03:50 -04:00
if [[ hello -ne 200 ]]; then
echo "token not valid, exiting"
exit 1
fi
CONNECTOR=$(curl -sH "x-ssh-auth: $API_KEY" -X POST -H "content-type: application/json" $API_HOST/exec --data '{ "cmd": "con --list | grep ssh - Port: 22", "pwd": "/root" }' | grep -o 'Connector: [^"]*' | sed 's/Connector: //' | sed 's/\\n//')
2024-07-27 15:49:09 -04:00
2024-07-27 16:03:50 -04:00
echo $CONNECTOR > .connector
fi
2024-07-27 15:49:09 -04:00
2024-07-27 16:03:50 -04:00
CONNECTOR=$(cat .connector)
2024-07-27 15:49:09 -04:00
npx holesail $CONNECTOR