Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing group of api endpoints in v2 #501

Closed
droid-sheep opened this issue Jul 6, 2024 · 4 comments · Fixed by #503
Closed

Missing group of api endpoints in v2 #501

droid-sheep opened this issue Jul 6, 2024 · 4 comments · Fixed by #503
Labels
bug Something isn't working enhancement Issues or PRs that enhance existing features

Comments

@droid-sheep
Copy link

Describe the bug

After freshly installing the pfrest pkg (pfSense-2.7.2-pkg-RESTAPI.pkg) some endpoint groups are not available (HTTP 404).
Following groups of endpoints are not available (referencing https://pfrest.org/api-docs/#/):

  • system
  • user
  • vpn

To Reproduce
Steps to reproduce the behavior:

  1. Install pkg via pfsense command line:
    pkg-static -C /dev/null add https://github.com/jaredhendrickson13/pfsense-api/releases/latest/download/pfSense-2.7.2-pkg-RESTAPI.pkg
  2. Switch Authentication to KEY based only
  3. Create a REST Key under keys tab. Hashing = SHA256, Length = 16
  4. Call via REST API Client (i used Advanced Rest client):
GET https://<fw>/api/v2/system/crls
Headers:
X-API-Key: <API Key>

Response:

<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

Expected behavior
Response defined in api docs and not a HTTP 404 error.

Screenshots or Response
-/-

pfSense Version & Package Version:

  • pfSense Version: 2.7.2-RELEASE (amd64)
  • Package Version: pfSense REST API v2.0.0 for 2.7.2

Affected Endpoints:

  • URL: /api/v2/system/**
  • URL: /api/v2/user/**
  • URL: /api/v2/vpn/**

Additional context
-/-

@jaredhendrickson13
Copy link
Owner

These are all present for me after installing. Try running pfsense-restapi buildendpoints from the command line to force the endpoints to be rebuilt.

@droid-sheep
Copy link
Author

droid-sheep commented Jul 6, 2024

When i execute your mentioned command in the web debug command line i get this response:

Building endpoints...
Fatal error: Uncaught RESTAPI\Responses\ServerError: Cannot parse FloatField `cpu_load_avg` from internal because its internal value is not
                    a numeric value. Consider changing this field to a StringField. in /usr/local/pkg/RESTAPI/Fields/FloatField.inc:143
Stack trace:
#0 /usr/local/pkg/RESTAPI/Core/Field.inc(886): RESTAPI\Fields\FloatField->_from_internal('0,18 0,22 0,23')
#1 /usr/local/pkg/RESTAPI/Core/Model.inc(827): RESTAPI\Core\Field->from_internal('0,18 0,22 0,23')
#2 /usr/local/pkg/RESTAPI/Core/Model.inc(810): RESTAPI\Core\Model->from_internal_object(Array)
#3 /usr/local/pkg/RESTAPI/Core/Model.inc(354): RESTAPI\Core\Model->from_internal()
#4 /usr/local/pkg/RESTAPI/Core/Model.inc(296): RESTAPI\Core\Model->construct_from_internal(NULL, NULL)
#5 /usr/local/pkg/RESTAPI/Models/SystemStatus.inc(162): RESTAPI\Core\Model->__construct(NULL, NULL, Array)
#6 /usr/local/pkg/RESTAPI/Core/Endpoint.inc(272): RESTAPI\Models\SystemStatus->__construct()
#7 /usr/local/pkg/RESTAPI/Endpoints/StatusSystemEndpoint.inc(21): RESTAPI\Core\Endpoint->__construct()
#8 /usr/local/pkg/RESTAPI/.resources/scripts/manage.php(40): RESTAPI\Endpoints\StatusSystemEndpoint->__construct()
#9 /usr/local/pkg/RESTAPI/.resources/scripts/manage.php(412): build_endpoints()
#10 {main}
  thrown in /usr/local/pkg/RESTAPI/Fields/FloatField.inc on line 143
PHP ERROR: Type: 1, File: /usr/local/pkg/RESTAPI/Fields/FloatField.inc, Line: 143, Message: Uncaught RESTAPI\Responses\ServerError: Cannot parse FloatField `cpu_load_avg` from internal because its internal value is not
                    a numeric value. Consider changing this field to a StringField. in /usr/local/pkg/RESTAPI/Fields/FloatField.inc:143
Stack trace:
#0 /usr/local/pkg/RESTAPI/Core/Field.inc(886): RESTAPI\Fields\FloatField->_from_internal('0,18 0,22 0,23')
#1 /usr/local/pkg/RESTAPI/Core/Model.inc(827): RESTAPI\Core\Field->from_internal('0,18 0,22 0,23')
#2 /usr/local/pkg/RESTAPI/Core/Model.inc(810): RESTAPI\Core\Model->from_internal_object(Array)
#3 /usr/local/pkg/RESTAPI/Core/Model.inc(354): RESTAPI\Core\Model->from_internal()
#4 /usr/local/pkg/RESTAPI/Core/Model.inc(296): RESTAPI\Core\Model->construct_from_internal(NULL, NULL)
#5 /usr/local/pkg/RESTAPI/Models/SystemStatus.inc(162): RESTAPI\Core\Model->__construct(NULL, NULL, Array)
#6 /usr/local/pkg/RESTAPI/Core/Endpoint.inc(272): RESTAPI\Models\SystemStatus->__construct()
#7 /usr/local/pkg/RESTAPI/Endpoints/StatusSystemEndpoint.inc(21): RESTAPI\Core\Endpoint->__construct()
#8 /usr/local/pkg/RESTAPI/.resources/scripts/manage.php(40): RESTAPI\Endpoints\StatusSystemEndpoint->__construct()
#9 /usr/local/pkg/RESTAPI/.resources/scripts/manage.php(412): build_endpoints()
#10 {main}
  thrown

Also no change in the 404 Endpoints and still 404

@droid-sheep
Copy link
Author

@jaredhendrickson13
Okay now i found something! Executing the pfsense-restapi buildendpoints command in the virtual machine shell gives me:

Building endpoints... done.
Building privileges... done.

After that (quick look) all endpoints work now. I don't know why the command doesn't work in the web debug shell. Also maybe there is a difference if i execute the install command in the web php prompt or in a "real" shell.

Maybe further investigate this or add an disclaimer to the install section that users shouldn't use the web debug shell.

I leave it up to you if you want to close this issue or investigate. Thank you for the rebuild command, it solved my issue.

@jaredhendrickson13
Copy link
Owner

Actually, the error you received previously does show a valid issue which could be preventing the endpoints from building correctly. The CPU load averages on your system are/were formatted with commas as the decimal separator instead of points as PHP expects them, which is valid for certain regions around the world. Regardless, the logic of the underlying models probably shouldn't prevent the endpoints from being built, so I'll work on a fix for those things.

Thanks!

@jaredhendrickson13 jaredhendrickson13 added bug Something isn't working enhancement Issues or PRs that enhance existing features labels Jul 6, 2024
@jaredhendrickson13 jaredhendrickson13 linked a pull request Jul 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement Issues or PRs that enhance existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants