/** * Defined by Zend_Validate_Interface * * Returns true if and only if $value contains a valid UUID * * @param string $value * * @return boolean */ public function isValid($value) { $value = (string) $value; $this->_value = $value; // check if string is empty if (!strlen($value)) { $this->_error(self::STRING_EMPTY); return false; } if (function_exists('uuid_is_valid') && !uuid_is_valid($value)) { $this->_error(self::NOT_UUID); return false; } // check length if (strlen($value) !== 36) { $this->_error(self::NOT_UUID); return false; } // are there some invalid characters $pattern = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i'; if (!preg_match($pattern, $value)) { $this->_error(self::NOT_UUID); return false; } return true; }
require_once "pa_client.php"; $user = geni_loadUser(); if (!isset($user) || is_null($user) || !$user->isActive()) { relative_redirect('home.php'); } include "tool-lookupids.php"; show_header('GENI Portal: Projects'); include "tool-breadcrumbs.php"; if (!isset($project)) { $project = "new"; $isnew = true; print "<h1>NEW GENI Project</h1>\n"; } else { $isnew = false; $leadid = $project[PA_PROJECT_TABLE_FIELDNAME::LEAD_ID]; if (!uuid_is_valid($leadid)) { error_log("edit-project: invalid leadid from DB for project {$project_id}"); exit; } $lead = $user->fetchMember($leadid); $leadname = $lead->prettyName(); $leademail = $lead->email(); print "<h1>Edit GENI Project: " . "<i>" . $project[PA_PROJECT_TABLE_FIELDNAME::PROJECT_NAME] . "</i>" . "</h1>\n"; } class ProjectField { function __construct($field, $pretty_name, $enabled, $required) { $this->field = $field; $this->pretty_name = $pretty_name; $this->enabled = $enabled;
function cmp($a, $b) { return strcmp(strtolower($a['slice_name']), strtolower($b['slice_name'])); } usort($lead_slices, "cmp"); usort($nonlead_slices, "cmp"); if (count($lead_slices) > 0) { print "<h5>Slices I own</h5>"; make_slice_table($lead_slices); } if (count($nonlead_slices) > 0) { print "<h5>Slices I don't own</h5>"; make_slice_table($nonlead_slices); } } else { if (isset($project_id) && uuid_is_valid($project_id)) { print "<p><i>You do not have access to any slices in this project.</i></p>"; } else { print "<p><i>You do not have access to any slices.</i></p>"; } } function make_slice_table($slicelist) { global $user; print "<div class='tablecontainer'>"; print "<table class='slicetable'>"; print "<tr><th>Name</th>"; print "<th>Project</th>"; print "<th>Owner</th>"; print "<th>Expiration</th>"; print "<th>Next Resource <br> Expiration</th>";
} else { if ($project_id != $slice_project_id) { error_log($script . ": slice_id {$slice_id} has project id {$slice_project_id} != REQUEST project_id {$project_id}"); } } } } else { if ($slice_id != '') { error_log($script . ": invalid slice_id from REQUEST"); $slice_id = "none"; } } } if (array_key_exists("member_id", $_REQUEST)) { $member_id = $_REQUEST['member_id']; if (uuid_is_valid($member_id)) { $member = $user->fetchMember($member_id); $member_name = $member->prettyName(); } else { if ($member_id != '') { error_log($script . ": invalid member_id from REQUEST"); $member_id = "none"; } } } if (array_key_exists("rspec_id", $_REQUEST)) { $rspec_id = $_REQUEST['rspec_id']; $rspec = fetchRSpecById($rspec_id); if (is_null($rspec)) { if ($rspec_id != '') { error_log($script . ": invalid rspec_id {$rspec_id} from REQUEST");
if (strlen($name) > 32) { error_log("do-edit-project: project name '{$name}' too long"); relative_redirect('error-text.php?error=' . urlencode("Project Name '{$name}' is too long - use at most 32 characters.")); } else { if (!is_valid_project_name($name)) { error_log("do-edit-project: project name '{$name}' invalid"); relative_redirect('error-text.php?error=' . urlencode("Project Name '{$name}' is invalid: Use at most 32 alphanumeric characters or hyphen or underscore. No leading hyphen or underscore. ")); } } } } // Re-check authorization? // Auto? // Ensure project name is unique?! $project_id = create_project($sa_url, $user, $name, $lead_id, $purpose, $expiration); if ($project_id == "-1" || !uuid_is_valid($project_id)) { error_log("do-edit-project create_project got project_id {$project_id}"); $result = "Error"; } else { $result = "New"; } // print "Created project, got ID: $project_id<.br/>\n"; // Return on error? } else { // error_log("about to update project"); if (!$user->isAllowed(PA_ACTION::UPDATE_PROJECT, CS_CONTEXT_TYPE::PROJECT, $project_id)) { error_log("Non privileged user " . $user->urn . " tried to update project " . $project_id); relative_redirect('home.php'); } // FIXME: Diff new vals from old? // If this fails, message_handler currently redirects to an error page
function removeGroup($project_id, $group_name, $user) { if (!isset($project_id) || $project_id == "-1" || !uuid_is_valid($project_id)) { error_log("iRODS removeGroup: not a valid project ID. Nothing to do. {$project_id}"); return -1; } if (!isset($group_name) || is_null($group_name) || $group_name === '') { error_log("iRODS removeGroup: not a valid group name. Nothing to do. {$project_id}, {$group_name}"); return -1; } error_log("iRODS removeGroup {$group_name}"); global $irods_url; global $portal_irods_user; global $portal_irods_pw; global $irods_cert; $removed = -1; // -1=Error, 0=Success, 1=Already gone try { $rmstruct = doRESTCall($irods_url . IRODS_REMOVE_USER_URI1 . $group_name, $portal_irods_user, $portal_irods_pw, "DELETE", "", "", $irods_cert); // look for (\r or \n or \r\n){2} and move past that preg_match("/(\r|\n|\r\n){2}([^\r\n].+)\$/", $rmstruct, $m); if (!array_key_exists(2, $m)) { error_log("iRODS removeGroup: Malformed DELETE result from iRODS - error? Got: " . $rmstruct); throw new Exception("Failed to remove iRODS group - server error: " . $rmstruct); } // FIXME: Comment this out when ready error_log("DELETE result content: " . $m[2]); $rmjson = json_decode($m[2], true); // FIXME: Comment this out when ready error_log("remove group result: " . print_r($rmjson, true)); if (is_array($rmjson)) { $status = null; $msg = null; $groupCmdStatus = null; if (array_key_exists("status", $rmjson)) { $status = $rmjson["status"]; // Return true = 0 if removed the group, -1 on error if ($status == IRODS_STATUS_ERROR) { $removed = -1; } elseif ($status == IRODS_STATUS_SUCCESS) { $removed = 0; } } if (array_key_exists("message", $rmjson)) { $msg = $rmjson["message"]; // error_log("removeGroup result: '$msg'"); } // Mike C says delete when the group doesn't exist returns SUCCESS if (array_key_exists(IRODS_USER_GROUP_COMMAND_STATUS, $rmjson)) { $groupCmdStatus = $rmjson[IRODS_USER_GROUP_COMMAND_STATUS]; if ($groupCmdStatus != IRODS_STATUS_SUCCESS) { if ($groupCmdStatus === IRODS_STATUS_BAD_GROUP) { error_log("iRODS: group {$group_name} not there to delete. ({$groupCmdStatus}: '{$msg}')"); $removed = 1; } else { error_log("iRODS failed to remove group {$group_name}: {$groupCmdStatus}: '{$msg}'"); } } } elseif ($removed === -1) { error_log("iRODS failed to remove group {$group_name}: '{$msg}'"); } } else { $removed = -1; error_log("iRODS malformed return from removeGroup: " . print_r($rmjson, true)); } } catch (Exception $e) { error_log("Error doing iRODS delete to remove group: " . $e->getMessage()); $removed = -1; } // Return 0 if removed the group, -1 on error, 1 if no such group return $removed; }
/** * @brief Test an UUID to see if it is valid * * @param string $uuid The UUID * @return bool True if the UUID is valid. */ public function test($uuid) { return \uuid_is_valid($uuid); }