Skip to content

Commit

Permalink
Add Ganglia web rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
vvuksan committed Oct 22, 2010
0 parents commit 5eeb402
Show file tree
Hide file tree
Showing 91 changed files with 8,731 additions and 0 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
@@ -0,0 +1,2 @@
Federico Sacerdoti <fds@SDSC.EDU>
Matt Massie <massie@cs.berkeley.edu>
18 changes: 18 additions & 0 deletions COPYING
@@ -0,0 +1,18 @@
Copyright (c) 2001 by Matt Massie and The Regents of the University of California.
All rights reserved.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose, without fee, and without written agreement is
hereby granted, provided that the above copyright notice and the following
two paragraphs appear in all copies of this software.

IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
2 changes: 2 additions & 0 deletions README
@@ -0,0 +1,2 @@
This should work like the normal Ganglia web UI. The difference is that
you need to make the conf/ directory writeable by the Apache user.
101 changes: 101 additions & 0 deletions auth.php
@@ -0,0 +1,101 @@
<?php
#
# Functions to authenticate users with the HTTP "Basic" password
# box. Original author Federico Sacerdoti <fds@sdsc.edu>
#

#-------------------------------------------------------------------------------
# Returns an array of clusters that want to be private.
# Get list of private clusters. Put in $private[cluster name]="password"
function embarrassed ()
{
global $gmetad_root;
# The @ in front of a function name suppresses any warnings from it.
$fp=@fopen("./private_clusters","r");
if ($fp) {
while(!feof($fp)) {
$line=chop(fgets($fp,255));
if (!$line or !strcspn($line,"#")) { continue; }
$list=split("=",$line);
if (count($list)!=2) { continue; }
$name=trim($list[0]);
$pass=trim($list[1]);
$private[$name] = $pass;
}
fclose($fp);
}
return $private;
}

#-------------------------------------------------------------------------------
function authenticate()
{
global $clustername, $cluster;

$private_clusters = array_keys( embarrassed() );

if( in_array( $clustername, $private_clusters ) && ( $clustername == $cluster['NAME'] ) )
{
$auth_header = "WWW-authenticate: basic realm=\"Ganglia Private Cluster: " . $clustername . "\"";
}
else
{
$auth_header = "WWW-authenticate: basic realm=\"Ganglia Private Cluster\"";
}

header( $auth_header );
header("HTTP/1.0 401 Unauthorized");
#print "<HTML><HEAD><META HTTP-EQUIV=refresh CONTENT=1 URL=\"../?c=\"></HEAD>";
print "<H1>You are unauthorized to view the details of this Cluster</H1>";
print "In order to access this cluster page you will need a valid name and ".
"password.<BR>";
print "<H4><A HREF=\"./\">Back to Meta Cluster page</A></H4>";
exit;
}

#-------------------------------------------------------------------------------
function checkprivate()
{
global $clustername, $context;

# Allow the Meta context page.
if ($context=="meta") { return; }

$private=embarrassed();
if (isset($private[$clustername]) and $private[$clustername]) {
#echo "The password for $clustername is $private[$clustername]<br>";
if (empty($_SERVER['PHP_AUTH_PW'])) {
authenticate();
}
else {
# Check password (in md5 format). Username does not matter.
if (md5($_SERVER['PHP_AUTH_PW']) != $private[$clustername]) {
authenticate();
}
}
}
}

#-------------------------------------------------------------------------------
# To be called when in the control context. Assumes the password file
# "$gmetad_root/etc/private_clusters has an entry called "controlroom".
# The control room is always embarrassed.
function checkcontrol()
{
global $context;

if ($context != "control") { return; }

if (empty($_SERVER['PHP_AUTH_PW'])) {
authenticate();
}
else {
#echo "You entered password ". md5($PHP_AUTH_PW) ." ($PHP_AUTH_PW)<br>";
$private=embarrassed();
if (md5($_SERVER['PHP_AUTH_PW']) != $private["controlroom"]) {
authenticate();
}
}
}

?>
84 changes: 84 additions & 0 deletions calendar.php
@@ -0,0 +1,84 @@
<?php

# LGPL javascript calendar is optional, but very nice.
# Snag it from http://www.dynarch.com/demos/jscalendar/
# and install in jscalendar-1.0/ inside this web dir.

$calendar_head = '
<script type="text/javascript">
function ganglia_submit(clearonly) {
document.getElementById("cs").value = "";
document.getElementById("ce").value = "";
if (! clearonly)
document.ganglia_form.submit();
}
</script>
';

if ( ! is_readable('./jscalendar-1.0/calendar.js') ) {

$calendar = '';

} else {

$calendar_head .= '
<link rel="stylesheet" type="text/css" media="all" href="./jscalendar-1.0/calendar-system.css" title="calendar-system" />
<script type="text/javascript" src="./jscalendar-1.0/calendar.js"></script>
<script type="text/javascript" src="./jscalendar-1.0/lang/calendar-en.js"></script>
<script type="text/javascript" src="./jscalendar-1.0/calendar-setup.js"></script>
<script type="text/javascript">
var fmt = "%b %d %Y %H:%M"; // must be a format that RRDtool likes
function isDisabled(date, y, m, d) {
var today = new Date();
return (today.getTime() - date.getTime()) < -1 * Date.DAY;
}
function checkcal(cal) { // ensure cs < ce
var date = cal.date;
var time = date.getTime();
var field = document.getElementById("cs");
if (field == cal.params.inputField) {
// cs was changed: change ce
field = document.getElementById("ce");
var other = new Date(Date.parseDate(field.value, fmt));
if (time >= other) {
date = new Date(time + Date.HOUR);
field.value = date.print(fmt);
}
} else {
// ce was changed: change cs
field = document.getElementById("cs");
var other = new Date(Date.parseDate(field.value, fmt));
if (other >= time) {
date = new Date(time - Date.HOUR);
field.value = date.print(fmt);
}
}
}
</script>
';

$calendar = '
<script type="text/javascript">
Calendar.setup({
inputField : "cs",
ifFormat : fmt,
showsTime : true,
step : 1,
weekNumbers : false,
onUpdate : checkcal,
dateStatusFunc : isDisabled
});
Calendar.setup({
inputField : "ce",
ifFormat : fmt,
showsTime : true,
step : 1,
weekNumbers : false,
onUpdate : checkcal,
dateStatusFunc : isDisabled
});
</script>
';

}
?>

0 comments on commit 5eeb402

Please sign in to comment.