Location: PHPKode > projects > Free Windows Network User Accounting > fwnua-3.0/web-int/index.php
<?php /*
 FWNUA 3.0 Web Interface -> Main File

 Copyright (C) 2003-2004 FWNUA

 This program is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the Free
 Software Foundation; either version 2 of the License, or (at your option)
 any later version. This program is distributed in the hope that it will be
 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 Public License for more details.

 You should have received a copy of the GNU General Public License along
 with this program; if not, write to:

         Free Software Foundation, Inc.,
         59 Temple Place - Suite 330,
         Boston, MA  02111-1307, USA.

 Author:              Andrew Heacock <hide@address.com>
 Original Concept:    Thomas Taylor <hide@address.com>
 Web Site:            http://fwnua.sourceforge.net/
*/

/* Disable all caching since this page is very dynamic */
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
session_start();

/* Import config settings */
require_once ('config.php');

/* Create the FWNUA log file $data array */
if ($handle = opendir($logdir)){
    $x = 0;
    $z = 0;
    /* Open the file */
    while (false !== ($file = readdir($handle))){
        if ($file != "." && $file != "..") {
            $filearray = file($logdir.$file);
            $y = 0;
            /* Read each line */
            while (list(,$oneline_raw) = each($filearray)){
                /* Get rid of newlines */
                $oneline_tidy = trim($oneline_raw);
                /* Split each line into multi-dimensional array */
                $data[$x][$y] = split(",",$oneline_tidy);
                /* Fill the $search_data array if we are conducting a search */
                if (search_data($x, $y)){
                    $search_data[$z] = split(",",$oneline_tidy);
                    $z++;
                }
                $y++;
            }
            $x++;
        }
    }
    /* Get the number of rows we are returning */
    $rowsreturned = $x;
    if ($_GET){$results = $z;}
    /* Close the directory and start the page */
    closedir($handle);
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Free Windows Network User Accounting</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="index.css" />
<script type="text/javascript" src="sort.js"></script>
<script type="text/javascript" src="calendar.js"></script>
<script type="text/javascript">var cal1x = new CalendarPopup(); cal1x.showNavigationDropdowns();</script>
<script type="text/javascript">var cal1xx = new CalendarPopup(); cal1xx.showNavigationDropdowns();</script>
</head>
<body>
<table bgcolor="#4c5072" width="750" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td> <img src="top.png" alt="top.png" />
      <table width="750" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><a class="rowsreturned" href="index.php" title="Load FWNUA Index Table">Index</a></td>
          <td class="rowsreturned" align="right">Current User Count: <?php echo $rowsreturned ?></td>
        </tr>
      </table>
      <form action="index.php" method="get">
        <table width="750" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="28" colspan="3"><div align="center"><a class="header">FWNUA Search</a></div></td>
          </tr>
          <tr>
            <td width="309" height="28" class="searchleft"><a class="searchheader">Username:</a></td>
            <td width="7" class="searchleft"></td>
            <td width="434" class="searchright">
              <select name="username" size="1" class="sorttabledata">
                <option>-</option>
<?php           search_form_options("0") ?>
              </select>
            </td>
          </tr>
          <tr>
            <td height="28" class="searchleft"><a class="searchheader">Logged On/Off:</a></td>
            <td height="28" class="searchleft"></td>
            <td class="searchright">
              <select name="status" size="1" class="sorttabledata">
                <option>-</option>
                <option>on</option>
                <option>off</option>
              </select>
            </td>
          </tr>
          <tr>
            <td height="28" class="searchleft"><a class="searchheader">Computer Name:</a></td>
            <td height="28" class="searchleft"></td>
            <td class="searchright">
              <select name="computer" size="1" class="sorttabledata">
                <option>-</option>
<?php           search_form_options("2") ?>
              </select>
            </td>
          </tr>
          <tr>
            <td height="28" class="searchleft"><a class="searchheader">IP Address:</a></td>
            <td height="28" class="searchleft"></td>
            <td class="searchright">
              <select name="ipaddress" size="1" class="sorttabledata">
                <option>-</option>
<?php           search_form_options("3") ?>
              </select>
            </td>
          </tr>
          <tr>
            <td height="28" class="searchleft"><a class="searchheader">Domain:</a></td>
            <td height="28" class="searchleft"></td>
            <td class="searchright">
              <select name="domain" size="1" class="sorttabledata">
                <option>-</option>
<?php           search_form_options("5") ?>
              </select>
            </td>
          </tr>
          <tr>
            <td height="28" class="searchleft"><a class="searchheader">From:</a></td>
            <td height="28" class="searchleft"></td>
            <td class="searchright"><a class="rowsreturned"> Date: </a>
              <input type="text" name="date1x" value="-" size="8" class="sorttabledata" />
              <a href="#" class="rowsreturned" onclick="cal1x.select(document.forms[0].date1x,'anchor1x','yyyyMMdd'); return false;" name="anchor1x" id="anchor1x"><img src="cal.png" alt="Calender Pop-up: Start Date" border="0" align="middle" /></a>
              <a class="rowsreturned">Hour:</a>
              <select name="starthour" size="1" class="sorttabledata">
                <option selected="selected">-</option>
<?php           search_form_options("hourx") ?>
              </select>
              <a class="rowsreturned">Min:</a>
              <select name="startmin" size="1" class="sorttabledata">
                <option selected="selected">-</option>
<?php           search_form_options("minx") ?>
              </select> 
            </td>
          </tr>
          <tr>
            <td height="28" class="searchleft"><a class="searchheader">Until:</a></td> 
            <td height="28" class="searchleft"></td>
            <td class="searchright"><a class="header"></a><a class="rowsreturned">Date:</a>
              <input type="text" name="date1xx" value="-" size="8" class="sorttabledata" />
              <a href="#" class="rowsreturned" onclick="cal1xx.select(document.forms[0].date1xx,'anchor1xx','yyyyMMdd'); return false;" name="anchor1xx" id="anchor1xx"><img src="cal.png" alt="Calender Pop-up: End Date" border="0" align="middle" /></a>
              <a class="rowsreturned">Hour:</a> 
              <select name="endhour" size="1" class="sorttabledata">
                <option selected="selected">-</option>
<?php           search_form_options("hourx") ?>
              </select>
              <a class="rowsreturned">Min:</a>
              <select name="endmin" size="1" class="sorttabledata">
                <option selected="selected">-</option>
<?php           search_form_options("minx") ?>
              </select>
            </td>
          </tr>
          <tr>
            <td height="28" colspan="2"></td>
            <td class="searchright"><input name="submit" type="submit" value="Submit Query"/></td>
          </tr>
        </table>
      </form>
      <table width="750" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td class="rowsreturned" align="right"><?php if($_GET){echo "Results Returned: $results";} ?></td>
        </tr>
      </table>
      <table class="sortable" id="table" border="0" width="750" cellspacing="1" cellpadding="2">
        <tr>
<?php
    if ($colusername == 1)  {echo "          <td class=\"sorttableheader\" title=\"Sort Table By Username\">Username</td>\n";}
    if ($colcomputer == 1)  {echo "          <td class=\"sorttableheader\" title=\"Sort Table By Computer Name\">Computer</td>\n";}
    if ($colipaddress == 1) {echo "          <td class=\"sorttableheader\" title=\"Sort Table By IP Address\">IP</td>\n";}
    if ($coldomain == 1)    {echo "          <td class=\"sorttableheader\" title=\"Sort Table By Domain Name\">Domain</td>\n";}
    if ($colstatus == 1)    {echo "          <td class=\"sorttableheader\" title=\"Sort Table By Login Status\">Status</td>\n";}
    if ($coldate == 1)      {echo "          <td class=\"sorttableheader\" title=\"Sort Table By Date/Time\">Date</td>\n";}
    if ($colvnc == 1)       {echo "          <td class=\"sorttableheader\" title=\"Column Unsortable\">VNC</td>\n";}
    echo "        </tr>\n";

    /* Display the latest data if we are not searching */
    if(!$_GET){
        for($i=0; $i < $rowsreturned; $i++){
            $j = count($data[$i]) - 1;
            echo "        <tr>\n";
            if ($colusername == 1)  {echo "          <td class=\"sorttabledata\"><a href=\"/$vdir/"; print_r($data["$i"]["$j"]["0"]); echo ".csv\" target=\"_blank\" class=\"links\" title=\"View User's CSV Log File\">"; print_r($data["$i"]["$j"]["0"]); echo "</a></td>\n";}
            if ($colcomputer == 1)  {echo "          <td class=\"sorttabledata\"><a href=\"file:////"; print_r($data["$i"]["$j"]["2"]); echo "\" target=\"_blank\" class=\"links\" title=\"View Computer's Shared Resources\">"; print_r($data["$i"]["$j"]["2"]); echo "</a></td>\n";}
            if ($colipaddress == 1) {echo "          <td class=\"sorttabledata\">"; print_r($data["$i"]["$j"]["3"]); echo "</td>\n";}
            if ($coldomain == 1)    {echo "          <td class=\"sorttabledata\">"; print_r($data["$i"]["$j"]["5"]); echo "</td>\n";}
            if ($colstatus == 1)    {echo "          <td class=\"sorttabledata\">Logged "; print_r($data["$i"]["$j"]["1"]); echo "</td>\n";}
            if ($coldate == 1)      {echo "          <td class=\"sorttabledata\">"; print_r($data["$i"]["$j"]["4"]["4"]); 
                                                                                    print_r($data["$i"]["$j"]["4"]["5"]); echo "/"; 
                                                                                    print_r($data["$i"]["$j"]["4"]["6"]); 
                                                                                    print_r($data["$i"]["$j"]["4"]["7"]); echo "/"; 
                                                                                    print_r($data["$i"]["$j"]["4"]["0"]); 
                                                                                    print_r($data["$i"]["$j"]["4"]["1"]); 
                                                                                    print_r($data["$i"]["$j"]["4"]["2"]); 
                                                                                    print_r($data["$i"]["$j"]["4"]["3"]); echo " "; 
                                                                                    print_r($data["$i"]["$j"]["4"]["8"]); 
                                                                                    print_r($data["$i"]["$j"]["4"]["9"]); echo ":"; 
                                                                                    print_r($data["$i"]["$j"]["4"]["10"]);
                                                                                    print_r($data["$i"]["$j"]["4"]["11"]); echo "</td>\n";}
            if ($colvnc == 1)       {echo "          <td class=\"sorttabledata\"><a href=\"http://"; print_r($data["$i"]["$j"]["3"]); echo ":5800\" class=\"links\" title=\"Connect to Computer via Web VNC\">Connect</a></td>\n";}
            echo "        </tr>\n";       
        }
    /* Display the search data if we are running a search */
    }elseif($_GET){
        for($i=0; $i < $results; $i++){
            echo "        <tr>\n";
            if ($colusername == 1)  {echo "          <td class=\"sorttabledata\"><a href=\"/$vdir/"; print_r($search_data["$i"]["0"]); echo ".csv\" target=\"_blank\" class=\"links\" title=\"View User's CSV Log File\">"; print_r($search_data["$i"]["0"]); echo "</a></td>\n";}
            if ($colcomputer == 1)  {echo "          <td class=\"sorttabledata\"><a href=\"file:////"; print_r($search_data["$i"]["2"]); echo "\" target=\"_blank\" class=\"links\" title=\"View Computer's Shared Resources\">"; print_r($search_data["$i"]["2"]); echo "</a></td>\n";}
            if ($colipaddress == 1) {echo "          <td class=\"sorttabledata\">"; print_r($search_data["$i"]["3"]); echo "</td>\n";}
            if ($coldomain == 1)    {echo "          <td class=\"sorttabledata\">"; print_r($search_data["$i"]["5"]); echo "</td>\n";}
            if ($colstatus == 1)    {echo "          <td class=\"sorttabledata\">Logged "; print_r($search_data["$i"]["1"]); echo "</td>\n";}
            if ($coldate == 1)      {echo "          <td class=\"sorttabledata\">"; print_r($search_data["$i"]["4"]["4"]); 
                                                                                    print_r($search_data["$i"]["4"]["5"]); echo "/"; 
                                                                                    print_r($search_data["$i"]["4"]["6"]); 
                                                                                    print_r($search_data["$i"]["4"]["7"]); echo "/"; 
                                                                                    print_r($search_data["$i"]["4"]["0"]); 
                                                                                    print_r($search_data["$i"]["4"]["1"]); 
                                                                                    print_r($search_data["$i"]["4"]["2"]); 
                                                                                    print_r($search_data["$i"]["4"]["3"]); echo " "; 
                                                                                    print_r($search_data["$i"]["4"]["8"]); 
                                                                                    print_r($search_data["$i"]["4"]["9"]); echo ":"; 
                                                                                    print_r($search_data["$i"]["4"]["10"]);
                                                                                    print_r($search_data["$i"]["4"]["11"]); echo "</td>\n";}
            if ($colvnc == 1)       {echo "          <td class=\"sorttabledata\"><a href=\"http://"; print_r($search_data["$i"]["3"]); echo ":5800\" class=\"links\" title=\"Connect to Computer via Web VNC\">Connect</a></td>\n";}
            echo "        </tr>\n";     
        }
    }?>
      </table>
      <img src="bottom.png" alt="bottom.png" />
    </td>
  </tr>
</table>
<p align="center"><img src="valid.png" alt="valid.png" /></p>
</body>
</html>

<?php
/* Given a $data column number, this function returns <option>'s from the data, sorting it, and also eliminating duplicates */
function search_form_options($c){
    global $data;
    /* Create minute options */
    if ($c == "minx"){
        for ($x = 0; $x < 60; $x++){
            if ($x < 10){
                $x = "0".$x;
            }
            $options[] = $x;
        }
    /* Create hour options */
        
    }elseif($c == "hourx"){
        for ($x = 0; $x < 24; $x++){
            if ($x < 10){
                $x = "0".$x;
            }
            $options[] = $x;
        }
        
    /* Create data options */
    }else{
        
        /* Grab each item specified by column $c, to be sorted, into $list */
        for ($x = 0; $x <= count($data); $x++){
            for ($y = 0; $y <= count($data[$x]); $y++){
                $list[] = $data[$x][$y][$c];
            }
        }
        
        /* Eliminate duplicates and sort for drop downs */
        $options = array_unique($list);
        natcasesort($options);
        array_shift($options);
    }
    
    /* Print resluts back to function */
    foreach($options as $item){
        print "                <option>$item</option>\n";
    }
}

/* Given two $data array indexes, this function returns true if the search vars submited match $data[$x][$y] each iteration helping create the $search_data array */
function search_data($x, $y){
    /* Stop if we aren't even running a search */
    if (!$_GET){return false;}
    /* Pull in $data array for local usage */
    global $data;
    /* Pull in vars from search form */
    $vars['0']  = $_GET['username'];
    $vars['1']  = $_GET['status'];
    $vars['2']  = $_GET['computer'];
    $vars['3']  = $_GET['ipaddress'];
    $vars['4']  = $_GET['domain'];
    $vars['5']  = $_GET['date1x'];
    $vars['6']  = $_GET['date1xx'];
    $vars['7']  = $_GET['starthour'];
    $vars['8']  = $_GET['endhour'];
    $vars['9']  = $_GET['startmin'];
    $vars['10'] = $_GET['endmin'];
    
    /* Replace any foreign chars with known searchable values */
    if ($vars['0']  == "-"){$vars['0']  = $data[$x][$y]['0'];}
    if ($vars['1']  == "-"){$vars['1']  = $data[$x][$y]['1'];}
    if ($vars['2']  == "-"){$vars['2']  = $data[$x][$y]['2'];}
    if ($vars['3']  == "-"){$vars['3']  = $data[$x][$y]['3'];}
    if ($vars['4']  == "-"){$vars['4']  = $data[$x][$y]['5'];}
    if ($vars['5']  == "-"){$vars['5']  = "19700101";} /* Default: Starts search from Jan. 1st, 1970 */
    if ($vars['6']  == "-"){$vars['6']  = "20701231";} /* Default: Ends search on Dec. 31st, 2070 */
    if ($vars['7']  == "-"){$vars['7']  = "00";}
    if ($vars['8']  == "-"){$vars['8']  = "24";} /* To search on a single day, the start hour must be 00 while the end hour must be 24, not 00 */
    if ($vars['9']  == "-"){$vars['9']  = "00";}
    if ($vars['10'] == "-"){$vars['10'] = "00";}
    
    /* Set the timeframe to be searched through */
    $start = $vars['5'].$vars['7'].$vars['9'];
    $end   = $vars['6'].$vars['8'].$vars['10'];
    
    /* Execute all data vars with date range */
    if (($vars['0'] == $data[$x][$y]['0'])&&
        ($vars['1'] == $data[$x][$y]['1'])&&
        ($vars['2'] == $data[$x][$y]['2'])&&
        ($vars['3'] == $data[$x][$y]['3'])&&
        ($vars['4'] == $data[$x][$y]['5'])&&
        ($start     <= $data[$x][$y]['4'])&&
        ($end       >= $data[$x][$y]['4'])){
        /* If all of the above is true, return true */
        return true;
    }else{
        return false;
    }
}
?>
Return current item: Free Windows Network User Accounting