index.php 15 KB

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