dlinux-connect/connect.sh

36 lines
1.1 KiB
Bash

#!/bin/bash
if [ ! -f .connector ]; then
API_HOST="https://api.ssh.surf"
API_KEY=$(cat .api-key)
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
echo "Connector saved, deleting .api-key"
rm .api-key
fi
CONNECTOR=$(cat .connector)
if [[ "$1" == "--experimental-use-manager" ]]; then
echo -e "Connecting using holesail manager is experimental.\nYou can report any bugs here: https://git.ssh.surf/Cyber/dlinux-connect/issues\n"
npx --package=holesail -- holesail-manager create $CONNECTOR --name dlinux-connect
sleep 3 # Wait for the connection to open
ssh localhost -p 8989
else
npx holesail $CONNECTOR
fi