editsubnet.php 7.9 KB

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