control-subnets.php 9.3 KB

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