editsubnet.php 11 KB

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