webbukkit / dynmap

A set of Minecraft mods that provide a real time web-based map system for various Minecraft server implementations.
https://www.reddit.com/r/Dynmap/
Apache License 2.0
2.06k stars 421 forks source link

PHP errors occasionally when running dynmap standalone - potential cause: world names with spaces, double forward slashes in pathnames #3137

Open RWoof opened 4 years ago

RWoof commented 4 years ago

Issue Description: Disclaimer: I have little to no PHP experience so I'm pretty lost here and my assumptions could be way off base. I noticed after installing dynmap standalone using Nginx that I would occasionally get a few PHP errors in my error log. I think part of the issue was 3 of my worlds having spaces in their names and I also think that the current code in update.php will add a double // to the $fname variable since the $webpath seems to always add a forward slash at the end when it's created and the code to set $fname adds another slash in front of /standalone.

My attempts to correct this using if/else statements to add the ' characters in the $fname if $world contains spaces have caused dynmap to fail to update in my web browser. Here's what I tried:

if(isset($webpath)) {
  if ($world == trim($world) && strpos($world, ' ') !== false)
    $fname = $webpath . "standalone/'updates_" . $world . ".php'";
  else
    $fname = $webpath . 'standalone/updates_' . $world . '.php';
}
else {
  if ($world == trim($world) && strpos($world, ' ') !== false)
    $fname = 'updates_' . "'$world" . ".php'";
  else
    $fname = 'updates_' . $world . '.php';
}

I believe it might be failing because the if(!is_readable($fname)) code shortly after $fname is set that causes the script to return rather than continuing.

if(!is_readable($fname)) { header('HTTP/1.0 404 Not Found'); return; }

$useridlc = strtolower($userid); $uid = '[' . $useridlc . ']';

if(isset($worldaccess[$world])) { $ss = stristr($worldaccess[$world], $uid); if($ss === false) { echo "{ \"error\": \"access-denied\" }"; return; } }

$lines = file($fname);


* **Steps to Replicate:**
Set up a standalone version of dynmap using Nginx, have world names in Minecraft with spaces in them. The errors for me don't appear constantly, usually I get a few each day, I'm not sure what causes update.php to run, what the code after $lines is set does and why it doesn't error constantly. I'm not even sure what these update files are for to be honest.

 [X] *I have looked at all other issues and this is not a duplicate*  
 [X] *I have been able to replicate this*
isaaclepes commented 3 years ago

I am also seeing this issue, but there are no spaces in my world name "8675309". Error occurs dozens of times a day. My suspicion is that, if the web request comes in while updates_world.php is being updated, it sees it as missing. I can't imagine it locking the file for more than mere milliseconds, though, so this may not be the correct assumption.

It does produce the '//' in the path, but most operating systems (Windows, Mac, Unix, and Linux included) allow the inclusion of multiple slashes between file name or directory components of a file path. They just ignore the extra slash characters.

[error] 976#976: *1060859 FastCGI sent in stderr: "PHP message: PHP Warning: file(/var/www/html//standalone/updates8675309.php): failed to open stream: No such file or directory in /var/www/html/standalone/update.php on line 51" while reading response header from upstream, client: 10.0.0.9, server: , request: "GET /standalone/update.php?world=8675309&ts=1620740155312 HTTP/1.0", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "10.0.0.13", referrer: "https://[REDACTED]/index.html"

Dynmap Jar: Dynmap-3.1-spigot.jar