index.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. defineTablePrefix($dbTablePrefix);
  21. # Declare
  22. $result = '';
  23. # Database
  24. $database = new mysqli($dbHost, $dbUser, $dbPassword, $dbName);
  25. if (mysqli_connect_errno()!=0) {
  26. echo 'Error 100: ' . mysqli_connect_errno() . ': ' . mysqli_connect_error() . '' . PHP_EOL;
  27. exit();
  28. }
  29. # Result
  30. $query = Database::prepare($database, "SELECT FROM_UNIXTIME(time), type, function, line, text FROM ?", [LYCHEE_TABLE_LOG]);
  31. $result = $database->query($query);
  32. # Output
  33. if ($result->num_rows===0) {
  34. echo('Everything looks fine, Lychee has not reported any problems!' . PHP_EOL . PHP_EOL);
  35. } else {
  36. while($row = $result->fetch_row()) {
  37. # Encode result before printing
  38. $row = array_map("htmlentities", $row);
  39. # Format: time TZ - type - function(line) - text
  40. printf ("%s %s - %s - %s (%s) \t- %s\n", $row[0], date_default_timezone_get(), $row[1], $row[2], $row[3], $row[4]);
  41. }
  42. }
  43. ?>