control-subnets.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  4. if (isset($_POST["s_remove"])) {
  5. $s_id = $_POST["s_id"];
  6. while (list ($key, $val) = @each($s_id)) {
  7. if (isset($val)) {
  8. LOG_INFO($db_link, "Remove subnet id: $val");
  9. delete_record($db_link, "subnets", "id=" . $val);
  10. }
  11. }
  12. header("Location: " . $_SERVER["REQUEST_URI"]);
  13. }
  14. if (isset($_POST['s_save'])) {
  15. $len = is_array($_POST['s_save']) ? count($_POST['s_save']) : 0;
  16. for ($i = 0; $i < $len; $i ++) {
  17. $save_id = intval($_POST['s_save'][$i]);
  18. $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
  19. for ($j = 0; $j < $len_all; $j ++) {
  20. if (intval($_POST['n_id'][$j]) != $save_id) { continue; }
  21. $new[subnet] = trim($_POST['s_subnet'][$j]);
  22. $new[office] = $_POST['s_office'][$j]*1;
  23. $new[hotspot] = $_POST['s_hotspot'][$j]*1;
  24. $new[vpn] = $_POST['s_vpn'][$j]*1;
  25. $new[free] = $_POST['s_free'][$j]*1;
  26. $new[dhcp] = $_POST['s_dhcp'][$j]*1;
  27. $new[dhcp_lease_time] = $_POST['s_lease_time'][$j]*1;
  28. $new['static'] = $_POST['s_static'][$j]*1;
  29. $new[discovery] = $_POST['s_discovery'][$j]*1;
  30. $new[dhcp_update_hostname] = $_POST['s_dhcp_update'][$j]*1;
  31. $new[comment] = trim($_POST['s_comment'][$j]);
  32. $range = cidrToRange($new[subnet]);
  33. $first_user_ip = $range[0];
  34. $last_user_ip = $range[1];
  35. $cidr = $range[2][1];
  36. if (isset($cidr) and $cidr <= 32) {
  37. $new[subnet] = $first_user_ip . '/' . $cidr;
  38. } else {
  39. $new[subnet] = '';
  40. }
  41. $new[ip_int_start] = ip2long($first_user_ip);
  42. $new[ip_int_stop] = ip2long($last_user_ip);
  43. $new[dhcp_start] = ip2long(trim($_POST['s_dhcp_start'][$j]));
  44. $new[dhcp_stop] = ip2long(trim($_POST['s_dhcp_stop'][$j]));
  45. $dhcp_fail=0;
  46. if (!isset($new[dhcp_start]) or $new[dhcp_start]==0) { $dhcp_fail=1; }
  47. if (!isset($new[dhcp_stop]) or $new[dhcp_stop]==0) { $dhcp_fail=1; }
  48. if (!$dhcp_fail and ($new[dhcp_start]-$new[ip_int_stop] >= 0)) { $dhcp_fail=1; }
  49. if (!$dhcp_fail and ($new[dhcp_start]-$new[ip_int_start] <= 0)) { $dhcp_fail=1; }
  50. if (!$dhcp_fail and ($new[dhcp_stop]-$new[ip_int_stop]>=0)) { $dhcp_fail=1; }
  51. if (!$dhcp_fail and ($new[dhcp_stop]-$new[ip_int_start]<=0)) { $dhcp_fail=1; }
  52. if (!$dhcp_fail and ($new[dhcp_start]-$new[dhcp_stop]>=0)) { $dhcp_fail=1; }
  53. if ($dhcp_fail) {
  54. $new[dhcp_start]=ip2long($range[3]);
  55. $new[dhcp_stop]=ip2long($range[4]);
  56. }
  57. $gateway = ip2long(trim($_POST['s_gateway'][$j]));
  58. if (!isset($gateway)) { $gateway=$range[5]; }
  59. $new[gateway]=$gateway;
  60. if ($new[hotspot]) {
  61. $new[dhcp_update_hostname] = 0;
  62. $new[discovery] = 0;
  63. $new[vpn] = 0;
  64. }
  65. if ($new[vpn]) {
  66. $new[discovery] = 0;
  67. $new[dhcp] = 0;
  68. }
  69. if ($new[office]) {
  70. $new[free] = 0;
  71. }
  72. if (!$new[office]) {
  73. $new[discovery] = 0;
  74. $new[dhcp] = 0;
  75. $new['static'] = 0;
  76. $new[dhcp_update_hostname] = 0;
  77. $new[gateway] = 0;
  78. $new[dhcp_start] = 0;
  79. $new[dhcp_stop] = 0;
  80. }
  81. update_record($db_link, "subnets", "id='{$save_id}'", $new);
  82. }
  83. }
  84. header("Location: " . $_SERVER["REQUEST_URI"]);
  85. }
  86. if (isset($_POST["s_create"])) {
  87. $new_subnet = $_POST["s_create_subnet"];
  88. if (isset($new_subnet)) {
  89. $new[subnet] = trim($new_subnet);
  90. $range = cidrToRange($new[subnet]);
  91. $first_user_ip = $range[0];
  92. $last_user_ip = $range[1];
  93. $cidr = $range[2][1];
  94. if (isset($cidr) and $cidr < 32) {
  95. $ip = $first_user_ip . '/' . $cidr;
  96. } else {
  97. $ip = $first_user_ip;
  98. }
  99. $new[ip_int_start] = ip2long($first_user_ip);
  100. $new[ip_int_stop] = ip2long($last_user_ip);
  101. $new[dhcp_start] = ip2long($range[3]);
  102. $new[dhcp_stop] = ip2long($range[4]);
  103. $new[gateway] = ip2long($range[5]);
  104. LOG_INFO($db_link, "Create new subnet $new_subnet");
  105. insert_record($db_link, "subnets", $new);
  106. }
  107. header("Location: " . $_SERVER["REQUEST_URI"]);
  108. }
  109. unset($_POST);
  110. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  111. print_control_submenu($page_url);
  112. ?>
  113. <div id="cont">
  114. <br>
  115. <form name="def" action="control-subnets.php" method="post">
  116. <b>Сети организации</b> <br>
  117. <table class="data">
  118. <tr align="center">
  119. <td></td>
  120. <td width=30><b>id</b></td>
  121. <td><b>Сеть</b></td>
  122. <td><b>Шлюз</b></td>
  123. <td><b>DHCP</b></td>
  124. <td><b>Static</b></td>
  125. <td><b>DHCP start</b></td>
  126. <td><b>DHCP end</b></td>
  127. <td><b>Lease time,m</b></td>
  128. <td><b>Офисная</b></td>
  129. <td><b>Хот-спот</b></td>
  130. <td><b>VPN</b></td>
  131. <td><b>Free</b></td>
  132. <td><b>Обновлять dns</b></td>
  133. <td><b>Discovery</b></td>
  134. <td><b>Комментарий</b></td>
  135. <td><input type="submit" name="s_remove" value="Удалить"></td>
  136. </tr>
  137. <?
  138. $t_subnets = get_records($db_link,'subnets','True ORDER BY ip_int_start');
  139. foreach ( $t_subnets as $row ) {
  140. print "<tr align=center>\n";
  141. $cl="data";
  142. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
  143. print "<td class=\"$cl\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  144. print "<td class=\"$cl\"><input type=\"text\" name='s_subnet[]' value='{$row['subnet']}' size='18'></td>\n";
  145. $cell_disabled='';
  146. if ($row['office'] and !$row['vpn']) {
  147. $default_range=cidrToRange($row['subnet']);
  148. if (!isset($row['dhcp_start']) or !($row['dhcp_start']>0)) { $row['dhcp_start']=ip2long($default_range[3]); }
  149. if (!isset($row['dhcp_stop']) or !($row['dhcp_stop']>0)) { $row['dhcp_stop']=ip2long($default_range[4]); }
  150. } else {
  151. $cell_disabled='readonly=true';
  152. $cl='down';
  153. }
  154. print "<td class=\"$cl\"><input type=\"text\" name='s_gateway[]' value='".long2ip($row['gateway'])."' size='15' $cell_disabled></td>\n";
  155. if ($row['dhcp']) { $cl = 'up'; } else { $cl = 'data'; }
  156. print "<td class=\"$cl\">"; print_qa_select("s_dhcp[]",$row['dhcp']); print "</td>\n";
  157. if ($row['static']) { $cl = 'up'; } else { $cl = 'data'; }
  158. print "<td class=\"$cl\">"; print_qa_select("s_static[]",$row['static']); print "</td>\n";
  159. $cl = 'data';
  160. print "<td class=\"$cl\"><input type=\"text\" name='s_dhcp_start[]' value='".long2ip($row['dhcp_start'])."' size='15' $cell_disabled></td>\n";
  161. print "<td class=\"$cl\"><input type=\"text\" name='s_dhcp_stop[]' value='".long2ip($row['dhcp_stop'])."' size='15' $cell_disabled></td>\n";
  162. print "<td class=\"$cl\"><input type=\"text\" name='s_lease_time[]' value='".$row['dhcp_lease_time']."'size='3' $cell_disabled></td>\n";
  163. $row_cl = 'data';
  164. if (!$row['office']) { $row_cl='down'; }
  165. if ($row['office']) { $cl = 'up'; } else { $cl = 'data'; }
  166. print "<td class=\"$cl\">";
  167. print_qa_select("s_office[]",$row['office']);
  168. print "</td>\n";
  169. if ($row_cl ==='data' and $row['hotspot']) { $cl = 'up'; } else { $cl = $row_cl; }
  170. print "<td class=\"$cl\">";
  171. print_qa_select_ext("s_hotspot[]",$row['hotspot'],!$row['office']);
  172. print "</td>\n";
  173. if ($row_cl ==='data' and $row['vpn']) { $cl = 'up'; } else { $cl = $row_cl; }
  174. print "<td class=\"$cl\">";
  175. print_qa_select_ext("s_vpn[]",$row['vpn'],!$row['office']);
  176. print "</td>\n";
  177. if ($row['free']) { $cl = 'up'; } else { $cl = $row_cl; }
  178. print "<td class=\"$cl\">";
  179. print_qa_select("s_free[]",$row['free']);
  180. print "</td>\n";
  181. if ($row_cl ==='data' and $row['dhcp_update_hostname']) { $cl = 'up'; } else { $cl = $row_cl; }
  182. print "<td class=\"$cl\">";
  183. print_qa_select_ext("s_dhcp_update[]",$row['dhcp_update_hostname'],!$row['office']);
  184. print "</td>\n";
  185. if ($row_cl ==='data' and $row['discovery']) { $cl = 'up'; } else { $cl = $row_cl; }
  186. print "<td class=\"$cl\">";
  187. print_qa_select_ext("s_discovery[]",$row['discovery'],!$row['office']);
  188. print "</td>\n";
  189. print "<td class=\"data\"><input type=\"text\" name='s_comment[]' value='{$row['comment']}'></td>\n";
  190. print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>Сохранить</button></td>\n";
  191. print "</tr>\n";
  192. }
  193. ?>
  194. <tr>
  195. <td colspan=6>Новая сеть :<?php print "<input type=\"text\" name='s_create_subnet' value=''>"; ?></td>
  196. <td><input type="submit" name="s_create" value="Добавить"></td>
  197. </tr>
  198. </table>
  199. </form>
  200. <?php
  201. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  202. ?>