Location: PHPKode > projects > VNCTracker > vnctracker-3.2/index.php
<?php
/*
  VNCTracker - 2005-2008 Robert M. Cassell

  Retrieve host info and format .vnc file
  for quick url link to .VNC connection files.
  http://sourceforge.net/projects/vnctracker
  
  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 the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

include('config.php');

//////////////////////////////
// You can turn off RegisterGlobals in php.ini
// RegisterGlobals = off
$dowhat = $_REQUEST['dowhat']; 
$delhost = $_REQUEST['delhost'];
$requesthost = $_REQUEST['requesthost'];
$listenip = $_REQUEST['listenip'];
$remoteip = getenv('REMOTE_ADDR');

//add host
$ihostname = $_REQUEST['ihostname'];
$idate = $_REQUEST['idate'];
$iip = $_REQUEST['iip'];
$iphone = $_REQUEST['iphone'];
$icontact = $_REQUEST['icontact'];
$iconnection = $_REQUEST['iconnection'];
$ios = $_REQUEST['ios'];
//////////////////////////////


//Request VNC
if ($dowhat == "Request")
    {
    $remoteip = getenv('REMOTE_ADDR');
    exec ("sh hosts/request.vnc.sh $requesthost $remoteip");
    echo "Requesting VNC Session from Store $requesthost... \n";
    } 

//Delete host
if ($dowhat == "Delete")
    {
    mysql_connect("$db_host", "$db_user", "$db_pass") or die(mysql_error());
    mysql_select_db("$db_db") or die(mysql_error());
    $querydel = "DELETE FROM $db_table WHERE hostname='$delhost'";
    mysql_query("$querydel") or die(mysql_error());
    $response = "Removed $delhost from VNCTracker...";
    }

//Add host
if ($dowhat == "Add")
    {
    mysql_connect("$db_host", "$db_user", "$db_pass") or die(mysql_error());
    mysql_select_db("$db_db") or die(mysql_error());
    $queryadd = "INSERT INTO $db_table VALUES ('$ihostname', '$idate', '$iip', '$iphone', '$icontact', '$iconnection', '$ios')";
    mysql_query("$queryadd") or die(mysql_error());
    $response = "Added $ihostname to VNCTracker...";
    } 
?>


<!-- Start html -->
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
 'http://www.w3.org/TR/html4/loose.dtd'>
<html>
<!-- Head -->
<head>
<meta http-equiv='content-type' content='text/html; charset=UTF-8'>
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='refresh' content='180'>
<link rel='shortcut icon' href='http://<? echo "$mydomain/$vnctpath" ?>favicon.ico'>
<link rel='stylesheet' href='style.css'>
<title>VNCTracker</title>

<!-- vnc request prompt -->
<script type="text/javascript">
<!--
function ReqConfirm() {
      if (alert("This VNC Request can take up to 5 minutes.." + '\n' + "Make sure you have VNC Listen Running!" + '\n' + '\n' + "If the host doesn't connect to you after a few minutes, you" + '\n' + "should check and make sure they have VNC Server running." + '\n\n' + "Also make sure you have your firewall set to forward TCP port 5500.")) {
            window.location = "index.php";
      } else {
            return false;
      }
}
//-->
</script>



<!-- delhost confirm prompt -->
<SCRIPT LANGUAGE="Javascript">
<!---
function decision(message, url){
if(confirm(message)) location.href = url;
}
// --->
</SCRIPT>                                                        


</head>

<!-- Body begin -->
<body bgcolor='#0066CC'>
<!-- Insert Header
//Include('header.html'); -->


<!-- current time -->
<font size='4' color='#FFFFFF'><b><? echo "$month-$day-$year $fcblue _ $fcclose $hdate" ?></b></font><font color='#FFFFFF' size='1'> refreshed every 180 secs</font>
<br>
<!-- Main table -->
<table width='90%' border='0'>
<!-- Top Left Cell -->
<tr><td>
<!-- Help box -->
<div title='Date Color Map' class='colorbox'>
<ul><li><font color='#006600'><b>Green</b></font><font color='black'> = 15 minutes ago or less</font>
<li><font color='#FF9900'><b>Orange</b></font><font color='black' = 16 - 30 minutes. </font>
<li><font color='#FF0000'><b>Red</b></font><font color='black' = 31+ minutes </font></ul>
</div>


<!-- Update button -->
<form action='index.php' method='POST'>
<input class='button' title=' Check Mail Logs for Current IPs.. ' type='submit' name='dowhat' value='Update'>
</form>
<br>
<!-- Refresh button -->
<form action='index.php' method='POST'>
<input class='button' title=' Check the Current Database for IPs.. ' type='submit' name='dowhat' value='Refresh'>
</form>
</td><td width='20%'>
<!-- Top Right Cell -->
</td></tr>
<tr><td width='90%'>
<!-- Left results table -->
<table width='100%' cellspacing='1' cellpadding='2' border='0'>

<!-- Table header -->
<tr id='ignore' style='cursor:help' bgcolor='#C0C0C0'>
<th title='Host eMail Links...'> Host </th>
<th title='See Color Chart above for Data/Color meanings...'> Date</th>
<th title='Last known good IP Address...'> IP</th>
<th title='Phone (voice)'> Phone</th>
<th title='Contact...'> Contact</th>
<th title='Connection Type...'> Speed</th>
<th title='Operating System...'> OS</th>
<th title='Request Reverse VNC Connection'> VNC</th>
<th title='Remove Host...'> rm</th></tr>

<?
//DB connect..
mysql_connect("$db_host", "$db_user", "$db_pass") or die(mysql_error());
mysql_select_db("$db_db") or die(mysql_error());
$result = mysql_query("SELECT * FROM $db_table order by $db_sort") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {

//Alternates row <tr> colors
//$bgcolor = ($i++ & 1) ? '#CCCC99' : '#FFFFFF';
$bgcolor = ($i++ & 1) ? '#D5D5D5' : '#e5e5e5';

//Chop up the results..
$hosttime = $row['date'];
$myhost = $row['hostname'];
$myip = $row['ip'];
$mycontact = $row['contact'];
$myphone = $row['phone'];
$myconnect = $row['connection'];
$myos = $row['os'];

//Change font color per expire time
//If it's there it's fresh(green)..then how stale..(green -> orange -> red)
$age = "#339900";

if ($hosttime < $expire30) {
   $age = "#FF0000";  //red
   } elseif ($hosttime < $expire15) {
   $age = "#FF9900";  //orange
   } else {
   $age = "#339900";  //green
}

//Results into main table
//Print out the contents of each row into a table.
echo "<tr $neato bgcolor='$bgcolor'><td align='center' title=' eMail Host.. '><a href='mailto:$myhost@$mydomain'>\n";
echo " $myhost ";
echo "</a></td><td nowrap align='center' title=' Dialup IP is only good for around 20 minutes.. '><font color='$age'>\n";
echo " <b>$hosttime</b> ";
echo "</font></td><td align='center' title=' Begin VNC Connection.. '>\n";
echo "<a href='http://$mydomain/hosts/host$myhost.vnc'>\n";
echo " $myip ";
echo "</a></td><td align='center' title=' Phone Number.. '>\n";
echo " $myphone \n";
echo "</td><td nowrap title=' Contact names.. ' align='center'>\n";
echo " $mycontact \n";
echo "</td><td title=' Connection Type.. ' align='center'>\n";
echo " $myconnect \n";
echo "</td><td title=' Operating System.. ' align='center'>\n";
echo " $myos \n";
echo "</td><td title=' Request VNC Session.. ' align='center'>\n";
echo "<a href='index.php?dowhat=Request&amp;requesthost=$myhost&amp;listenip=$remoteip' onclick='ReqConfirm();'><font color='green'><b>Request</b></font></a>\n";
echo "</td><td style='cursor:crosshair' title=' Remove Host.. ' align='center'>\n";
echo "<a style='cursor:crosshair' href=\"javascript:decision('Remove this host from the database?  $myhost ','index.php?dowhat=Delete&amp;delhost=$myhost')\"><font color='#FF0000'><b>>!<</b></font></a>\n";
echo "</td></tr>\n";
}

//Add host form
?>
<form action='index.php' method='POST'>
<td><input type='text' name='ihostname' maxlength='12' value='' size='12'></td>
<td><input type='text' name='idate' maxlength='19' value=' <? echo "$date $time" ?> ' size='19'></td>
<td><input type='text' name='iip' maxlength='15' value='' size='15'></td>
<td><input type='text' name='iphone' maxlength='12' value='' size='12'></td>
<td><input type='text' name='icontact' maxlength='24' value='' size='20'></td>
<td><input type='text' name='iconnection' maxlength='5' value='' size='5'></td>
<td><input type='text' name='ios' maxlength='5' value='' size='5'></td>
<td><input class='button' title=' Add this new host.. ' type='submit' name='dowhat' value='Add'></td>
</form></tr>
<?

//Left table close
echo "</table></td>\n";

//Right table start
//Notification area for Update|Refresh|Add|Delete
echo "<td width='100%'>$fcwhite\n";

//debug
//echo "$dowhat\n";
//echo "$delhost\n";
//echo "$ihostname\n";
//echo "$idate\n";
//echo "$iip\n";
//echo "$iphone\n";
//echo "$icontact\n";
//echo "$iconnection\n";
//echo "$ios\n"; 

//Update DB from mail logs.
if ($dowhat == "Update")
    {
    $doUpdate = system("./update-hostips.sh $upoptions");
    echo "<pre> $doUpdate </pre> Updated.. \n";
    }

//Refresh
if ($dowhat == "Refresh")
    {
    echo " Refreshed.. \n";
    }

//Delete host entry
//delhost code now at top of page for refresh after removal.
if ($dowhat == "Delete")
    {
    echo "$response \n";
    }

//Add host
if ($dowhat == "Add")
    {
    echo "$response \n";
    }
?>

<!-- Close right column reset font color -->
</font></td>

<!-- Insert Footer -->
<? Include('footer.html') ?>


<!-- Close the big table and doc -->
</table></body></html>
Return current item: VNCTracker