<?php
	// GPL 1999
	// Hans Schou <chlor@schou.dk>
	header("Expires: Mon, 25 Jan 1999 05:00:00 GMT"); // Date in the past
	header("Last-Modified: ".gmdate("D, d M Y H:i:s")."GMT"); // modified
	header("Cache-Control: no-cache, must-revalidate");   // HTTP/1.1
	header("Pragma: no-cache"); // HTTP/1.0
	if ($TWO_TASK)
		 $SID = $TWO_TASK;      // Oracle is running on a remote machine
	else
		 $SID = $ORACLE_SID;    // Oracle is running on this machine
		              // Authenticate user, default Oracle username/password: system/manager
	if(!isset($PHP_AUTH_USER)) {
		header("WWW-Authenticate: Basic realm=\"Oracle SYSTEM login required. SID=$SID\"");
		header("HTTP/1.0 401 Unauthorized");
		echo "You have no access to Oracle\n";
		exit;
	}
?><html>
<title>Who is using Oracle</title>
<meta http-equiv="Refresh" content="60"; URL="http://<?php echo $PHP_SELF; ?>">
<body bgcolor=white><center>
<?php
	echo "<h2>Who is using Oracle?<br>Server: ".$SID;
	echo date("H:i:s, Y-m-d", time())."<br>";
	echo "User name: ".$PHP_AUTH_USER;
	echo "</h2>\n";
	// connect, default Oracle username/password: system/m anager
	// To use another SID, enter user name  as: "system@ORCL"
	$conn = ora_logon($PHP_AUTH_USER,$PHP_AUTH_PW);
	if ($conn) {
		// prepare
		$curs = ora_open($conn);
		$sql = "SELECT osuser,machine,program FROM v\$session ORDER BY osuser";
		ora_parse($curs,$sql,1);
		// execute sql statement
		if (ora_exec($curs)) {
			// fetch
			echo "<table border=5 cellpadding=5>\n";
			echo "<tr><th>".ora_columnname($curs,0)."</th>";
			echo "<th>".ora_columnname($curs,1)."</th>";
			echo "<th>".ora_columnname($curs,2)."</th></tr>\n";
			while (ora_fetch($curs)) {
				echo "<tr><td>";
				echo ora_getcolumn($curs,0);
				echo "</td><td>";
				echo ora_getcolumn($curs,1);
				echo "</td><td>";
				echo ora_getcolumn($curs,2);
				echo "</td></tr>\n";
			}
			echo "</tr></table>\n";
			echo "<p>\n";
		}
		ora_close($curs);
		ora_logoff($conn);
	}
	// Display source file if exists
	if (file_exists($fn = basename($PHP_SELF. "s") ))
		echo  "<i><a href=\"".$fn. "\">Source file: $fn</a></i>\n";
	else
		echo  "<i>Source file is not available</i>\n" ;
?>
</center>
</body></html>
