edit_group.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  4. require_once ($_SERVER["DOCUMENT_ROOT"]."/inc/idfilter.php");
  5. global $default_user_ou_id;
  6. global $default_hotspot_ou_id;
  7. if (isset($_POST['save'])) {
  8. $new['ou_name'] = $_POST['f_group_name'];
  9. $new['default_users'] = $_POST['f_default']*1;
  10. $new['default_hotspot'] = $_POST['f_default_hotspot']*1;
  11. $new['nagios_dir'] = $_POST['f_nagios'];
  12. $new['nagios_host_use'] = $_POST['f_nagios_host'];
  13. $new['nagios_ping'] = $_POST['f_nagios_ping'];
  14. $new['nagios_default_service'] = $_POST['f_nagios_service'];
  15. $new['queue_id']= $_POST['f_queue_id']*1;
  16. $new['filter_group_id']= $_POST['f_filter_group_id']*1;
  17. $new['enabled']= $_POST['f_enabled']*1;
  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");
  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. update_record($db_link, "auth_rules", "id='{$save_id}'", $new);
  45. }
  46. }
  47. header("Location: " . $_SERVER["REQUEST_URI"]);
  48. exit;
  49. }
  50. if (isset($_POST["s_create"])) {
  51. $new_rule = $_POST["s_new_rule"];
  52. if (!empty($new_rule)) {
  53. $new['type'] = $_POST["s_new_type"];
  54. $new['rule'] = $new_rule;
  55. $new['ou_id'] = $id;
  56. LOG_INFO($db_link, "Create new rule $new_rule for ou_id: $id");
  57. insert_record($db_link, "auth_rules", $new);
  58. }
  59. header("Location: " . $_SERVER["REQUEST_URI"]);
  60. exit;
  61. }
  62. unset($_POST);
  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" method="post">
  68. <table class="data">
  69. <tr align="center">
  70. <td colspan=2><b>Название</b></td>
  71. <td><b>Default</b></td>
  72. <td><b>Hotspot</b></td>
  73. </tr>
  74. <?php
  75. $ou_info = get_record_sql($db_link,'SELECT * FROM OU WHERE id='.$id);
  76. print "<tr align=center>\n";
  77. print "<td colspan=2 class=\"data\"><input type=\"text\" name='f_group_name' value='{$ou_info['ou_name']}' style=\"width:95%;\"></td>\n";
  78. if ($ou_info['default_users']) { $cl = "up"; } else { $cl="data"; }
  79. print "<td class=\"$cl\">"; print_qa_select("f_default",$ou_info['default_users']); print "</td>\n";
  80. if ($ou_info['default_hotspot']) { $cl = "up"; } else { $cl="data"; }
  81. print "<td class=\"$cl\">"; print_qa_select("f_default_hotspot",$ou_info['default_hotspot']); print "</td>\n";
  82. ?>
  83. <tr>
  84. <td><b>Nagios directory</b></td>
  85. <td><b>Host template</b></td>
  86. <td><b>Ping</b></td>
  87. <td><b>Host service</b></td>
  88. </tr>
  89. <?php
  90. print "<td class=\"data\"><input type=\"text\" name='f_nagios' value='{$ou_info['nagios_dir']}'></td>\n";
  91. print "<td class=\"data\"><input type=\"text\" name='f_nagios_host' value='{$ou_info['nagios_host_use']}'></td>\n";
  92. print "<td class=\"data\">"; print_qa_select("f_nagios_ping",$ou_info['nagios_ping']); print "</td>\n";
  93. print "<td class=\"data\"><input type=\"text\" name='f_nagios_service' value='{$ou_info['nagios_default_service']}'></td>\n";
  94. ?>
  95. </tr>
  96. <tr><td colspan=4>Правила для автоназначенных клиентов</td></tr>
  97. <tr>
  98. <td class="data">Фильтр&nbsp<?php print_group_select($db_link, 'f_filter_group_id', $ou_info['filter_group_id']); ?></td>
  99. <td class="data">Шейпер&nbsp<?php print_queue_select($db_link, 'f_queue_id', $ou_info['queue_id']); ?></td>
  100. <td class="data">Включен&nbsp<?php print_qa_select('f_enabled', $ou_info['enabled']); ?></td>
  101. <?php print "<td align=right class=\"data\"><button name='save' value='{$ou_info['id']}'>Сохранить</button></td>\n"; ?>
  102. </tr>
  103. </table>
  104. <br>
  105. <b>Правила автоназначения адресов в <?php print_url($auth_info['login'],"/admin/users/edituser.php?id=$id"); ?></b>
  106. <br>
  107. Порядок применения: hotspot => subnet => mac => hostname => default user
  108. <br><br>
  109. <table class="data">
  110. <tr align="center">
  111. <td></td>
  112. <td width=30><b>id</b></td>
  113. <td><b>Тип</b></td>
  114. <td><b>Правило</b></td>
  115. <td><input type="submit" onclick="return confirm('Удалить?')" name="s_remove" value="Удалить"></td>
  116. </tr>
  117. <?php
  118. $t_auth_rules = get_records($db_link,'auth_rules',"ou_id=$id ORDER BY id");
  119. foreach ( $t_auth_rules as $row ) {
  120. print "<tr align=center>\n";
  121. print "<td class=\"data\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
  122. print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  123. print "<td class=\"data\">"; print_qa_rule_select("s_type[]","{$row['type']}"); print "</td>\n";
  124. print "<td class=\"data\"><input type=\"text\" name='s_rule[]' value='{$row['rule']}'></td>\n";
  125. print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>Сохранить</button></td>\n";
  126. print "</tr>\n";
  127. }
  128. ?>
  129. <tr>
  130. <td colspan=6>Новое правило :<?php print_qa_rule_select("s_new_type","1"); print "<input type=\"text\" name='s_new_rule' value=''>"; ?></td>
  131. <td><input type="submit" name="s_create" value="Добавить"></td>
  132. </tr>
  133. </table>
  134. </form>
  135. <?php require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php"); ?>