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

Error undefined index when saving PiHole settings screen for custom DNS upstream servers #1754

Closed
franz-josef-kaiser opened this issue Mar 1, 2021 · 17 comments · Fixed by #1970

Comments

@franz-josef-kaiser
Copy link

franz-josef-kaiser commented Mar 1, 2021

Versions

# pihole -v
  Pi-hole version is v5.2.4 (Latest: v5.2.4)
  AdminLTE version is v5.4 (Latest: v5.4)
  FTL version is v5.7 (Latest: v5.7)

Platform

  • OS and version:
# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal
  • Platform:
    • Raspberry Pi 4
# php -v
PHP 7.4.15 (cli) (built: Feb 23 2021 15:12:26) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies

Expected behavior

When adding custom Upstream DNS Servers (one IPv4 and one IPv6 address), the addresses get saved without an error.

Actual behavior / bug

When saving the Upstream DNS Servers with only one IPv4 address 127.0.0.1#53000 in the Custom 1 (IPv4) field and one IPv6 address ::1#53000 in the Custom 3 (IPv6) field, an error message gets rendered in a red box above the settings.

There was a problem applying your settings.
Debugging information:
PHP error (2): Undefined array key "v6_2" in /var/www/html/admin/scripts/pi-hole/php/savesettings.php:276

Steps to reproduce

Steps to reproduce the behavior:

Note: Everything is set up using the GUI. The setupVars.conf does not have any PIHOLE_DNS_${i} entries. The settings.php data loading is not applied.

  1. Go to Settings
  2. Open DNS Tab
  3. Empty the Upstream DNS Servers checkboxes for all predefined (source: /etc/pihole/dns-servers.conf).
  4. Save settings by using the blue Save button at the end of the settings page
  5. See error
# Demonstration purpose only!
# If you want to replay this: Replace domain `pi.hole` with your local domain pointing to the PiHole server.
# Cookie, etc. should be available.
curl 'http://pi.hole/admin/settings.php?tab=dns' \
  -H 'Connection: keep-alive' \
  -H 'Pragma: no-cache' \
  -H 'Cache-Control: no-cache' \
  -H 'Upgrade-Insecure-Requests: 1' \
  -H 'Origin: http://pi.hole' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36' \
  -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
  -H 'Referer: http://pi.hole/admin/settings.php?tab=dns' \
  -H 'Accept-Language: de-AT,de;q=0.9,en-GB;q=0.8,en;q=0.7,cs-CZ;q=0.6,cs;q=0.5,de-DE;q=0.4,en-US;q=0.3' \
  -H 'Cookie: persistentlogin=938f9b281b8efgfgfg4aec769690e1621cfcweqwwqw64390979db3a4b4781c; PHPSESSID=3vra222n0s979kbqwqfasalotpui' \
  --data-raw 'custom1val=&custom2=Customv4&custom2val=127.0.0.1%2353000&custom3val=&custom4=Customv6&custom4val=%3A%3A1%2353000&DNSinterface=all&DNSrequiresFQDN=on&DNSbogusPriv=on&field=DNS&token=z3qMsntRL43fzSeq%2Ff2XCh%2BTSn4a4XBvnrg%2FfYpbU%2Bg%3D' \
  --compressed \
  --insecure

Screenshots

Screen Shot of the admin Web GUI Settings page with DNS tab open and an error message stating the array key 6_2 is not defined

Additional context

I want to set up a local DNS cache, hence the custom DNS Upstream servers. The Cache itself then delegates further. PiHole does not need to know more than the local host IP addresses, for both IPv6 and IPv4, and the port.

@franz-josef-kaiser
Copy link
Author

franz-josef-kaiser commented Mar 1, 2021

This is the actual error that needs to get fixed:

  • The error message states that the error appears in savesettings.php L#276.
    ⚠️ The array_key_exists() check is prefixed with an @ error control operator that should suppress the error, but does not work. The reason probably is, that the severity level gets set to 0, but as the settings.php handler script calls error_get_last() here, the error still gets fetched and printed to the screen.
    Note: Error control/ suppression does not stop errors from ending up in the error handlers or in logs. They just don't get thrown. In other words: This is no valid error suppression and the code needs to get fixed.
    This might be something that changes in PHP 8 tough.

Some notes to help later readers as I took a quick look at the source of the problem:

  • The DNSServerList global that gets looped is built up using readDNSserversList().
  • The readDNSserversList() function loads its data from /etc/pihole/dns-servers.conf.
  • The actual loop searches for keys of the "DNSserver".str_replace(".","_",$value[$type]) format inside the $_POST data array:
    DNSserver9.9.9.9: true
    DNSserver149.112.112.112: true
    DNSserver2620:fe::fe: true
    DNSserver2620:fe::9: true
    
    This does not work for custom entries, which get send like this:
    custom1val: 127.0.0.1#53000
    custom2val: 
    custom3val: ::1#53000
    custom4val: 
    

I noticed that the /etc/pihole/dns-servers.conf entries for IPv4 only Upstream DNS server providers, have a missing ; semicolon, so they won't end up in the 6_2 array key either:

Google (ECS);8.8.8.8;8.8.4.4;2001:4860:4860:0:0:0:0:8888;2001:4860:4860:0:0:0:0:8844
OpenDNS (ECS, DNSSEC);208.67.222.222;208.67.220.220;2620:119:35::35;2620:119:53::53
Level3;4.2.2.1;4.2.2.2;;
Comodo;8.26.56.26;8.20.247.20;;
DNS.WATCH;84.200.69.80;84.200.70.40;2001:1608:10:25:0:0:1c04:b12f;2001:1608:10:25:0:0:9249:d69b
Quad9 (filtered, DNSSEC);9.9.9.9;149.112.112.112;2620:fe::fe;2620:fe::9
Quad9 (unfiltered, no DNSSEC);9.9.9.10;149.112.112.10;2620:fe::10;2620:fe::fe:10
Quad9 (filtered + ECS);9.9.9.11;149.112.112.11;2620:fe::11;2620:fe::fe:11
Cloudflare;1.1.1.1;1.0.0.1;2606:4700:4700::1111;2606:4700:4700::1001

UI The error HTML Element:

    <div id="alError" class="alert alert-danger alert-dismissible fade in" role="alert">
        <button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span>
        </button>
        <h4><i class="icon fa fa-ban"></i> Error</h4>
        There was a problem applying your settings.<br>Debugging information:<br>PHP error (2): Undefined array key &quot;v6_2&quot; in /var/www/html/admin/scripts/pi-hole/php/savesettings.php:276    </div>

@kacnje
Copy link

kacnje commented Oct 11, 2021

I have Pi-hole v5.5, FTL v5.10.2, Web Interface v5.7 and when I try to change an Upstream DNS server, I also the same error.
Is this a bug?

@DenyDarko
Copy link

This is a php8.0 issue (and it's still valid)
It doesn't appear on previous PHP releases.

@franz-josef-kaiser
Copy link
Author

@DenyDarko please read the first paragraph of my last comment. It's independent of the PHP version as it's root is in how error suppression works (and does not work) in PHP.

@DenyDarko
Copy link

@DenyDarko please read the first paragraph of my last comment. It's independent of the PHP version as it's root is in how error suppression works (and does not work) in PHP.

Hey Franz!

I really don't have deep knowledge in how PHP suppression works. I just commenting on what I saw. In 7.3 the error doesn't show up (while it's still there I assume), when 8.0.11 is installed, the error pop up on the screen.

@alex-phipps
Copy link

image

Just spun up a second instance and just been faced with the same error (HA setup, primary server appears unaffected)

@pralor-bot
Copy link

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

https://discourse.pi-hole.net/t/finding-pi-hole-ip-addresses-after-v5-4-update/49712/61

@bcutter
Copy link

bcutter commented Nov 9, 2021

Happens whenever hitting Save, so even without changing anything. Therefore not limited to "custom DNS upstream server changes". Topic title and description could be adjusted.

@franz-josef-kaiser franz-josef-kaiser changed the title Error undefined index when saving custom DNS upstream servers in PiHole settings Error undefined index when saving PiHole settings screen for custom DNS upstream servers Nov 11, 2021
@franz-josef-kaiser
Copy link
Author

@bcutter adjusted.

@KweebIT
Copy link

KweebIT commented Nov 11, 2021

Any luck with finding a solution to fix this?

I am running an Ubuntu server VM on my Unraid box and this the error code it is throwing me.

I even made a brand new VM and still the same.

Any ideas?

@DL6ER
Copy link
Member

DL6ER commented Nov 12, 2021

Sorry this has slipped though so long. It really looks to be an issue with PHP 8 as mentioned by a few of you before. I wasn't able to reproduce this on my development system (PHP 7.4.3) even when removing the error suppression (@). Accordingly, I prepared a fix based solely on the issue description here and, hence, I depend on testing of you to see if it is fixed.

Please try

pihole checkout web fix/v6_2

if your not using a Docker container. In case you are all using Docker, I could also generate a custom Docker container.

@DL6ER DL6ER linked a pull request Nov 12, 2021 that will close this issue
8 tasks
@jbpickrell
Copy link

Awesome worked ... the pihole checkout web fix was able to fix the issue and save the custom DNS entry.

You guys wrote an amazing piece of software and I can speak for the masses when I say Thank You...

@dowden20
Copy link

dowden20 commented Nov 20, 2021

pihole checkout web fix/v6_2

this fixes DNS setting save error.
now if go to Whitelist, Blacklist, Clients, Adlists, they are all showing no entry.
I checked from sqlite, the records still exists.

shown on the bottom page:

Pi-hole v5.6
FTL v5.11
Web Interface vDev (fix/v6_2, v5.8-36-g0c00ea9)

to fix this, i did:
pihole checkout web master

@DL6ER
Copy link
Member

DL6ER commented Nov 20, 2021

@dowden20 This other bug comes from another bug fixed by @yubiuser
I rebased the branch fix/v6_2 on most recent devel, could you try the checkout command again?

@dowden20
Copy link

dowden20 commented Nov 20, 2021

$ pihole checkout web fix/v6_2
  Please note that changing branches severely alters your Pi-hole subsystems
  Features that work on the master branch, may not on a development branch
  This feature is NOT supported unless a Pi-hole developer explicitly asks!
  Have you read and understood this? [y/N] y

  [✓] Fetching branches from https://github.com/pi-hole/AdminLTE.git
  [i] 29 branches available for Web Admin

  [✓] Switching to branch: 'fix/v6_2' from 'refs/heads/master'
fatal: Not possible to fast-forward, aborting.

@DL6ER

update:

 pihole checkout dev
 pihole checkout web fix/v6_2

this fixes both issues

$ pihole -v
  Pi-hole version is development v5.6-6-gcdd4d9ea (Latest: v5.6)
  AdminLTE version is fix/v6_2 v5.8-36-g0c00ea9 (Latest: v5.8)
  FTL version is development vDev-0d44449 (Latest: v5.11)
$ pihole -up
  [✓] Update local cache of available packages
  [i] Existing PHP installation detected : PHP version 8.0.8
  [✓] Checking for git
  [✓] Checking for iproute2
  [✓] Checking for whiptail
  [✓] Checking for ca-certificates

  [i] Checking for updates...
  [i] Pi-hole Core:     up to date
  [i] Web Interface:    update available
  [i] FTL:              up to date

  [i] Pi-hole Web Admin files out of date, updating local repo.
  [✓] Check for existing repository in /var/www/html/admin
  [i] Update repo in /var/www/html/admin...
  : Could not update local repository. Contact support.

@yubiuser
Copy link
Member

yubiuser commented Jan 1, 2022

Fix released with

#1970

@yubiuser yubiuser closed this as completed Jan 1, 2022
@franz-josef-kaiser
Copy link
Author

@yubiuser @DL6ER Thanks a lot for the fix!

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

Successfully merging a pull request may close this issue.