php8
[web.mtrack] / admin / logs.php
1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3 include '../../inc/common.php';
4
5 MTrackACL::requireAnyRights('Browser', 'modify');
6
7 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
8   if (isset($_POST['reset'])) {
9     MTrackDB::q('delete from search_engine_state');
10   }
11   header("Location: {$ABSWEB}admin/logs.php");
12   exit;
13 }
14
15 mtrack_head("Logs");
16
17 $vardir = MTrackConfig::get('core', 'vardir');
18 $filename = "$vardir/indexer.log";
19
20
21 echo "<h1>Indexer Log</h1>\n";
22 echo "<tt>$filename</tt><br>\n";
23 $mtime = filemtime($filename);
24 if ($mtime) {
25   echo "Modified: " . mtrack_date("@$mtime", true) . "<br>";
26 }
27
28 $last = null;
29 foreach (MTrackDB::q('select last_run from search_engine_state')->fetchAll()
30     as $row) {
31   $last = $row[0];
32 }
33 if ($last === null) {
34   echo "No objects have been indexed yet\n";
35 } else {
36   echo "Last Indexed Object: " . mtrack_date($last, true) . "<br>\n";
37 }
38
39 if ($mtime) {
40   $fp = fopen($filename, 'r');
41   $lines = array();
42   while (($line = fgets($fp)) !== false) {
43     $lines[] = htmlentities($line, ENT_QUOTES, 'utf-8');
44     if (count($lines) > 100) {
45       array_shift($lines);
46     }
47   }
48   echo "<pre>";
49   foreach ($lines as $line) {
50     echo $line;
51   }
52   echo "</pre>";
53 }
54 ?>
55 <form method='post'>
56   <button type='submit' name='reset'
57     >Rebuild Index from scratch on next run</button>
58 </form>
59 <?php
60
61 mtrack_foot();
62