editsubnet.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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_vlan; ?></b></td>
  90. <?php print "<td colspan=2 class=\"data\"><input type=\"text\" name='s_vlan' value='".$subnet_info['vlan']."' pattern='^(409[0-6]|(40[0-8]|[1-3]\d\d|[1-9]\d|[1-9])\d|[1-9])$'></td>\n"; ?></tr>
  91. <td><td><b><?php echo WEB_network_gateway; ?></b></td>
  92. <?php
  93. $cell_disabled = '';
  94. if ($subnet_info['office'] and !$subnet_info['vpn']) {
  95. $default_range = cidrToRange($subnet_info['subnet']);
  96. if (!isset($subnet_info['dhcp_start']) or !($subnet_info['dhcp_start'] > 0)) {
  97. $subnet_info['dhcp_start'] = ip2long($default_range[3]);
  98. }
  99. if (!isset($subnet_info['dhcp_stop']) or !($subnet_info['dhcp_stop'] > 0)) {
  100. $subnet_info['dhcp_stop'] = ip2long($default_range[4]);
  101. }
  102. } else {
  103. $cell_disabled = 'readonly=true';
  104. $cl = 'down';
  105. }
  106. print "<td colspan=2 class=\"$cl\"><input type=\"text\" name='s_gateway' value='" . long2ip($subnet_info['gateway']) . "' size='15' $cell_disabled></td>\n";
  107. ?>
  108. </tr>
  109. <td><td><b><?php echo WEB_network_use_dhcp; ?></b></td>
  110. <?php
  111. if ($subnet_info['dhcp']) { $cl = 'up'; } else { $cl = 'data'; }
  112. print "<td colspan=2 class=\"$cl\">";
  113. print_qa_select("s_dhcp", $subnet_info['dhcp']);
  114. print "</td>\n";
  115. ?>
  116. </tr>
  117. <td><td><b><?php echo WEB_network_static; ?></b></td>
  118. <?php
  119. if ($subnet_info['static']) { $cl = 'up'; } else { $cl = 'data'; }
  120. print "<td colspan=2 class=\"$cl\">";
  121. print_qa_select("s_static", $subnet_info['static']);
  122. print "</td>\n";
  123. $cl = 'data';
  124. ?>
  125. </tr>
  126. <td><td><b><?php echo WEB_network_dhcp_first; ?></b></td>
  127. <?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>
  128. <td><td><b><?php echo WEB_network_dhcp_last; ?></b></td>
  129. <?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>
  130. <td><td><b><?php echo WEB_network_dhcp_leasetime; ?></b></td>
  131. <?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>
  132. <td><td><b><?php echo WEB_network_office_subnet; ?></b></td>
  133. <?php
  134. $row_cl = 'data';
  135. if (!$subnet_info['office']) { $row_cl = 'down'; }
  136. if ($subnet_info['office']) { $cl = 'up'; } else { $cl = 'data'; }
  137. print "<td colspan=2 class=\"$cl\">";
  138. print_qa_select("s_office", $subnet_info['office']);
  139. print "</td>\n";
  140. ?>
  141. </tr>
  142. <td><td><b><?php echo WEB_network_hotspot; ?></b></td>
  143. <?php
  144. if ($row_cl === 'data' and $subnet_info['hotspot']) { $cl = 'up'; } else { $cl = $row_cl; }
  145. print "<td colspan=2 class=\"$cl\">";
  146. print_qa_select_ext("s_hotspot", $subnet_info['hotspot'], !$subnet_info['office']);
  147. print "</td>\n";
  148. ?>
  149. </tr>
  150. <td><td><b><?php echo WEB_network_vpn; ?></b></td>
  151. <?php
  152. if ($row_cl === 'data' and $subnet_info['vpn']) { $cl = 'up'; } else { $cl = $row_cl; }
  153. print "<td colspan=2 class=\"$cl\">";
  154. print_qa_select_ext("s_vpn", $subnet_info['vpn'], !$subnet_info['office']);
  155. print "</td>\n";
  156. ?>
  157. </tr>
  158. <td><td><b><?php echo WEB_network_free; ?></b></td>
  159. <?php
  160. if ($subnet_info['free']) { $cl = 'up'; } else { $cl = $row_cl; }
  161. print "<td colspan=2 class=\"$cl\">";
  162. print_qa_select("s_free", $subnet_info['free']);
  163. print "</td>\n";
  164. ?>
  165. </tr>
  166. <td><td><b><?php echo WEB_network_dyndns; ?></b></td>
  167. <?php
  168. if ($row_cl === 'data' and $subnet_info['dhcp_update_hostname']) { $cl = 'up'; } else { $cl = $row_cl; }
  169. print "<td colspan=2 class=\"$cl\">";
  170. print_qa_select_ext("s_dhcp_update", $subnet_info['dhcp_update_hostname'], !$subnet_info['office']);
  171. print "</td>\n";
  172. ?>
  173. </tr>
  174. <td><td><b><?php echo WEB_network_discovery; ?></b></td>
  175. <?php
  176. if ($row_cl === 'data' and $subnet_info['discovery']) { $cl = 'up'; } else { $cl = $row_cl; }
  177. print "<td colspan=2 class=\"$cl\">";
  178. print_qa_select_ext("s_discovery", $subnet_info['discovery'], !$subnet_info['office']);
  179. print "</td>\n";
  180. ?>
  181. </tr>
  182. </table>
  183. <?php
  184. if ($msg_error) {
  185. print "<div id='msg'><b>$msg_error</b></div><br>\n";
  186. }
  187. ?>
  188. </form>
  189. <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php"); ?>