diff --git a/www/index.php b/www/index.php index bf58256..6eb224b 100644 --- a/www/index.php +++ b/www/index.php @@ -47,6 +47,12 @@ function get_zip_meta($path): array { } $meta = fread($fp, unpack("V", substr($zipHdr2, 18, 4))[1]); + fclose($fp); + return array($meta, $version); +} + +function get_zip_files($path, $skip=0): string { + $fp = fopen($path, "rb"); $files = "{"; $first = true; while (!feof($fp)) { @@ -59,6 +65,7 @@ function get_zip_meta($path): array { $crc = unpack("V", substr($zipHdr3, 14, 4))[1]; fseek($fp, $compSize, SEEK_CUR); $hex = substr("00000000" . dechex($crc), -8); + if ($skip-- > 0) continue; if (!$first) $files .= ", "; $files .= "\"$name\": {\"compressed_size\": $compSize, \"uncompressed_size\": $uncompSize, \"crc32\": \"$hex\"}"; $first = false; @@ -66,7 +73,7 @@ function get_zip_meta($path): array { $files .= "}"; fclose($fp); - return array($meta, $version, $files); + return $files; } $path = $_SERVER['PATH_INFO']; @@ -183,8 +190,12 @@ foreach ($clients as $c) { $datetime = '"' . $dt->format(DateTimeInterface::RFC3339) . '"'; $zwstid = "\"$parts[2]\""; } - list($meta, $version, $files) = get_zip_meta($path); - $files ??= "null"; + list($meta, $version) = get_zip_meta($path); + if (str_ends_with($file, ".zip")) { + $files = get_zip_files($path, $meta !== 'null' ? 2 : 0); + } else { + $files = "null"; + } $version ??= "null"; echo " {\"name\": \"$file\", \"timestamp\": $datetime, \"zwstid\": $zwstid, \"meta\": $meta, \"files\": $files, " . "\"version\": $version, \"url\": \"$url\", \"size\": $size, \"created\": \"$cre\", \"modified\": \"$mod\"}";