Add a class for better readability of list type within the code

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
Adam Warner
2019-12-08 18:47:08 +00:00
parent 3a0a596b11
commit 258ea04432
5 changed files with 24 additions and 19 deletions

View File

@@ -34,27 +34,27 @@ $db = SQLite3_connect($GRAVITYDB, SQLITE3_OPEN_READWRITE);
switch($list) {
case "white":
echo add_to_table($db, "domainlist", $domains, $comment, false, false, 0);
echo add_to_table($db, "domainlist", $domains, $comment, false, false, ListType::whitelist);
break;
case "black":
echo add_to_table($db, "domainlist", $domains, $comment, false, false, 1);
echo add_to_table($db, "domainlist", $domains, $comment, false, false, ListType::blacklist);
break;
case "white_regex":
echo add_to_table($db, "domainlist", $domains, $comment, false, false, 2);
echo add_to_table($db, "domainlist", $domains, $comment, false, false, ListType::regex_whitelist);
break;
case "white_wild":
echo add_to_table($db, "domainlist", $domains, $comment, true, false, 2);
echo add_to_table($db, "domainlist", $domains, $comment, true, false, ListType::regex_whitelist);
break;
case "black_regex":
echo add_to_table($db, "domainlist", $domains, $comment, false, false, 3);
echo add_to_table($db, "domainlist", $domains, $comment, false, false, ListType::regex_blacklist);
break;
case "black_wild":
echo add_to_table($db, "domainlist", $domains, $comment, true, false, 3);
echo add_to_table($db, "domainlist", $domains, $comment, true, false, ListType::regex_blacklist);
break;
case "audit":

View File

@@ -285,4 +285,9 @@ function remove_from_table($db, $table, $domains, $returnnum=false, $type=-1)
}
}
?>
class ListType{
const whitelist = 0;
const blacklist = 1;
const regex_whitelist = 2;
const regex_blacklist = 3;
}

View File

@@ -55,14 +55,14 @@ function filterArray(&$inArray) {
switch ($listtype)
{
case "white":
$exact = array("whitelist" => getTableContent(0));
$regex = array("regex_whitelist" => getTableContent(2));
$exact = array("whitelist" => getTableContent(ListType::whitelist));
$regex = array("regex_whitelist" => getTableContent(ListType::regex_whitelist));
$list = array_merge($exact, $regex);
break;
case "black":
$exact = array("blacklist" => getTableContent(1));
$regex = array("regex_blacklist" => getTableContent(3));
$exact = array("blacklist" => getTableContent(ListType::blacklist));
$regex = array("regex_blacklist" => getTableContent(ListType::regex_blacklist));
$list = array_merge($exact, $regex);
break;

View File

@@ -27,19 +27,19 @@ $db = SQLite3_connect($GRAVITYDB, SQLITE3_OPEN_READWRITE);
switch($type) {
case "white":
echo remove_from_table($db, "domainlist", $domains, false, 0);
echo remove_from_table($db, "domainlist", $domains, false, ListType::whitelist);
break;
case "black":
echo remove_from_table($db, "domainlist", $domains, false, 1);
echo remove_from_table($db, "domainlist", $domains, false, ListType::blacklist);
break;
case "white_regex":
echo remove_from_table($db, "domainlist", $domains, false, 2);
echo remove_from_table($db, "domainlist", $domains, false, ListType::regex_whitelist);
break;
case "black_regex":
echo remove_from_table($db, "domainlist", $domains, false, 3);
echo remove_from_table($db, "domainlist", $domains, false, ListType::regex_blacklist);
break;
default:

View File

@@ -365,10 +365,10 @@ else
exit("cannot open/create ".htmlentities($archive_file_name)."<br>\nPHP user: ".exec('whoami')."\n");
}
archive_add_table("whitelist.exact.json", "domainlist");
archive_add_table("whitelist.regex.json", "domainlist");
archive_add_table("blacklist.exact.json", "domainlist");
archive_add_table("blacklist.regex.json", "domainlist");
archive_add_table("whitelist.exact.json", "domainlist", ListType::whitelist);
archive_add_table("whitelist.regex.json", "domainlist", ListType::regex_whitelist);
archive_add_table("blacklist.exact.json", "domainlist", ListType::blacklist);
archive_add_table("blacklist.regex.json", "domainlist", ListType::regex_blacklist);
archive_add_table("adlist.json", "adlist");
archive_add_table("domain_audit.json", "domain_audit");
archive_add_file("/etc/pihole/","setupVars.conf");