OPNsense Forum

Archive => 19.1 Legacy Series => Topic started by: BrianW on February 07, 2019, 06:52:54 pm

Title: CP Endpoints for White List
Post by: BrianW on February 07, 2019, 06:52:54 pm
Can anyone point me to the endpoints for getting, adding, and deleting MAC address to the CP white list via the API?

Thanks
Title: Re: CP Endpoints for White List
Post by: fabian on February 07, 2019, 09:58:30 pm
API docs: https://docs.opnsense.org/development/api/core/captiveportal.html
Title: Re: CP Endpoints for White List
Post by: BrianW on February 07, 2019, 10:56:04 pm
Thank you. I am aware of that documentation, but it is rather sparse.

The only endpoint that makes sense to me for this purpose would be api/captiveportal/settings/setzone/ (I have acquired the uuid with searchzones).

I know that I should be including a JSON object in the body of the request, but there's nothing to indicate what it should contain. I've tried what seemed meaningful values for this and other endpoints, but the only response I ever receive is {"result":"failed"}

Is there more comprehensive documentation for the API, or somewhere that would give me an idea of what my JSON object should contain?

Thanks
Title: Re: CP Endpoints for White List
Post by: fabian on February 08, 2019, 05:36:27 pm
usually not, but you can look either on the model XML (https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/CaptivePortal/CaptivePortal.xml#L9) or download it first with the get call.
Title: Re: CP Endpoints for White List
Post by: BrianW on February 08, 2019, 06:26:30 pm
Thanks. I don't know why I didn't think to examine the result of a get first. Exploring it now.

b.
Title: Re: CP Endpoints for White List
Post by: BrianW on February 13, 2019, 05:12:37 pm
Thank you for helping out the newb.

When I get https://10.15.1.227/api/captiveportal/settings/getzone/2dd820e7-0995-4174-8546-6fa66fb0bf5f

I get a big json object. If I post it right back to /setzone, no alteration, I get the error:

Code: [Select]
{"errorMessage":"Error at /usr/local/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php:700 - strtolower() expects parameter 1 to be string, array given (errno=2)","errorTitle":"An API exception occured"}
I can pick out certain things and change successfully, like enable / disable, or description.

The relevant portion I would like to post is
Code: [Select]
{"zone":{"allowedMACAddresses":{"00:11:22:33:44:55":{"value":"00:11:22:33:44:55","selected":1},"aa:bb:cc:dd:ee:ff":{"value":"aa:bb:cc:dd:ee:ff","selected":1}}}}
but this generates the same error.

I can send
Code: [Select]
{"zone":{"allowedMACAddresses":"aa:bb:cc:dd:ee:ff"}}
Which works, but, expectedly, this replaces any MAC addresses on the list.

Thanks
Title: Re: CP Endpoints for White List
Post by: fabian on February 13, 2019, 05:29:32 pm
try to post such multi value and dropdown fields as CSV string.
Title: Re: CP Endpoints for White List
Post by: BrianW on February 14, 2019, 09:11:16 pm
Thank you so much!

That did it.