feat: save connector to a file

This commit is contained in:
CyberL1 2024-07-27 22:03:50 +02:00
parent 4bbc916282
commit a493ab7e40
2 changed files with 14 additions and 7 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.api-key
.connector

View File

@ -3,15 +3,21 @@
API_HOST="https://api.ssh.surf"
API_KEY=$(cat .api-key)
[ -z $API_KEY ] && echo "API key not found" && exit 1
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)
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
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=$(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//')
CONNECTOR=$(cat .connector)
npx holesail $CONNECTOR