} else { return ""; } } function fileInformation($myFile) { $ft = filetype($myFile); if (!$ft) { return "name=" . $myFile . " error=not found or file error"; } else { return "name=" . $myFile . " type=" . $ft . " size=" . filesize($myFile) . " permissions=" . substr(sprintf('%o', fileperms($myFile)), -4) . " time=" . date("M d H:i:s e", filemtime($myFile)); } } if ($secretHash == $storedSecretHash) { $overwrite = FALSE; $message = logMsg("\n" . fileInformation($localPgnFile) . "\n" . fileInformation($localPgnTmpFile) . "\n" . fileInformation($localPgnLogFile) . "\n" . fileInformation(".")); switch ($action) { case "grab PGN URL overwrite": $overwrite = TRUE; case "grab PGN URL": $message = $message . "\n" . "action=" . $action . "\n" . "localPgnFile=" . $localPgnFile . "\n" . "pgnUrl=" . $pgnUrl . "\n" . "refreshSeconds=" . $refreshSeconds . "\n" . "refreshSteps=" . $refreshSteps; $errorMessage = checkFileExisting($localPgnFile, $localPgnTmpFile, $localPgnLogFile); if (!$overwrite && $errorMessage) { $message = $message . "\n" . $errorMessage; } else { if (--$refreshSteps < 0) { $message = $message . "\n" . "error=invalid refresh steps"; } else { $logOk = FALSE; $newLastPgnUrlModification = ""; $pgnHeaders = get_headers($pgnUrl, 1);
/** * Get a directory listing, or the listing for a single file. * * @param string $path the target's path * @return array|int array of files, or int indicating lack of success (see RFUtilException for possible values) */ function rf_ls($path) { $data = array(); // return data array $wildcard = false; if (strpos($path, '*') !== false) { $wildcard = basename($path); $path = dirname($path) . '/'; // was glob inside path? if (strpos($path, '*') !== false) { return RFUtilException::BAD_WILDCARD_LOCATION; } $wildcard = explode('*', $wildcard); foreach ($wildcard as &$token) { $token = preg_quote($token); } $wildcard = implode('.*', $wildcard); $wildcard = sprintf('/^%s$/i', $wildcard); } if (!file_exists($path)) { return RFUtilException::FILE_NOT_FOUND; } if (!is_readable($path)) { return RFUtilException::UNREADABLE_PATH; } // directory if (is_dir($path)) { // fail if path doesn't end in a slash (client should redirect) if (substr($path, -1) !== '/') { return RFUtilException::DIR_MISSING_SLASH; } if ($d = opendir($path)) { while (($f = readdir($d)) !== false) { // wildcard check if ($wildcard !== false && preg_match($wildcard, $f) == 0) { continue; } $tmp = fileInformation($path, $f); if ($tmp) { $data[$f] = $tmp; } } closedir($d); } } elseif (is_file($path)) { $f = basename($path); $dir = dirname($path) . '/'; $data[$f] = fileInformation($dir, $f); } else { return RFUtilException::BAD_FILE_TYPE; } return $data; }