newnode_edit.php3 6.42 KB
Newer Older
1 2
<?PHP
#
Leigh Stoller's avatar
Leigh Stoller committed
3
# Copyright (c) 2003-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/>.
# 
# }}}
23 24 25 26 27 28 29 30 31 32 33
#
require("defs.php3");

#
# List the nodes that have checked in and are awaint being added the the real
# testbed
#

#
# Only admins can see this page
#
34 35 36 37
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();

38 39 40 41
if (! $isadmin) {
    USERERROR("You do not have admin privileges!", 1);
}

42 43 44 45 46
$reqargs = RequiredPageArguments("id",         PAGEARG_STRING);
$optargs = OptionalPageArguments("node_id",    PAGEARG_STRING,
				 "type",       PAGEARG_STRING,
				 "IP",         PAGEARG_STRING,
				 "identifier", PAGEARG_STRING);
47

48 49 50 51 52
#
# Standard Testbed Header
#
PAGEHEADER("New Testbed Node");

53 54 55 56
if (!TBvalid_node_id($id)) {
    PAGEARGERROR("Invalid id");
}

57 58 59
#
# If we had any update information passed to us, do the update now
#
60
if (isset($node_id)) {
61 62 63 64 65 66 67 68 69 70 71 72
    if (!TBvalid_node_id($node_id)) {
	PAGEARGERROR("Invalid node id");
    }
    if (!TBvalid_node_type($type)) {
	PAGEARGERROR("Invalid node type");
    }
    if (!TBvalid_IP($IP)) {
	PAGEARGERROR("Invalid node IP");
    }
    if (!TBvalid_userdata($identifier)) {
	PAGEARGERROR("Invalid node identifier");
    }
73
    DBQueryFatal("UPDATE new_nodes SET node_id='$node_id', type='$type', " .
74
    	"IP='$IP', identifier='$identifier' WHERE new_node_id='$id'");
75 76 77 78 79
}

#
# Same for interface update information
#
Mike Hibler's avatar
Mike Hibler committed
80
foreach ($_GET as $key => $value) {
81 82
    if (preg_match("/iface(\d+)_mac/",$key,$matches)) {
    	$card        = $matches[1];
Mike Hibler's avatar
Mike Hibler committed
83 84 85 86 87 88 89
    	$mac         = addslashes($_GET["iface${card}_mac"]);
    	$type        = addslashes($_GET["iface${card}_type"]);
    	$switch_id   = addslashes($_GET["iface${card}_switch_id"]);
    	$switch_card = addslashes($_GET["iface${card}_switch_card"]);
    	$switch_port = addslashes($_GET["iface${card}_switch_port"]);
    	$cable       = addslashes($_GET["iface${card}_cable"]);
    	$len         = addslashes($_GET["iface${card}_len"]);
Leigh Stoller's avatar
Leigh Stoller committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
        $query = "UPDATE new_interfaces SET mac='$mac', " .
	    "interface_type='$type', switch_id='$switch_id' ";
        if ($switch_card != '') {
            $query .= ",switch_card='$switch_card'";
        }
        if ($switch_port != '') {
            $query .= ",switch_port='$switch_port'";
        }
        if ($cable != '') {
            $query .= ",cable='$cable'";
        }
        if ($len != '') {
            $query .= ",len='$len' ";
        }
        DBQueryFatal("$query WHERE new_node_id=$id AND card='$card'");
105 106 107 108 109 110 111
    }
}

#
# Get the information about the node they asked for
#
$query_result = DBQueryFatal("SELECT new_node_id, node_id, type, IP, " .
112
	"DATE_FORMAT(created,'%M %e %H:%i:%s') as created, dmesg, " .
113
	"identifier, building " .
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
	"FROM new_nodes WHERE new_node_id='$id'");

if (mysql_num_rows($query_result) != 1) {
    USERERROR("Error getting information for node ID $id",1);
}

$row = mysql_fetch_array($query_result)

?>

<h4><a href="newnodes_list.php3">Back to the new node list</a></h4>

<form action="newnode_edit.php3" method="get">

<input type="hidden" name="id" value="<?=$id?>">

<h3 align="center">Node</h3>

<table align="center">
<tr>
    <th>ID</th>
    <td><?= $row['new_node_id'] ?></td>
</tr>
<tr>
    <th>Node ID</th>
    <td>
    <input type="text" width=10 name="node_id" value="<?=$row['node_id']?>">
    </td>
</tr>
143 144 145 146 147 148
<tr>
    <th>Identifier</th>
    <td>
    <input type="text" width=10 name="identifier" value="<?=$row['identifier']?>">
    </td>
</tr>
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
<tr>
    <th>Type</th>
    <td>
    <input type="text" width=10 name="type" value="<?=$row['type']?>">
    </td>
</tr>
<tr>
    <th>IP</th>
    <td>
    <input type="text" width=10 name="IP" value="<?=$row['IP']?>">
    </td>
</tr>
<tr>
    <th>Created</th>
    <td><?= $row['created'] ?></td>
</tr>
165 166 167 168 169 170 171 172 173 174 175
<tr>
    <th>Location</th>
    <td>
    <? if ($row['building']) {
	echo "Set (<a href=setnodeloc.php3?node_id=$id&isnewid=1>Change</a>)\n";
       } else {
	echo "Unset (<a href=setnodeloc.php3?node_id=$id&isnewid=1>Set</a>)\n";
       }
    ?>
    </td>
</tr>
176 177 178 179 180 181 182 183
<tr>
    <th>dmesg Output</th>
    <td><?= $row['dmesg'] ?></td>
</tr>
</table>

<h3 align="center">Interfaces</h3>

184 185
<em>Note:</em>Cable and Length are for informational use only, and are optional.

186 187 188 189 190 191 192 193
<table align="center">
<tr>
    <th>Interface</th>
    <th>MAC</th>
    <th>Type</th>
    <th>Switch</th>
    <th>Card</th>
    <th>Port</th>
194 195
    <th>Cable</th>
    <th>Length</th>
196 197 198 199
</tr>

<?

200
$query_result = DBQueryFatal("SELECT card, mac, interface_type, switch_id, " .
201
	"switch_card, switch_port, cable, len FROM new_interfaces " .
202
	"where new_node_id=$id order by card");
203
while ($row = mysql_fetch_array($query_result)) {
204
    $card        = $row['card'];
205 206 207 208 209
    $mac         = $row['mac'];
    $type        = $row['interface_type'];
    $switch_id   = $row['switch_id'];
    $switch_card = $row['switch_card'];
    $switch_port = $row['switch_port'];
210 211
    $cable       = $row['cable'];
    $len         = $row['len'];
212
    echo "<tr>\n";
213 214
    echo "<td>$card</td>\n";
    echo "<td><input type='text' name='iface${card}_mac' size=12 " .
215
	"value='$mac'></td>\n";
216
    echo "<td><input type='text' name='iface${card}_type' size=5 " .
217
	"value='$type'></td>\n";
218
    echo "<td><input type='text' name='iface${card}_switch_id' size=16 " .
219
	"value='$switch_id'></td>\n";
220
    echo "<td><input type='text' name='iface${card}_switch_card' size=3 " .
221
	"value='$switch_card'></td>\n";
222
    echo "<td><input type='text' name='iface${card}_switch_port' size=3 " .
223
	"value='$switch_port'></td>\n";
224 225 226 227
    echo "<td><input type='text' name='iface${card}_cable' size=5 " .
	"value='$cable'></td>\n";
    echo "<td><input type='text' name='iface${card}_len' size=3 " .
	"value='$len'></td>\n";
228 229 230 231 232 233 234 235 236 237 238 239 240 241
    echo "</tr>\n";
}

?>

</table>

<br>

<center>
<input type="submit" name="submit" value="Update node">
</center>
<?

242

243 244 245 246 247 248
#
# Standard Testbed Footer
# 
PAGEFOOTER();

?>