Commit a7c02305 authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Minor changes; update the nickname when remote nodes checkin in case

their real hostname changes.
parent 48629e9c
......@@ -95,6 +95,19 @@ if (isset($wahostname) &&
return;
}
#
# Generate a nickname if given hostname.
#
unset($nickname);
if (isset($wahostname)) {
if (strpos($wahostname, ".")) {
$nickname = str_replace(".", "-", $wahostname);
}
else {
$nickname = $wahostname;
}
}
if (isset($roottag) &&
!ereg("[0-9a-zA-Z]+", $roottag)) {
SPITSTATUS(CDROMSTATUS_INVALIDARGS);
......@@ -130,21 +143,13 @@ if (isset($updated) && $updated == 1) {
"set IP='$IP' ".
"where privkey='$privkey'");
#
# Generate a nickname if given hostname.
#
$nickname = "";
$type = "pcwa";
if (isset($wahostname)) {
$nickname .= "-n ";
if (strpos($wahostname, ".")) {
$nickname .= str_replace(".", "-", $wahostname);
}
else {
$nickname .= $wahostname;
}
$newargs = "-w -i $IP ";
if (isset($nickname)) {
$newargs .= " -n $nickname ";
}
$type = "pcwa";
if (isset($wahostname)) {
#
# XXX Parse hostname to see if a ron node.
# Silly, but effective since we will never have anything else
......@@ -155,8 +160,8 @@ if (isset($updated) && $updated == 1) {
$type = "pcron";
}
}
SUEXEC("nobody", $TBADMINGROUP,
"webnewwanode -w $nickname -t $type -i $IP", 0);
$newargs .= " -t $type ";
SUEXEC("nobody", $TBADMINGROUP, "webnewwanode $newargs", 0);
}
$newroot = "";
if (isset($roottag)) {
......@@ -168,6 +173,17 @@ if (isset($updated) && $updated == 1) {
" $newroot ".
"where privkey='$privkey'");
#
# Update with new nickname. Nice if node changes its real hostname.
#
if (isset($nickname)) {
$nodeid = TBIPtoNodeID($IP);
if ($nodeid) {
DBQueryFatal("update reserved set vname='$nickname' ".
"where node_id='$nodeid'");
}
}
SPITSTATUS(CDROMSTATUS_OKAY);
return;
}
......
......@@ -1190,6 +1190,24 @@ function TBGetVerificationKey($name) {
return $row[verify_key];
}
#
# Map IP to nodeid.
#
function TBIPtoNodeID($ip) {
$query_result =
DBQueryFatal("select n.node_id from interfaces as i ".
"left join nodes as n on n.node_id=i.node_id ".
"left join node_types as t ".
" on t.type=n.type and i.card=t.control_net ".
"where i.IP='$ip'");
if (mysql_num_rows($query_result) == 0) {
return 0;
}
$row = mysql_fetch_array($query_result);
return $row[node_id];
}
#
# DB Interface.
#
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment