1 |
c7de8be4
|
jim-p
|
#!/usr/local/bin/php -q
|
2 |
|
|
<?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 |
|
|
log_error("{$argv[0]}: Starting URL table alias updates");
|
36 |
|
|
|
37 |
dd042c51
|
Renato Botelho
|
$filter_reload = false;
|
38 |
c7de8be4
|
jim-p
|
foreach ($todo as $t) {
|
39 |
|
|
$r = process_alias_urltable($t['name'], $t['url'], $t['freq']);
|
40 |
|
|
if ($r == 1) {
|
41 |
|
|
$result = "";
|
42 |
dd042c51
|
Renato Botelho
|
// TODO: Change it when pf supports tables with ports
|
43 |
e173dd74
|
Phil Davis
|
if ($t['type'] == "urltable") {
|
44 |
dd042c51
|
Renato Botelho
|
exec("/sbin/pfctl -t " . escapeshellarg($t['name']) . " -T replace -f /var/db/aliastables/" . escapeshellarg($t['name']) . ".txt 2>&1", $result);
|
45 |
e173dd74
|
Phil Davis
|
} else {
|
46 |
dd042c51
|
Renato Botelho
|
$filter_reload = true;
|
47 |
e173dd74
|
Phil Davis
|
}
|
48 |
c7de8be4
|
jim-p
|
log_error("{$argv[0]}: Updated {$t['name']} content from {$t['url']}: {$result[0]}");
|
49 |
|
|
} elseif ($r == -1) {
|
50 |
869dfb66
|
Renato Botelho
|
log_error("{$argv[0]}: {$t['name']} does not need updating.");
|
51 |
c7de8be4
|
jim-p
|
} else {
|
52 |
|
|
log_error("{$argv[0]}: ERROR: could not update {$t['name']} content from {$t['url']}");
|
53 |
|
|
}
|
54 |
|
|
}
|
55 |
dd042c51
|
Renato Botelho
|
|
56 |
e173dd74
|
Phil Davis
|
if ($filter_reload) {
|
57 |
dd042c51
|
Renato Botelho
|
send_event("filter reload");
|
58 |
e173dd74
|
Phil Davis
|
}
|
59 |
c7de8be4
|
jim-p
|
}
|
60 |
dd042c51
|
Renato Botelho
|
?>
|