Skip to content

Instantly share code, notes, and snippets.

@chetcuti
Created February 3, 2019 18:45
Show Gist options
  • Save chetcuti/d27321624889fd49874b769e6401097b to your computer and use it in GitHub Desktop.
Save chetcuti/d27321624889fd49874b769e6401097b to your computer and use it in GitHub Desktop.
Pi-hole Whitelist & Blacklist Addition Script
<?php
// Bookmark: javascript:void(window.open('http://pi.hole/add.php?action=w&url='+location.href, '_blank'));
// Modify the above URL accordingly
// Whitelist: action=w
// Blacklist: action=b
$action = $_GET['action'];
if (isset($_GET['url'])) {
if (isset($_GET['w'])) $action .= " -d";
$url = parse_url($_GET['url'], PHP_URL_HOST);
if (substr($url, 0, 4) === 'www.') {
$urls[0] = $url;
$urls[1] = substr($url, 4);
} else {
$urls[0] = $url;
$urls[1] = 'www.' . $url;
}
foreach ($urls AS $each_url) {
exec("sudo pihole -$action $each_url", $output, $status);
}
print("<pre>");
for ($i = 0; $i < sizeof($output); $i++) {
print(str_replace("\u{001b}[K", "", $output[$i]) . "<br />\n");
}
print("</pre>");
if (!isset($_GET['w'])) {
$wl_or_bl = ($action === 'w' ? 'WHITELIST' : 'BLACKLIST'); ?>
<p><input type="button" value="UNDO ACTION (REMOVE DOMAIN FROM <?php echo $wl_or_bl; ?>)"
onclick="location.href=location.href+'&w';"/></p><?php
}
} else {
print("Something went wrong. Please try again.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment