Add domain to AUTHORIZED_HOSTNAMES permanently?

Please follow the below template, it will help us to help you!

Expected Behaviour:

I access my Pi-hole admin interfaces from pihole.mydomain.net and pihole2.mydomain.net (I own the domain but these are accessible from the LAN only, via /etc/hosts). To pass the CORS check and be able to update any settings, I have to first edit /var/www/html/admin/scripts/pi-hole/php/auth.php and add each domain to the $AUTHORIZED_HOSTNAMES array manually. Whenever the web interface is updated, however, auth.php is overwritten and I have to re-add my domains. Is there a persistent array somewhere that I can add my domains, so that updates to the web interface don't require manual modification every time?

Actual Behaviour:

As above, the $AUTHORIZED_HOSTNAMES array, as part of auth.php, is overwritten every time the web interface is updated, and I have to manually re-add my domains.

Debug Token:

None created at this time.

You could add bookmarks with the IP's - http://192.168.0.100/admin

sudo sed -i '/$AUTHORIZED_HOSTNAMES =/!{p;d;};n;n;n;n;n;n;aarray_push($AUTHORIZED_HOSTNAMES,"pihole.mydomain.net","pihole2.mydomain.net");' /var/www/html/admin/scripts/pi-hole/php/auth.php

Make a script or Bash alias so that whenever you pihole -up, you run this command too.

This assumes $AUTHORIZED_HOSTNAMES is 7 lines long. This variable hasn't been updated in 4 years so I would call this a long-term solution. The better way would be to find the magic sed syntax to find the end of the declaration instead of counting 7 lines.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.