Changeset 0662b2d for src/webapp/webservice/inc/GnuBoat/ServiceLogFiles.php
- Timestamp:
- Aug 30, 2017, 2:45:37 PM (9 years ago)
- Branches:
- 0.5, debian/bullseye, debian/jessie, master
- Children:
- a50c18f
- Parents:
- 89c510f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webservice/inc/GnuBoat/ServiceLogFiles.php
r89c510f r0662b2d 39 39 $files = glob($config->logDirectory() ."*.log"); 40 40 array_walk($files, 'GnuBoat\ServiceLogFiles::stripLogDirectory'); 41 return $this->output($files); 42 } 41 43 42 header('Content-Type: application/json'); 43 if($debug > 0){ 44 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>"; 45 52 } 46 else{ 47 echo json_encode($files) ."\n"; 48 } 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; 49 58 } 50 59 else{ 51 // prepare a download of available log files 52 $files = $_POST["logfilesSelected"]; 53 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>"; 54 68 return; 55 69 } 56 elseif(count($files) == 1){ 57 $content = file_get_contents($config->logDirectory() . $files[0]); 58 if($content === false){ 59 echo "<html><head></head><body>Failed to read logfile ". $files[0] ."</body></html>"; 60 } 61 62 header('Content-Type: text/plain'); 63 header('Content-disposition: attachment; filename="'. $files[0] .'"'); 64 header('Content-Length: ' . filesize($config->logDirectory() . $files[0])); 65 echo $content; 66 } 67 else{ 68 $date = new \DateTime('NOW'); 69 $archiveName = "gnuboat-logs-". $date->format("Y-m-d"); 70 71 // provide files as zip file 72 $tmpArchive = tempnam(sys_get_temp_dir(), $archiveName); 73 $zip = new \ZipArchive(); 74 if($zip->open($tmpArchive, \ZipArchive::CREATE) !== TRUE){ 75 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>"; 76 74 return; 77 75 } 78 foreach($files as $file){79 if($zip->addFile($config->logDirectory() . $file, $archiveName ."/". $file) !== true){80 $zip->close();81 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";82 return;83 }84 }85 if($zip->close() !== true){86 echo "<html><head></head><body>Failed to save zip file</body></html>";87 return;88 }89 90 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";91 92 //Send zip folder93 while (ob_get_level()) {94 ob_end_clean();95 }96 ob_start();97 header('Content-Type: application/zip');98 header('Content-Transfer-Encoding: Binary');99 header('Content-disposition: attachment; filename=' . $archiveName . '.zip');100 header('Content-Length: ' . filesize($tmpArchive));101 ob_flush();102 ob_clean();103 readfile($tmpArchive);104 unlink($tmpArchive);105 return;106 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; 107 98 } 108 99 }
Note:
See TracChangeset
for help on using the changeset viewer.
