index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/dynfilter.php");
  14. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/dhcpfilter.php");
  15. $sort_table = 'User_auth';
  16. if ($sort_field == 'login') { $sort_table = 'User_list'; }
  17. if ($sort_field == 'fio') { $sort_table = 'User_list'; }
  18. if ($sort_field == 'ou_name') { $sort_table = 'OU'; }
  19. $sort_url = "<a href=index.php?ou=" . $rou;
  20. if ($rou == 0) { $ou_filter = ''; } else { $ou_filter = " and User_list.ou_id=$rou "; }
  21. if (empty($rcidr)) { $cidr_filter = ''; } else {
  22. $cidr_range = cidrToRange($rcidr);
  23. if (!empty($cidr_range)) { $cidr_filter = " and User_auth.ip_int>=".ip2long($cidr_range[0])." and User_auth.ip_int<=".ip2long($cidr_range[1]); }
  24. }
  25. $enabled_filter='';
  26. if ($enabled>0) {
  27. if ($enabled===2) { $enabled_filter = ' and (User_auth.enabled=1 and User_list.enabled=1)'; }
  28. if ($enabled===1) { $enabled_filter = ' and (User_auth.enabled=0 or User_list.enabled=0)'; }
  29. }
  30. $dynamic_filter='';
  31. if ($dynamic_enabled>0) {
  32. if ($dynamic_enabled ==1) { $dynamic_filter = ' and User_auth.dynamic=1'; }
  33. if ($dynamic_enabled ==2) { $dynamic_filter = ' and User_auth.dynamic=0'; }
  34. }
  35. $dhcp_filter='';
  36. if ($dhcp_enabled>0) {
  37. if ($dhcp_enabled ==1) { $dhcp_filter = ' and User_auth.dhcp=1'; }
  38. if ($dhcp_enabled ==2) { $dhcp_filter = ' and User_auth.dhcp=0'; }
  39. }
  40. if (isset($_POST['search_str'])) { $f_search_str = trim($_POST['search_str']); }
  41. if (!isset($f_search_str) and isset($_SESSION[$page_url]['search_str'])) { $f_search_str=$_SESSION[$page_url]['search_str']; }
  42. if (!isset($f_search_str)) { $f_search_str=''; }
  43. $_SESSION[$page_url]['search_str']=$f_search_str;
  44. $f_search=replaceSpecialChars($f_search_str);
  45. $ip_list_type_filter='';
  46. if ($ip_type>0) {
  47. //suspicious - dhcp not found 3 last days
  48. 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.arp_found)>259200) and (UNIX_TIMESTAMP()-User_auth.arp_found)<259200)"; }
  49. //dhcp
  50. if ($ip_type===2) { $ip_list_type_filter = " and (User_auth.dhcp_action IN ('add', 'old', 'del'))"; }
  51. //static
  52. if ($ip_type===1) { $ip_list_type_filter = " and (User_auth.dhcp_action NOT IN ('add', 'old', 'del'))"; }
  53. }
  54. $ip_where = '';
  55. if (!empty($f_search_str)) {
  56. $f_ip = normalizeIpAddress($f_search_str);
  57. if (!empty($f_ip)) {
  58. $ip_where = " and ip_int=inet_aton('" . $f_ip . "') ";
  59. $f_search_str = $f_ip;
  60. } else {
  61. if (checkValidMac($f_search_str)) { $ip_where =" and mac='" . mac_dotted($f_search_str) ."'"; }
  62. else {
  63. $ip_where =" and (mac like '" . mac_dotted($f_search) . "%' or login like '".$f_search."%' or comments like '".$f_search."%' or dns_name like '".$f_search."%' or dhcp_hostname like '".$f_search."%')";
  64. }
  65. }
  66. }
  67. $ip_list_filter = $ou_filter.$cidr_filter.$enabled_filter.$ip_list_type_filter.$dynamic_filter.$dhcp_filter.$ip_where;
  68. print_ip_submenu($page_url);
  69. ?>
  70. <div id="cont">
  71. <br>
  72. <form name="filter" action="index.php" method="post">
  73. <input type="hidden" name="ip-filter" value="<?php print $ip_list_filter; ?>">
  74. <input type="hidden" name="ip-sort" value="<?php print $sort_table.".".$sort_field." ".$order; ?>">
  75. <table>
  76. <tr>
  77. <td>
  78. <b><?php print WEB_cell_ou; ?> - </b><?php print_ou_select($db_link, 'ou', $rou); ?>
  79. </td>
  80. <td>
  81. <b><?php print WEB_network_subnet; ?> - </b><?php print_subnet_select_office_splitted($db_link, 'cidr', $rcidr); ?>
  82. </td>
  83. <td></td>
  84. </tr>
  85. <tr>
  86. <td>
  87. <b><?php echo WEB_ips_show_by_state; ?> - </b><?php print_enabled_select('enabled', $enabled); ?>
  88. </td>
  89. <td>
  90. <b><?php echo WEB_ips_show_by_ip_type; ?> - </b><?php print_ip_type_select('ip_type', $ip_type); ?>
  91. </td>
  92. <td></td>
  93. </tr>
  94. <tr>
  95. <td>
  96. <b><?php echo WEB_cell_dhcp; ?> - </b><?php print_yn_select('dhcp_enabled', $dhcp_enabled); ?>
  97. </td>
  98. <td>
  99. <b><?php echo WEB_cell_temporary; ?> - </b><?php print_yn_select('dynamic_enabled', $dynamic_enabled); ?>
  100. </td>
  101. <td></td>
  102. </tr>
  103. <tr>
  104. <td colspan=2>
  105. <?php echo WEB_ips_search_host; ?>:&nbsp<input type="text" name="search_str" value="<?php echo $f_search_str; ?>"/>
  106. </td>
  107. <td>
  108. <?php print WEB_rows_at_page."&nbsp"; print_row_at_pages('rows',$displayed); ?>
  109. <input id="btn_filter" name="btn_filter" type="submit" value="<?php echo WEB_btn_show; ?>">
  110. </td>
  111. </tr>
  112. </table>
  113. </form>
  114. <a class="mainButton" href="#modal"><?php print WEB_btn_apply_selected; ?></a>
  115. <div class="remodal" data-remodal-options="closeOnConfirm: true" data-remodal-id="modal" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
  116. <div class="remodalBorder">
  117. <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
  118. <form id="formAuthApply">
  119. <h2 id="modal1Title"><?php print WEB_selection_title; ?></h2>
  120. <input type="hidden" name="ApplyForAll" value="MassChange">
  121. <table class="data" align=center>
  122. <tr><td><input type=checkbox class="putField" name="e_new_ou" value='1'></td><td align=left><?php print WEB_cell_ou."</td><td align=right>";print_ou_select($db_link, 'a_new_ou', 0); ?></td></tr>
  123. <tr><td><input type=checkbox class="putField" name="e_enabled" value='1'></td><td align=left><?php print WEB_cell_enabled."</td><td align=right>";print_qa_select('a_enabled', 1);?></td></tr>
  124. <tr><td><input type=checkbox class="putField" name="e_group_id" value='1'></td><td align=left><?php print WEB_cell_filter."</td><td align=right>";print_filter_group_select($db_link, 'a_group_id', 0);?></td></tr>
  125. <tr><td><input type=checkbox class="putField" name="e_queue_id" value='1'></td><td align=left><?php print WEB_cell_shaper."</td><td align=right>";print_queue_select($db_link, 'a_queue_id', 0);?></td></tr>
  126. <tr><td><input type=checkbox class="putField" name="e_dhcp" value='1'></td><td align=left><?php print "Dhcp"."</td><td align=right>"; print_qa_select('a_dhcp', 1);?></td></tr>
  127. <tr><td><input type=checkbox class="putField" name="e_dhcp_acl" value='1'></td><td align=left><?php print "Dhcp-acl"."</td><td align=right>"; print_dhcp_acl_list($db_link,"a_dhcp_acl"); ?></td></tr>
  128. <tr><td><input type=checkbox class="putField" name="e_dhcp_option_set" value='1'></td><td align=left><?php print "Dhcp-option-set"."</td><td align=right>"; print_dhcp_option_set_list($db_link,"a_dhcp_option_set"); ?></td></tr>
  129. <tr><td><input type=checkbox class="putField" name="e_traf" value='1'></td><td align=left><?php print "Save traffic"."</td><td align=right>"; print_qa_select('a_traf',1);?></td></tr>
  130. <tr><td><input type=checkbox class="putField" name="e_bind_mac" value='1'></td><td align=left><?php print WEB_user_bind_mac."</td><td align=right>";print_qa_select('a_bind_mac', 1);?></td></tr>
  131. <tr><td><input type=checkbox class="putField" name="e_bind_ip" value='1'></td><td align=left><?php print WEB_user_bind_ip."</td><td align=right>";print_qa_select('a_bind_ip', 1);?></td></tr>
  132. </table>
  133. <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
  134. </form>
  135. </div>
  136. </div>
  137. <a class="delButton" href="#modalDel"><?php print WEB_btn_delete; ?></a>
  138. <div class="remodal" data-remodal-options="closeOnConfirm: true" data-remodal-id="modalDel" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
  139. <div class="remodalBorder">
  140. <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
  141. <form id="formAuthDel">
  142. <h2 id="modal1Title"><?php print WEB_msg_delete_selected; ?></h2>
  143. <input type="hidden" name="RemoveAuth" value="MassChange">
  144. <?php print_qa_select('f_deleted', 0);?><br><br>
  145. <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
  146. </form>
  147. </div>
  148. </div>
  149. <a class="exportButton" href="#modalExport"><?php print WEB_btn_export; ?></a>
  150. <div class="remodal" data-remodal-options="closeOnConfirm: true" data-remodal-id="modalExport" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
  151. <div class="remodalBorder">
  152. <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
  153. <form id="formAuthExport">
  154. <h2 id="modal1Title"><?php print WEB_selection_title; ?></h2>
  155. <input type="hidden" name="ExportAuth" value="MassChange">
  156. <?php print WEB_msg_export_selected."&nbsp"; print_qa_select('a_selected', 1);?>
  157. <br><br>
  158. <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_run; ?>">
  159. </form>
  160. </div>
  161. </div>
  162. <form id="def" name="def">
  163. <?php
  164. $countSQL="SELECT Count(*) FROM User_auth
  165. LEFT JOIN User_list
  166. ON User_auth.user_id = User_list.id
  167. LEFT JOIN OU
  168. ON OU.id=User_list.ou_id
  169. WHERE User_auth.deleted =0 $ip_list_filter";
  170. $res = mysqli_query($db_link, $countSQL);
  171. $count_records = mysqli_fetch_array($res);
  172. $total=ceil($count_records[0]/$displayed);
  173. if ($page>$total) { $page=$total; }
  174. if ($page<1) { $page=1; }
  175. $start = ($page * $displayed) - $displayed;
  176. print_navigation($page_url,$page,$displayed,$count_records[0],$total);
  177. ?>
  178. <br>
  179. <table class="data">
  180. <tr>
  181. <td align=Center><input type="checkbox" onClick="checkAll(this.checked);"></td>
  182. <td align=Center><?php print $sort_url . "&sort=ou_name&order=$new_order>" . WEB_cell_ou . "</a>"; ?></td>
  183. <td align=Center><?php print $sort_url . "&sort=login&order=$new_order>" . WEB_cell_login . "</a>"; ?></td>
  184. <td align=Center><?php print $sort_url . "&sort=ip_int&order=$new_order>" . WEB_cell_ip . "</a>"; ?></td>
  185. <td align=Center><?php print $sort_url . "&sort=mac&order=$new_order>" . WEB_cell_mac . "</a>"; ?></td>
  186. <td align=Center><?php print WEB_cell_comment; ?></td>
  187. <td align=Center><?php print WEB_cell_dns_name; ?></td>
  188. <td align=Center><?php print WEB_cell_filter; ?></td>
  189. <td align=Center><?php print WEB_cell_shaper; ?></td>
  190. <td align=Center><?php print WEB_cell_traf; ?></td>
  191. <td align=Center><?php print WEB_cell_dhcp; ?></td>
  192. <td align=Center><?php print WEB_cell_acl; ?></td>
  193. <td align=Center><?php print $sort_url . "&sort=arp_found&order=$new_order>Last</a>"; ?></td>
  194. <td align=Center><?php print WEB_cell_connection; ?></td>
  195. </tr>
  196. <?php
  197. $sSQL = "SELECT User_auth.*, User_list.login, User_list.enabled as UEnabled, User_list.blocked as UBlocked, OU.ou_name
  198. FROM User_auth
  199. LEFT JOIN User_list
  200. ON User_auth.user_id = User_list.id
  201. LEFT JOIN OU
  202. ON OU.id=User_list.ou_id
  203. WHERE User_auth.deleted =0 $ip_list_filter
  204. ORDER BY $sort_table.$sort_field $order LIMIT $start,$displayed";
  205. $users = get_records_sql($db_link,$sSQL);
  206. foreach ($users as $user) {
  207. if ($user['dhcp_time'] == '0000-00-00 00:00:00') {
  208. $dhcp_str = '';
  209. } else {
  210. $dhcp_str = $user['dhcp_time'] . " (" . $user['dhcp_action'] . ")";
  211. }
  212. if ($user['last_found'] == '0000-00-00 00:00:00') { $user['last_found'] = ''; }
  213. if ($user['arp_found'] == '0000-00-00 00:00:00') { $user['arp_found'] = ''; }
  214. print "<tr align=center>\n";
  215. $cl = "data";
  216. if (!$user['enabled']) { $cl = "warn"; }
  217. if ($user['blocked']) { $cl = "error"; }
  218. if (!$user['UEnabled'] or $user['UBlocked']) { $cl = "off"; }
  219. print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=fid[] value=".$user['id']."></td>\n";
  220. print "<td class=\"$cl\" >".$user['ou_name']."</td>\n";
  221. if (empty($user['login'])) { $user_name = $user['user_id']; } else { $user_name = $user['login']; }
  222. print "<td class=\"$cl\" ><a href=/admin/users/edituser.php?id=".$user['user_id'].">" . $user_name . "</a></td>\n";
  223. print "<td class=\"$cl\" ><a href=/admin/users/editauth.php?id=".$user['id'].">" . $user['ip'] . "</a></td>\n";
  224. print "<td class=\"$cl\" >" . expand_mac($db_link,$user['mac']) . "</td>\n";
  225. if (isset($user['dhcp_hostname']) and strlen($user['dhcp_hostname']) > 0) {
  226. print "<td class=\"$cl\" width=200 >".$user['comments']." [" . $user['dhcp_hostname'] . "]</td>\n";
  227. } else {
  228. print "<td class=\"$cl\" width=200 >".$user['comments']."</td>\n";
  229. }
  230. print "<td class=\"$cl\" >".$user['dns_name']."</td>\n";
  231. print "<td class=\"$cl\" >" . get_group($db_link, $user['filter_group_id']) . "</td>\n";
  232. print "<td class=\"$cl\" >" . get_queue($db_link, $user['queue_id']) . "</td>\n";
  233. print_td_qa($user['save_traf'],FALSE,$cl);
  234. print_td_qa($user['dhcp'],FALSE,$cl);
  235. print "<td class=\"$cl\" >".$user['dhcp_acl']."</td>\n";
  236. if (empty($user['arp_found'])) {
  237. print "<td class=\"$cl\" >".$user['last_found']."</td>\n";
  238. } else {
  239. print "<td class=\"$cl\" >".$user['arp_found']."</td>\n";
  240. }
  241. print "<td class=\"$cl\" >" . get_connection($db_link, $user['id']) . "</td>\n";
  242. print "</tr>\n";
  243. }
  244. print "</table>\n";
  245. print_navigation($page_url,$page,$displayed,$count_records[0],$total);
  246. ?>
  247. <br>
  248. <table class="data">
  249. <tr><td><?php echo WEB_color_description; ?></td></tr>
  250. <tr>
  251. <td class="data"><?php echo WEB_color_auth_enabled; ?></td>
  252. <td class="warn"><?php echo WEB_color_auth_disabled; ?></td>
  253. <td class="error"><?php echo WEB_color_user_blocked; ?></td>
  254. <td class="off"><?php echo WEB_color_user_disabled; ?></td>
  255. </table>
  256. <script src="/js/remodal/remodal.min.js"></script>
  257. <script src="/js/remodal-auth.js"></script>
  258. <script>
  259. document.getElementById('ou').addEventListener('change', function(event) {
  260. const buttonApply = document.getElementById('btn_filter');
  261. buttonApply.click();
  262. });
  263. document.getElementById('cidr').addEventListener('change', function(event) {
  264. const buttonApply = document.getElementById('btn_filter');
  265. buttonApply.click();
  266. });
  267. document.getElementById('enabled').addEventListener('change', function(event) {
  268. const buttonApply = document.getElementById('btn_filter');
  269. buttonApply.click();
  270. });
  271. document.getElementById('ip_type').addEventListener('change', function(event) {
  272. const buttonApply = document.getElementById('btn_filter');
  273. buttonApply.click();
  274. });
  275. document.getElementById('rows').addEventListener('change', function(event) {
  276. const buttonApply = document.getElementById('btn_filter');
  277. buttonApply.click();
  278. });
  279. document.getElementById('dhcp_enabled').addEventListener('change', function(event) {
  280. const buttonApply = document.getElementById('btn_filter');
  281. buttonApply.click();
  282. });
  283. document.getElementById('dynamic_enabled').addEventListener('change', function(event) {
  284. const buttonApply = document.getElementById('btn_filter');
  285. buttonApply.click();
  286. });
  287. </script>
  288. <?php
  289. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.simple.php");
  290. ?>