1
0

edit_group.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. if ($new['default_users'] == TRUE) { run_sql($db_link,"UPDATE OU set default_users=0 WHERE id!='{$id}'"); }
  17. if ($new['default_hotspot'] == TRUE) { run_sql($db_link,"UPDATE OU set default_hotspot=0 WHERE id!='{$id}'"); }
  18. update_record($db_link, "OU", "id='{$id}'", $new);
  19. header("Location: " . $_SERVER["REQUEST_URI"]);
  20. exit;
  21. }
  22. if (isset($_POST["s_remove"])) {
  23. $s_id = $_POST["s_id"];
  24. foreach ($s_id as $key => $val) {
  25. if (isset($val)) {
  26. LOG_INFO($db_link, "Remove rule id: $val");
  27. delete_record($db_link, "auth_rules", "id=" . $val);
  28. }
  29. }
  30. header("Location: " . $_SERVER["REQUEST_URI"]);
  31. exit;
  32. }
  33. if (isset($_POST['s_save'])) {
  34. $len = is_array($_POST['s_save']) ? count($_POST['s_save']) : 0;
  35. for ($i = 0; $i < $len; $i ++) {
  36. $save_id = intval($_POST['s_save'][$i]);
  37. $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
  38. for ($j = 0; $j < $len_all; $j ++) {
  39. if (intval($_POST['n_id'][$j]) != $save_id) { continue; }
  40. $new['type'] = $_POST['s_type'][$j];
  41. $new['rule'] = trim($_POST['s_rule'][$j]);
  42. update_record($db_link, "auth_rules", "id='{$save_id}'", $new);
  43. }
  44. }
  45. header("Location: " . $_SERVER["REQUEST_URI"]);
  46. exit;
  47. }
  48. if (isset($_POST["s_create"])) {
  49. $new_rule = $_POST["s_new_rule"];
  50. if (!empty($new_rule)) {
  51. $new['type'] = $_POST["s_new_type"];
  52. $new['rule'] = $new_rule;
  53. $new['ou_id'] = $id;
  54. LOG_INFO($db_link, "Create new rule $new_rule for ou_id: $id");
  55. insert_record($db_link, "auth_rules", $new);
  56. }
  57. header("Location: " . $_SERVER["REQUEST_URI"]);
  58. exit;
  59. }
  60. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  61. fix_auth_rules($db_link);
  62. ?>
  63. <div id="cont">
  64. <form name="def" action="edit_group.php?id=<?php echo $id; ?>" method="post">
  65. <input type="hidden" name="id" value=<?php echo $id; ?>>
  66. <table class="data">
  67. <tr align="center">
  68. <td colspan=2><b>Название</b></td>
  69. <td><b>Default</b></td>
  70. <td><b>Hotspot</b></td>
  71. </tr>
  72. <?php
  73. $ou_info = get_record_sql($db_link,'SELECT * FROM OU WHERE id='.$id);
  74. print "<tr align=center>\n";
  75. print "<td colspan=2 class=\"data\"><input type=\"text\" name='f_group_name' value='{$ou_info['ou_name']}' style=\"width:95%;\"></td>\n";
  76. if ($ou_info['default_users']) { $cl = "up"; } else { $cl="data"; }
  77. print "<td class=\"$cl\">"; print_qa_select("f_default",$ou_info['default_users']); print "</td>\n";
  78. if ($ou_info['default_hotspot']) { $cl = "up"; } else { $cl="data"; }
  79. print "<td class=\"$cl\">"; print_qa_select("f_default_hotspot",$ou_info['default_hotspot']); print "</td>\n";
  80. ?>
  81. <tr>
  82. <td><b>Nagios directory</b></td>
  83. <td><b>Host template</b></td>
  84. <td><b>Ping</b></td>
  85. <td><b>Host service</b></td>
  86. </tr>
  87. <?php
  88. print "<td class=\"data\"><input type=\"text\" name='f_nagios' value='{$ou_info['nagios_dir']}'></td>\n";
  89. print "<td class=\"data\"><input type=\"text\" name='f_nagios_host' value='{$ou_info['nagios_host_use']}'></td>\n";
  90. print "<td class=\"data\">"; print_qa_select("f_nagios_ping",$ou_info['nagios_ping']); print "</td>\n";
  91. print "<td class=\"data\"><input type=\"text\" name='f_nagios_service' value='{$ou_info['nagios_default_service']}'></td>\n";
  92. ?>
  93. </tr>
  94. <tr><td colspan=4>Правила для автоназначенных клиентов</td></tr>
  95. <tr>
  96. <td class="data">Фильтр&nbsp<?php print_group_select($db_link, 'f_filter_group_id', $ou_info['filter_group_id']); ?></td>
  97. <td class="data">Шейпер&nbsp<?php print_queue_select($db_link, 'f_queue_id', $ou_info['queue_id']); ?></td>
  98. <td class="data">Включен&nbsp<?php print_qa_select('f_enabled', $ou_info['enabled']); ?></td>
  99. <?php print "<td align=right class=\"data\"><button name='save' value='{$ou_info['id']}'>Сохранить</button></td>\n"; ?>
  100. </tr>
  101. </table>
  102. <br>
  103. <b>Правила автоназначения адресов в <?php print $ou_info['ou_name']; ?></b>
  104. <br>
  105. Порядок применения: hotspot => subnet => mac => hostname => default user
  106. <br><br>
  107. <table class="data">
  108. <tr align="center">
  109. <td></td>
  110. <td width=30><b>id</b></td>
  111. <td><b>Тип</b></td>
  112. <td><b>Правило</b></td>
  113. <td><input type="submit" onclick="return confirm('Удалить?')" name="s_remove" value="Удалить"></td>
  114. </tr>
  115. <?php
  116. $t_auth_rules = get_records($db_link,'auth_rules',"ou_id=$id ORDER BY id");
  117. foreach ( $t_auth_rules as $row ) {
  118. print "<tr align=center>\n";
  119. print "<td class=\"data\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
  120. print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  121. print "<td class=\"data\">"; print_qa_rule_select("s_type[]","{$row['type']}"); print "</td>\n";
  122. print "<td class=\"data\"><input type=\"text\" name='s_rule[]' value='{$row['rule']}'></td>\n";
  123. print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>Сохранить</button></td>\n";
  124. print "</tr>\n";
  125. }
  126. ?>
  127. <tr>
  128. <td colspan=6>Новое правило :<?php print_qa_rule_select("s_new_type","1"); print "<input type=\"text\" name='s_new_rule' value=''>"; ?></td>
  129. <td><input type="submit" name="s_create" value="Добавить"></td>
  130. </tr>
  131. </table>
  132. </form>
  133. <?php require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php"); ?>