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

10 11 12
# Overridden by the defs file!
$TBMAINSITE     = 0;

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

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

26 27 28 29 30 31 32 33
#
# Hardcoded check against $WWWHOST, to prevent anyone from accidentally setting
# $TBMAINSITE when it shouldn't be
#
if ($WWWHOST != "www.emulab.net") {
    $TBMAINSITE = 0;
}

34
$TBPROJ_DIR     = "/proj";
35
$TBUSER_DIR	= "/users";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
36
$TBNSSUBDIR     = "nsdir";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
37

38 39
$TBAUTHCOOKIE   = "HashCookie" . $TBCOOKIESUFFIX;
$TBNAMECOOKIE   = "MyUidCookie" . $TBCOOKIESUFFIX;
40
$TBAUTHTIMEOUT  = 21600;
41

42 43
$HTTPTAG        = "http://";

44
#
45 46 47
# 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 ...
# 
48 49
$TBMAILADDR     = "<a href=\"mailto:$TBMAILADDR_OPS\">
                      Testbed Operations ($TBMAILADDR_OPS)</a>";
50

51 52 53 54 55
#
# Database constants and the like.
#
include("dbdefs.php3");

56 57 58 59
#
# Generate the KEY from a name
#
function GENKEY ($name) {
60
    return crypt("TB_"."$name"."_USR", strlen($name) + 13);
61 62
}

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#
# 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);
}

81 82 83 84 85
#
# 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.
#
86
function TBERROR ($message, $death, $xmp = 0) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
87
    global $TBMAIL_WWW, $TBMAIL_OPS, $TBMAILADDR;
88

89 90
    TBMAIL($TBMAIL_OPS,
         "WEB ERROR REPORT",
91 92 93 94
         "\n".
         "$message\n\n".
         "Thanks,\n".
         "Testbed WWW\n",
95
         "From: $TBMAIL_OPS\n".
96
         "Errors-To: $TBMAIL_WWW");
97

Leigh B. Stoller's avatar
Leigh B. Stoller committed
98
    # Allow sendmail to run.
99 100
    sleep(1);
    
101
    if ($death) {
102 103 104
	if ($xmp)
	    $message = "<XMP>$message</XMP>\n";
	
105
            $msg = "<font size=+1><br>
106 107
                    $message
	            <br>	
108
        	    </font>
109 110 111 112
                    <p><p>
		    Could not continue. Please contact $TBMAILADDR\n";

	    PAGEERROR($msg);
113 114 115
    }
    return 0;
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
116 117 118 119 120

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

123
    $msg = "<font size=+1><br>
124 125
            $message
            <br>	
126
      	    </font>
127 128
            <p><p>
            Please contact $TBMAILADDR if you feel this message is an error.";
129

Leigh B. Stoller's avatar
Leigh B. Stoller committed
130
    if ($death) {
131
	PAGEERROR($msg);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
132
    }
133 134
    else
        echo "$msg\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
135 136
}

137 138 139 140 141 142 143 144
#
# A form error.
#
function FORMERROR($field) {
    USERERROR("Missing field; ".
              "Please go back and fill out the \"$field\" field!", 1);
}

145 146 147 148
#
# Run a program as a user.
#
function SUEXEC($uid, $gid, $cmdandargs, $die) {
149
    global $TBSUEXEC_PATH;
150

151 152
    ignore_user_abort(1);

153 154
    $output = array();
    $retval = 0;
155
    $result = exec("$TBSUEXEC_PATH $uid $gid $cmdandargs",
156 157 158
		   $output, $retval);

    if ($retval) {
159
	$foo = "";
160 161 162 163
        for ($i = 0; $i < count($output); $i++) {
	      $foo = "$foo $output[$i]";
	}
	
164 165 166
	TBERROR("SUEXEC failure: '$cmdandargs'\n".
		"Error output:\n\n".
                "$foo", $die, 1);
167 168 169 170
    }
    return $retval;
}

171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
#
# 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);
	}
187
	$fp = fopen($url, "r");
188 189 190 191 192 193 194 195 196
	if (! $fp) {
	    USERERROR("URL ($url) is not valid (cannot be accessed). ".
		      "Please go back and fix it up.", 1);
	}
	fclose($fp);
    }
    return 0;
}

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 239 240 241 242 243 244 245 246
#
# 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);
}

247 248 249 250
function LASTNODELOGIN($node)
{
}

251 252 253 254
#
# Beware empty spaces (cookies)!
# 
require("tbauth.php3");
255 256 257 258 259

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