auth_export.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
  3. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
  4. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/xlsxwriter.class.php");
  5. if (!defined("CONFIG")) die("Not defined");
  6. if (isset($_POST["ExportAuth"])) {
  7. //export selected only
  8. $filename = 'all-ips.xlsx';
  9. header('Content-disposition: attachment; filename="'.XLSXWriter::sanitize_filename($filename).'"');
  10. header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
  11. header('Content-Transfer-Encoding: binary');
  12. header('Cache-Control: must-revalidate');
  13. header('Pragma: public');
  14. $header = array(
  15. 'login'=>'string',
  16. 'ip'=>'string',
  17. 'mac'=>'string',
  18. 'comment'=>'string',
  19. 'dns'=>'string',
  20. 'last found'=>'date',
  21. );
  22. $writer = new XLSXWriter();
  23. $writer->setAuthor('Eye');
  24. $writer->writeSheetHeader('Sheet1', $header );
  25. if ($_POST["a_selected"] * 1) {
  26. $auth_id = $_POST["fid"];
  27. foreach ($auth_id as $key => $val) {
  28. if ($val) {
  29. $sSQL = "SELECT User_list.login, User_auth.ip, User_auth.mac, User_auth.comment, User_auth.dns_name, User_auth.last_found FROM User_auth, User_list WHERE User_auth.user_id = User_list.id AND User_auth.id = ".$val;
  30. $record = get_record_sql($db_link,$sSQL);
  31. $writer->writeSheetRow('Sheet1', $record);
  32. }
  33. }
  34. } else {
  35. //export all
  36. $sSQL = "SELECT User_list.login, User_auth.ip, User_auth.mac, User_auth.comment, User_auth.dns_name, User_auth.last_found FROM User_auth, User_list WHERE User_auth.user_id = User_list.id AND User_auth.deleted = 0 ORDER BY User_auth.ip_int";
  37. $auth_table = mysqli_query($db_link, $sSQL);
  38. while ($record = mysqli_fetch_array($auth_table)) {
  39. $writer->writeSheetRow('Sheet1', $record);
  40. }
  41. }
  42. $writer->writeToStdOut();
  43. }