uid(); $returning = 1; } else { # # No uid, so must be new. # $returning = 0; } unset($addpubkeyargs); $ACCOUNTWARNING = "Before continuing, please make sure your username " . "reflects your normal login name. ". "Emulab accounts are not to be shared amongst users!"; $EMAILWARNING = "Before continuing, please make sure the email address you have ". "provided is current and non-pseudonymic. Redirections and anonymous ". "email addresses are not allowed."; # # Spit the form out using the array of data. # function SPITFORM($formfields, $returning, $errors) { global $TBDB_UIDLEN, $TBDB_PIDLEN, $TBDOCBASE, $WWWHOST; global $usr_keyfile, $FirstInitState; global $ACCOUNTWARNING, $EMAILWARNING; global $WIKISUPPORT, $WIKIHOME, $USERSELECTUIDS; PAGEHEADER("Start a New Testbed Project"); # # First initialization gets different text # if ($FirstInitState == "createproject") { echo "
Oops, please fix the following errors! | |
---|---|
$name: | $message |
Fields marked with * are required. |
- Please consult our security policies for information regarding passwords and email addresses.\n"; if (! $returning) { echo "
- If you want us to use your existing ssh public key, then please specify the path to your your identity.pub file. NOTE: We use the OpenSSH key format, which has a slightly different protocol 2 public key format than some of the commercial vendors such as SSH Communications. If you use one of these commercial vendors, then please upload the public key file and we will convert it for you.\n"; } echo "
In the meantime, as a new user of the Testbed you will receive a key via email. When you receive the message, please follow the instructions contained in the message on how to verify your account.\n"; } PAGEFOOTER(); return; } # # On first load, display a virgin form and exit. # if (! isset($submit)) { $defaults = array(); $defaults["proj_head_uid"] = ""; $defaults["usr_name"] = ""; $defaults["wikiname"] = ""; $defaults["usr_title"] = ""; $defaults["usr_affil"] = ""; $defaults["usr_affil_abbrev"] = ""; $defaults["usr_URL"] = "$HTTPTAG"; $defaults["usr_email"] = ""; $defaults["usr_addr"] = ""; $defaults["usr_addr2"] = ""; $defaults["usr_city"] = ""; $defaults["usr_state"] = ""; $defaults["usr_zip"] = ""; $defaults["usr_country"] = "USA"; $defaults["usr_phone"] = ""; $defaults["password1"] = ""; $defaults["password2"] = ""; $defaults["pid"] = ""; $defaults["proj_name"] = ""; $defaults["proj_URL"] = "$HTTPTAG"; $defaults["proj_public"] = "checked"; $defaults["proj_whynotpublic"] = ""; $defaults["proj_linked"] = "checked"; $defaults["proj_funders"] = ""; $defaults["proj_members"] = ""; $defaults["proj_pcs"] = ""; $defaults["proj_ronpcs"] = ""; $defaults["proj_plabpcs"] = ""; $defaults["proj_why"] = ""; if ($FirstInitState == "createproject") { $defaults["pid"] = "testbed"; $defaults["proj_pcs"] = "256"; $defaults["proj_members"] = "256"; $defaults["proj_funders"] = "none"; $defaults["proj_name"] = "Your Testbed Project"; $defaults["proj_why"] = "This project is used for testbed ". "administrators to develop and test new software. "; } SPITFORM($defaults, $returning, 0); PAGEFOOTER(); return; } # Form submitted. Make sure we have a formfields array. if (!isset($formfields)) { PAGEARGERROR("Invalid form arguments."); } #TBERROR("A\n\n" . print_r($formfields, TRUE), 0); # # Otherwise, must validate and redisplay if errors # $errors = array(); # # These fields are required! # if (! $returning) { if ($USERSELECTUIDS || $FirstInitState == "createproject") { if (!isset($formfields["proj_head_uid"]) || strcmp($formfields["proj_head_uid"], "") == 0) { $errors["Username"] = "Missing Field"; } elseif (!TBvalid_uid($formfields["proj_head_uid"])) { $errors["UserName"] = TBFieldErrorString(); } elseif (User::Lookup($formfields["proj_head_uid"]) || posix_getpwnam($formfields["proj_head_uid"])) { $errors["UserName"] = "Already in use. Pick another"; } } if (!isset($formfields["usr_title"]) || strcmp($formfields["usr_title"], "") == 0) { $errors["Job Title/Position"] = "Missing Field"; } elseif (! TBvalid_title($formfields["usr_title"])) { $errors["Job Title/Position"] = TBFieldErrorString(); } if (!isset($formfields["usr_name"]) || strcmp($formfields["usr_name"], "") == 0) { $errors["Full Name"] = "Missing Field"; } elseif (! TBvalid_usrname($formfields["usr_name"])) { $errors["Full Name"] = TBFieldErrorString(); } # Make sure user name has at least two tokens! $tokens = preg_split("/[\s]+/", $formfields["usr_name"], -1, PREG_SPLIT_NO_EMPTY); if (count($tokens) < 2) { $errors["Full Name"] = "Please provide a first and last name"; } if ($WIKISUPPORT) { if (!isset($formfields["wikiname"]) || strcmp($formfields["wikiname"], "") == 0) { $errors["WikiName"] = "Missing Field"; } elseif (! TBvalid_wikiname($formfields["wikiname"])) { $errors["WikiName"] = TBFieldErrorString(); } elseif (User::LookupByWikiName($formfields["wikiname"])) { $errors["WikiName"] = "Already in use. Pick another"; } } if (!isset($formfields["usr_affil"]) || strcmp($formfields["usr_affil"], "") == 0) { $errors["Affiliation Name"] = "Missing Field"; } elseif (! TBvalid_affiliation($formfields["usr_affil"])) { $errors["Affiliation Name"] = TBFieldErrorString(); } if (!isset($formfields["usr_affil_abbrev"]) || strcmp($formfields["usr_affil_abbrev"], "") == 0) { $errors["Affiliation Abbreviation"] = "Missing Field"; } elseif (! TBvalid_affiliation_abbreviation($formfields["usr_affil_abbrev"])) { $errors["Affiliation Name"] = TBFieldErrorString(); } if (!isset($formfields["usr_email"]) || strcmp($formfields["usr_email"], "") == 0) { $errors["Email Address"] = "Missing Field"; } elseif (! TBvalid_email($formfields["usr_email"])) { $errors["Email Address"] = TBFieldErrorString(); } elseif (User::LookupByEmail($formfields["usr_email"])) { # # Treat this error separate. Not allowed. # $errors["Email Address"] = "Already in use. Did you forget to login?"; } if (isset($formfields["usr_URL"]) && strcmp($formfields["usr_URL"], "") && strcmp($formfields["usr_URL"], $HTTPTAG) && ! CHECKURL($formfields["usr_URL"], $urlerror)) { $errors["Home Page URL"] = $urlerror; } if (!isset($formfields["usr_addr"]) || strcmp($formfields["usr_addr"], "") == 0) { $errors["Address 1"] = "Missing Field"; } elseif (! TBvalid_addr($formfields["usr_addr"])) { $errors["Address 1"] = TBFieldErrorString(); } # Optional if (isset($formfields["usr_addr2"]) && !TBvalid_addr($formfields["usr_addr2"])) { $errors["Address 2"] = TBFieldErrorString(); } if (!isset($formfields["usr_city"]) || strcmp($formfields["usr_city"], "") == 0) { $errors["City"] = "Missing Field"; } elseif (! TBvalid_city($formfields["usr_city"])) { $errors["City"] = TBFieldErrorString(); } if (!isset($formfields["usr_state"]) || strcmp($formfields["usr_state"], "") == 0) { $errors["State"] = "Missing Field"; } elseif (! TBvalid_state($formfields["usr_state"])) { $errors["State"] = TBFieldErrorString(); } if (!isset($formfields["usr_zip"]) || strcmp($formfields["usr_zip"], "") == 0) { $errors["ZIP/Postal Code"] = "Missing Field"; } elseif (! TBvalid_zip($formfields["usr_zip"])) { $errors["Zip/Postal Code"] = TBFieldErrorString(); } if (!isset($formfields["usr_country"]) || strcmp($formfields["usr_country"], "") == 0) { $errors["Country"] = "Missing Field"; } elseif (! TBvalid_country($formfields["usr_country"])) { $errors["Country"] = TBFieldErrorString(); } if (!isset($formfields["usr_phone"]) || strcmp($formfields["usr_phone"], "") == 0) { $errors["Phone #"] = "Missing Field"; } elseif (!TBvalid_phone($formfields["usr_phone"])) { $errors["Phone #"] = TBFieldErrorString(); } if (!isset($formfields["password1"]) || strcmp($formfields["password1"], "") == 0) { $errors["Password"] = "Missing Field"; } if (!isset($formfields["password2"]) || strcmp($formfields["password2"], "") == 0) { $errors["Confirm Password"] = "Missing Field"; } elseif (strcmp($formfields["password1"], $formfields["password2"])) { $errors["Confirm Password"] = "Does not match Password"; } elseif (! CHECKPASSWORD((($USERSELECTUIDS || $FirstInitState == "createproject") ? $formfields["proj_head_uid"] : "ignored"), $formfields["password1"], $formfields["usr_name"], $formfields["usr_email"], $checkerror)) { $errors["Password"] = "$checkerror"; } } if (!isset($formfields["pid"]) || strcmp($formfields["pid"], "") == 0) { $errors["Project Name"] = "Missing Field"; } else { if (!TBvalid_newpid($formfields["pid"])) { $errors["Project Name"] = TBFieldErrorString(); } elseif (Project::LookupByPid($formfields["pid"])) { $errors["Project Name"] = "Already in use. Select another"; } } if (!isset($formfields["proj_name"]) || strcmp($formfields["proj_name"], "") == 0) { $errors["Project Description"] = "Missing Field"; } elseif (! TBvalid_description($formfields["proj_name"])) { $errors["Project Description"] = TBFieldErrorString(); } if (!isset($formfields["proj_URL"]) || strcmp($formfields["proj_URL"], "") == 0 || strcmp($formfields["proj_URL"], $HTTPTAG) == 0) { $errors["Project URL"] = "Missing Field"; } elseif (! CHECKURL($formfields["proj_URL"], $urlerror)) { $errors["Project URL"] = $urlerror; } if (!isset($formfields["proj_funders"]) || strcmp($formfields["proj_funders"], "") == 0) { $errors["Funding Sources"] = "Missing Field"; } elseif (! TBvalid_description($formfields["proj_funders"])) { $errors["Funding Sources"] = TBFieldErrorString(); } if (!isset($formfields["proj_members"]) || strcmp($formfields["proj_members"], "") == 0) { $errors["#of Members"] = "Missing Field"; } elseif (! TBvalid_num_members($formfields["proj_members"])) { $errors["#of Members"] = TBFieldErrorString(); } if (!isset($formfields["proj_pcs"]) || strcmp($formfields["proj_pcs"], "") == 0) { $errors["#of PCs"] = "Missing Field"; } elseif (! TBvalid_num_pcs($formfields["proj_pcs"])) { $errors["#of PCs"] = TBFieldErrorString(); } if (isset($formfields["proj_plabpcs"]) && strcmp($formfields["proj_plabpcs"], "") && strcmp($formfields["proj_plabpcs"], "checked")) { $errors["Planetlab Access"] = "Bad Value"; } if (isset($formfields["proj_ronpcs"]) && strcmp($formfields["proj_ronpcs"], "") && strcmp($formfields["proj_ronpcs"], "checked")) { $errors["Ron Access"] = "Bad Value"; } if (!isset($formfields["proj_why"]) || strcmp($formfields["proj_why"], "") == 0) { $errors["How and Why?"] = "Missing Field"; } elseif (! TBvalid_why($formfields["proj_why"])) { $errors["How and Why?"] = TBFieldErrorString(); } if ((!isset($formfields["proj_public"]) || strcmp($formfields["proj_public"], "checked")) && (!isset($formfields["proj_whynotpublic"]) || strcmp($formfields["proj_whynotpublic"], "") == 0)) { $errors["Why Not Public?"] = "Missing Field"; } if (isset($formfields["proj_linked"]) && strcmp($formfields["proj_linked"], "") && strcmp($formfields["proj_linked"], "checked")) { $errors["Link to Us"] = "Bad Value"; } # Present these errors before we call out to do anything else. if (count($errors)) { SPITFORM($formfields, $returning, $errors); PAGEFOOTER(); return; } # # Create the User first, then the Project/Group. # Certain of these values must be escaped or otherwise sanitized. # if (!$returning) { $args = array(); $args["name"] = $formfields["usr_name"]; $args["email"] = $formfields["usr_email"]; $args["address"] = $formfields["usr_addr"]; $args["address2"] = $formfields["usr_addr2"]; $args["city"] = $formfields["usr_city"]; $args["state"] = $formfields["usr_state"]; $args["zip"] = $formfields["usr_zip"]; $args["country"] = $formfields["usr_country"]; $args["phone"] = $formfields["usr_phone"]; $args["shell"] = 'tcsh'; $args["title"] = $formfields["usr_title"]; $args["affiliation"] = $formfields["usr_affil"]; $args["affiliation_abbreviation"] = $formfields["usr_affil_abbrev"]; $args["password"] = $formfields["password1"]; if ($WIKISUPPORT) { $args["wikiname"] = $formfields["wikiname"]; } if (isset($formfields["usr_URL"]) && $formfields["usr_URL"] != $HTTPTAG && $formfields["usr_URL"] != "") { $args["URL"] = $formfields["usr_URL"]; } if ($USERSELECTUIDS || $FirstInitState == "createproject") { $args["login"] = $formfields["proj_head_uid"]; } # Backend verifies pubkey and returns error. if (isset($_FILES['usr_keyfile']) && $_FILES['usr_keyfile']['name'] != "" && $_FILES['usr_keyfile']['name'] != "none") { $localfile = $_FILES['usr_keyfile']['tmp_name']; $args["pubkey"] = file_get_contents($localfile); } # Just collect the user XML args here and pass the file to NewNewProject. # Underneath, newproj calls newuser with the XML file. # # Calling newuser down in Perl land makes creation of the leader account # and the project "atomic" from the user's point of view. This avoids a # problem when the DB is locked for daily backup: in newproject, the call # on NewNewUser would block and then unblock and get done; meanwhile the # PHP thread went away so we never returned here to call NewNewProject. # if (! ($newuser_xml = User::NewNewUserXML($args, $errors)) != 0) { $errors["Error Creating User XML"] = $error; TBERROR("B\n${error}\n\n" . print_r($args, TRUE), 0); SPITFORM($formfields, $returning, $errors); PAGEFOOTER(); return; } } # # Now for the new Project # $args = array(); if (isset($newuser_xml)) { $args["newuser_xml"] = $newuser_xml; } if ($returning) { # An existing, logged-in user is starting the project. $args["leader"] = $this_user->uid(); } $args["name"] = $formfields["pid"]; $args["short description"] = $formfields["proj_name"]; $args["URL"] = $formfields["proj_URL"]; $args["members"] = $formfields["proj_members"]; $args["num_pcs"] = $formfields["proj_pcs"]; $args["long description"] = $formfields["proj_why"]; $args["funders"] = $formfields["proj_funders"]; $args["whynotpublic"] = $formfields["proj_whynotpublic"]; if (!isset($formfields["proj_public"]) || $formfields["proj_public"] != "checked") { $args["public"] = 0; } else { $args["public"] = 1; } if (!isset($formfields["proj_linked"]) || $formfields["proj_linked"] != "checked") { $args["linkedtous"] = 0; } else { $args["linkedtous"] = 1; } if (isset($formfields["proj_plabpcs"]) && $formfields["proj_plabpcs"] == "checked") { $args["plab"] = 1; } if (isset($formfields["proj_ronpcs"]) && $formfields["proj_ronpcs"] == "checked") { $args["ron"] = 1; } if (! ($project = Project::NewNewProject($args, $error))) { $errors["Error Creating Project"] = $error; TBERROR("C\n${error}\n\n" . print_r($args, TRUE), 0); SPITFORM($formfields, $returning, $errors); PAGEFOOTER(); return; } # # Need to do some extra work for the first project; eventually move to backend # if ($FirstInitState) { $leader = $project->GetLeader(); $proj_head_uid = $leader->uid(); # Set up the management group (emulab-ops). Group::Initialize($proj_head_uid); # # Move to next phase. # $pid = $formfields["pid"]; TBSetFirstInitPid($pid); TBSetFirstInitState("approveproject"); header("Location: approveproject.php3?pid=$pid&approval=approve"); return; } # # Spit out a redirect so that the history does not include a post # in it. The back button skips over the post and to the form. # See above for conclusion. # header("Location: newproject.php3?finished=1"); ?>