1
0
Fork 0

Updated roagen.php - aligned test better

This commit is contained in:
netravnen 2018-12-14 17:29:19 +00:00
parent ebc4055b81
commit f355060e9a
1 changed files with 58 additions and 56 deletions

View File

@ -1,7 +1,7 @@
<?php
// Before we begin. Ensure registry repository is up-to-date
echo shell_exec("/usr/bin/git -C ../registry/ pull origin master:master 2>&1");
echo shell_exec ("/usr/bin/git -C ../registry/ pull origin master:master 2>&1");
/*
* Function:
@ -49,8 +49,8 @@ function trim_special_chars ($string)
$roas = array();
// Set folders we need to scan.
$files6 = scandir("../registry/data/route6/");
$files4 = scandir("../registry/data/route/");
$files6 = scandir ("../registry/data/route6/");
$files4 = scandir ("../registry/data/route/");
/*
*
@ -76,16 +76,16 @@ foreach ($files6 as $file)
* source: DN42
*/
$data = file("../registry/data/route6/$file");
$data = file ("../registry/data/route6/$file");
foreach ($data as $str)
{
$str = trim_special_chars ($str);
if (startsWith ($str, ("max"), 3)) $raw_array[$i]["max"] = $str;
elseif (startsWith ($str, ("source"), 6)) $raw_array[$i]["source"] = $str;
elseif (startsWith ($str, ("route"), 5)) $raw_array[$i]["route"] = $str;
elseif (startsWith ($str, ("origin"), 6)) $raw_array[$i]["asn"][$j++] = $str;
if (startsWith ($str, "max", 3)) $raw_array[$i]["max"] = $str;
elseif (startsWith ($str, "source", 6)) $raw_array[$i]["source"] = $str;
elseif (startsWith ($str, "route", 5)) $raw_array[$i]["route"] = $str;
elseif (startsWith ($str, "origin", 6)) $raw_array[$i]["asn"][$j++] = $str;
// Catch max-length not set in route object.
if (empty ($raw_array[$i]["max"])) $raw_array[$i]["max"] = -1;
@ -100,26 +100,27 @@ foreach ($raw_array as $sub_array)
// Extract prefix and subnet size
// Match prefix sizes 29-64, 80.
$prefix = array();
preg_match("/([a-f0-9\:]{0,128})\/(29|[3-5][0-9]|6[0-4]|80)/",
explode("6: ", $sub_array["route"])[1],
preg_match ("/([a-f0-9\:]{0,128})\/(29|[3-5][0-9]|6[0-4]|80)/",
explode ("6: ", $sub_array["route"])[1],
$prefix);
// Extract ta information
$source = array();
preg_match ("/([A-Z0-4]+)/",
explode(":", $sub_array["source"])[1],
explode (":", $sub_array["source"])[1],
$source);
// Try to extract max-length information
$maxlength = array();
if (($sub_array["max"]) != -1)
preg_match ("/([0-9]+)/",
explode(":", $sub_array["max"])[1],
explode (":", $sub_array["max"])[1],
$maxlength);
// Store extracted values
$_prefix = $prefix[0];
$_ta = (isset ($source[0]) ? $source[0] : "");
$_prefix = $prefix[0];
$_ta = (isset ($source[0]) ? $source[0] : "");
// We need to do conditional setting of maxLength to avoid errornous output.
if (($sub_array["max"]) != -1)
$_maxlength = (isset ($maxlength[0]) ? $maxlength[0] : "");
@ -167,16 +168,16 @@ foreach ($files4 as $file)
* source: DN42
*/
$data = file("../registry/data/route/$file");
$data = file ("../registry/data/route/$file");
foreach ($data as $str)
{
$str = trim_special_chars ($str);
if (startsWith ($str, ("max"), 3)) $raw_array[$i]["max"] = $str;
elseif (startsWith ($str, ("source"), 6)) $raw_array[$i]["source"] = $str;
elseif (startsWith ($str, ("route"), 5)) $raw_array[$i]["route"] = $str;
elseif (startsWith ($str, ("origin"), 6)) $raw_array[$i]["asn"][$j++] = $str;
if (startsWith ($str, "max", 3)) $raw_array[$i]["max"] = $str;
elseif (startsWith ($str, "source", 6)) $raw_array[$i]["source"] = $str;
elseif (startsWith ($str, "route", 5)) $raw_array[$i]["route"] = $str;
elseif (startsWith ($str, "origin", 6)) $raw_array[$i]["asn"][$j++] = $str;
// Catch max-length not set in route object.
if (empty ($raw_array[$i]["max"])) $raw_array[$i]["max"] = -1;
@ -189,26 +190,27 @@ foreach ($raw_array as $sub_array)
// Extract prefix and subnet size
// Match prefix sizes 8-32.
$prefix = array();
preg_match("/([0-9\.]{7,15})\/([8-9]|[1-2][0-9]|3[0-2])/",
explode(":", $sub_array["route"])[1],
preg_match ("/([0-9\.]{7,15})\/([8-9]|[1-2][0-9]|3[0-2])/",
explode (":", $sub_array["route"])[1],
$prefix);
// Extract ta information
$source = array();
preg_match ("/([A-Z0-4]+)/",
explode(":", $sub_array["source"])[1],
explode (":", $sub_array["source"])[1],
$source);
// Try to extract max-length information
$maxlength = array();
if (($sub_array["max"]) != -1)
preg_match ("/([0-9]+)/",
explode(":", $sub_array["max"])[1],
explode (":", $sub_array["max"])[1],
$maxlength);
// Store extracted values
$_prefix = $prefix[0];
$_ta = (isset ($source[0]) ? $source[0] : "");
$_prefix = $prefix[0];
$_ta = (isset ($source[0]) ? $source[0] : "");
// We need to do conditional setting of maxLength to avoid errornous output.
if (($sub_array["max"]) != -1)
$_maxlength = (isset ($maxlength[0]) ? $maxlength[0] : "");
@ -233,14 +235,14 @@ foreach ($raw_array as $sub_array)
}
// Do JSON encoding before writing result to file
$json = json_encode($roas, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
$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);
$fp = fopen ('dn42-rpki-export.json', 'w');
fwrite ($fp, $json);
fclose ($fp);
// Commit and push to all git remote repositories
echo shell_exec("./update.sh 2>&1");
echo shell_exec ("./update.sh 2>&1");
?>