showuser.php3 16.2 KB
Newer Older
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
#
24 25
include("defs.php3");
include("showstuff.php3");
26
include_once("template_defs.php");
27
include_once("table_defs.php");
28
include_once("pub_defs.php");
29 30 31 32

#
# Only known and logged in users can do this.
#
33 34 35
$this_user = CheckLoginOrDie(CHECKLOGIN_USERSTATUS|
			     CHECKLOGIN_WEBONLY|CHECKLOGIN_WIKIONLY);
$uid       = $this_user->uid();
36
$uid_idx   = $this_user->uid_idx();
37
$isadmin   = ISADMIN();
38 39

#
40
# Verify page arguments.
41
#
42 43 44 45
$optargs = OptionalPageArguments("target_user", PAGEARG_USER);

if (! isset($target_user)) {
    $target_user = $this_user;
46 47 48 49 50
}
$userstatus = $target_user->status();
$wikionly   = $target_user->wikionly();
$target_idx = $target_user->uid_idx();
$target_uid = $target_user->uid();
51
$archived   = ($userstatus == TBDB_USERSTATUS_ARCHIVED);
52

53

54 55
#
# Verify that this uid is a member of one of the projects that the
Leigh Stoller's avatar
Leigh Stoller committed
56
# target_uid is in. Must have proper permission in that group too. 
57
#
58 59 60
if (!$isadmin && 
    !$target_user->AccessCheck($this_user, $TB_USERINFO_READINFO)) {
    USERERROR("You do not have permission to view this user's information!", 1);
61 62
}

63 64 65
#
# Tell the user how many PCs he is using.
#
66
$notice  = null;
67
$yourpcs = $target_user->PCsInUse();
68 69

if ($yourpcs) {
70
    if (! $this_user->SameUser($target_user))
71
	$notice = "$target_uid is using $yourpcs PCs!\n";
72
    else
73
	$notice = "You are using $yourpcs PCs!\n";
74 75
}

76
#
77
# Standard Testbed Header, now that we know what we want to say.
78
#
79
if (! $this_user->SameUser($target_user)) {
80
    PAGEHEADER("${target_uid}'s $FLAVOR", null, null, $notice);
81 82
}
else {
83
    PAGEHEADER("My $FLAVOR", null, null, $notice);
84 85
}

86 87 88
$html_groups    = null;
$html_stats     = null;
$html_templates = null;
89
$html_pubs      = null;
90
$html_exports   = null;
91

92 93 94 95 96 97 98 99 100 101 102
#
# See if any mailman lists owned by the user. If so we add a menu item.
#
$mm_result =
    DBQueryFatal("select owner_uid from mailman_listnames ".
		 "where owner_uid='$target_uid'");
#
# Table defs for functions that generate tables.
#
$tabledefs = array('#html' => TRUE);

103 104 105 106 107 108 109 110 111
echo "<script type='text/javascript' language='javascript'>
	function PortalLogin(theform, user) {
            var namex = theform['selectpeer'].selectedIndex;
            var name  = theform['selectpeer'].options[namex].value;
            newurl    = 'gotopeer.php?peer=' + name + '&user=' + user;
            window.open(newurl, '_self');
	}
      </script>\n";

112
# The user profile.
113 114 115
# Add all the menu stuff. Ick.
ob_start();
SUBPAGESTART();
116

117 118 119 120
#
# Permission check not needed; if the user can view this page, they can
# generally access these subpages, but if not, the subpage will still whine.
#
121 122
if (!$archived) {
    SUBMENUSTART("Options");
123

124 125 126 127
    WRITESUBMENUBUTTON("Edit Profile",
		       CreateURL("moduserinfo", $target_user));
}
if (!$archived && !$target_user->wikionly() &&
128 129
    ($isadmin || $target_user->SameUser($this_user))) {
    WRITESUBMENUBUTTON("Edit SSH Keys",
130
		       CreateURL("ssh-keys", $target_user));
131 132 133 134
    
    WRITESUBMENUBUTTON("Generate SSL Cert",
		       CreateURL("gensslcert", $target_user));

135
    if ($target_user->HasEncryptedCert(0)) {
136 137 138 139 140
	WRITESUBMENUBUTTON("Download your SSL Cert",
			   CreateURL("gensslcert", $target_user,
				     "finished", 1));
    }

141 142 143 144 145 146 147
    # Do we have a storage pool? The we support datasets.
    $havestoragepool = HaveStoragePool();
    if ($havestoragepool) {
        WRITESUBMENUBUTTON("My Datasets",
                           CreateURL("list-datasets", $target_user));
    }

148 149 150 151 152 153 154 155 156 157 158 159 160
    if ($MAILMANSUPPORT) {
        #
        # See if any mailman lists owned by the user. If so we add a menu item.
        #
	$mm_result =
	    DBQueryFatal("select owner_uid from mailman_listnames ".
			 "where owner_uid='$target_uid'");

	if (mysql_num_rows($mm_result)) {
	    WRITESUBMENUBUTTON("Show Mailman Lists",
			       CreateURL("showmmlists", $target_user));
	}
    }
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
    if ($PORTAL_ENABLE && $PORTAL_ISPRIMARY) {
	$peer_result =
	    DBQueryFatal("select peer from user_exports ".
			 "where uid_idx=$target_idx");
	if (mysql_num_rows($peer_result) &&
	    ($this_user->SameUser($target_user) || $isadmin)) {
	
	    $portaltext =
		"<form name=\"portal\" onsubmit=\"return false;\">\n
                  <select name=\"selectpeer\">
                    <option value=''>Portal Login</option>\n";
	    while ($row = mysql_fetch_array($peer_result)) {
		$peer = $row["peer"];

		$portaltext .= "<option value='$peer'>$peer</option>\n";
	    }
	    $portaltext .= "</select> ";
	    $portaltext .=
		"<input type=button name='go' value='Go'
                        onclick='PortalLogin(portal, $target_idx);'>";
	    $portaltext .= "</form>\n";
	
	    WRITESUBMENUBUTTON($portaltext);
	}
    }
186 187 188
}

if ($isadmin) {
189
    SUBMENUSECTION("Admin Options");
190

191 192 193 194 195 196 197 198 199 200 201 202 203
    if (!$archived) {
	if ($target_user->status() == TBDB_USERSTATUS_FROZEN) {
	    WRITESUBMENUBUTTON("Thaw User",
			       CreateURL("freezeuser", $target_user,
					 "action", "thaw"));
	}
	else {
	    WRITESUBMENUBUTTON("Freeze User",
			       CreateURL("freezeuser", $target_user,
					 "action", "freeze"));
	}
	WRITESUBMENUBUTTON("Delete User",
			   CreateURL("deleteuser", $target_user));
204

205 206
	WRITESUBMENUBUTTON("SU as User",
			   CreateURL("suuser", $target_user));
207

208 209 210 211 212 213 214 215 216 217 218 219 220 221
	if ($target_user->status() == TBDB_USERSTATUS_UNAPPROVED) {
	    WRITESUBMENUBUTTON("Change UID",
			       CreateURL("changeuid", $target_user));
	}

	if ($target_user->status() == TBDB_USERSTATUS_NEWUSER ||
	    $target_user->status() == TBDB_USERSTATUS_UNVERIFIED) {
	    WRITESUBMENUBUTTON("Resend Verification Key",
			       CreateURL("resendkey", $target_user));
	}
	else {
	    WRITESUBMENUBUTTON("Send Test Email Message",
			       CreateURL("sendtestmsg", $target_user));
	}
222
    }
223 224
    WRITESUBMENUBUTTON("Experiment History",
		       CreateURL("showstats", $target_user, "showby", "user"));
225 226 227 228 229 230
}
SUBMENUEND();
$target_user->Show();
SUBPAGEEND();
$html_profile = ob_get_contents();
ob_end_clean();
231 232 233 234
list ($html_profile, $button_profile) =
	TableWrapUp($html_profile, FALSE, FALSE,
		    "profile_table", "profile_button");

235 236 237 238 239 240 241 242
if ($isadmin) {
    $html_stats = $target_user->ShowStats();
    $html_stats = "<center><h3>User Stats</h3></center>$html_stats";
    list ($html_stats, $button_stats) =
	TableWrapUp($html_stats, FALSE, FALSE,
		    "stats_table", "stats_button");
}

243
#
244
# Lets show Experiments.
245
#
246 247
if ($EXPOSETEMPLATES) {
    $html_templates = SHOWTEMPLATELIST("USER", 0, $uid, $target_uid, "", TRUE);
248 249 250 251 252
    if ($html_templates) {
	list ($html_templates, $button_templates) =
	    TableWrapUp($html_templates, FALSE, FALSE,
			"templates_table", "templates_button");
    }
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
}
$html_experiments =
    ShowExperimentList_internal(FALSE, "USER", $this_user,
				$target_user,
				array('#html' => TRUE,
				      '#id'   => 'experiments_sorted'));
if ($html_experiments) {
    list ($html_experiments, $button_experiments) =
	TableWrapUp($html_experiments, FALSE, TRUE,
		    "experiments_table", "experiments_button");
}
$html_instances =
    ShowExperimentList_internal(TRUE, "USER", $this_user, 
				$target_user,
				array('#html' => TRUE,
				      '#id'   => 'instances_sorted'));
				
if ($html_instances) {
    list ($html_instances, $button_instances) =
	TableWrapUp($html_instances, FALSE, FALSE,
		    "instances_table", "instances_button");
}
275 276

#
277
# Lets show project and group membership.
278 279
#
$query_result =
280 281
    DBQueryFatal("select distinct g.pid,g.gid,g.trust,p.name,gr.description, ".
    		 "       count(distinct r.node_id) as ncount ".
282
		 " from group_membership as g ".
283
		 "left join projects as p on p.pid=g.pid ".
284
		 "left join groups as gr on gr.pid=g.pid and gr.gid=g.gid ".
285 286
		 "left join experiments as e on g.pid=e.pid and g.gid=e.gid ".
		 "left join reserved as r on e.pid=r.pid and e.eid=r.eid ".
287
		 "left join group_membership as g2 on g2.pid=g.pid and ".
288 289
		 "     g2.gid=g.gid and ".
		 "     g2.uid_idx='" . $this_user->uid_idx() . "' ".
Leigh Stoller's avatar
Leigh Stoller committed
290 291
		 "where g.uid_idx='$target_idx' ".
		 ($isadmin ? "" : "and g2.uid_idx is not null ") .
292
		 "group by g.pid, g.gid, g.trust ".
293
		 "order by g.pid,gr.created");
294 295

if (mysql_num_rows($query_result)) {
296
    ob_start();
297
    echo "<center>
298
          <h3>Project and Group Membership</h3>
299 300 301 302
          </center>
          <table align=center border=1 cellpadding=1 cellspacing=2>\n";

    echo "<tr>
303 304
              <th>PID</th>
              <th>GID</th>
305
	      <th>Nodes</th>
306 307 308
              <th>Name/Description</th>
              <th>Trust</th>
              <th>MailTo</th>
309 310 311
          </tr>\n";

    while ($projrow = mysql_fetch_array($query_result)) {
312 313 314 315 316 317
	$pid   = $projrow["pid"];
	$gid   = $projrow["gid"];
	$name  = $projrow["name"];
	$desc  = $projrow["description"];
	$trust = $projrow["trust"];
	$nodes = $projrow["ncount"];
Leigh Stoller's avatar
Leigh Stoller committed
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347

	echo "<tr>
                 <td><A href='showproject.php3?pid=$pid'>
                        $pid</A></td>
                 <td><A href='showgroup.php3?pid=$pid&gid=$gid'>
                        $gid</A></td>\n";

	echo "<td>$nodes</td>\n";

	if (strcmp($pid,$gid)) {
	    echo "<td>$desc</td>\n";
	    $mail  = $pid . "-" . $gid . "-users@" . $OURDOMAIN;
	}
	else {
	    echo "<td>$name</td>\n";
	    $mail  = $pid . "-users@" . $OURDOMAIN;
	}

	$color = ($trust == TBDB_TRUSTSTRING_NONE ? "red" : "black");

	echo "<td><font color=$color>$trust</font></td>\n";

	if ($MAILMANSUPPORT) {
            # Not sure what I want to do here ...
	    echo "<td nowrap><a href=mailto:$mail>$mail</a></td>";
	}
	else {
	    echo "<td nowrap><a href=mailto:$mail>$mail</a></td>";
	}
	echo "</tr>\n";
348 349 350
    }
    echo "</table>\n";

351 352 353
    echo "<center>
          Click on the GID to view/edit group membership and trust levels.
          </center>\n";
354 355 356 357 358
    $html_groups = ob_get_contents();
    list ($html_groups, $button_groups) =
	TableWrapUp($html_groups, FALSE, FALSE,
		    "groups_table", "groups_button");
    ob_end_clean();
359
}
360

361 362 363 364
if ($PUBSUPPORT) {
    #
    # List pubs owned by user if any
    #
365
    $query_result = GetPubs("`owner` = $target_idx");
366 367 368 369 370 371 372 373 374 375
    if (mysql_num_rows($query_result)) {
	$html_pubs = MakeBibList($this_user, $isadmin, $query_result);
	$html_pubs .= '<p><a href="deleted_pubs.php">Show Deleted Publications</a></p>';
	$html_pubs .= "\n";
	list ($html_pubs, $button_pubs) =
	  TableWrapUp($html_pubs, FALSE, FALSE,
		      "pubs_table", "pubs_button");
    }
}

376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
#
# Portal support; show exports.
#
if ($PORTAL_ENABLE && $PORTAL_ISPRIMARY) {
    $query_result =
	DBQueryFatal("select * from user_exports where uid_idx='$target_idx'");
    if (mysql_num_rows($query_result)) {
	$html_exports =
	    "<center>
               <h3>Peer Exports</h3>
             </center>
             <table align=center border=1 cellpadding=1 cellspacing=2>\n";

        $html_exports .=
	    "<tr>
                <th>Peer</th>
                <th>Exported</th>
  	        <th>Updated</th>
             </tr>\n";

	while ($exportrow = mysql_fetch_array($query_result)) {
	    $peer     = $exportrow["peer"];
	    $updated  = $exportrow["updated"];
	    $exported = $exportrow["exported"];

	    $html_exports .=
		"<tr>
                    <td>$peer</td>
                    <td>$exported</td>
                    <td>$updated</td>
                  </tr>\n";
	}
	$html_exports .= "</table>\n";
	list ($html_exports, $button_exports) =
	    TableWrapUp($html_exports, FALSE, FALSE,
			"exports_table", "exports_button");
    }
}
 
415
#
416
# Special banner message.
417
#
418 419 420 421 422 423
$message = TBGetSiteVar("web/banner");
if ($message != "") {
    echo "<center><font color=Red size=+1>\n";
    echo "$message\n";
    echo "</font></center><br>\n";
}
424

425
#
426
# Function to change what is being shown.
427
#
428
echo "<script type='text/javascript' language='javascript'>
429 430
        var li_current = 'li_profile';
        var table_current = 'profile_table';
431 432
        function Show(which) {
	    li = getObjbyName(li_current);
433 434 435 436 437 438
            if (li) {
                li.style.backgroundColor = '#DDE';
                li.style.borderBottom = '1px solid #778';
                table = getObjbyName(table_current);
                table.style.display = 'none';
            }
439 440 441

            li_current = 'li_' + which;
            table_current = which + '_table';
442 443 444 445 446 447 448
   	    li = getObjbyName(li_current);
            if (li) {
                li.style.backgroundColor = 'white';
                li.style.borderBottom = '1px solid white';
                table = getObjbyName(table_current);
                table.style.display = 'block';
            }
449 450 451

            return false;
        }
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
        function Setup() {
	    var urllocation = location.href; //find url parameter
	    if (urllocation && urllocation.indexOf('#') >= 0) {
                var which = urllocation.substr(urllocation.indexOf('#') + 1);
	        li = getObjbyName('li_' + which);
                if (!li) {
                    which = 'profile';
                }
                Show(which);
            }
            else {
	        li = getObjbyName(li_current);
                if (li) {
                    li.style.backgroundColor = 'white';
                    li.style.borderBottom = '1px solid white';
                    table = getObjbyName(table_current);
                    table.style.display = 'block';
                }
            }
471 472
        }
      </script>\n";
473

474
#
475 476 477 478 479 480
# This is the topbar
#
echo "<div width=\"100%\" align=center>\n";
echo "<ul id=\"topnavbar\">\n";
if ($html_templates) {
    echo "<li>
481 482
           <a href=\"#templates\" ".
	       "class=topnavbar onfocus=\"this.hideFocus=true;\" ".
483 484
               "id=\"li_templates\" onclick=\"Show('templates');\">".
               "Templates</a></li>\n";
485
}
486 487
if ($html_experiments) {
     echo "<li>
488 489
            <a href=\"#experiments\" ".
	       "class=topnavbar onfocus=\"this.hideFocus=true;\" ".
490 491
               "id=\"li_experiments\" onclick=\"Show('experiments');\">".
               "Experiments</a></li>\n";
492
}
493 494
if ($html_instances) {
    echo "<li>
495 496
           <a href=\"#instances\" ".
	      "class=topnavbar onfocus=\"this.hideFocus=true;\"  ".
497 498 499 500 501
              "id=\"li_instances\" onclick=\"Show('instances');\">".
              "Instances</a></li>\n";
}
if ($html_groups) {
    echo "<li>
502 503
          <a href=\"#groups\" ".
	      "class=topnavbar onfocus=\"this.hideFocus=true;\" ".
504
	      "id=\"li_groups\" onclick=\"Show('groups');\">".
505
              "Projects</a></li>\n";
506 507
}
echo "<li>
508 509
      <a href=\"#profile\" ".
           "class=topnavbar onfocus=\"this.hideFocus=true;\" ".
510 511 512 513 514
           "id=\"li_profile\" onclick=\"Show('profile');\">".
           "Profile</a></li>\n";

if ($isadmin && $html_stats) {
    echo "<li>
515 516
          <a href=\"#stats\" ".
	      "class=topnavbar onfocus=\"this.hideFocus=true;\" ".
517 518 519
	      "id=\"li_stats\" onclick=\"Show('stats');\">".
              "User Stats</a></li>\n";
}
520 521
if ($html_pubs) {
    echo "<li>
522 523
          <a href=\"#pubs\" ".
	      "class=topnavbar onfocus=\"this.hideFocus=true;\" ".
524 525 526
	      "id=\"li_pubs\" onclick=\"Show('pubs');\">".
              "Publications</a></li>\n";
}
527 528 529 530 531 532 533
if ($html_exports) {
    echo "<li>
          <a href=\"#exports\" ".
	      "class=topnavbar onfocus=\"this.hideFocus=true;\" ".
	      "id=\"li_exports\" onclick=\"Show('exports');\">".
              "Peers</a></li>\n";
}
534 535 536
echo "</ul>\n";
echo "</div>\n";
echo "<div align=center id=topnavbarbottom>&nbsp</div>\n"; 
537

538 539 540 541 542 543 544 545
if ($html_templates) {
     echo $html_templates;
}
if ($html_instances) {
    echo $html_instances;
}
if ($html_groups) {
    echo $html_groups;
546
}
547 548 549 550
echo $html_profile;
if ($isadmin && $html_stats) {
    echo $html_stats;
}
551 552 553
if ($html_pubs) {
    echo $html_pubs;
}
554 555 556
if ($html_exports) {
    echo $html_exports;
}
557 558 559 560 561 562 563
if ($html_experiments) {
    echo $html_experiments;
}

#
# Get the active tab to look right.
#
564 565
$current = ($html_experiments ? "experiments" : "profile");

566
echo "<script type='text/javascript' language='javascript'>
567
      Setup();
568
      </script>\n";
569

570 571 572 573 574
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>
Chad Barb's avatar
Chad Barb committed
575 576 577