From 268a257deb2a3d22ddfe3ccd99c9002b46fb0f18 Mon Sep 17 00:00:00 2001 From: mcrane Date: Fri, 2 Oct 2009 12:15:18 -0600 Subject: Introducing a dnsblacklist a new package created by the collaboration of xa0z and mcrane. --- config/dnsblacklist/dnsblacklist.inc | 143 ++++++++++++++++ config/dnsblacklist/dnsblacklist.tmp | 199 ++++++++++++++++++++++ config/dnsblacklist/dnsblacklist.tmp.old | 276 +++++++++++++++++++++++++++++++ config/dnsblacklist/dnsblacklist.xml | 116 +++++++++++++ 4 files changed, 734 insertions(+) create mode 100644 config/dnsblacklist/dnsblacklist.inc create mode 100644 config/dnsblacklist/dnsblacklist.tmp create mode 100644 config/dnsblacklist/dnsblacklist.tmp.old create mode 100644 config/dnsblacklist/dnsblacklist.xml (limited to 'config/dnsblacklist') diff --git a/config/dnsblacklist/dnsblacklist.inc b/config/dnsblacklist/dnsblacklist.inc new file mode 100644 index 00000000..8aa3a9e5 --- /dev/null +++ b/config/dnsblacklist/dnsblacklist.inc @@ -0,0 +1,143 @@ +10^x|1024->2^x] + $s=array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'); + $e=floor(log($bytes,$convention)); + return round($bytes/pow($convention,$e),2).' '.$s[$e]; +} + + +function phpservice_sync_package_php() +{ + + global $config; + + conf_mount_rw(); + config_unlock(); + + + conf_mount_ro(); + + +} + + +function php_sync_package() +{ + global $config; + phpservice_sync_package_php(); +} + + +function php_install_command() +{ + + global $config; + conf_mount_rw(); + config_lock(); + + if (!is_dir('/usr/local/www/packages/')) { + exec("mkdir /usr/local/www/packages/"); + } + + if (!is_dir('/usr/local/www/packages/dnsblacklist/')) { + exec("mkdir /usr/local/www/packages/dnsblacklist/"); + } + + //extract the blacklist + exec("cp /tmp/blacklists.tar.gz /usr/local/www/packages/dnsblacklist/blacklists.tar.gz"); + chdir("/usr/local/www/packages/dnsblacklist/"); + exec("tar xvf blacklists.tar.gz"); + exec("rm /tmp/blacklists.tar.gz"); + exec("rm /usr/local/www/packages/dnsblacklist/blacklists.tar.gz"); + + //rename PHP files from .tmp to .php + exec("cp /tmp/dnsblacklist.tmp /usr/local/www/packages/dnsblacklist/dnsblacklist.php"); + unlink_if_exists("/tmp/phpservice_php.tmp"); + + //write_rcfile(array( + // "file" => "phpservice.sh", + // "start" => "/usr/local/bin/php /usr/local/pkg/phpservice.php >> /var/log/phpservice.log &", + // "stop" => "rm /tmp/phpmonitor.pid" + // ) + //); + + //php_sync_package(); + //$handle = popen("/usr/local/etc/rc.d/phpservice.sh start", "r"); + //pclose($handle); + + //if (pkg_is_service_running('phpservice')) { + //documentation purposes + //} + + conf_mount_ro(); + config_unlock(); + +} + + +function deinstall_command() +{ + conf_mount_rw(); + config_lock(); + exec("rm -R /usr/local/www/packages/dnsblacklist/"); + + $handle = popen("/usr/local/etc/rc.d/dnsblacklist.sh stop", "r"); + unlink_if_exists("/usr/local/pkg/dnsblacklist.xml"); + unlink_if_exists("/usr/local/pkg/dnsblacklist.inc"); + unlink_if_exists("/usr/local/etc/rc.d/dnsblacklist.sh"); + conf_mount_ro(); + config_unlock(); +} + +?> \ No newline at end of file diff --git a/config/dnsblacklist/dnsblacklist.tmp b/config/dnsblacklist/dnsblacklist.tmp new file mode 100644 index 00000000..6f80bc00 --- /dev/null +++ b/config/dnsblacklist/dnsblacklist.tmp @@ -0,0 +1,199 @@ +"; + //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) { + $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)) { + fwrite($fh2, "address=/" .trim($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. Restart dnsmasq service under 'Status' then 'Services' to make the settings active."; +} +?> + + +

Services: DNS Blacklist

+
+ +\n"; +} +else { + echo "\n"; +} +?> + +Enable DNS Blacklist

+ +\n"; + if ($config['installedpackages']['dnsblacklist']['config'][0][$key] == 1) { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + else { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + echo "\n"; + $x++; +} +echo "
+ + +Below is a scroll-box filled with categories you can select to be added to your blacklist.

Each category has a list of known domains/sites that will be denied access by users of this network. +

(Note: Using all categories at once will require 300Mb of free memory. The adult and porn categories are rather memory intensive, requiring 200Mb together.) +


+ + +
+\n"; +foreach($category as $key => $value) { + $domain_count = line_number("blacklists/$key/domains"); + echo "
".$value['name_en']."".$value['desc_en']."($domain_count domains)".$value['name_en']."".$value['desc_en']."($domain_count domains)
\n"; + +?> + +
+
+ + "Edit Category", ); +////$tmp_category = str_replace(" ", " ", $category); +//echo "\n"; +?> + + + + + + +
+ + + + + \ No newline at end of file diff --git a/config/dnsblacklist/dnsblacklist.tmp.old b/config/dnsblacklist/dnsblacklist.tmp.old new file mode 100644 index 00000000..e9fadf57 --- /dev/null +++ b/config/dnsblacklist/dnsblacklist.tmp.old @@ -0,0 +1,276 @@ +"; + //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) { + $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)) { + fwrite($fh2, "address=/" .trim($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."; +} +?> + + +

Services: DNS Blacklist

+
+ +\n"; +} +else { + echo "\n"; +} +?> + +Enable DNS Blacklist

+ +\n"; + if ($config['installedpackages']['dnsblacklist']['config'][0][$key] == 1) { + // echo "\n"; + } + else { + // echo " \n"; + } + echo "\n"; + $x++; +} +echo "
+ + +Below is a scroll-box filled with categories you can select to be added to your blacklist.

Each category has a list of known domains/sites that will be denied access by users of this network. +

(Note: Using all categories at once will require 300Mb of free memory. The adult and porn categories are rather memory intensive, requiring 200Mb together.) +


+ +function ListFiles($dir) { + + if($dh = opendir($dir)) { + + $files = Array(); + $inner_files = Array(); + + while($file = readdir($dh)) { + if($file != "." && $file != ".." && $file[0] != '.') { + if(is_dir($dir . "/" . $file)) { + array_push($files, $dir); + //$inner_files = ListFiles($dir . "/" . $file); + //if(is_array($inner_files)) $files = array_merge($files, $inner_files); + } else { + //array_push($files, $dir . "/" . $file); + } + } + } + + closedir($dh); + return $files; + } +} + + +foreach (ListFiles('/usr/local/www/packages/dnsblacklist/') as $key=>$file){ + echo $file ."
\n"; +} + + + +
+\n"; +foreach($category as $key => $value) { + $domain_count = line_number("blacklists/$key/domains"); + //echo "name: ".$key."
"; + echo "
$key$value($domain_count domains)$key$value($domain_count domains)
\n"; +*/ +?> + +
+
+ + "Edit Category", ); +////$tmp_category = str_replace(" ", " ", $category); +//echo "\n"; +?> + + + + + + +
+ + + + + \ No newline at end of file diff --git a/config/dnsblacklist/dnsblacklist.xml b/config/dnsblacklist/dnsblacklist.xml new file mode 100644 index 00000000..10e330ec --- /dev/null +++ b/config/dnsblacklist/dnsblacklist.xml @@ -0,0 +1,116 @@ + + + + + + + + DNS Blacklist + Describe your package requirements here + Currently there are no FAQ items provided. + DNS Blacklist Settings + 0.1 + Settings + /usr/local/pkg/dnsblacklist.inc + + DNSBlacklist + PHP Service settings. +
Services
+ dnsblacklist.xml + /packages/dnsblacklist/dnsblacklist.php +
+ + dnsblacklist + dnsblacklist.sh + dnsblacklist + DNS Blacklist service. + + + + Settings + /pkg_edit.php?xml=dnsblacklist.xml&id=0 + + + + installedpackages->package->$packagename->configuration->dnsblacklist + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/dnsblacklist/dnsblacklist.xml + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/dnsblacklist/dnsblacklist.inc + + + /tmp/ + 0755 + http://www.pfsense.com/packages/config/dnsblacklist/dnsblacklist.tmp + + + /tmp/ + 0755 + http://www.pfsense.com/packages/config/dnsblacklist/blacklists.tar.gz + + + + Variable One + var1 + Enter the variable one here. + input + + + Variable Two + var1 + Enter the variable one here. + input + + + + + + php_sync_package(); + + + php_sync_package(); + + + php_install_command(); + + + deinstall_command(); + +
\ No newline at end of file -- cgit v1.2.3