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 |
|
|
exit;
|
10 |
|
|
}
|
11 |
|
|
|
12 |
|
|
// Gather list of urltable aliases
|
13 |
|
|
$todo = array();
|
14 |
|
|
foreach ($config['aliases']['alias'] as $alias) {
|
15 |
|
|
if ($alias['type'] == 'urltable') {
|
16 |
|
|
$tmp = array();
|
17 |
|
|
$tmp['name'] = $alias['name'];
|
18 |
|
|
$tmp['url'] = $alias['url'];
|
19 |
|
|
$tmp['freq'] = $alias['updatefreq'];
|
20 |
|
|
$todo[] = $tmp;
|
21 |
|
|
}
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
if (count($todo) > 0) {
|
25 |
|
|
log_error("{$argv[0]}: Starting up.");
|
26 |
|
|
|
27 |
|
|
if ($argv[1] != "now") {
|
28 |
|
|
// Wait a little before updating.
|
29 |
|
|
$wait = mt_rand(5, 60);
|
30 |
|
|
log_error("{$argv[0]}: Sleeping for {$wait} seconds.");
|
31 |
|
|
sleep($wait);
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
log_error("{$argv[0]}: Starting URL table alias updates");
|
35 |
|
|
|
36 |
|
|
foreach ($todo as $t) {
|
37 |
|
|
$r = process_alias_urltable($t['name'], $t['url'], $t['freq']);
|
38 |
|
|
if ($r == 1) {
|
39 |
|
|
$result = "";
|
40 |
|
|
exec("/sbin/pfctl -t " . escapeshellarg($t['name']) . " -T replace -f /var/db/aliastables/" . escapeshellarg($t['name']) . ".txt 2>&1", $result);
|
41 |
|
|
log_error("{$argv[0]}: Updated {$t['name']} content from {$t['url']}: {$result[0]}");
|
42 |
|
|
} elseif ($r == -1) {
|
43 |
|
|
log_error("{$argv[0]}: {$t['name']} does not need updated.");
|
44 |
|
|
} else {
|
45 |
|
|
log_error("{$argv[0]}: ERROR: could not update {$t['name']} content from {$t['url']}");
|
46 |
|
|
}
|
47 |
|
|
}
|
48 |
|
|
}
|
49 |
|
|
?>
|