Subversion Repositories logviewer

Rev

Rev 8 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * ViaThinkSoft LogViewer
  5.  * Copyright 2018-2022 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. $hostname = trim(file_get_contents('/etc/hostname'));
  21.  
  22. if (file_exists(__DIR__."/config_$hostname.inc.php")) {
  23.         require_once __DIR__."/config_$hostname.inc.php";
  24. } else {
  25.         require_once __DIR__.'/config.inc.php';
  26. }
  27.  
  28. if (file_exists(__DIR__."/db_$hostname.inc.php")) {
  29.         require_once __DIR__."/db_$hostname.inc.php";
  30. } else {
  31.         require_once __DIR__.'/db.inc.php';
  32. }
  33.  
  34. if (file_exists(__DIR__."/auth_$hostname.inc.php")) {
  35.         require_once __DIR__."/auth_$hostname.inc.php";
  36. } else {
  37.         require_once __DIR__.'/auth.inc.php';
  38. }
  39.  
  40. try {
  41.         logviewer_check_access();
  42. } catch (Exception $e) {
  43.         die('<h1>ViaThinkSoft LogViewer - Error</h1><p>'.$e->getMessage().'</p>');
  44. }
  45.  
  46. $sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : '';
  47. if ($sort == '') $sort = 'anzahl';
  48. if (($sort != 'anzahl') && ($sort != 'letzter') && ($sort != 'random')) die('Sort falsch');
  49.  
  50. # Please keep this code synchronized with ajax_cmd.php
  51. $add_filters = logviewer_additional_filter();
  52. $hardcoded_filters = empty($add_filters) ? '' : "and ($add_filters)";
  53. $hardcoded_filters .= " and (letzter >= DATE_SUB(NOW(),INTERVAL ".MAXYEARS." YEAR))";
  54. # Please keep this code synchronized with ajax_cmd.php
  55.  
  56. if (isset($_REQUEST['solveall']) && logviewer_allow_solvemark()) {
  57.         db_query("update vts_fehlerlog set anzahlsolved = anzahl where text like '%".db_real_escape_string($_REQUEST['solveall'])."%'");
  58.         header('location:?sort='.urlencode($sort)); // avoid F5
  59.         die();
  60. }
  61.  
  62. $filter_add = '';
  63. if (isset($_REQUEST['filter'])) {
  64.         $ary = explode(' ', $_REQUEST['filter']);
  65.         foreach ($ary as $a) {
  66.                 $a = trim($a);
  67.                 if ($a == '') continue;
  68.  
  69.                 if (substr($a,0,1) == '-') {
  70.                         $negate = "NOT ";
  71.                         $a = substr($a, 1); // remove "-"
  72.                 } else {
  73.                         $negate = " ";
  74.                 }
  75.  
  76.                 $filter_add .= " and text $negate like '".db_real_escape_string('%'.$a.'%')."' ";
  77.         }
  78. }
  79.  
  80. ?>
  81. <html>
  82.  
  83. <head>
  84.         <title>ViaThinkSoft LogViewer</title>
  85.         <script src="ajax.js"></script>
  86.         <link href="style<?php if (file_exists("style_$hostname.css")) echo "_$hostname"; ?>.css" rel="stylesheet" type="text/css">
  87. </head>
  88.  
  89. <body>
  90.  
  91. <h1>ViaThinkSoft LogViewer</h1>
  92.  
  93. <form method="GET" action="index.php">
  94. <input type="hidden" name="sort" value="<?php echo htmlentities($sort); ?>">
  95. <p>Filter: <input style="width:300px" type="text" name="filter" value="<?php echo htmlentities(isset($_REQUEST['filter']) ? $_REQUEST['filter'] : ''); ?>"> <input type="submit" value="Filter"><?php
  96. if (isset($_REQUEST['filter'])) {
  97.         echo ' <a href="?sort='.htmlentities($sort).'">Clear filter</a>';
  98.         if (logviewer_allow_solvemark()) {
  99.                 echo ' | <a href="?sort='.htmlentities($sort).'&solveall='.urlencode($_REQUEST['filter']).'" onclick="return confirm(\'Are you sure?\');">Solve all</a>';
  100.         }
  101. }
  102. ?></p>
  103. <p><font size="-3">Search terms divided with whitespace. Prepend hyphen to exclude a search term. Only field "Message" will be searched.</font></p>
  104. </form>
  105.  
  106. <?php
  107. if (!empty($add_filters)) {
  108.         echo '<span class="filter_hint">Showing max. '.COUNT.' results of max. '.MAXYEARS.' years; Hardcoded filter: '.htmlentities($add_filters).'</span>';
  109. } else {
  110.         echo '<span class="filter_hint">Showing max. '.COUNT.' results of max. '.MAXYEARS.' years</span>';
  111. }
  112. ?>
  113.  
  114. <div id="sort">Sort by: <?php
  115.  
  116. if ($sort == 'anzahl') {
  117.         echo '<span class="selected_menu">Occurrences</span>';
  118. } else {
  119.         echo '<a href="?sort=anzahl'.((isset($_REQUEST['filter'])) ? '&filter='.urlencode($_REQUEST['filter']) : '').'">Occurrences</a>';
  120. }
  121.  
  122. ?> | <?php
  123.  
  124. if ($sort == 'letzter') {
  125.         echo '<span class="selected_menu">Last occurrence</span>';
  126. } else {
  127.         echo '<a href="?sort=letzter'.((isset($_REQUEST['filter'])) ? '&filter='.urlencode($_REQUEST['filter']) : '').'">Last occurrence</a>';
  128. }
  129.  
  130. ?> | <?php
  131.  
  132. if ($sort == 'random') {
  133.         echo '<span class="selected_menu">Random order</span>';
  134. } else {
  135.         echo '<a href="?sort=random'.((isset($_REQUEST['filter'])) ? '&filter='.urlencode($_REQUEST['filter']) : '').'">Random order</a>';
  136. }
  137.  
  138. ?> (<span id="count"><?php
  139.  
  140. $res = db_query("select count(*) as cnt from vts_fehlerlog where (anzahl > anzahlsolved) ".$filter_add." ".$hardcoded_filters.";");
  141. $row = db_fetch_object($res);
  142. echo $row->cnt;
  143.  
  144. ?></span>)</div>
  145.  
  146. <table border="1" width="100%">
  147. <thead>
  148. <tr>
  149. <?php
  150. if (SOURCE_STYLE == 0) {
  151.         // nothing
  152. } else if (SOURCE_STYLE == 1) {
  153. ?>
  154.         <td>Source</td>
  155.         <td>Module</td>
  156. <?php
  157. } else if (SOURCE_STYLE == 2) {
  158. ?>
  159.         <td>User</td>
  160. <?php
  161. }
  162. ?>
  163.         <?php if (logviewer_allow_solvemark()) { ?><td>Mark&nbsp;as...</td><?php } ?>
  164.         <td>Count</td>
  165.         <td>Last&nbsp;occurrence</td>
  166.         <td>Message</td>
  167. </tr>
  168. </thead>
  169. <tbody>
  170. <tr>
  171. <?php
  172.  
  173. $odd = true;
  174.  
  175. if ($sort == 'letzter') {
  176.         $res = db_query("select * from vts_fehlerlog where (anzahl > anzahlsolved) ".$filter_add." ".$hardcoded_filters." order by letzter desc, anzahl desc, id asc limit ".COUNT);
  177. } else if ($sort == 'anzahl') {
  178.         $res = db_query("select * from vts_fehlerlog where (anzahl > anzahlsolved) ".$filter_add." ".$hardcoded_filters." order by anzahl desc, letzter desc, id asc limit ".COUNT);
  179. } else if ($sort == 'random') {
  180.         $res = db_query("select * from vts_fehlerlog where (anzahl > anzahlsolved) ".$filter_add." ".$hardcoded_filters." order by RAND() limit ".COUNT);
  181. }
  182. while ($row = db_fetch_object($res)) {
  183.         $text = htmlentities($row->text);
  184.         $text = preg_replace('@ ([^ ]{2,}) on line@ismU', ' <a href="?sort='.urlencode($sort).'&filter=\1">\1</a> on line', $text); // TODO: urlencode \1
  185.         $text = preg_replace('@(at|in) ([^ ]{2,}):(\d+)@ismU', '\1 <a href="?sort='.urlencode($sort).'&filter=\2">\2</a>:\3', $text); // TODO: urlencode \2
  186.  
  187.         $anzahl = htmlentities($row->anzahl);
  188.         if ($row->anzahlsolved != 0) $anzahl .= '<br>('.$row->anzahlsolved.')';
  189.  
  190.         $class = $odd ? 'tr_odd' : 'tr_even';
  191.         $odd = !$odd;
  192.  
  193.         echo '<tr id="line'.$row->id.'" class="'.$class.'">';
  194.         if (SOURCE_STYLE == 0) {
  195.                 // nothing
  196.         } else if (SOURCE_STYLE == 1) {
  197.                 echo '<td>'.htmlentities($row->logfile).'</td>';
  198.                 echo '<td>'.htmlentities($row->modul).'</td>';
  199.         } else {
  200.                 $user = preg_match('@/home/(.+)/@sU', $row->logfile, $m) ? $m[1] : ((strpos($row->logfile, '/root/') === 0) ? 'root' : '');
  201.                 echo '<td>'.htmlentities($user).'</td>';
  202.         }
  203.         if (logviewer_allow_solvemark()) echo '<td><a href="javascript:_solve('.$row->id.')">Solved</a></td>';
  204.         echo '<td>'.$anzahl.'</td>';
  205.         echo '<td>'.htmlentities($row->letzter).'</td>';
  206.         echo '<td>'.$text.'</td>';
  207.         echo '</tr>';
  208.         flush();
  209. }
  210. ?>
  211. </tr>
  212. </tbody>
  213. </table>
  214.  
  215. </body>
  216.  
  217. </html>
  218.