2018-12-10 16:23:15 +00:00
|
|
|
<?php
|
|
|
|
|
2018-12-10 17:54:30 +00:00
|
|
|
// Before we begin. Ensure registry repository is up-to-date
|
2018-12-10 17:44:12 +00:00
|
|
|
echo shell_exec("/usr/bin/git -C ../registry/ pull origin master:master 2>&1");
|
2018-12-10 16:23:15 +00:00
|
|
|
|
2018-12-10 17:54:30 +00:00
|
|
|
/*
|
|
|
|
* Function:
|
|
|
|
* startsWith( $string, 'word')
|
|
|
|
*
|
|
|
|
* Find lines beginning with 'word'.
|
|
|
|
*/
|
2018-12-10 16:23:15 +00:00
|
|
|
function startsWith($haystack, $needle)
|
|
|
|
{
|
|
|
|
$length = strlen($needle);
|
|
|
|
return (substr($haystack, 0, $length) === $needle);
|
|
|
|
}
|
|
|
|
|
2018-12-10 17:54:30 +00:00
|
|
|
/*
|
|
|
|
* Function:
|
|
|
|
* endsWith( $string, 'word')
|
|
|
|
*
|
|
|
|
* Find lines ending with 'word'.
|
|
|
|
*/
|
2018-12-10 16:23:15 +00:00
|
|
|
function endsWith($haystack, $needle)
|
|
|
|
{
|
|
|
|
$length = strlen($needle);
|
|
|
|
if ($length == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (substr($haystack, -$length) === $needle);
|
|
|
|
}
|
|
|
|
|
2018-12-10 17:54:30 +00:00
|
|
|
// Create empty array $roas
|
2018-12-10 16:23:15 +00:00
|
|
|
$roas = array();
|
2018-12-10 17:54:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* IPv6 route objects
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Set directory for which all files are to be scanned
|
2018-12-10 17:44:12 +00:00
|
|
|
$files = scandir('../registry/data/route6/');
|
2018-12-10 17:54:30 +00:00
|
|
|
|
2018-12-10 16:23:15 +00:00
|
|
|
$h = 0; // count up when reading new file
|
2018-12-10 17:54:30 +00:00
|
|
|
$i = 0; // used when loop through sub-arrays. I.e. when route objects have more than one listed origin asn
|
2018-12-10 16:23:15 +00:00
|
|
|
|
|
|
|
foreach($files as $file)
|
|
|
|
{
|
2018-12-10 17:44:12 +00:00
|
|
|
$handle = fopen("../registry/data/route6/$file", "r");
|
2018-12-10 16:23:15 +00:00
|
|
|
while (($line = fgets($handle)) !== false) {
|
|
|
|
// extract var $ta
|
|
|
|
if (startsWith($line,'source')) {
|
|
|
|
$source = array();
|
|
|
|
preg_match('/([A-Z0-4]+)/',explode(':', $line)[1], $source);
|
|
|
|
$ta = $source[1];
|
|
|
|
}
|
|
|
|
// extract var $route
|
|
|
|
// extract var $maskLength
|
|
|
|
if (startsWith($line,'route6')) {
|
|
|
|
$prefix = array();
|
|
|
|
$line2 = explode('6: ', $line);
|
|
|
|
// validate v6 netmasks with following cmd
|
2018-12-10 17:44:12 +00:00
|
|
|
// cmd: ls -1 ../registry/data/route6/ | egrep -o "\b\_[0-9]+\b" | sed 's/\_//' | sort -n | uniq
|
2018-12-10 16:23:15 +00:00
|
|
|
preg_match('/([a-f0-9\:]{0,128})\/(32|40|4[4-9]|5[0-9]|6[0-4]|80)/', $line2[1], $prefix);
|
|
|
|
$route = $prefix[0];
|
|
|
|
$mask = $prefix[2];
|
|
|
|
}
|
2018-12-10 18:31:49 +00:00
|
|
|
// extract var $maxLength
|
2018-12-10 20:17:25 +00:00
|
|
|
/*if (startsWith($line,'max-length')) {
|
2018-12-10 18:31:49 +00:00
|
|
|
$maxLength = array();
|
2018-12-10 18:40:40 +00:00
|
|
|
preg_match('/([0-9]+)/',explode(':', $line)[1], $maxLength);
|
2018-12-10 19:40:44 +00:00
|
|
|
$maxLength = $maxLength[1];
|
|
|
|
} else {
|
|
|
|
$maxLength = '';
|
2018-12-10 20:17:25 +00:00
|
|
|
}*/
|
2018-12-10 16:23:15 +00:00
|
|
|
// extract var $asn
|
|
|
|
if (startsWith($line, 'origin')) {
|
|
|
|
$asn = array();
|
|
|
|
preg_match('/AS[0-9]+/', explode(':', $line)[1], $asn);
|
|
|
|
if (count($asn) > 1) {
|
|
|
|
foreach ($asn as $key => $value) {
|
|
|
|
if (!empty($value)) {
|
|
|
|
$roas['roas'][$i]['asn'] = $asn[0];
|
|
|
|
$roas['roas'][$i]['prefix'] = $route;
|
2018-12-10 20:17:25 +00:00
|
|
|
/*if (isset($ta)) {
|
2018-12-10 19:12:12 +00:00
|
|
|
if ($ta == 'DN42') {
|
2018-12-10 16:23:15 +00:00
|
|
|
$mask = ($mask <= 64 ? '64' : $mask);
|
2018-12-10 19:12:12 +00:00
|
|
|
if ($maxLength != '') $mask = $maxLength;
|
2018-12-10 16:23:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$ta = 'NULL';
|
2018-12-10 20:17:25 +00:00
|
|
|
}*/
|
2018-12-10 18:40:40 +00:00
|
|
|
$roas['roas'][$i]['maxLength'] = $mask;
|
2018-12-10 20:20:22 +00:00
|
|
|
$roas['roas'][$i]['ta'] = (empty($ta) ? '' : $ta);
|
2018-12-10 16:23:15 +00:00
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$roas['roas'][$i]['asn'] = $asn[0];
|
|
|
|
$roas['roas'][$i]['prefix'] = $route;
|
2018-12-10 20:17:25 +00:00
|
|
|
/*if (isset($ta)) {
|
2018-12-10 19:12:12 +00:00
|
|
|
if ($ta == 'DN42') {
|
2018-12-10 16:23:15 +00:00
|
|
|
$mask = ($mask <= 64 ? '64' : $mask);
|
2018-12-10 19:12:12 +00:00
|
|
|
if ($maxLength != '') $mask = $maxLength;
|
2018-12-10 16:23:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$ta = 'NULL';
|
2018-12-10 20:17:25 +00:00
|
|
|
}*/
|
2018-12-10 18:40:40 +00:00
|
|
|
$roas['roas'][$i]['maxLength'] = $mask;
|
2018-12-10 20:20:22 +00:00
|
|
|
$roas['roas'][$i]['ta'] = (empty($ta) ? '' : $ta);
|
2018-12-10 16:23:15 +00:00
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-10 17:54:30 +00:00
|
|
|
fclose($handle); // close $file when finished reading data
|
2018-12-10 16:23:15 +00:00
|
|
|
$h++;
|
|
|
|
}
|
|
|
|
|
2018-12-10 17:54:30 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* IPv4 route objects
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Set directory for which all files are to be scanned
|
2018-12-10 17:44:12 +00:00
|
|
|
$files = scandir('../registry/data/route/');
|
2018-12-10 16:23:15 +00:00
|
|
|
|
|
|
|
foreach($files as $file)
|
|
|
|
{
|
2018-12-10 17:44:12 +00:00
|
|
|
$handle = fopen("../registry/data/route/$file", "r");
|
2018-12-10 16:23:15 +00:00
|
|
|
while (($line = fgets($handle)) !== false) {
|
|
|
|
// extract var $ta
|
|
|
|
if (startsWith($line,'source')) {
|
|
|
|
$source = array();
|
|
|
|
preg_match('/([A-Z0-4]+)/',explode(':', $line)[1], $source);
|
|
|
|
$ta = $source[1];
|
|
|
|
}
|
|
|
|
// extract var $route
|
|
|
|
// extract var $maskLength
|
|
|
|
if (startsWith($line,'route')) {
|
|
|
|
$prefix = array();
|
|
|
|
preg_match('/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(3[0-2]|[0-2]?[0-9])/', explode(':', $line)[1], $prefix);
|
|
|
|
$route = $prefix[0];
|
|
|
|
$mask = $prefix[5];
|
|
|
|
}
|
2018-12-10 19:12:12 +00:00
|
|
|
// extract var $maxLength
|
2018-12-10 20:17:25 +00:00
|
|
|
/*$maxLength = ''; // ensure var is null when starting new loop
|
2018-12-10 18:31:49 +00:00
|
|
|
if (startsWith($line,'max-length')) {
|
|
|
|
$maxLength = array();
|
2018-12-10 18:40:40 +00:00
|
|
|
preg_match('/([0-9]+)/',explode(':', $line)[1], $maxLength);
|
2018-12-10 19:40:44 +00:00
|
|
|
$maxLength = $maxLength[1];
|
|
|
|
} else {
|
|
|
|
$maxLength = '';
|
2018-12-10 20:17:25 +00:00
|
|
|
}*/
|
2018-12-10 16:23:15 +00:00
|
|
|
// extract var $asn
|
|
|
|
if (startsWith($line, 'origin')) {
|
|
|
|
$asn = array();
|
|
|
|
preg_match('/AS[0-9]+/', explode(':', $line)[1], $asn);
|
|
|
|
if (count($asn) > 1) {
|
|
|
|
foreach ($asn as $key => $value) {
|
|
|
|
if (!empty($value)) {
|
|
|
|
$roas['roas'][$i]['asn'] = $asn[0];
|
|
|
|
$roas['roas'][$i]['prefix'] = $route;
|
2018-12-10 20:17:25 +00:00
|
|
|
/*if (isset($ta)) {
|
2018-12-10 19:12:12 +00:00
|
|
|
if ($ta == 'DN42') {
|
2018-12-10 16:23:15 +00:00
|
|
|
$mask = ($mask <= 28 ? '28' : $mask);
|
2018-12-10 19:12:12 +00:00
|
|
|
if ($maxLength != '') $mask = $maxLength;
|
2018-12-10 16:23:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$ta = 'NULL';
|
2018-12-10 20:17:25 +00:00
|
|
|
}*/
|
2018-12-10 18:40:40 +00:00
|
|
|
$roas['roas'][$i]['maxLength'] = $mask;
|
2018-12-10 20:20:22 +00:00
|
|
|
$roas['roas'][$i]['ta'] = (empty($ta) ? '' : $ta);
|
2018-12-10 16:23:15 +00:00
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$roas['roas'][$i]['asn'] = $asn[0];
|
|
|
|
$roas['roas'][$i]['prefix'] = $route;
|
2018-12-10 20:17:25 +00:00
|
|
|
/*if (isset($ta)) {
|
2018-12-10 19:12:12 +00:00
|
|
|
if ($ta == 'DN42') {
|
2018-12-10 16:23:15 +00:00
|
|
|
$mask = ($mask <= 28 ? '28' : $mask);
|
2018-12-10 19:12:12 +00:00
|
|
|
if ($maxLength != '') $mask = $maxLength;
|
2018-12-10 16:23:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$ta = 'NULL';
|
2018-12-10 20:17:25 +00:00
|
|
|
}*/
|
2018-12-10 18:40:40 +00:00
|
|
|
$roas['roas'][$i]['maxLength'] = $mask;
|
2018-12-10 20:20:22 +00:00
|
|
|
$roas['roas'][$i]['ta'] = (empty($ta) ? '' : $ta);
|
2018-12-10 16:23:15 +00:00
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-10 17:54:30 +00:00
|
|
|
fclose($handle); // close $file when finished reading data
|
2018-12-10 16:23:15 +00:00
|
|
|
$h++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do JSON encoding before writing result to file
|
|
|
|
$json = json_encode($roas, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
|
|
|
|
|
|
|
|
// Write JSON to file
|
|
|
|
$fp = fopen('dn42-rpki-export.json', 'w');
|
|
|
|
fwrite($fp, $json);
|
|
|
|
fclose($fp);
|
|
|
|
|
2018-12-10 17:55:56 +00:00
|
|
|
// Commit and push to all git remote repositories
|
2018-12-10 16:34:16 +00:00
|
|
|
echo shell_exec("./update.sh 2>&1");
|
|
|
|
|
2018-12-10 16:23:15 +00:00
|
|
|
?>
|