defs.php3.in 5.48 KB
Newer Older
1 2
<?php
#
3
# Standard definitions! 
4
#
5 6 7 8 9 10 11 12
$TBDIR          = "@prefix@/";
$WWWDEFS        = "@WWWDEFS@";

#
# Include configure selected definitions.
#
include("$WWWDEFS"."-defs.php3");

Leigh B. Stoller's avatar
Leigh B. Stoller committed
13 14
$TBWWW_DIR	= "$TBDIR"."www/";
$TBBIN_DIR	= "$TBDIR"."bin/";
15
$TBETC_DIR	= "$TBDIR"."etc/";
16 17 18
$TBLIBEXEC_DIR	= "$TBDIR"."libexec/";
$TBSUEXEC_PATH  = "$TBLIBEXEC_DIR/suexec";
$TBCHKPASS_PATH = "$TBLIBEXEC_DIR/checkpass";
19
$TBCSLOGINS     = "$TBETC_DIR/cslogins";
20

21
$TBPROJ_DIR     = "/proj";
22
$TBUSER_DIR	= "/users";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
23
$TBNSSUBDIR     = "nsdir";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
24

25 26
$TBAUTHCOOKIE   = "HashCookie" . $TBCOOKIESUFFIX;
$TBNAMECOOKIE   = "MyUidCookie" . $TBCOOKIESUFFIX;
27
$TBAUTHTIMEOUT  = 21600;
28

29 30
$HTTPTAG        = "http://";

31
#
32 33 34
# This just spits out an email address in a page, so it does not need
# to be configured per development tree. It could be though ...
# 
35 36
$TBMAILADDR     = "<a href=\"mailto:$TBMAILADDR_OPS\">
                      Testbed Operations ($TBMAILADDR_OPS)</a>";
37

38 39 40 41 42
#
# Database constants and the like.
#
include("dbdefs.php3");

43 44 45 46 47 48 49 50 51 52 53 54 55
#
# Generate the KEY from a name
#
function GENKEY ($name) {
     return crypt("TB_"."$name"."_USR", strlen($name) + 13);
}

#
# Internal errors should be reported back to the user simply. The actual 
# error information should be emailed to the list for action. The script
# should then terminate if required to do so.
#
function TBERROR ($message, $death) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
56
    global $TBMAIL_WWW, $TBMAIL_OPS, $TBMAILADDR;
57

58 59
    mail($TBMAIL_OPS,
         "TESTBED WEB ERROR REPORT",
60 61 62 63
         "\n".
         "$message\n\n".
         "Thanks,\n".
         "Testbed WWW\n",
64
         "From: $TBMAIL_OPS\n".
65
         "Errors-To: $TBMAIL_WWW");
66

Leigh B. Stoller's avatar
Leigh B. Stoller committed
67
    # Allow sendmail to run.
68
    sleep(1); 
69 70

    if ($death) {
71
            $msg = "<font size=+1><br>
72 73
                    $message
	            <br>	
74
        	    </font>
75 76 77 78
                    <p><p>
		    Could not continue. Please contact $TBMAILADDR\n";

	    PAGEERROR($msg);
79 80 81
    }
    return 0;
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
82 83 84 85 86

#
# General user errors should print something warm and fuzzy
#
function USERERROR($message, $death) {
87 88
    global $TBMAILADDR;

89
    $msg = "<font size=+1><br>
90 91
            $message
            <br>	
92
      	    </font>
93 94
            <p><p>
            Please contact $TBMAILADDR if you feel this message is an error.";
95

Leigh B. Stoller's avatar
Leigh B. Stoller committed
96
    if ($death) {
97
	PAGEERROR($msg);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
98
    }
99 100
    else
        echo "$msg\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
101 102
}

103 104 105 106 107 108 109 110
#
# A form error.
#
function FORMERROR($field) {
    USERERROR("Missing field; ".
              "Please go back and fill out the \"$field\" field!", 1);
}

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
#
# Is this user an admin type?
#
function ISADMIN($uid) {
    global $TBDBNAME;

    $query_result = mysql_db_query($TBDBNAME,
	"SELECT admin FROM users WHERE uid='$uid'");

    if (! $query_result) {
        $err = mysql_error();
        TBERROR("Database Error getting admin status for $uid: $err\n", 1);
    }

    $row = mysql_fetch_row($query_result);
    $admin  = $row[0];

    return $admin;
}

131 132 133 134
#
# Run a program as a user.
#
function SUEXEC($uid, $gid, $cmdandargs, $die) {
135
    global $TBSUEXEC_PATH;
136

137 138
    ignore_user_abort(1);

139 140
    $output = array();
    $retval = 0;
141
    $result = exec("$TBSUEXEC_PATH $uid $gid $cmdandargs",
142 143 144
		   $output, $retval);

    if ($retval) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
145
	$foo = "<XMP>\n";
146 147 148
        for ($i = 0; $i < count($output); $i++) {
	      $foo = "$foo $output[$i]";
	}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
149
        $foo = "$foo </XMP>\n";
150 151 152 153 154 155 156
	
	TBERROR("suexec failure. Cmd was \"$cmdandargs\". Error output:\n\n".
                "$foo", $die);
    }
    return $retval;
}

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
#
# Verify a URL.
#
function VERIFYURL($url) {
    global $HTTPTAG;

    if (strlen($url)) {
	if (strstr($url, " ")) {
	    USERERROR("URL ($url) is malformed; spaces are not allowed. ".
		      "Please go back and fix it up.", 1);
	}
	
	if (strcmp($HTTPTAG, substr($url, 0, strlen($HTTPTAG)))) {
	    USERERROR("URL ($url) must begin with $HTTPTAG. ".
		      "Please go back and fix it up.", 1);
	}
	$fp = @fopen($url, "r");
	if (! $fp) {
	    USERERROR("URL ($url) is not valid (cannot be accessed). ".
		      "Please go back and fix it up.", 1);
	}
	fclose($fp);
    }
    return 0;
}

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
#
# Get the last USERS node login for a user (or all users). If this fails,
# the let testbed ops know, but its not a fatal problem.
#
function LASTUSERSLOGIN($uid) {
    global $TBLIBEXEC_DIR;
    
    $output = array();
    $retval = 0;

    #
    # Either a specific UID or a list of all UIDs.
    #
    $uidarg = "";
    if ($uid) {
	$uidarg = "-u $uid";
    }
200

201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
    $cmdandargs = "$TBLIBEXEC_DIR/lastlogin $uidarg";

    $result = exec($cmdandargs, $output, $retval);

    if ($retval) {
      if (0) {
	$foo = "";
        for ($i = 0; $i < count($output); $i++) {
	      $foo = "$foo $output[$i]";
	}
	
	TBERROR("LASTUSERSLOGIN: ".
		"Cmd was \"$cmdandargs\". \n".
		"Error output:\n\n $foo\n", 0);
      }
        return 0;
    }
218 219 220 221 222
    $hashtable = array();

    #
    # In single user mode, return a hash of date, time, node.
    # 
223
    if ($uid) {
224 225 226 227 228 229 230 231 232
	if (! $output[0])
	    return 0;
	
	$parts = explode(" ", $output[0]);

	$hashtable["date"] = $parts[0];
	$hashtable["time"] = $parts[1];
	$hashtable["node_id"] = $parts[2];
	return $hashtable;
233
    }
234
    
235
    #
236
    # In all user mode, return a hash of hashes, indexed by uid.
237 238
    #
    for ($i = 0; $i < count($output); $i++) {
239 240
	$utable = array();
	$parts  = explode(" ", $output[$i]);
241

242 243 244 245 246
	$utable["date"] = $parts[1];
	$utable["time"] = $parts[2];
	$utable["node_id"] = $parts[3];	

	$hashtable["$parts[0]"] = $utable;
247 248
    }
    return $hashtable;
249
}
250

251 252 253 254
function LASTNODELOGIN($node)
{
}

255 256 257 258
#
# Beware empty spaces (cookies)!
# 
require("tbauth.php3");
259 260 261 262 263

#
# Okay, this is what checks the login and spits out the menu.
#
require("menu.php3");
264
?>