2014-05-19 16:40:33 +00:00
|
|
|
<?php
|
|
|
|
|
2016-02-06 22:53:17 +00:00
|
|
|
/**
|
|
|
|
* @author Tobias Reich
|
|
|
|
* @copyright 2015 by Tobias Reich
|
|
|
|
* @description This file queries the database for log messages and displays them if present.
|
|
|
|
*/
|
2014-05-19 16:40:33 +00:00
|
|
|
|
2016-01-26 14:31:53 +00:00
|
|
|
namespace Log;
|
2014-05-19 16:40:33 +00:00
|
|
|
|
2016-01-26 14:31:53 +00:00
|
|
|
use Mysqli;
|
|
|
|
use Lychee\Modules\Database;
|
|
|
|
use Lychee\Modules\Settings;
|
|
|
|
|
|
|
|
$lychee = __DIR__ . '/../../';
|
2016-01-24 12:07:25 +00:00
|
|
|
|
2014-05-19 16:40:33 +00:00
|
|
|
require($lychee . 'php/define.php');
|
|
|
|
require($lychee . 'php/autoload.php');
|
2016-01-26 14:31:53 +00:00
|
|
|
|
2016-02-06 22:53:17 +00:00
|
|
|
// Start the session
|
2016-01-26 14:31:53 +00:00
|
|
|
session_start();
|
2014-05-19 16:40:33 +00:00
|
|
|
|
2016-02-06 22:53:17 +00:00
|
|
|
// Set content
|
2014-05-19 16:40:33 +00:00
|
|
|
header('content-type: text/plain');
|
|
|
|
|
2016-02-06 22:53:17 +00:00
|
|
|
// Load config
|
2014-05-19 16:40:33 +00:00
|
|
|
if (!file_exists(LYCHEE_CONFIG_FILE)) exit('Error 001: Configuration not found. Please install Lychee first.');
|
|
|
|
require(LYCHEE_CONFIG_FILE);
|
|
|
|
|
2016-02-06 22:53:17 +00:00
|
|
|
// Ensure that user is logged in
|
2016-01-10 12:07:21 +00:00
|
|
|
if ((isset($_SESSION['login'])&&$_SESSION['login']===true)&&
|
2016-01-26 14:31:53 +00:00
|
|
|
(isset($_SESSION['identifier'])&&$_SESSION['identifier']===Settings::get()['identifier'])) {
|
2015-11-04 22:00:57 +00:00
|
|
|
|
2016-02-06 22:53:17 +00:00
|
|
|
// Result
|
|
|
|
$query = Database::prepare(Database::get(), "SELECT FROM_UNIXTIME(time), type, function, line, text FROM ?", array(LYCHEE_TABLE_LOG));
|
|
|
|
$result = Database::get()->query($query);
|
2015-11-04 22:00:57 +00:00
|
|
|
|
2016-02-06 22:53:17 +00:00
|
|
|
// Output
|
2016-01-10 12:07:21 +00:00
|
|
|
if ($result->num_rows===0) {
|
2014-05-19 16:40:33 +00:00
|
|
|
|
2016-01-10 12:07:21 +00:00
|
|
|
echo('Everything looks fine, Lychee has not reported any problems!');
|
2014-08-29 22:01:42 +00:00
|
|
|
|
2016-01-10 12:07:21 +00:00
|
|
|
} else {
|
2014-08-29 22:01:42 +00:00
|
|
|
|
2016-01-10 12:07:21 +00:00
|
|
|
while($row = $result->fetch_row()) {
|
2014-08-29 22:01:42 +00:00
|
|
|
|
2016-02-06 22:53:17 +00:00
|
|
|
// Encode result before printing
|
2016-01-10 12:07:21 +00:00
|
|
|
$row = array_map('htmlentities', $row);
|
2014-05-19 16:40:33 +00:00
|
|
|
|
2016-02-06 22:53:17 +00:00
|
|
|
// Format: time TZ - type - function(line) - text
|
|
|
|
printf("%s - %s - %s (%s) \t- %s\n", $row[0], $row[1], $row[2], $row[3], $row[4]);
|
2014-05-19 16:40:33 +00:00
|
|
|
|
2016-01-10 12:07:21 +00:00
|
|
|
}
|
2014-08-29 22:01:42 +00:00
|
|
|
|
2014-05-19 16:40:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-10 12:07:21 +00:00
|
|
|
} else {
|
|
|
|
|
2016-02-06 22:53:17 +00:00
|
|
|
// Don't go further if the user is not logged in
|
2016-02-06 23:12:28 +00:00
|
|
|
exit('You have to be logged in to see the log.');
|
2016-01-10 12:07:21 +00:00
|
|
|
|
2014-05-19 16:40:33 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 22:53:17 +00:00
|
|
|
?>
|