index.php 1.8 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. # Start the session
  11. session_start();
  12. # Load requirements
  13. require($lychee . 'php/define.php');
  14. require($lychee . 'php/autoload.php');
  15. require($lychee . 'php/modules/misc.php');
  16. # Set content
  17. header('content-type: text/plain');
  18. # Load config
  19. if (!file_exists(LYCHEE_CONFIG_FILE)) exit('Error 001: Configuration not found. Please install Lychee first.');
  20. require(LYCHEE_CONFIG_FILE);
  21. # Define the table prefix
  22. defineTablePrefix(@$dbTablePrefix);
  23. # Declare
  24. $result = '';
  25. # Database
  26. $database = new mysqli($dbHost, $dbUser, $dbPassword, $dbName);
  27. if (mysqli_connect_errno()!=0) {
  28. echo 'Error 100: ' . mysqli_connect_errno() . ': ' . mysqli_connect_error() . '' . PHP_EOL;
  29. exit();
  30. }
  31. # Load settings
  32. $settings = new Settings($database);
  33. $settings = $settings->get();
  34. # Ensure that user is logged in
  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. ?>