Search code examples
phppostmanfreeradius

Using FauxAPI query to add a user to the freeradius config xml list of users with PHP function


I have a server with a list of allowed users for the captive portal using freeradius. I want to have a separate server be able to send a faux api request to add a user to this config xml list.

I am trying to use postman to send a request to my pfsense file to patch the config. How should the body be structured?

I have already tried the function_call request

{
   "function":"radius"
   "args":[args]
}

and believe maybe that I should be using the config_patch request

The error does not help in describing the structure of the json data it expects though. I provided a null json:

{}

Which returned :

Fatal error: Uncaught TypeError: Argument 2 passed to
fauxapi\v1\fauxApiPfsenseInterface::array_merge_recursive_distinct() must be of the type array, null given, called in
/etc/inc/fauxapi/fauxapi_pfsense_interface.inc on line 120 and defined in
/etc/inc/fauxapi/fauxapi_pfsense_interface.inc:135
Stack trace:
#0 /etc/inc/fauxapi/fauxapi_pfsense_interface.inc(120):
fauxapi\v1\fauxApiPfsenseInterface->array_merge_recursive_distinct(Array, NULL)
#1 /etc/inc/fauxapi/fauxapi_actions.inc(113): fauxapi\v1\fauxApiPfsenseInterface->config_patch(NULL, true, true)
#2 /etc/inc/fauxapi/fauxapi.inc(90): fauxapi\v1\fauxApiActions->config_patch(Array)
#3 /usr/local/www/fauxapi/v1/index.php(32): fauxapi\v1\fauxApi->__call('config_patch', Array)
#4 {main}
thrown in /etc/inc/fauxapi/fauxapi_pfsense_interface.inc on line 135
PHP ERROR: Type: 1, File: /etc/inc/fauxapi/fauxapi_pfsense_interface.inc, Line: 135, Message: Uncaught TypeError:
Argument 2 passed to fauxapi\v1\fauxApiPfsenseInterface::array_merge_recursive_distinct() must be of the type array,
null given, called in /etc/inc/fauxapi/fauxapi_pfsense_interface.inc on line 120 and defined in
/etc/inc/fauxapi/fauxapi_pfsense_interface.inc:135
Stack trace:
#0 /etc/inc/fauxapi/fauxapi_pfsense_interface.inc(120):
fauxapi\v1\fauxApiPfsenseInterface->array_merge_recursive_distinct(Array, NULL)
#1 /etc/inc/fauxapi/fauxapi_actions.inc(113): fauxapi\v1\fauxApiPfsenseInterface->config_patch(NULL, true, true)
#2 /etc/inc/fauxapi/fauxapi.inc(90): fauxapi\v1\fauxApiActions->config_patch(Array)
#3 /usr/local/www/fauxapi/v1/index.php(32): fauxapi\v1\fauxApi->__call('config_patch', Array)
#4 {main}
thrown

I want to add a user in this structure:

"freeradius": {
                    "config": [
                        {
                            "sortable": "",
                            "varusersusername": "blah",
                            "varuserspassword": "password",
//just for debug purposes
                            "varuserspasswordencryption": "Cleartext-Password",
                            "varusersmotpenable": "",
                            "varusersauthmethod": "",
                            "varusersmotpinitsecret": "",
                            "varusersmotppin": "",
                            "varusersmotpoffset": "",
                            "qrcodetext": "",
                            "varuserswisprredirectionurl": "",
                            "varuserssimultaneousconnect": "",
                            "description": "",
                            "varusersframedipaddress": "",
                            "varusersframedipnetmask": "",
                            "varusersframedroute": "",
                            "varusersvlanid": "",
                            "varusersexpiration": "",
                            "varuserssessiontimeout": "",
                            "varuserslogintime": "",
                            "varusersamountoftime": "",
                            "varuserspointoftime": "Daily",
                            "varusersmaxtotaloctets": "1000",
                            "varusersmaxtotaloctetstimerange": "daily",
                            "varusersmaxbandwidthdown": "2048",
                            "varusersmaxbandwidthup": "2048",
                            "varusersacctinteriminterval": "",
                            "varuserstopadditionaloptions": "",
                            "varuserscheckitemsadditionaloptions": "",
                            "varusersreplyitemsadditionaloptions": ""
                        },

Solution

  • Ok so turns out that the pfsense is not well integrated with freeradius. The post would overwrite the xml config array for freeradius. I found that OPNSense is much better equipped to handle plugins.

    Using this I was able to better handle users of freeradius:

    https://docs.opnsense.org/development/api/plugins/freeradius.html