Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_GET['logfile'])){
- $log_dir = '/var/log/mikrotik';
- echo '<html><head><title>Log File</title><link href="style.css" rel="stylesheet" type="text/css"></head>';
- // print the header
- echo '<table class="header"><tr class="header"><th class="header" align="left"><a class="header" href="./listfiles.php">';
- echo 'Mikrotik Router Log Viewer</a>     ['.$_GET['logfile'].']';
- echo '</th><th class="header" align="right">';
- echo date("Y.m.d");
- echo '</th></tr></table>';
- echo '<body>';
- echo '<p><br></p>';
- $handle = fopen($log_dir.'/'.$_GET['logfile'],'r');
- if($handle != FALSE){
- // print table of log file heading
- echo '<table class="log"><tr class="log"><th class="log">#</th>';
- echo '<th class="log">Day</th>';
- echo '<th class="log">Month</th>';
- echo '<th class="log">Time</th>';
- //echo '<th class="log">Source</th>';
- echo '<th class="log">Topic</th>';
- echo '<th class="log" align="left">Message</th></tr>';
- $count = 0;
- while(($line = fgets($handle)) != FALSE){
- //echo $line.'<br>';
- $new_line = $line;
- // check to see if the log entry was an error
- $error = 0;
- if(strpos(strtolower($line),'error') !== FALSE){
- $error = 1;
- }
- //split line into collums [Month, Day, Time, Source, Topic, Message]
- $cols = array("0","1","2","3","4","5");
- for($i=0;$i<5;$i++){
- $pos = 0;
- $pos = strpos($new_line,' ',$pos);
- $cols[$i] = trim(substr($new_line, 0,$pos));
- $new_line = trim(substr($new_line,$pos));
- }
- $cols[5] = trim($new_line);
- if($error == 1){
- echo '<tr class="error">';
- }
- else {
- echo '<tr class="log">';
- }
- echo '<td class="log">'.$count.'</td>';
- echo '<td class="log">'.$cols[1].'</td>'; //swap day and month collums
- echo '<td class="log">'.$cols[0].'</td>'; //swap day and month collums
- echo '<td class="log">'.$cols[2].'</td>';
- //echo '<td class="log">'.$cols[3].'</td>';
- echo '<td class="log">'.$cols[4].'</td>';
- echo '<td class="log" align="left">'.$cols[5].'</td></tr>';
- $count++;
- }
- echo '</table>';
- }
- else{
- header("Location: ./listfiles.php");
- exit();
- }
- echo '</body></html>';
- }
- else{
- //not parameter set
- //echo "ERROR";
- header("Location: ./listfiles.php");
- exit();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment