editsubnet.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
  3. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
  4. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/idfilter.php");
  5. if (isset($_POST['s_save'])) {
  6. $new['subnet'] = trim($_POST['s_subnet']);
  7. $new['vlan_tag'] = trim($_POST['s_vlan'])*1;
  8. if (empty($new['vlan_tag']) or ($new['vlan_tag']<1 or $new['vlan_tag']>4096)) { $new['vlan_tag'] =1; }
  9. $new['office'] = $_POST['s_office'] * 1;
  10. $new['hotspot'] = $_POST['s_hotspot'] * 1;
  11. $new['vpn'] = $_POST['s_vpn'] * 1;
  12. $new['free'] = $_POST['s_free'] * 1;
  13. $new['dhcp'] = $_POST['s_dhcp'] * 1;
  14. $new['dhcp_lease_time'] = $_POST['s_lease_time'] * 1;
  15. $new['static'] = $_POST['s_static'] * 1;
  16. $new['discovery'] = $_POST['s_discovery'] * 1;
  17. $new['dhcp_update_hostname'] = $_POST['s_dhcp_update'] * 1;
  18. $new['comment'] = trim($_POST['s_comment']);
  19. $range = cidrToRange($new['subnet']);
  20. $first_user_ip = $range[0];
  21. $last_user_ip = $range[1];
  22. $cidr = $range[2][1];
  23. if (isset($cidr) and $cidr <= 32) { $new['subnet'] = $first_user_ip . '/' . $cidr; } else { $new['subnet'] = ''; }
  24. $new['ip_int_start'] = ip2long($first_user_ip);
  25. $new['ip_int_stop'] = ip2long($last_user_ip);
  26. $new['dhcp_start'] = ip2long(trim($_POST['s_dhcp_start']));
  27. $new['dhcp_stop'] = ip2long(trim($_POST['s_dhcp_stop']));
  28. $dhcp_fail = 0;
  29. if (!isset($new['dhcp_start']) or $new['dhcp_start'] == 0) { $dhcp_fail = 1; }
  30. if (!isset($new['dhcp_stop']) or $new['dhcp_stop'] == 0) { $dhcp_fail = 1; }
  31. if (!$dhcp_fail and ($new['dhcp_start'] - $new['ip_int_stop'] >= 0)) { $dhcp_fail = 1; }
  32. if (!$dhcp_fail and ($new['dhcp_start'] - $new['ip_int_start'] <= 0)) { $dhcp_fail = 1; }
  33. if (!$dhcp_fail and ($new['dhcp_stop'] - $new['ip_int_stop'] >= 0)) { $dhcp_fail = 1; }
  34. if (!$dhcp_fail and ($new['dhcp_stop'] - $new['ip_int_start'] <= 0)) { $dhcp_fail = 1; }
  35. if (!$dhcp_fail and ($new['dhcp_start'] - $new['dhcp_stop'] >= 0)) { $dhcp_fail = 1; }
  36. if ($dhcp_fail) {
  37. $new['dhcp_start'] = ip2long($range[3]);
  38. $new['dhcp_stop'] = ip2long($range[4]);
  39. }
  40. $gateway = ip2long(trim($_POST['s_gateway']));
  41. if (!isset($gateway)) { $gateway = $range[5]; }
  42. $new['gateway'] = $gateway;
  43. if ($new['hotspot']) {
  44. $new['dhcp_update_hostname'] = 0;
  45. $new['discovery'] = 0;
  46. $new['vpn'] = 0;
  47. }
  48. if ($new['vpn']) {
  49. $new['discovery'] = 0;
  50. $new['dhcp'] = 0;
  51. }
  52. if ($new['office']) { $new['free'] = 0; }
  53. if (!$new['office']) {
  54. $new['discovery'] = 0;
  55. $new['dhcp'] = 0;
  56. $new['static'] = 0;
  57. $new['dhcp_update_hostname'] = 0;
  58. $new['gateway'] = 0;
  59. $new['dhcp_start'] = 0;
  60. $new['dhcp_stop'] = 0;
  61. }
  62. update_record($db_link, "subnets", "id='$id'", $new);
  63. header("Location: " . $_SERVER["REQUEST_URI"]);
  64. exit;
  65. }
  66. unset($_POST);
  67. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
  68. print_control_submenu($page_url);
  69. $sSQL = "SELECT * FROM subnets WHERE id=$id";
  70. $subnet_info = get_record_sql($db_link, $sSQL);
  71. ?>
  72. <div id="cont">
  73. <?php
  74. if (!empty($_SESSION[$page_url]['msg'])) {
  75. print '<div id="msg">' . $_SESSION[$page_url]['msg'] . '</div>';
  76. unset($_SESSION[$page_url]['msg']);
  77. }
  78. ?>
  79. <br>
  80. <form name="def" action="editsubnet.php?id=<?php echo $id; ?>" method="post">
  81. <input type="hidden" name="id" value=<?php echo $id; ?>>
  82. <table class="data">
  83. <td><td><b><?php echo WEB_network_subnet; ?></b></td>
  84. <?php
  85. $cl = "data";
  86. print "<td class=\"$cl\"><input type=\"text\" name='s_subnet' value='".$subnet_info['subnet']."' size='18'></td>\n";
  87. ?>
  88. <td><button name='s_save' value='save'><?php print WEB_btn_save; ?></button></td></tr>
  89. <td><td><b><?php echo WEB_cell_comment; ?></b></td>
  90. <?php print "<td colspan=2 class=\"data\"><input type=\"text\" name='s_comment' value='".$subnet_info['comment']."'></td>\n"; ?></tr>
  91. <td><td><b><?php echo WEB_network_vlan; ?></b></td>
  92. <?php print "<td colspan=2 class=\"data\"><input type=\"text\" name='s_vlan' value='".$subnet_info['vlan_tag']."' pattern='^(409[0-6]|(40[0-8]|[1-3]\d\d|[1-9]\d|[1-9])\d|[1-9])$'></td>\n"; ?></tr>
  93. <td><td><b><?php echo WEB_network_gateway; ?></b></td>
  94. <?php
  95. $cell_disabled = '';
  96. if ($subnet_info['office'] and !$subnet_info['vpn']) {
  97. $default_range = cidrToRange($subnet_info['subnet']);
  98. if (!isset($subnet_info['dhcp_start']) or !($subnet_info['dhcp_start'] > 0)) {
  99. $subnet_info['dhcp_start'] = ip2long($default_range[3]);
  100. }
  101. if (!isset($subnet_info['dhcp_stop']) or !($subnet_info['dhcp_stop'] > 0)) {
  102. $subnet_info['dhcp_stop'] = ip2long($default_range[4]);
  103. }
  104. } else {
  105. $cell_disabled = 'readonly=true';
  106. $cl = 'down';
  107. }
  108. print "<td colspan=2 class=\"$cl\"><input type=\"text\" name='s_gateway' value='" . long2ip($subnet_info['gateway']) . "' size='15' $cell_disabled></td>\n";
  109. ?>
  110. </tr>
  111. <td><td><b><?php echo WEB_network_use_dhcp; ?></b></td>
  112. <?php
  113. if ($subnet_info['dhcp']) { $cl = 'up'; } else { $cl = 'data'; }
  114. print "<td colspan=2 class=\"$cl\">";
  115. print_qa_select("s_dhcp", $subnet_info['dhcp']);
  116. print "</td>\n";
  117. ?>
  118. </tr>
  119. <td><td><b><?php echo WEB_network_static; ?></b></td>
  120. <?php
  121. if ($subnet_info['static']) { $cl = 'up'; } else { $cl = 'data'; }
  122. print "<td colspan=2 class=\"$cl\">";
  123. print_qa_select("s_static", $subnet_info['static']);
  124. print "</td>\n";
  125. $cl = 'data';
  126. ?>
  127. </tr>
  128. <td><td><b><?php echo WEB_network_dhcp_first; ?></b></td>
  129. <?php print "<td colspan=2 class=\"$cl\"><input type=\"text\" name='s_dhcp_start' value='" . long2ip($subnet_info['dhcp_start']) . "' size='15' $cell_disabled></td>\n"; ?></tr>
  130. <td><td><b><?php echo WEB_network_dhcp_last; ?></b></td>
  131. <?php print "<td colspan=2 class=\"$cl\"><input type=\"text\" name='s_dhcp_stop' value='" . long2ip($subnet_info['dhcp_stop']) . "' size='15' $cell_disabled></td>\n"; ?></tr>
  132. <td><td><b><?php echo WEB_network_dhcp_leasetime; ?></b></td>
  133. <?php print "<td colspan=2 class=\"$cl\"><input type=\"text\" name='s_lease_time' value='" . $subnet_info['dhcp_lease_time'] . "'size='3' $cell_disabled></td>\n"; ?></tr>
  134. <td><td><b><?php echo WEB_network_office_subnet; ?></b></td>
  135. <?php
  136. $row_cl = 'data';
  137. if (!$subnet_info['office']) { $row_cl = 'down'; }
  138. if ($subnet_info['office']) { $cl = 'up'; } else { $cl = 'data'; }
  139. print "<td colspan=2 class=\"$cl\">";
  140. print_qa_select("s_office", $subnet_info['office']);
  141. print "</td>\n";
  142. ?>
  143. </tr>
  144. <td><td><b><?php echo WEB_network_hotspot; ?></b></td>
  145. <?php
  146. if ($row_cl === 'data' and $subnet_info['hotspot']) { $cl = 'up'; } else { $cl = $row_cl; }
  147. print "<td colspan=2 class=\"$cl\">";
  148. print_qa_select_ext("s_hotspot", $subnet_info['hotspot'], !$subnet_info['office']);
  149. print "</td>\n";
  150. ?>
  151. </tr>
  152. <td><td><b><?php echo WEB_network_vpn; ?></b></td>
  153. <?php
  154. if ($row_cl === 'data' and $subnet_info['vpn']) { $cl = 'up'; } else { $cl = $row_cl; }
  155. print "<td colspan=2 class=\"$cl\">";
  156. print_qa_select_ext("s_vpn", $subnet_info['vpn'], !$subnet_info['office']);
  157. print "</td>\n";
  158. ?>
  159. </tr>
  160. <td><td><b><?php echo WEB_network_free; ?></b></td>
  161. <?php
  162. if ($subnet_info['free']) { $cl = 'up'; } else { $cl = $row_cl; }
  163. print "<td colspan=2 class=\"$cl\">";
  164. print_qa_select("s_free", $subnet_info['free']);
  165. print "</td>\n";
  166. ?>
  167. </tr>
  168. <td><td><b><?php echo WEB_network_dyndns; ?></b></td>
  169. <?php
  170. if ($row_cl === 'data' and $subnet_info['dhcp_update_hostname']) { $cl = 'up'; } else { $cl = $row_cl; }
  171. print "<td colspan=2 class=\"$cl\">";
  172. print_qa_select_ext("s_dhcp_update", $subnet_info['dhcp_update_hostname'], !$subnet_info['office']);
  173. print "</td>\n";
  174. ?>
  175. </tr>
  176. <td><td><b><?php echo WEB_network_discovery; ?></b></td>
  177. <?php
  178. if ($row_cl === 'data' and $subnet_info['discovery']) { $cl = 'up'; } else { $cl = $row_cl; }
  179. print "<td colspan=2 class=\"$cl\">";
  180. print_qa_select_ext("s_discovery", $subnet_info['discovery'], !$subnet_info['office']);
  181. print "</td>\n";
  182. ?>
  183. </tr>
  184. </table>
  185. <?php
  186. if ($msg_error) {
  187. print "<div id='msg'><b>$msg_error</b></div><br>\n";
  188. }
  189. ?>
  190. </form>
  191. <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php"); ?>