index.php 1.7 KB

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