index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. $default_displayed=500;
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  5. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  6. $default_sort='ip_int';
  7. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/oufilter.php");
  8. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/cidrfilter.php");
  9. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/sortfilter.php");
  10. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/gatefilter.php");
  11. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/enabledfilter.php");
  12. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/iptypefilter.php");
  13. $sort_table = 'User_auth';
  14. if ($sort_field == 'login') { $sort_table = 'User_list'; }
  15. if ($sort_field == 'fio') { $sort_table = 'User_list'; }
  16. if ($sort_field == 'ou_name') { $sort_table = 'OU'; }
  17. $sort_url = "<a href=index.php?ou=" . $rou;
  18. if ($rou == 0) { $ou_filter = ''; } else { $ou_filter = " and User_list.ou_id=$rou "; }
  19. if (empty($rcidr)) { $cidr_filter = ''; } else {
  20. $cidr_range = cidrToRange($rcidr);
  21. if (!empty($cidr_range)) { $cidr_filter = " and User_auth.ip_int>=".ip2long($cidr_range[0])." and User_auth.ip_int<=".ip2long($cidr_range[1]); }
  22. }
  23. $enabled_filter='';
  24. if ($enabled>0) {
  25. if ($enabled===2) { $enabled_filter = ' and (User_auth.enabled=1 and User_list.enabled=1)'; }
  26. if ($enabled===1) { $enabled_filter = ' and (User_auth.enabled=0 or User_list.enabled=0)'; }
  27. }
  28. if (isset($_POST['ip'])) { $f_ip = $_POST['ip']; }
  29. if (!isset($f_ip) and isset($_SESSION[$page_url]['ip'])) { $f_ip=$_SESSION[$page_url]['ip']; }
  30. if (!isset($f_ip)) { $f_ip=''; }
  31. $_SESSION[$page_url]['ip']=$f_ip;
  32. $ip_list_type_filter='';
  33. if ($ip_type>0) {
  34. //suspicious
  35. if ($ip_type===3) { $ip_list_type_filter = " and (User_auth.dhcp_action IN ('add', 'old', 'del') and (ABS(User_auth.dhcp_time - User_auth.last_found)>259200) and (UNIX_TIMESTAMP()-User_auth.last_found)<259200)"; }
  36. //dhcp
  37. if ($ip_type===2) { $ip_list_type_filter = " and (User_auth.dhcp_action IN ('add', 'old', 'del'))"; }
  38. //static
  39. if ($ip_type===1) { $ip_list_type_filter = " and (User_auth.dhcp_action NOT IN ('add', 'old', 'del'))"; }
  40. }
  41. $ip_where = '';
  42. if (!empty($f_ip)) {
  43. if (checkValidIp($f_ip)) { $ip_where = " and ip_int=inet_aton('" . $f_ip . "') "; }
  44. if (empty($ip_where)) { $ip_where =" and (mac like '" . mac_dotted($f_ip) . "%' or comments like '".$f_ip."%' or dns_name like '".$f_ip."%' or dhcp_hostname like '".$f_ip."%')"; }
  45. $ip_list_filter = $ip_where;
  46. } else {
  47. $ip_list_filter = $ou_filter.$cidr_filter.$enabled_filter.$ip_list_type_filter;
  48. }
  49. print_ip_submenu($page_url);
  50. ?>
  51. <div id="cont">
  52. <form name="filter" action="index.php" method="post">
  53. <input type="hidden" name="ip-filter" value="<?php print $ip_list_filter; ?>">
  54. <input type="hidden" name="ip-sort" value="<?php print $sort_table.".".$sort_field." ".$order; ?>">
  55. <table class="data">
  56. <tr>
  57. <td>
  58. <b><?php print WEB_cell_ou; ?> - </b><?php print_ou_select($db_link, 'ou', $rou); ?>
  59. <b><?php print WEB_network_subnet; ?> - </b><?php print_subnet_select_office_splitted($db_link, 'cidr', $rcidr); ?>
  60. <b><?php echo WEB_ips_show_by_state; ?> - </b><?php print_enabled_select('enabled', $enabled); ?>
  61. <b><?php echo WEB_ips_show_by_ip_type; ?> - </b><?php print_ip_type_select('ip_type', $ip_type); ?>
  62. <?php echo WEB_ips_search_host; ?>:&nbsp<input type="text" name="ip" value="<?php echo $f_ip; ?>"/>
  63. <?php print WEB_rows_at_page."&nbsp"; print_row_at_pages('rows',$displayed); ?>
  64. <input id="btn_filter" name="btn_filter" type="submit" value="<?php echo WEB_btn_show; ?>">
  65. </td>
  66. </tr>
  67. </table>
  68. </form>
  69. <a class="mainButton" href="#modal"><?php print WEB_btn_apply_selected; ?></a>
  70. <div class="remodal" data-remodal-options="closeOnConfirm: true" data-remodal-id="modal" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
  71. <div class="remodalBorder">
  72. <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
  73. <form id="formAuthApply">
  74. <h2 id="modal1Title"><?php print WEB_selection_title; ?></h2>
  75. <input type="hidden" name="ApplyForAll" value="MassChange">
  76. <table class="data" align=center>
  77. <tr><td><input type=checkbox class="putField" name="e_enabled" value='1'></td><td><?php print WEB_cell_enabled."&nbsp"; print_qa_select('a_enabled', 1);?></td></tr>
  78. <tr><td><input type=checkbox class="putField" name="e_group_id" value='1'></td><td><?php print WEB_cell_filter."&nbsp";print_group_select($db_link, 'a_group_id', 0);?></td></tr>
  79. <tr><td><input type=checkbox class="putField" name="e_queue_id" value='1'></td><td><?php print WEB_cell_shaper."&nbsp";print_queue_select($db_link, 'a_queue_id', 0);?></td></tr>
  80. <tr><td><input type=checkbox class="putField" name="e_dhcp" value='1'></td><td><?php print "Dhcp&nbsp"; print_qa_select('a_dhcp', 1);?></td></tr>
  81. <tr><td><input type=checkbox class="putField" name="e_dhcp_acl" value='1'></td><td><?php print "Dhcp-acl&nbsp";print_dhcp_acl_select('a_dhcp_acl','');?></td></tr>
  82. <tr><td><input type=checkbox class="putField" name="e_traf" value='1'></td><td><?php print "Save traffic&nbsp"; print_qa_select('a_traf',1);?></td></tr>
  83. <tr><td><input type=checkbox class="putField" name="e_bind_mac" value='1'></td><td><?php print WEB_user_bind_mac."&nbsp";print_qa_select('a_bind_mac', 1);?></td></tr>
  84. <tr><td><input type=checkbox class="putField" name="e_bind_ip" value='1'></td><td><?php print WEB_user_bind_ip."&nbsp";print_qa_select('a_bind_ip', 1);?></td></tr>
  85. </table>
  86. <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
  87. </form>
  88. </div>
  89. </div>
  90. <a class="delButton" href="#modalDel"><?php print WEB_btn_delete; ?></a>
  91. <div class="remodal" data-remodal-options="closeOnConfirm: true" data-remodal-id="modalDel" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
  92. <div class="remodalBorder">
  93. <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
  94. <form id="formAuthDel">
  95. <h2 id="modal1Title"><?php print WEB_msg_delete_selected; ?></h2>
  96. <input type="hidden" name="RemoveAuth" value="MassChange">
  97. <?php print_qa_select('f_deleted', 0);?><br><br>
  98. <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
  99. </form>
  100. </div>
  101. </div>
  102. <a class="exportButton" href="#modalExport"><?php print WEB_btn_export; ?></a>
  103. <div class="remodal" data-remodal-options="closeOnConfirm: true" data-remodal-id="modalExport" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
  104. <div class="remodalBorder">
  105. <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
  106. <form id="formAuthExport">
  107. <h2 id="modal1Title"><?php print WEB_selection_title; ?></h2>
  108. <input type="hidden" name="ExportAuth" value="MassChange">
  109. <?php print WEB_msg_export_selected."&nbsp"; print_qa_select('a_selected', 1);?>
  110. <br><br>
  111. <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_run; ?>">
  112. </form>
  113. </div>
  114. </div>
  115. <form id="def" name="def">
  116. <?php
  117. $countSQL="SELECT Count(*) FROM User_auth
  118. LEFT JOIN User_list
  119. ON User_auth.user_id = User_list.id
  120. LEFT JOIN OU
  121. ON OU.id=User_list.ou_id
  122. WHERE User_auth.deleted =0 $ip_list_filter";
  123. $res = mysqli_query($db_link, $countSQL);
  124. $count_records = mysqli_fetch_array($res);
  125. $total=ceil($count_records[0]/$displayed);
  126. if ($page>$total) { $page=$total; }
  127. if ($page<1) { $page=1; }
  128. $start = ($page * $displayed) - $displayed;
  129. print_navigation($page_url,$page,$displayed,$count_records[0],$total);
  130. ?>
  131. <br>
  132. <table class="data">
  133. <tr>
  134. <td align=Center><input type="checkbox" onClick="checkAll(this.checked);"></td>
  135. <td align=Center><?php print $sort_url . "&sort=ou_name&order=$new_order>" . WEB_cell_ou . "</a>"; ?></td>
  136. <td align=Center><?php print $sort_url . "&sort=login&order=$new_order>" . WEB_cell_login . "</a>"; ?></td>
  137. <td align=Center><?php print $sort_url . "&sort=ip_int&order=$new_order>" . WEB_cell_ip . "</a>"; ?></td>
  138. <td align=Center><?php print $sort_url . "&sort=mac&order=$new_order>" . WEB_cell_mac . "</a>"; ?></td>
  139. <td align=Center><?php print WEB_cell_comment; ?></td>
  140. <td align=Center><?php print WEB_cell_dns_name; ?></td>
  141. <td align=Center><?php print WEB_cell_filter; ?></td>
  142. <td align=Center><?php print WEB_cell_shaper; ?></td>
  143. <td align=Center><?php print WEB_cell_traf; ?></td>
  144. <td align=Center><?php print WEB_cell_dhcp; ?></td>
  145. <td align=Center><?php print WEB_cell_acl; ?></td>
  146. <td align=Center><?php print $sort_url . "&sort=last_found&order=$new_order>Last</a>"; ?></td>
  147. <td align=Center><?php print WEB_cell_connection; ?></td>
  148. </tr>
  149. <?php
  150. $sSQL = "SELECT User_auth.*, User_list.login, User_list.enabled as UEnabled, User_list.blocked as UBlocked, OU.ou_name
  151. FROM User_auth
  152. LEFT JOIN User_list
  153. ON User_auth.user_id = User_list.id
  154. LEFT JOIN OU
  155. ON OU.id=User_list.ou_id
  156. WHERE User_auth.deleted =0 $ip_list_filter
  157. ORDER BY $sort_table.$sort_field $order LIMIT $start,$displayed";
  158. $users = get_records_sql($db_link,$sSQL);
  159. foreach ($users as $user) {
  160. if ($user['dhcp_time'] == '0000-00-00 00:00:00') {
  161. $dhcp_str = '';
  162. } else {
  163. $dhcp_str = $user['dhcp_time'] . " (" . $user['dhcp_action'] . ")";
  164. }
  165. if ($user['last_found'] == '0000-00-00 00:00:00') { $user['last_found'] = ''; }
  166. print "<tr align=center>\n";
  167. $cl = "data";
  168. if (!$user['enabled']) { $cl = "warn"; }
  169. if ($user['blocked']) { $cl = "error"; }
  170. if (!$user['UEnabled'] or $user['UBlocked']) { $cl = "off"; }
  171. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=fid[] value=".$user['id']."></td>\n";
  172. print "<td class=\"$cl\" >".$user['ou_name']."</td>\n";
  173. print "<td class=\"$cl\" ><a href=/admin/users/edituser.php?id=".$user['user_id'].">" . $user['login'] . "</a></td>\n";
  174. print "<td class=\"$cl\" ><a href=/admin/users/editauth.php?id=".$user['id'].">" . $user['ip'] . "</a></td>\n";
  175. print "<td class=\"$cl\" >" . expand_mac($db_link,$user['mac']) . "</td>\n";
  176. if (isset($user['dhcp_hostname']) and strlen($user['dhcp_hostname']) > 0) {
  177. print "<td class=\"$cl\" width=200 >".$user['comments']." [" . $user['dhcp_hostname'] . "]</td>\n";
  178. } else {
  179. print "<td class=\"$cl\" width=200 >".$user['comments']."</td>\n";
  180. }
  181. print "<td class=\"$cl\" >".$user['dns_name']."</td>\n";
  182. print "<td class=\"$cl\" >" . get_group($db_link, $user['filter_group_id']) . "</td>\n";
  183. print "<td class=\"$cl\" >" . get_queue($db_link, $user['queue_id']) . "</td>\n";
  184. print "<td class=\"$cl\" >" . get_qa($user['save_traf']) . "</td>\n";
  185. print "<td class=\"$cl\" >" . get_qa($user['dhcp']) . "</td>\n";
  186. print "<td class=\"$cl\" >".$user['dhcp_acl']."</td>\n";
  187. print "<td class=\"$cl\" >".$user['last_found']."</td>\n";
  188. print "<td class=\"$cl\" >" . get_connection($db_link, $user['id']) . "</td>\n";
  189. print "</tr>\n";
  190. }
  191. print "</table>\n";
  192. print_navigation($page_url,$page,$displayed,$count_records[0],$total);
  193. ?>
  194. <br>
  195. <table class="data">
  196. <tr><td><?php echo WEB_color_description; ?></td></tr>
  197. <tr>
  198. <td class="data"><?php echo WEB_color_auth_enabled; ?></td>
  199. <td class="warn"><?php echo WEB_color_auth_disabled; ?></td>
  200. <td class="error"><?php echo WEB_color_user_blocked; ?></td>
  201. <td class="off"><?php echo WEB_color_user_disabled; ?></td>
  202. </table>
  203. <script src="/js/remodal/remodal.min.js"></script>
  204. <script src="/js/remodal-auth.js"></script>
  205. <?php
  206. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  207. ?>