Browse Source

Send a 404 error if nothing is to be done.

Joe Clarke 5 years ago
parent
commit
b32f2bb461
1 changed files with 6 additions and 3 deletions
  1. 6 3
      www/swreg/callhome.php

+ 6 - 3
www/swreg/callhome.php

@@ -53,8 +53,6 @@ $logger->setMask($mask);
 
 list($pid, $sn) = explode('/', trim($_SERVER['PATH_INFO'], '/'));
 
-header('Content-type: text/plain');
-
 // Right now, we will just check if the switch should be re-ZTP'd
 
 $sql = 'SELECT should_re_ztp FROM DEVICE_MAP WHERE serial_number=?';
@@ -62,6 +60,7 @@ try {
     $sth = $dbh->prepare($sql);
     $res = $sth->execute(array($sn));
 } catch (PDOException $e) {
+    header('Content-type: text/plain');
     echo "! ERROR: Failed to get switch for SN {$sn}: ".$e->getMessage()."\r\n";
     $logger->crit("Failed to get switch for SN {$sn}: ".$e->getMessage());
     exit(1);
@@ -70,7 +69,9 @@ try {
 $row = $sth->fetch();
 $sth->closeCursor();
 
+// Only handle re-ZTP for now.
 if ($row['should_re_ztp'] == 1) {
+    header('Content-type: text/plain');
     echo "! RE-ZTP\r\n";
     $logger->info("Sending RE-ZTP message for switch {$sn}");
 
@@ -84,4 +85,6 @@ if ($row['should_re_ztp'] == 1) {
     exit(0);
 }
 
-echo "!\r\n";
+// Send a 404 to prevent unnecessarily writing to flash
+http_response_code(404);
+exit(0);