profile-activity.php 5.74 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2018 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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
# 
# {{{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/>.
# 
# }}}
#
chdir("..");
include("defs.php3");
chdir("apt");
include("quickvm_sup.php");
include("profile_defs.php");
$page_title = "My Profiles";

#
# Verify page arguments.
#
$reqargs = RequiredPageArguments("uuid",  PAGEARG_STRING);

#
# Get current user.
#
RedirectSecure();
40 41
$this_user = CheckLoginOrRedirect();

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
SPITHEADER(1);

$profile = Profile::Lookup($uuid);
if (!$profile) {
    SPITUSERERROR("No such profile!");
}
else if ($this_user->uid_idx() != $profile->creator_idx() && !ISADMIN()) {
    SPITUSERERROR("Not enough permission!");
}
$profileid = $profile->profileid();
$instances = array();

#
# First existing instances and then the history table.
#
57
$query1_result =
58 59
    DBQueryFatal("select 1 as active, ".
                 "   i.uuid,i.profile_version,i.created,'' as destroyed, ".
60
		 "   i.creator,p.uuid as profile_uuid,u.email,".
61
                 "   GROUP_CONCAT(ia.public_url) as public_urls, ".
62
                 "   GROUP_CONCAT(aa.abbreviation) as clusters, ".
63
                 "   i.slice_uuid,f.exitmessage,f.exitcode ".
64
		 "  from apt_instances as i ".
65 66
                 "left join apt_instance_failures as f ".
                 "     on f.uuid=i.uuid ".
67 68
                 "left join apt_instance_aggregates as ia ".
                 "     on ia.uuid=i.uuid ".
69 70 71
		 "left join apt_profile_versions as p on ".
		 "     p.profileid=i.profile_id and ".
		 "     p.version=i.profile_version ".
72
		 "left join geni.geni_users as u on u.uuid=i.creator_uuid ".
73
                 "left join apt_aggregates as aa on aa.urn=ia.aggregate_urn ".
74
		 "where i.profile_id='$profileid' ".
75
		 "group by i.uuid order by i.created desc");
76 77

$query2_result =
78 79
    DBQueryFatal("select 0 as active, ".
                 "    h.uuid,h.profile_version,h.created,h.destroyed, ".
80
		 "    h.creator,p.uuid as profile_uuid,u.email, ".
81
                 "    GROUP_CONCAT(ia.public_url) as public_urls, ".
82
                 "    GROUP_CONCAT(aa.abbreviation) as clusters, ".
83
                 "    h.slice_uuid,f.exitmessage,f.exitcode ".
84
		 "  from apt_instance_history as h ".
85 86
                 "left join apt_instance_failures as f ".
                 "     on f.uuid=h.uuid ".
87 88
                 "left join apt_instance_aggregate_history as ia ".
                 "     on ia.uuid=h.uuid ".
89 90 91
		 "left join apt_profile_versions as p on ".
		 "     p.profileid=h.profile_id and ".
		 "     p.version=h.profile_version ".
92
		 "left join geni.geni_users as u on u.uuid=h.creator_uuid ".
93
                 "left join apt_aggregates as aa on aa.urn=ia.aggregate_urn ".
94
		 "where h.profile_id='$profileid' ".
95
		 "group by h.uuid order by h.created desc");
96

97 98
if (mysql_num_rows($query1_result) == 0 &&
    mysql_num_rows($query2_result) == 0) {
99 100 101 102 103
    $message = "<b>Oops, there is no activity to show you.</b><br>";
    SPITUSERERROR($message);
    exit();
}

104 105
foreach (array($query1_result, $query2_result) as $query_result) {
    while ($row = mysql_fetch_array($query_result)) {
106
        $active    = $row["active"];
107 108 109 110 111 112 113
	$uuid      = $row["uuid"];
	$puuid     = $row["profile_uuid"];
	$pversion  = $row["profile_version"];
	$created   = $row["created"];
	$destroyed = $row["destroyed"];
	$creator   = $row["creator"];
	$email     = $row["email"];
114 115
        $exitmessage= $row["exitmessage"];
        $exitcode   = $row["exitcode"];
116
        $public_urls= $row["public_urls"];
117
        $slice_uuid= $row["slice_uuid"];
118
        $clusters  = $row["clusters"];
119 120 121 122 123
	# If a guest user, use email instead.
	if (isset($email)) {
	    $creator = $email;
	}
	$instance = array();
124
        $instance["active"]      = intval($active);
125 126 127 128 129 130
	$instance["uuid"]        = $uuid;
	$instance["p_uuid"]      = $puuid;
	$instance["p_version"]   = $pversion;
	$instance["creator"]     = $creator;
	$instance["created"]     = $created;
	$instance["destroyed"]   = $destroyed;
131
	$instance["clusters"]    = ($clusters ? $clusters : "n/a");
132 133 134 135 136 137 138 139 140 141 142 143 144 145
        if (isset($exitcode)) {
            $instance["iserror"]       = 1;

            if ($exitcode >= 0 && $exitcode <= count($geni_response_codes)) {
                $instance["error_reason"] = $geni_response_codes[$exitcode];
            }
            elseif ($exitcode == GENIRESPONSE_STITCHER_ERROR) {
                $instance["error_reason"] = "Stitcher Failed";
            }
            else {
                $instance["error_reason"]  = $exitcode;
            }
            $instance["error_message"] = $exitmessage;
        }
146 147
	$instances[] = $instance;
    }
148 149 150 151 152 153 154
}

# Place to hang the toplevel template.
echo "<div id='activity-body'></div>\n";

echo "<script type='text/javascript'>\n";
echo "    window.AJAXURL  = 'server-ajax.php';\n";
155
echo "    window.ISADMIN  = " . ISADMIN() . ";\n";
156 157
echo "</script>\n";
echo "<script type='text/plain' id='instances-json'>\n";
158 159
echo json_encode($instances,
                 JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_TAG|JSON_HEX_AMP);
160 161 162
echo "</script>\n";
echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";

163 164 165 166 167
REQUIRE_UNDERSCORE();
REQUIRE_SUP();
SPITREQUIRE("js/profile-activity.js");

AddTemplate("profile-activity");
168 169
SPITFOOTER();
?>