Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. <form action="" method="POST">
  2. <table>
  3. <tr>
  4. <td>BGP AS</td>
  5. <td><input type="text" value="" name="as" pattern="\d{1,6}"> брать <a href="https://bgp.he.net" target="_blank">тут</a></td>
  6. </tr>
  7. <tr>
  8. <td>Мангл или маршрут</td>
  9. <td>
  10. <select name="clas_m">
  11. <option value="route">route</option>
  12. <option value="mangle">mangle</option>
  13. </select>
  14. </td>
  15. </tr>
  16. <tr>
  17. <td>comment:</td>
  18. <td><input type="text" name="comment"></td>
  19. </tr>
  20. <tr>
  21. <td>routmark:</td>
  22. <td><input type="text" name="routmark"></td>
  23. </tr>
  24. </table>
  25. <input type="submit">
  26. </form>
  27. <pre>
  28. <?php
  29. if($_POST)
  30. {
  31. /*from bgpq3 geting list of IPv4 subnets from inputed AS*/
  32. exec("bgpq3 AS$_POST[as] -A", $output);
  33. unset($output[0]);
  34. /*check mangle or route we create*/
  35. switch ($_POST['clas_m'])
  36. {
  37. case "mangle":
  38. echo "/ip firewall mangle <BR>";
  39. break;
  40. case "route":
  41. echo "/ip route <BR>";
  42. break;
  43. }
  44. foreach ($output as $key=>$prefix)
  45. {
  46. /*cuting text prefix output of bgpq3*/
  47. $output[$key]=str_replace("ip prefix-list NN permit ", "", $prefix);
  48. }
  49. foreach ($output as $key=>$prefix)
  50. {
  51. /*шукаємо символи характерні для рядка вже загрегованого діапазону*/
  52. $num_a=0;
  53. $num_a=stripos($prefix, " ge");
  54. /*if their present than cuting him from end of string*/
  55. if ($num_a>0)
  56. {
  57. $adress=$output[$key];
  58. $output[$key]=substr($adress, 0, $num_a);
  59. }
  60. $num_a=0;
  61. $num_a=stripos($prefix, " le");
  62. /*if their present than cuting him from end of string*/
  63. if ($num_a>0)
  64. {
  65. $adress=$output[$key];
  66. $output[$key]=substr($adress, 0, $num_a);
  67. }
  68. //echo $output[$key]."<BR>";
  69. }
  70. /*deleting duplicate values, from output of bgpq3*/
  71. $output=array_unique($output);
  72. foreach ($output as $key1=>$ipaddr1)
  73. {
  74. /*parsing address to two variables - adres and mask*/
  75. list($base1, $bits1) = explode('/', $ipaddr1);
  76. /*parsing adres to 4 variables, each for one octet*/
  77. list($a, $b, $c, $d) = explode('.', $base1);
  78. /*transform octets to binary view, 8 symbols*/
  79. $a_bin=sprintf("%08b", $a);
  80. $b_bin=sprintf("%08b", $b);
  81. $c_bin=sprintf("%08b", $c);
  82. $d_bin=sprintf("%08b", $d);
  83. /*create binary view of all adress*/
  84. $adress1=$a_bin.$b_bin.$c_bin.$d_bin;
  85. /*extrakt subnet from address*/
  86. $net1=substr($adress1,0,$bits1);
  87. $adre1= str_replace($net1, "", $adress1);
  88. foreach ($output as $key2=>$ipaddr2)
  89. {
  90. if ($key2==$key1)
  91. {
  92. continue;
  93. }
  94. list($base2, $bits2) = explode('/', $ipaddr2);
  95. list($a, $b, $c, $d) = explode('.', $base2);
  96. $a_bin=sprintf("%08b", $a);
  97. $b_bin=sprintf("%08b", $b);
  98. $c_bin=sprintf("%08b", $c);
  99. $d_bin=sprintf("%08b", $d);
  100. $adress2=$a_bin.$b_bin.$c_bin.$d_bin;
  101. $net2=substr($adress2,0,$bits2);
  102. $adre2= str_replace($net2, "", $adress2);
  103. /*search smaller mask*/
  104. if($bits2>$bits1)
  105. {
  106. /*search first %bits1% symbols of adres2*/
  107. $net_check_2=substr($adress2,0,$bits1);
  108. /*if net2 is a part of net1*/
  109. if ($net_check_2==$net1)
  110. {
  111. unset($output[$key2]);
  112. //echo "unseting output $key2 because his part of $key1<BR>";
  113. continue;
  114. }
  115. }
  116. }
  117. }
  118. foreach ($output as $key=>$prefix)
  119. {
  120. /*check mangle or route we create*/
  121. switch ($_POST['clas_m'])
  122. {
  123. case "mangle":
  124. echo "add action=mark-routing chain=prerouting comment=$_POST[comment] dst-address=$prefix new-routing-mark=$_POST[routmark] passthrough=yes<BR>";
  125. break;
  126. case "route":
  127. /*if routmark is present then adding him to the text*/
  128. if ($_POST['routmark']!="")
  129. {
  130. $routemark=" routing-mark=$_POST[routmark]";
  131. }
  132. else
  133. {
  134. $routemark="";
  135. }
  136. echo "add comment=$_POST[comment] distance=1 dst-address=$prefix gateway=1.1.1.1$routemark<BR>";
  137. break;
  138. }
  139.  
  140.  
  141. }
  142. }
  143. ?>
  144. </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement