";
//echo "\$category['$value'] = 'zzz';
\n";
//$x++;
//}
//unset($x);
//echo "
";
//print_r($_POST["blacklist"]);
//echo "
";
//foreach($_POST["blacklist"] as $key => $value) {
//echo "name: ".$value."
";
//$x++;
//}
if (count($_POST)>0) {
conf_mount_rw();
$dnsmasqfile = "/usr/local/etc/dnsmasq.conf";
$targetfile = "/usr/local/etc/dnsmasq.blacklist.conf";
$includestring = "conf-file=/usr/local/etc/dnsmasq.blacklist.conf";
$dnsmasqconf = "/usr/local/etc/dnsmasq.conf";
//clear previous values
foreach($category as $key => $value) {
$config['installedpackages']['dnsblacklist']['config'][0][$key] = '';
}
if ($_POST['enable'] == 1) {
//echo "enabled";
$config['installedpackages']['dnsblacklist_settings']['config'][0]['enable'] = 1;
}
else {
//echo "disabled";
$config['installedpackages']['dnsblacklist_settings']['config'][0]['enable'] = 0;
}
//add the include entry for dnsmasq.blacklist.conf to dnsmasq.conf
if (file_exists($dnsmasqfile)) {
$getdnsmasq = file_get_contents($dnsmasqfile);
if(stristr($getdnsmasq,'conf-file=/usr/local/etc/dnsmasq.blacklist.conf') === TRUE) {
//include found no need to add it
}
else {
$myfhandle = fopen($dnsmasqconf, 'r+');
fwrite($myfhandle, $includestring);
fclose($myfhandle);
}
}
else {
$my2fhandle = fopen($dnsmasqconf, 'x+');
fwrite($my2fhandle, $includestring);
fclose($my2fhandle);
}
//truncate the dnsmasq.blacklist.conf file
if (file_exists($targetfile)) {
$fh = fopen($targetfile, 'w');
fclose($fh);
}
//build the dnsmasq.blacklist.conf
if (count($_POST["blacklist"]) > 0) {
foreach($_POST["blacklist"] as $value) {
//set the current selected values
$blackfile = "blacklists/$value/domains";
$config['installedpackages']['dnsblacklist']['config'][0][$value] = 1;
//if enabled write the selected categories to the dnsmasq.blacklist.conf
if ($config['installedpackages']['dnsblacklist_settings']['config'][0]['enable'] == 1) {
$fh2 = fopen($targetfile, 'a');
$fh = fopen($blackfile,'r');
while($line=fgets($fh)) {
//remove all characters other than alpha numeric period and dash
preg_match("/([a-zA-Z0-9.-]*)/i", $line, $arraymatches);
$line = $arraymatches[1];
fwrite($fh2, "address=/" .$line. "/74.125.45.100". "\n");
}
fclose($fh);
fclose($fh2);
}
}
}
write_config();
services_dnsmasq_configure();
sleep(1);
$savemsg_dnsb = "DNS Blacklist settings have been saved. ";
conf_mount_ro();
}
?>
Services: DNS Blacklist