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

8 9 10
# Overridden by the defs file!
$TBMAINSITE     = 0;

11 12 13 14 15
#
# Include configure selected definitions.
#
include("$WWWDEFS"."-defs.php3");

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

24
$TBPROJ_DIR     = "/proj";
25
$TBUSER_DIR	= "/users";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
26
$TBNSSUBDIR     = "nsdir";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
27

28 29
$TBAUTHCOOKIE   = "HashCookie" . $TBCOOKIESUFFIX;
$TBNAMECOOKIE   = "MyUidCookie" . $TBCOOKIESUFFIX;
30
$TBAUTHTIMEOUT  = 21600;
31

32 33
$HTTPTAG        = "http://";

34
#
35 36 37
# 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 ...
# 
38 39
$TBMAILADDR     = "<a href=\"mailto:$TBMAILADDR_OPS\">
                      Testbed Operations ($TBMAILADDR_OPS)</a>";
40

41 42 43 44 45
#
# Database constants and the like.
#
include("dbdefs.php3");

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

#
# 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.
#
58
function TBERROR ($message, $death, $xmp = 0) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
59
    global $TBMAIL_WWW, $TBMAIL_OPS, $TBMAILADDR;
60

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

Leigh B. Stoller's avatar
Leigh B. Stoller committed
70
    # Allow sendmail to run.
71 72
    sleep(1);
    
73
    if ($death) {
74 75 76
	if ($xmp)
	    $message = "<XMP>$message</XMP>\n";
	
77
            $msg = "<font size=+1><br>
78 79
                    $message
	            <br>	
80
        	    </font>
81 82 83 84
                    <p><p>
		    Could not continue. Please contact $TBMAILADDR\n";

	    PAGEERROR($msg);
85 86 87
    }
    return 0;
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
88 89 90 91 92

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

95
    $msg = "<font size=+1><br>
96 97
            $message
            <br>	
98
      	    </font>
99 100
            <p><p>
            Please contact $TBMAILADDR if you feel this message is an error.";
101

Leigh B. Stoller's avatar
Leigh B. Stoller committed
102
    if ($death) {
103
	PAGEERROR($msg);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
104
    }
105 106
    else
        echo "$msg\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
107 108
}

109 110 111 112 113 114 115 116
#
# A form error.
#
function FORMERROR($field) {
    USERERROR("Missing field; ".
              "Please go back and fill out the \"$field\" field!", 1);
}

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
#
# 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;
}

137 138 139 140
#
# Run a program as a user.
#
function SUEXEC($uid, $gid, $cmdandargs, $die) {
141
    global $TBSUEXEC_PATH;
142

143 144
    ignore_user_abort(1);

145 146
    $output = array();
    $retval = 0;
147
    $result = exec("$TBSUEXEC_PATH $uid $gid $cmdandargs",
148 149 150
		   $output, $retval);

    if ($retval) {
151
	$foo = "";
152 153 154 155
        for ($i = 0; $i < count($output); $i++) {
	      $foo = "$foo $output[$i]";
	}
	
156 157 158
	TBERROR("SUEXEC failure: '$cmdandargs'\n".
		"Error output:\n\n".
                "$foo", $die, 1);
159 160 161 162
    }
    return $retval;
}

163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
#
# 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);
	}
179
	$fp = fopen($url, "r");
180 181 182 183 184 185 186 187 188
	if (! $fp) {
	    USERERROR("URL ($url) is not valid (cannot be accessed). ".
		      "Please go back and fix it up.", 1);
	}
	fclose($fp);
    }
    return 0;
}

189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
#
# Verify a URL.
#
function CHECKURL($url, &$error) {
    global $HTTPTAG;

    if (strlen($url)) {
	if (strstr($url, " ")) {
	    $error = "URL is malformed; spaces are not allowed!";
	    return 0;
	}
	
	if (strcmp($HTTPTAG, substr($url, 0, strlen($HTTPTAG)))) {
	    $error = "URL is malformed; must begin with $HTTPTAG!";
	    return 0;
	}
	
	$fp = @fopen($url, "r");
	if (! $fp) {
	    $error = "URL is not valid; Cannot be accessed!";
	    return 0;
	}
	fclose($fp);
    }
    return 1;
}

#
# Check a password.
#
function CHECKPASSWORD($uid, $password, $name, $email, &$error)
{
    global $TBCHKPASS_PATH;
    
    $mypipe =
	popen(escapeshellcmd("$TBCHKPASS_PATH $password $uid '$name:$email'"),
	      "w+");
    
    if ($mypipe) { 
        $retval=fgets($mypipe, 1024);
        if (strcmp($retval,"ok\n") != 0) {
	    $error = "$retval";
	    return 0;
	}
	return 1;
    }
    TBERROR("Checkpass Failure! Returned '$mypipe'.\n\n".
	    "$TBCHKPASS_PATH $password $uid '$name:$email'", 1);
}

239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
#
# 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";
    }
256

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
    $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;
    }
274 275 276 277 278
    $hashtable = array();

    #
    # In single user mode, return a hash of date, time, node.
    # 
279
    if ($uid) {
280 281 282 283 284 285 286 287 288
	if (! $output[0])
	    return 0;
	
	$parts = explode(" ", $output[0]);

	$hashtable["date"] = $parts[0];
	$hashtable["time"] = $parts[1];
	$hashtable["node_id"] = $parts[2];
	return $hashtable;
289
    }
290
    
291
    #
292
    # In all user mode, return a hash of hashes, indexed by uid.
293 294
    #
    for ($i = 0; $i < count($output); $i++) {
295 296
	$utable = array();
	$parts  = explode(" ", $output[$i]);
297

298 299 300 301 302
	$utable["date"] = $parts[1];
	$utable["time"] = $parts[2];
	$utable["node_id"] = $parts[3];	

	$hashtable["$parts[0]"] = $utable;
303 304
    }
    return $hashtable;
305
}
306

307 308 309 310
function LASTNODELOGIN($node)
{
}

311 312 313 314
#
# Beware empty spaces (cookies)!
# 
require("tbauth.php3");
315 316 317 318 319

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