<commit_before><?php
function pi_log($message) {
    error_log($message . "\n", 3, '/var/log/lighttpd/pihole_php.log');
}

function die_and_log($message) {
    pi_log($message);
    die($message);
}

if(!isset($_POST['domain'], $_POST['list'], $_POST['token'])) {
    die_and_log("Missing POST variables");
}

$AUTHORIZED_HOSTNAMES = [
    $_SERVER['SERVER_ADDR'],
    'pi.hole'
];

// Check CORS
$CORS_ALLOW_ORIGIN = false;
if(in_array($_SERVER['HTTP_ORIGIN'], $AUTHORIZED_HOSTNAMES)) {
    $CORS_ALLOW_ORIGIN = $_SERVER['HTTP_ORIGIN'];
} else if(in_array($_SERVER['HTTP_HOST'], $AUTHORIZED_HOSTNAMES)) {
    $CORS_ALLOW_ORIGIN = $_SERVER['HTTP_HOST'];
}

if (!$CORS_ALLOW_ORIGIN)
    die_and_log("Failed CORS");

header("Access-Control-Allow-Origin: $CORS_ALLOW_ORIGIN");

session_start();

// Check CSRF token
if(!hash_equals($_SESSION['token'], $_POST['token']))
    die_and_log("Wrong token");


switch($_POST['list']) {
    case "white":
        exec("sudo pihole -w -q ${_POST['domain']}");
        break;
    case "black":
        exec("sudo pihole -b -q ${_POST['domain']}");
        break;
}

?><commit_msg>re-add -d flag that got lost somehow<commit_after><?php
function pi_log($message) {
    error_log($message . "\n", 3, '/var/log/lighttpd/pihole_php.log');
}

function die_and_log($message) {
    pi_log($message);
    die($message);
}

if(!isset($_POST['domain'], $_POST['list'], $_POST['token'])) {
    die_and_log("Missing POST variables");
}

$AUTHORIZED_HOSTNAMES = [
    $_SERVER['SERVER_ADDR'],
    'pi.hole'
];

// Check CORS
$CORS_ALLOW_ORIGIN = false;
if(in_array($_SERVER['HTTP_ORIGIN'], $AUTHORIZED_HOSTNAMES)) {
    $CORS_ALLOW_ORIGIN = $_SERVER['HTTP_ORIGIN'];
} else if(in_array($_SERVER['HTTP_HOST'], $AUTHORIZED_HOSTNAMES)) {
    $CORS_ALLOW_ORIGIN = $_SERVER['HTTP_HOST'];
}

if (!$CORS_ALLOW_ORIGIN)
    die_and_log("Failed CORS");

header("Access-Control-Allow-Origin: $CORS_ALLOW_ORIGIN");

session_start();

// Check CSRF token
if(!hash_equals($_SESSION['token'], $_POST['token']))
    die_and_log("Wrong token");


switch($_POST['list']) {
    case "white":
        exec("sudo pihole -w -q -d ${_POST['domain']}");
        break;
    case "black":
        exec("sudo pihole -b -q -d ${_POST['domain']}");
        break;
}

?>
{'fraction_non_alphanumeric': 0.19796730004418914, 'fraction_numerical': 0.0008837825894829872, 'mean_word_length': 4.617866004962779, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '2036272', 'n_tokens_mistral': 872, 'n_tokens_neox': 865, 'n_words': 136}