External links in the pihole menu


#1

Since the feature request to add external links to the pihole menu has obviously been denied, here is the solution to add it yourself. Unfortunately, pihole -up and pihole -r will kill the change, so you need to implement it every time. To make this less time consuming, a script is included to make the change for you.

TESTED ON Pi-hole Version v4.1.1 Web Interface Version v4.1.1 FTL Version v4.1.2

STEP 1: create a new php script /var/www/html/admin/scripts/pi-hole/php/externalurl.php, content:

<li class="treeview active">
	<a href="#">
		<span class="pull-right-container">
			<i class="fa fa-angle-down pull-right" style="padding-right: 5px;"></i>
		</span>
		<i class="fa fa-folder"></i> <span>External Links</span>
	</a>
    <ul class="treeview-menu">
		<?php
		if(file_exists("/etc/pihole/links.conf")) {
			$file = fopen("/etc/pihole/links.conf", "r") or exit("Unable to open file!");
			while(!feof($file)) {
				$array = explode(',', fgets($file));
				?>
				<li>
					<a href="<?php echo "$array[1]"; ?>" target="_blank">
					<i class="fa fa-newspaper-o"></i> <span><?php echo "$array[0]"; ?></span>
					</a>
				</li>			
			<?php
			}
			fclose($file);
		}
		?>		
	</ul>
</li>				

STEP2: create the configuration file /etc/pihole/links.conf, populated with the links you want. Example:

discourse,https://discourse.pi-hole.net/latest/
reddit,https://www.reddit.com/r/pihole/
docs,https://docs.pi-hole.net/
webmin,https://192.168.2.57:10000/
sql browser,http://192.168.2.57/phpliteadmin.php

Syntax: name, url
The separator is a comma
There should NOT be a new line after the last entry, as it will create an empty menu item.
The webmin installation is explained here , section 4.11
The sql browser installation is explained here .

STEP 3: run this script (sudo) to make the necessary changes to /var/www/html/admin/scripts/pi-hole/php/header.php, content:

#!/bin/bash

file=/var/www/html/admin/scripts/pi-hole/php/header.php
line=$(grep "<!-- External Links -->" $file)
if [ $? -eq 1 ]; then
	echo "added"
	sudo sed -i 's/<!-- Donate -->/<!-- External Links -->\n&/' $file
	sudo sed -i 's/<!-- Donate -->/<?php include "scripts\/pi-hole\/php\/externalurl.php"; ?>\n&/' $file
fi

Doneā€¦
The result:

Beware, discourse sometimes changes double quotes into something else, when copy / pasting the content, so check your copy well!!!

edit
the necessary files can now be retrieved from github
/edit


External links entry in the pihole menu