edit_group.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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['save'])) {
  6. $new['ou_name'] = $_POST['f_group_name'];
  7. $new['default_users'] = $_POST['f_default']*1;
  8. $new['default_hotspot'] = $_POST['f_default_hotspot']*1;
  9. $new['nagios_dir'] = $_POST['f_nagios'];
  10. $new['nagios_host_use'] = $_POST['f_nagios_host'];
  11. $new['nagios_ping'] = $_POST['f_nagios_ping'];
  12. $new['nagios_default_service'] = $_POST['f_nagios_service'];
  13. $new['queue_id']= $_POST['f_queue_id']*1;
  14. $new['filter_group_id']= $_POST['f_filter_group_id']*1;
  15. $new['enabled']= $_POST['f_enabled']*1;
  16. $new['dynamic']= $_POST['f_dynamic']*1;
  17. if ($new['dynamic']) { $new['life_duration']= $_POST['f_life_duration']*1; } else { $new['life_duration']=0; }
  18. if ($new['default_users'] == TRUE) { run_sql($db_link,"UPDATE OU set default_users=0 WHERE id!='{$id}'"); }
  19. if ($new['default_hotspot'] == TRUE) { run_sql($db_link,"UPDATE OU set default_hotspot=0 WHERE id!='{$id}'"); }
  20. update_record($db_link, "OU", "id='{$id}'", $new);
  21. header("Location: " . $_SERVER["REQUEST_URI"]);
  22. exit;
  23. }
  24. if (isset($_POST["s_remove"])) {
  25. $s_id = $_POST["s_id"];
  26. foreach ($s_id as $key => $val) {
  27. if (isset($val)) {
  28. LOG_INFO($db_link, "Remove rule id: $val ".dump_record($db_link,'auth_rules','id='.$val));
  29. delete_record($db_link, "auth_rules", "id=" . $val);
  30. }
  31. }
  32. header("Location: " . $_SERVER["REQUEST_URI"]);
  33. exit;
  34. }
  35. if (isset($_POST['s_save'])) {
  36. $len = is_array($_POST['s_save']) ? count($_POST['s_save']) : 0;
  37. for ($i = 0; $i < $len; $i ++) {
  38. $save_id = intval($_POST['s_save'][$i]);
  39. $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
  40. for ($j = 0; $j < $len_all; $j ++) {
  41. if (intval($_POST['n_id'][$j]) != $save_id) { continue; }
  42. $new['type'] = $_POST['s_type'][$j];
  43. $new['rule'] = trim($_POST['s_rule'][$j]);
  44. $new['comment'] = trim($_POST['s_comment'][$j]);
  45. update_record($db_link, "auth_rules", "id='{$save_id}'", $new);
  46. }
  47. }
  48. header("Location: " . $_SERVER["REQUEST_URI"]);
  49. exit;
  50. }
  51. if (isset($_POST["s_create"])) {
  52. $new_rule = $_POST["s_new_rule"];
  53. if (!empty($new_rule)) {
  54. $new['type'] = $_POST["s_new_type"];
  55. $new['rule'] = $new_rule;
  56. $new['ou_id'] = $id;
  57. LOG_INFO($db_link, "Create new rule $new_rule for ou_id: $id");
  58. insert_record($db_link, "auth_rules", $new);
  59. }
  60. header("Location: " . $_SERVER["REQUEST_URI"]);
  61. exit;
  62. }
  63. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  64. fix_auth_rules($db_link);
  65. ?>
  66. <div id="cont">
  67. <form name="def" action="edit_group.php?id=<?php echo $id; ?>" method="post">
  68. <input type="hidden" name="id" value=<?php echo $id; ?>>
  69. <table class="data">
  70. <tr align="center">
  71. <td colspan=2><b><?php echo WEB_cell_name; ?></b></td>
  72. <td><b>Default</b></td>
  73. <td width=100><b>Hotspot</b></td>
  74. <td><b><?php print WEB_cell_dynamic; ?></b></td>
  75. </tr>
  76. <?php
  77. $ou_info = get_record_sql($db_link,'SELECT * FROM OU WHERE id='.$id);
  78. if ($ou_info['life_duration']<1) { $ou_info['life_duration']=1; }
  79. print "<tr align=center>\n";
  80. print "<td colspan=2 class=\"data\"><input type=\"text\" name='f_group_name' value='{$ou_info['ou_name']}' style=\"width:95%;\"></td>\n";
  81. if ($ou_info['default_users']) { $cl = "up"; } else { $cl="data"; }
  82. print "<td class=\"$cl\">"; print_qa_select("f_default",$ou_info['default_users']); print "</td>\n";
  83. if ($ou_info['default_hotspot']) { $cl = "up"; } else { $cl="data"; }
  84. print "<td class=\"$cl\">"; print_qa_select("f_default_hotspot",$ou_info['default_hotspot']); print "</td>\n";
  85. print "<td class=\"data\">"; print_qa_select("f_dynamic",$ou_info['dynamic']); print "</td>\n";
  86. ?>
  87. <tr>
  88. <td><b>Nagios directory</b></td>
  89. <td><b>Host template</b></td>
  90. <td><b>Ping</b></td>
  91. <td><b>Host service</b></td>
  92. <td></td>
  93. </tr>
  94. <?php
  95. print "<td class=\"data\"><input type=\"text\" name='f_nagios' value='{$ou_info['nagios_dir']}'></td>\n";
  96. print "<td class=\"data\"><input type=\"text\" name='f_nagios_host' value='{$ou_info['nagios_host_use']}'></td>\n";
  97. print "<td class=\"data\">"; print_qa_select("f_nagios_ping",$ou_info['nagios_ping']); print "</td>\n";
  98. print "<td class=\"data\"><input type=\"text\" name='f_nagios_service' value='{$ou_info['nagios_default_service']}'></td>\n";
  99. print "<td class=\"data\"></td>\n";
  100. ?>
  101. </tr>
  102. <tr><td colspan=4><?php echo WEB_ou_autoclient_rules; ?></td></tr>
  103. <tr>
  104. <td class="data"><?php print WEB_cell_enabled."&nbsp"; print_qa_select('f_enabled', $ou_info['enabled']); ?></td>
  105. <td class="data"><?php print WEB_cell_filter."&nbsp"; print_group_select($db_link, 'f_filter_group_id', $ou_info['filter_group_id']); ?></td>
  106. <td class="data"><?php print WEB_cell_shaper."&nbsp"; print_queue_select($db_link, 'f_queue_id', $ou_info['queue_id']); ?></td>
  107. <td class="data" align=right><?php print WEB_cell_life_hours."&nbsp"; print "<input type=\"number\" min=1 name='f_life_duration' value='{$ou_info['life_duration']}'";
  108. if (!$ou_info['dynamic']) { print "disabled"; }; print " style=\"width:35%;\" ></td>\n"; ?>
  109. <?php print "<td align=right class=\"data\"><button name='save' value='{$ou_info['id']}'>".WEB_btn_save."</button></td>\n"; ?>
  110. </tr>
  111. </table>
  112. <br>
  113. <b><?php echo WEB_ou_rules_for_autoassigning."&nbsp"; print $ou_info['ou_name']; ?></b>
  114. <br>
  115. <?php echo WEB_ou_rules_order; ?>: hotspot => subnet => mac => hostname => default user
  116. <br><br>
  117. <table class="data">
  118. <tr align="center">
  119. <td></td>
  120. <td width=30><b>id</b></td>
  121. <td><b><?php echo WEB_cell_type; ?></b></td>
  122. <td><b><?php echo WEB_ou_rule; ?></b></td>
  123. <td><b><?php echo WEB_cell_comment; ?></b></td>
  124. <td><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="s_remove" value="<?php echo WEB_btn_delete; ?>"></td>
  125. </tr>
  126. <?php
  127. $t_auth_rules = get_records($db_link,'auth_rules',"ou_id=$id ORDER BY id");
  128. foreach ( $t_auth_rules as $row ) {
  129. print "<tr align=center>\n";
  130. print "<td class=\"data\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
  131. print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  132. print "<td class=\"data\">"; print_qa_rule_select("s_type[]","{$row['type']}"); print "</td>\n";
  133. print "<td class=\"data\"><input type=\"text\" name='s_rule[]' value='{$row['rule']}'></td>\n";
  134. print "<td class=\"data\"><input type=\"text\" name='s_comment[]' value='{$row['comment']}'></td>\n";
  135. print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>".WEB_btn_save."</button></td>\n";
  136. print "</tr>\n";
  137. }
  138. ?>
  139. </table>
  140. <div>
  141. <?php print WEB_ou_new_rule."&nbsp"; print_qa_rule_select("s_new_type","1");
  142. print "<input type=\"text\" name='s_new_rule' value=''>"; ?>
  143. <input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>">
  144. </div>
  145. </form>
  146. <?php require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php"); ?>