index.php 16 KB

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