control-subnets.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. $s_id = $_POST["s_id"];
  6. if (!empty($s_id)) {
  7. foreach ($s_id as $key => $val) {
  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. exit;
  16. }
  17. if (isset($_POST['s_save'])) {
  18. $len = is_array($_POST['s_save']) ? count($_POST['s_save']) : 0;
  19. for ($i = 0; $i < $len; $i++) {
  20. $save_id = intval($_POST['s_save'][$i]);
  21. $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
  22. for ($j = 0; $j < $len_all; $j++) {
  23. if (intval($_POST['n_id'][$j]) != $save_id) {
  24. continue;
  25. }
  26. $new['subnet'] = trim($_POST['s_subnet'][$j]);
  27. $new['office'] = $_POST['s_office'][$j] * 1;
  28. $new['hotspot'] = $_POST['s_hotspot'][$j] * 1;
  29. $new['vpn'] = $_POST['s_vpn'][$j] * 1;
  30. $new['free'] = $_POST['s_free'][$j] * 1;
  31. $new['dhcp'] = $_POST['s_dhcp'][$j] * 1;
  32. $new['dhcp_lease_time'] = $_POST['s_lease_time'][$j] * 1;
  33. $new['static'] = $_POST['s_static'][$j] * 1;
  34. $new['discovery'] = $_POST['s_discovery'][$j] * 1;
  35. $new['dhcp_update_hostname'] = $_POST['s_dhcp_update'][$j] * 1;
  36. $new['comment'] = trim($_POST['s_comment'][$j]);
  37. $range = cidrToRange($new['subnet']);
  38. $first_user_ip = $range[0];
  39. $last_user_ip = $range[1];
  40. $cidr = $range[2][1];
  41. if (isset($cidr) and $cidr <= 32) {
  42. $new['subnet'] = $first_user_ip . '/' . $cidr;
  43. } else {
  44. $new['subnet'] = '';
  45. }
  46. $new['ip_int_start'] = ip2long($first_user_ip);
  47. $new['ip_int_stop'] = ip2long($last_user_ip);
  48. $new['dhcp_start'] = ip2long(trim($_POST['s_dhcp_start'][$j]));
  49. $new['dhcp_stop'] = ip2long(trim($_POST['s_dhcp_stop'][$j]));
  50. $dhcp_fail = 0;
  51. if (!isset($new['dhcp_start']) or $new['dhcp_start'] == 0) {
  52. $dhcp_fail = 1;
  53. }
  54. if (!isset($new['dhcp_stop']) or $new['dhcp_stop'] == 0) {
  55. $dhcp_fail = 1;
  56. }
  57. if (!$dhcp_fail and ($new['dhcp_start'] - $new['ip_int_stop'] >= 0)) {
  58. $dhcp_fail = 1;
  59. }
  60. if (!$dhcp_fail and ($new['dhcp_start'] - $new['ip_int_start'] <= 0)) {
  61. $dhcp_fail = 1;
  62. }
  63. if (!$dhcp_fail and ($new['dhcp_stop'] - $new['ip_int_stop'] >= 0)) {
  64. $dhcp_fail = 1;
  65. }
  66. if (!$dhcp_fail and ($new['dhcp_stop'] - $new['ip_int_start'] <= 0)) {
  67. $dhcp_fail = 1;
  68. }
  69. if (!$dhcp_fail and ($new['dhcp_start'] - $new['dhcp_stop'] >= 0)) {
  70. $dhcp_fail = 1;
  71. }
  72. if ($dhcp_fail) {
  73. $new['dhcp_start'] = ip2long($range[3]);
  74. $new['dhcp_stop'] = ip2long($range[4]);
  75. }
  76. $gateway = ip2long(trim($_POST['s_gateway'][$j]));
  77. if (!isset($gateway)) {
  78. $gateway = $range[5];
  79. }
  80. $new['gateway'] = $gateway;
  81. if ($new['hotspot']) {
  82. $new['dhcp_update_hostname'] = 0;
  83. $new['discovery'] = 0;
  84. $new['vpn'] = 0;
  85. }
  86. if ($new['vpn']) {
  87. $new['discovery'] = 0;
  88. $new['dhcp'] = 0;
  89. }
  90. if ($new['office']) {
  91. $new['free'] = 0;
  92. }
  93. if (!$new['office']) {
  94. $new['discovery'] = 0;
  95. $new['dhcp'] = 0;
  96. $new['static'] = 0;
  97. $new['dhcp_update_hostname'] = 0;
  98. $new['gateway'] = 0;
  99. $new['dhcp_start'] = 0;
  100. $new['dhcp_stop'] = 0;
  101. }
  102. update_record($db_link, "subnets", "id='{$save_id}'", $new);
  103. }
  104. }
  105. header("Location: " . $_SERVER["REQUEST_URI"]);
  106. exit;
  107. }
  108. if (isset($_POST["s_create"])) {
  109. $new_subnet = $_POST["s_create_subnet"];
  110. if (isset($new_subnet)) {
  111. $new['subnet'] = trim($new_subnet);
  112. $range = cidrToRange($new['subnet']);
  113. $first_user_ip = $range[0];
  114. $last_user_ip = $range[1];
  115. $cidr = $range[2][1];
  116. if (isset($cidr) and $cidr < 32) {
  117. $ip = $first_user_ip . '/' . $cidr;
  118. } else {
  119. $ip = $first_user_ip;
  120. }
  121. $new['ip_int_start'] = ip2long($first_user_ip);
  122. $new['ip_int_stop'] = ip2long($last_user_ip);
  123. $new['dhcp_start'] = ip2long($range[3]);
  124. $new['dhcp_stop'] = ip2long($range[4]);
  125. $new['gateway'] = ip2long($range[5]);
  126. LOG_INFO($db_link, "Create new subnet $new_subnet");
  127. insert_record($db_link, "subnets", $new);
  128. }
  129. header("Location: " . $_SERVER["REQUEST_URI"]);
  130. exit;
  131. }
  132. unset($_POST);
  133. fix_auth_rules($db_link);
  134. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
  135. print_control_submenu($page_url);
  136. ?>
  137. <div id="cont">
  138. <br>
  139. <form name="def" action="control-subnets.php" method="post">
  140. <b><?php echo WEB_network_org_title; ?></b> <br>
  141. <table class="data">
  142. <tr align="center">
  143. <td></td>
  144. <td width=30><b>id</b></td>
  145. <td><b><?php echo WEB_network_subnet; ?></b></td>
  146. <td><b><?php echo WEB_network_gateway; ?></b></td>
  147. <td><b><?php echo WEB_network_use_dhcp; ?></b></td>
  148. <td><b><?php echo WEB_network_static; ?></b></td>
  149. <td><b><?php echo WEB_network_dhcp_first; ?></b></td>
  150. <td><b><?php echo WEB_network_dhcp_last; ?></b></td>
  151. <td><b><?php echo WEB_network_dhcp_leasetime; ?></b></td>
  152. <td><b><?php echo WEB_network_office_subnet; ?></b></td>
  153. <td><b><?php echo WEB_network_hotspot; ?></b></td>
  154. <td><b><?php echo WEB_network_vpn; ?></b></td>
  155. <td><b><?php echo WEB_network_free; ?></b></td>
  156. <td><b><?php echo WEB_network_dyndns; ?></b></td>
  157. <td><b><?php echo WEB_network_discovery; ?></b></td>
  158. <td><b><?php echo WEB_cell_comment; ?></b></td>
  159. <td><input type="submit" onclick="return confirm('<?php print WEB_btn_delete; ?>?')" name="s_remove" value="<?php print WEB_btn_remove; ?>"></td>
  160. </tr>
  161. <?php
  162. $t_subnets = get_records($db_link, 'subnets', 'True ORDER BY ip_int_start');
  163. foreach ($t_subnets as $row) {
  164. print "<tr align=center>\n";
  165. $cl = "data";
  166. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
  167. print "<td class=\"$cl\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  168. print "<td class=\"$cl\"><input type=\"text\" name='s_subnet[]' 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[]' 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['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['static']);
  198. print "</td>\n";
  199. $cl = 'data';
  200. print "<td class=\"$cl\"><input type=\"text\" name='s_dhcp_start[]' value='" . long2ip($row['dhcp_start']) . "' size='15' $cell_disabled></td>\n";
  201. print "<td class=\"$cl\"><input type=\"text\" name='s_dhcp_stop[]' value='" . long2ip($row['dhcp_stop']) . "' size='15' $cell_disabled></td>\n";
  202. print "<td class=\"$cl\"><input type=\"text\" name='s_lease_time[]' 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['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['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['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['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['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['discovery'], !$row['office']);
  254. print "</td>\n";
  255. print "<td class=\"data\"><input type=\"text\" name='s_comment[]' value='{$row['comment']}'></td>\n";
  256. print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>" . WEB_btn_save . "</button></td>\n";
  257. print "</tr>\n";
  258. }
  259. ?>
  260. <tr>
  261. <td colspan=6><?php print WEB_network_create . "&nbsp:<input type=\"text\" name='s_create_subnet' value=''>"; ?></td>
  262. <td><input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>"></td>
  263. </tr>
  264. </table>
  265. </form>
  266. <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php"); ?>