I’m SSHing into my router to try and run some simple curl commands. To whit
curl -X POST -H "Content-Type: application/json" \
-d '{"Token": "MyToken"}' \
http://192.168.8.1/cgi-bin/api/ovpn/client/list
This gives me an error msg:
{“code”:-1,“msg”:“Token is null”}
What am I doing wrong? I’m fairly certain I have the correct Authorization code in my command.
LupusE
July 27, 2022, 5:32pm
2
You’re about to mix up two communications.
connect per ssh
and execute local commands.
connect per curl
and use the well documented API
It is not useful to login remote to send a http request.
In the API documentation is the very first part ‘Authentication’ (okay, the second, after ‘Prepare the Environment’).
Maybe the API differs from your device. It is useful to know against what device/firmware you are executing the curl-request.
Johnex
July 27, 2022, 7:53pm
3
Did you get the token like so?
curl 192.168.8.1/cgi-bin/api/router/login -d "pwd=YOUR_ROUTER_PASS"
The token you get from the above login command you use bellow
curl 192.168.8.1/cgi-bin/api/ovpn/client/list -X POST -H "Content-Type: application/json" -d '{"Token": "TOKEN_HERE"}'
Yes, I tried that and get
{"code":-1,"msg":"Token is null"}
LupusE
July 29, 2022, 6:26am
5
I’ll get the same at my Beryl (snapshot Firmware).
Does ‘router/hello’ works for you?
lupus@kira:~$ curl -k https://192.168.8.1/cgi-bin/api/router/hello -X GET -H "Content-Type: application/json"
{"init":true,"connected":true,"configured":true,"version":"3.215","firmware_user":"","firmware_type":"","model":"mt1300","mac":"94:83:c4:xx:xx:xx","type":"router","name":"","code":0}
I don’t think it is a SSL issue, because http:// give the same result.
On my SlateAX, I get as result only ‘403 Forbidden’. But I have no time to find the right switch, right now. I’ll try this weekend, again.
Edit:
HINT: Don’t use !! in your Password . At least Linux Bash will expand !! to ‘last command’. Very disturbing.
Else it is working on Beryl with the explaination from @alzhao .
alzhao
July 29, 2022, 10:14am
6
curl -X POST -H "Content-Type: application/json" \
-H "Authorization: YOUR-ACTUAL-TOKEN" \
-d '{""}' \
http://192.168.8.1/cgi-bin/api/ovpn/client/list
1 Like
Where does the actual token (assume ABCDEFG
) go?
My ultimate goal is to connect/disconnect to one of the defined OpenVPN or WireGuard clients
alzhao
July 30, 2022, 1:05am
9
I modified my answer. Hope it is clear now.
Please remove the brackets and change text to caps, ie
-H "Authorization: YOUR-ACTUAL-TOKEN" \
So the next guy that sees this won’t include the brackets.
1 Like
alzhao
August 1, 2022, 10:07am
12
Changed. Thanks for your suggestions.