Guest User

showlog.php

a guest
Oct 18th, 2014
717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.35 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_GET['logfile'])){
  4.    
  5.     $log_dir = '/var/log/mikrotik';
  6.    
  7.     echo '<html><head><title>Log File</title><link href="style.css" rel="stylesheet" type="text/css"></head>';
  8.    
  9.     // print the header
  10.     echo '<table class="header"><tr class="header"><th class="header" align="left"><a class="header" href="./listfiles.php">';
  11.     echo 'Mikrotik Router Log Viewer</a>&nbsp&nbsp&nbsp&nbsp&nbsp['.$_GET['logfile'].']';
  12.     echo '</th><th class="header" align="right">';
  13.     echo date("Y.m.d");
  14.     echo '</th></tr></table>';
  15.    
  16.     echo '<body>';
  17.     echo '<p><br></p>';
  18.  
  19.    
  20.     $handle = fopen($log_dir.'/'.$_GET['logfile'],'r');
  21.    
  22.     if($handle != FALSE){
  23.        
  24.         // print table of log file heading
  25.         echo '<table class="log"><tr class="log"><th class="log">#</th>';
  26.         echo '<th class="log">Day</th>';
  27.         echo '<th class="log">Month</th>';
  28.         echo '<th class="log">Time</th>';
  29.         //echo '<th class="log">Source</th>';
  30.         echo '<th class="log">Topic</th>';
  31.         echo '<th class="log" align="left">Message</th></tr>';     
  32.        
  33.        
  34.         $count = 0;
  35.        
  36.         while(($line = fgets($handle)) != FALSE){
  37.             //echo $line.'<br>';   
  38.            
  39.             $new_line = $line;
  40.            
  41.             // check to see if the log entry was an error
  42.             $error = 0;
  43.             if(strpos(strtolower($line),'error') !== FALSE){
  44.                 $error = 1;
  45.             }
  46.            
  47.             //split line into collums [Month, Day, Time, Source, Topic, Message]
  48.             $cols = array("0","1","2","3","4","5");
  49.            
  50.             for($i=0;$i<5;$i++){
  51.                 $pos = 0;
  52.                 $pos = strpos($new_line,' ',$pos);
  53.                 $cols[$i] = trim(substr($new_line, 0,$pos));
  54.                 $new_line = trim(substr($new_line,$pos));
  55.                
  56.             }
  57.            
  58.             $cols[5] = trim($new_line);
  59.            
  60.             if($error == 1){
  61.                 echo '<tr class="error">';
  62.             }
  63.             else {
  64.                 echo '<tr class="log">';
  65.             }
  66.             echo '<td class="log">'.$count.'</td>';
  67.             echo '<td class="log">'.$cols[1].'</td>'; //swap day and month collums
  68.             echo '<td class="log">'.$cols[0].'</td>'; //swap day and month collums
  69.             echo '<td class="log">'.$cols[2].'</td>';
  70.             //echo '<td class="log">'.$cols[3].'</td>';
  71.             echo '<td class="log">'.$cols[4].'</td>';
  72.             echo '<td class="log" align="left">'.$cols[5].'</td></tr>';
  73.            
  74.             $count++;
  75.         }
  76.        
  77.         echo '</table>';
  78.    
  79.     }
  80.     else{
  81.         header("Location: ./listfiles.php");
  82.         exit();
  83.     }
  84.     echo '</body></html>';
  85. }
  86. else{
  87.     //not parameter set
  88.     //echo "ERROR";
  89.     header("Location: ./listfiles.php");
  90.     exit();
  91.    
  92. }
  93.  
  94.  
  95. ?>
Advertisement
Add Comment
Please, Sign In to add comment