Projet

Général

Profil

Télécharger (1,55 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / etc / rc.update_urltables @ master

1
#!/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 (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
	log_error("{$argv[0]}: Starting URL table alias updates");
36

    
37
	$filter_reload = false;
38
	foreach ($todo as $t) {
39
		$r = process_alias_urltable($t['name'], $t['url'], $t['freq']);
40
		if ($r == 1) {
41
			$result = "";
42
			// TODO: Change it when pf supports tables with ports
43
			if ($t['type'] == "urltable")
44
				exec("/sbin/pfctl -t " . escapeshellarg($t['name']) . " -T replace -f /var/db/aliastables/" . escapeshellarg($t['name']) . ".txt 2>&1", $result);
45
			else
46
				$filter_reload = true;
47
			log_error("{$argv[0]}: Updated {$t['name']} content from {$t['url']}: {$result[0]}");
48
		} elseif ($r == -1) {
49
			log_error("{$argv[0]}: {$t['name']} does not need updating.");
50
		} else {
51
			log_error("{$argv[0]}: ERROR: could not update {$t['name']} content from {$t['url']}");
52
		}
53
	}
54

    
55
	if ($filter_reload)
56
		send_event("filter reload");
57
}
58
?>
(97-97/103)