Commit dc5da311 authored by David Johnson's avatar David Johnson

Bugs.

parent 4f60ddee
...@@ -50,13 +50,17 @@ $FILEROOT = "$TBDIR/etc/osconfig"; ...@@ -50,13 +50,17 @@ $FILEROOT = "$TBDIR/etc/osconfig";
# #
function SPITERROR($msg) { function SPITERROR($msg) {
header("Content-Type: text/plain"); header("Content-Type: text/plain");
echo "TBERROR: $msg\n"; $fmsg = "TBERROR: $msg\n";
header("Content-Length: " . strlen($fmsg) . "\n");
echo "$fmsg";
exit(1); exit(1);
} }
function SPITMSG($msg) { function SPITMSG($msg) {
header("Content-Type: text/plain"); header("Content-Type: text/plain");
echo "TBMSG: $msg\n"; $fmsg = "TBMSG: $msg\n";
header("Content-Length: " . strlen($fmsg) . "\n");
echo "$fmsg";
exit(1); exit(1);
} }
...@@ -123,28 +127,38 @@ if ($_SERVER["REMOTE_ADDR"] != $ip) { ...@@ -123,28 +127,38 @@ if ($_SERVER["REMOTE_ADDR"] != $ip) {
SPITERROR("no proxies allowed"); SPITERROR("no proxies allowed");
} }
# need this below # need node_id below
$node = Node::LookupByIP($ip);
if (!$node) {
SPITERROR("no such node");
}
$node_id = $node->node_id();
# #
# Make sure this is a valid request before we return anything. # Make sure this is a valid request before we return anything.
# #
# Note, we don't use Node::LookupByIP in the widearea case since there might
# be multiple node_ids using this control IP -- we explicitly look for the
# one in the widearea_nodeinfo table.
$node_id = "";
if (isset($privkey)) { if (isset($privkey)) {
$qres = DBQueryFatal("select node_id from widearea_nodeinfo" . $qres = DBQueryFatal("select node_id from widearea_nodeinfo" .
" where node_id='" . addslashes($node_id) . "' and" . " where IP='" . addslashes($ip) . "' and" .
" privkey='" . addslashes($privkey) . "'"); " privkey='" . addslashes($privkey) . "'");
if (! mysql_num_rows($qres)) { if (!$qres || mysql_num_rows($qres) < 1) {
SPITERROR("noauth"); SPITERROR("noauth");
} }
else if (mysql_num_rows($qres) > 1) {
SPITERROR("ambiguous id");
}
$row = mysql_fetch_array($qres);
$node_id = $row["node_id"];
$node = Node::Lookup($node_id);
} }
else { else {
if (!IsControlNetIP($ip)) { if (!IsControlNetIP($ip)) {
SPITERROR("notlocal"); SPITERROR("notlocal");
} }
$node = Node::Lookup($ip);
$node_id = $node->node_id();
}
if (!$node) {
SPITERROR("no such node");
} }
# #
...@@ -178,7 +192,9 @@ while ($row = mysql_fetch_array($qres)) { ...@@ -178,7 +192,9 @@ while ($row = mysql_fetch_array($qres)) {
if (!in_array($c,$constraints)) if (!in_array($c,$constraints))
continue; continue;
#echo "matching $c / " . $row["constraint_value"] . " to " . $data["$c"] . "\n";
$val = match_constraint($c,$row["constraint_value"],$data); $val = match_constraint($c,$row["constraint_value"],$data);
#var_dump($val);
if (!isset($conproc[$row["target_file_idx"]])) if (!isset($conproc[$row["target_file_idx"]]))
$conproc[$row["target_file_idx"]] = array(); $conproc[$row["target_file_idx"]] = array();
...@@ -195,9 +211,9 @@ while ($row = mysql_fetch_array($qres)) { ...@@ -195,9 +211,9 @@ while ($row = mysql_fetch_array($qres)) {
# have been met, then we can call this target matched. # have been met, then we can call this target matched.
# #
foreach ($conproc as $target_idx => $target) { foreach ($conproc as $target_idx => $target) {
$cmatch = FALSE; $cmatch = TRUE;
foreach ($target as $constraint => $match) foreach ($target as $constraint => $match)
$cmatch = ($cmatch || $match); $cmatch = ($cmatch && $match);
if ($cmatch) if ($cmatch)
array_push($match_targets,$target_idx); array_push($match_targets,$target_idx);
...@@ -238,7 +254,7 @@ $manifest_str = ""; ...@@ -238,7 +254,7 @@ $manifest_str = "";
$i = 0; $i = 0;
while ($row = mysql_fetch_array($qres)) { while ($row = mysql_fetch_array($qres)) {
if (in_array($row['file_idx'],$match_targets) if (in_array($row['file_idx'],$match_targets)
&& !in_array($row['file_idx'])) { && !in_array($row['file_idx'],$done)) {
$files[$i++] = $row["path"]; $files[$i++] = $row["path"];
$manifest_str .= $row["path"] . "\t" . $row["type"] . "\t" . $manifest_str .= $row["path"] . "\t" . $row["type"] . "\t" .
$row["dest"] . "\n"; $row["dest"] . "\n";
...@@ -265,12 +281,12 @@ chdir($FILEROOT); ...@@ -265,12 +281,12 @@ chdir($FILEROOT);
$retval = system("tar -cf $archive " . implode(" ",$files)); $retval = system("tar -cf $archive " . implode(" ",$files));
if ($retval) if ($retval)
SPITERROR("cdata"); SPITERROR("cdata1");
chdir("$randdir"); chdir("$randdir");
$retval = system("tar -rf $archive MANIFEST"); $retval = system("tar -rf $archive MANIFEST");
if ($retval) if ($retval)
SPITERROR("cdata"); SPITERROR("cdata2");
system("gzip $archive"); system("gzip $archive");
$archive .= ".gz"; $archive .= ".gz";
......
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