dlinux-connect/shell.sh

24 lines
724 B
Bash

#!/bin/bash
API_HOST="https://api.ssh.surf"
API_KEY=$(cat .api-key)
if [ ! -f .connector ]; then
echo "SSH Connector not found, getting for the first time"
[ -z $API_KEY ] && echo "API key not found" && exit 1
hello=$(curl -w %{http_code} -sH "x-ssh-auth: $API_KEY" $API_HOST/hello -o /dev/null)
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//')
echo $CONNECTOR > .connector
fi
CONNECTOR=$(cat .connector)
npx holesail $CONNECTOR