= 2 ) { return true; } else { return false; } } function get_and_print_site($site_array) { global $api; $sites = $api->GetSites( $site_array, array( "name", "site_id", "url", "enabled", "node_ids", "person_ids", "date_created", "slice_ids", "max_slivers", "max_slices", "login_base" ) ); if ( count($sites) > 0 ) { foreach( $sites as $site) { $name = $site['name']; $site_id = $site['site_id']; $url = $site['url']; $enabled = $site['enabled']; $node_ids = $site['node_ids']; $slice_ids_count = count($site['slice_ids']); $person_ids = $site['person_ids']; $date_created = date("M j G:i Y", $site['date_created']); $max_slivers = $site['max_slivers']; $max_slices = $site['max_slices']; $login_base = $site['login_base']; echo "\n"; echo "$name\n"; echo "(home)\n"; echo "[ $slice_ids_count of $max_slices ]\n"; echo ""; if (!$enabled) echo "Not Enabled
\n"; //else echo "$date_created\n"; echo "$date_created\n"; echo "Nodes: "; foreach ($site['node_ids'] as $node_id) { echo " $node_id, "; } echo "\n"; } } } function get_and_print_hostname($host_array) { global $api; $nodes = $api->GetNodes( $host_array, array( "hostname", "node_id", "site_id", "date_created", "last_contact", "boot_state" ) ); if ( count ($nodes) > 0 ) { foreach($nodes as $node) { $hostname= $node['hostname']; $node_id = $node['node_id']; $boot_state= $node['boot_state']; $last_contact = $node['last_contact']; $date_created = date("M j G:i Y", $node['date_created']); echo ""; echo "$node_id "; echo "$hostname"; echo "$boot_state"; if( $last_contact != NULL ) { $last_contact_str = timeDiff($last_contact); } else { $last_contact_str = "Never"; } echo "$last_contact_str\n"; echo "$date_created\n"; echo "\n"; } } return $nodes; } function get_and_print_user ($user_array) { global $api; $persons= $api->GetPersons( $user_array, array( "person_id", "first_name", "last_name", "email", "roles", "enabled", "date_created", "site_ids" ) ); if ( count($persons) > 0 ) { foreach($persons as $person) { $first= $person['first_name']; $last = $person['last_name']; $person_id= $person['person_id']; $email= $person['email']; $enabled= $person['enabled']; $roles = $person['roles']; $role = $person['roles'][0]; $date_created = date("M j G:i Y", $person['date_created']); $site_ids= $person['site_ids']; echo "\n"; echo ""; echo "$first $last"; echo "($person_id) "; echo "$email "; echo ""; if (!$enabled) echo "Not Enabled
\n"; //else echo "$date_created\n"; echo "$date_created\n"; //if (!$enabled) echo " Not Enabled "; //else echo "$date"; echo " roles: "; foreach ($person['roles'] as $role) { echo " $role, "; } echo "\n"; } } return $persons; } // find person roles $_person= $plc->person; $_roles= $_person['role_ids']; /////////////////////////////////////////////////////////////////////// // Initially, we need a search form, and blank information after that. // Based on the fields of the search form, we should be able to populate a lot // of information, related to user, site, keys, // // from a simple domain name search, it would display the site, // nodes -> pcu // users grouped by role, // from a user search, it would find, // user info link, site, roles, etc. // // userquery will be one of these types: // part of a user name, email, user_id // part of a site name, site alias, site_id // part of a node name, domain, node_id // // we should be able to return results based on these guesses. If they're // good, we'll get hits, if nothing comes back, we won't display anything. echo "
\n
\n"; if( $_POST['userquery'] or $_GET['userquery']) { if ( $_POST['userquery'] ) { $query = $_POST['userquery']; } else { $query = $_GET['userquery']; } } echo "

(Separate with commas for multiple queries.)\n \n \n

\n
\n
\n"; // if userquery then search based on string if( $_POST['userquery'] or $_GET['userquery']) { if ( $_POST['userquery'] ) { $query = $_POST['userquery']; } else { $query = $_GET['userquery']; } echo "\n"; $f_commas = explode(",", $query); // PHASE 1: query contains email, user_id, or part of a user name foreach($f_commas as $tok) { $tok = trim($tok); // strip white space. $e = false; //find user by email if ( is_valid_email_addr($tok) ){ $u = get_and_print_user(array("email"=>$tok)); $e = true; if( count( $u ) == 0 ) $none = 1; } $n = false; // find user by user_id if ( is_numeric($tok) ){ $u = get_and_print_user(array("person_id"=>intval($tok))); $n = true; if( count( $u ) == 0 ) $none = 1; } // neither of the above, if (!$n && !$e) { // split on spaces, and search each part. // TODO: search upper and lower-case $f_spaces = explode(" ", $tok); foreach($f_spaces as $stok) { // assume $tok is part of a name // get_user $a = get_and_print_user(array("first_name"=>$stok)); $b = get_and_print_user(array("last_name"=>$stok)); // c = intersect_users(a, b) // if c // print_user(c), // else // print_user(a,b) } if( count( $a ) == 0 && count( $b ) == 0 ) $none = 1; } // PHASE 2: query contains login_base, site_id, or part of a site name // find site by login_base $lb = false; $s = get_and_print_site(array("login_base"=>strtolower($tok))); if( count( $s ) == 0 ) $none = 1; else $lb = true; $n = false; // find site by site_id if ( is_numeric($tok) ){ $s = get_and_print_site(array("site_id"=>intval($tok))); $n = true; if( count( $s ) == 0 ) $none = 1; } if( !$lb && !$n ) { $f_spaces = explode(" ", $tok); foreach($f_spaces as $stok) { $a = get_and_print_site(array("name"=>$stok)); } if( count($a) == 0 ) $none = 1; } // PHASE 3: query contains part of a node name, domain, node_id //if( $none == 1 ) echo "\n"; if ( is_possible_domainname($tok) ) { $n = get_and_print_hostname(array("hostname"=>$tok)); } } echo "
Search Results:
No Results.
\n"; } if (false) { // if a site_id is given, display the site nodes only if( $_GET['site_id'] ) { $site_id= $_GET['site_id']; // Get site info $site_info= $api->GetSites( array( intval( $site_id ) ), array( "name", "person_ids" ) ); // Get site nodes $persons= $api->GetPersons( $site_info[0]['person_ids'], array( "person_id", "first_name", "last_name", "email", "roles", "peer_id", "enabled" ) ); drupal_set_title("People with " . $site_info[0]['name']); sort_persons( $persons ); echo paginate_trash ( $persons, "person_id", "Persons", 25, "email" ); } // if no person id, display list of persons to choose elseif( !$_GET['id'] ) { // GetPersons API call $persons= $api->GetPersons( NULL, array( "person_id", "first_name", "last_name", "email", "roles" , "peer_id", "enabled" ) ); sort_persons( $persons ); echo "
\n
\n"; if( $pers_email ) echo "'$pers_email' is not a valid person email.\n"; echo "

\n \n \n

\n
\n"; } else { // get the person_id from the URL $person_id= intval( $_GET['id'] ); // GetPersons API call for this person $person_info= $api->GetPersons( array( $person_id ) ); if( empty( $person_info ) ) { echo "No such person."; } else { // vars from api $first_name= $person_info[0]['first_name']; $last_name= $person_info[0]['last_name']; $title= $person_info[0]['title']; $url= $person_info[0]['url']; $phone= $person_info[0]['phone']; $email= $person_info[0]['email']; $enabled= $person_info[0]['enabled']; $peer_id=$person_info[0]['peer_id']; // arrays from api $role_ids= $person_info[0]['role_ids']; $roles= $person_info[0]['roles']; $site_ids= $person_info[0]['site_ids']; $slice_ids= $person_info[0]['slice_ids']; $key_ids= $person_info[0]['key_ids']; // gets more data from API calls $site_info= $api->GetSites( $site_ids, array( "site_id", "name" ) ); $slice_info= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) ); $key_info= $api->GetKeys( $key_ids ); drupal_set_title("$first_name $last_name Account Information"); // start form if ( ! $peer_id ) { echo "\n"; } else { echo "
"; } echo "\n"; if ( ! $peer_id ) { # if ( Admin, PI, or user ) allow deletion if( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $site_ids[0], $_person['site_ids'] ) ) || $_person['person_id'] == $person_id) { // list to take person action echo "

\n"; # if ( Admin or PI ) check whether to allow # 'enabling/disabling'. if( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $site_ids[0], $_person['site_ids'] ) ) ) { if( $enabled == true ) { $actions['disable']= "Disable $first_name"; } else { $actions['enable']= "Enable $first_name"; $select_end = $select_end . "   ". "<- This user is not enabled. Choose here to enable or delete."; } if ( in_array( 10, $_roles )) { $actions['su'] = "Become $first_name"; } } # for all cases, list each 'select' key foreach( $actions as $key => $val ) { echo "

\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
First Name: $first_name
Last Name: $last_name
Title: $title
Email: $email
Password: ***********
Phone: $phone
URL: $url
\n"; if( in_array( 10, $_roles ) || $_person['person_id'] == $person_id ) echo "
Update account information\n"; echo "


\n"; // keys $can_manage_keys = ( ( ! $peer_id ) && (in_array( "10", $_roles ) || $person_id == $_person['person_id'])); echo "

Keys

\n"; if( !empty( $key_ids ) ) { echo "

\n"; echo "\n"; foreach( $key_info as $key ) { $key_type= $key['key_type']; $key_id= $key['key_id']; $key_html= wordwrap( $key['key'], 70, "
\n", 1 ); echo "\n"; } echo "
TypeKey
$key_type$key_html
\n"; } else { echo " This user has no known key"; } if( $can_manage_keys ) echo "

Manage Keys\n"; echo "


"; // sites echo "

Sites

\n"; if( !empty( $site_info ) ) { echo "\n"; foreach( $site_info as $site ) { $site_name= $site['name']; $site_id= $site['site_id']; echo "\n"; } echo "
$site_name ( remove)
\n"; echo "\n"; } else { echo " This user is not affiliated with a site !!"; } // diplay site select list to add another site for user if( ! $peer_id && in_array( 10, $_roles ) ) { // get site info $full_site_info= $api->GetSites( NULL, array( "site_id", "name" ) ); if( $site_info ) $person_site= arr_diff( $full_site_info, $site_info ); else $person_site= $full_site_info; sort_sites( $person_site ); echo "

Select a site to add this user to: "; echo ""; } echo "


\n"; // roles echo "

Roles

\n"; echo "

\n"; echo ""; if( in_array( "10", $_roles ) ) echo ""; echo "\n"; // construct role array for( $n=0; $n$role_ids[$n], 'name'=>$roles[$n] ); } if ( !empty ($roles) ) { foreach( $proles as $role ) { $role_name= $role['name']; $role_id= $role['role_id']; echo "\n"; } } else { echo " This user has no known role !!"; } echo "
RoleRemove
$role_name"; if( in_array( 10, $_roles ) ) { echo ""; } echo "
\n"; if ( in_array( 10, $_roles ) ) echo "
\n"; // if admin show roles to add if( in_array( 10, $_roles ) ) { $all_roles= $api->GetRoles(); $addable_roles= arr_diff( $all_roles, $proles ); if( !empty( $addable_roles ) ) { echo "

Add role: \n"; } } echo "


\n"; // slices echo "

Slices

\n"; if( !empty( $slice_info ) ) { foreach( $slice_info as $slice ) { $slice_name= $slice['name']; $slice_id= $slice['slice_id']; echo "$slice_name
\n"; } } else { echo "No slices found for that user"; } if ( ! $peer_id ) { echo "\n"; } else { echo "
\n"; } } echo "

Back to person list"; } } // Print footer include 'plc_footer.php'; ?>