<commit_before><?php
/* Pi-hole: A black hole for Internet advertisements
*  (c) 2017 Pi-hole, LLC (https://pi-hole.net)
*  Network-wide ad blocking via your own hardware.
*
*  This file is copyright under the latest version of the EUPL.
*  Please see LICENSE file for your rights under this license. */

ob_end_flush();
ini_set("output_buffering", "0");
ob_implicit_flush(true);
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');

function echoEvent($datatext) {
    if(!isset($_GET["IE"]))
      echo "data: ".implode("\ndata: ", explode("\n", $datatext))."\n\n";
    else
      echo $datatext;
}

// Credit: http://stackoverflow.com/a/4694816/2087442
function is_valid_domain_name($domain_name)
{
    return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name) //valid chars check
            && preg_match("/^.{1,253}$/", $domain_name) //overall length check
            && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name)   ); //length of each label
}

// Test if domain is set
if(isset($_GET["domain"]))
{
    // Is this a valid domain?
    $url = $_GET["domain"];
    if(!is_valid_domain_name($url))
    {
        echoEvent("Invalid domain!");
        die();
    }
}
else
{
    echoEvent("No domain provided");
    die();
}

if(isset($_GET["exact"]))
{
    $exact = "-exact";
}
else
{
    $exact = "";
}

$proc = popen("sudo pihole -q ".$url." ".$exact, 'r');
while (!feof($proc)) {
    echoEvent(fread($proc, 4096));
}
?><commit_msg>Modifications to support core queryFunc() changes<commit_after><?php
/* Pi-hole: A black hole for Internet advertisements
*  (c) 2017 Pi-hole, LLC (https://pi-hole.net)
*  Network-wide ad blocking via your own hardware.
*
*  This file is copyright under the latest version of the EUPL.
*  Please see LICENSE file for your rights under this license. */

ob_end_flush();
ini_set("output_buffering", "0");
ob_implicit_flush(true);
header("Content-Type: text/event-stream");
header("Cache-Control: no-cache");
ini_set("pcre.recursion_limit", 1500);

function validate_domain($domain) { // Cr: http://stackoverflow.com/a/4694816
    return (preg_match("/^([a-z\d]((-|_)*[a-z\d])*)(\.([a-z\d]((-|_)*[a-z\d])*))*$/i", $domain) // Valid chars check
        && preg_match("/^.{1,253}$/", $domain) // Overall length check
        && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain)); // Length of each label
}

// Validate domain, if set
if(isset($_GET["domain"])) {
    if(validate_domain($_GET["domain"])) {
        $domain = $_GET["domain"];
    } else {
        die("::: Invalid domain");
    }
} else {
    die("::: Domain query not specified");
}

$exact = isset($_GET["exact"]) ? "-exact" : "";

$proc = popen("sudo pihole -q ".escapeshellarg($domain)." $exact", "r");
while (!feof($proc)) {
    echo fread($proc, 4096);
}
?>
{'fraction_non_alphanumeric': 0.22179125528913962, 'fraction_numerical': 0.02221438645980254, 'mean_word_length': 3.6432078559738135, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1189035', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1002, 'n_words': 229}