- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webservice/inc/GnuBoat/ServiceLogFiles.php
r1ba85cf r0662b2d 32 32 $debug = $this->debug(); 33 33 $config = new Config(); 34 if($debug > 1) 35 print "Log directory: ". $config->logDirectory() ."\n"; 34 36 35 37 if(!array_key_exists("logfilesSelected", $_POST)){ … … 37 39 $files = glob($config->logDirectory() ."*.log"); 38 40 array_walk($files, 'GnuBoat\ServiceLogFiles::stripLogDirectory'); 41 return $this->output($files); 42 } 39 43 40 header('Content-Type: application/json'); 41 if($debug > 0){ 42 echo json_encode($files, JSON_PRETTY_PRINT) ."\n"; 44 // prepare a download of available log files 45 $files = $_POST["logfilesSelected"]; 46 if(count($files) < 1) 47 return $this->error("No logfile selected"); 48 elseif(count($files) == 1){ 49 $content = file_get_contents($config->logDirectory() . $files[0]); 50 if($content === false){ 51 echo "<html><head></head><body>Failed to read logfile ". $files[0] ."</body></html>"; 43 52 } 44 else{ 45 echo json_encode($files) ."\n"; 46 } 53 54 header('Content-Type: text/plain'); 55 header('Content-disposition: attachment; filename="'. $files[0] .'"'); 56 header('Content-Length: ' . filesize($config->logDirectory() . $files[0])); 57 echo $content; 47 58 } 48 59 else{ 49 // prepare a download of available log files 50 $files = $_POST["logfilesSelected"]; 51 if(count($files) < 1){ 60 $date = new \DateTime('NOW'); 61 $archiveName = "gnuboat-logs-". $date->format("Y-m-d"); 62 63 // provide files as zip file 64 $tmpArchive = tempnam(sys_get_temp_dir(), $archiveName); 65 $zip = new \ZipArchive(); 66 if($zip->open($tmpArchive, \ZipArchive::CREATE) !== TRUE){ 67 echo "<html><head></head><body>Failed to create zip file</body></html>"; 52 68 return; 53 69 } 54 elseif(count($files) == 1){ 55 $content = file_get_contents($config->logDirectory() . $files[0]); 56 if($content === false){ 57 echo "<html><head></head><body>Failed to read logfile ". $files[0] ."</body></html>"; 58 } 59 60 header('Content-Type: text/plain'); 61 header('Content-disposition: attachment; filename="'. $files[0] .'"'); 62 header('Content-Length: ' . filesize($config->logDirectory() . $files[0])); 63 echo $content; 64 } 65 else{ 66 $date = new \DateTime('NOW'); 67 $archiveName = "gnuboat-logs-". $date->format("Y-m-d"); 68 69 // provide files as zip file 70 $tmpArchive = tempnam(sys_get_temp_dir(), $archiveName); 71 $zip = new \ZipArchive(); 72 if($zip->open($tmpArchive, \ZipArchive::CREATE) !== TRUE){ 73 echo "<html><head></head><body>Failed to create zip file</body></html>"; 70 foreach($files as $file){ 71 if($zip->addFile($config->logDirectory() . $file, $archiveName ."/". $file) !== true){ 72 $zip->close(); 73 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>"; 74 74 return; 75 75 } 76 foreach($files as $file){77 if($zip->addFile($config->logDirectory() . $file, $archiveName ."/". $file) !== true){78 $zip->close();79 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";80 return;81 }82 }83 if($zip->close() !== true){84 echo "<html><head></head><body>Failed to save zip file</body></html>";85 return;86 }87 88 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";89 90 //Send zip folder91 while (ob_get_level()) {92 ob_end_clean();93 }94 ob_start();95 header('Content-Type: application/zip');96 header('Content-Transfer-Encoding: Binary');97 header('Content-disposition: attachment; filename=' . $archiveName . '.zip');98 header('Content-Length: ' . filesize($tmpArchive));99 ob_flush();100 ob_clean();101 readfile($tmpArchive);102 unlink($tmpArchive);103 return;104 76 } 77 if($zip->close() !== true){ 78 echo "<html><head></head><body>Failed to save zip file</body></html>"; 79 return; 80 } 81 82 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>"; 83 84 //Send zip folder 85 while (ob_get_level()) { 86 ob_end_clean(); 87 } 88 ob_start(); 89 header('Content-Type: application/zip'); 90 header('Content-Transfer-Encoding: Binary'); 91 header('Content-disposition: attachment; filename=' . $archiveName . '.zip'); 92 header('Content-Length: ' . filesize($tmpArchive)); 93 ob_flush(); 94 ob_clean(); 95 readfile($tmpArchive); 96 unlink($tmpArchive); 97 return; 105 98 } 106 99 }
Note:
See TracChangeset
for help on using the changeset viewer.
