1
Virtual private networks / Re: Bulk wireguard client config import?
« on: August 04, 2021, 01:41:01 am »
Easier said than done, hah, that's well outside my experience. If I hunt through the page source I can find stuff like this:
What I can say is that this works:
But this returns a 501 Not Implemented:
Even then, I don't know how to properly format the JSON input for the above. If I try this:
Anyways, I don't know enough about web application technology to look at this and know what to do, and I didn't really find enough OPNsense API examples in my searches to find some code to "borrow."
Code: [Select]
$("#grid-clients").UIBootgrid(
{ 'search':'/api/wireguard/client/searchClient',
'get':'/api/wireguard/client/getClient/',
'set':'/api/wireguard/client/setClient/',
'add':'/api/wireguard/client/addClient/',
'del':'/api/wireguard/client/delClient/',
'toggle':'/api/wireguard/client/toggleClient/'
}
);
...which doesn't really tell me anything, since I know of those from the documentation. https://docs.opnsense.org/development/api/plugins/wireguard.htmlWhat I can say is that this works:
Code: [Select]
curl -s -k -u $KEY:$SECRET https://$HOST/api/wireguard/client/get
And outputs something like this:Code: [Select]
{"client":{"clients":{"client":{"aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaaaaaaa":"enabled":"1","name":"Test","pubkey":"asdasdasdasdasdasdasdasdasdasdsa","psk":"",
"tunneladdress":"192.168.2.2\/24":"value":"192.168.2.2\/24","selected":1}},"serveraddress":"","serverport":"","keepalive":""}}}}}
But this returns a 501 Not Implemented:
Code: [Select]
curl -X port -d '' -k -u $KEY:$SECRET https://$HOST/api/wireguard/client/addClient
Even then, I don't know how to properly format the JSON input for the above. If I try this:
Code: [Select]
curl -X POST -d '{"client":{"enabled":"1","name":"Test","pubkey":"asdasdasdasdasdasdasdasdasdasdsa","psk":"","tunneladdress":"192.168.2.2\/24":"value":"192.168.2.2\/24","selected":1}},"serveraddress":"","serverport":"","keepalive":""}}}' \
-H "Content-Type: application/json" -k -u $KEY:$SECRET https://opnsense.fung.us/api/wireguard/client/addClient
... it returns: Code: [Select]
{"result":"failed"}
Anyways, I don't know enough about web application technology to look at this and know what to do, and I didn't really find enough OPNsense API examples in my searches to find some code to "borrow."