index.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. ###
  3. # @name Display Log Plugin
  4. # @author Tobias Reich
  5. # @copyright 2015 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. # Load settings
  31. $settings = new Settings($database);
  32. $settings = $settings->get();
  33. # Ensure that user is logged in
  34. session_start();
  35. if ((isset($_SESSION['login'])&&$_SESSION['login']===true)&&
  36. (isset($_SESSION['identifier'])&&$_SESSION['identifier']===$settings['identifier'])) {
  37. # Result
  38. $query = Database::prepare($database, "SELECT FROM_UNIXTIME(time), type, function, line, text FROM ?", array(LYCHEE_TABLE_LOG));
  39. $result = $database->query($query);
  40. # Output
  41. if ($result->num_rows===0) {
  42. echo('Everything looks fine, Lychee has not reported any problems!');
  43. } else {
  44. while($row = $result->fetch_row()) {
  45. # Encode result before printing
  46. $row = array_map('htmlentities', $row);
  47. # Format: time TZ - type - function(line) - text
  48. printf ("%s - %s - %s (%s) \t- %s\n", $row[0], $row[1], $row[2], $row[3], $row[4]);
  49. }
  50. }
  51. } else {
  52. # Don't go further if the user is not logged in
  53. echo('You have to be logged in to see the log.');
  54. exit();
  55. }
  56. ?>