defs.php3.in 5.17 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
$TBAUTHCOOKIE   = "HashCookie";
26
$TBNAMECOOKIE   = "MyUidCookie";
27
$TBAUTHTIMEOUT  = 21600;
28

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

31 32 33 34 35 36 37 38 39 40
#
# Menu Formatting Stuff
#
# Color for the title on each page.
$TITLECOLOR     = "#E04050";
$BANNERCOLOR    = "#ABABE0";
$THISHOMEBASE   = "Emulab.Net";
$THISPROJECT    = "The Utah Network Testbed";

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

47 48 49 50 51
#
# Database constants and the like.
#
include("dbdefs.php3");

52 53 54 55 56 57 58 59 60 61 62 63 64
#
# 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
65
    global $TBMAIL_WWW, $TBMAIL_OPS, $TBMAILADDR;
66

67 68
    mail($TBMAIL_OPS,
         "TESTBED WEB ERROR REPORT",
69 70 71 72
         "\n".
         "$message\n\n".
         "Thanks,\n".
         "Testbed WWW\n",
73
         "From: $TBMAIL_OPS\n".
74
         "Errors-To: $TBMAIL_WWW");
75

Leigh B. Stoller's avatar
Leigh B. Stoller committed
76
    # Allow sendmail to run.
77
    sleep(1); 
78 79

    if ($death) {
80 81 82 83 84 85 86 87 88 89
	    echo "<h3><br><br>
        	  $message
	          <br>	
        	  </h3>";

	    echo "<p><p>
		  Could not continue. Please contact $TBMAILADDR\n";

	    PAGEFOOTER();
	    die("");
90 91 92
    }
    return 0;
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
93 94 95 96 97

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

Leigh B. Stoller's avatar
Leigh B. Stoller committed
100 101 102 103 104
    echo "<h3><br><br>
          $message
          <br>
          </h3>";

105
    echo "<p><p>
106
          Please contact $TBMAILADDR if you feel this message is an error.";
107

Leigh B. Stoller's avatar
Leigh B. Stoller committed
108
    if ($death) {
109
	PAGEFOOTER();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
110 111 112 113
        die("");
    }
}

114 115 116 117 118 119 120 121
#
# A form error.
#
function FORMERROR($field) {
    USERERROR("Missing field; ".
              "Please go back and fill out the \"$field\" field!", 1);
}

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
#
# 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;
}

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

148 149
    ignore_user_abort(1);

150 151
    $output = array();
    $retval = 0;
152
    $result = exec("$TBSUEXEC_PATH $uid $gid $cmdandargs",
153 154 155
		   $output, $retval);

    if ($retval) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
156
	$foo = "<XMP>\n";
157 158 159
        for ($i = 0; $i < count($output); $i++) {
	      $foo = "$foo $output[$i]";
	}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
160
        $foo = "$foo </XMP>\n";
161 162 163 164 165 166 167
	
	TBERROR("suexec failure. Cmd was \"$cmdandargs\". Error output:\n\n".
                "$foo", $die);
    }
    return $retval;
}

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
#
# 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;
}

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
#
# 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";
    }
    $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;
    }
    if ($uid) {
	return $output[0];
    }
231 232 233 234 235 236 237 238 239 240 241
    #
    # Convert to a hash table.
    #
    $hashtable = array();
    
    for ($i = 0; $i < count($output); $i++) {
	$parts = explode(" ", $output[$i]);

	$hashtable["$parts[0]"] = "$parts[1] $parts[2]";
    }
    return $hashtable;
242
}
243

244 245 246 247
#
# Beware empty spaces (cookies)!
# 
require("tbauth.php3");
248 249 250 251 252

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