AdguardTeam / AdGuardHome

Network-wide ads & trackers blocking DNS server
https://adguard.com/adguard-home.html
GNU General Public License v3.0
24.63k stars 1.78k forks source link

RESTful API: GET /dhcp/interfaces respond Content-Type as text/plain rather than application/json #5716

Closed sky96111 closed 1 year ago

sky96111 commented 1 year ago

Prerequisites

Operating system type

Linux, Other (please mention the version in the description)

CPU architecture

AMD64

Installation

GitHub releases or script from README

Setup

On one machine

AdGuard Home version

v0.108.0-b.33

Description

What did you do?

curl -vv --request GET \
    --url http://127.0.0.1:8080/control/dhcp/interfaces \
    --header 'Authorization: Basic ******************'

Expected result

respond

......
< HTTP/1.1 200 OK
< Content-Length: 430
< Content-Type: application/json; charset=utf-8
< 
......

Actual result

respond

......
< HTTP/1.1 200 OK
< Content-Length: 430
< Content-Type: text/plain; charset=utf-8
< 
......

Screenshots (if applicable)

Additional information

sky96111 commented 1 year ago

I also find other API respond wrong Content-Type:

/control/version.json

Maybe there are more wrong API responds, I will check them when I available

sky96111 commented 1 year ago

I also find other API respond wrong Content-Type:

/control/version.json

Maybe there are more wrong API responds, I will check them when I available

I tested most APIs, and seems only the two APIs are wrong

ainar-g commented 1 year ago

@sky96111, thanks for reporting and investigating! This should be fixed in the most recent Edge build. Could you please check?

sky96111 commented 1 year ago

Thanks for your fix! Now /dhcp/interfaces respond right Content-Type. While seems /control/version.json still respond as text/plain edge version: v0.108.0-a.539+d6043e23

*   Trying 192.168.122.62:8080...
* Connected to 192.168.122.62 (192.168.122.62) port 8080 (#0)
> GET /control/version.json HTTP/1.1
> Host: 192.168.122.62:8080
> User-Agent: curl/8.0.1
> Accept: */*
> Authorization: Basic ********
> 
< HTTP/1.1 200 OK
< Date: Wed, 19 Apr 2023 14:44:55 GMT
< Content-Length: 233
< Content-Type: text/plain; charset=utf-8
< 
{"new_version":"v0.108.0-a.539+d6043e23","announcement":"AdGuard Home v0.108.0-a.539+d6043e23 is now available!","announcement_url":"https://github.com/AdguardTeam/AdGuardHome/wiki/Platforms","can_autoupdate":false,"disabled":false}
* Connection #0 to host 192.168.122.62 left intact
ainar-g commented 1 year ago

You are correct, and it seems like there were two bugs here. The latest Edge build, v0.108.0-a.540+757ddb06, should fix that one as well.

sky96111 commented 1 year ago

Great! It now work correctly!

Vendo232 commented 1 year ago

Hello, I would like to call/ trigger Adguard service from Home Assistant. e.g. turn ON/OFF Youtube blocking for my kids. image

I did see this page but it is beyond my comprehansion , could you help me here with a clue how to get the Restful API call link? https://github.com/AdguardTeam/AdGuardHome/tree/master/openapi

sky96111 commented 1 year ago

You can clone this repo and run command below

yarn
yarn start

in AdGuardHome/openapi

Then surfing http://localhost:4000/#tag/blocked_services for detailed API for blocked_services.

To set YouTube in blocked_service, you should use method: POST /blocked_services/set with application/json payload

[
  "youtube"
]

If success, it respond 200 OK

Hello, I would like to call/ trigger Adguard service from Home Assistant. e.g. turn ON/OFF Youtube blocking for my kids. image

I did see this page but it is beyond my comprehansion , could you help me here with a clue how to get the Restful API call link? https://github.com/AdguardTeam/AdGuardHome/tree/master/openapi

Vendo232 commented 1 year ago

thank you @sky96111 , I` running AdGuard Home in LXC container on Proxmox using Alpine Linux. It seems the openapi.yaml does not work with this user case.

image

sky96111 commented 1 year ago

@Vendo232 You'd better to open up another new Discussion https://github.com/AdguardTeam/AdGuardHome/discussions . It seems that you missed some dependencies. Did you run yarn (install) before yarn start?