.
[corvix.git] / var / deb-package / cluster_raw_old / opt / cluster / lib / www / ganglia / auth.php
blobc33b054a4bf623c12da80dbaed99841e46c799d2
1 <?php
3 # Functions to authenticate users with the HTTP "Basic" password
4 # box. Original author Federico Sacerdoti <fds@sdsc.edu>
7 #-------------------------------------------------------------------------------
8 # Returns an array of clusters that want to be private.
9 # Get list of private clusters. Put in $private[cluster name]="password"
10 function embarrassed ()
12 global $gmetad_root;
13 # The @ in front of a function name suppresses any warnings from it.
14 $fp=@fopen("./private_clusters","r");
15 if ($fp) {
16 while(!feof($fp)) {
17 $line=chop(fgets($fp,255));
18 if (!$line or !strcspn($line,"#")) { continue; }
19 $list=split("=",$line);
20 if (count($list)!=2) { continue; }
21 $name=trim($list[0]);
22 $pass=trim($list[1]);
23 $private[$name] = $pass;
25 fclose($fp);
27 return $private;
30 #-------------------------------------------------------------------------------
31 function authenticate()
33 header("WWW-authenticate: basic realm=\"Ganglia Private Cluster\"");
34 header("HTTP/1.0 401 Unauthorized");
35 #print "<HTML><HEAD><META HTTP-EQUIV=refresh CONTENT=1 URL=\"../?c=\"></HEAD>";
36 print "<H1>You are unauthorized to view the details of this Cluster</H1>";
37 print "In order to access this cluster page you will need a valid name and ".
38 "password.<BR>";
39 print "<H4><A HREF=\"./\">Back to Meta Cluster page</A></H4>";
40 exit;
43 #-------------------------------------------------------------------------------
44 function checkprivate()
46 global $clustername, $context;
48 # Allow the Meta context page.
49 if ($context=="meta") { return; }
51 $private=embarrassed();
52 if (isset($private[$clustername]) and $private[$clustername]) {
53 #echo "The password for $clustername is $private[$clustername]<br>";
54 if (empty($_SERVER['PHP_AUTH_PW'])) {
55 authenticate();
57 else {
58 # Check password (in md5 format). Username does not matter.
59 if (md5($_SERVER['PHP_AUTH_PW']) != $private[$clustername]) {
60 authenticate();
66 #-------------------------------------------------------------------------------
67 # To be called when in the control context. Assumes the password file
68 # "$gmetad_root/etc/private_clusters has an entry called "controlroom".
69 # The control room is always embarrassed.
70 function checkcontrol()
72 global $context;
74 if ($context != "control") { return; }
76 if (empty($_SERVER['PHP_AUTH_PW'])) {
77 authenticate();
79 else {
80 #echo "You entered password ". md5($PHP_AUTH_PW) ." ($PHP_AUTH_PW)<br>";
81 $private=embarrassed();
82 if (md5($_SERVER['PHP_AUTH_PW']) != $private["controlroom"]) {
83 authenticate();