ndejong / pfsense_fauxapi

REST based API interface for pfSense 2.3.x and 2.4.x to facilitate devops
Apache License 2.0
354 stars 61 forks source link

FauxAPI PHP errors SOMETIMES when using to toggle pfSense rules #60

Closed burntoc closed 4 years ago

burntoc commented 4 years ago

I'd posted on r/pfSense first because I'm afraid I'll have to have my hand held if I need to troubleshoot this further - but I'm happy to try. They pointed me here. I installed FauxAPI on my box to use a custom component for Home Assistant to toggle pfSense rules . Sometimes toggling the switch in Hassio works, but many times it doesn't and when I visit pfSense I see this:

amd64
11.3-STABLE
FreeBSD 11.3-STABLE #67 123f7c00f04(RELENG_2_4_5): Wed Feb 26 15:06:33 EST 2020     root@buildbot1-nyi.netgate.com:/build/ce-crossbuild-245/obj/amd64/YNx4Qq3j/build/ce-crossbuild-245/sources/FreeBSD-src/sys/pfSense

Crash report details:
PHP Errors:
[04-Mar-2020 15:59:48 America/Los_Angeles] PHP Fatal error:  Uncaught Error: Call to undefined function phpsession_begin() in /etc/inc/config.lib.inc:491
Stack trace:
#0 /etc/inc/config.lib.inc(673): write_config('Reverted to con...', false)
#1 /etc/inc/fauxapi/fauxapi_pfsense_interface.inc(269): config_restore('/cf/conf/backup...')
#2 /etc/inc/fauxapi/fauxapi_actions.inc(85): fauxapi\v1\fauxApiPfsenseInterface->config_save(Array, true, true)
#3 /etc/inc/fauxapi/fauxapi.inc(90): fauxapi\v1\fauxApiActions->config_set(Array)
#4 /usr/local/www/fauxapi/v1/index.php(32): fauxapi\v1\fauxApi->__call('config_set', Array)
#5 {main}
  thrown in /etc/inc/config.lib.inc on line 491
No FreeBSD crash data found.

If I go to that .inc file referenced it looks like 491 is just a bit of code checking to see if the call is made by admin or another user. In any case, I'm wondering if maybe the issue is FauxAPI tripping up on the RC version of pfSense 2.4.5 I'm running or something in the custom components, which haven't been updated in about a year.

I'd appreciate any help getting to the bottom of this so the rule toggles will work all the time.

ndejong commented 4 years ago

Thanks for the report.

This issue seems to be rooted in the fact that at line 491 of pfSense there is a call to phpsession_begin() which fails because phpsessionmanager.inc from pfSense has not been loaded.

What's curious here is that pfSense code uses an @ prefix before the phpsession_begin() call which should silence the error-condition - digging even further shows that pfSense does something unusual with the error_reporting setting here

My expectation is that this can be resolved by making sure phpsessionmanager.inc gets loaded before FauxAPI attempts to call the pfSense write_config function

I'll mark this up as a bug until I have time to investigate and resolve

burntoc commented 4 years ago

Thanks for taking a look! I'll be happy to test whenever it's appropriate.

burntoc commented 4 years ago

I feel like it's unlikely they'd address it on their end at this time, but I wanted to provide an update. The calls have been mostly failing, rather than mostly succeeding. For some reason they do on occasion work, which I suppose has to do with the execution order happening to fire right as you suspect. But I will say this - it could be luck, but I upgraded to the final RC this morning and 7 or 8 attempts have worked so far. Even for the 1 that failed I didn't get the crash detection notification on my dash as I had before. Maybe even that 1 failure had something else going on.

burntoc commented 4 years ago

Just confirming that it's still a problem with the latest RC. I didn't expect it had solved it, but I hoped it had.

ndejong commented 4 years ago

Closing this issue two ways