2018-12-18 12:52:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function:
|
|
|
|
* checkoutMaster ()
|
|
|
|
*
|
|
|
|
* Checkout git master branch.
|
|
|
|
*/
|
|
|
|
function checkoutMaster ()
|
|
|
|
{
|
2020-02-02 20:01:05 +00:00
|
|
|
echo shell_exec ("/usr/bin/git -C ../registry/ checkout master --quiet 2>&1");
|
2018-12-18 12:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function:
|
|
|
|
* startsWith ($string, "word", $length)
|
|
|
|
*
|
|
|
|
* Find lines beginning with "word". Optionally
|
|
|
|
* give the length of the string you are looking for.
|
|
|
|
*/
|
|
|
|
function startsWith ($haystack, $needle, $length = "0")
|
|
|
|
{
|
|
|
|
if ($length <= 0 || $length > (strlen ($needle)))
|
|
|
|
$length = strlen ($needle);
|
|
|
|
|
|
|
|
return (substr ($haystack, 0, $length) === $needle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function:
|
|
|
|
* endsWith ($string, "word")
|
|
|
|
*
|
|
|
|
* Find lines ending with "word".
|
|
|
|
*/
|
|
|
|
function endsWith ($haystack, $needle)
|
|
|
|
{
|
|
|
|
$length = strlen ($needle);
|
|
|
|
|
|
|
|
if ($length == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return (substr( $haystack, -$length) === $needle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function:
|
|
|
|
* trim_special_chars ($string)
|
|
|
|
*
|
|
|
|
* Remove special characters.
|
|
|
|
*/
|
|
|
|
function trim_special_chars ($string)
|
|
|
|
{
|
|
|
|
return (trim ($string, " \t\n\r\0\x0B"));
|
|
|
|
}
|
|
|
|
|
2018-12-18 13:21:26 +00:00
|
|
|
function writeBirdConfig ($roas)
|
2018-12-18 12:52:52 +00:00
|
|
|
{
|
2018-12-18 13:21:26 +00:00
|
|
|
$json = json_encode($roas, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
|
|
|
|
|
2019-01-05 20:56:27 +00:00
|
|
|
$bird1_fq = fopen ('roa/bird_roa_dn42.conf', 'w');
|
2019-01-03 13:37:29 +00:00
|
|
|
$bird1_fq4 = fopen ('roa/bird4_roa_dn42.conf', 'w');
|
|
|
|
$bird1_fq6 = fopen ('roa/bird6_roa_dn42.conf', 'w');
|
2018-12-18 13:00:14 +00:00
|
|
|
|
2019-01-05 20:56:27 +00:00
|
|
|
$bird2_fq = fopen ('roa/bird_route_dn42.conf', 'w');
|
2019-01-03 13:37:29 +00:00
|
|
|
$bird2_fq4 = fopen ('roa/bird4_route_dn42.conf', 'w');
|
|
|
|
$bird2_fq6 = fopen ('roa/bird6_route_dn42.conf', 'w');
|
|
|
|
|
2020-02-02 20:01:05 +00:00
|
|
|
fwrite ($bird1_fq, shell_exec ("/usr/bin/git -C ../registry/ log -n 1 --merges | sed 's/^/# /g'"));
|
|
|
|
fwrite ($bird1_fq4, shell_exec ("/usr/bin/git -C ../registry/ log -n 1 --merges | sed 's/^/# /g'"));
|
|
|
|
fwrite ($bird1_fq6, shell_exec ("/usr/bin/git -C ../registry/ log -n 1 --merges | sed 's/^/# /g'"));
|
2019-01-03 13:37:29 +00:00
|
|
|
|
2020-02-02 20:01:05 +00:00
|
|
|
fwrite ($bird2_fq, shell_exec ("/usr/bin/git -C ../registry/ log -n 1 --merges | sed 's/^/# /g'"));
|
|
|
|
fwrite ($bird2_fq4, shell_exec ("/usr/bin/git -C ../registry/ log -n 1 --merges | sed 's/^/# /g'"));
|
|
|
|
fwrite ($bird2_fq6, shell_exec ("/usr/bin/git -C ../registry/ log -n 1 --merges | sed 's/^/# /g'"));
|
2018-12-18 12:52:52 +00:00
|
|
|
|
|
|
|
foreach ($roas["roas"] as $roa)
|
|
|
|
{
|
2020-01-08 19:30:17 +00:00
|
|
|
$prefix = $roa["prefix"];
|
|
|
|
$maxLength = $roa["maxLength"];
|
|
|
|
$asn = $roa["asn"];
|
|
|
|
$source = $roa["ta"];
|
|
|
|
$mntby = $roa["mnt-by"];
|
2018-12-18 12:52:52 +00:00
|
|
|
|
2020-01-08 19:30:17 +00:00
|
|
|
$bird_strng = "$prefix max $maxLength as $asn;";
|
|
|
|
$bird_strng .= " # $source/$mntby";
|
|
|
|
|
|
|
|
$bird1_strng = "roa $bird_strng\n";
|
|
|
|
$bird2_strng = "route $bird_strng\n";
|
2019-01-03 13:37:29 +00:00
|
|
|
|
|
|
|
fwrite ($bird1_fq, $bird1_strng);
|
|
|
|
fwrite ($bird2_fq, $bird2_strng);
|
2018-12-18 12:52:52 +00:00
|
|
|
|
2020-01-08 19:30:17 +00:00
|
|
|
if (strpos ($prefix, ":") !== false)
|
2019-01-03 13:37:29 +00:00
|
|
|
{
|
|
|
|
fwrite ($bird1_fq6, $bird1_strng);
|
|
|
|
fwrite ($bird2_fq6, $bird2_strng);
|
|
|
|
}
|
2018-12-18 12:52:52 +00:00
|
|
|
else
|
2019-01-03 13:37:29 +00:00
|
|
|
{
|
|
|
|
fwrite ($bird1_fq4, $bird1_strng);
|
2019-01-05 20:56:27 +00:00
|
|
|
fwrite ($bird2_fq4, $bird2_strng);
|
2019-01-03 13:37:29 +00:00
|
|
|
}
|
2018-12-18 12:52:52 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:37:29 +00:00
|
|
|
fclose ($bird1_fq);
|
|
|
|
fclose ($bird1_fq4);
|
|
|
|
fclose ($bird1_fq6);
|
|
|
|
|
|
|
|
fclose ($bird2_fq);
|
|
|
|
fclose ($bird2_fq4);
|
|
|
|
fclose ($bird2_fq6);
|
2018-12-18 12:52:52 +00:00
|
|
|
}
|
|
|
|
|
2018-12-18 13:21:26 +00:00
|
|
|
function writeRoutinatorExceptionFile ($roas)
|
2018-12-18 12:52:52 +00:00
|
|
|
{
|
2018-12-18 13:21:26 +00:00
|
|
|
$json = json_encode($roas, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK);
|
|
|
|
|
2018-12-18 12:52:52 +00:00
|
|
|
$fp = fopen('roa/export_rfc8416_dn42.json', 'w');
|
|
|
|
|
|
|
|
fwrite($fp, $json);
|
|
|
|
|
|
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
|
2018-12-18 13:21:26 +00:00
|
|
|
function writeExportJSON ($roas)
|
2018-12-18 12:52:52 +00:00
|
|
|
{
|
2019-01-05 23:58:13 +00:00
|
|
|
$n = 0;
|
|
|
|
foreach ($roas['roas'] as $object)
|
|
|
|
{
|
|
|
|
$roas['roas'][$n]['asn'] = "AS" . $roas['roas'][$n]['asn'];
|
2020-01-08 18:24:38 +00:00
|
|
|
$roas['roas'][$n]['maxLength'] = (int)preg_replace('/\D/', '', $roas['roas'][$n]['maxLength']); // Ensure unquoted integer
|
2019-01-05 23:58:13 +00:00
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
|
2018-12-18 13:21:26 +00:00
|
|
|
$json = json_encode($roas, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
|
|
|
|
|
2018-12-18 12:52:52 +00:00
|
|
|
$fp = fopen ('roa/export_dn42.json', 'w');
|
|
|
|
|
|
|
|
fwrite ($fp, $json);
|
|
|
|
|
|
|
|
fclose ($fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|