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

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

14 15 16
#
# Only known and logged in users can look at experiments.
#
17 18 19
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
20 21 22

#
# Verify page arguments.
23
#
24 25 26
$reqargs = RequiredPageArguments("experiment", PAGEARG_EXPERIMENT);
$optargs = OptionalPageArguments("submit", PAGEARG_STRING,
				 "formfields", PAGEARG_ARRAY);
27

28 29 30 31
# Need these below.
$pid = $experiment->pid();
$eid = $experiment->eid();
$gid = $experiment->gid();
32

33
# Permission
34
if (!$isadmin &&
35
    !$experiment->AccessCheck($this_user, $TB_PROJECT_READINFO)) {
36
    USERERROR("You do not have permission to view tags for ".
37
	      "archive in $pid/$eid!", 1);
38 39 40 41
}

function SPITFORM($formfields, $errors)
{
42
    global $experiment, $TBDB_ARCHIVE_TAGLEN, $referrer;
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

    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> 
71 72
          <form action='" . CreateURL("archive_tag", $experiment) . "' ".
	        "method=post>\n";
73

74 75 76 77
    if (isset($referrer)) {
	echo "<input type=hidden name=referrer value=$referrer>\n";
    }
    
78 79 80 81 82 83 84 85 86 87
    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]\"
88
                         value=\"" . $formfields["tag"] . "\"
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
	                 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>" .
104
	            ereg_replace("\r", "", $formfields["message"]) .
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
	            "</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.
#
132
if (! isset($submit)) {
133
    $defaults = array();
134 135 136
    $defaults["tag"]     = "";
    $defaults["message"] = "";
    
137 138 139
    if (!isset($referrer))
	$referrer = $_SERVER['HTTP_REFERER'];
    
140 141 142 143 144 145 146 147 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
    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;
}

210 211
STARTBUSY("Committing and Tagging!");

212 213 214
#
# First lets make sure the tag is unique. 
#
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
if ($tag != "") {
    $retval = SUEXEC($uid, "$pid,$gid",
		     "webarchive_control checktag $pid $eid $tag",
		     SUEXEC_ACTION_IGNORE);

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

    #
    # Fatal Error. 
    # 
    if ($retval < 0) {
	SUEXECERROR(SUEXEC_ACTION_DIE);
    }
230

231 232 233
    # User error. Tell user and exit.
    if ($retval) {
	$errors["Tag"] = "Already in use; pick another";
234
    
235 236 237 238
	SPITFORM($formfields, $errors);
	PAGEFOOTER();
	return;
    }
239 240 241
}

SUEXEC($uid, "$pid,$gid",
242
       "webarchive_control $tagarg $message -u commit $pid $eid",
243 244
       SUEXEC_ACTION_DIE);

245 246
STOPBUSY();

247 248
if (!isset($referrer)) {
    $exptidx  = $experiment->idx();
249
    $referrer = "archive_view.php3/$exptidx/?exptidx=$exptidx";
250
}
251 252 253 254 255 256 257

PAGEREPLACE($referrer);

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