Subversion Repositories logviewer

Rev

Rev 9 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * ViaThinkSoft LogViewer
  5.  * Copyright 2018-2023 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. $filter_add = '';
  57. if (isset($_REQUEST['filter'])) {
  58.         $ary = explode(' ', $_REQUEST['filter']);
  59.         foreach ($ary as $a) {
  60.                 $a = trim($a);
  61.                 if ($a == '') continue;
  62.  
  63.                 if (substr($a,0,1) == '-') {
  64.                         $negate = "NOT ";
  65.                         $a = substr($a, 1); // remove "-"
  66.                 } else {
  67.                         $negate = " ";
  68.                 }
  69.  
  70.                 $filter_add .= " and text $negate like '".db_real_escape_string('%'.$a.'%')."' ";
  71.         }
  72. }
  73.  
  74. $where = "(anzahl > anzahlsolved) ".$filter_add." ".$hardcoded_filters;
  75.  
  76. if (isset($_REQUEST['solveall']) && logviewer_allow_solvemark()) {
  77.         db_query("update vts_fehlerlog set anzahlsolved = anzahl where $where");
  78.         header('location:?sort='.urlencode($sort)); // avoid F5
  79.         die();
  80. }
  81.  
  82. ?>
  83. <html>
  84.  
  85. <head>
  86.         <title>ViaThinkSoft LogViewer</title>
  87.         <script src="ajax.js"></script>
  88.         <link href="style<?php if (file_exists("style_$hostname.css")) echo "_$hostname"; ?>.css" rel="stylesheet" type="text/css">
  89. </head>
  90.  
  91. <body>
  92.  
  93. <h1>ViaThinkSoft LogViewer</h1>
  94.  
  95. <form method="GET" action="index.php">
  96. <input type="hidden" name="sort" value="<?php echo htmlentities($sort); ?>">
  97. <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
  98. if (isset($_REQUEST['filter'])) {
  99.         echo ' <a href="?sort='.htmlentities($sort).'">Clear filter</a>';
  100.         if (logviewer_allow_solvemark()) {
  101.                 echo ' | <a href="?sort='.htmlentities($sort).'&solveall=1&filter='.urlencode($_REQUEST['filter']).'" onclick="return confirm(\'Are you sure?\');">Solve all</a>';
  102.         }
  103. }
  104. ?></p>
  105. <p><font size="-3">Search terms divided with whitespace. Prepend hyphen to exclude a search term. Only field "Message" will be searched.</font></p>
  106. </form>
  107.  
  108. <?php
  109. if (!empty($add_filters)) {
  110.         echo '<span class="filter_hint">Showing max. '.COUNT.' results of max. '.MAXYEARS.' years; Hardcoded filter: '.htmlentities($add_filters).'</span>';
  111. } else {
  112.         echo '<span class="filter_hint">Showing max. '.COUNT.' results of max. '.MAXYEARS.' years</span>';
  113. }
  114. ?>
  115.  
  116. <div id="sort">Sort by: <?php
  117.  
  118. if ($sort == 'anzahl') {
  119.         echo '<span class="selected_menu">Occurrences</span>';
  120. } else {
  121.         echo '<a href="?sort=anzahl'.((isset($_REQUEST['filter'])) ? '&filter='.urlencode($_REQUEST['filter']) : '').'">Occurrences</a>';
  122. }
  123.  
  124. ?> | <?php
  125.  
  126. if ($sort == 'letzter') {
  127.         echo '<span class="selected_menu">Last occurrence</span>';
  128. } else {
  129.         echo '<a href="?sort=letzter'.((isset($_REQUEST['filter'])) ? '&filter='.urlencode($_REQUEST['filter']) : '').'">Last occurrence</a>';
  130. }
  131.  
  132. ?> | <?php
  133.  
  134. if ($sort == 'random') {
  135.         echo '<span class="selected_menu">Random order</span>';
  136. } else {
  137.         echo '<a href="?sort=random'.((isset($_REQUEST['filter'])) ? '&filter='.urlencode($_REQUEST['filter']) : '').'">Random order</a>';
  138. }
  139.  
  140. ?> (<span id="count"><?php
  141.  
  142. $res = db_query("select count(*) as cnt from vts_fehlerlog where $where;");
  143. $row = db_fetch_object($res);
  144. echo $row->cnt;
  145.  
  146. ?></span>)</div>
  147.  
  148. <table border="1" width="100%">
  149. <thead>
  150. <tr>
  151. <?php
  152. if (SOURCE_STYLE == 0) {
  153.         // nothing
  154. } else if (SOURCE_STYLE == 1) {
  155. ?>
  156.         <td>Source</td>
  157.         <td>Module</td>
  158. <?php
  159. } else if (SOURCE_STYLE == 2) {
  160. ?>
  161.         <td>User</td>
  162. <?php
  163. }
  164. ?>
  165.         <?php if (logviewer_allow_solvemark()) { ?><td>Mark&nbsp;as...</td><?php } ?>
  166.         <td>Count</td>
  167.         <td>Last&nbsp;occurrence</td>
  168.         <td>Message</td>
  169. </tr>
  170. </thead>
  171. <tbody>
  172. <tr>
  173. <?php
  174.  
  175. $odd = true;
  176.  
  177. if ($sort == 'letzter') {
  178.         $res = db_query("select * from vts_fehlerlog where $where order by letzter desc, anzahl desc, id asc limit ".COUNT);
  179. } else if ($sort == 'anzahl') {
  180.         $res = db_query("select * from vts_fehlerlog where $where order by anzahl desc, letzter desc, id asc limit ".COUNT);
  181. } else if ($sort == 'random') {
  182.         $res = db_query("select * from vts_fehlerlog where $where order by RAND() limit ".COUNT);
  183. }
  184. while ($row = db_fetch_object($res)) {
  185.         $text = htmlentities($row->text);
  186.         $text = preg_replace('@ ([^ ]{2,}) on line@ismU', ' <a href="?sort='.urlencode($sort).'&filter=\1">\1</a> on line', $text); // TODO: urlencode \1
  187.         $text = preg_replace('@(at|in) ([^ ]{2,}):(\d+)@ismU', '\1 <a href="?sort='.urlencode($sort).'&filter=\2">\2</a>:\3', $text); // TODO: urlencode \2
  188.  
  189.         $anzahl = htmlentities($row->anzahl);
  190.         if ($row->anzahlsolved != 0) $anzahl .= '<br>('.$row->anzahlsolved.')';
  191.  
  192.         $class = $odd ? 'tr_odd' : 'tr_even';
  193.         $odd = !$odd;
  194.  
  195.         echo '<tr id="line'.$row->id.'" class="'.$class.'">';
  196.         if (SOURCE_STYLE == 0) {
  197.                 // nothing
  198.         } else if (SOURCE_STYLE == 1) {
  199.                 echo '<td>'.htmlentities($row->logfile).'</td>';
  200.                 echo '<td>'.htmlentities($row->modul).'</td>';
  201.         } else {
  202.                 $user = preg_match('@/home/(.+)/@sU', $row->logfile, $m) ? $m[1] : ((strpos($row->logfile, '/root/') === 0) ? 'root' : '');
  203.                 echo '<td>'.htmlentities($user).'</td>';
  204.         }
  205.         if (logviewer_allow_solvemark()) echo '<td><a href="javascript:_solve('.$row->id.')">Solved</a></td>';
  206.         echo '<td>'.$anzahl.'</td>';
  207.         echo '<td>'.htmlentities($row->letzter).'</td>';
  208.         echo '<td>'.$text.'</td>';
  209.         echo '</tr>';
  210.         flush();
  211. }
  212. ?>
  213. </tr>
  214. </tbody>
  215. </table>
  216.  
  217. </body>
  218.  
  219. </html>
  220.