index.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. ###
  3. # @name Display Log Plugin
  4. # @author Tobias Reich
  5. # @copyright 2014 by Tobias Reich
  6. # @description This file queries the database for log messages and displays them if present.
  7. ###
  8. # Location
  9. $lychee = __DIR__ . '/../../';
  10. # Load requirements
  11. require($lychee . 'php/define.php');
  12. require($lychee . 'php/autoload.php');
  13. require($lychee . 'php/modules/misc.php');
  14. # Set content
  15. header('content-type: text/plain');
  16. # Load config
  17. if (!file_exists(LYCHEE_CONFIG_FILE)) exit('Error 001: Configuration not found. Please install Lychee first.');
  18. require(LYCHEE_CONFIG_FILE);
  19. # Define the table prefix
  20. if (!isset($dbTablePrefix)) $dbTablePrefix = '';
  21. defineTablePrefix($dbTablePrefix);
  22. # Declare
  23. $result = '';
  24. # Database
  25. $database = new mysqli($dbHost, $dbUser, $dbPassword, $dbName);
  26. if (mysqli_connect_errno()!=0) {
  27. echo 'Error 100: ' . mysqli_connect_errno() . ': ' . mysqli_connect_error() . '' . PHP_EOL;
  28. exit();
  29. }
  30. # Result
  31. $query = Database::prepare($database, "SELECT FROM_UNIXTIME(time), type, function, line, text FROM ?", array(LYCHEE_TABLE_LOG));
  32. $result = $database->query($query);
  33. # Output
  34. if ($result->num_rows===0) {
  35. echo('Everything looks fine, Lychee has not reported any problems!' . PHP_EOL . PHP_EOL);
  36. } else {
  37. while($row = $result->fetch_row()) {
  38. # Encode result before printing
  39. $row = array_map("htmlentities", $row);
  40. # Format: time TZ - type - function(line) - text
  41. printf ("%s %s - %s - %s (%s) \t- %s\n", $row[0], date_default_timezone_get(), $row[1], $row[2], $row[3], $row[4]);
  42. }
  43. }
  44. ?>