Project

General

Profile

Download (1.89 KB) Statistics
| Branch: | Tag: | Revision:
1 cb7d18d5 Renato Botelho
#!/usr/local/bin/php-cgi -q
2 c7de8be4 jim-p
<?php
3
require_once("config.inc");
4
require_once("util.inc");
5
require_once("pfsense-utils.inc");
6
7
if (!is_array($config['aliases']['alias'])) {
8
	// No aliases
9 9ea554ee Ermal LUÇI
	return;
10 c7de8be4 jim-p
}
11
12
// Gather list of urltable aliases
13
$todo = array();
14
foreach ($config['aliases']['alias'] as $alias) {
15 dd042c51 Renato Botelho
	if (preg_match('/urltable/i', $alias['type'])) {
16 c7de8be4 jim-p
		$tmp = array();
17 dd042c51 Renato Botelho
		$tmp['type'] = $alias['type'];
18 c7de8be4 jim-p
		$tmp['name'] = $alias['name'];
19
		$tmp['url']  = $alias['url'];
20
		$tmp['freq'] = $alias['updatefreq'];
21
		$todo[] = $tmp;
22
	}
23
}
24
25
if (count($todo) > 0) {
26
	log_error("{$argv[0]}: Starting up.");
27
28
	if ($argv[1] != "now") {
29
		// Wait a little before updating.
30
		$wait = mt_rand(5, 60);
31
		log_error("{$argv[0]}: Sleeping for {$wait} seconds.");
32
		sleep($wait);
33
	}
34
35 f6622167 NOYB
	// Set whether or not to force the table update before it's time.
36
	if (!empty($argv[2]) && ($argv[2] == "forceupdate")) {
37
		$forceupdate = true;
38
	} else {
39
		$forceupdate = false;
40
	}
41
42 c7de8be4 jim-p
	log_error("{$argv[0]}: Starting URL table alias updates");
43
44 dd042c51 Renato Botelho
	$filter_reload = false;
45 c7de8be4 jim-p
	foreach ($todo as $t) {
46 f6622167 NOYB
47
		// Update a specifically named URL table only.
48
		if (!empty($argv[3]) && ($argv[3] != $t['name'])) {
49
			continue;
50
		}
51
52 3b07f4fe NOYB
		$r = process_alias_urltable($t['name'], $t['type'], $t['url'], $t['freq'], $forceupdate);
53 c7de8be4 jim-p
		if ($r == 1) {
54
			$result = "";
55 dd042c51 Renato Botelho
			// TODO: Change it when pf supports tables with ports
56 e173dd74 Phil Davis
			if ($t['type'] == "urltable") {
57 dd042c51 Renato Botelho
				exec("/sbin/pfctl -t " . escapeshellarg($t['name']) . " -T replace -f /var/db/aliastables/" . escapeshellarg($t['name']) . ".txt 2>&1", $result);
58 e173dd74 Phil Davis
			} else {
59 dd042c51 Renato Botelho
				$filter_reload = true;
60 e173dd74 Phil Davis
			}
61 c7de8be4 jim-p
			log_error("{$argv[0]}: Updated {$t['name']} content from {$t['url']}: {$result[0]}");
62
		} elseif ($r == -1) {
63 869dfb66 Renato Botelho
			log_error("{$argv[0]}: {$t['name']} does not need updating.");
64 c7de8be4 jim-p
		} else {
65
			log_error("{$argv[0]}: ERROR: could not update {$t['name']} content from {$t['url']}");
66
		}
67
	}
68 dd042c51 Renato Botelho
69 e173dd74 Phil Davis
	if ($filter_reload) {
70 dd042c51 Renato Botelho
		send_event("filter reload");
71 e173dd74 Phil Davis
	}
72 c7de8be4 jim-p
}
73 dd042c51 Renato Botelho
?>