control-subnets.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
  3. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
  4. if (isset($_POST["s_remove"])) {
  5. if (!empty($_POST["s_id"])) {
  6. $s_id = $_POST["s_id"];
  7. foreach ($s_id as $key => $net_id) {
  8. if (isset($net_id)) {
  9. LOG_INFO($db_link, "Remove subnet id: $net_id");
  10. delete_record($db_link, "subnets", "id=" . $net_id);
  11. }
  12. }
  13. }
  14. header("Location: " . $_SERVER["REQUEST_URI"]);
  15. exit;
  16. }
  17. if (isset($_POST['s_save'])) {
  18. if (!empty($_POST["s_id"])) {
  19. $s_id = $_POST["s_id"];
  20. foreach ($s_id as $key => $net_id) {
  21. if (isset($net_id)) {
  22. $new['subnet'] = trim($_POST['s_subnet'][$net_id]);
  23. $new['office'] = $_POST['s_office'][$net_id] * 1;
  24. $new['hotspot'] = $_POST['s_hotspot'][$net_id] * 1;
  25. $new['vpn'] = $_POST['s_vpn'][$net_id] * 1;
  26. $new['free'] = $_POST['s_free'][$net_id] * 1;
  27. $new['dhcp'] = $_POST['s_dhcp'][$net_id] * 1;
  28. $new['dhcp_lease_time'] = $_POST['s_lease_time'][$net_id] * 1;
  29. $new['static'] = $_POST['s_static'][$net_id] * 1;
  30. $new['discovery'] = $_POST['s_discovery'][$net_id] * 1;
  31. $new['dhcp_update_hostname'] = $_POST['s_dhcp_update'][$net_id] * 1;
  32. $new['comment'] = trim($_POST['s_comment'][$net_id]);
  33. $range = cidrToRange($new['subnet']);
  34. $first_user_ip = $range[0];
  35. $last_user_ip = $range[1];
  36. $cidr = $range[2][1];
  37. if (isset($cidr) and $cidr <= 32) {
  38. $new['subnet'] = $first_user_ip . '/' . $cidr;
  39. } else {
  40. $new['subnet'] = '';
  41. }
  42. $new['ip_int_start'] = ip2long($first_user_ip);
  43. $new['ip_int_stop'] = ip2long($last_user_ip);
  44. $new['dhcp_start'] = ip2long(trim($_POST['s_dhcp_start'][$net_id]));
  45. $new['dhcp_stop'] = ip2long(trim($_POST['s_dhcp_stop'][$net_id]));
  46. $dhcp_fail = 0;
  47. if (!isset($new['dhcp_start']) or $new['dhcp_start'] == 0) {
  48. $dhcp_fail = 1;
  49. }
  50. if (!isset($new['dhcp_stop']) or $new['dhcp_stop'] == 0) {
  51. $dhcp_fail = 1;
  52. }
  53. if (!$dhcp_fail and ($new['dhcp_start'] - $new['ip_int_stop'] >= 0)) {
  54. $dhcp_fail = 1;
  55. }
  56. if (!$dhcp_fail and ($new['dhcp_start'] - $new['ip_int_start'] <= 0)) {
  57. $dhcp_fail = 1;
  58. }
  59. if (!$dhcp_fail and ($new['dhcp_stop'] - $new['ip_int_stop'] >= 0)) {
  60. $dhcp_fail = 1;
  61. }
  62. if (!$dhcp_fail and ($new['dhcp_stop'] - $new['ip_int_start'] <= 0)) {
  63. $dhcp_fail = 1;
  64. }
  65. if (!$dhcp_fail and ($new['dhcp_start'] - $new['dhcp_stop'] >= 0)) {
  66. $dhcp_fail = 1;
  67. }
  68. if ($dhcp_fail) {
  69. $new['dhcp_start'] = ip2long($range[3]);
  70. $new['dhcp_stop'] = ip2long($range[4]);
  71. }
  72. $gateway = ip2long(trim($_POST['s_gateway'][$net_id]));
  73. if (!isset($gateway)) {
  74. $gateway = $range[5];
  75. }
  76. $new['gateway'] = $gateway;
  77. if ($new['hotspot']) {
  78. $new['dhcp_update_hostname'] = 0;
  79. $new['discovery'] = 0;
  80. $new['vpn'] = 0;
  81. }
  82. if ($new['vpn']) {
  83. $new['discovery'] = 0;
  84. $new['dhcp'] = 0;
  85. }
  86. if ($new['office']) {
  87. $new['free'] = 0;
  88. }
  89. if (!$new['office']) {
  90. $new['discovery'] = 0;
  91. $new['dhcp'] = 0;
  92. $new['static'] = 0;
  93. $new['dhcp_update_hostname'] = 0;
  94. $new['gateway'] = 0;
  95. $new['dhcp_start'] = 0;
  96. $new['dhcp_stop'] = 0;
  97. }
  98. update_record($db_link, "subnets", "id='$net_id'", $new);
  99. }
  100. }
  101. }
  102. header("Location: " . $_SERVER["REQUEST_URI"]);
  103. exit;
  104. }
  105. if (isset($_POST["s_create"])) {
  106. $new_subnet = $_POST["s_create_subnet"];
  107. if (isset($new_subnet)) {
  108. $new['subnet'] = trim($new_subnet);
  109. $range = cidrToRange($new['subnet']);
  110. $first_user_ip = $range[0];
  111. $last_user_ip = $range[1];
  112. $cidr = $range[2][1];
  113. if (isset($cidr) and $cidr < 32) {
  114. $ip = $first_user_ip . '/' . $cidr;
  115. } else {
  116. $ip = $first_user_ip;
  117. }
  118. $new['ip_int_start'] = ip2long($first_user_ip);
  119. $new['ip_int_stop'] = ip2long($last_user_ip);
  120. $new['dhcp_start'] = ip2long($range[3]);
  121. $new['dhcp_stop'] = ip2long($range[4]);
  122. $new['gateway'] = ip2long($range[5]);
  123. LOG_INFO($db_link, "Create new subnet $new_subnet");
  124. insert_record($db_link, "subnets", $new);
  125. }
  126. header("Location: " . $_SERVER["REQUEST_URI"]);
  127. exit;
  128. }
  129. unset($_POST);
  130. fix_auth_rules($db_link);
  131. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
  132. print_control_submenu($page_url);
  133. ?>
  134. <div id="cont">
  135. <br>
  136. <form name="def" action="control-subnets.php" method="post">
  137. <div>
  138. <?php print WEB_network_create . "&nbsp:<input type=\"text\" name='s_create_subnet' value=''>"; ?>
  139. <input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>">
  140. <button class="button_right" name='s_save' value='save'><?php print WEB_btn_save; ?></button>
  141. <input type="submit" onclick="return confirm('<?php print WEB_btn_delete; ?>?')" name="s_remove" value="<?php print WEB_btn_remove; ?>">
  142. </div>
  143. <b><?php echo WEB_network_org_title; ?></b> <br>
  144. <table class="data">
  145. <tr align="center">
  146. <td></td>
  147. <td><b><?php echo WEB_network_subnet; ?></b></td>
  148. <td><b><?php echo WEB_network_gateway; ?></b></td>
  149. <td><b><?php echo WEB_network_use_dhcp; ?></b></td>
  150. <td><b><?php echo WEB_network_static; ?></b></td>
  151. <td><b><?php echo WEB_network_dhcp_first; ?></b></td>
  152. <td><b><?php echo WEB_network_dhcp_last; ?></b></td>
  153. <td><b><?php echo WEB_network_dhcp_leasetime; ?></b></td>
  154. <td><b><?php echo WEB_network_office_subnet; ?></b></td>
  155. <td><b><?php echo WEB_network_hotspot; ?></b></td>
  156. <td><b><?php echo WEB_network_vpn; ?></b></td>
  157. <td><b><?php echo WEB_network_free; ?></b></td>
  158. <td><b><?php echo WEB_network_dyndns; ?></b></td>
  159. <td><b><?php echo WEB_network_discovery; ?></b></td>
  160. <td><b><?php echo WEB_cell_comment; ?></b></td>
  161. </tr>
  162. <?php
  163. $t_subnets = get_records($db_link, 'subnets', 'True ORDER BY ip_int_start');
  164. foreach ($t_subnets as $row) {
  165. print "<tr align=center>\n";
  166. $cl = "data";
  167. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=s_id[] value='" . $row['id'] . "'></td>\n";
  168. print "<td class=\"$cl\"><input type=\"text\" name='s_subnet[" . $row['id'] . "]' value='".$row['subnet']."' size='18'></td>\n";
  169. $cell_disabled = '';
  170. if ($row['office'] and !$row['vpn']) {
  171. $default_range = cidrToRange($row['subnet']);
  172. if (!isset($row['dhcp_start']) or !($row['dhcp_start'] > 0)) {
  173. $row['dhcp_start'] = ip2long($default_range[3]);
  174. }
  175. if (!isset($row['dhcp_stop']) or !($row['dhcp_stop'] > 0)) {
  176. $row['dhcp_stop'] = ip2long($default_range[4]);
  177. }
  178. } else {
  179. $cell_disabled = 'readonly=true';
  180. $cl = 'down';
  181. }
  182. print "<td class=\"$cl\"><input type=\"text\" name='s_gateway[" . $row['id'] . "]' value='" . long2ip($row['gateway']) . "' size='15' $cell_disabled></td>\n";
  183. if ($row['dhcp']) {
  184. $cl = 'up';
  185. } else {
  186. $cl = 'data';
  187. }
  188. print "<td class=\"$cl\">";
  189. print_qa_select("s_dhcp[" . $row['id'] . "]", $row['dhcp']);
  190. print "</td>\n";
  191. if ($row['static']) {
  192. $cl = 'up';
  193. } else {
  194. $cl = 'data';
  195. }
  196. print "<td class=\"$cl\">";
  197. print_qa_select("s_static[" . $row['id'] . "]", $row['static']);
  198. print "</td>\n";
  199. $cl = 'data';
  200. print "<td class=\"$cl\"><input type=\"text\" name='s_dhcp_start[" . $row['id'] . "]' value='" . long2ip($row['dhcp_start']) . "' size='15' $cell_disabled></td>\n";
  201. print "<td class=\"$cl\"><input type=\"text\" name='s_dhcp_stop[" . $row['id'] . "]' value='" . long2ip($row['dhcp_stop']) . "' size='15' $cell_disabled></td>\n";
  202. print "<td class=\"$cl\"><input type=\"text\" name='s_lease_time[" . $row['id'] . "]' value='" . $row['dhcp_lease_time'] . "'size='3' $cell_disabled></td>\n";
  203. $row_cl = 'data';
  204. if (!$row['office']) {
  205. $row_cl = 'down';
  206. }
  207. if ($row['office']) {
  208. $cl = 'up';
  209. } else {
  210. $cl = 'data';
  211. }
  212. print "<td class=\"$cl\">";
  213. print_qa_select("s_office[" . $row['id'] . "]", $row['office']);
  214. print "</td>\n";
  215. if ($row_cl === 'data' and $row['hotspot']) {
  216. $cl = 'up';
  217. } else {
  218. $cl = $row_cl;
  219. }
  220. print "<td class=\"$cl\">";
  221. print_qa_select_ext("s_hotspot[" . $row['id'] . "]", $row['hotspot'], !$row['office']);
  222. print "</td>\n";
  223. if ($row_cl === 'data' and $row['vpn']) {
  224. $cl = 'up';
  225. } else {
  226. $cl = $row_cl;
  227. }
  228. print "<td class=\"$cl\">";
  229. print_qa_select_ext("s_vpn[" . $row['id'] . "]", $row['vpn'], !$row['office']);
  230. print "</td>\n";
  231. if ($row['free']) {
  232. $cl = 'up';
  233. } else {
  234. $cl = $row_cl;
  235. }
  236. print "<td class=\"$cl\">";
  237. print_qa_select("s_free[" . $row['id'] . "]", $row['free']);
  238. print "</td>\n";
  239. if ($row_cl === 'data' and $row['dhcp_update_hostname']) {
  240. $cl = 'up';
  241. } else {
  242. $cl = $row_cl;
  243. }
  244. print "<td class=\"$cl\">";
  245. print_qa_select_ext("s_dhcp_update[" . $row['id'] . "]", $row['dhcp_update_hostname'], !$row['office']);
  246. print "</td>\n";
  247. if ($row_cl === 'data' and $row['discovery']) {
  248. $cl = 'up';
  249. } else {
  250. $cl = $row_cl;
  251. }
  252. print "<td class=\"$cl\">";
  253. print_qa_select_ext("s_discovery[" . $row['id'] . "]", $row['discovery'], !$row['office']);
  254. print "</td>\n";
  255. print "<td class=\"data\"><input type=\"text\" name='s_comment[" . $row['id'] . "]' value='".$row['comment']."'></td>\n";
  256. print "</tr>\n";
  257. }
  258. ?>
  259. </table>
  260. </form>
  261. <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php"); ?>