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

API call to modify local DNS and CNAME records #2091

Merged
merged 3 commits into from
Feb 7, 2022
Merged

API call to modify local DNS and CNAME records #2091

merged 3 commits into from
Feb 7, 2022

Conversation

goopilot
Copy link

@goopilot goopilot commented Jan 19, 2022

Signed-off-by: Alexandr Salamatov wpgnetworks@gmail.com

By submitting this pull request, I confirm the following: {please fill any appropriate checkboxes, e.g: [X]}

{Please ensure that your pull request is for the 'devel' branch!}

  • I have read and understood the contributors guide, as well as this entire template.
  • I have made only one major change in my proposed changes.
  • I have commented my proposed changes within the code.
  • I have tested my proposed changes.
  • I am willing to help maintain this change if there are issues with it later.
  • I give this submission freely and claim no ownership.
  • It is compatible with the EUPL 1.2 license
  • I have squashed any insignificant commits. (git rebase)
  • I have Signed Off all commits. (git commit --signoff)

What does this PR aim to accomplish?:

Add API call to manage custom DNS and CNAME records

How does this PR accomplish the above?:
Add new DNS record
http://ADDRESSOFPIHOLE/admin/api.php?customdns&action=add&ip=IPADDRESS&domain=youdomain&auth=XXX
Delete existing DNS record
http://ADDRESSOFPIHOLE/admin/api.php?customdns&action=delete&ip=IPADDRESS&domain=youdomain&auth=XXX
List existing DNS records
http://ADDRESSOFPIHOLE/admin/api.php?customdns&action=get&auth=XXX

Add new CNAME record
http://ADDRESSOFPIHOLE/admin/api.php?customcname&action=add&domain=YOURCNAME&target=TARGETDOMAIN&auth=XXX
Delete existing CNAME record
http://ADDRESSOFPIHOLE/admin/api.php?customcname&action=delete&domain=YOURCNAME&target=TARGETDOMAIN&auth=XXX
List existing CNAME records
http://ADDRESSOFPIHOLE/admin/api.php?customcname&action=get&auth=XXX

What documentation changes (if any) are needed to support this PR?:

Alexandr Salamatov added 2 commits January 19, 2022 16:07
Signed-off-by: Alexandr Salamatov <wpgnetworks@gmail.com>
Signed-off-by: Alexandr Salamatov <wpgnetworks@gmail.com>
@goopilot goopilot changed the title API call to modify local DNS records API call to modify local DNS and CNAME records Jan 21, 2022
api.php Outdated Show resolved Hide resolved
Signed-off-by: Alexandr Salamatov <wpgnetworks@gmail.com>
@PromoFaux PromoFaux requested a review from a team February 3, 2022 18:06
@PromoFaux
Copy link
Member

I don't know if I'm missing anything here... but it I just get redirected to the dashboard when making GET requests to the above example API endpoints:

e.g

curl http://localhost/api.php?customdns&action=get&auth=apikeyhere
[1] 30470
[2] 30471
root@pihole-docker:/var/www/html/admin#     <!doctype html>
    <html lang='en'>
        <head>
            <meta charset='utf-8'>
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <title>● localhost</title>
            <link rel='stylesheet' href='/pihole/blockingpage.css'>
            <link rel='shortcut icon' href='/admin/img/favicons/favicon.ico' type='image/x-icon'>
        </head>
        <body id='splashpage'>
            <div id="pihole_card">
              <img src='/admin/img/logo.svg' alt='Pi-hole logo' id="pihole_logo_splash" />
              <p>Pi-<strong>hole</strong>: Your black hole for Internet advertisements</p>
              <a href='/admin'>Did you mean to go to the admin panel?</a>
            </div>
        </body>
    </html>

@PromoFaux
Copy link
Member

I absolutely was missing something (but so were your example URLs - I've updated your OP to reflect)

http://pi.hole/ADMIN/api.php....

After figuring that out, can confirm this does what it says it does

@goopilot
Copy link
Author

goopilot commented Feb 5, 2022

I absolutely was missing something (but so were your example URLs - I've updated your OP to reflect)

http://pi.hole/ADMIN/api.php....

After figuring that out, can confirm this does what it says it does

Thanks and sorry for confusion.

Copy link
Member

@yubiuser yubiuser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we need to document the new API anywhere?

@goopilot
Copy link
Author

goopilot commented Feb 7, 2022

I wonder if we need to document the new API anywhere?

Most likely, however I couldn't find documentation for existing API, could you point me to it?

@yubiuser
Copy link
Member

yubiuser commented Feb 7, 2022

I could not find it, too. We'll have a much better documented API with v6 one day....

@yubiuser yubiuser merged commit 551e2d0 into pi-hole:devel Feb 7, 2022
@pralor-bot
Copy link

This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/pi-hole-ftl-v5-14-web-v5-11-and-core-v5-9-released/53529/1

@jojost1
Copy link

jojost1 commented Feb 14, 2022

@yubiuser Thanks for this. Question: I'm getting a response like this:

{"data":[["testje.testje","192.168.1.68"],["test.test2","192.168.1.42"]]}[]

which is not valid JSON due to the [] at the end.

In theory, something like the response below would be ideal, though just having the [] removed would be enough for now. Is it possible to fix this?

{
    "data": [
        {
            "domain": "testje.testje",
            "ip": "192.168.1.68"
        },
        {
            "domain": "test.test2",
            "ip": "192.168.1.42"
        }
    ]
}

Thanks 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants