control-subnets.php 8.8 KB

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