From 4fa1cb6bacdf2a4f004b4517311dee33feaf6ae8 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 29 Apr 2017 20:52:58 +0200 Subject: [PATCH] Clip too long domain names. Fixes #464 --- scripts/pi-hole/php/teleporter.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/pi-hole/php/teleporter.php b/scripts/pi-hole/php/teleporter.php index 65701d0f..53cf28e4 100644 --- a/scripts/pi-hole/php/teleporter.php +++ b/scripts/pi-hole/php/teleporter.php @@ -14,6 +14,13 @@ if (php_sapi_name() !== "cli") { check_csrf(isset($_POST["token"]) ? $_POST["token"] : ""); } +function limit_length(&$item, $key) +{ + // limit max length for a domain entry to 100 chars + // return only a part of the string if it is longer + $item = substr($item, 0, 100); +} + function process_zip($name) { global $zip; @@ -29,6 +36,12 @@ function process_zip($name) } fclose($zippointer); $domains = array_filter(explode("\n",$contents)); + + // Walk array and apply a max string lenght + // function to every member of the array of domains + array_walk($array, "limit_length"); + + // Check validity of domains (after possible clipping) check_domains($domains); return $domains; }