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

11 12 13 14 15 16
$TBMAILADDR_OPS		= "@TBOPSEMAIL_NOSLASH@";
$TBMAILADDR_WWW		= "@TBWWWEMAIL_NOSLASH@";
$TBMAILADDR_APPROVAL	= "@TBAPPROVALEMAIL_NOSLASH@";
$TBMAILADDR_LOGS	= "@TBLOGSEMAIL_NOSLASH@";
$TBMAILADDR_AUDIT	= "@TBAUDITEMAIL_NOSLASH@";

17 18 19
# Can override this in the -defs file. 
$TBAUTHTIMEOUT  = 21600;

20 21 22
# Overridden by the defs file!
$TBMAINSITE     = 0;

23 24 25 26 27
#
# Include configure selected definitions.
#
include("$WWWDEFS"."-defs.php3");

Leigh B. Stoller's avatar
Leigh B. Stoller committed
28 29
$TBWWW_DIR	= "$TBDIR"."www/";
$TBBIN_DIR	= "$TBDIR"."bin/";
30
$TBETC_DIR	= "$TBDIR"."etc/";
31 32 33
$TBLIBEXEC_DIR	= "$TBDIR"."libexec/";
$TBSUEXEC_PATH  = "$TBLIBEXEC_DIR/suexec";
$TBCHKPASS_PATH = "$TBLIBEXEC_DIR/checkpass";
34
$TBCSLOGINS     = "$TBETC_DIR/cslogins";
35

36 37
#
# Hardcoded check against $WWWHOST, to prevent anyone from accidentally setting
38
# $TBMAINSITE when it should not be
39 40 41 42 43
#
if ($WWWHOST != "www.emulab.net") {
    $TBMAINSITE = 0;
}

44
$TBPROJ_DIR     = "/proj";
45
$TBUSER_DIR	= "/users";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
46
$TBNSSUBDIR     = "nsdir";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
47

48 49
$TBAUTHCOOKIE   = "HashCookie" . $TBCOOKIESUFFIX;
$TBNAMECOOKIE   = "MyUidCookie" . $TBCOOKIESUFFIX;
50

51 52
$HTTPTAG        = "http://";

53 54 55 56 57 58
$TBMAIL_OPS		= "Testbed Ops <$TBMAILADDR_OPS>";
$TBMAIL_WWW		= "Testbed WWW <$TBMAILADDR_WWW>";
$TBMAIL_APPROVAL	= "Testbed Approval <$TBMAILADDR_APPROVAL>";
$TBMAIL_LOGS		= "Testbed Logs <$TBMAILADDR_LOGS>";
$TBMAIL_AUDIT		= "Testbed Audit <$TBMAILADDR_AUDIT>";

59
#
60 61 62
# 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 ...
# 
63 64
$TBMAILADDR     = "<a href=\"mailto:$TBMAILADDR_OPS\">
                      Testbed Operations ($TBMAILADDR_OPS)</a>";
65

66 67 68
# So subscripts always know ...
putenv("HTTP_SCRIPT=1");

69 70 71 72 73
#
# Database constants and the like.
#
include("dbdefs.php3");

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#
# Wrap up the mail function so we can prepend a tag to the subject
# line that indicates what testbed. Useful when multiple testbed
# email to the same list.
#
# 
function TBMAIL($to, $subject, $message, $headers = 0)
{
    global $THISHOMEBASE;

    $subject = strtoupper($THISHOMEBASE) . ": $subject";

    if ($headers)
	    return mail($to, $subject, $message, $headers);
    else
	    return mail($to, $subject, $message);
}

92 93 94 95 96
#
# 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.
#
97
function TBERROR ($message, $death, $xmp = 0) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
98
    global $TBMAIL_WWW, $TBMAIL_OPS, $TBMAILADDR;
99

100 101
    TBMAIL($TBMAIL_OPS,
         "WEB ERROR REPORT",
102 103 104 105
         "\n".
         "$message\n\n".
         "Thanks,\n".
         "Testbed WWW\n",
106
         "From: $TBMAIL_OPS\n".
107
         "Errors-To: $TBMAIL_WWW");
108

109
    if ($death) {
110 111 112
	if ($xmp)
	    $message = "<XMP>$message</XMP>\n";
	
113
            $msg = "<font size=+1><br>
114 115
                    $message
	            <br>	
116
        	    </font>
117
                    <p><p><p>
118 119 120
		    Could not continue. Please contact $TBMAILADDR\n";

	    PAGEERROR($msg);
121 122 123
    }
    return 0;
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
124 125 126 127 128

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

131
    $msg = "<font size=+1><br>
132 133
            $message
            <br>	
134
      	    </font>
135 136 137 138
            <br><br><br><br>
            <font size=-1>
            Please contact $TBMAILADDR if you feel this message is an error.
            </font>\n";
139

Leigh B. Stoller's avatar
Leigh B. Stoller committed
140
    if ($death) {
141
	PAGEERROR($msg);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
142
    }
143 144
    else
        echo "$msg\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
145 146
}

147 148 149 150 151 152 153 154
#
# A form error.
#
function FORMERROR($field) {
    USERERROR("Missing field; ".
              "Please go back and fill out the \"$field\" field!", 1);
}

155 156 157 158
#
# Run a program as a user.
#
function SUEXEC($uid, $gid, $cmdandargs, $die) {
159
    global $TBSUEXEC_PATH;
160

161 162
    ignore_user_abort(1);

163 164
    $output = array();
    $retval = 0;
165
    $result = exec("$TBSUEXEC_PATH $uid $gid $cmdandargs",
166 167 168
		   $output, $retval);

    if ($retval) {
169 170 171 172 173 174 175 176
	$foo = "SUEXEC failure: '$uid/$gid $cmdandargs'";
	    
	if (count($output)) {
	    $foo = "$foo\nError output:\n\n";
	    
	    for ($i = 0; $i < count($output); $i++) {
		$foo .= "$output[$i]\n";
	    }
177 178
	}
	
179
	TBERROR($foo, $die, 1);
180 181 182 183
    }
    return $retval;
}

184 185 186
function ADDPUBKEY($uid, $cmdandargs) {
    global $TBSUEXEC_PATH;

187 188 189 190 191 192 193 194 195 196
    #
    # Complication. User might not have an actual account if setting or
    # changing his own pubkeys. webonly, unapproved, and unverified users
    # can still muck with their personal info. So, just invoke as user
    # nobody. We will get audit email in case we need to track what has
    # happened. 
    #
    if (! HASREALACCOUNT($uid)) {
	$uid = "nobody";
    }
197
    return SUEXEC($uid, "nobody", $cmdandargs, 0);
198 199
}

200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
#
# 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;
	}
216

217 218
	$fp = @fopen($url, "r");
	if (! $fp) {
219
	    # Check to see if it was a redirect, in which case its OK
220 221 222 223 224 225 226 227 228 229 230
	    for ($i = 0; $i < count($http_response_header); $i++) {
		if (!strcmp("Location:", substr($http_response_header[$i],0,9))) {
		    $is_redirect = 1;
		}
	    }
	    if (!$is_redirect) {
		$error = "URL is not valid; Cannot be accessed!";
		return 0;
	    }
	} else {
	    fclose($fp);
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
	}
    }
    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);
}

259 260 261 262
function LASTNODELOGIN($node)
{
}

263 264 265 266
#
# Beware empty spaces (cookies)!
# 
require("tbauth.php3");
267 268 269 270 271

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