Source for file GuiLogtail.php

Documentation is available at GuiLogtail.php

  1. <?php
  2. /**
  3.  * 
  4.  * GuiLogtail.php.php
  5.  *
  6.  * Show log files in the web GUI
  7.  *
  8.  * @package     FreeNAC
  9.  * @author      Sean Boran/Thomas Dagonnier (FreeNAC Core Team)
  10.  * @copyright   2008 FreeNAC
  11.  * @license     http://www.gnu.org/copyleft/gpl.html   GNU Public License Version 3
  12.  * @version     SVN: $Id$
  13.  * @link        http://freenac.net
  14.  *
  15.  */
  16.  
  17.  
  18. class GuiLogtail extends WebCommon {
  19.   // See also WebCommon and Common
  20.  
  21.  
  22.   function __construct($filename$length=10$pattern="vmpsd|postconnect")
  23.   {
  24.     global $ad_auth;
  25.     parent::__construct();     // See also WebCommon and Common
  26.     $this->logger->setDebugLevel(3);
  27.  
  28.  
  29.        if ($_SESSION['nac_rights']>=1{
  30.          echo $this->logtail($filename$length$pattern);
  31.        }
  32.        else {
  33.          echo "<h1>ACCESS DENIED</h1>";
  34.          echo "<p>Please verify the nac_rights for username: <" .$_SESSION['username']
  35.           .">.</p>";
  36.          $this->logger->logit("ACCESS DENIED: verify the nac_rights for username: <" .$_SESSION['username'.">.</p>");
  37.        }
  38.  
  39.     echo $this->print_footer();
  40.  
  41.   }
  42.  
  43.   function logtail($filename$length=10$pattern='')
  44.   {
  45.         $logfile fopen($filename,'r');
  46.         // TBD: catch error if file cannot be read, or non existant.
  47.  
  48.         if strlen($pattern)>
  49.           $cmd="/usr/bin/tail -n $length $filename | egrep \"$pattern\"";
  50.         }
  51.         else {
  52.           $cmd="/usr/bin/tail -n $length $filename ";
  53.         }
  54.         $this->debug($cmd3);
  55.         exec($cmd$logtext$error);
  56.  
  57.         $text "<h2>The last $length lines in the log $filename :</h2>";
  58.         if ($error){
  59.             $text .= "Tail Error: ($cmd$error\n";
  60.             $this->logger->logit("Tail Error: ($cmd$error");
  61.         }
  62.         else {
  63.             //$text .= "\n<p>\n<pre>\n";
  64.             $text .= "\n<p class='logtext'>";
  65.             foreach ($logtext as $logline{
  66.                 //$text .= $logline."\n";
  67.                 $text .= $logline ."<br/>\n";
  68.             };
  69.             //$text .= "</pre>";
  70.             $text .= "</p>";
  71.         };
  72.         return($text);
  73.   }
  74.  
  75.  
  76.   /**
  77.    * Generic query report
  78.    */
  79.   public function query($q
  80.   {
  81.     $conn=$this->getConnection()//  make sure we have a DB connection
  82.     $output="<table id='t2' width='1000' border='0' class='text14'>";
  83.  
  84.     try {
  85.       #$limit=$this->real_escape_string1($limit, $conn);
  86.       $rowcount=0;
  87.       #$q.=" LIMIT 1"; 
  88.       $this->debug("query() $q"2);
  89.  
  90.       $res $conn->query($q);
  91.       if ($res === FALSE)
  92.         throw new DatabaseErrorException($conn->error);
  93.  
  94.       // Title: Grab the list of field names
  95.       $fields=$res->fetch_fields();
  96.       while (($row $res->fetch_assoc()) !== NULL{
  97.         $rowcount++;
  98.         foreach ($fields as $field{
  99.           $fname=$field->name;
  100.           $output.="<tr><td>$fname</td><td>{$row[$fname]}</td></tr>";
  101.         
  102.       }
  103.  
  104.       $output.="<tr><td>Date printed</td><td>" .date("F j, Y, g:i a"."</td></tr>";
  105.  
  106.       // Inform the user if no data was returned
  107.       if ( ($rowcount)=={
  108.         $output.= "<br/><tr><td colspan='4' align='center' class='text16red'>The report is empty</td></tr><tr></tr><br/>";
  109.  
  110.       }
  111.       $res->close();
  112.  
  113.     catch (Exception $e{
  114.       #if ($in_db_conn === NULL and isset($conn))
  115.       if (isset($conn))
  116.         $conn->close();
  117.       throw $e;
  118.     }
  119.  
  120.     // close table, send back text
  121.     $output.="</table>";
  122.     return($output);
  123.   }
  124.  
  125.  
  126.  
  127. // class
  128.  
  129. ?>

Documentation generated on Mon, 17 Nov 2008 01:10:37 +0100 by phpDocumentor 1.4.0