1
|
#!/usr/local/bin/php-cgi -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
|
return;
|
10
|
}
|
11
|
|
12
|
// Gather list of urltable aliases
|
13
|
$todo = array();
|
14
|
foreach ($config['aliases']['alias'] as $alias) {
|
15
|
if (preg_match('/urltable/i', $alias['type'])) {
|
16
|
$tmp = array();
|
17
|
$tmp['type'] = $alias['type'];
|
18
|
$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
|
// 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
|
log_error("{$argv[0]}: Starting URL table alias updates");
|
43
|
|
44
|
$filter_reload = false;
|
45
|
foreach ($todo as $t) {
|
46
|
|
47
|
// Update a specifically named URL table only.
|
48
|
if (!empty($argv[3]) && ($argv[3] != $t['name'])) {
|
49
|
continue;
|
50
|
}
|
51
|
|
52
|
$r = process_alias_urltable($t['name'], $t['type'], $t['url'], $t['freq'], $forceupdate);
|
53
|
if ($r == 1) {
|
54
|
$result = "";
|
55
|
// TODO: Change it when pf supports tables with ports
|
56
|
if ($t['type'] == "urltable") {
|
57
|
exec("/sbin/pfctl -t " . escapeshellarg($t['name']) . " -T replace -f /var/db/aliastables/" . escapeshellarg($t['name']) . ".txt 2>&1", $result);
|
58
|
} else {
|
59
|
$filter_reload = true;
|
60
|
}
|
61
|
log_error("{$argv[0]}: Updated {$t['name']} content from {$t['url']}: {$result[0]}");
|
62
|
} elseif ($r == -1) {
|
63
|
log_error("{$argv[0]}: {$t['name']} does not need updating.");
|
64
|
} else {
|
65
|
log_error("{$argv[0]}: ERROR: could not update {$t['name']} content from {$t['url']}");
|
66
|
}
|
67
|
}
|
68
|
|
69
|
if ($filter_reload) {
|
70
|
send_event("filter reload");
|
71
|
}
|
72
|
}
|
73
|
?>
|