Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Shallalist2pfBlockerNG.php - script to import shallalit category to pfBlockerNG

    Scheduled Pinned Locked Moved pfBlockerNG
    13 Posts 9 Posters 7.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      javcasta
      last edited by

      Hi.

      A new version for this script.

      I only change the path, because on a reboot the directory /tmp is not persistent.

      Now the path is: /usr/games/ , I have checked that this directory is persistent after a reboot.

      The code.

      
      /*
      	shallalist2pfBlockerNG.php
      	Copyright (C) 2016 javier@javcasta.com Javier Castañón
              @javcasta - PIyMenta - https://javcasta.com/
      
      	Redistribution and use in source and binary forms, with or without
      	modification, are permitted provided that the following conditions are met:
      
      	1\. Redistributions of source code must retain the above copyright notice,
      	   this list of conditions and the following disclaimer.
      
      	2\. Redistributions in binary form must reproduce the above copyright
      	   notice, this list of conditions and the following disclaimer in the
      	   documentation and/or other materials provided with the distribution.
      
      	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
      	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
      	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
      	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
      	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
      	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
      	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
      	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      	POSSIBILITY OF SUCH DAMAGE.
      */
      
      require_once("config.inc");
      require_once("util.inc");
      require_once("functions.inc");
      require_once("pkg-utils.inc");
      require_once("pfsense-utils.inc");
      require_once("globals.inc");
      require_once("services.inc");
      
      global $config;
      $config = parse_config(true);
      
      //bash 
      // /usr/games/
      //Remove directory
      print_r("Remove /usr/games/BL dir \n");
      mwexec("/bin/rm -rf /usr/games/BL");
      //Create directory
      print_r("Create /usr/games/BL dir \n");
      mwexec("/bin/mkdir /usr/games/BL");
      //Download list
      print_r("Download shallalist.tar.gz \n");
      mwexec("/usr/bin/fetch -o /usr/games/BL http://www.shallalist.de/Downloads/shallalist.tar.gz");
      #Extract and remove archive
      print_r("Extract... \n");
      //mwexec("/usr/bin/cd /usr/games/BL");
      mwexec("/usr/bin/tar -xf /usr/games/BL/shallalist.tar.gz --strip 1 -C /usr/games/BL");
      mwexec("/bin/rm -rf /usr/games/BL/shallalist.tar.gz");
      
      function listFolders($dir)
      {
          //ref //http://stackoverflow.com/questions/14358346/how-to-build-a-array-that-contains-a-folder-structure
          $dh = scandir($dir);
          $resultado = array();
          $laruta = '';
      
          foreach ($dh as $folder) {
              if ($folder != '.' && $folder != '..' && $folder != 'COPYRIGHT' &&
                      $folder != 'global_usage' && $folder != 'shallalist.tar.gz') {
                  $laruta = $dir . '/' . $folder;
                  if (is_dir($dir . '/' . $folder)) {                
                      $resultado[] = listFolders($dir . '/' . $folder);               
                  } else {
                      if (strpos($folder, 'domains') !== false) $resultado[] = $laruta;                
                  }
              }
          }
          return $resultado;
      }
      //folders /usr/games/BL to array
      $losdiraux = listFolders("/usr/games/BL");
      $losdir = iterator_to_array(new RecursiveIteratorIterator(new RecursiveArrayIterator($losdiraux)), 0);
      
      //DNSBL feed shallalist2pfBlockerNG
      $j = 0;
      $existeDNSBLfeed = false;
      while (!empty($config['installedpackages']['pfblockerngdnsbl']['config'][$j]['aliasname'])) {
          $j++;
          if (strpos($config['installedpackages']['pfblockerngdnsbl']['config'][$j]['aliasname'], "shallalist2pfpBlockerNG") !== false) {
              $existeDNSBLfeed = true;
              print_r("Already exists DNSBL feed shallalist2pfpBlockerNG ... \n");
          }
      }
      
      if (!$existeDNSBLfeed) {
          $config['installedpackages']['pfblockerngdnsbl']['config'][$j]['aliasname'] = "shallalist2pfpBlockerNG";
          $config['installedpackages']['pfblockerngdnsbl']['config'][$j]['description'] = "shallalist to pfBlockerNG";
          $config['installedpackages']['pfblockerngdnsbl']['config'][$j]['infolist'] = "";
          //...
          $i = 0;
          foreach ($losdir as $elemento) {
              $config['installedpackages']['pfblockerngdnsbl']['config'][$j]['row'][$i]['format'] = 'auto';
              $config['installedpackages']['pfblockerngdnsbl']['config'][$j]['row'][$i]['state'] = 'Disabled'; //Enabled
              $config['installedpackages']['pfblockerngdnsbl']['config'][$j]['row'][$i]['url'] = "$elemento";
              $config['installedpackages']['pfblockerngdnsbl']['config'][$j]['row'][$i]['header'] = "sh2pfB_$i";
              $i++;
          }
          //...
          $config['installedpackages']['pfblockerngdnsbl']['config'][$j]['action'] = "unbound";
          $config['installedpackages']['pfblockerngdnsbl']['config'][$j]['cron'] = "Weekly";
          $config['installedpackages']['pfblockerngdnsbl']['config'][$j]['filter_alexa'] = "on";
          $config['installedpackages']['pfblockerngdnsbl']['config'][$j]['custom'] = "";
          $config['installedpackages']['pfblockerngdnsbl']['config'][$j]['custom_update'] = "disabled";
          print  "pfBlockerNG DNSBL feed List shallalist2pfpBlockerNG Import Completed...\n\n";
          write_config();
      }
      
      //Cron
      //si no existe /usr/games/scripts lo creamos - if not exist /scripts create it
      if(!is_dir('/usr/games/scripts')) {
        mkdir('/usr/games/scripts');
      }
      //si no existe /usr/games/scripts/cron-download-shallalist2pfpBlockerNG.sh lo creamos
      if (!file_exists('/usr/games/scripts/cron-download-shallalist2pfpBlockerNG.sh')) {
       //bash
       $contenido = "#!/bin/sh\n"
              . "/bin/rm -rf /usr/games/BL\n"
              . "/bin/mkdir /usr/games/BL\n"
              . "/usr/bin/fetch -o /usr/games/BL http://www.shallalist.de/Downloads/shallalist.tar.gz\n"
              . "/usr/bin/tar -xf /usr/games/BL/shallalist.tar.gz --strip 1 -C /usr/games/BL\n"
              . "/bin/rm -rf /usr/games/BL/shallalist.tar.gz\n";
       file_put_contents("/usr/games/scripts/cron-download-shallalist2pfpBlockerNG.sh", $contenido);
       print_r("Create /usr/games/scripts/cron-download-shallalist2pfpBlockerNG.sh ... \n");
      
      } else print_r("Already exists /usr/games/scripts/cron-download-shallalist2pfpBlockerNG.sh ... \n");
      //existe Cron?
      $j = 0;
      $existecron = false;
      while (!empty($config['cron']['item'][$j]['command'])) {
          $j++;
          //print_r($config['cron']['item'][$j]['command']."\n");
          if (strpos($config['cron']['item'][$j]['command'], "/bin/sh /usr/games/scripts/cron-download-shallalist2pfpBlockerNG.sh") !== false) {
              $existecron = true;
              print_r("Already exists cron for /bin/sh /usr/games/scripts/cron-download-shallalist2pfpBlockerNG.sh \n");
          }
      }
      //si no existe cron lo creamos a ejecutar como root cada domingo a las 06:06
      if (!$existecron) {
          $config['cron']['item'][$j]['minute'] = "6";
          $config['cron']['item'][$j]['hour'] = "6";
          //$config['cron']['item'][$j]['mday'] = "*";
          //$config['cron']['item'][$j]['month'] = "*";
          $config['cron']['item'][$j]['wday'] = "7";
          $config['cron']['item'][$j]['who'] = "root";
          $config['cron']['item'][$j]['command'] = "/bin/sh /usr/games/scripts/cron-download-shallalist2pfpBlockerNG.sh";
          print_r("Create cron for /bin/sh /usr/games/scripts/cron-download-shallalist2pfpBlockerNG.sh ... \n\n");
          write_config();
      }
      print_r("You have to go to https://YOUR-IP-PFSENSE/pkg.php?xml=/pfblockerng/pfblockerng_dnsbl_lists.xml \n"
              . " Firewall > pfBlockerNG > DNSBL Feeds: and edit/put ON/OFF the Categories you wish \n"
              . "and Force Update update/reload DNSBL pfblockerNG \n\n");
      print_r("The End :). By javcasta - htpps://javcasta.com \n");
      ?>
      
      

      Regards.

      Javier Castañón
      Técnico de comunicaciones, soporte y sistemas.

      Mi web: https://javcasta.com/

      Soporte scripting/pfSense https://javcasta.com/soporte/

      1 Reply Last reply Reply Quote 0
      • B
        Brutos
        last edited by

        Great will give this a test as i was looking for a way to stop using squid and squidguard

        1 Reply Last reply Reply Quote 0
        • M
          Mr. Jingles
          last edited by

          Beautiful, thank you very much, karma for you  :-*

          6 and a half billion people know that they are stupid, agressive, lower life forms.

          1 Reply Last reply Reply Quote 0
          • J
            javcasta
            last edited by

            Hi

            @Mr.:

            Beautiful, thank you very much, karma for you  :-*

            Pay attention to the next release of pfBlockerNG. It will bring many new features, including categories from the list of shallalist … and many more things :). Great tool!!!

            Regads.

            Javier Castañón
            Técnico de comunicaciones, soporte y sistemas.

            Mi web: https://javcasta.com/

            Soporte scripting/pfSense https://javcasta.com/soporte/

            1 Reply Last reply Reply Quote 0
            • G
              gerdesj
              last edited by

              Great stuff and I am about to give it a go.

              Why are you using /usr/games?  I understand that /tmp is transient but surely a better place would be /var/lib/BL for lists and /usr/local/BL for your code.

              You could put everything under /usr/local/shallalist, so /usr/local/shallalist/{bin, tmp, lib} for code, downloads and working, lists.

              Cheers
              Jon

              [edit]  Nice piece of work.  Just had a go and it works flawlessly.  Thank you.

              1 Reply Last reply Reply Quote 0
              • J
                javcasta
                last edited by

                Hi
                @Jon:

                Great stuff and I am about to give it a go.

                Why are you using /usr/games?  I understand that /tmp is transient but surely a better place would be /var/lib/BL for lists and /usr/local/BL for your code.

                You could put everything under /usr/local/shallalist, so /usr/local/shallalist/{bin, tmp, lib} for code, downloads and working, lists.

                Cheers
                Jon

                [edit]  Nice piece of work.  Just had a go and it works flawlessly.  Thank you.

                hi Jon, thanks :)

                The path /usr/games It's like a wink or a joke to the scripters and developers  ;D

                This script is obsolete or deprecated from the moment the next version of pfBlockerNG is released.

                We are waiting for pfBlockerNG 2.1.1_7 !!!!!!!!!!! (GREAT TOOL!!!)

                Regards

                Javier Castañón
                Técnico de comunicaciones, soporte y sistemas.

                Mi web: https://javcasta.com/

                Soporte scripting/pfSense https://javcasta.com/soporte/

                1 Reply Last reply Reply Quote 0
                • I
                  iplost
                  last edited by

                  Me too. Waiting for godot  8)

                  1 Reply Last reply Reply Quote 0
                  • RonpfSR
                    RonpfS
                    last edited by

                    @javcasta:

                    hi Jon, thanks :)

                    This script is obsolete or deprecated from the moment the next version of pfBlockerNG is released.

                    We are waiting for pfBlockerNG 2.1.1_7 !!!!!!!!!!! (GREAT TOOL!!!)

                    The 2.1.1_7 doesn't have this implemented yet  :(

                    2.4.5-RELEASE-p1 (amd64)
                    Intel Core2 Quad CPU Q8400 @ 2.66GHz 8GB
                    Backup 0.5_5, Bandwidthd 0.7.4_4, Cron 0.3.7_5, pfBlockerNG-devel 3.0.0_16, Status_Traffic_Totals 2.3.1_1, System_Patches 1.2_5

                    1 Reply Last reply Reply Quote 0
                    • M
                      meruem
                      last edited by

                      cant tell, does this work or not , current pfBlockerNG 2.1.1_8

                      1 Reply Last reply Reply Quote 0
                      • A
                        Albertopfsense
                        last edited by

                        good morning all

                        i have pfBlockerNG 2.1.1_10 shalla function is built in ?

                        where can i find  it ?

                        thanks Alberto

                        1 Reply Last reply Reply Quote 0
                        • T
                          thatmakesnoSense
                          last edited by

                          Hi,

                          pfSense 2.4.0 Release with pfBlockerNG 2.1.2:

                          I can not find any option to activate shallalist. :-(

                          Any news? When will it be available?

                          Regards

                          1 Reply Last reply Reply Quote 0
                          • RonpfSR
                            RonpfS
                            last edited by

                            The latest updates to pfBlockerNG are bug fixes.

                            I guess BBCan177 will change version number when the new features are implemented and tested.

                            2.4.5-RELEASE-p1 (amd64)
                            Intel Core2 Quad CPU Q8400 @ 2.66GHz 8GB
                            Backup 0.5_5, Bandwidthd 0.7.4_4, Cron 0.3.7_5, pfBlockerNG-devel 3.0.0_16, Status_Traffic_Totals 2.3.1_1, System_Patches 1.2_5

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.