archive_tag.php3 5.95 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
include("showstuff.php3");

10 11 12 13 14
#
# Standard Testbed Header
#
PAGEHEADER("Commit and Tag");

15 16 17 18 19 20 21 22 23
#
# Only known and logged in users can look at experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);

#
# Verify page arguments.
24 25 26
#
if (! isset($exptidx) || $exptidx == "") {
    USERERROR("Must supply an experiment to view!", 1);
27
}
28 29
if (!TBvalid_integer($exptidx)) {
    USERERROR("Invalid characters in $exptidx!", 1);
30
}
31 32 33 34 35 36 37 38 39 40

#
# We get an index. Must map that to a pid/gid to do a group level permission
# check, since it might not be an current experiment.
#
unset($pid);
unset($eid);
unset($gid);
if (TBExptidx2PidEid($exptidx, $pid, $eid, $gid) < 0) {
    USERERROR("No such experiment index $exptidx!", 1);
41
}
42 43 44 45 46 47 48 49

if (!$isadmin &&
    !TBProjAccessCheck($uid, $pid, $gid, $TB_PROJECT_READINFO)) {
    USERERROR("You do not have permission to view tags for ".
	      "archive in $pid/$gid ($exptidx)!", 1);
}
if (!TBCurrentExperiment($exptidx)) {
    USERERROR("Experiment index $exptidx is not a current experiment!", 1);
50 51 52 53
}

function SPITFORM($formfields, $errors)
{
54
    global $isadmin, $exptidx, $TBDB_ARCHIVE_TAGLEN, $referrer;
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

    echo "<center>
          Commit/Tag Archive
          </center><br>\n";

    if ($errors) {
	echo "<table class=nogrid
                     align=center border=0 cellpadding=6 cellspacing=0>
              <tr>
                 <th align=center colspan=2>
                   <font size=+1 color=red>
                      &nbsp;Oops, please fix the following errors!&nbsp;
                   </font>
                 </td>
              </tr>\n";

	while (list ($name, $message) = each ($errors)) {
	    echo "<tr>
                     <td align=right>
                       <font color=red>$name:&nbsp;</font></td>
                     <td align=left>
                       <font color=red>$message</font></td>
                  </tr>\n";
	}
	echo "</table><br>\n";
    }

    echo "<table align=center border=1> 
83
          <form action=archive_tag.php3?exptidx=$exptidx method=post>\n";
84

85 86 87 88
    if (isset($referrer)) {
	echo "<input type=hidden name=referrer value=$referrer>\n";
    }
    
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
    echo "<tr>
              <td align=center>
               <b>Please enter a tag[<b>1</b>]</b>
              </td>
          </tr>\n";

    echo "<tr>
              <td class=left>
                  <input type=text
                         name=\"formfields[tag]\"
                         value=\"" . $formfields[tag] . "\"
	                 size=$TBDB_ARCHIVE_TAGLEN
                         maxlength=$TBDB_ARCHIVE_TAGLEN>
          </tr>\n";


    echo "<tr>
              <td align=center>
               <b>Please enter an optional message to be logged
                       with the tag.</b>
              </td>
          </tr>
          <tr>
              <td align=center class=left>
                  <textarea name=\"formfields[message]\"
                    rows=10 cols=70>" .
	            ereg_replace("\r", "", $formfields[message]) .
	            "</textarea>
              </td>
          </tr>\n";

    echo "<tr>
              <td align=center>
                 <b><input type=submit name=submit value='Commit and Tag'></b>
              </td>
          </tr>\n";

    echo "</form>
          </table>\n";

    echo "<blockquote><blockquote><blockquote>
          <ol>
            <li> Optional tag must contain only alphanumeric characters,
                 starting with an alpha character. If no tag is supplied,
                 we will make one up for you, but that is probably not
                 what you want.

          </ol>
          </blockquote></blockquote></blockquote>\n";
}

#
# On first load, display a virgin form and exit.
#
if (! $submit) {
    $defaults = array();
145 146 147
    if (!isset($referrer))
	$referrer = $_SERVER['HTTP_REFERER'];
    
148 149 150 151 152 153 154 155 156 157 158 159 160 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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
    SPITFORM($defaults, 0);
    PAGEFOOTER();
    return;
}

# Args to shell.
$tag      = "";
$tagarg   = "";
$message  = "";
$tmpfname = Null;

function CLEANUP()
{
    global $tmpfname;

    if ($tmpfname != NULL)
	unlink($tmpfname);
    
    exit();
}
register_shutdown_function("CLEANUP");

#
# Otherwise, must validate and redisplay if errors
#
$errors = array();

#
# Tag
#
if (isset($formfields["tag"]) && $formfields["tag"] != "") {
    if (! TBvalid_archive_tag($formfields["tag"])) {
	$errors["Tag"] = TBFieldErrorString();
    }
    else {
	$tag = escapeshellarg($formfields["tag"]);
	$tagarg = "-t $tag" ;
    }
}

if (isset($formfields["message"]) && $formfields["message"] != "") {
    if (! TBvalid_archive_message($formfields["message"])) {
	$errors["Message"] = TBFieldErrorString();
    }
    else {
	#
	# Easier to stick the entire message into a temporary file and
	# send that through. 
	#
	$tmpfname = tempnam("/tmp", "archive_tag");

	$fp = fopen($tmpfname, "w");
	fwrite($fp, $formfields["message"]);
	fclose($fp);
	chmod($tmpfname, 0666);
	
	$message = "-m $tmpfname";
    }
}

#
# If any errors, respit the form with the current values and the
# error messages displayed. Iterate until happy.
# 
if (count($errors)) {
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    return;
}

218 219
STARTBUSY("Committing and Tagging!");

220 221 222 223 224 225
#
# First lets make sure the tag is unique. 
#
$retval = SUEXEC($uid, "$pid,$gid",
		 "webarchive_control checktag $pid $eid $tag",
		 SUEXEC_ACTION_IGNORE);
226 227 228 229 230

/* Clear the various 'loading' indicators. */
if ($retval) 
    STOPBUSY();

231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
#
# Fatal Error. 
# 
if ($retval < 0) {
    SUEXECERROR(SUEXEC_ACTION_DIE);
}

# User error. Tell user and exit.
if ($retval) {
    $errors["Tag"] = "Already in use; pick another";
    
    SPITFORM($formfields, $errors);
    PAGEFOOTER();
    return;
}

SUEXEC($uid, "$pid,$gid",
248
       "webarchive_control $tagarg $message -u commit $pid $eid",
249 250
       SUEXEC_ACTION_DIE);

251 252 253 254 255 256 257 258 259 260 261
STOPBUSY();

if (!isset($referrer))
    $referrer = "archive_view.php3/$exptidx/?exptidx=$exptidx";

PAGEREPLACE($referrer);

#
# Standard Testbed Footer
# 
PAGEFOOTER();
262
?>