index.php 1.3 KB

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