aboutsummaryrefslogtreecommitdiffstats
path: root/config/dnsblacklist/dnsblacklist.tmp
diff options
context:
space:
mode:
authormcrane <mctch@yahoo.com>2009-10-02 12:15:18 -0600
committermcrane <mctch@yahoo.com>2009-10-02 13:48:00 -0600
commit268a257deb2a3d22ddfe3ccd99c9002b46fb0f18 (patch)
tree1d462843998595f8093c42ea5ff93fffc4ddadc5 /config/dnsblacklist/dnsblacklist.tmp
parent1904ec30efb7260c8aab675fb58addc61c73a162 (diff)
downloadpfsense-packages-268a257deb2a3d22ddfe3ccd99c9002b46fb0f18.tar.gz
pfsense-packages-268a257deb2a3d22ddfe3ccd99c9002b46fb0f18.tar.bz2
pfsense-packages-268a257deb2a3d22ddfe3ccd99c9002b46fb0f18.zip
Introducing a dnsblacklist a new package created by the collaboration of xa0z and mcrane.
Diffstat (limited to 'config/dnsblacklist/dnsblacklist.tmp')
-rw-r--r--config/dnsblacklist/dnsblacklist.tmp199
1 files changed, 199 insertions, 0 deletions
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 @@
+<?php
+
+ //Blacklist was retrieved from
+ //http://cri.univ-tlse1.fr/blacklists/index_en.php
+
+ require_once('config.inc');
+ require("guiconfig.inc");
+ include("head.inc");
+
+ //set the config as a global variable
+ global $config;
+
+ $global_usage = '/usr/local/www/packages/dnsblacklist/blacklists/global_usage';
+ $fh = fopen($global_usage, 'r');
+ while($line=fgets($fh)) {
+ $line = trim($line);
+ $line_array = explode (":", $line);
+ if (strtolower($line_array[0]) == "name") {
+ $name = trim($line_array[1]);
+ }
+ if (strtolower($line_array[0]) == "name en") {
+ $name_en = trim($line_array[1]);
+ $category[$name]['name_en'] = $name_en;
+ }
+ if (strtolower($line_array[0]) == "desc en") {
+ $desc_en = trim($line_array[1]);
+ $category[$name]['desc_en'] = $desc_en;
+ }
+
+ }
+
+ //get line count for domains list
+ function line_number ($file) {
+ $result = trim(exec("wc -l $file"));
+ $result_array = explode (" ", $result);
+ return $result_array[0];
+ }
+
+ //print_r($_POST);
+ //$x = 0;
+ //foreach($_POST['blacklist'] as $value) {
+ //$blacklist[$x]['name'] = $val;
+ //$blacklist[$value] = 'zzz';
+ //echo "\$category[\$x]['name'] = '$val';<br>";
+ //echo "\$category['$value'] = 'zzz'; <br/>\n";
+ //$x++;
+ //}
+ //unset($x);
+ //echo "<pre>";
+ //print_r($_POST["blacklist"]);
+ //echo "</pre>";
+ //foreach($_POST["blacklist"] as $key => $value) {
+ //echo "name: ".$value."<br />";
+ //$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.";
+}
+?>
+
+<?php include("fbegin.inc"); ?>
+<p class="pgtitle">Services: DNS Blacklist</p>
+<form method=POST action="">
+
+<?php
+if ($config['installedpackages']['dnsblacklist_settings']['config'][0]['enable'] == 1) {
+ echo "<input name='enable' type='checkbox' value='1' checked>\n";
+}
+else {
+ echo "<input name='enable' type='checkbox' value='1'>\n";
+}
+?>
+
+<strong>Enable DNS Blacklist</strong><br><br>
+<table width="100%" border="0" cellpadding="0" cellspacing="0">
+<tr><td class="tabcont" >
+<?php if ($savemsg_dnsb) print_info_box($savemsg_dnsb); ?>
+
+Below is a scroll-box filled with categories you can select to be added to your blacklist. <br><br> Each category has a list of known domains/sites that will be denied access by users of this network.
+<br><br><i>(Note: Using all categories at once will require 300Mb of free memory. The <b>adult</b> and <b>porn</b> categories are rather memory intensive, requiring 200Mb together.)</i>
+<br><br><br>
+
+
+<div style="height:340px;width:95%;overflow:scroll;">
+<?php
+
+echo "<table>\n";
+foreach($category as $key => $value) {
+ $domain_count = line_number("blacklists/$key/domains");
+ echo "<tr>\n";
+ if ($config['installedpackages']['dnsblacklist']['config'][0][$key] == 1) {
+ echo "<td><input type='checkbox' name='blacklist[]' value='$key' checked /></td>\n";
+ echo "<td><strong>".$value['name_en']."<strong></td>\n";
+ echo "<td>".$value['desc_en']."</td>\n";
+ echo "<td><i>($domain_count domains)</i></td>\n";
+ }
+ else {
+ echo "<td><input type='checkbox' name='blacklist[]' value='$key' /></td>\n";
+ echo "<td><strong>".$value['name_en']."</strong></td>\n";
+ echo "<td>".$value['desc_en']."</td>\n";
+ echo "<td><i>($domain_count domains)</i></td>\n";
+ }
+ echo "</tr>\n";
+ $x++;
+}
+echo "</table>\n";
+
+?>
+</div>
+<br />
+<br />
+<!--
+Select a category to edit:
+-->
+<?php
+////$tmp_category = array(1=> "Edit Category", );
+////$tmp_category = str_replace(" ", " ", $category);
+//echo "<SELECT name=category>\n";
+//foreach($category as $key => $value) {
+// echo "<OPTION value='".$key."'>".$key."</option>\n";
+// $x++;
+//}
+//echo "</select>\n";
+?>
+<!-- or <u>Add your own domains</u> <i>(Coming Soon)</i>
+<br />
+<br />
+-->
+
+<input type="submit" value="Save">
+</td>
+</tr>
+</table>
+</form>
+
+<?php include("fend.inc"); ?>
+
+</body>
+</html> \ No newline at end of file