{ header('HTTP/1.1 404 Not Found'); print 'No slice id specified.'; exit; } if (!count($_GET)) { // No parameters. Return an error result? // For now, return nothing. no_slice_error(); } $slice = null; include "tool-lookupids.php"; if (is_null($slice) || $slice == '') { no_slice_error(); } if (isset($slice_expired) && convert_boolean($slice_expired)) { if (!isset($slice_name)) { $slice_name = ""; } $_SESSION['lasterror'] = "Slice " . $slice_name . " is expired."; relative_redirect('dashboard.php#slices'); } if (!$user->isAllowed(SA_ACTION::GET_SLICE_CREDENTIAL, CS_CONTEXT_TYPE::SLICE, $slice_id)) { relative_redirect('home.php'); } // TODO: Pass expiration to slicecred.py $outside_key = db_fetch_outside_private_key_cert($user->account_id); if (!$outside_key) { include "header.php"; show_header('GENI Portal: Slices'); include "tool-breadcrumbs.php";
} // FIXME: hardcoded path $download_url = 'https://' . $_SERVER['SERVER_NAME'] . '/secure/kmcert.php?close=1'; $download_text = 'Create and download your certificate'; if ($has_certificate) { $download_text = 'Download your certificate'; } /* --------- PROJECTS ---------- */ $all_project_ids = get_projects_for_member($sa_url, $user, $user->account_id, true); $num_projects = count($all_project_ids); $project_ids = array(); // Filter out expired projects if ($num_projects > 0) { $projects = lookup_project_details($sa_url, $user, $all_project_ids); foreach ($projects as $proj) { if (!convert_boolean($proj[PA_PROJECT_TABLE_FIELDNAME::EXPIRED])) { $project_ids[] = $proj[PA_PROJECT_TABLE_FIELDNAME::PROJECT_ID]; } } } // Update the count to only the active projects $num_projects = count($project_ids); $is_project_lead = $user->isAllowed(PA_ACTION::CREATE_PROJECT, CS_CONTEXT_TYPE::RESOURCE, null); if ($num_projects == 0) { // warn that the user has no projects $warn = '<p class="warn">You are not a member of any projects.' . ' No default project can be chosen unless you'; if ($is_project_lead) { $warn .= ' <button onClick="window.location=\'edit-project.php\'"><b>create a project</b></button> or'; } $warn .= ' <button onClick="window.location=\'join-project.php\'"><b>join a project</b></button>.</p>'; $warnings22[] = $warn;
function query_sliverstatus($user, $ams, $sa_url, $slice, $slice_id) { // Takes an arg am_id which may have multiple values. Each is treated // as the ID from the DB of an AM which should be queried // If no such arg is given, then query the DB and query all registered AMs if (!isset($ams) || is_null($ams) || count($ams) <= 0) { // Didnt get an array of AMs if (!isset($am) || is_null($am)) { // Nor a single am $ams = get_services_of_type(SR_SERVICE_TYPE::AGGREGATE_MANAGER); } else { $ams = array(); $ams[] = $am; } } if (!isset($ams) || is_null($ams) || count($ams) <= 0) { error_log("Found no AMs for query-sliverstatus!"); $slivers_output = "No AMs registered."; } if (convert_boolean($slice['expired'])) { $msg = "Slice is expired"; $good = false; $obj = array(); } else { $slivers_output = ""; // Get the slice credential from the SA $slice_credential = get_slice_credential($sa_url, $user, $slice_id); // Get the slice URN via the SA $slice_urn = $slice[SA_ARGUMENT::SLICE_URN]; $am_urls = array(); foreach ($ams as $am) { if (is_array($am)) { if (array_key_exists(SR_TABLE_FIELDNAME::SERVICE_URL, $am)) { $am_url = $am[SR_TABLE_FIELDNAME::SERVICE_URL]; } else { error_log("Malformed array of AM URLs?"); continue; } } else { $am_url = $am; } $am_urls[] = $am_url; } $retVal = sliver_status($am_urls, $user, $slice_credential, $slice_urn); $good = FALSE; if (!is_null($retVal) && count($retVal) == 2) { $msg = $retVal[0]; $obj = $retVal[1]; $good = TRUE; } elseif (count($retVal) == 1) { $msg = $retVal; $obj[$am_url] = ""; } else { $msg = "Call to sliver_status() FAILed"; $obj = array(); } } $retVal2 = array(); $retVal2[] = $msg; $retVal2[] = $obj; $retVal2[] = $good; return $retVal2; }
print "<script type='text/javascript'>"; print "\$(document).ready(function(){"; print 'update_selector($("#projectfilterswitch"), "-EXPIRED-PROJECTS-");'; print 'switch_to_card("#projects");'; print 'update_projects();'; print "});"; print "</script>"; } make_navigation_tabs(); if (get_preference($user->urn(), "homepage_view") == "cards") { // Get the user's unexpired slices $unexpired_slices = array(); foreach ($slice_objects as $slice) { $slice_id = $slice[SA_SLICE_TABLE_FIELDNAME::SLICE_ID]; $expired = $slice[SA_SLICE_TABLE_FIELDNAME::EXPIRED]; if (!convert_boolean($expired)) { $unexpired_slices[$slice_id] = $slice; } } $slice_objects = $unexpired_slices; // Get all of the slice owner names $slice_owner_names = array(); if (count($slice_objects) > 0) { $slice_owner_names = lookup_member_names_for_rows($ma_url, $user, $slice_objects, SA_SLICE_TABLE_FIELDNAME::OWNER_ID); } $user_id = $user->account_id; $project_slice_counts = array(); $slice_boxes = ''; // Make slice box and get slice counts for making the project boxes foreach ($slice_objects as $slice) { // Get all the basic slice info for making the slice box
function list_slice($slice, $user) { global $project_objects, $slice_owner_names; global $base_url, $slice_base_url, $listres_base_url, $resource_base_url; global $delete_sliver_base_url; global $gemini_base_url, $labwiki_base_url; global $disabled, $jfed_button_start, $jfed_button_part2; global $sa_url, $user; global $portal_max_slice_renewal_days; $slice_id = $slice[SA_SLICE_TABLE_FIELDNAME::SLICE_ID]; $slice_urn = $slice[SA_ARGUMENT::SLICE_URN]; $slice_expired = false; if (array_key_exists(SA_SLICE_TABLE_FIELDNAME::EXPIRED, $slice)) { $slice_expired = $slice[SA_SLICE_TABLE_FIELDNAME::EXPIRED]; } $disable_buttons_str = ""; if (isset($slice_expired) && convert_boolean($slice_expired)) { $disable_buttons_str = "disabled"; } $slice_name = $slice[SA_ARGUMENT::SLICE_NAME]; $args['slice_id'] = $slice_id; $query = http_build_query($args); $slice_url = $slice_base_url . $query; print "<tr class='slicetablerow'><td><a href='{$slice_url}'>{$slice_name}</a></td>"; $slice_project_id = $slice[SA_ARGUMENT::PROJECT_ID]; // There's an odd edge case in which a project has expired // but some slice of the project has not. In this case, $project_objects may not // contain the project of the slice. If so, list the project using something else. if (!array_key_exists($slice_project_id, $project_objects)) { $slice_project_name = "-Expired Project-"; $project_expiration = ""; } else { $project = $project_objects[$slice_project_id]; $project_expiration = $project[PA_PROJECT_TABLE_FIELDNAME::EXPIRATION]; $slice_project_name = $project[PA_PROJECT_TABLE_FIELDNAME::PROJECT_NAME]; } print "<td><a href='project.php?project_id={$slice_project_id}'>{$slice_project_name}</a></td>"; // Slice owner name $slice_owner_id = $slice[SA_ARGUMENT::OWNER_ID]; $slice_owner_name = $slice_owner_names[$slice_owner_id]; print "<td>{$slice_owner_name}</td>"; // Slice expiration $slice_exp_date = $slice[SA_ARGUMENT::EXPIRATION]; $slice_exp_hours = get_time_diff($slice_exp_date); $slice_exp_str = dateUIFormat($slice_exp_date); $slice_exp_pretty_str = "In <b>" . get_time_diff_string($slice_exp_hours) . "</b>"; $slice_exp_color = get_urgency_color($slice_exp_hours); $slice_exp_icon = get_urgency_icon($slice_exp_hours); print "<td><span title='{$slice_exp_str}'>{$slice_exp_pretty_str} "; print "<i class='material-icons' style='color:{$slice_exp_color}; font-size: 18px;'>{$slice_exp_icon}</i></span></td>"; // Next resource expiration $slivers = lookup_sliver_info_by_slice($sa_url, $user, $slice_urn); $resource_count = count($slivers); if ($resource_count == 0) { $resource_exp_str = ""; $resource_exp_pretty_str = "<i>No resources</i>"; $resource_exp_color = "#5F584E"; $resource_exp_icon = ""; $resource_exp_hours = 1000000; } else { $first_sliver = reset($slivers); $next_exp = new DateTime($first_sliver[SA_SLIVER_INFO_TABLE_FIELDNAME::SLIVER_INFO_EXPIRATION]); foreach ($slivers as $sliver) { $this_date = new DateTime($sliver[SA_SLIVER_INFO_TABLE_FIELDNAME::SLIVER_INFO_EXPIRATION]); if ($next_exp > $this_date) { $next_exp = $this_date; } } $resource_exp_str = dateUIFormat($next_exp); $resource_exp_hours = get_time_diff($resource_exp_str); $resource_exp_pretty_str = "In <b>" . get_time_diff_string($resource_exp_hours) . "</b>"; $resource_exp_color = get_urgency_color($resource_exp_hours); $resource_exp_icon = get_urgency_icon($resource_exp_hours); } print "<td><span title='{$resource_exp_str}'>{$resource_exp_pretty_str} "; print "<i class='material-icons' style='color:{$resource_exp_color}; font-size: 18px;'>{$resource_exp_icon}</i></span></td>"; // Slice actions $add_url = $resource_base_url . $query; $remove_url = $delete_sliver_base_url . $query; $listres_url = $listres_base_url . $query; $gemini_url = $gemini_base_url . $query; $labwiki_url = $labwiki_base_url . $query; print "<td style='text-align: center;'>"; print "<ul class='selectorcontainer slicetableactions' style='margin: 0px;'><li class='has-sub selector' style='float:none;'>"; print "<span class='selectorshown'>Actions</span><ul class='submenu'>"; print "<li><a href='{$slice_url}'>Manage slice</a></li>"; if ($user->isAllowed(SA_ACTION::ADD_SLIVERS, CS_CONTEXT_TYPE::SLICE, $slice_id)) { print "<li><a href='{$add_url}'>Add resources</a></li>"; } $dashboard_max_renewal_days = 7; $renewal_days = min($dashboard_max_renewal_days, $portal_max_slice_renewal_days); if ($project_expiration) { $project_expiration_dt = new DateTime($project_expiration); $now_dt = new DateTime(); $difference = $project_expiration_dt->diff($now_dt); $renewal_days = $difference->days; $renewal_days = min($renewal_days, $portal_max_slice_renewal_days, $dashboard_max_renewal_days); } $slivers = lookup_sliver_info_by_slice($sa_url, $user, $slice_urn); $renewal_hours = 24 * $renewal_days; $disable_renewal = ""; if ($slice_exp_hours > $renewal_hours && $resource_exp_hours > $renewal_hours) { $disable_renewal = "class='disabledaction'"; } if ($resource_count > 0) { print "<li><a {$disable_renewal} onclick='renew_slice(\"{$slice_id}\", {$renewal_days}, {$resource_count}, {$slice_exp_hours}, {$resource_exp_hours});'>Renew resources ({$renewal_days} days)</a></li>"; if ($user->isAllowed(SA_ACTION::GET_SLICE_CREDENTIAL, CS_CONTEXT_TYPE::SLICE, $slice_id)) { print "<li><a onclick='info_set_location(\"{$slice_id}\", \"{$listres_url}\")'>Resource details</a></li>"; } if ($user->isAllowed(SA_ACTION::DELETE_SLIVERS, CS_CONTEXT_TYPE::SLICE, $slice_id)) { print "<li><a onclick='info_set_location(\"{$slice_id}\", \"{$remove_url}\")'>Delete resources</a></li>"; } } print "</ul></li></ul>"; print "</td></tr>\n"; }
function project_is_expired($proj) { return convert_boolean($proj[PA_PROJECT_TABLE_FIELDNAME::EXPIRED]); }
function get_project_slice_member_info($sa_url, $ma_url, $user, $allow_expired = False, $project_id = null) { $member_ids = array(); $slice_ids = array(); $slice_objects = array(); $project_objects = array(); $member_objects = array(); $project_slice_map = array(); $project_activeslice_map = array(); if (!is_null($project_id)) { $projects = array($project_id); } else { // This is all project IDs the member belongs to, even expired $projects = get_projects_for_member($sa_url, $user, $user->account_id, true); } if (count($projects) > 0) { // These are the details of these projects $project_objects = lookup_project_details($sa_url, $user, $projects); // We get back all the projects. But optionally filter out expired projects. if (!$allow_expired) { $unexpired_projects = array(); $unexpired_project_objects = array(); $now = new DateTime(); foreach ($project_objects as $project) { $project_id = $project[PA_PROJECT_TABLE_FIELDNAME::PROJECT_ID]; $project_expired = $project[PA_PROJECT_TABLE_FIELDNAME::EXPIRED]; $project_name = $project[PA_PROJECT_TABLE_FIELDNAME::PROJECT_NAME]; // error_log("PEXP = " . $project_id . " " . $project_name . // " " . $project_expired); if (convert_boolean($project_expired)) { continue; } $unexpired_project_objects[] = $project; $unexpired_projects[] = $project_id; } $projects = $unexpired_projects; $project_objects = $unexpired_project_objects; } // At this point, $projects and $project_objects have all // the projects we're interested in: expired or not // Get all slices of which user is a member (expired or not) $slice_member_role_ids = get_slices_for_member($sa_url, $user, $user->account_id, True); $slice_member_ids = array(); foreach ($slice_member_role_ids as $slice_member_role_id) { //NOTE: FOR NOW ONLY ALLOW UNEXPIRED SLICES if (!$slice_member_role_id[SA_SLICE_TABLE_FIELDNAME::EXPIRED]) { $slice_member_id = $slice_member_role_id[SA_SLICE_MEMBER_TABLE_FIELDNAME::SLICE_ID]; $slice_member_ids[] = $slice_member_id; } } // $slice_member_ids is the ID's of slices to which the member belongs // This is indexed by project_id, containing an array of slice data // CHAPI: this doesn't generally work any more, since non-members aren't allowed // to get details for slices they aren't members of //$slice_data = get_slices_for_projects($sa_url, $user, $projects, $allow_expired); $slice_data = get_slices_in_projects($sa_url, $user, $slice_member_ids, $projects, $allow_expired); // error_log("SLICE_MEMBER_IDS = " . print_r($slice_member_ids, true)); // error_log("SLICE_DATA = = " . print_r($slice_data, true)); // error_log("PROJECTS = " . print_r($projects, true)); foreach ($project_objects as $project) { $project_id = $project[PA_PROJECT_TABLE_FIELDNAME::PROJECT_ID]; $proj_lead_id = $project[PA_PROJECT_TABLE_FIELDNAME::LEAD_ID]; $proj_slices = $slice_data[$project_id]; $member_ids[] = $proj_lead_id; $proj_slice_ids = array(); $proj_activeslice_ids = array(); foreach ($proj_slices as $proj_slice) { $proj_slice_id = $proj_slice[SA_SLICE_TABLE_FIELDNAME::SLICE_ID]; $proj_slice_id_expired = $proj_slice[SA_SLICE_TABLE_FIELDNAME::EXPIRED]; if (!in_array($proj_slice_id, $slice_member_ids)) { continue; } $proj_slice_ids[] = $proj_slice_id; //error_log("slice id = ". $proj_slice_id . " expired = " . $proj_slice_id_expired); if (!$proj_slice_id_expired) { //error_log("Adding active slice to list ...."); $proj_activeslice_ids[] = $proj_slice_id; } $owner_id = $proj_slice[SA_SLICE_TABLE_FIELDNAME::OWNER_ID]; if (!in_array($owner_id, $member_ids)) { $member_ids[] = $owner_id; } // Optionally filter out expired slices if (!convert_boolean($proj_slice_id_expired) || $allow_expired) { $slice_objects[$proj_slice_id] = $proj_slice; } } // $proj_slice_ids = lookup_slice_ids($sa_url, $user, $project_id); $project_slice_map[$project_id] = $proj_slice_ids; $project_activeslice_map[$project_id] = $proj_activeslice_ids; //error_log("GPSMI: project ".$project_id." ids = ".print_r($proj_activeslice_ids,true)); $slice_ids = array_merge($slice_ids, $proj_slice_ids); // is this ok } } if (count($member_ids) > 0) { $member_objects = lookup_member_details($ma_url, $user, $member_ids); } // error_log("SIDS = " . print_r($slice_ids, true)); // error_log("MIDS = " . print_r($member_ids, true)); // error_log("SMIDS = " . print_r($slice_member_ids, true)); // foreach($project_objects as $po) { error_log("PO = " . print_r($po, true)); } // foreach($slice_objects as $so) { error_log("SO = " . print_r($so, true)); } // foreach($member_objects as $mo) { error_log("MO = " . print_r($mo, true)); } // error_log("PSM = " . print_r($project_slice_map, true)); // error_log("PASM = " . print_r($project_activeslice_map, true)); // At this point, we should have // project_objects has all the projects to which the member belongs // expired or not by request // slice_objects has all the slices to which the member belongs // expired or not by request // member_objects // all the members who are leads of slices or projects in previous lists return array($project_objects, $slice_objects, $member_objects, $project_slice_map, $project_activeslice_map); }
function draw_table($projects, $lead_names, $attribs_by_project, $show_actions) { if (count($projects) == 0) { return; } $show_purpose = false; echo "<table>"; $actions_entry = ""; if ($show_actions) { $actions_entry = "<th>Actions</th>"; } $purpose_entry = ""; if ($show_purpose) { $purpose_entry = "<tr>Purpose</th>"; } echo "<tr><th>Project Name</th><th>Wireless Group</th><th>Project Lead</th>{$purpose_entry} {$actions_entry}<th></th></tr>"; foreach ($projects as $project) { $lead_id = $project[PA_PROJECT_TABLE_FIELDNAME::LEAD_ID]; $proj_id = $project[PA_PROJECT_TABLE_FIELDNAME::PROJECT_ID]; $proj_name = $project[PA_PROJECT_TABLE_FIELDNAME::PROJECT_NAME]; $proj_purpose = $project[PA_PROJECT_TABLE_FIELDNAME::PROJECT_PURPOSE]; $lead_name = $lead_names[$lead_id]; $expired = convert_boolean($project[PA_PROJECT_TABLE_FIELDNAME::EXPIRED]); // error_log("PN = $proj_name EXP = $expired"); $group_name = ""; $wimax_enabled = is_wimax_enabled($proj_id, $attribs_by_project); if ($wimax_enabled) { $group_name = "geni-" . $proj_name; } if ($expired) { continue; } $proj_href = "<a href='project.php?project_id={$proj_id}'>{$proj_name}</a>"; $actions_entry = ""; if ($show_actions) { $enable_button_name = "Enable project"; $enable_button_action = "do_enable_wireless('{$proj_id}', '{$proj_name}');"; $enable_button_hidden = ""; $enable_button_id = "enable-{$proj_id}"; $disable_button_name = "Disable project"; $disable_button_action = "do_disable_wireless('{$proj_id}', '{$proj_name}');"; $disable_button_hidden = 'hidden="hidden"'; $disable_button_id = "disable-{$proj_id}"; $sync_button_name = "Sync Project"; $sync_button_action = "do_wireless_sync('{$proj_id}', '{$proj_name}');"; $sync_button_disabled = "disabled=\"disabled\""; $sync_button_id = "sync-{$proj_id}"; if ($wimax_enabled) { $enable_button_hidden = 'hidden="hidden"'; $disable_button_hidden = ""; $sync_button_disabled = ""; } $enable_button = "<button id=\"{$enable_button_id}\" {$enable_button_hidden} onClick=\"{$enable_button_action}\">{$enable_button_name}</button>"; $disable_button = "<button id=\"{$disable_button_id}\" {$disable_button_hidden} onClick=\"{$disable_button_action}\">{$disable_button_name}</button>"; $sync_button = "<button id=\"{$sync_button_id}\" {$disable_button_hidden} {$sync_button_disabled} onClick=\"{$sync_button_action}\">{$sync_button_name}</button>"; $actions = $enable_button . $disable_button . $sync_button; $actions_entry = "<td>{$actions}</td>"; } $purpose_entry = ""; if ($show_purpose) { $purpose_entry = "<td>{$proj_purpose}</td>"; } $error_entry_id = "error-" . $proj_id; $error_entry = "<td id=\"{$error_entry_id}\"></td>"; echo "<tr><td>{$proj_href}</td><td id=\"group-{$proj_id}\">{$group_name}</td><td>{$lead_name}</td>{$purpose_entry} {$actions_entry} {$error_entry}</tr>"; } echo "</table>"; }