Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form action="" method="POST">
- <table>
- <tr>
- <td>BGP AS</td>
- <td><input type="text" value="" name="as" pattern="\d{1,6}"> брать <a href="https://bgp.he.net" target="_blank">тут</a></td>
- </tr>
- <tr>
- <td>Мангл или маршрут</td>
- <td>
- <select name="clas_m">
- <option value="route">route</option>
- <option value="mangle">mangle</option>
- </select>
- </td>
- </tr>
- <tr>
- <td>comment:</td>
- <td><input type="text" name="comment"></td>
- </tr>
- <tr>
- <td>routmark:</td>
- <td><input type="text" name="routmark"></td>
- </tr>
- </table>
- <input type="submit">
- </form>
- <pre>
- <?php
- if($_POST)
- {
- /*from bgpq3 geting list of IPv4 subnets from inputed AS*/
- exec("bgpq3 AS$_POST[as] -A", $output);
- unset($output[0]);
- /*check mangle or route we create*/
- switch ($_POST['clas_m'])
- {
- case "mangle":
- echo "/ip firewall mangle <BR>";
- break;
- case "route":
- echo "/ip route <BR>";
- break;
- }
- foreach ($output as $key=>$prefix)
- {
- /*cuting text prefix output of bgpq3*/
- $output[$key]=str_replace("ip prefix-list NN permit ", "", $prefix);
- }
- foreach ($output as $key=>$prefix)
- {
- /*шукаємо символи характерні для рядка вже загрегованого діапазону*/
- $num_a=0;
- $num_a=stripos($prefix, " ge");
- /*if their present than cuting him from end of string*/
- if ($num_a>0)
- {
- $adress=$output[$key];
- $output[$key]=substr($adress, 0, $num_a);
- }
- $num_a=0;
- $num_a=stripos($prefix, " le");
- /*if their present than cuting him from end of string*/
- if ($num_a>0)
- {
- $adress=$output[$key];
- $output[$key]=substr($adress, 0, $num_a);
- }
- //echo $output[$key]."<BR>";
- }
- /*deleting duplicate values, from output of bgpq3*/
- $output=array_unique($output);
- foreach ($output as $key1=>$ipaddr1)
- {
- /*parsing address to two variables - adres and mask*/
- list($base1, $bits1) = explode('/', $ipaddr1);
- /*parsing adres to 4 variables, each for one octet*/
- list($a, $b, $c, $d) = explode('.', $base1);
- /*transform octets to binary view, 8 symbols*/
- $a_bin=sprintf("%08b", $a);
- $b_bin=sprintf("%08b", $b);
- $c_bin=sprintf("%08b", $c);
- $d_bin=sprintf("%08b", $d);
- /*create binary view of all adress*/
- $adress1=$a_bin.$b_bin.$c_bin.$d_bin;
- /*extrakt subnet from address*/
- $net1=substr($adress1,0,$bits1);
- $adre1= str_replace($net1, "", $adress1);
- foreach ($output as $key2=>$ipaddr2)
- {
- if ($key2==$key1)
- {
- continue;
- }
- list($base2, $bits2) = explode('/', $ipaddr2);
- list($a, $b, $c, $d) = explode('.', $base2);
- $a_bin=sprintf("%08b", $a);
- $b_bin=sprintf("%08b", $b);
- $c_bin=sprintf("%08b", $c);
- $d_bin=sprintf("%08b", $d);
- $adress2=$a_bin.$b_bin.$c_bin.$d_bin;
- $net2=substr($adress2,0,$bits2);
- $adre2= str_replace($net2, "", $adress2);
- /*search smaller mask*/
- if($bits2>$bits1)
- {
- /*search first %bits1% symbols of adres2*/
- $net_check_2=substr($adress2,0,$bits1);
- /*if net2 is a part of net1*/
- if ($net_check_2==$net1)
- {
- unset($output[$key2]);
- //echo "unseting output $key2 because his part of $key1<BR>";
- continue;
- }
- }
- }
- }
- foreach ($output as $key=>$prefix)
- {
- /*check mangle or route we create*/
- switch ($_POST['clas_m'])
- {
- case "mangle":
- echo "add action=mark-routing chain=prerouting comment=$_POST[comment] dst-address=$prefix new-routing-mark=$_POST[routmark] passthrough=yes<BR>";
- break;
- case "route":
- /*if routmark is present then adding him to the text*/
- if ($_POST['routmark']!="")
- {
- $routemark=" routing-mark=$_POST[routmark]";
- }
- else
- {
- $routemark="";
- }
- echo "add comment=$_POST[comment] distance=1 dst-address=$prefix gateway=1.1.1.1$routemark<BR>";
- break;
- }
- }
- }
- ?>
- </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement