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

FEATURE REQUEST: Rest API for AP management #1498

Closed
NL-TCH opened this issue Jan 15, 2024 · 10 comments · Fixed by #1519
Closed

FEATURE REQUEST: Rest API for AP management #1498

NL-TCH opened this issue Jan 15, 2024 · 10 comments · Fixed by #1519

Comments

@NL-TCH
Copy link
Contributor

NL-TCH commented Jan 15, 2024

Is your feature request related to a problem?

No, but with the RestAPI a whole new world of automation opens, like HA integration with automation based on connected clients, etc...

Describe the solution you'd like

A Rest API with functionality like:

  • get connected clients amount
  • list active clients (with details)
  • Shutdown AP/ Start AP
  • Get VPN status/ details
  • Get Adblock status/ details

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.
None

Additional context

Add any other context or screenshots about the feature request here.

@NL-TCH
Copy link
Contributor Author

NL-TCH commented Jan 15, 2024

this is quite a big feature, so idk if this is anything "we" should want

@billz
Copy link
Member

billz commented Jan 15, 2024

Agreed that the level of effort is somewhat non-trivial. However it's a frequently requested feature #1372 #602 #393 (probably more examples) and would indeed make RaspAP more useful for IoT / HA applications.

I've been gradually moving the project toward more PHP class definitions (see contents of /src/RaspAP) so it would make sense for an API to live here. Probably best to start with a few simple endpoints, eg., service status. We could also leverage an existing RESTful API framework, though my preference would be for something lean and minimal rather than a bloated 'kitchen sink' type framework.

@NL-TCH
Copy link
Contributor Author

NL-TCH commented Jan 15, 2024

cool!
Is it an idea, that i will try to create a PoC for an API with python (FastAPI)?
So we have a different script for the API on python than on the already existing webgui (on a different port).
Or do you want to have it per-sé integrated in the php code?

@billz
Copy link
Member

billz commented Jan 15, 2024

Sure, totally open to a non-PHP approach. FastAPI is great, I've played with it a bit in the past.

@NL-TCH
Copy link
Contributor Author

NL-TCH commented Jan 15, 2024

quick update, i have the system info already implemented, moving on to wifi info:

(testing on local machine)
image

the following parts i cannot implement because of having zero knowledge about php:
button in webinterface enables a systemd service (which is already installed, but not running) that runs this API
field in webinterface to let the user input a API key (because the API needs to be exposed to the eth0 interface to be of any use)

i'll continue this weekend

@billz
Copy link
Member

billz commented Jan 16, 2024

That was quick 😅 Re: PHP or implementing API endpoints, generally, I'm happy to give advice and/or contribute code as needed.

@NL-TCH
Copy link
Contributor Author

NL-TCH commented Jan 26, 2024

Hey @billz the API is progressing quite nicely, can i ask to get insider access?
i am implementing the wireguard api, and it would benefit to have API access to view the different configs imo.

what is your opinion on this?

the branch is quite cluttered, but if you're interested, here is the progress: https://github.com/NL-TCH/raspap-docker/tree/API-alpha

@NL-TCH
Copy link
Contributor Author

NL-TCH commented Feb 6, 2024

@billz can you give feedback on the branch?
all the GET requests are implemented, POST requests are only configured for the hostspot, and more are comming.

  • TCH

@billz
Copy link
Member

billz commented Feb 6, 2024

@NL-TCH great! I'll carve out some time and give it a round of testing.

@billz
Copy link
Member

billz commented Feb 6, 2024

Image built successfully. Started the container per usual. The raspap-api.service exited with a path error. Executing the following worked:

root@raspberrypi:/home/API# uvicorn main:app --host 0.0.0.0 --port 8081
insecure
INFO:     Started server process [1511]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8081 (Press CTRL+C to quit)
INFO:     192.168.0.101:50949 - "GET /docs HTTP/1.1" 200 OK
INFO:     192.168.0.101:50952 - "GET /openapi.json HTTP/1.1" 200 OK
INFO:     192.168.0.101:51188 - "GET /ap HTTP/1.1" 200 OK

Opening http://raspberrypi.local:8081/docs loads the interactive FastAPI docs (very nice).

Tried several endpoints - all the ones I tested worked as expected. eg.:

GET http://raspberrypi.local:8081/ap

{
  "driver": "nl80211",
  "ctrl_interface": "/var/run/hostapd",
  "ctrl_interface_group": "0",
  "auth_algs": "1",
  "wpa_key_mgmt": "WPA-PSK",
  "beacon_int": "100",
  "ssid": "raspi-webgui",
  "channel": "1",
  "hw_mode": "g",
  "ieee80211n": "1 # 802.11n support (Raspberry Pi 3)",
  "wpa_passphrase": "ChangeMe",
  "interface": "/var/run/hostapd",
  "wpa": "2",
  "wpa_pairwise": "CCMP",
  "country_code": "GB",
  "ignore_broadcast_ssid": ""
}

Amazing work!

@billz billz pinned this issue Feb 7, 2024
@billz billz moved this to In Progress in @RaspAP's project Feb 10, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in @RaspAP's project Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants