edit_group.php 5.4 KB

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