Subversion Repositories logviewer

Rev

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

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