OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • Archive »
  • 19.1 Legacy Series »
  • CP Endpoints for White List
« previous next »
  • Print
Pages: [1]

Author Topic: CP Endpoints for White List  (Read 4189 times)

BrianW

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
    • View Profile
CP Endpoints for White List
« 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
Logged

fabian

  • Hero Member
  • *****
  • Posts: 2769
  • Karma: 200
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: CP Endpoints for White List
« Reply #1 on: February 07, 2019, 09:58:30 pm »
API docs: https://docs.opnsense.org/development/api/core/captiveportal.html
Logged

BrianW

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
    • View Profile
Re: CP Endpoints for White List
« Reply #2 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
Logged

fabian

  • Hero Member
  • *****
  • Posts: 2769
  • Karma: 200
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: CP Endpoints for White List
« Reply #3 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.
Logged

BrianW

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
    • View Profile
Re: CP Endpoints for White List
« Reply #4 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.
Logged

BrianW

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
    • View Profile
Re: CP Endpoints for White List
« Reply #5 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
Logged

fabian

  • Hero Member
  • *****
  • Posts: 2769
  • Karma: 200
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: CP Endpoints for White List
« Reply #6 on: February 13, 2019, 05:29:32 pm »
try to post such multi value and dropdown fields as CSV string.
Logged

BrianW

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
    • View Profile
Re: CP Endpoints for White List
« Reply #7 on: February 14, 2019, 09:11:16 pm »
Thank you so much!

That did it.
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • Archive »
  • 19.1 Legacy Series »
  • CP Endpoints for White List
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2024 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2