editsubnet.php 7.9 KB

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