index.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @author Tobias Reich
  4. * @copyright 2015 by Tobias Reich
  5. * @description This file queries the database for log messages and displays them if present.
  6. */
  7. namespace Log;
  8. use Mysqli;
  9. use Lychee\Modules\Database;
  10. use Lychee\Modules\Settings;
  11. $lychee = __DIR__ . '/../../';
  12. require($lychee . 'php/define.php');
  13. require($lychee . 'php/autoload.php');
  14. // Start the session
  15. session_start();
  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. // Ensure that user is logged in
  22. if ((isset($_SESSION['login'])&&$_SESSION['login']===true)&&
  23. (isset($_SESSION['identifier'])&&$_SESSION['identifier']===Settings::get()['identifier'])) {
  24. // Result
  25. $query = Database::prepare(Database::get(), "SELECT FROM_UNIXTIME(time), type, function, line, text FROM ?", array(LYCHEE_TABLE_LOG));
  26. $result = Database::get()->query($query);
  27. // Output
  28. if ($result->num_rows===0) {
  29. echo('Everything looks fine, Lychee has not reported any problems!');
  30. } else {
  31. while($row = $result->fetch_row()) {
  32. // Encode result before printing
  33. $row = array_map('htmlentities', $row);
  34. // Format: time TZ - type - function(line) - text
  35. printf("%s - %s - %s (%s) \t- %s\n", $row[0], $row[1], $row[2], $row[3], $row[4]);
  36. }
  37. }
  38. } else {
  39. // Don't go further if the user is not logged in
  40. exit('You have to be logged in to see the log.');
  41. }
  42. ?>