newgroup.php3 6.7 KB
Newer Older
Leigh Stoller's avatar
Leigh Stoller committed
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2017 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
Leigh Stoller's avatar
Leigh Stoller committed
24 25 26 27 28
include("defs.php3");

#
# Only known and logged in users.
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
Leigh Stoller's avatar
Leigh Stoller committed
32 33

#
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
# Verify page arguments.
#
$optargs = OptionalPageArguments("project",    PAGEARG_PROJECT,
				 "submit",     PAGEARG_STRING,
				 "formfields", PAGEARG_ARRAY);
if (!isset($project)) {
    #
    # See what projects the uid can do this in.
    #
    $projlist = $this_user->ProjectAccessList($TB_PROJECT_MAKEGROUP);

    if (! count($projlist)) {
	USERERROR("You do not appear to be a member of any Projects in which ".
		  "you have permission to create new groups.", 1);
    }
49
}
50 51 52 53 54 55 56 57 58 59
else {
    #
    # Verify permission for specific project.
    #
    $pid = $project->pid();
    
    if (!$project->AccessCheck($this_user, $TB_PROJECT_MAKEGROUP)) {
	USERERROR("You do not have permission to create groups in ".
		  "project $pid!", 1);
    }
Leigh Stoller's avatar
Leigh Stoller committed
60 61
}

62 63 64 65 66
#
# Standard Testbed Header
#
PAGEHEADER("Create a Project Group");

Leigh Stoller's avatar
Leigh Stoller committed
67
#
68
# Spit the form out using the array of data. 
Leigh Stoller's avatar
Leigh Stoller committed
69
# 
70 71 72 73
function SPITFORM($formfields, $errors)
{
    global $project, $pid, $projlist;
    global $TBDB_GIDLEN, $TBDB_UIDLEN;
74
    global $WIKIDOCURL;
75 76 77 78 79 80 81 82 83 84 85 86 87

    if ($errors) {
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
              <tr>
                 <th align=center colspan=2>
                   <font size=+1 color=red>
                      &nbsp;Oops, please fix the following errors!&nbsp;
                   </font>
                 </td>
              </tr>\n";

	while (list ($name, $message) = each ($errors)) {
88 89
            # XSS prevention.
	    $message = CleanString($message);
90 91 92 93 94 95 96 97 98
	    echo "<tr>
                     <td align=right>
                       <font color=red>$name:&nbsp;</font></td>
                     <td align=left>
                       <font color=red>$message</font></td>
                  </tr>\n";
	}
	echo "</table><br>\n";
    }
99 100 101 102
    # XSS prevention.
    while (list ($key, $val) = each ($formfields)) {
	$formfields[$key] = CleanString($val);
    }
Leigh Stoller's avatar
Leigh Stoller committed
103

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
    echo "<br>
          <table align=center border=1> 
          <tr>
             <td align=center colspan=2>
                 <em>(Fields marked with * are required)</em>
             </td>
          </tr>\n";

    if (isset($project)) {
	$url = CreateURL("newgroup", $project);
	echo "<form action='$url' method=post>
	      <tr>
		  <td>* Project:</td>
		  <td class=left>
		      <input name=project type=readonly value='$pid'>
		  </td>
	      </tr>\n";
    }
    else {
	$url = CreateURL("newgroup");
	echo "<form action='$url' method=post>
	      <tr>
		  <td>*Select Project:</td>";
	echo "    <td><select name=project>";

	while (list($proj) = each($projlist)) {
	    echo "<option value='$proj'>$proj </option>\n";
	}

	echo "       </select>";
	echo "    </td>
	      </tr>\n";
    }
Leigh Stoller's avatar
Leigh Stoller committed
137

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    echo "<tr>
	      <td>*Group Name (no blanks, lowercase):</td>
	      <td class=left>
		  <input type=text 
			 name=\"formfields[group_id]\" 
			 value=\"" . $formfields["group_id"] . "\"
			 size=$TBDB_GIDLEN
			 maxlength=$TBDB_GIDLEN>
	      </td>
	  </tr>\n";

    echo "<tr>
	      <td>*Group Description:</td>
	      <td class=left>
		  <input type=text size=50
			 name=\"formfields[group_description]\"
			 value=\"" . $formfields["group_description"] . "\">
	      </td>
	  </tr>\n";

    echo "<tr>
	      <td>*Group Leader (Emulab userid):</td>
	      <td class=left>
		  <input type=text
			 name=\"formfields[group_leader]\"
			 value=\"" . $formfields["group_leader"] . "\"
			 size=$TBDB_UIDLEN maxlength=$TBDB_UIDLEN>
	      </td>
	  </tr>\n";

    echo "<tr>
              <td align=center colspan=2>
                  <b><input type=submit name=submit value=Submit></b>
              </td>
          </tr>\n";

    echo "</form>
          </table>\n";

    echo "<br><center>
178
	     Important <a href='$WIKIDOCURL/Groups#SECURITY'>
179
	     security issues</a> are discussed in the
180
	     <a href='$WIKIDOCURL/Groups'>Groups Tutorial</a>.
181
          </center>\n";
182 183
}

Leigh Stoller's avatar
Leigh Stoller committed
184
#
185 186 187 188 189 190 191
# Accumulate error reports for the user, e.g.
#    $errors["Key"] = "Msg";
# Required page args may need to be checked early.
$errors  = array();

#
# On first load, display a virgin form and exit.
Leigh Stoller's avatar
Leigh Stoller committed
192
#
193 194 195 196 197 198 199 200 201
if (!isset($submit)) {
    $defaults = array();
    $defaults["group_id"]	   = "";
    $defaults["group_description"] = "";
    $defaults["group_leader"]	   = $uid;

    SPITFORM($defaults, $errors);
    PAGEFOOTER();
    return;
Leigh Stoller's avatar
Leigh Stoller committed
202
}
203

Leigh Stoller's avatar
Leigh Stoller committed
204
#
205
# Build up argument array to pass along.
Leigh Stoller's avatar
Leigh Stoller committed
206
#
207
$args = array();
Leigh Stoller's avatar
Leigh Stoller committed
208

209 210 211
if (isset($formfields["project"]) &&
    $formfields["project"] != "none" && $formfields["project"] != "") {
    $args["project"]		= $formfields["project"];
Leigh Stoller's avatar
Leigh Stoller committed
212
}
213 214
if (isset($formfields["group_id"]) && $formfields["group_id"] != "") {
    $args["group_id"]	= $formfields["group_id"];
215 216 217 218
    # Check here, easier.
    if (! TBvalid_newgid($formfields["group_id"])) {
        $errors["group_id"] = $DBFieldErrstr;
    }
Leigh Stoller's avatar
Leigh Stoller committed
219
}
220 221 222 223 224 225
if (isset($formfields["group_description"]) && 
    $formfields["group_description"] != "") {
    $args["group_description"]	= $formfields["group_description"];
}
if (isset($formfields["group_leader"]) && $formfields["group_leader"] != "") {
    $args["group_leader"]	= $formfields["group_leader"];
226
}
Leigh Stoller's avatar
Leigh Stoller committed
227

228 229 230 231 232 233 234 235 236 237
#
# If any errors, respit the form with the current values and the
# error messages displayed. Iterate until happy.
# 
if (count($errors)) {
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    return;
}

238 239 240
$group_id = $formfields["group_id"];
###STARTBUSY("Creating project group $group_id.");
echo "<br>Creating project group $group_id.<br>\n";
Leigh Stoller's avatar
Leigh Stoller committed
241
flush();
242

243 244 245 246 247 248 249
if (! ($newgroup = Group::Create($project, $uid, $args, $errors))) {
    # Always respit the form so that the form fields are not lost.
    # I just hate it when that happens so lets not be guilty of it ourselves.
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    return;
}
Leigh Stoller's avatar
Leigh Stoller committed
250

251
###STOPBUSY();
252

253
echo "<center><h3>Done!</h3></center>\n";
254
PAGEREPLACE(CreateURL("showgroup", $newgroup));
255

256 257 258 259
#
# Standard Testbed Footer
# 
PAGEFOOTER();
Leigh Stoller's avatar
Leigh Stoller committed
260
?>