archive_missing.php3 4.45 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2007 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/>.
# 
# }}}
23 24 25 26 27 28
#
include("defs.php3");

#
# Only known and logged in users can end experiments.
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
32 33 34

#
# Verify page arguments.
35
#
36
$reqargs  = RequiredPageArguments("experiment", PAGEARG_EXPERIMENT);
37

38 39 40 41 42 43
# Need these below.
$pid = $experiment->pid();
$eid = $experiment->eid();
$gid = $experiment->gid();

# Permission
44
if (!$isadmin &&
45
    !$experiment->AccessCheck($this_user, $TB_PROJECT_READINFO)) {
46
    USERERROR("You do not have permission to view missing files for ".
47
	      "archive in $pid/$eid!", 1);
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
}

#
# Move files requested.
#
if (isset($movesome)) {
    #
    # Go through the post list and find all the filenames.
    #
    $fileargs = "";
    
    while (list ($var, $value) = each ($_POST)) {
	if (preg_match('/^fn[\d]+$/', $var) &&
	    preg_match('/^([-\w\/\.\+\@,~]+)$/', $value)) {
	    $fileargs = "$fileargs " . escapeshellarg($value);
	}
    }
    SUEXEC($uid, "$pid,$gid",
	   "webarchive_control addtoarchive $pid $eid $fileargs",
	   SUEXEC_ACTION_DUPDIE);
    
69
    header("Location: " . CreateURL("archive_missing", $experiment));
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    return;
}

#
# Standard Testbed Header
#
PAGEHEADER("Add Missing Files");

echo "<script language=JavaScript>
      <!--
          function NormalSubmit() {
              document.form1.target='_self';
              document.form1.submit();
          }
          function SelectAll() {
              var i;
              var setval;

              if (document.form1.selectall.value == 'Select All') {
                   document.form1.selectall.value = 'Clear All'
                   setval = true;
              }
              else {
                   document.form1.selectall.value = 'Select All'
                   setval = false;
              }

              for (i = 0; i < document.form1.elements.length; i++) {
                  var element = document.form1.elements[i];

                  if (element.type == 'checkbox') {
                      element.checked = setval;
                  }
              }
          }
          //-->
          </script>\n";

108 109
echo $experiment->PageHeader();
echo "<br><br>\n";
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

#
# We ask an external script for the list of missing files. 
#
SUEXEC($uid, "$pid,$gid",
       "webarchive_control missing $pid $eid",
       SUEXEC_ACTION_DIE);

#
# Show the user the output.
#
if (count($suexec_output_array)) {
    echo "<br>".
	"<b>These files have been referenced by your experiment, but ".
	"are not contained within the experiments archive directory. ".
	"Selecting these files will move them into the experiment archive ".
	"directory, leaving symlinks behind.";
    echo "</b><br><br>";

    echo "<table border=1>\n";
130 131 132
    echo "<form action='" .
	          CreateURL("archive_missing", $experiment) . "' " .
	       "onsubmit=\"return false;\"
133 134 135 136 137
                name=form1 method=post>\n";
    echo "<input type=hidden name=movesome value=Submit>\n";    
    echo "<tr><td align=center colspan=2>\n";
    echo "<input type=button name=movesome value='Move Selected'
                 onclick=\"NormalSubmit();\"></b>";
138
    echo "&nbsp;&nbsp;&nbsp; ";
139 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
    echo "<input type=button name=selectall value='Select All'
                 onclick=\"SelectAll();\"></b>";
    echo "</td></tr>\n";

    echo "<tr>
           <th>Pathname</th>
           <th>Move to Archive</th>
          </tr>\n";
    
    for ($i = 0; $i < count($suexec_output_array); $i++) {
	$fn = rtrim($suexec_output_array[$i]);
	$name = "fn$i";
	
	echo "<tr>\n";
	echo "<td><tt>" . $fn . "</tt></td>";
	echo "<td><input type=checkbox name=$name value='$fn'>&nbsp</td>\n";
	echo "</tr>\n";
    }
    echo "</form>\n";
    echo "</table>\n";
}

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