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

    Update a table via cronjob?

    Scheduled Pinned Locked Moved Firewalling
    6 Posts 2 Posters 2.3k 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.
    • S
      senser
      last edited by

      I'd like to update a table from a cronjob. The command creates a list of networks in cidr notation. I know how to create the cronjob, but how do I get the list into the mighty pf?
      Thanks for your help!

      We use the mighty pf, we cannot be fooled.

      1 Reply Last reply Reply Quote 0
      • R
        rjcrowder
        last edited by

        @senser:

        I'd like to update a table from a cronjob. The command creates a list of networks in cidr notation. I know how to create the cronjob, but how do I get the list into the mighty pf?
        Thanks for your help!

        It is already done automatically via Cron.  If you cat the /etc/crontab file it is this line

        30	12	*	*	*	root	/usr/bin/nice -n20 /etc/rc.update_urltables
        

        I had a need to do it from a web UI and this is the php code that I use to force an update of my url tables… Basically just copy the new file into the proper location and then run this code.

        #!/usr/local/bin/php -q
        require_once("config.gui.inc");
        require_once("util.inc");
        require_once("pfsense-utils.inc");
        
        if (!is_array($config['aliases']['alias'])) {
        	// No aliases
        	exit;
        }
        
        // Gather list of urltable aliases
        $todo = array();
        foreach ($config['aliases']['alias'] as $alias) {
        	if ($alias['type'] == 'urltable') {
        		$tmp = array();
        		$tmp['name'] = $alias['name'];
        		$tmp['url']  = $alias['url'];
        		$tmp['freq'] = $alias['updatefreq'];
        		$todo[] = $tmp;
        	}
        }
        
        if (count($todo) > 0) {
        	log_error("{$argv[0]}: Starting up.");
        
        	log_error("{$argv[0]}: Starting URL table alias updates");
        
        	foreach ($todo as $t) {
        		$r = process_alias_urltable($t['name'], $t['url'], $t['freq'], true);
        		if ($r == 1) {
        			$result = "";
        			exec("/sbin/pfctl -t " . escapeshellarg($t['name']) . " -T replace -f /var/db/aliastables/" . escapeshellarg($t['name']) . ".txt 2>&1", $result);
        			log_error("{$argv[0]}: Updated {$t['name']} content from {$t['url']}: {$result[0]}");
        		} elseif ($r == -1) {
        			log_error("{$argv[0]}: {$t['name']} does not need updated.");
        		} else {
        			log_error("{$argv[0]}: ERROR: could not update {$t['name']} content from {$t['url']}");
        		}
        	}
        }
        ?>
        
        
        1 Reply Last reply Reply Quote 0
        • S
          senser
          last edited by

          OK, I don't need the GUI option. But your hints were useful. :)

          This is what I did (haven't tested it yet though):
          Added the command that creates my list of networks (as /tmp/networks.txt) to a <shellcmd>(to get the list on boot, hopefully) and to crontab, because it needs periodic updates.
          Added the resulting file as a text source to an existing list in pfBlocker.

          Now, currently I can only hope that
          1. shellcmd runs before pfBlocker at boot (so the file is created when pfBlocker starts) and
          2. shellcmd does NOT run before the network (especially pppoe) is up.

          While I am testing - if anyone got a more 'failsafe', pfSense'ish approach, let me know.</shellcmd>

          We use the mighty pf, we cannot be fooled.

          1 Reply Last reply Reply Quote 0
          • R
            rjcrowder
            last edited by

            @senser:

            OK, I don't need the GUI option. But your hints were useful. :)

            This is what I did (haven't tested it yet though):
            Added the command that creates my list of networks (as /tmp/networks.txt) to a <shellcmd>(to get the list on boot, hopefully) and to crontab, because it needs periodic updates.
            Added the resulting file as a text source to an existing list in pfBlocker.

            Now, currently I can only hope that
            1. shellcmd runs before pfBlocker at boot (so the file is created when pfBlocker starts) and
            2. shellcmd does NOT run before the network (especially pppoe) is up.

            While I am testing - if anyone got a more 'failsafe', pfSense'ish approach, let me know.</shellcmd>

            You can run a script at boot… just put it in /usr/local/etc/rc.d. If you want to run it last, start the name with zz or something like that...

            1 Reply Last reply Reply Quote 0
            • S
              senser
              last edited by

              pfblocker and the network interfaces are initialized somewhere else - so you can't control the order of initialization of those and your scripts via prefixes. Which is want I (may) need. Still haven't test-booted

              We use the mighty pf, we cannot be fooled.

              1 Reply Last reply Reply Quote 0
              • S
                senser
                last edited by

                Did I meantion that I use nanobsd? :-)
                It would be best to have some persistent storage for my list of networks.
                Maybe I'll get an answer here http://forum.pfsense.org/index.php/topic,65500.0.html

                We use the mighty pf, we cannot be fooled.

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