summaryrefslogtreecommitdiffstats
path: root/skripti/ipranges.php
blob: a387da9ced24154b1c862b9e639614ae38f8b245 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/php
<?php
/**
 * program izpiše bind9 aclje za države v ripe območku.
 * privzeto izpiše vse, vendar bind9 umre ob prevelikem številu acljev
 * uporaba: ./ipranges.php si de hr it
 * v argumentih lahko torej povemo, za katere države želimo aclje
 */
$a = "";
$p = [];
$c = [];
$response = file_get_contents("https://ftp.ripe.net/pub/stats/ripencc/membership/alloclist.txt");
if ($response === false)
	exit(1);
foreach (explode("\n", $response) as $l) {
	if ($l == "")
		continue;
	if ($l[0] != " ") {
		$a = trim($l);
		$p[$a] = [];
		$c[explode(".", $a)[0]][] = $a;
		continue;
	}
	if (strchr(trim($l), "\t") !== false)
		$p[$a]["ranges"][] = explode("\t", trim($l));
	else
		$p[$a]["name"] = trim($l);
}
ksort($p);
foreach ($p as $k => $v) {
	if (sizeof($argv) > 1)
		if (!in_array(explode(".", $k)[0], $argv))
			continue;
	echo "acl $k {\t// {$v['name']}" . PHP_EOL;
	foreach ($v["ranges"] as $r) {
		echo "\t{$r[1]}; //\t{$r[0]}" . PHP_EOL;
	}
	echo "};" . PHP_EOL;
}
foreach ($c as $k => $v) {
	if (sizeof($argv) > 1)
		if (!in_array($k, $argv))
			continue;
	echo "acl $k {" . PHP_EOL;
	foreach ($v as $a) {
		echo "\t$a;\t// {$p[$a]["name"]}" . PHP_EOL;
	}
	echo "};" . PHP_EOL;
}
str_replace("/", "", str_replace(".", "", array_shift($argv)));
echo "acl ipranges.php {" . PHP_EOL;
foreach ($argv as $a) {
	echo "\t$a;" . PHP_EOL;
}
echo "};" . PHP_EOL;